Subject: CGAL users discussion list
List archive
- From: "Sebastien Loriot (GeometryFactory)" <>
- To:
- Subject: Re: [cgal-discuss] Getting indices from a Complex_2_in_triangulation_3
- Date: Tue, 15 Jul 2014 09:45:25 +0200
- Organization: GeometryFactory
On 07/12/2014 05:14 PM, donben wrote:
Hello and thank you for the impressive work on CGAL.
I'm beginning with the library and trying to use the Surface_mesher example.
What I want to do is to get positions and indices to feed VBOs that I can
display with glDrawArray.
Thanks to this post
(http://cgal-discuss.949826.n4.nabble.com/Need-to-write-facets-created-from-Implicit-surface-meshing-td951670.html)
I'm able to get the vertices of the Complex_2_in_triangulation_3 and display
them (nice skull !).
But my indices array seems uncorrect and the resulting displayed triangles
are disordered.
Is there a simple example code to build VBOs adn draw them ?
And how to access normals in the result if they are performed ?
Thank you and sorry for my bad english.
BenoƮt
If you're using something like the following:
const Vertex_handle vh1( c.vertex( (index + 1)%4 ) );
const Vertex_handle vh2( c.vertex( (index + 2)%4 ) );
const Vertex_handle vh3( c.vertex( (index + 3)%4 ) );
_face_indices.push_back( vh_to_index_map[vh1] );
_face_indices.push_back( vh_to_index_map[vh2] );
_face_indices.push_back( vh_to_index_map[vh3] );
your facets will be inconsistently oriented.
You need something like the following:
Vertex_handle vh1 = c.vertex( c2t2.vertex_triple_index(index,1)%4 );
Vertex_handle vh2 = c.vertex( c2t2.vertex_triple_index(index,2)%4 );
Vertex_handle vh3 = c.vertex( c2t2.vertex_triple_index(index,3)%4 );
No normal vector is computed in the c2t3.
Here is some pseudo code for one way to do it.
std::size_t nb_vertices=XXX;
std::vector< K::Vector_3 > normals(CGAL::NULL_VECTOR, nb_vertices);
std::vector< int > nb_incident_facets(0, nb_vertices);
foreach facet f:
K::Vector_3 n = normal of f; //using CGAL::cross_product
Vertex_handle vh1, vh2, vh3;
//assuming index_of(vh) is a function returning the id of vh
normals[index_of(vh1)] = normals[index_of(vh1)] + n;
++nb_incident_facets[index_of(vh1)];
//same for vh2, vh3
foreach vertex_handle vh:
normals[index_of(vh)] = normals[index_of(vh)] /
nb_incident_facets[index_of(vh1)];
// normals now contains non-normalized normal vector per vertex
HTH
Sebastien.
--
View this message in context:
http://cgal-discuss.949826.n4.nabble.com/Getting-indices-from-a-Complex-2-in-triangulation-3-tp4659553.html
Sent from the cgal-discuss mailing list archive at Nabble.com.
- [cgal-discuss] Getting indices from a Complex_2_in_triangulation_3, donben, 07/12/2014
- Re: [cgal-discuss] Getting indices from a Complex_2_in_triangulation_3, Sebastien Loriot (GeometryFactory), 07/15/2014
Archive powered by MHonArc 2.6.18.