Mon, 11/19/2018 - 16:31
TopoDS_Shape theShape = /* load a shape*/
//required variable declaration
Standard_Boolean bDone = Standard_False;
Standard_Real aU, aV;
Standard_Integer NbAlongU = 1, theNbAlongU = 1, NbAlongV = 1, theNbAlongV=1, theLength = 10;
Standard_Real NormalLength;
Standard_Boolean ToUseMesh = Standard_False;
Standard_Boolean ToOrient = Standard_True;
//explore faces
for (TopExp_Explorer aFe(theShape, TopAbs_FACE); aFe.More(); aFe.Next())
{
// one face loaded to aFace from theshape
const TopoDS_Face& aFace = TopoDS::Face(aFe.Current());
//required variable declaration
Standard_Real aUmin = 0.0, aVmin = 0.0, aUmax = 0.0, aVmax = 0.0;
BRepTools::UVBounds(aFace, aUmin, aUmax, aVmin, aVmax);
const Standard_Boolean isUseMidU = (theNbAlongU == 1);
const Standard_Boolean isUseMidV = (theNbAlongV == 1);
const Standard_Real aDU = (aUmax - aUmin) / (isUseMidU ? 2 : (theNbAlongU - 1));
const Standard_Real aDV = (aVmax - aVmin) / (isUseMidV ? 2 : (theNbAlongV - 1));
BRepAdaptor_Surface aSurface(aFace);
for (Standard_Integer aUIter = 0; aUIter < theNbAlongU; ++aUIter)
{
const Standard_Real aU = aUmin + (isUseMidU ? 1 : aUIter) * aDU;
for (Standard_Integer aVIter = 0; aVIter < theNbAlongV; ++aVIter)
{
const Standard_Real aV = aVmin + (isUseMidV ? 1 : aVIter) * aDV;
gp_Pnt aP1;
gp_Vec aV1, aV2;
aSurface.D1(aU, aV, aP1, aV1, aV2);
gp_Vec aVec = aV1.Crossed(aV2);
Standard_Real aNormalLen = aVec.Magnitude();
if (aFace.Orientation() == TopAbs_REVERSED) {
aVec.Reverse();
}
//aVec is the normal vector of the face explored
}
}
}