Skip to Content.
Sympa Menu

cgal-discuss - Grey_level_image triangulation to STL file

Subject: CGAL users discussion list

List archive

Grey_level_image triangulation to STL file


Chronological Thread 
  • From:
  • To:
  • Subject: Grey_level_image triangulation to STL file
  • Date: Sun, 23 Sep 2007 12:30:29 +0200

Hi,

I'm trying to do a grey_level_image triangulation (like described in the
on-line manual Chapter X) and output the result into a STL file.

The 3d image triangulation seems to work fine but I just don't get it how to
extract the mesh faces (with their correct normal vector) to create the STL
output. I do get something similar to what I expect but a lot of faces have
inverted normal-vectors. Some faces are completely deteriorated.

Anyway, I'm not very familiar with the whole thing of geometric triangulation
(not with CGAL either). I read a lot of manuals and CGAL Lib documentation,
but this didn't help me to understand what would be the right soloution.

Here is how I tried to extract the surface triangles:

for ( CGAL::Surface_mesh_default_triangulation_3::Finite_facets_iterator i =
tr.finite_facets_begin(); i != tr.finite_facets_end(); ++i) {
Cell_handle h=i->first;

// if ( h->next()->next()->next() != h) {
// cerr << " format error: polyhedron in file is not
triangulated." << endl;
// exit( 1);
// }
Point p;
Point q;
Point r;

//ignore origin points
int index=0;
do {
p = h->vertex(index)->point();
++index;
} while ((p.x() < 0.1)&&(p.y() < 0.1)&&(p.z() <
0.1)&&(index<5));
do {
q = h->vertex(index)->point();
++index;
} while ((q.x() < 0.1)&&(q.y() < 0.1)&&(q.z() <
0.1)&&(index<5));
do {
r = h->vertex(index)->point();
++index;
} while ((r.x() < 0.1)&&(r.y() < 0.1)&&(r.z() <
0.1)&&(index<5));

// compute normal
Vector n;
n = CGAL::cross_product( q - p , r - p );
Vector norm = n / sqrt( n * n );
*p_out << " facet normal " << norm << endl;
*p_out << " outer loop " << endl;
*p_out << " vertex " << p << endl;
*p_out << " vertex " << q << endl;
*p_out << " vertex " << r << endl;
*p_out << " endloop " << endl;
*p_out << " endfacet " << endl;
}

Maybe someone could give me a hint about what I am doing wrong.

Is there a possibility to get the Surface Triangles of a Triangulation
directly instead of iterating through the facet-cells?

Thanks a lot, Tobi



Archive powered by MHonArc 2.6.16.

Top of Page