Skip to Content.
Sympa Menu

cgal-discuss - [cgal-discuss] Using Polyhedron fill_hole()

Subject: CGAL users discussion list

List archive

[cgal-discuss] Using Polyhedron fill_hole()


Chronological Thread 
  • From: Jens Nielsen <>
  • To:
  • Subject: [cgal-discuss] Using Polyhedron fill_hole()
  • Date: Mon, 26 Aug 2013 12:21:57 +0100

Hi

I have been trying to use the fill_hole method described here http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Polyhedron_ref/Class_Polyhedron_3.html to fill a number of holes in a 3D polyhedron that I have to process. However I am unable to get it working. After calling the fill hole I still have the same number of border halfedges and the polygon is not closed. An additional face is inserted but it does not seem to close the polyhedron.  

Attached is a minimal example based on a modification of the off2stl example. I load a closed off polyhedron and make a hole in it which seems to work as expected. However the closing of the hole using "P.fill_hole(P.border_halfedges_begin());" does not work as expected. Is there a missing update function or can someone spot something else obvious that I have done wrong. 

This is done using CGAL 4.2, I have not yet tried the 4.3 beta. 

Thanks 
Jens H Nielsen

// Make and fill hole in surface modified from off2stl example. 
// Convert from OFF format to StereoLithography StL format.

#include <CGAL/Simple_cartesian.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/IO/Polyhedron_iostream.h>
#include <CGAL/IO/Verbose_ostream.h>
#include <cstddef>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <fstream>

using namespace std;

bool  verbose  = false;
bool  binary    = false;

typedef CGAL::Simple_cartesian<double>  Kernel;
typedef Kernel::Point_3                 Point;
typedef Kernel::Vector_3                Vector;
typedef CGAL::Polyhedron_3<Kernel>      Polyhedron;
typedef Polyhedron::Vertex_iterator     Vertex_iterator;
typedef Polyhedron::Facet_iterator      Facet_iterator;
typedef Polyhedron::Halfedge_iterator   Halfedge_iterator;
typedef Polyhedron::Halfedge_handle     Halfedge_handle;


// main function with standard unix commandline arguments
// ------------------------------------------------------
int main( int argc, char **argv) {
    int n = 0; // number of filenames
    char *filename[2];
    bool help = false;
    for (int i = 1; i < argc; i++) { // check commandline options
        if ( strcmp( "-v", argv[i]) == 0)
            verbose = true;
        else if ( strcmp( "-b", argv[i]) == 0)
            binary = true;
        else if ( (strcmp( "-h", argv[i]) == 0) ||
                  (strcmp( "-help", argv[i]) == 0))
            help = true;
        else if ( n < 2 ) {
            filename[ n++] = argv[i];
        } else {
   ++n;
            break;
}
    }
    if ((n > 2) || help) {
        if ( ! help)
            cerr << "Error: in parameter list" << endl;
        cerr << "Usage: " << argv[0] << " [<options>] [<infile> [<outfile>]]"
             << endl;
        cerr << "       convert a CGAL object (OFF) to StereoLithography StL "
                "format." << endl;
        cerr << "       -v      verbose." << endl;
        cerr << "       -b      binary." << endl;
        exit( ! help);
    }

    CGAL::Verbose_ostream vout( verbose);
    vout << argv[0] << ": verbosity on." << endl;

    const char*  iname = "cin";
    istream*     p_in  = &cin;
    ifstream     in;
    if ( n > 0) {
        in.open( filename[0]);
        p_in = &in;
        iname = filename[0];
    }
    if ( !*p_in) {
        cerr << argv[0] << ": error: cannot open file '"<< iname
             << "' for reading." <<endl;
        exit( 1);
    }

    vout << "Reading polyhedron ..." << endl;
    Polyhedron P;
    (*p_in) >> P;
    vout << "    .... done." << endl;

    if ( !*p_in) {
        cerr << argv[0] << " read error: while reading file '"<< iname << "'."
             << endl;
        exit( 1);
    }

cout << "Surface loaded" << endl;
P.normalize_border();
cout << P.is_closed () << endl;
cout <<  P.size_of_vertices() << endl;
cout << P.size_of_halfedges() << endl;
cout << P.size_of_border_halfedges () << endl;
cout << P.size_of_facets() << endl;

cout << "Make a Hole" << endl;
P.make_hole(P.halfedges_begin());
P.normalize_border();
cout << P.size_of_border_halfedges() << endl;
cout << P.is_closed() << endl;
cout <<  P.size_of_vertices() << endl;
cout << P.size_of_halfedges() << endl;
cout << P.size_of_border_halfedges () << endl;
cout << P.size_of_facets() << endl;


Halfedge_iterator j;
for (j = P.border_halfedges_begin(); j != P.halfedges_end(); ++j){
cout << j->vertex()->point() << " " << j->opposite()->vertex()->point() <<  endl;
}
cout << "And Filling" << endl;
P.fill_hole(P.border_halfedges_begin());
P.normalize_border();
cout << P.size_of_border_halfedges() << endl;
cout << P.is_closed () << endl;
cout <<  P.size_of_vertices() << endl;
cout << P.size_of_halfedges() << endl;
cout << P.size_of_border_halfedges () << endl;
cout << P.size_of_facets() << endl;


for (j = P.border_halfedges_begin(); j != P.halfedges_end(); ++j){
cout << j->vertex()->point() << " " << j->opposite()->vertex()->point() <<  endl;
}

    return 0;
}
// EOF //

// Make and fill hole in surface modified from off2stl example. 
// Convert from OFF format to StereoLithography StL format.

#include <CGAL/Simple_cartesian.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/IO/Polyhedron_iostream.h>
#include <CGAL/IO/Verbose_ostream.h>
#include <cstddef>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <fstream>

using namespace std;

bool  verbose  = false;
bool  binary    = false;

typedef CGAL::Simple_cartesian<double>  Kernel;
typedef Kernel::Point_3                 Point;
typedef Kernel::Vector_3                Vector;
typedef CGAL::Polyhedron_3<Kernel>      Polyhedron;
typedef Polyhedron::Vertex_iterator     Vertex_iterator;
typedef Polyhedron::Facet_iterator      Facet_iterator;
typedef Polyhedron::Halfedge_iterator   Halfedge_iterator;
typedef Polyhedron::Halfedge_handle     Halfedge_handle;


// main function with standard unix commandline arguments
// ------------------------------------------------------
int main( int argc, char **argv) {
    int n = 0; // number of filenames
    char *filename[2];
    bool help = false;
    for (int i = 1; i < argc; i++) { // check commandline options
        if ( strcmp( "-v", argv[i]) == 0)
            verbose = true;
        else if ( strcmp( "-b", argv[i]) == 0)
            binary = true;
        else if ( (strcmp( "-h", argv[i]) == 0) ||
                  (strcmp( "-help", argv[i]) == 0))
            help = true;
        else if ( n < 2 ) {
            filename[ n++] = argv[i];
        } else {
	    ++n;
            break;
	}
    }
    if ((n > 2) || help) {
        if ( ! help)
            cerr << "Error: in parameter list" << endl;
        cerr << "Usage: " << argv[0] << " [<options>] [<infile> [<outfile>]]"
             << endl;
        cerr << "       convert a CGAL object (OFF) to StereoLithography StL "
                "format." << endl;
        cerr << "       -v      verbose." << endl;
        cerr << "       -b      binary." << endl;
        exit( ! help);
    }

    CGAL::Verbose_ostream vout( verbose);
    vout << argv[0] << ": verbosity on." << endl;

    const char*  iname = "cin";
    istream*     p_in  = &cin;
    ifstream     in;
    if ( n > 0) {
        in.open( filename[0]);
        p_in = &in;
        iname = filename[0];
    }
    if ( !*p_in) {
        cerr << argv[0] << ": error: cannot open file '"<< iname
             << "' for reading." <<endl;
        exit( 1);
    }

    vout << "Reading polyhedron ..." << endl;
    Polyhedron P;
    (*p_in) >> P;
    vout << "    .... done." << endl;

    if ( !*p_in) {
        cerr << argv[0] << " read error: while reading file '"<< iname << "'."
             << endl;
        exit( 1);
    }

	cout << "Surface loaded" << endl;
	P.normalize_border();	
	cout << P.is_closed () << endl;
	cout <<  P.size_of_vertices() << endl;
	cout << P.size_of_halfedges() << endl;
	cout << P.size_of_border_halfedges () << endl;
	cout << P.size_of_facets() << endl;

	cout << "Make a Hole" << endl;
	P.make_hole(P.halfedges_begin());
	P.normalize_border();	
	cout << P.size_of_border_halfedges() << endl;
	cout << P.is_closed() << endl;
	cout <<  P.size_of_vertices() << endl;
	cout << P.size_of_halfedges() << endl;
	cout << P.size_of_border_halfedges () << endl;
	cout << P.size_of_facets() << endl;


	Halfedge_iterator j;
	for (j = P.border_halfedges_begin(); j != P.halfedges_end(); ++j){
		cout << j->vertex()->point() << " " << j->opposite()->vertex()->point() <<  endl;
	}
	cout << "And Filling" << endl;
	P.fill_hole(P.border_halfedges_begin());
	P.normalize_border();	
	cout << P.size_of_border_halfedges() << endl;
	cout << P.is_closed () << endl;
	cout <<  P.size_of_vertices() << endl;
	cout << P.size_of_halfedges() << endl;
	cout << P.size_of_border_halfedges () << endl;
	cout << P.size_of_facets() << endl;


	for (j = P.border_halfedges_begin(); j != P.halfedges_end(); ++j){
		cout << j->vertex()->point() << " " << j->opposite()->vertex()->point() <<  endl;
	}

    return 0;
}
// EOF //


  • [cgal-discuss] Using Polyhedron fill_hole(), Jens Nielsen, 08/26/2013

Archive powered by MHonArc 2.6.18.

Top of Page