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


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


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

  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();

return boolean->GetOutput();

Using images for a boolean operation is often a very bad idea. What’s with vtkBooleanOperationPolyDataFilter or

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.


@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

const double red_radius = implant->GetHoleDiameter() / 2;
//cylinder->SetAxis(0, 1, 0);

//Cylinder red
vtkNew<vtkPolyDataMapper> mapper;
vtkNew<vtkActor> actor_cylinder;
actor_cylinder->GetProperty()->SetColor(1, 0, 0);


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


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.


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.