[vtkusers] vtkPolyDataToImageStencil

Frank Gao gao at mdimaging.com
Wed May 23 15:25:39 EDT 2007


Hi David, All,

It works well for me, but would you please shed some light on a problem I am
having with both old and new versions?

What I am trying to do is to draw a closed profile and use it to cut a 3D
image. I have a closed spline on a plane, extrude it in the normal direction
by vtkLinearExtrusionFilter with capping on. (Unfortunately, this extrusion
filter does not generate capping surfaces for this case.) Then I use
vtkPolyDataToImageStencil to convert the extruded vtkPolyData into image
stencil like a cookie cutter, and use vtkImageStencil to cut the dataset.
What I expected here is vtkPolyDataToImageStencil can give me a volume, so
that I can get the inside or outside part of my dataset by vtkImageStencil.

This works very well except when the spline is on YZ plane and the extrude
direction is X axis, where I only get points on the surface instead of a
volume. Does this have anything to do with the raterization algorithm in
vtkPolyDataToImageStencil? If vtkPolyDataToImageStencil raterizes the
extrusion along X Axis, I do not get a volume?

Your help is greatly appreciated!

Thanks,

Frank

-----Original Message-----
From: David Gobbi [mailto:dgobbi at atamai.com]
Sent: Tuesday, May 22, 2007 5:09 PM
To: gao at mdimaging.com
Cc: Vtkusers at Vtk.Org
Subject: Re: [vtkusers] Possible Bug in vtkPolyDataToImageStencil

Hi Frank,

Sure thing.   Let me know how it works for you.

 - David



Frank Gao wrote:
> Hi David,
>
> I am using vtkPolyDataToImageStencil, and saw an earlier email thread as
below.
>
> Most of the time I am getting good results but have same issue as Jesus.
Would it be possible for you to send me a copy of another
vtkPolyDataToImageStencil class you mentioned in your post?
>
> Thanks in advance,
>
> Frank Gao
>
>
>
> Hi Jesus,
>
> The vtkPolyDataToImageStencil does use a scanline approach, and the way
> it works is that it uses vtkOBBTree to find out where the scanline
> intersects the polydata.  Let's just say that this isn't the best way to
> rasterize a polydata, and it doesn't work very well with sharp points.
> I'm the original author of the class, so I take responsibility for its
> less-than-robust implementation.
>
> My company has another vtkPolyDataToImageStencil class that uses a
> different algorithm, I will send it to you so that you can try it out.
> It is definitely more robust than the current VTK one.
>
>  - David
>
>
> Jesús Spínola wrote:
> >/ Hello,///
> >//
> >/ 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 ( http://hades.udg.es/~chus/images.tar.bz2
<http://hades.udg.es/%7Echus/images.tar.bz2> ///
> >/ <http://hades.udg.es/%7Echus/images.tar.bz2> )///
> >//
> >/ 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 ).///
> >//
> >/ 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.///
> >//
> >/ The original dicom images i used for this examples are: ///
> >/
http://www.creatis.insa-lyon.fr/~jpr/PUBLIC/gdcm/gdcmSampleData/imgdisplay_t
estcases/dish_p05.dcm
<http://www.creatis.insa-lyon.fr/%7Ejpr/PUBLIC/gdcm/gdcmSampleData/imgdispla
y_testcases/dish_p05.dcm> ///
> >/
<http://www.creatis.insa-lyon.fr/%7Ejpr/PUBLIC/gdcm/gdcmSampleData/imgdispla
y_testcases/dish_p05.dcm> ///
> >/ for the hexahedron and ///
> >/
http://www.creatis.insa-lyon.fr/~jpr/PUBLIC/gdcm/gdcmSampleData/imgdisplay_t
estcases/dish_p09.dcm
<http://www.creatis.insa-lyon.fr/%7Ejpr/PUBLIC/gdcm/gdcmSampleData/imgdispla
y_testcases/dish_p09.dcm> ///
> >/
<http://www.creatis.insa-lyon.fr/%7Ejpr/PUBLIC/gdcm/gdcmSampleData/imgdispla
y_testcases/dish_p09.dcm> ///
> >/ for the star shape.///
> >//
> >/ The coordinates for the star shape ( refering to pixels coordinates,
///
> >/ where 1,1 is the first pixel ) are///
> >/ (133, 257)///
> >/ (199, 233)///
> >/ (169, 169)///
> >/ (233, 199)///
> >/ (257, 133)///
> >/ (281, 199)///
> >/ (345, 169)///
> >/ (315, 233)///
> >/ (381, 257)///
> >/ (315, 281)///
> >/ (345, 345)///
> >/ (281, 315)///
> >/ (257, 381)///
> >/ (233, 315)///
> >/ (169, 345)///
> >/ (199, 281)///
> >//
> >/ My code looks like this ( it's the same for the hexahedron and for the
///
> >/ star shape )///
> >//
> >/ int vertices = getNumberOfVerticesOfThePolygon();///
> >/ vtkPoints *points = vtkPoints::New();///
> >/ vtkCellArray *vertexs = vtkCellArray::New();///
> >/ vertexs->InsertNextCell( vertices + 1 );///
> >/ int polyX, polyY;///
> >/ double x, y;///
> >/ for( int i = 0; i < vertices; i++ )///
> >/ {///
> >/       getPolygonVertex( i, polyX, polyY ) )///
> >/      ///
> >/       // to transform the pixel coordinates to world points
coordinates///
> >/       x = origin[0] + (polyX-1.0)*spacing[0];///
> >/       y = origin[1] + ( polyY-1.0)*spacing[1];///
> >//
> >/       points->InsertPoint( i , x, y, 0.0 );///
> >/       vertexs->InsertCellPoint( i );///
> >/ }///
> >/ // to close the polygon///
> >/ vertexs->InsertCellPoint( 0 );///
> >/ vtkPolyData *polyData = vtkPolyData::New();///
> >/ polyData->SetPoints( points );///
> >/ polyData->SetLines( vertexs );///
> >//
> >/ vtkLinearExtrusionFilter *extruder =
vtkLinearExtrusionFilter::New();///
> >/ extruder->SetScaleFactor(1);///
> >/ extruder->SetExtrusionTypeToNormalExtrusion();///
> >/ extruder->SetVector( 0 , 0 , 1 );///
> >/ extruder->SetInput( polyData );///
> >//
> >/ m_polygonalPolyDataStencil = vtkPolyDataToImageStencil::New();///
> >/ m_polygonalPolyDataStencil->SetInput( extruder->GetOutput() );///
> >/ extruder->Delete();///
> >//
> >/ stencil = vtkImageStencil::New();///
> >/ stencil->SetInput( m_imageData ); // m_imageData is of type ///
> >/ vtkImageData, contains the original dicom dataset///
> >/ stencil->ReverseStencilOn();///
> >/ stencil->SetBackgroundValue( m_backgroundValue );///
> >/ stencil->SetStencil( m_rectangularPolyDataStencil->GetOutput() );///
> >/ ....///
> >//
> >/ m_imageViewer->SetInput( stencil->GetOutput() ); // m_imageViewer is
///
> >/ of type vtkImageViewer2///
> >//
> >/ 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.///
> >//
> >/ 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.///
> >//
> >/ Thanks in advance!///
>
>/ ------------------------------------------------------------------------/
//
> >//
> >/ _______________________________________________///
> >/ This is the private VTK discussion list. ///
> >/ Please keep messages on-topic. Check the FAQ at:
http://www.vtk.org/Wiki/VTK_FAQ///
> >/ Follow this link to subscribe/unsubscribe:///
> >/ http://www.vtk.org/mailman/listinfo/vtkusers///
> >/   ///
>
> ------------------------------------------------------------------------
>
>     * Previous message: [vtkusers] Possible Bug in
>       vtkPolyDataToImageStencil
>
<http://public.kitware.com/pipermail/vtkusers/2007-March/090179.html>
>     * Next message: [vtkusers]
>       vtkTrivialProducer/vtkXMLImageDataReader question
>
<http://public.kitware.com/pipermail/vtkusers/2007-March/090175.html>
>     * *Messages sorted by:* [ date ]
>
<http://public.kitware.com/pipermail/vtkusers/2007-March/date.html#90180>
>       [ thread ]
>
<http://public.kitware.com/pipermail/vtkusers/2007-March/thread.html#90180>
>       [ subject ]
>
<http://public.kitware.com/pipermail/vtkusers/2007-March/subject.html#90180>
>       [ author ]
>
<http://public.kitware.com/pipermail/vtkusers/2007-March/author.html#90180>
>
>
> ------------------------------------------------------------------------
>
> More information about the vtkusers mailing list
> <http://www.vtk.org/mailman/listinfo/vtkusers>
>

--
Internal Virus Database is out-of-date.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 268.18.26/748 - Release Date: 4/5/2007
3:33 PM

--
Internal Virus Database is out-of-date.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 268.18.26/748 - Release Date: 4/5/2007
3:33 PM





More information about the vtkusers mailing list