DiscussionsIssue archiveOther usage issues

Archived discussion

Indexed Mesh

Other usage issuesFri, 06/16/2006 - 19:151 reply

Browse this forum
QuestionAuthor

Hi,

How does one extract the indexed mesh data structure after faceting a BREP with BRepMesh::Mesh(TopoDS,dDeflection)?

The tessalate example shows how to perform a per face basis. Is this the only way to extract the facet details? Or can one simply apply faceting to the whole shape and then get the indexed mesh data for the facets?

Many thanks in advance,
Theo.

Discussion

1 archived reply

Posts are displayed in their archived order.

01Commenter-1

I use this code to create an indexed mesh:

m_vertscount = 0;
m_triscount = 0;

//counting vertices and triangles
for (TopExp_Explorer ex(topoShape, TopAbs_FACE) ; ex.More(); ex.Next())
{
F = TopoDS::Face(ex.Current());
facing = BRep_Tool::Triangulation(F,L);
if(facing.IsNull() == Standard_False)
{
m_triscount += facing->NbTriangles();
m_vertscount += facing->NbNodes();
}
else
{
TraceDebugFormattedStr("Creating model - GeoEntityTopo [","%i","] - failed to process a face.",entityIdentifier);
}
}

if(m_tris != NULL)
delete [] m_tris;
if(m_verts != NULL)
delete [] m_verts;

m_tris = new IndexedTriangle[m_triscount];
m_verts = new Point[m_vertscount];

int triscount = 0;
int vertscount = 0;

//assigning
for (TopExp_Explorer ex(topoShape, TopAbs_FACE) ; ex.More(); ex.Next()) {
F = TopoDS::Face(ex.Current());
facing = BRep_Tool::Triangulation(F,L);
if(facing.IsNull() == Standard_False)
{
int nbtris = facing->NbTriangles();
Poly_Array1OfTriangle tris(1, nbtris);
tris = facing->Triangles();
for (int i = 1; i <= nbtris; i++)
{
Poly_Triangle tri = tris.Value(i);
Standard_Integer index0, index1, index2;
tri.Get(index0, index1, index2);

m_tris[triscount] = IndexedTriangle(index0 + vertscount - 1, index1 + vertscount - 1, index2 + vertscount - 1 );
triscount += 1;
}

int nbnodes = facing->NbNodes();
TColgp_Array1OfPnt nodes(1, nbnodes);
nodes = facing->Nodes();

for (int i = 1; i <= nbnodes; i++)
{
gp_Pnt node = nodes.Value(i);

m_verts[vertscount] = Point((float)node.X(), (float)node.Y(), (float)node.Z());
vertscount += 1;
}
}

You have to leave out some variables that reference to not-OC objects (TraceDebug, etc.), but generally this code works.

Regards
Commenter-1