[vtkusers] Solid Voxelization with VTK

Berti Krüger berti_krueger at hotmail.com
Wed Sep 26 03:04:49 EDT 2018


Hi David,

thanks again for your help.

I added the method calls on the normalFilter as you have suggested but it didn't change the wrong voxelization of the Eiffel tower model.

It did indead change the result to something different:

[cid:ea753225-8561-4c0f-a7b0-2bb764dff664]    [cid:a3cf6ebe-b37d-42ec-b0aa-fc502c405607]               [cid:4439e9e1-f381-4580-8b22-005d383ff492]


left image:      result with wrong orientation and without normalsFilter->AutoOrientNormalsOn()
center image: mesh with wrong orientation and normalsFilter->AutoOrientNormalsOn()
right image:   meshlab corrected version


I attached both Eiffel tower models (with the wrong normals / polygon orientation and the corrected meshlab version) if you want to try it yourself.

The vtkStripper is indead unecessary. I tried various meshes with and without using the vtkStripper filter step inbetween and it didn't make any difference. Since i took it from the Slicer3D source code Csaba pointed me to, i don't have any idea why the Slicer Guys use it there. Maybe they have some special kind of polydata where it is needed. For my general purpose meshes it does not seem to make a difference. The processing is, of course, faster without this additional step.

The complete source code for voxelization and visualization and the CMakeList.txt is attached.


The resulting code for the voxelization function:

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
  //
  // The purpose of the vtkPolyDataNormals filter here is to enforce a
  // consistent orientation of the polygons (via the method ConsistencyOn)
  // and to get an automatic determination of the correct orientation of the
  // normals on the polydata surface (via the method AutoOrientNormalsOn).
  //
  // To increase the performance of the filter we turn off the splitting of
  // sharp edges (via the method SplittingOff) since it is not necessary for
  // getting a correct result here.
  //
  // The application of the filter on the polydata is purely optional if all
  // the polygons are already correctly oriented.
  vtkNew<vtkPolyDataNormals> normalFilter;
  normalFilter->SetInputData(closedSurfacePolyData);
  normalFilter->ConsistencyOn();
  normalFilter->AutoOrientNormalsOn();
  normalFilter->SplittingOff();

  // Make sure that we have a clean triangle polydata using the
  // vtkTriangleFilter which generates triangles from input polygons.
  // Only needed if the input polygons are not flat.
  vtkNew<vtkTriangleFilter> triangle;
  triangle->SetInputConnection(normalFilter->GetOutputPort());

  // Convert polydata to stencil
  vtkNew<vtkPolyDataToImageStencil> polyDataToImageStencil;
  polyDataToImageStencil->SetInputConnection(triangle->GetOutputPort());
  polyDataToImageStencil->SetOutputSpacing(binaryLabelMap->GetSpacing());
  polyDataToImageStencil->SetOutputOrigin(binaryLabelMap->GetOrigin());
  polyDataToImageStencil->SetOutputWholeExtent(binaryLabelMap->GetExtent());
  polyDataToImageStencil->Update();

  // Convert stencil to image
  vtkNew<vtkImageStencilToImage> imageStencilToImage;
  imageStencilToImage->SetInputConnection(polyDataToImageStencil->GetOutputPort());
  imageStencilToImage->SetOutsideValue(0);
  imageStencilToImage->SetInsideValue(1);
  imageStencilToImage->SetOutput(binaryLabelMap);
  imageStencilToImage->Update();

  return true;
}


Thanks again for everything.

Cheers,

Berti






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

Hi Berti,

Just a few extra comments about the three "preprocessing" steps that you apply in your sample code:

For vtkPolyDataNormals, you might want to add  normalsFilter->AutoOrientNormalsOn(), since this option is specifically designed to fix inside-out shapes like the Eiffel tower model.  And normalsFilter->SplittingOff() will make this filter work faster.  It would also be good if the comment mentioned that the purpose of the filter is to enforce consistent orientation of the polygons, and that the filter is optional if all the polygons are already correctly oriented.

The vtkStripper should be removed, unless you actually saw that it provides some benefit.  The vtkPolyDataToImageStencil class should give exactly the same results for triangles as for strips.  And vtkTriangleFilter is only needed if the input polygons are not flat.

Thanks again for the code,
 - David


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180926/5a04dfe4/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: eiffel_tower_wrong_orientation.jpg
Type: image/jpeg
Size: 88782 bytes
Desc: eiffel_tower_wrong_orientation.jpg
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180926/5a04dfe4/attachment-0002.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: eiffel_tower_right_orientation.jpg
Type: image/jpeg
Size: 37648 bytes
Desc: eiffel_tower_right_orientation.jpg
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180926/5a04dfe4/attachment-0003.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: eiffel_tower_false.png
Type: image/png
Size: 54477 bytes
Desc: eiffel_tower_false.png
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180926/5a04dfe4/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: eiffel_tower_small.stl
Type: application/sla
Size: 759184 bytes
Desc: eiffel_tower_small.stl
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180926/5a04dfe4/attachment-0002.stl>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: eiffel_tower_small_wrong_orientation.stl
Type: application/sla
Size: 759184 bytes
Desc: eiffel_tower_small_wrong_orientation.stl
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180926/5a04dfe4/attachment-0003.stl>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PolyDataToImageDataVisualizationSTL.cxx
Type: text/x-c++src
Size: 7818 bytes
Desc: PolyDataToImageDataVisualizationSTL.cxx
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180926/5a04dfe4/attachment-0001.cxx>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: CMakeLists.txt
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180926/5a04dfe4/attachment-0001.txt>


More information about the vtkusers mailing list