# How to convert vtkImageData to vtkPolyData

**URL:** https://discourse.vtk.org/t/how-to-convert-vtkimagedata-to-vtkpolydata/3635
**Category:** Support
**Created:** [June 24, 2020, 6:58pm UTC](https://discourse.vtk.org/t/how-to-convert-vtkimagedata-to-vtkpolydata/3635 "2020-06-24T18:58:20Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![beginner](https://discourse.vtk.org/user_avatar/discourse.vtk.org/beginner/32/1930_2.png) [@beginner](https://discourse.vtk.org/u/beginner)
#### Post date: [June 24, 2020, 6:58pm UTC](https://discourse.vtk.org/t/how-to-convert-vtkimagedata-to-vtkpolydata/3635/1 "2020-06-24T18:58:20Z")

</div>

I’m trying to use the GetPoints method in vtkPolyData to generate a 3D mesh from an image. Currently, I parsed the image as a vtkImageData. How do I convert vtkImageData to vtkPolyData? Or are there any alternative ways to create a mesh?

---

<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: [June 25, 2020, 4:02pm UTC](https://discourse.vtk.org/t/how-to-convert-vtkimagedata-to-vtkpolydata/3635/2 "2020-06-25T16:02:27Z")

</div>

There are different ways to do this, depending on your purpose.

The vtkMarchingCubes filter will extract an isosurface from the image as a polydata mesh. This requires that you know ahead of time what isovalue you want to use.

The vtkGeometryFilter extracts the outer surface (i.e. bounding box) of the image as a polydata mesh.

The vtkProbeFilter will take an existing polydata mesh, and will color the mesh according to the values of the image.

Is any of these what you want?

---

<div class="post-metadata">

### Author: ![beginner](https://discourse.vtk.org/user_avatar/discourse.vtk.org/beginner/32/1930_2.png) [@beginner](https://discourse.vtk.org/u/beginner)
#### Post date: [June 25, 2020, 5:33pm UTC](https://discourse.vtk.org/t/how-to-convert-vtkimagedata-to-vtkpolydata/3635/3 "2020-06-25T17:33:32Z")

</div>

Thanks David!

I think vtkMarchingCubes and vtkGeometryFilter might work. I am very new to vtk so if you don’t mind me asking, how do I determine the isovalue?

---

<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: [June 25, 2020, 6:43pm UTC](https://discourse.vtk.org/t/how-to-convert-vtkimagedata-to-vtkpolydata/3635/4 "2020-06-25T18:43:12Z")

</div>

If you know the lowest value in the image and the highest value in the image, the isovalue that you choose is going to be somewhere in between. You can find a good isovalue by trial-end-error, or you can statistically compute a good isovalue via e.g. Otsu’s method.

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [June 27, 2020, 8:44pm UTC](https://discourse.vtk.org/t/how-to-convert-vtkimagedata-to-vtkpolydata/3635/6 "2020-06-27T20:44:28Z")

</div>

Hello, friend!

Sorry, but why do you want to convert a `vtkImageData` into a `vtkPolyData`? The latter requires explicit geometry (that is, you need to supply vertex coordinates for each corner as well supply the edges and faces definitions) and, therefore, has a way larger footprint. The former has implicit (that is, only the visible parts are calculated on the fly as needed) geometry. `vtkImageData` is preferrable over `vtkPolyData` whenever possible. `vtkPolyData` justifies only if the shape of your cells varies or some filter down the pipline requires one as input.

kind regards,

Paulo

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [June 27, 2020, 9:24pm UTC](https://discourse.vtk.org/t/how-to-convert-vtkimagedata-to-vtkpolydata/3635/8 "2020-06-27T21:24:34Z")

</div>

So, after the casting simulation do you have the xyz coordinates of the particles?

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [June 27, 2020, 9:32pm UTC](https://discourse.vtk.org/t/how-to-convert-vtkimagedata-to-vtkpolydata/3635/9 "2020-06-27T21:32:08Z")

</div>

If you have the xyz locations of the particles, you can make a tetra mesh by using the `vtkDelaunay3D` class: [https://vtk.org/doc/nightly/html/classvtkDelaunay3D.html](https://vtk.org/doc/nightly/html/classvtkDelaunay3D.html) . It uses a point set as input (`vtkPointSet` or any subclass) and outputs a `vtkUnstructuredGrid`. It’s called “unstructured” because the data residing in its cells don’t have an implicit topology like a regular or Cartesian grid.

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [June 28, 2020, 12:29pm UTC](https://discourse.vtk.org/t/how-to-convert-vtkimagedata-to-vtkpolydata/3635/12 "2020-06-28T12:29:16Z")

</div>

Good luck out there.

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [June 28, 2020, 1:25pm UTC](https://discourse.vtk.org/t/how-to-convert-vtkimagedata-to-vtkpolydata/3635/13 "2020-06-28T13:25:54Z")

</div>

I don’t think it’s VTK’s fault. It’s likely your simulation algorithm needs to be smarter. I mean, do not output highly dense points where it is not needed. You only need small cells near edges, around holes or material interfaces. FEM is flexible to work with elements of varying sizes. It’s called adaptive gridding. See example below:  
 ![image](https://discourse.vtk.org/uploads/default/original/2X/f/fb09fec16e8541abc17612107cf28f2508a27bf9.png)

---

<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: [June 28, 2020, 4:30pm UTC](https://discourse.vtk.org/t/how-to-convert-vtkimagedata-to-vtkpolydata/3635/15 "2020-06-28T16:30:18Z")

</div>

Bill, when I read through this discussion, it really looks like Paulo’s original reply was to the original poster, not to your post. Everything after that is a train wreck that I can’t follow.

Paulo, when you reply, please be explicit about who you are replying to.

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [June 28, 2020, 6:31pm UTC](https://discourse.vtk.org/t/how-to-convert-vtkimagedata-to-vtkpolydata/3635/17 "2020-06-28T18:31:18Z")

</div>

Meshing is not actually a nightmare if you know what you’re doing. If VTK’s Delaunay implementation doesn’t suit you, you either help improving it (it’s open source for that purpose); hire a coder to write a custom `vtkDelaunay3D` for you or use something “industrial” like GMSH, CGAL or OpenInventor.

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [June 28, 2020, 6:38pm UTC](https://discourse.vtk.org/t/how-to-convert-vtkimagedata-to-vtkpolydata/3635/18 "2020-06-28T18:38:15Z")

</div>

The notification button at the bottom of the page is at your service.  
 ![image](https://discourse.vtk.org/uploads/default/original/2X/6/672c3fde2e7e0f07cb1995b63944673fff83a03b.png)
