# How to convert polydata vtk file to structured grid vtk file

**URL:** https://discourse.paraview.org/t/how-to-convert-polydata-vtk-file-to-structured-grid-vtk-file/4242
**Category:** ParaView Support
**Tags:** vtk
**Created:** [May 3, 2020, 6:23pm UTC](https://discourse.paraview.org/t/how-to-convert-polydata-vtk-file-to-structured-grid-vtk-file/4242 "2020-05-03T18:23:08Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![s1291](https://discourse.paraview.org/user_avatar/discourse.paraview.org/s1291/32/15950_2.png) [@s1291](https://discourse.paraview.org/u/s1291)
#### Post date: [May 3, 2020, 6:23pm UTC](https://discourse.paraview.org/t/how-to-convert-polydata-vtk-file-to-structured-grid-vtk-file/4242/1 "2020-05-03T18:23:08Z")

</div>

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

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [May 4, 2020, 1:25am UTC](https://discourse.paraview.org/t/how-to-convert-polydata-vtk-file-to-structured-grid-vtk-file/4242/2 "2020-05-04T01:25:48Z")

</div>

Filters -\> RessampleToImage.

---

<div class="post-metadata">

### Author: ![s1291](https://discourse.paraview.org/user_avatar/discourse.paraview.org/s1291/32/15950_2.png) [@s1291](https://discourse.paraview.org/u/s1291)
#### Post date: [May 4, 2020, 7:28am UTC](https://discourse.paraview.org/t/how-to-convert-polydata-vtk-file-to-structured-grid-vtk-file/4242/3 "2020-05-04T07:28:37Z")

</div>

Here is my original mesh

![original](https://discourse.paraview.org/uploads/default/original/2X/9/9d93844e974d7bc05d293b4acf0e1cb0dc211660.png)

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

![output](https://discourse.paraview.org/uploads/default/original/2X/4/492400d2404a97c6fb4ab623cb0b2039e00e1524.png)

Unfortunately, that doesn’t work as expected.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [May 4, 2020, 7:55am UTC](https://discourse.paraview.org/t/how-to-convert-polydata-vtk-file-to-structured-grid-vtk-file/4242/4 "2020-05-04T07:55:34Z")

</div>

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 ?

---

<div class="post-metadata">

### Author: ![s1291](https://discourse.paraview.org/user_avatar/discourse.paraview.org/s1291/32/15950_2.png) [@s1291](https://discourse.paraview.org/u/s1291)
#### Post date: [May 4, 2020, 8:30am UTC](https://discourse.paraview.org/t/how-to-convert-polydata-vtk-file-to-structured-grid-vtk-file/4242/5 "2020-05-04T08:30:52Z")

</div>

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](https://discourse.paraview.org/uploads/default/original/2X/b/b916875f4c5d4e6e2e460dbe49b28da1792d60ed.png)  
But this file `my_domain.vtk` contains: the following at the header:

```auto
....
....
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

---

<div class="post-metadata">

### Author: ![Kenneth\_Moreland](https://discourse.paraview.org/user_avatar/discourse.paraview.org/kenneth_moreland/32/15033_2.png) [@Kenneth\_Moreland](https://discourse.paraview.org/u/Kenneth_Moreland)
#### Post date: [May 4, 2020, 2:19pm UTC](https://discourse.paraview.org/t/how-to-convert-polydata-vtk-file-to-structured-grid-vtk-file/4242/6 "2020-05-04T14:19:05Z")

</div>

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](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.

---

<div class="post-metadata">

### Author: ![s1291](https://discourse.paraview.org/user_avatar/discourse.paraview.org/s1291/32/15950_2.png) [@s1291](https://discourse.paraview.org/u/s1291)
#### Post date: [May 4, 2020, 4:10pm UTC](https://discourse.paraview.org/t/how-to-convert-polydata-vtk-file-to-structured-grid-vtk-file/4242/7 "2020-05-04T16:10:11Z")

</div>

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

---

<div class="post-metadata">

### Author: ![MiguelAngelAGUIRRE](https://discourse.paraview.org/user_avatar/discourse.paraview.org/miguelangelaguirre/32/2986_2.png) [@MiguelAngelAGUIRRE](https://discourse.paraview.org/u/MiguelAngelAGUIRRE)
#### Post date: [April 15, 2022, 3:28pm UTC](https://discourse.paraview.org/t/how-to-convert-polydata-vtk-file-to-structured-grid-vtk-file/4242/8 "2022-04-15T15:28:15Z")

</div>

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