contour interpolation/resampling

I’m completely new to vtk so bear with me if what I ask turns out to be incredibly easy for the expert user. Believe me, I’ve searched everywhere but I can’t find a way to do what I need. So here’s my problem:

I have a mesh, and I need to extract contours cutting it with planes at regular intervals. I’m using vtkCutter + vtkStripper + vtkCleanPolyData to obtain a list of points. So far so good, however I need these contours to be resampled/interpolated so that each contour is returned as a fixed number of points, equally spaced. Is there a way to do this in vtk: options to set on vtkCutter, other filters that I can add?

I also have another question: on some meshes the contours run clockwise, on others counter-clockwise, why? Of course I’m using the same planes, always oriented in the direction of the positive X axis.


my code:

vtkSmartPointer intersection(vtkPlane& plane, vtkSmartPointer polydata) {
auto cutter = vtkSmartPointer::New();

auto cutStripper = vtkSmartPointer<vtkStripper>::New();

auto cleanPolyData = vtkSmartPointer<vtkCleanPolyData>::New();

vtkSmartPointer<vtkPolyData> contour = cleanPolyData->GetOutput();
return contour;


I don’t think there is a polyline resampling filter in VTK. You can take ResamplePoints function from 3D Slicer (it only uses VTK).

You find and append line segments in random order, so polygon winding is random. It would require extra computation to determine winding and reverse the list of point indices, so it is not done in the cutter or stripper. If you don’t find a method in VTK for getting winding of a polygon then do a web search, you’ll find many implementations.

Look at this example FitSplineToCutterOutput from the VTKExamplesProject.

Thank you both for the useful info. @lorensen, I’m trying to make that example work for me, and failing. All the examples are geared towards rendering, with mapper and actor, but what I need is points, sampled from the spline at regular intervals. I have tried this code, but the resulting contour has 0 points:

auto spline = vtkSmartPointer<vtkKochanekSpline>::New();
auto sf = vtkSmartPointer<vtkSplineFilter>::New();
auto contour = vtkSmartPointer<vtkPolyData>::New();
auto nl = contour->GetNumberOfLines();  // -> 0
auto np = contour->GetNumberOfPoints();  // -> 0
auto npi = contour->GetNumberOfPieces();  // -> 1
auto nv = contour->GetNumberOfVerts();  // -> 0

My problem is that I still don’t get how vtk works, I’m just copying the examples and hoping it works…
If I can’t get my points using vtk calls, I’m thinking of doing linear interpolation of the points from cutStripper or cleanPolyData, but I imagine whatever I can come up with will be less efficient.

VTK is a demand-driven pipeline. See: Visualization Pipeline.

That said, just do a
and you should see the data you are asking for.

For future reference, the entire VTK Text Book is available in two forms:

Enjoy VTK,


…d’oh! It wasn’t in the example, but I should’ve realized it was necessary. Thanks Bill.

I still have a couple of problems:

  • more than 50 points per spline, the number is always 1 + n*(50+1)
  • some points are overlapping and not equally spaced

My feeling is that the problem is the previous steps: vtkStripper + vtkCleanPolyData are generating the points in more than one section, with overlappings. I guess I have to do myself the unwinding as @lassoan was suggesting.

Just a final comment about my remaining issues:

  • multiple lines from vtkStripper: for whatever reason vtkStripper was always returning one good line, containing the expected contour, plus a couple of spurious bits containing 1-3 points each. The simple solution is to just keep the longest line.
  • some contours are clockwise, some anti-clockwise: it just happens, even within the same mesh. If the direction is important, just check afterwards and reverse if necessary.