Thu, 08/03/2017 - 11:12
Forums:
Hi Guys,
I am following the shape fixing examples in the documentation and I have the following code.
Standard_Real sphere_radius = 100.0;
TopoDS_Shape aShape = BRepPrimAPI_MakeSphere( sphere_radius ).Shape();
BRepMesh_IncrementalMesh ( aShape, 0.9 );
I know that the sphere shape created from this will contain some edges / triangles that are degenerate so I tried the following ...
Handle(ShapeFix_FixSmallFace) sffsm = new ShapeFix_FixSmallFace();
sffsm -> Init (aShape);
sffsm -> SetPrecision (1e-3);
sffsm -> Perform();
aShape = sffsm -> FixShape();
Following this I attempted to iterate through the faces of the shape.
namespace
{
// Tool to get triangles from triangulation taking into account face
// orientation and location
class TriangleAccessor
{
public:
TriangleAccessor (const TopoDS_Face& aFace)
{
TopLoc_Location aLoc;
myPoly = BRep_Tool::Triangulation (aFace, aLoc);
myTrsf = aLoc.Transformation();
myNbTriangles = (myPoly.IsNull() ? 0 : myPoly->Triangles().Length());
myInvert = (aFace.Orientation() == TopAbs_REVERSED);
if (myTrsf.IsNegative())
myInvert = ! myInvert;
}
int NbTriangles () const { return myNbTriangles; }
// get i-th triangle and outward normal
void GetTriangle (int iTri, gp_Vec &theNormal, gp_Pnt &thePnt1, gp_Pnt &thePnt2, gp_Pnt &thePnt3)
{
// get positions of nodes
int iNode1, iNode2, iNode3;
myPoly->Triangles()(iTri).Get (iNode1, iNode2, iNode3);
thePnt1 = myPoly->Nodes()(iNode1);
thePnt2 = myPoly->Nodes()(myInvert ? iNode3 : iNode2);
thePnt3 = myPoly->Nodes()(myInvert ? iNode2 : iNode3);
// apply transormation if not identity
if (myTrsf.Form() != gp_Identity)
{
thePnt1.Transform (myTrsf);
thePnt2.Transform (myTrsf);
thePnt3.Transform (myTrsf);
}
// calculate normal
theNormal = (thePnt2.XYZ() - thePnt1.XYZ()) ^ (thePnt3.XYZ() - thePnt1.XYZ());
Standard_Real aNorm = theNormal.Magnitude();
if (aNorm > gp::Resolution()) theNormal /= aNorm;
}
private:
Handle(Poly_Triangulation) myPoly;
gp_Trsf myTrsf;
int myNbTriangles;
bool myInvert;
};
}
for (TopExp_Explorer exp (aShape , TopAbs_FACE); exp.More(); exp.Next())
{
TriangleAccessor aTool (TopoDS::Face (exp.Current()));
std::cout << aTool.NbTriangles() << std::endl;
}
But i find the aShape is now empty. Do I need to build the incremental mesh again? What was wrong with my approach here?
Thanks !