Substraction between one volume respect other two volumes does not affect the intersected areas

Hello,

I have a doubt I hope someone can give me an idea. I want to substract one volume (obtained from a polydata with vtkPolyDataToImageStencil) from several cubes which are polydatas too. I append the cubes with vtkAppendPolyData to make a single substraction and i also transform it into volume. And i make a boolean substraction . The substracion in the areas with cubes that are intersecting the substraction is not applied. I solved it by substracting each cube one by one to the volume but it becomes slower. I wonder how the filters treat the intersected areas. I don´t want to do this operation with polydatas because i have many problems clipping and closing surfaces because the data can come with many issues.

Thank you very much

intersection

Do you have any code and sample files for us?

Sure, here it is:

vtkSmartPointer<vtkPolyDataCollection > allCylindersRed = widget_mgr_.lock()->getAllCylindersOfImplantActor(0); //0 => RED CYLINDER
vtkSmartPointer<vtkAppendPolyData> appendFilterRedCylinders = vtkSmartPointer<vtkAppendPolyData>::New();
//Create a polydata with all the implants for the boolean
for (allCylindersRed->InitTraversal();
	vtkPolyData* PolyData = allCylindersRed->GetNextItem();) {
	//Append the two meshes
	appendFilterRedCylinders->AddInputData(PolyData);
	appendFilterRedCylinders->Update();
}

  vtkSmartPointer<vtkImageData> RedCylinders_img =   getFromPolydataToImage(appendFilterRedCylinders->GetOutput(), final_bounds);

  extrude_WithoutRedCylinders_img =    booleanSubstractionTwoPolyDatas(extrude, RedCylinders_img );

vtkSmartPointer<vtkImageData> booleanSubstractionTwoPolyDatas(vtkSmartPointer<vtkImageData> extrude1, vtkSmartPointer<vtkImageData> extrude2) {

}

//Substract one image from the other
vtkSmartPointer<vtkImageMathematics> boolean = vtkSmartPointer<vtkImageMathematics>::New();
boolean->SetInput1Data(extrude1);
boolean->SetInput2Data(extrude2);
boolean->SetOperationToSubtract();
boolean->Update();


return boolean->GetOutput();
}

Using images for a boolean operation is often a very bad idea. What’s with vtkBooleanOperationPolyDataFilter or https://github.com/zippy84/vtkbool?

Thanks for answering. I tried it but it was very slow

Could you please provide your polydatas!

Hi, here you have the stl and i tried to substract a cylinder and it takes a long time.

Thanks

@zandarina One stl is not enough. Where is the cylinder?

Hello, thanks for answering i use this piece of code for the cylinder and i move it with a bounding box and i initialize it with the position of the mouse

cylinder->SetHeight(height_red_cyl);
const double red_radius = implant->GetHoleDiameter() / 2;
cylinder->SetRadius(red_radius);
cylinder->SetResolution(100);
//cylinder->Update();
//cylinder->SetAxis(0, 1, 0);

//Cylinder red
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(cylinder->GetOutputPort());
mapper->Update();
vtkNew<vtkActor> actor_cylinder;
actor_cylinder->SetMapper(mapper);
actor_cylinder->GetProperty()->SetColor(1, 0, 0);
actor_cylinder->GetProperty()->SetOpacity(0.5);

thanks

I need two stl’s or vtk’s! I don’t know your parameters. Try to export one of you cylinders.

sure, i have added the polydatas to make the substraction

Thanks

There is no contact:

Hi sorry i don´t understand why it did not apply the transformation. I checked the vtk files and both polydatas intersect. I hope it is ok this time.

Thanks

With my filter you will get this result:

Awesome results. How long did it take? Is the result a closed surface?.

Thanks for trying and congrats for your library

Only a few milliseconds…

Just apply CleanPolyData and you will have one surface.

Hi, I am trying to use your library as you suggested but when i try to susbtract two polydatas to empty the extruded stl, it goes very slow. How can i speed up the susbstraction?. Thank you very much

vtkNew<vtkSTLReader> reader;
reader->SetFileName("filename.stl");
reader->Update();


///// 1
/////// extrude towards height to make the hole
vtkSmartPointer<vtkLinearExtrusionFilter> extrude =
	vtkSmartPointer<vtkLinearExtrusionFilter>::New();
extrude->SetInputData(reader->GetOutput());
extrude->SetExtrusionTypeToVectorExtrusion();
extrude->SetVector(0, 0, 1);
extrude->SetScaleFactor(5.2);
extrude->Update();






///// 2

// Make the basis
vtkSmartPointer<vtkPolyDataNormals> normals2 =
	vtkSmartPointer<vtkPolyDataNormals>::New();
normals2->SetInputData(reader->GetOutput());
normals2->ConsistencyOn();
normals2->SetComputeCellNormals(1);
normals2->SplittingOff();
normals2->Update();



/////// original cut /////
vtkSmartPointer<vtkLinearExtrusionFilter> extrude2 =
	vtkSmartPointer<vtkLinearExtrusionFilter>::New();
extrude2->SetInputData(normals2->GetOutput());
extrude2->SetExtrusionTypeToNormalExtrusion();
//extrude->SetVector(0, 0, -1);
extrude2->SetScaleFactor(3.0);
extrude2->Update();



vtkPolyDataBooleanFilter *bf2 =   
  vtkPolyDataBooleanFilter::New();
bf2->SetInputConnection(0, extrude->GetOutputPort());
bf2->SetInputConnection(1, extrude2->GetOutputPort());
bf2->SetOperModeToDifference();
bf2->Update();

vtkSmartPointer<vtkPolyDataMapper> Mapper4 =
	vtkSmartPointer<vtkPolyDataMapper>::New();
Mapper4->SetInputData(bf2->GetOutput());
Mapper4->ScalarVisibilityOff();

vtkSmartPointer<vtkActor> Actor4 =
	vtkSmartPointer<vtkActor>::New();
Actor4->SetMapper(Mapper4);
Actor4->GetProperty()->SetColor(0, 0, 1);




// Create renderers and add actors of plane and cube
vtkSmartPointer<vtkRenderer> renderer =
	vtkSmartPointer<vtkRenderer>::New();


renderer->AddActor(Actor4); 


vtkSmartPointer<vtkRenderWindow> renderWindow =
	vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
renderWindow->SetSize(600, 600);

vtkSmartPointer<vtkRenderWindowInteractor> interactor =
	vtkSmartPointer<vtkRenderWindowInteractor>::New();
interactor->SetRenderWindow(renderWindow);
renderer->SetBackground(0, 0, 0);
renderWindow->Render();

interactor->Start();

Hi, one last question, I was thinking again about the booleans you suggested me by now I have it all in volume operations and I got a decent result. But I am thinking that combining both options it can be a good idea to obtain even a better polydata.

But I was wondering in the picture you show why the bottom of the cylinder is not removed from the output of the boolean operation substraction. The result should be a hole. I does not make sense to me. I also got the same issue with the substraction of the polydata with the cylinder.

Thanks

Screenshot_1

I found that this is caused in debug but not a release. Amd the vtkAppendPolyData if there is intersection does not work eaither. But I fixed it doing one by one. I will look into the vtkAppendPolyData to see what’s wrong with this filter in the intersections. If I find it out I will let you know because it happens in volume and polydata in boolean operations. Thanks

Here I have two meshes, I used vtkbool library(GitHub - zippy84/vtkbool: A new boolean operations filter for VTK) to get the result of which the operation of boolean difference, but the result modes have some errors, like holes. I want to known how to solve the problem?Thanks a lot.
A.stl (684 Bytes)
B.stl (61.0 KB)
result.stl (82.0 KB)

1 Like