How to obtain a closed mesh for a solid

Dear all,
I need to mesh a solid shape and obtain a "closed" mesh, so that vertices are not
repeated, for example if I mesh a cube I would like to obtain 8 vertices and 12 triangles pointing those veritces.

At the moment I'm only able to triangulate each face and read the single meshes, however in this way my vertices are all repeated and for the cube I get 24 vertices.

How can this be done?

This is the code I'm using now, but as you can see it meshes a single face at a time and fills up a list of vertices and lists of indices.

BRepMesh::Mesh(shape,0.5);
Standard_Integer result(0);

int count = 0;
for (TopExp_Explorer ex(shape,TopAbs_FACE) ; ex.More(); ex.Next()) {
TopoDS_Face F =TopoDS::Face(ex.Current());

TopLoc_Location L;
Handle (Poly_Triangulation) facing = BRep_Tool::Triangulation(F,L);
result = result + facing->NbTriangles();

TColgp_Array1OfPnt tab(1,(facing->NbNodes()));
tab = facing->Nodes();
for (Standard_Integer i=0; iNbNodes(); i++)
{
points.push_back(tab.Value(i+1));
}

//Prendiamo i triangoli considerando l'orientamento della faccia
const Poly_Array1OfTriangle& triangles = facing->Triangles();
Standard_Integer nbTriangles = 0, n1, n2, n3;
nbTriangles = facing->NbTriangles();
for(Standard_Integer tr = 1 ; tr {
triangles(tr).Get(n1, n2, n3);
TopAbs_Orientation orient = F.Orientation();

//Orientiamo correttamente le normali
if(orient == TopAbs_REVERSED)
{
aIndex.push_back(n3+count);
bIndex.push_back(n2+count);
cIndex.push_back(n1+count);
}
else
{
aIndex.push_back(n1+count);
bIndex.push_back(n2+count);
cIndex.push_back(n3+count);
}
}

count+=facing->NbNodes();
}

Anup's picture

Hi Silvia,

U know more about meshing actually When i import IGES File and go with triangulation using BRep_Tool::Triangulation(aFace,aLoc) is it possible to change triangles in counterclockwise order??? if i change it then i can easily import using coin3D s inbuilt STL library. Please help me, coz even u have posted this change of orientation here.

Thanks & Regards
Anup

Silvia's picture

Hi Anup,
I don't know much about IGES import, however if you have a face then I guess you can use the code I wrote above.
The idea is that the triangulation of a face is computed according to the surface orientation, so if a face orientation is reversed (i.e. the face orientation is opposite to the surface orientation) you need to flip triangles as I do in that code.
In order to change the triangle orientation you only need to change the order of two vertex indeces.

Hope this help, cheers

Silvia

Anup's picture

Hi Silvia,

I got little bit idea on doing it, I used BRepTools_ReShape to change the orientation of the face.

Handle(BRepTools_ReShape) reshaper = new BRepTools_ReShape();

reshaper->ModeConsiderOrientation() = Standard_True;
for (TopExp_Explorer Ex1(myShape,TopAbs_FACE); Ex1.More(); Ex1.Next())
{
TopoDS_Face anFace1 = TopoDS::Face(Ex1.Current());
TopAbs_Orientation oriF1 = anFace1.Orientation();
if(oriF1 == TopAbs_REVERSED)
{
TopoDS_Shape anFace2 = anFace1.Complemented();
reshaper->Replace(anFace1, anFace2, Standard_True );
}

/*else if (oriF1 == TopAbs_FORWARD)
{
reshaper->Replace(anFace1, anFace1, Standard_True);
}*/
}

From the above code can u tell me where i have gone wrong after orienting the face should i use ur part of code to orient the traingles too. or orientation of face will be enough??

Thanks & Regards
Anup

Anup's picture

Hi Silvia,

I got little bit idea on doing it, I used BRepTools_ReShape to change the orientation of the face.

Handle(BRepTools_ReShape) reshaper = new BRepTools_ReShape();

reshaper->ModeConsiderOrientation() = Standard_True;
for (TopExp_Explorer Ex1(myShape,TopAbs_FACE); Ex1.More(); Ex1.Next())
{
TopoDS_Face anFace1 = TopoDS::Face(Ex1.Current());
TopAbs_Orientation oriF1 = anFace1.Orientation();
if(oriF1 == TopAbs_REVERSED)
{
TopoDS_Shape anFace2 = anFace1.Complemented();
reshaper->Replace(anFace1, anFace2, Standard_True );
}

/*else if (oriF1 == TopAbs_FORWARD)
{
reshaper->Replace(anFace1, anFace1, Standard_True);
}*/
}

From the above code can u tell me where i have gone wrong after orienting the face should i use ur part of code to orient the traingles too. or orientation of face will be enough??

Thanks & Regards
Anup