[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;
normalFilter->SetInputData(closedSurfacePolyData);
normalFilter->ConsistencyOn();
// Make sure that we have a clean triangle polydata
vtkNew<vtkTriangleFilter> triangle;
triangle->SetInputConnection(normalFilter->GetOutputPort());
// Convert to triangle strip
vtkNew<vtkStripper> stripper;
stripper->SetInputConnection(triangle->GetOutputPort());
// Convert polydata to stencil
vtkNew<vtkPolyDataToImageStencil> polyDataToImageStencil;
polyDataToImageStencil->SetInputConnection(stripper->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;
}
As always i attached the enhanced example code and the CMakeLists.
The result for the voxelization with and without opacity turned on:
[cid:a98f252d-e72d-4809-a32f-404b6d8007b7][cid:cff0c507-5d76-4450-a3dc-3cf160cb50fd]
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:
[cid:1fe1d519-2656-4e2d-899c-7b685f711898]
Maybe there are some small defects (broken normals, wrongly oriented polygons etc.) in the alien queen mesh as well.
Here is a closeup:
[cid:115412aa-d4c4-4377-8e33-5fa96e974b09]
[cid:0d0e1d24-29f9-4f08-8acc-12ee09a34973]
[cid:b5e05242-4131-4648-ab72-72e9f648438c]
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?
Cheers,
Berti
PS:
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