Overview
Here is code that you can reuse for common operations with meshes, faces, and facets.
Get All Facets in a Mesh
Use the getFacetCount() and the getFacet() functions to loop over all of the facets in a mesh. With each facet, use getVertex() and getNormal() to look up the coordinates of each vertex and components of each vertex normal.
RoseMesh * fs;
unsigned i, sz;
for (i=0, sz=fs->getFacetCount(); i< sz; i++)
{
const RoseMeshFacet * f = fs->getFacet(i);
const double * v0 = fs->getVertex(f->verts[0]);
const double * v1 = fs->getVertex(f->verts[1]);
const double * v2 = fs->getVertex(f->verts[2]);
const double * n0 = fs->getNormal(f->normals[0]);
const double * n1 = fs->getNormal(f->normals[1]);
const double * n2 = fs->getNormal(f->normals[2]);
printf(Facet #%u:\n
, i);
printf(\t (%g,%g,%g), normal (%g,%g,%g)\n
,
v0[0], v0[1], v0[2], n0[0], n0[1], n0[2]);
printf(\t (%g,%g,%g), normal (%g,%g,%g)\n
,
v1[0], v1[1], v1[2], n1[0], n1[1], n1[2]);
printf(\t (%g,%g,%g), normal (%g,%g,%g)\n
,
v2[0], v2[1], v2[2], n2[0], n2[1], n2[2]);
}
Get Each Face in a Mesh
Use the getFaceCount() and the getFace() functions to loop over each face in a mesh, and then proceed as above to work with the sequence of facets for the face.
RoseMesh * fs;
unsigned i, sz;
for (i=0, sz=fs-> getFaceCount(); i< sz; i++)
{
const RoseMeshFace * face = fs->getFace(i);
unsigned fnum = face->getFirstFacet();
unsigned fend = fnum + face->getFacetCount();
for (; fnum < fend; fnum++)
{
const RoseMeshFacet * f = fs->getFacet(fnum);
const double * v0 = fs->getVertex(f->verts[0]);
const double * v1 = fs->getVertex(f->verts[1]);
const double * v2 = fs->getVertex(f->verts[2]);
const double * n0 = fs->getNormal(f->normals[0]);
const double * n1 = fs->getNormal(f->normals[1]);
const double * n2 = fs->getNormal(f->normals[2]);
printf(Facet #%u:\n
, fnum);
printf(\t (%g,%g,%g), normal (%g,%g,%g)\n
,
v0[0], v0[1], v0[2], n0[0], n0[1], n0[2]);
printf(\t (%g,%g,%g), normal (%g,%g,%g)\n
,
v1[0], v1[1], v1[2], n1[0], n1[1], n1[2]);
printf(\t (%g,%g,%g), normal (%g,%g,%g)\n
,
v2[0], v2[1], v2[2], n2[0], n2[1], n2[2]);
}
}