Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] Construct Polyhedron from points

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] Construct Polyhedron from points


Chronological Thread 
  • From: Matthias Teich <>
  • To:
  • Subject: Re: [cgal-discuss] Construct Polyhedron from points
  • Date: Mon, 27 Jul 2009 10:46:03 +0200

Hi!

My first guess would be that your input mesh contains multiple vertices, e.g that your cube mesh has not only 8 vertices.
I used a very similar code to transform my Mesh to CGAL.



Icek schrieb:
Hello, Im trying to construct Polyhedron from my mesh structure. And then
NefPolyhedron from polyhedron. I found that I have to use Incremental
builder, but resulting polyhedron is_closed() is always false, even when my
mesh is simple cube. And NefPolyheron requires closed polyhedron, so is this
piece of code right? Or how do I create polyhedron from points?
template <class HDS> class PolyhedronFromMesh : public
CGAL::Modifier_base<HDS> {
public:
PolyhedronFromMesh(const Mesh & mesh) : _mesh(mesh)
{

}

void operator()( HDS& hds)
{
// Postcondition: `hds' is a valid polyhedral surface.
CGAL::Polyhedron_incremental_builder_3<HDS> B( hds, false);

typedef typename HDS::Vertex Vertex;
typedef typename Vertex::Point Point;

unsigned int nPoints = _mesh.Points.size();
unsigned int nFacets = _mesh.Indices.size() ? _mesh.Indices.size()
/ 3 : nPoints / 3;

B.begin_surface(nPoints,nFacets);

for(unsigned int i = 0; i < nPoints; i++)
{
Vec3 p = _mesh.Points[i]; B.add_vertex(Point(p.x,p.y, p.z));
}

if(_mesh.Indices.size())
for(unsigned int i=0; i < _mesh.Indices.size(); i+=3)
{
B.begin_facet();
B.add_vertex_to_facet((long unsigned int)_mesh.Indices[i]);
B.add_vertex_to_facet((long unsigned int)_mesh.Indices[i+1]);
B.add_vertex_to_facet((long unsigned int)_mesh.Indices[i+2]);
B.end_facet();
}
else
for(unsigned int i=0; i < _mesh.Indices.size(); i+=3)
{
B.begin_facet();
B.add_vertex_to_facet( i);
B.add_vertex_to_facet( i+1);
B.add_vertex_to_facet( i+2);
B.end_facet();
}

B.end_surface();
}

const Mesh & _mesh;
};

------------------------------------------------------------------------


Eingehende eMail ist virenfrei.
Von AVG uberpruft - www.avg.de Version: 8.5.375 / Virendatenbank: 270.13.31/2265 - Ausgabedatum: 07/26/09 17:59:00




Archive powered by MHonArc 2.6.16.

Top of Page