[vtkusers] wrong result while using vtkBooleanOperationPolyDataFilter

NsPx nspx.roronoa at gmail.com
Fri Aug 24 11:08:49 EDT 2012


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

Regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120824/23fdc75e/attachment.htm>


More information about the vtkusers mailing list