[vtkusers] Problem with vtkContourTriangulator and vtkPlaneCutter

David Gobbi david.gobbi at gmail.com
Thu Mar 8 12:59:23 EST 2018


Hi Jeffery,

Your replies include the digest of the whole day's vtk-users posts.  Can
you trim them from your messages?

To be fair, when you move the slider to the left, triangles in the toroid
become degenerate.  This can be seen by viewing the toroid as a wireframe.
I'm guessing that you don't actually need a square toroid for your
application.

The vtkContourTriangulator doesn't care if the points have different z, as
long as the points all lie in a plane, and as long as all the line segments
form a closed curve (or multiple closed curves) that do not self-intersect
when viewed along the plane normal.  Of course there are tolerance issues
since the "plane normal" is computed within the limits of double-precision.

One thing that might help is a filter that I wrote a few years ago for
clipping surfaces generated from vtkMarchingCubes.  This class does both
the clipping and the triangulation and is more robust than vtkCutter
because it never accidentally merges points in ways that change the
topology.  Unfortunately it is a "clipping" filter rather than a "cutting"
filter, so it's output has to be filtered in order for it to do what you
need:

// Set up the clipper which will produce the cut polygons (unfortunately,
its output includes half the original surface)
vtkSmartPointer<vtkPlaneCollection> planes =
vtkSmartPointer<vtkPlaneCollection>::New();
        planes->AddItem(planeCut);
vtkSmartPointer<vtkClipClosedSurface> polygonsClip =
vtkSmartPointer<vtkClipClosedSurface>::New();
polygonsClip->SetInputConnection(clean->GetOutputPort());
        polygonsClip->SetClippingPlanes(planes);
        polygonsClip->SetScalarModeToLabels();

        // extract just the cut-surface polygons (I wish this was simpler!)
        vtkSmartPointer<vtkIdTypeArray> labels =
vtkSmartPointer<vtkIdTypeArray>::New();
        labels->SetName("Labels");
        labels->InsertNextValue(1); // extract cut faces, which are labeled
with "1"
vtkSmartPointer<vtkSelectionNode> node =
vtkSmartPointer<vtkSelectionNode>::New();
        node->SetFieldType(vtkSelectionNode::CELL);
        node->SetContentType(vtkSelectionNode::VALUES);
        node->SetSelectionList(labels);
vtkSmartPointer<vtkSelection> select = vtkSmartPointer<vtkSelection>::New();
        select->AddNode(node);
vtkSmartPointer<vtkExtractSelection> extract =
vtkSmartPointer<vtkExtractSelection>::New();
        extract->SetInputConnection(0, polygonsClip->GetOutputPort());
        extract->SetInputData(1, select);
        // the "extract' filter produces the cut-face polygons that we want

This filter is described further here:
https://www.vtk.org/Wiki/VTK/Closed_Surface_Clipping

Regarding the vtkPlaneCutter class, it doesn't work for me, either.
Hopefully somebody reading this message is familiar with this class and
will chime it.  Perhaps it hasn't been fully tested with vtkPolyData as an
input?  It looks like it was primarily designed for use on 3D mesh data.

 - David


On Thu, Mar 8, 2018 at 9:42 AM, Jeffery Lewis <jlewis at accuray.com> wrote:

> Thank you David for investigating this.
>
> Adding the call to SetTolerance() on the vtkCleanPolyData does help. If
> you play around with the XY squareness slider (particularly to the left),
> you will still see the problem (even with tolerance set lower to 1e-4).
>
> Does vtkContourTriangulator require no z components in the polygons? I am
> cutting the surface model in 3D space. The contour generated by vtkCutter
> is essentially confined to a plane, but the contour polygons have z
> components in the coordinates (e.g. they are 3D points).
>
> Also, if I replace vtkCutter with vtkPlaneCutter, the program still
> crashes at start up.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://vtk.org/pipermail/vtkusers/attachments/20180308/631e5eb7/attachment.html>


More information about the vtkusers mailing list