How to convert polydata vtk file to structured grid vtk file

Hello
I have a VTK file that contains only quad cells but it is written as Polydata dataset. How can I convert it to a structured grid?

Thanks

Filters -> RessampleToImage.

Here is my original mesh

original

And here is the result after applying the “Resample to Image” filter:

output

Unfortunately, that doesn’t work as expected.

Indeed, What I suggested trasnform your dataset into an Image.

There is now way to create a StructuredGrid from scratch in PV, and your dataset does not seems to be described as a structure grid since it contains a hole.

What are you trying to achieve exactly ?

I want to get a structured or unstructured (but not using triangulation, and preserving the original grid) version of that VTK file written as “POLYDATA DATASET”.
To make things simple, I will try to give a very minimal example:

Suppose that I have grid: my_domain.vtk that looks like:
mesh_domain
But this file my_domain.vtk contains: the following at the header:

....
....
DATASET POLYDATA
...

My question is how to convert this file to a structured grid (or at least unstructured if tha makes sense but keeping the grid intact) not a polydata.

Most of the tools I use expect the VTK file to be either in STRUCTURED_GRD or UNSTRUCTURED_GRD but not POLYDATA.

Thanks

If you just want to convert a poly data to an unstructured grid, you can load the data in ParaView and run the Clean to Grid filter. You can then write it back out as an unstructured grid.

If you want to be able to edit your .vtk file outside of ParaView (or just know more about the file format), you can get the documentation for the legacy VTK file format here: https://vtk.org/wp-content/uploads/2015/04/file-formats.pdf

I agree that your data could probably be represented in a structured (curvilinear) grid. However, there is no method to do a simple conversion from poly data to structured grid because most of the time the conversion is ill-formed. It would probably be possible to write some custom code to convert this data to a structured grid, but you’re much better off writing the data as a structured grid in the first place.

1 Like

Thank you very much for your reply. Now, at least I know how to convert from POLYDATA to UNSTRUCTURED_GRID.

The reason I am having my original file in POLYDATA is that the tool I am using to get the mesh file can output only as POLYDATA.

Now, according to your answer, I think there is no solution but to write my own script that will do the job.

Thank you

Hello,

Here is a little update to this post:

I was also looking for a “polydata to unstructered grid conversion” but I wanted to do it inside a Python-based programmable filter. The “Clean to Grid” filter uses the “vtkmCleanGrid” class but it is actually difficult to find an example of how to implement it in a python programmable filter. So, here is the example (works fine in ParaView 5.10.0):

import vtk
input = self.GetInputDataObject(0, 0)

clean = vtk.vtkmCleanGrid()
clean.SetInputData(input)
clean.Update()
self.GetOutput().ShallowCopy(clean.GetOutput())

Note: VTK-m does not currently support mixed cell types or triangle strips in vtkPolyData.