Cut a mesh using lasso

I’m doing a lasso that I converted on 3D Mesh. and now I cut a polydata with it using the following code

vtkTriangleFilter* triFil = vtkTriangleFilter::New();

vtkTriangleFilter* triFil2 = vtkTriangleFilter::New();

vtkIntersectionPolyDataFilter * intersectionPolyDataFilter = vtkIntersectionPolyDataFilter::New();
0, triFil->GetOutput());

1, triFil2->GetOutput());


vtkNew plyWriter;
std::cout << “cut finished” << endl;

The problem is I get only contour and it fails most of the time.

We worked a lot on implementing robust curve cutting in 3D Slicer and after some experimentation and VTK fixes we finally got it right. It is very robust and accurate and supports both straight and crinkle cuts:

Straight cut:

Crinkle cut (original cells are kept):

You can either use the tool as is (either via GUI or Python) or copy the implementation into your code:

The steps are so complicated, can you please show an excerpt where input is Mesh as curve, and another mesh as input too ? I would like to select the faces that the curve intersected.

The code is very short and a full, working example for cutting a mesh with a curve. I would recommend to copy the code into your project as is, and try to simplify it yourself.

What does OutputWorldToModelTransform do ?
and why its needed, it confuses me.
where is the input mesh, and input curve ?

My curve is a patch ( mesh ) not a bunch of points

this is my trial

auto CleanFilter = vtkSmartPointer::New();


auto InputModelToWorldTransform = vtkSmartPointer::New();
auto InputModelToWorldTransformFilter = vtkSmartPointer::New();

auto SelectionFilter = vtkSmartPointer::New();

// Further connections depend on cut mode (straight or whole cells)
auto ClipFilter = vtkSmartPointer::New();

auto ConnectivityFilter = vtkSmartPointer::New();

auto OutputWorldToModelTransform = vtkSmartPointer::New();
auto OutputWorldToModelTransformFilter = vtkSmartPointer::New();

auto outputOutsideMesh = vtkSmartPointer::New();

to be more accuracte I want to select what’s under the curve there… The curve is a 3D Mesh projected.

I would like to select the faces under that curve, the curve is not in X,Y,Z points, the curve is a 3D mesh

3D Slicer allows performing any operations on arbitrarily transformed inputs. If the operation has multiple inputs then you need to convert all inputs to world coordinates, perform the operation, and then transform the result back to the object’s local coordinate system. If your objects are already all in world coordinate system then you can skip all the spatial transformations.

Input mesh is an object that stores a vtkPolyData containing a surface mesh.
Input curve is an object that stores a vtkPolyData containing a curve (a single line cell with many points).

You can get edge points and both sides of the cut surface of the surface using vtkSelectPolyData.

If your original curve input points are far from the mesh then you may want to constrain the curve to the mesh (using projection, optionally combined with Dijkstra path search on the surface). This projection is a quite complex task, we implemented a custom VTK filter for it: vtkProjectMarkupsCurvePointsFilter.

I use now VtkSlelectPolyData, but I get meshes that are artifcats, and random noises arounds the cuts…

I would recommend to try this first using the 3D Slicer GUI. If it works well there then you know that the problem is in how you extracted the code from Slicer and moved it into your project. If you find that something does not work in Slicer either then you can report it in the Slicer forum.