Hello,<br><br>I'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'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'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'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->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 < 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;"> getPolygonVertex( i, polyX, polyY ) )</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 transform the pixel coordinates to world points coordinates</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> x = origin[0] + (polyX-1.0)*spacing[0];</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> 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;"> points->InsertPoint( i , x, y, 0.0 );
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> vertexs->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->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->SetPoints( points );</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">polyData->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->SetScaleFactor(1);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
extruder->SetExtrusionTypeToNormalExtrusion();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">extruder->SetVector( 0 , 0 , 1 ); </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">extruder->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->SetInput( extruder->GetOutput() );
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">extruder->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->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->ReverseStencilOn();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
stencil->SetBackgroundValue( m_backgroundValue );</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">stencil->SetStencil( m_rectangularPolyDataStencil->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->SetInput( stencil->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'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'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!