[vtkusers] Fitting a spline to a contour (vtkSplineWidget)

Dean Inglis dean.inglis at camris.ca
Thu Apr 5 09:45:04 EDT 2007


Hi Jon,

I have written a class that "bug walks" around the edge of a binary
mask that will extract the points in sequence around the object's
perimeter.  The points form a closed sequence of straight line segments
that can easily be passed to vtkSplineWidget's
IntitializeHandles(vtkPoints*)
method.  If you call SetResolution(points->GetNumberOfPoints()-1),
you instruct the widget to form straight line segments between
the points.  A better class for doing this is
vtkOrientedGlyphContourRepresentation
as it is much more efficient for manipulating the potentially large
number of "handles" that your contour representation could have.
AFAIK, the inverse problem you are describing cannot be directly done with
any of vtk's spline classes: you have more points than the number
of control points you are requesting. That is, you pass all the
points to a spline and it will fit a spline to all of them, one control
point
per point.  Although I haven't tried this, you could look at
vtkAmoebaMinimizer
which would allow you to write your own cost function to measure a spline's
fit to
a set of points.

Dean


I am attempting to convert a contour (mask or distance map) to a
vtksplinewidget.  Short of adding every pixel of the contour as a control
point, I can not seem to figure out how to map the spline onto the contour.
Is there a way to down sample the spline's control points or perhaps
interpolate the spline from polydata?  Any guidance would be much
appreciated.



More information about the vtkusers mailing list