I’m quite new in using vtk, but I manage to write some code in C++ that allows a user to cut a bone thanks to mouse click.
I’ll explain: user select three points on the STL file he wants to cut, a plane is created thanks to those three points and then I want to clip the stl according to this plane. This part pertfectly works using vtkClipDataSet and the related mapper and actor.
You can see the result on the next image:
The left part of the renderer is where the original STL file is displayed and the user can choose points to define the cutting plane. The right renderer is the result, thus the cutted bone.
As you can see, the top surface is not “closed”. I thought I could do that quite simply by using vtkClipClosedSurface instead of vtkClipDatSet, but it doesn’t seems to work (as you can see on the capture below).
Here is the code related to this part:
vtkSmartPointer planes = vtkSmartPointer::New();
vtkSmartPointer<vtkClipClosedSurface> clipper = vtkSmartPointer<vtkClipClosedSurface>::New(); clipper->SetInputData(STLreader->GetOutput()); clipper->SetClippingPlanes(planes); clipper->SetScalarModeToColors(); clipper->SetClipColor(0.8900, 0.8100, 0.3400); // banana clipper->SetBaseColor(1.0000, 0.3882, 0.2784); // tomato vtkSmartPointer<vtkDataSetMapper> clipMapper = vtkSmartPointer<vtkDataSetMapper>::New(); clipMapper->SetInputConnection(clipper->GetOutputPort()); vtkSmartPointer<vtkActor> clipActor = vtkSmartPointer<vtkActor>::New(); clipActor->SetMapper(clipMapper); clipActor->GetProperty()->SetColor(1.0000, 0.3882, 0.2784); clipActor->GetProperty()->SetInterpolationToFlat(); rightRenderer->AddActor(clipActor); //add the cutted actor rightRenderer->RemoveActor(actor); //remove the STL original file
Am I forgotting something? I tried to follow the exemple given by vtk
[https://lorensen.github.io/VTKExamples/site/Cxx/Meshes/ClipClosedSurface/](http://vtk example) and just adapt it to work with the rest of my code…
Maybe vtkClipClosedSurface don’t work with “empty” volume? (I tried to figure it out with the doc but didn’t success…)
Thank you for your time and help
Don’t hesitate if I wasn’t clear, it’s my first post here so I’m not used to explain issue that I encouter…