[vtkusers] Filling a polygon in ImageData

kent williams nkwmailinglists at gmail.com
Sun Dec 16 13:35:03 EST 2007


Method 2 sounds like the ticket. I wasn't aware that there was such a
method.  Sometimes Doxygen man pages make it hard to see the trees for
the forest.  It would also be great if people were more diligent about
internally documenting their code so that the Doxygen pages would be
more useful!

I will look at what's involved in writing this as a vtk filter.  My
natural inclination is to just write a function that takes a list of
the polydata that my 3D Contour tracer generates, and return a binary
image giving the mask described by the contours.

I'm actually saving and restoring the control points of the contour,
which means that I will have to instantiate a
vtkContourRepresentation, push in the control points, and then call
vtkContourRepresentation::GetContourRepresentationAsPolyData() to get
a polygon approximating the spline path around the contour.  That was
actually the function I called to get the control points the first
time through, until I noticed that it  was returning a lot more points
beyond the control points I'd picked!

Then there's the issue that what I get from the
vtkContourRepresentation is a vtkCellArray, and not a vtkPolygon.  I
can see how to instantiate a vtkPolygon and add vertices from the
points in the vtkPolyData, but it seems like that transformation
should already be in VTK.  My last experience with trying to navigate
through the vtkCell data structures didn't end well, for reasons I
never figured out.

On Dec 15, 2007 10:49 AM, Karthik Krishnan <karthik.krishnan at kitware.com> wrote:
> 2.  vtkPolygon::PointInPolygon will do the job for you...
>
> Just get the bounds of the closed polyline. For every pixel in your image
> that lies within those bounds, check if its world coordinates are within the
> Polygon and you are done.
>
> The method is very fast. It just checks the number of times a ray starting
> at the point intersects the polygon. If it intersects it, even number of
> times, it is outside, odd implies inside. In reality, it throws a bunch of
> rays in different directions, and does a voting, to overcome numerical
> issues that might arize when one or more rays fall exactly on an edge of the
> polygon.
>
>
> PS: If you choose to use method (2), It would be great if you could wrap it
> into a VTK filter (deriving from vtkImageAlgorithm) and contribite it :)
>



More information about the vtkusers mailing list