Custom file format for VTK

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?

Hi @AndreAhmed

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

Best,

If your mesh is a simple surface mesh, the VTK Cube example might help.

@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 ?

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.

@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 ?

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

@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.

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.

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 ?

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

What are the VTKTools for that purpose ?

VTK is the tool itself.