[vtkusers] Filling a hole

alex. gouaillard Alexandre.Gouaillard at Sun.COM
Wed Mar 15 22:33:34 EST 2006


this code supposely close all "holes" on the surface by tracking them,
creating a patch, patching, and deleting duplicated edges and points on
the border of the "holes". I haven't tested it for .... ages, but it
should be ok.

beware: this is closing ALL holes. You might want to hack in to directly
pass only the border you wanna fill. As you are cutting before, the
boundary of your hole is planar, and everything should be ok.


         vtkPolyData *meshin = this->GetInput();
         vtkPolyData *meshout= this->GetOutput();

         int nombre;

         int pointsNumber;


         // detect holes
         vtkFeatureEdges *boundaryEdges = vtkFeatureEdges::New();
         boundaryEdges->SetInput(meshin);
         boundaryEdges->SetBoundaryEdges(1);//only border points
         boundaryEdges->SetFeatureEdges(0);
         boundaryEdges->SetNonManifoldEdges(0);
         boundaryEdges->SetManifoldEdges(0);
         boundaryEdges->Update();


         // "nombre" gives us the total number of border edges


         nombre = (boundaryEdges->GetOutput()->GetNumberOfLines());
         pointsNumber = nombre;
         
         vtkCleanPolyData *poly = vtkCleanPolyData::New();
         poly->SetInput(meshin);
         poly->Update();


         vtkPolyDataConnectivityFilter *region = vtkPolyDataConnectivityFilter::New();
         vtkAppendPolyData *meshAppend = vtkAppendPolyData::New();
         vtkStripper *bouchon = vtkStripper::New();
         vtkPolyData *bouchonPoly = vtkPolyData::New();
         vtkTriangleFilter *bouchontri = vtkTriangleFilter::New();


         meshAppend->AddInput(poly->GetOutput());
         meshAppend->AddInput(bouchontri->GetOutput());


         region->SetInput(boundaryEdges->GetOutput());
         region->SetExtractionMode(6);


         bouchon->SetInput(region->GetOutput());

         bouchontri->SetInput(bouchonPoly);


         poly->SetInput(meshAppend->GetOutput());
         poly->SetTolerance(0.0);    
         poly->SetConvertLinesToPoints(0); 
         poly->SetConvertPolysToLines(0);
         poly->SetConvertStripsToPolys(0); 


         boundaryEdges->SetInput(poly->GetOutput());


         while (nombre != 0)     
         {

                region->Update();
                                                 
                 // creating polygonal patches
                 bouchon->Update();
                 
                 bouchonPoly->Initialize();
                 bouchonPoly->SetPoints(bouchon->GetOutput()->GetPoints());
                 bouchonPoly->SetPolys(bouchon->GetOutput()->GetLines());
                 bouchonPoly->Update();


                 // triangulate the polygonal patch 
                 bouchontri->Update();
                 
                 // patch (add the patch to the mesh)
                 meshAppend->Update();


                // remove duplicated edges and points
                poly->Update();


                // update the number of border edges
                boundaryEdges->Update();


                nombre=((boundaryEdges->GetOutput())->GetNumberOfLines());


                this->UpdateProgress((pointsNumber - nombre) / pointsNumber);


         } // END while (nombre!=0)


         boundaryEdges->Delete();
         region->Delete();
         meshAppend->Delete();
         bouchon->Delete();
         bouchonPoly->Delete();
         bouchontri->Delete();
         
         meshout->DeepCopy(poly->GetOutput()); 
         poly->Delete();        




More information about the vtkusers mailing list