[vtkusers] Solid Voxelization with VTK

Berti Krüger berti_krueger at hotmail.com
Tue Sep 25 04:41:41 EDT 2018

Hi David,

thank you very much again for the hints.

As you said, i removed the initialization code for the binaryLabelMap and replaced the DeepCopy with a call to imageStencilToImage->SetOutput and it works perfectly!

The resulting code for the whole polygon mesh voxelization from this code review iteration is now simply:

bool ConvertPolyDataToBinaryLabelMap(vtkSmartPointer<vtkPolyData> closedSurfacePolyData,
                                     vtkSmartPointer<vtkImageData> binaryLabelMap)
  // Check for consistency
  if (closedSurfacePolyData->GetNumberOfPoints() < 2 || closedSurfacePolyData->GetNumberOfCells() < 2)
    std::cout << "Convert: Cannot create binary labelmap from surface with number of points: "
        << closedSurfacePolyData->GetNumberOfPoints() << " and number of cells: "
        << closedSurfacePolyData->GetNumberOfCells() << std::endl;

      return false;

  // Compute polydata normals
  vtkNew<vtkPolyDataNormals> normalFilter;

  // Make sure that we have a clean triangle polydata
  vtkNew<vtkTriangleFilter> triangle;

  // Convert to triangle strip
  vtkNew<vtkStripper> stripper;

  // Convert polydata to stencil
  vtkNew<vtkPolyDataToImageStencil> polyDataToImageStencil;

  // Convert stencil to image
  vtkNew<vtkImageStencilToImage> imageStencilToImage;

  return true;

As always i attached the enhanced example code and the CMakeLists.

The result for the voxelization with and without opacity turned on:


And yes you were right with the Eiffel tower mesh!

I reoriented the polygon orientation / normals (but with meshlab not vtk) and now the voxelization code above also works with the Eiffel tower:


Maybe there are some small defects (broken normals, wrongly oriented polygons etc.) in the alien queen mesh as well.

Here is a closeup:



It could be that these small dark polygons at the backside of the nails of the claw are dark because their normals are broken or wrongly oriented.

Could that lead to the strange voxelization result above?




Bill if you think this example could be of any use for other vtk users, then please feel free to add / modify / enhance / rip it apart / put it in the vtk github example repository. Personally i think vtk can not have enough examples. They are always life savers.

Von: David Gobbi <david.gobbi at gmail.com>
Gesendet: Montag, 24. September 2018 04:09
An: Berti Krüger
Cc: Csaba Pinter; VTK Users; Bill Lorensen
Betreff: Re: [vtkusers] Solid Voxelization with VTK

Hi Berti,

You don't even have to initialize binaryLabelMap, since you don't use it as an input for anything until the DeepCopy.  Really the DeepCopy isn't necessary either, you could call imageStencilToImage->SetOutput(binaryLabelMap) before calling imageStencilToImage->Update().

Thanks for the samples, those results are very interesting.  Because of the way the algorithm works, the Z axis is immune to those bridges in the result, so you are correct that majority voting or a logical "and" might clean it up.  For the Eiffel tower, the polygons might be wound the wrong way (i.e. the shape is inside-out).  You could try applying vtkReverseSense.

 - David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180925/037893d9/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: skull2.jpg
Type: image/jpeg
Size: 64281 bytes
Desc: skull2.jpg
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180925/037893d9/attachment-0004.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: skull1.png
Type: image/png
Size: 281975 bytes
Desc: skull1.png
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180925/037893d9/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: eiffel_tower_correct.png
Type: image/png
Size: 80360 bytes
Desc: eiffel_tower_correct.png
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180925/037893d9/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: alienqueen_voxelization.jpg
Type: image/jpeg
Size: 65454 bytes
Desc: alienqueen_voxelization.jpg
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180925/037893d9/attachment-0005.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: queen_close1.jpg
Type: image/jpeg
Size: 132745 bytes
Desc: queen_close1.jpg
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180925/037893d9/attachment-0006.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: queen_close2.jpg
Type: image/jpeg
Size: 28658 bytes
Desc: queen_close2.jpg
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180925/037893d9/attachment-0007.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PolyDataToImageDataVisualizationSTL.cxx
Type: text/x-c++src
Size: 7101 bytes
Desc: PolyDataToImageDataVisualizationSTL.cxx
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180925/037893d9/attachment-0001.cxx>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: CMakeLists.txt
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180925/037893d9/attachment-0001.txt>

More information about the vtkusers mailing list