Hello,<br><br>I&#39;m using the vtkPolyDataToImageStencil class to cut
parts of a dataset. It works fine for several polygons but I have a
case with a star-shaped polygon with a strange result. I&#39;ve attached
several images with the resuts ( <a href="http://hades.udg.es/~chus/images.tar.bz2">http://hades.udg.es/~chus/images.tar.bz2</a> )<br><br>For example, when I make the stencil with an hexahedron the
result is ok ( see noStencilHexahedron.png and stencilHexahedron.png,
that&#39;s before cutting and after cutting with the stencil, respectively
).<br><br>
But when constructing another kind of polygon I get a strange result.
First I thought the coordinates I was giving were wrong, so I created
and actor with the same polydata to see if it was wrong, but the actor
is rendered as I expected, so the polydata is ok. You can see the
original image before cutting is noStencilstarShape.png. After cutting
with the stencil I get stencilOnlyStarShape.png. Then you can see the
polygon created for the stencil in this image
stencilWithPolyDataStarShape.png.<br><br>The original dicom images i used for this examples are: 
<a href="http://www.creatis.insa-lyon.fr/%7Ejpr/PUBLIC/gdcm/gdcmSampleData/imgdisplay_testcases/dish_p05.dcm" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.creatis.insa-lyon.fr/~jpr/PUBLIC/gdcm/gdcmSampleData/imgdisplay_testcases/dish_p05.dcm
</a> for the hexahedron and 
<a href="http://www.creatis.insa-lyon.fr/%7Ejpr/PUBLIC/gdcm/gdcmSampleData/imgdisplay_testcases/dish_p09.dcm" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.creatis.insa-lyon.fr/~jpr/PUBLIC/gdcm/gdcmSampleData/imgdisplay_testcases/dish_p09.dcm
</a> for the star shape.
<br><br>The coordinates for the star shape ( refering to pixels coordinates, where 1,1 is the first pixel ) are <br>(133, 257) <br>(199, 233)<br>(169, 169)<br>(233, 199)<br>(257, 133)<br>(281, 199)<br>(345, 169)<br>(315, 233)
<br>(381, 257)<br>(315, 281)<br>(345, 345)<br>(281, 315)<br>(257, 381)<br>(233, 315)<br>(169, 345)<br>(199, 281)<br><br>My code looks like this ( it&#39;s the same for the hexahedron and for the star shape )<br><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">int vertices = getNumberOfVerticesOfThePolygon();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">vtkPoints *points = vtkPoints::New();
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">vtkCellArray *vertexs = vtkCellArray::New();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">


vertexs-&gt;InsertNextCell( vertices + 1 );</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">int polyX, polyY;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">
double x, y;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">for( int i = 0; i &lt; vertices; i++ )</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">


{</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getPolygonVertex( i, polyX, polyY ) )</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // to transform the pixel coordinates to world points coordinates</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x = origin[0] + (polyX-1.0)*spacing[0];</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; y = origin[1] + (
polyY-1.0)*spacing[1];</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; points-&gt;InsertPoint( i , x, y, 0.0 );
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vertexs-&gt;InsertCellPoint( i );</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">


}</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">// to close the polygon</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">


vertexs-&gt;InsertCellPoint( 0 );</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">vtkPolyData *polyData = vtkPolyData::New();</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">polyData-&gt;SetPoints( points );</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">polyData-&gt;SetLines( vertexs );
</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">vtkLinearExtrusionFilter *extruder = vtkLinearExtrusionFilter::New();
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">extruder-&gt;SetScaleFactor(1);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">


extruder-&gt;SetExtrusionTypeToNormalExtrusion();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">extruder-&gt;SetVector( 0 , 0 , 1 ); </span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">extruder-&gt;SetInput( polyData );</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">


m_polygonalPolyDataStencil = vtkPolyDataToImageStencil::New();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">m_polygonalPolyDataStencil-&gt;SetInput( extruder-&gt;GetOutput() );
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">extruder-&gt;Delete();</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">stencil = vtkImageStencil::New();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">stencil-&gt;SetInput( m_imageData ); // m_imageData is of type vtkImageData, contains the original dicom dataset
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">stencil-&gt;ReverseStencilOn();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">


stencil-&gt;SetBackgroundValue( m_backgroundValue );</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">stencil-&gt;SetStencil( m_rectangularPolyDataStencil-&gt;GetOutput() );
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">....</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">


m_imageViewer-&gt;SetInput( stencil-&gt;GetOutput() ); // m_imageViewer is of type vtkImageViewer2</span><br><br>I want to know if this is because of an error of my code or if it&#39;s due to some bug in the implicated classes.
<br><br>As a side note, other workmates that are using this class had also problems like this on the sharpen vertexs of the polygons. Maybe it&#39;s because the algorithm is a kind of scanline method and when the same pixel in the polygon is the begin and the end of the region that it encloses the algorithm fails.
<br><br>Thanks in advance!