<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">&lt;<a href="mailto:roman.grothausmann@helmholtz-berlin.de" target="_blank">roman.grothausmann@helmholtz-berlin.de</a>&gt;</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&#39;ve experienced the same problem, and thanks to David I&#39;ve now a more clear understanding when this happens. So far I&#39;ve only checked if the mesh is closed. I will add a check with tolerance &gt;0.<br>
With colleagues I&#39;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&#39;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 &lt;itkImage.h&gt;<br>
//#include &lt;itkQuadEdgeMesh.h&gt;<br>
#include &lt;itkVTKPolyDataReader.h&gt; //can only read ASCII legacy VTK-files containing only triangles!!!<br>
#include &lt;<u></u>itkTriangleMeshToBinaryImageFi<u></u>lter.h&gt;<br>
#include &lt;itkImageFileWriter.h&gt;<br>
#include &quot;itkFilterWatcher2.h&quot;<br>
<br>
<br>
int main( int argc, char *argv[] ){<br>
<br>
<br>
  Â  if( argc != 9 )<br>
  Â  Â  Â  {<br>
  Â  Â  Â  std::cerr &lt;&lt; &quot;Usage: &quot; &lt;&lt; argv[0];<br>
  Â  Â  Â  std::cerr &lt;&lt; &quot; input_VTKpolydata-mesh&quot;;<br>
  Â  Â  Â  std::cerr &lt;&lt; &quot; outputImage&quot;;<br>
  Â  Â  Â  std::cerr &lt;&lt; &quot; dx dy dz ox oy oz&quot;;<br>
  Â  Â  Â  std::cerr &lt;&lt; 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&lt;<u></u>double, 3, 3,double,double&gt; TriangleMeshTraits;<br>
  Â  //typedef itk::Mesh&lt;double,3, TriangleMeshTraits&gt; TriangleMeshType;<br>
<br>
  Â  //typedef itk::QuadEdgeMesh&lt; float, Dimension &gt; Â  MeshType;<br>
<br>
  Â  typedef itk::Mesh&lt; double, 3 &gt; MeshType;<br>
<br>
  Â  typedef itk::Image&lt; PixelType, Dimension &gt; Â  Â  Â  ImageType;<br>
<br>
<br>
  Â  typedef itk::VTKPolyDataReader&lt;<u></u>MeshType&gt; VTKmeshreaderType;<br>
<br>
<br>
  Â  VTKmeshreaderType::Pointer meshReader = VTKmeshreaderType::New();<br>
  Â  meshReader-&gt;SetFileName(argv[<u></u>1]);<br>
<br>
  Â  std::cout &lt;&lt; &quot;Reading: &quot; &lt;&lt; argv[1] &lt;&lt; std::endl;<br>
  Â  try<br>
  Â  Â  Â  {<br>
  Â  Â  Â  meshReader-&gt;Update();<br>
  Â  Â  Â  }<br>
  Â  catch( itk::ExceptionObject &amp; excp )<br>
  Â  Â  Â  {<br>
  Â  Â  Â  std::cerr &lt;&lt; &quot;Exception: &quot; &lt;&lt; excp &lt;&lt; std::endl;<br>
  Â  Â  Â  return EXIT_FAILURE;<br>
  Â  Â  Â  }<br>
<br>
  Â  std::cout &lt;&lt; &quot;Read: &quot; &lt;&lt; argv[1] &lt;&lt; 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-&gt;SetRegions(size);<br>
  Â  output-&gt;SetSpacing(spacing);<br>
  Â  output-&gt;SetOrigin(origin);<br>
  Â  //output-&gt;SetRegions(<u></u>meshReader-&gt;GetOutput()-&gt;<u></u>GetRequestedRegion());<br>
  Â  output-&gt;Allocate();<br>
<br>
  Â  std::cout &lt;&lt; &quot;Image allocated!&quot; &lt;&lt; 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&lt;MeshType, ImageType&gt; MeshFilterType;<br>
  Â  MeshFilterType::Pointer meshFilter = MeshFilterType::New();<br>
<br>
  Â  meshFilter-&gt;SetInput(<u></u>meshReader-&gt;GetOutput());<br>
  Â  meshFilter-&gt;SetInfoImage(<u></u>output); //<br>
  Â  meshFilter-&gt;SetTolerance (1.0);<br>
  Â  //meshFilter-&gt;SetSize (size);<br>
  Â  //meshFilter-&gt;SetSpacing (spacing);<br>
  Â  //meshFilter-&gt;SetOrigin(<u></u>origin);<br>
  Â  //meshFilter-&gt;SetIndex (index);<br>
  Â  //meshFilter-&gt;<u></u>SetUseObjectValue( true );<br>
  Â  meshFilter-&gt;SetInsideValue(<u></u>fill);<br>
  Â  meshFilter-&gt;SetOutsideValue(<u></u>empty);<br>
  Â  FilterWatcher watcher(meshFilter, &quot;filter&quot;);<br>
  Â  meshFilter-&gt;Update();<br>
<br>
  Â  // Write the image<br>
  Â  typedef itk::ImageFileWriter&lt; ImageType &gt; Â  Â  WriterType;<br>
  Â  WriterType::Pointer writer = WriterType::New();<br>
<br>
  Â  writer-&gt;SetFileName(argv[2]);<br>
  Â  writer-&gt;SetInput(meshFilter-&gt;<u></u>GetOutput());<br>
  Â  try<br>
  Â  Â  Â  {<br>
  Â  Â  Â  meshFilter-&gt;Update();<br>
  Â  Â  Â  writer-&gt;Update();<br>
  Â  Â  Â  }<br>
  Â  catch( itk::ExceptionObject &amp; excp )<br>
  Â  Â  Â  {<br>
  Â  Â  Â  std::cerr &lt;&lt; excp &lt;&lt; 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-&gt;SetInputConnection(<u></u>yourdata-&gt;GetOutputPort());<br>
edges-&gt;FeatureEdgesOff();<br>
edges-&gt;NonManifoldEdgesOn();<br>
edges-&gt;BoundaryEdgesOn();<br>
edges-&gt;Update();<br>
cout &lt;&lt; edges-&gt;GetOutput()-&gt;<u></u>GetNumberOfCells() &lt;&lt; endl;<br>
<br>
It should print &quot;0&quot; 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 &lt;<a href="mailto:vianamp@gmail.com" target="_blank">vianamp@gmail.com</a>&gt; 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&#39;ve a polydata and I&#39;d like to voxelize that in order to obtain an<br>
ImageData. In order to do so, I&#39;m using the following code:<br>
<br>
  vtkImageData *blankImage = vtkImageData::New();<br>
  blankImage -&gt; SetExtent(extent);<br>
  blankImage -&gt; SetOrigin(0,0,0);<br>
  blankImage -&gt; SetSpacing(1,1,1);<br>
  blankImage -&gt; SetScalarTypeToUnsignedChar();<br>
  blankImage -&gt; AllocateScalars();<br>
<br>
  vtkPolyDataToImageStencil *pol2Stenc = vtkPolyDataToImageStencil::<u></u>New();<br>
  pol2Stenc -&gt; SetTolerance(0.5);<br>
  pol2Stenc -&gt; SetInput(myPolyData);<br>
  pol2Stenc -&gt; SetInformationInput(<u></u>blankImage);<br>
  pol2Stenc -&gt; Update();<br>
<br>
  vtkImageStencil *stencil = vtkImageStencil::New();<br>
  stencil -&gt; SetInput(blankImage);<br>
  stencil -&gt; ReverseStencilOff();<br>
  stencil -&gt; SetStencil(pol2Stenc-&gt;<u></u>GetOutput());<br>
  stencil -&gt; Update();<br>
  vtkImageData *image = stencil -&gt; GetOutput();<br>
<br>
It does the job, but I&#39;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>