<html><body><div style="color:#000; background-color:#fff; font-family:Courier New, courier, monaco, monospace, sans-serif;font-size:10pt"><div><div><font size="2">Hi,</font></div><div><font size="2"><br></font></div><div><font size="2">You simply forgot to compute the normals of your polydata. Use the vtkPolyDataNormals filter on "bloc" in order to do it. It should work.</font></div><div><font size="2"><br></font></div><div><font size="2">Anyway, you should be aware that the vtkBooleanOperationPolyDataFilter has several bugs. </font></div><div><font size="2">You can find information about it on previous threads:</font></div><div><font size="2">http://vtk.1045678.n5.nabble.com/PolyData-Boolean-operation-problem-td5714926.html</font></div><div><font size="2">http://vtk.1045678.n5.nabble.com/Holes-in-mesh-after-vtkBooleanOperationPolyDataFilter-td5713284.html</font></div><div><br></div><div><font size="2">Best</font></div><div><font
size="2">James</font></div></div> <div style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 10pt; "> <div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; "> <div dir="ltr"> <font size="2" face="Arial"> <hr size="1"> <b><span style="font-weight:bold;">De :</span></b> Cory Quammen <cquammen@cs.unc.edu><br> <b><span style="font-weight: bold;">À :</span></b> NsPx <nspx.roronoa@gmail.com> <br><b><span style="font-weight: bold;">Cc :</span></b> vtkusers@vtk.org <br> <b><span style="font-weight: bold;">Envoyé le :</span></b> Vendredi 24 août 2012 16h45<br> <b><span style="font-weight: bold;">Objet :</span></b> Re: [vtkusers] wrong result while using vtkBooleanOperationPolyDataFilter<br> </font> </div> <br>Please be more specific about what the problem is. Does the code not<br>compile? Is the result of the boolean operation incorrect?<br><br>Thank
you,<br>Cory<br><br>On Fri, Aug 24, 2012 at 10:38 AM, NsPx <<a ymailto="mailto:nspx.roronoa@gmail.com" href="mailto:nspx.roronoa@gmail.com">nspx.roronoa@gmail.com</a>> wrote:<br>> Hi all,<br>><br>> I'm trying to use vtkBooleanOperationPolyDataFilter but it seems I'm missing<br>> something. I get unexpected result when computing the difference between a<br>> simple sphere and a poledron.<br>><br>> Can someone explain me what is wrong in the following example ?<br>><br>> Thanks by advance.<br>><br>> ##############<br>><br>> #include <vtkSmartPointer.h><br>> #include <vtkSphereSource.h><br>> #include <vtkPolyData .h><br>> #include <vtkPoints.h><br>> #include <vtkCellArray.h><br>> #include <vtkIdType.h><br>> #include <vtkTriangle.h><br>> #include <vtkBooleanOperationPolyDataFilter.h><br>> #include <vtkRenderer.h><br>> #include
<vtkPolyDataMapper.h><br>> #include <vtkActor.h><br>> #include <vtkRenderWindow.h><br>> #include <vtkRenderWindowInteractor.h><br>><br>> #include <vector><br>><br>> int main(int argc, char *argv[])<br>> {<br>> // sphere<br>> vtkSmartPointer<vtkSphereSource> sphereSource1 =<br>> vtkSmartPointer<vtkSphereSource>::New();<br>> sphereSource1->SetCenter(.25, 0, 0);<br>> sphereSource1->Update();<br>><br>> vtkPolyData * sphere = sphereSource1->GetOutput();<br>><br>> // design a bloc which intersects the sphere<br>> double bounds[6];<br>> sphere->GetBounds(bounds);<br>><br>> double x1,x2,y1,y2,z1,z2;<br>> x1=bounds[0];<br>> x2=bounds[1];<br>> y1=bounds[2]-0.5;<br>>
y2=bounds[3]+0.5;<br>> z1=bounds[4]-0.5;<br>> z2=bounds[5]+0.5;<br>><br>> double lx = x2-x1;<br>><br>> vtkSmartPointer<vtkPolyData> bloc = vtkSmartPointer<vtkPolyData>::New();<br>> vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();<br>> vtkSmartPointer<vtkCellArray> triangles =<br>> vtkSmartPointer<vtkCellArray>::New();<br>> bloc->SetPoints(points);<br>> bloc->SetPolys(triangles);<br>><br>> vector<vtkIdType> ids;<br>> ids.push_back( points->InsertNextPoint( x1+0.3*lx, y1, z2));<br>> ids.push_back( points->InsertNextPoint( x1+0.6*lx, y1, z2));<br>> ids.push_back( points->InsertNextPoint( x1+0.6*lx, y2, z2));<br>> ids.push_back(
points->InsertNextPoint( x1+0.3*lx, y2, z2));<br>> ids.push_back( points->InsertNextPoint( x1+0.3*lx, y1, z1));<br>> ids.push_back( points->InsertNextPoint( x1+0.6*lx, y1, z1));<br>> ids.push_back( points->InsertNextPoint( x1+0.6*lx, y2, z1));<br>> ids.push_back( points->InsertNextPoint( x1+0.3*lx, y2, z1));<br>><br>> vtkSmartPointer<vtkTriangle> t0 = vtkSmartPointer<vtkTriangle>::New();<br>> t0->GetPointIds()->SetId ( 0, ids[0]);<br>> t0->GetPointIds()->SetId ( 1, ids[1]);<br>> t0->GetPointIds()->SetId ( 2, ids[2]);<br>> triangles->InsertNextCell ( t0 );<br>> vtkSmartPointer<vtkTriangle> t1 = vtkSmartPointer<vtkTriangle>::New();<br>> t1->GetPointIds()->SetId ( 0, ids[0]);<br>>
t1->GetPointIds()->SetId ( 1, ids[2]);<br>> t1->GetPointIds()->SetId ( 2, ids[3]);<br>> triangles->InsertNextCell ( t1 );<br>> vtkSmartPointer<vtkTriangle> t2 = vtkSmartPointer<vtkTriangle>::New();<br>> t2->GetPointIds()->SetId ( 0, ids[1]);<br>> t2->GetPointIds()->SetId ( 1, ids[5]);<br>> t2->GetPointIds()->SetId ( 2, ids[2]);<br>> triangles->InsertNextCell ( t2 );<br>> vtkSmartPointer<vtkTriangle> t3 = vtkSmartPointer<vtkTriangle>::New();<br>> t3->GetPointIds()->SetId ( 0, ids[2]);<br>> t3->GetPointIds()->SetId ( 1, ids[5]);<br>> t3->GetPointIds()->SetId ( 2, ids[6]);<br>> triangles->InsertNextCell ( t3 );<br>> vtkSmartPointer<vtkTriangle> t4 =
vtkSmartPointer<vtkTriangle>::New();<br>> t4->GetPointIds()->SetId ( 0, ids[2]);<br>> t4->GetPointIds()->SetId ( 1, ids[6]);<br>> t4->GetPointIds()->SetId ( 2, ids[7]);<br>> triangles->InsertNextCell ( t4 );<br>> vtkSmartPointer<vtkTriangle> t5 = vtkSmartPointer<vtkTriangle>::New();<br>> t5->GetPointIds()->SetId ( 0, ids[2]);<br>> t5->GetPointIds()->SetId ( 1, ids[7]);<br>> t5->GetPointIds()->SetId ( 2, ids[3]);<br>> triangles->InsertNextCell ( t5 );<br>> vtkSmartPointer<vtkTriangle> t6 = vtkSmartPointer<vtkTriangle>::New();<br>> t6->GetPointIds()->SetId ( 0, ids[3]);<br>> t6->GetPointIds()->SetId ( 1, ids[7]);<br>> t6->GetPointIds()->SetId ( 2,
ids[4]);<br>> triangles->InsertNextCell ( t6 );<br>> vtkSmartPointer<vtkTriangle> t7 = vtkSmartPointer<vtkTriangle>::New();<br>> t7->GetPointIds()->SetId ( 0, ids[4]);<br>> t7->GetPointIds()->SetId ( 1, ids[3]);<br>> t7->GetPointIds()->SetId ( 2, ids[0]);<br>> triangles->InsertNextCell ( t7 );<br>> vtkSmartPointer<vtkTriangle> t8 = vtkSmartPointer<vtkTriangle>::New();<br>> t8->GetPointIds()->SetId ( 0, ids[0]);<br>> t8->GetPointIds()->SetId ( 1, ids[4]);<br>> t8->GetPointIds()->SetId ( 2, ids[5]);<br>> triangles->InsertNextCell ( t8 );<br>> vtkSmartPointer<vtkTriangle> t9 = vtkSmartPointer<vtkTriangle>::New();<br>> t9->GetPointIds()->SetId ( 0,
ids[0]);<br>> t9->GetPointIds()->SetId ( 1, ids[1]);<br>> t9->GetPointIds()->SetId ( 2, ids[5]);<br>> triangles->InsertNextCell ( t9);<br>> vtkSmartPointer<vtkTriangle> t10 = vtkSmartPointer<vtkTriangle>::New();<br>> t10->GetPointIds()->SetId ( 0, ids[6]);<br>> t10->GetPointIds()->SetId ( 1, ids[5]);<br>> t10->GetPointIds()->SetId ( 2, ids[4]);<br>> triangles->InsertNextCell ( t10);<br>> vtkSmartPointer<vtkTriangle> t11 = vtkSmartPointer<vtkTriangle>::New();<br>> t11->GetPointIds()->SetId ( 0, ids[7]); t11->GetPointIds()->SetId ( 1,<br>> ids[6]); t11->GetPointIds()->SetId ( 2, ids[4]);<br>> triangles->InsertNextCell ( t11);<br>><br>>
bloc->BuildLinks();<br>><br>> // boolean filter<br>> vtkSmartPointer<vtkBooleanOperationPolyDataFilter> booleanOperation =<br>> vtkSmartPointer<vtkBooleanOperationPolyDataFilter>::New();<br>> booleanOperation->SetOperationToDifference();<br>> booleanOperation->SetInputConnection( 1, sphere->GetProducerPort());<br>> booleanOperation->SetInputConnection( 0, bloc->GetProducerPort());<br>> booleanOperation->Update();<br>><br>> //display result<br>> vtkSmartPointer<vtkRenderer> renderer =<br>> vtkSmartPointer<vtkRenderer>::New();<br>> vtkSmartPointer<vtkPolyDataMapper> mapper =<br>> vtkSmartPointer<vtkPolyDataMapper>::New();<br>> mapper->SetInput(booleanOperation->GetOutput());<br>>
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();<br>> actor->SetMapper(mapper);<br>><br>> renderer->AddActor( actor);<br>><br>> vtkSmartPointer<vtkRenderWindow> rendWindow =<br>> vtkSmartPointer<vtkRenderWindow>::New();<br>> rendWindow->AddRenderer(renderer);<br>><br>> vtkSmartPointer<vtkRenderWindowInteractor> iren =<br>> vtkSmartPointer<vtkRenderWindowInteractor>::New();<br>> iren->SetRenderWindow( rendWindow);<br>><br>> renderer->ResetCamera();<br>> rendWindow->Render();<br>> iren->Start();<br>><br>> return 0;<br>> }<br>><br>> ##############<br>><br>> _______________________________________________<br>> Powered by www.kitware.com<br>><br>> Visit other Kitware
open-source projects at<br>> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>><br>> Please keep messages on-topic and check the VTK FAQ at:<br>> <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>><br>> Follow this link to subscribe/unsubscribe:<br>> <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>><br><br><br><br>-- <br>Cory Quammen<br>Research Associate<br>Department of Computer Science<br>The University of North Carolina at Chapel Hill<br>_______________________________________________<br>Powered by www.kitware.com<br><br>Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br><br>Please keep messages
on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br><br>Follow this link to subscribe/unsubscribe:<br><a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br><br><br> </div> </div> </div></body></html>