# Custom file format for VTK

**URL:** https://discourse.vtk.org/t/custom-file-format-for-vtk/9855
**Category:** Development
**Tags:** file-formats
**Created:** [November 17, 2022, 9:42am UTC](https://discourse.vtk.org/t/custom-file-format-for-vtk/9855 "2022-11-17T09:42:16Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![AndreAhmed](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andreahmed/32/6061_2.png) [@AndreAhmed](https://discourse.vtk.org/u/AndreAhmed)
#### Post date: [November 17, 2022, 9:42am UTC](https://discourse.vtk.org/t/custom-file-format-for-vtk/9855/1 "2022-11-17T09:42:16Z")

</div>

Hello,  
I have a custom file format and I do conversion to VTK to to let VTK render my mesh, I would like to avoid such conversion from my mesh to VTK and from VTK to my mesh.  
Is there a suitable solution so that I inject the data structure of my mesh into VTK rendering pipeline directly?

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [November 17, 2022, 12:55pm UTC](https://discourse.vtk.org/t/custom-file-format-for-vtk/9855/2 "2022-11-17T12:55:48Z")

</div>

Hi @AndreAhmed

You have to implement your own reader in C++, take a look at the many readers in VTK/IO/

Best,

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [November 17, 2022, 1:21pm UTC](https://discourse.vtk.org/t/custom-file-format-for-vtk/9855/3 "2022-11-17T13:21:59Z")

</div>

If your mesh is a simple surface mesh, the [VTK Cube](https://kitware.github.io/vtk-examples/site/Cxx/GeometricObjects/Cube/) example might help.

---

<div class="post-metadata">

### Author: ![AndreAhmed](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andreahmed/32/6061_2.png) [@AndreAhmed](https://discourse.vtk.org/u/AndreAhmed)
#### Post date: [November 17, 2022, 2:40pm UTC](https://discourse.vtk.org/t/custom-file-format-for-vtk/9855/4 "2022-11-17T14:40:12Z")

</div>

@mwestphal Thanks. And to convert from VTK to my mesh in runtime how is be possible ?  
Should my mesh and VTK polydata share the same vertices,faces,.etc how would that be possible too ?

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [November 17, 2022, 2:41pm UTC](https://discourse.vtk.org/t/custom-file-format-for-vtk/9855/5 "2022-11-17T14:41:56Z")

</div>

> [@AndreAhmed](#):
>
> VTK to my mesh in runtime how is be possible ?

Yes, you need to write a Writer

> Should my mesh and VTK polydata share the same vertices,faces,.etc how would that be possible too ?

Everything is possible but if your memory layout is close to VTK, then less work and propably more efficient.

---

<div class="post-metadata">

### Author: ![AndreAhmed](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andreahmed/32/6061_2.png) [@AndreAhmed](https://discourse.vtk.org/u/AndreAhmed)
#### Post date: [November 17, 2022, 2:44pm UTC](https://discourse.vtk.org/t/custom-file-format-for-vtk/9855/6 "2022-11-17T14:44:08Z")

</div>

@mwestphal so the writer still will convert from VTK mesh to my own mesh, which is 500K triangles, at runtime this is time consuming… any other better idea ?

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [November 17, 2022, 2:47pm UTC](https://discourse.vtk.org/t/custom-file-format-for-vtk/9855/7 "2022-11-17T14:47:45Z")

</div>

Well any writer will need to write the data to disk, so I’m a bit confused but what you mean.

---

<div class="post-metadata">

### Author: ![AndreAhmed](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andreahmed/32/6061_2.png) [@AndreAhmed](https://discourse.vtk.org/u/AndreAhmed)
#### Post date: [November 17, 2022, 2:49pm UTC](https://discourse.vtk.org/t/custom-file-format-for-vtk/9855/8 "2022-11-17T14:49:20Z")

</div>

@mwestphal  
So lets suppost I wrote my own reader and converted my mesh file format into vtkpolydata,…etc

At runtime of the application, I’m using VTKpolydata, but I want to convert them to my mesh in runtime, and do some maths on my mesh back. So it’s like bakward conversion in runtime too not on desk.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [November 17, 2022, 2:55pm UTC](https://discourse.vtk.org/t/custom-file-format-for-vtk/9855/9 "2022-11-17T14:55:13Z")

</div>

> [@AndreAhmed](#):
>
> but I want to convert them to my mesh in runtime,

So not a writer/reader since not going through the disk and unrelated to file format at all.

Well just convert using VTK tools. If memory can be shared (zero copy), you want to do that, but that depends on your format.

---

<div class="post-metadata">

### Author: ![AndreAhmed](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andreahmed/32/6061_2.png) [@AndreAhmed](https://discourse.vtk.org/u/AndreAhmed)
#### Post date: [November 17, 2022, 2:58pm UTC](https://discourse.vtk.org/t/custom-file-format-for-vtk/9855/10 "2022-11-17T14:58:26Z")

</div>

I guess, there should be a reader, because I want to load the mesh from disk, then convert it to VTKpolydata…  
But the other scenario at runtime, don’t know how to solve the issue If I want from VTK to convert to my mesh…  
What are the VTKTools for that purpose ?

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [November 17, 2022, 3:01pm UTC](https://discourse.vtk.org/t/custom-file-format-for-vtk/9855/11 "2022-11-17T15:01:41Z")

</div>

> [@AndreAhmed](#):
>
> I guess, there should be a reader, because I want to load the mesh from disk, then convert it to VTKpolydata…

Then do not convert, but read it directly into a vtkPolyData.

> What are the VTKTools for that purpose ?

VTK is the tool itself.
