Skip to Content.
Sympa Menu

cgal-discuss - [cgal-discuss] Polyhedron_incremental_builder_3 and test_facet_indices [re-post]

Subject: CGAL users discussion list

List archive

[cgal-discuss] Polyhedron_incremental_builder_3 and test_facet_indices [re-post]


Chronological Thread 
  • From: Eric Boix <>
  • To:
  • Subject: [cgal-discuss] Polyhedron_incremental_builder_3 and test_facet_indices [re-post]
  • Date: Wed, 18 Jun 2008 16:37:27 +0200

Dear CGAL users,

Since I had no reply on first trial, I here dare to re-post...

I'm trying to get Polyhedron_incremental_builder_3 working for me.
I have the classical problem of having a surface given as triangles
but with uncoherent orientation. Thus before tossing out the triangles
to the incremental_builder_3, I use test_facet_indices() as an orientation
predicate and revert the triangle order when the test rejects one triangle.
[and yes they are many ways to orient the triangulation from outside
CGAL but this is not what we need ].

I must be doing things really wrong because I couldn't get it working
even for the following example for which the surface has only two
triangles [ I compile it with
g++ polySurface.cpp -lCGAL -lCGALcore++ -o polySurface -Wall] .
I would really appreciate any kind of help on this problem.

Best.
Eric Boix.

-----------------------------------------------------------------------------
#include <iostream> // for cout
#include <stdlib.h> // for exit

#include <CGAL/Simple_cartesian.h>
#include <CGAL/Triangle_3.h>
#include <CGAL/Polyhedron_incremental_builder_3.h>
#include <CGAL/Polyhedron_3.h>

template <class HDS>
class Build_Surface : public CGAL::Modifier_base<HDS>
{
public:
Build_Surface() { }
void operator()( HDS& hds );
};

template <class HDS>
void Build_Surface< HDS >::operator()( HDS &hds )
{
/// Build a simple surface made of two triangles.
CGAL::Polyhedron_incremental_builder_3<HDS> pB(hds, true);
pB.begin_surface( 6, 2, 0);

typedef typename HDS::Vertex::Point Point;
pB.add_vertex( Point( 0.0, 0.0, 0.0));
pB.add_vertex( Point( 1.0, 0.0, 0.0));
pB.add_vertex( Point( 0.0, 1.0, 0.0));
pB.add_vertex( Point( 0.0, 0.0, 1.0));
pB.add_vertex( Point( 1.0, 1.0, 1.0));
pB.add_vertex( Point( 1.0, 0.0, 1.0));

// First triangle:
pB.begin_facet();
pB.add_vertex_to_facet(2);
pB.add_vertex_to_facet(4);
pB.add_vertex_to_facet(0);
pB.end_facet();

// Second triangle:
std::vector< std::size_t> t;
t.push_back(0); t.push_back(5); t.push_back(4);
if( pB.test_facet_indices(t) == true )
std::cout << "Test passed." << std::endl;
else
{
std::cout << "Test failed." << std::endl;
exit( 0 ) ;
}

pB.begin_facet();
pB.add_vertex_to_facet(t[0]);
pB.add_vertex_to_facet(t[1]);
pB.add_vertex_to_facet(t[2]);
pB.end_facet();

pB.end_surface();
}

int main()
{
typedef CGAL::Simple_cartesian<double> Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef Polyhedron::HalfedgeDS HalfedgeDS;

Polyhedron P;
Build_Surface<HalfedgeDS> surface;
P.delegate(surface);
std::cout << "Done with surface building." << std::endl;
return 0;
}

#include <iostream>  // for cout
#include <stdlib.h>  // for exit

#include <CGAL/Simple_cartesian.h>
#include <CGAL/Triangle_3.h>
#include <CGAL/Polyhedron_incremental_builder_3.h>
#include <CGAL/Polyhedron_3.h>

template <class HDS>
class Build_Surface : public CGAL::Modifier_base<HDS>
{
public:
  Build_Surface() { }
  void operator()( HDS& hds );
};

template <class HDS>
void Build_Surface< HDS >::operator()( HDS &hds )
{
  /// Build a simple surface made of two triangles.
  CGAL::Polyhedron_incremental_builder_3<HDS> pB(hds, true);
  pB.begin_surface( 6, 2, 0);

  typedef typename HDS::Vertex::Point Point;
  pB.add_vertex( Point( 0.0, 0.0, 0.0));
  pB.add_vertex( Point( 1.0, 0.0, 0.0));
  pB.add_vertex( Point( 0.0, 1.0, 0.0));
  pB.add_vertex( Point( 0.0, 0.0, 1.0));
  pB.add_vertex( Point( 1.0, 1.0, 1.0));
  pB.add_vertex( Point( 1.0, 0.0, 1.0));

  // First triangle:
  pB.begin_facet();
    pB.add_vertex_to_facet(2);
    pB.add_vertex_to_facet(4);
    pB.add_vertex_to_facet(0);
  pB.end_facet();
  
  // Second triangle:
  std::vector< std::size_t> t;
  t.push_back(0); t.push_back(5); t.push_back(4);
  if( pB.test_facet_indices(t) == true )
    std::cout << "Test passed." << std::endl;
  else
  {
    std::cout << "Test failed." << std::endl;
    exit( 0 ) ;
  }

  pB.begin_facet();
    pB.add_vertex_to_facet(t[0]);
    pB.add_vertex_to_facet(t[1]);
    pB.add_vertex_to_facet(t[2]);
  pB.end_facet();

  pB.end_surface();
}

int main()
{
  typedef CGAL::Simple_cartesian<double> Kernel;
  typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
  typedef Polyhedron::HalfedgeDS HalfedgeDS;

  Polyhedron P;
  Build_Surface<HalfedgeDS> surface;
  P.delegate(surface);
  std::cout << "Done with surface building." << std::endl;
  return 0;
}




Archive powered by MHonArc 2.6.16.

Top of Page