<font><font face="verdana,sans-serif">I have switched from ITK to VTK voxelizer, due to a bug in <a href="https://issues.itk.org/jira/browse/ITK-2882">ITK</a>.<br></font></font><br><div class="gmail_quote">On Fri, Jul 27, 2012 at 9:52 AM, Roman Grothausmann <span dir="ltr"><<a href="mailto:roman.grothausmann@helmholtz-berlin.de" target="_blank">roman.grothausmann@helmholtz-berlin.de</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello Matheus,<br>
<br>
<br>
I've experienced the same problem, and thanks to David I've now a more clear understanding when this happens. So far I've only checked if the mesh is closed. I will add a check with tolerance >0.<br>
With colleagues I've prepared a blender plug-in based on vtk filters for voxelizing blender meshes. It will be published on Midas as soon as my colleagues have given their OK. Let me know if You'd be interesting in testing the script before.<br>
Otherwise You could try vtkPartialVolumeModeller from Cory Quammen and Taylor II R.M.: <a href="http://www.insight-journal.org/browse/publication/792" target="_blank">http://www.insight-journal.<u></u>org/browse/publication/792</a><br>
Corry is just upgrading the code a bit.<br>
<br>
One other option I know of is to use ITK, which during my testing, was not quicker than the VTK approach with vtkPolyDataToImageStencil. Below is a little test program.<br>
<br>
David: A more robust vtkPolyDataToImageStencil would be really great! Let me know if there is any upgrade to test.<br>
<br>
Happy coding<br>
Roman<br>
<br>
////////program to voxelize a vtk-polydata-mesh into a itk-voxel-image<br>
////////supposingly quicker than pure vtk: <a href="http://www.cmake.org/Wiki/VTK/Examples/PolyDataToImageData" target="_blank">http://www.cmake.org/Wiki/VTK/<u></u>Examples/PolyDataToImageData</a><br>
//allocating image before voxelization<br>
<br>
//#include <itkImage.h><br>
//#include <itkQuadEdgeMesh.h><br>
#include <itkVTKPolyDataReader.h> //can only read ASCII legacy VTK-files containing only triangles!!!<br>
#include <<u></u>itkTriangleMeshToBinaryImageFi<u></u>lter.h><br>
#include <itkImageFileWriter.h><br>
#include "itkFilterWatcher2.h"<br>
<br>
<br>
int main( int argc, char *argv[] ){<br>
<br>
<br>
  if( argc != 9 )<br>
    {<br>
    std::cerr << "Usage: " << argv[0];<br>
    std::cerr << " input_VTKpolydata-mesh";<br>
    std::cerr << " outputImage";<br>
    std::cerr << " dx dy dz ox oy oz";<br>
    std::cerr << std::endl;<br>
    return EXIT_FAILURE;<br>
    }<br>
<br>
<br>
<br>
  typedef unsigned char  PixelType;<br>
  const unsigned int   Dimension = 3;<br>
<br>
  //typedef itk::DefaultDynamicMeshTraits<<u></u>double, 3, 3,double,double> TriangleMeshTraits;<br>
  //typedef itk::Mesh<double,3, TriangleMeshTraits> TriangleMeshType;<br>
<br>
  //typedef itk::QuadEdgeMesh< float, Dimension >  MeshType;<br>
<br>
  typedef itk::Mesh< double, 3 > MeshType;<br>
<br>
  typedef itk::Image< PixelType, Dimension >    ImageType;<br>
<br>
<br>
  typedef itk::VTKPolyDataReader<<u></u>MeshType> VTKmeshreaderType;<br>
<br>
<br>
  VTKmeshreaderType::Pointer meshReader = VTKmeshreaderType::New();<br>
  meshReader->SetFileName(argv[<u></u>1]);<br>
<br>
  std::cout << "Reading: " << argv[1] << std::endl;<br>
  try<br>
    {<br>
    meshReader->Update();<br>
    }<br>
  catch( itk::ExceptionObject & excp )<br>
    {<br>
    std::cerr << "Exception: " << excp << std::endl;<br>
    return EXIT_FAILURE;<br>
    }<br>
<br>
  std::cout << "Read: " << argv[1] << std::endl;<br>
<br>
<br>
  // Set Size, Spacing and origin<br>
  ImageType::SizeType size;<br>
  size[ 0 ] = atoi(argv[3]);<br>
  size[ 1 ] = atoi(argv[4]);<br>
  size[ 2 ] = atoi(argv[5]);<br>
<br>
  ImageType::SpacingType spacing;<br>
  spacing[0] =  1; //100.0 / size[0];<br>
  spacing[1] =  1; //100.0 / size[1];<br>
  spacing[2] =  1; //100.0 / size[2];<br>
<br>
  ImageType::PointType origin;<br>
  origin[0]= atoi(argv[6]);<br>
  origin[1]= atoi(argv[7]);<br>
  origin[2]= atoi(argv[8]);<br>
<br>
  //allocate the output image<br>
  ImageType::Pointer output = ImageType::New();<br>
<br>
  output->SetRegions(size);<br>
  output->SetSpacing(spacing);<br>
  output->SetOrigin(origin);<br>
  //output->SetRegions(<u></u>meshReader->GetOutput()-><u></u>GetRequestedRegion());<br>
  output->Allocate();<br>
<br>
  std::cout << "Image allocated!" << std::endl;<br>
<br>
  //Set Inside/Outside voxel value<br>
  const PixelType empty  = 0;<br>
  const PixelType fill =  255;<br>
<br>
<br>
<br>
  typedef itk::<u></u>TriangleMeshToBinaryImageFilte<u></u>r<MeshType, ImageType> MeshFilterType;<br>
  MeshFilterType::Pointer meshFilter = MeshFilterType::New();<br>
<br>
  meshFilter->SetInput(<u></u>meshReader->GetOutput());<br>
  meshFilter->SetInfoImage(<u></u>output); //<br>
  meshFilter->SetTolerance (1.0);<br>
  //meshFilter->SetSize (size);<br>
  //meshFilter->SetSpacing (spacing);<br>
  //meshFilter->SetOrigin(<u></u>origin);<br>
  //meshFilter->SetIndex (index);<br>
  //meshFilter-><u></u>SetUseObjectValue( true );<br>
  meshFilter->SetInsideValue(<u></u>fill);<br>
  meshFilter->SetOutsideValue(<u></u>empty);<br>
  FilterWatcher watcher(meshFilter, "filter");<br>
  meshFilter->Update();<br>
<br>
  // Write the image<br>
  typedef itk::ImageFileWriter< ImageType >   WriterType;<br>
  WriterType::Pointer writer = WriterType::New();<br>
<br>
  writer->SetFileName(argv[2]);<br>
  writer->SetInput(meshFilter-><u></u>GetOutput());<br>
  try<br>
    {<br>
    meshFilter->Update();<br>
    writer->Update();<br>
    }<br>
  catch( itk::ExceptionObject & excp )<br>
    {<br>
    std::cerr << excp << std::endl;<br>
    return EXIT_FAILURE;<br>
    }<br>
<br>
<br>
  return EXIT_SUCCESS;<div><div class="h5"><br>
  }<br>
<br>
<br>
<br>
On 27.07.2012 00:53, David Gobbi wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Matheus,<br>
<br>
The vtkPolyDataToImageStencil filter is known to produce streaks like<br>
those under these conditions:<br>
1) if the input data has free edges or is non-manifold<br>
2) if the distance between points is small enough that it approaches<br>
  the numerical tolerance of 32-bit floats<br>
<br>
You can check the first condition with vtkFeatureEdges, using the<br>
following code:<br>
<br>
vtkFeatureEdges *edges = vtkFeatureEdges::New();<br>
edges->SetInputConnection(<u></u>yourdata->GetOutputPort());<br>
edges->FeatureEdgesOff();<br>
edges->NonManifoldEdgesOn();<br>
edges->BoundaryEdgesOn();<br>
edges->Update();<br>
cout << edges->GetOutput()-><u></u>GetNumberOfCells() << endl;<br>
<br>
It should print "0" if your data is nice, well-defined closed surface.<br>
<br>
You can check the second condition with vtkCleanPolyData. Â If your<br>
polydata is changed by vtkCleanPolyData when the tolerance is set to<br>
1e-7, then vtkPolyDataToImageStencil might give incorrect results due<br>
to roundoff error.<br>
<br>
I have plans to improve the vtkPolyDataToImageStencil code to make<br>
it more robust, but it will be several months (at least) before it rises<br>
to the top of my to-do list.<br>
<br>
 - David<br>
<br>
<br>
On Thu, Jul 26, 2012 at 3:32 PM, matheus_viana <<a href="mailto:vianamp@gmail.com" target="_blank">vianamp@gmail.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello guys.<br>
<br>
I've a polydata and I'd like to voxelize that in order to obtain an<br>
ImageData. In order to do so, I'm using the following code:<br>
<br>
 vtkImageData *blankImage = vtkImageData::New();<br>
 blankImage -> SetExtent(extent);<br>
 blankImage -> SetOrigin(0,0,0);<br>
 blankImage -> SetSpacing(1,1,1);<br>
 blankImage -> SetScalarTypeToUnsignedChar();<br>
 blankImage -> AllocateScalars();<br>
<br>
 vtkPolyDataToImageStencil *pol2Stenc = vtkPolyDataToImageStencil::<u></u>New();<br>
 pol2Stenc -> SetTolerance(0.5);<br>
 pol2Stenc -> SetInput(myPolyData);<br>
 pol2Stenc -> SetInformationInput(<u></u>blankImage);<br>
 pol2Stenc -> Update();<br>
<br>
 vtkImageStencil *stencil = vtkImageStencil::New();<br>
 stencil -> SetInput(blankImage);<br>
 stencil -> ReverseStencilOff();<br>
 stencil -> SetStencil(pol2Stenc-><u></u>GetOutput());<br>
 stencil -> Update();<br>
 vtkImageData *image = stencil -> GetOutput();<br>
<br>
It does the job, but I've observed some artifacts in the final image, as can<br>
be seen in the attached picture.<br>
<br>
Dos anyone have any idea about how to solve this problem? Is that a bug? Or<br>
am I doing any stupid thing?<br>
<br>
Cheers<br>
Matheus<br>
<br>
<a href="http://vtk.1045678.n5.nabble.com/file/n5714947/Viana-vtkPolyDataToImageStencil.jpg" target="_blank">http://vtk.1045678.n5.nabble.<u></u>com/file/n5714947/Viana-<u></u>vtkPolyDataToImageStencil.jpg</a><br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://vtk.1045678.n5.nabble.com/Problem-with-vtkPolyDataToImageStencil-tp5714947.html" target="_blank">http://vtk.1045678.n5.nabble.<u></u>com/Problem-with-<u></u>vtkPolyDataToImageStencil-<u></u>tp5714947.html</a><br>
Sent from the VTK - Users mailing list archive at Nabble.com.<br>
______________________________<u></u>_________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/<u></u>opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_<u></u>FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/<u></u>listinfo/vtkusers</a><br>
</blockquote>
______________________________<u></u>_________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/<u></u>opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_<u></u>FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/<u></u>listinfo/vtkusers</a><br>
<br>
</blockquote>
<br></div></div>
-- <br>
Roman Grothausmann<br>
<br>
Helmholtz-Zentrum Berlin für Materialien und Energie GmbH<br>
Bereich Funktionale Materialien<br>
Institut für angewandte Materialforschung<br>
Hahn-Meitner-Platz 1<br>
D-14109 Berlin  <br>
<br>
(früher Hahn-Meitner-Institut und BESSY)<br>
<br>
<br>
Tel.: <a href="tel:%2B49-%280%2930-8062-42816" value="+4930806242816" target="_blank">+49-(0)30-8062-42816</a><br>
Fax.: <a href="tel:%2B49-%280%2930-8062-43059" value="+4930806243059" target="_blank">+49-(0)30-8062-43059</a><br>
<br>
Vorsitzender des Aufsichtsrats: Prof. Dr. Dr. h.c. mult. Joachim Treusch<br>
Stellvertretende Vorsitzende: Dr. Beatrix Vierkorn-Rudolph<br>
Geschäftsführer: Prof. Dr. Anke Rita Kaysser-Pyzalla, Dr. Ulrich Breuer<br>
Sitz der Gesellschaft: Berlin<br>
Handelsregister: AG Charlottenburg, 89 HRB 5583<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
<br>
______________________________<u></u>_________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/<u></u>opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_<u></u>FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/<u></u>listinfo/vtkusers</a><br>
</div></div></blockquote></div><br>