Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] how to output a polyhedron to an obj file?

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] how to output a polyhedron to an obj file?


Chronological Thread 
  • From: Pierre Alliez <>
  • To:
  • Subject: Re: [cgal-discuss] how to output a polyhedron to an obj file?
  • Date: Sun, 29 Jun 2008 14:17:55 +0200
  • Organization: INRIA

hi Bill,

one solution is to hack something like (assume member function of your enriched polyhedron)

// write in obj file format (OBJ).
void write_obj(char *pFilename,
int incr = 1) // 1-based by default
{
std::ofstream stream(pFilename);

// output vertices
for(Point_iterator pPoint = points_begin();
pPoint != points_end();
pPoint++)
stream << 'v' << ' ' << pPoint->x() << ' ' <<
pPoint->y() << ' ' <<
pPoint->z() << std::endl;

// precompute vertex indices
this->set_index_vertices();

// this assumes you have defined an index per vertex
// and the function:

void set_index_vertices()
{
unsigned int index = 0;
for(Vertex_iterator v = vertices_begin();
v!= vertices_end();
v++)
v->index(index++);
}
// or something with a STL map to associate one index per vertex


// output facets
for(Facet_iterator pFacet = facets_begin();
pFacet != facets_end();
pFacet++)
{
stream << 'f';
Halfedge_around_facet_circulator pHalfedge = pFacet->facet_begin();
do
stream << ' ' << pHalfedge->vertex()->index()+incr;
while(++pHalfedge != pFacet->facet_begin());
stream << std::endl;
}
}



Archive powered by MHonArc 2.6.16.

Top of Page