[vtkusers] Problem with vtkPolyDataToImageStencil

David Gobbi david.gobbi at gmail.com
Thu Jul 26 18:53:45 EDT 2012


Hi Matheus,

The vtkPolyDataToImageStencil filter is known to produce streaks like
those under these conditions:
1) if the input data has free edges or is non-manifold
2) if the distance between points is small enough that it approaches
   the numerical tolerance of 32-bit floats

You can check the first condition with vtkFeatureEdges, using the
following code:

vtkFeatureEdges *edges = vtkFeatureEdges::New();
edges->SetInputConnection(yourdata->GetOutputPort());
edges->FeatureEdgesOff();
edges->NonManifoldEdgesOn();
edges->BoundaryEdgesOn();
edges->Update();
cout << edges->GetOutput()->GetNumberOfCells() << endl;

It should print "0" if your data is nice, well-defined closed surface.

You can check the second condition with vtkCleanPolyData.  If your
polydata is changed by vtkCleanPolyData when the tolerance is set to
1e-7, then vtkPolyDataToImageStencil might give incorrect results due
to roundoff error.

I have plans to improve the vtkPolyDataToImageStencil code to make
it more robust, but it will be several months (at least) before it rises
to the top of my to-do list.

 - David


On Thu, Jul 26, 2012 at 3:32 PM, matheus_viana <vianamp at gmail.com> wrote:
> Hello guys.
>
> I've a polydata and I'd like to voxelize that in order to obtain an
> ImageData. In order to do so, I'm using the following code:
>
>  vtkImageData *blankImage = vtkImageData::New();
>  blankImage -> SetExtent(extent);
>  blankImage -> SetOrigin(0,0,0);
>  blankImage -> SetSpacing(1,1,1);
>  blankImage -> SetScalarTypeToUnsignedChar();
>  blankImage -> AllocateScalars();
>
>  vtkPolyDataToImageStencil *pol2Stenc = vtkPolyDataToImageStencil::New();
>  pol2Stenc -> SetTolerance(0.5);
>  pol2Stenc -> SetInput(myPolyData);
>  pol2Stenc -> SetInformationInput(blankImage);
>  pol2Stenc -> Update();
>
>  vtkImageStencil *stencil = vtkImageStencil::New();
>  stencil -> SetInput(blankImage);
>  stencil -> ReverseStencilOff();
>  stencil -> SetStencil(pol2Stenc->GetOutput());
>  stencil -> Update();
>  vtkImageData *image = stencil -> GetOutput();
>
> It does the job, but I've observed some artifacts in the final image, as can
> be seen in the attached picture.
>
> Dos anyone have any idea about how to solve this problem? Is that a bug? Or
> am I doing any stupid thing?
>
> Cheers
> Matheus
>
> http://vtk.1045678.n5.nabble.com/file/n5714947/Viana-vtkPolyDataToImageStencil.jpg
>
>
>
> --
> View this message in context: http://vtk.1045678.n5.nabble.com/Problem-with-vtkPolyDataToImageStencil-tp5714947.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers



More information about the vtkusers mailing list