How to convert vtkImageData to vtkPolyData

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?

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?

1 Like

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?

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.

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,


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

If you have the xyz locations of the particles, you can make a tetra mesh by using the vtkDelaunay3D class: . 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.

Good luck out there.

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:

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.

1 Like

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.

The notification button at the bottom of the page is at your service.