1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

Coding - Apply .clang-format formatting #286

Update empty method guards to new style with regex (see PR).
Used clang-format 18.1.8.
New actions to validate code formatting is added.
Update .clang-format with disabling of include sorting.
  It is temporary changes, then include will be sorted.
Apply formatting for /src and /tools folder.
The files with .hxx,.cxx,.lxx,.h,.pxx,.hpp,*.cpp extensions.
This commit is contained in:
dpasukhi
2025-01-25 20:15:22 +00:00
parent dbba6f1289
commit a5a7b3185b
14005 changed files with 1273539 additions and 1195567 deletions

View File

@@ -12,7 +12,6 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <Bnd_Box.hxx>
#include <BndLib_Add3dCurve.hxx>
#include <BndLib_AddSurface.hxx>
@@ -47,29 +46,38 @@
//
static Standard_Boolean CanUseEdges(const Adaptor3d_Surface& BS);
//
static void FindExactUVBounds(const TopoDS_Face& F,
Standard_Real& umin, Standard_Real& umax,
Standard_Real& vmin, Standard_Real& vmax,
const Standard_Real Tol,
Standard_Boolean& isNaturalRestriction);
static void FindExactUVBounds(const TopoDS_Face& F,
Standard_Real& umin,
Standard_Real& umax,
Standard_Real& vmin,
Standard_Real& vmax,
const Standard_Real Tol,
Standard_Boolean& isNaturalRestriction);
//
static void AdjustFaceBox(const BRepAdaptor_Surface& BS,
const Standard_Real umin, const Standard_Real umax,
const Standard_Real vmin, const Standard_Real vmax,
Bnd_Box& FaceBox,
const Bnd_Box& EdgeBox, const Standard_Real Tol);
static void AdjustFaceBox(const BRepAdaptor_Surface& BS,
const Standard_Real umin,
const Standard_Real umax,
const Standard_Real vmin,
const Standard_Real vmax,
Bnd_Box& FaceBox,
const Bnd_Box& EdgeBox,
const Standard_Real Tol);
//
static Standard_Boolean IsModifySize(const BRepAdaptor_Surface& theBS,
const gp_Pln& thePln, const gp_Pnt& theP,
const Standard_Real umin, const Standard_Real umax,
const Standard_Real vmin, const Standard_Real vmax,
static Standard_Boolean IsModifySize(const BRepAdaptor_Surface& theBS,
const gp_Pln& thePln,
const gp_Pnt& theP,
const Standard_Real umin,
const Standard_Real umax,
const Standard_Real vmin,
const Standard_Real vmax,
const BRepTopAdaptor_FClass2d& theFClass,
const Standard_Real theTolU, const Standard_Real theTolV);
const Standard_Real theTolU,
const Standard_Real theTolV);
//
//=======================================================================
//function : Add
//purpose : Add a shape bounding to a box
// function : Add
// purpose : Add a shape bounding to a box
//=======================================================================
void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B, Standard_Boolean useTriangulation)
{
@@ -77,40 +85,48 @@ void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B, Standard_Boolean useTria
// Add the faces
BRepAdaptor_Surface BS;
TopLoc_Location l, aDummyLoc;
Standard_Integer i, nbNodes;
BRepAdaptor_Curve BC;
TopLoc_Location l, aDummyLoc;
Standard_Integer i, nbNodes;
BRepAdaptor_Curve BC;
for (ex.Init(S,TopAbs_FACE); ex.More(); ex.Next()) {
const TopoDS_Face& F = TopoDS::Face(ex.Current());
const Handle(Poly_Triangulation)& T = BRep_Tool::Triangulation(F, l);
const Handle(Geom_Surface)& GS = BRep_Tool::Surface (F, aDummyLoc);
if ((useTriangulation || GS.IsNull()) && !T.IsNull() && T->MinMax (B, l))
for (ex.Init(S, TopAbs_FACE); ex.More(); ex.Next())
{
const TopoDS_Face& F = TopoDS::Face(ex.Current());
const Handle(Poly_Triangulation)& T = BRep_Tool::Triangulation(F, l);
const Handle(Geom_Surface)& GS = BRep_Tool::Surface(F, aDummyLoc);
if ((useTriangulation || GS.IsNull()) && !T.IsNull() && T->MinMax(B, l))
{
// B.Enlarge(T->Deflection());
B.Enlarge (T->Deflection() + BRep_Tool::Tolerance (F));
} else
B.Enlarge(T->Deflection() + BRep_Tool::Tolerance(F));
}
else
{
if (!GS.IsNull()) {
if (!GS.IsNull())
{
BS.Initialize(F, Standard_False);
if (BS.GetType() != GeomAbs_Plane) {
if (BS.GetType() != GeomAbs_Plane)
{
BS.Initialize(F);
BndLib_AddSurface::Add(BS, BRep_Tool::Tolerance(F), B);
}
else {
else
{
// on travaille directement sur les courbes 3d.
TopExp_Explorer ex2(F, TopAbs_EDGE);
if (!ex2.More()) {
if (!ex2.More())
{
BS.Initialize(F);
BndLib_AddSurface::Add(BS, BRep_Tool::Tolerance(F), B);
}
else {
for (;ex2.More();ex2.Next()) {
else
{
for (; ex2.More(); ex2.Next())
{
const TopoDS_Edge& anEdge = TopoDS::Edge(ex2.Current());
if (BRep_Tool::IsGeometric (anEdge))
if (BRep_Tool::IsGeometric(anEdge))
{
BC.Initialize (anEdge);
BndLib_Add3dCurve::Add (BC, BRep_Tool::Tolerance (anEdge), B);
BC.Initialize(anEdge);
BndLib_Add3dCurve::Add(BC, BRep_Tool::Tolerance(anEdge), B);
}
}
B.Enlarge(BRep_Tool::Tolerance(F));
@@ -121,13 +137,13 @@ void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B, Standard_Boolean useTria
}
// Add the edges not in faces
Handle(TColStd_HArray1OfInteger) HIndices;
Handle(TColStd_HArray1OfInteger) HIndices;
Handle(Poly_PolygonOnTriangulation) Poly;
Handle(Poly_Triangulation) T;
for (ex.Init(S,TopAbs_EDGE,TopAbs_FACE); ex.More(); ex.Next())
Handle(Poly_Triangulation) T;
for (ex.Init(S, TopAbs_EDGE, TopAbs_FACE); ex.More(); ex.Next())
{
const TopoDS_Edge& E = TopoDS::Edge(ex.Current());
if (!useTriangulation && BRep_Tool::IsGeometric(E))
{
BC.Initialize(E);
@@ -139,11 +155,13 @@ void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B, Standard_Boolean useTria
if (!P3d.IsNull() && P3d->NbNodes() > 0)
{
const TColgp_Array1OfPnt& Nodes = P3d->Nodes();
nbNodes = P3d->NbNodes();
nbNodes = P3d->NbNodes();
for (i = 1; i <= nbNodes; i++)
{
if (l.IsIdentity()) B.Add(Nodes[i]);
else B.Add(Nodes[i].Transformed(l));
if (l.IsIdentity())
B.Add(Nodes[i]);
else
B.Add(Nodes[i].Transformed(l));
}
// B.Enlarge(P3d->Deflection());
B.Enlarge(P3d->Deflection() + BRep_Tool::Tolerance(E));
@@ -154,25 +172,26 @@ void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B, Standard_Boolean useTria
if (!Poly.IsNull() && !T.IsNull() && T->NbNodes() > 0)
{
const TColStd_Array1OfInteger& Indices = Poly->Nodes();
nbNodes = Indices.Length();
nbNodes = Indices.Length();
if (l.IsIdentity())
{
for (i = 1; i <= nbNodes; i++)
{
B.Add (T->Node (Indices[i]));
B.Add(T->Node(Indices[i]));
}
}
else
{
for (i = 1; i <= nbNodes; i++)
{
B.Add (T->Node (Indices[i]).Transformed (l));
B.Add(T->Node(Indices[i]).Transformed(l));
}
}
// B.Enlarge(T->Deflection());
B.Enlarge(Poly->Deflection() + BRep_Tool::Tolerance(E));
}
else {
else
{
if (BRep_Tool::IsGeometric(E))
{
BC.Initialize(E);
@@ -184,17 +203,16 @@ void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B, Standard_Boolean useTria
// Add the vertices not in edges
for (ex.Init(S,TopAbs_VERTEX,TopAbs_EDGE); ex.More(); ex.Next()) {
for (ex.Init(S, TopAbs_VERTEX, TopAbs_EDGE); ex.More(); ex.Next())
{
B.Add(BRep_Tool::Pnt(TopoDS::Vertex(ex.Current())));
B.Enlarge(BRep_Tool::Tolerance(TopoDS::Vertex(ex.Current())));
}
}
//=======================================================================
//function : AddClose
//purpose : Add a precise shape bounding to a box
// function : AddClose
// purpose : Add a precise shape bounding to a box
//=======================================================================
void BRepBndLib::AddClose(const TopoDS_Shape& S, Bnd_Box& B)
@@ -207,44 +225,48 @@ void BRepBndLib::AddClose(const TopoDS_Shape& S, Bnd_Box& B)
BRepAdaptor_Curve BC;
for (ex.Init(S,TopAbs_EDGE); ex.More(); ex.Next()) {
const TopoDS_Edge& anEdge = TopoDS::Edge (ex.Current());
if (BRep_Tool::IsGeometric (anEdge))
for (ex.Init(S, TopAbs_EDGE); ex.More(); ex.Next())
{
const TopoDS_Edge& anEdge = TopoDS::Edge(ex.Current());
if (BRep_Tool::IsGeometric(anEdge))
{
BC.Initialize (anEdge);
BndLib_Add3dCurve::Add(BC,0.,B);
BC.Initialize(anEdge);
BndLib_Add3dCurve::Add(BC, 0., B);
}
}
// Add the vertices not in edges
for (ex.Init(S,TopAbs_VERTEX,TopAbs_EDGE); ex.More(); ex.Next()) {
for (ex.Init(S, TopAbs_VERTEX, TopAbs_EDGE); ex.More(); ex.Next())
{
B.Add(BRep_Tool::Pnt(TopoDS::Vertex(ex.Current())));
}
}
//=======================================================================
//function : AddOptimal
//purpose : Add a shape bounding to a box
// function : AddOptimal
// purpose : Add a shape bounding to a box
//=======================================================================
void BRepBndLib::AddOptimal(const TopoDS_Shape& S, Bnd_Box& B,
const Standard_Boolean useTriangulation,
void BRepBndLib::AddOptimal(const TopoDS_Shape& S,
Bnd_Box& B,
const Standard_Boolean useTriangulation,
const Standard_Boolean useShapeTolerance)
{
TopExp_Explorer ex;
// Add the faces
BRepAdaptor_Surface BS;
BRepAdaptor_Surface BS;
Handle(Poly_Triangulation) T;
TopLoc_Location l;
Standard_Integer i, nbNodes;
BRepAdaptor_Curve BC;
TopLoc_Location l;
Standard_Integer i, nbNodes;
BRepAdaptor_Curve BC;
for (ex.Init(S,TopAbs_FACE); ex.More(); ex.Next()) {
for (ex.Init(S, TopAbs_FACE); ex.More(); ex.Next())
{
const TopoDS_Face& F = TopoDS::Face(ex.Current());
T = BRep_Tool::Triangulation(F, l);
T = BRep_Tool::Triangulation(F, l);
Bnd_Box aLocBox;
if (useTriangulation && !T.IsNull() && T->MinMax (aLocBox, l))
if (useTriangulation && !T.IsNull() && T->MinMax(aLocBox, l))
{
// B.Enlarge(T->Deflection());
aLocBox.Enlarge(T->Deflection() + BRep_Tool::Tolerance(F));
@@ -255,27 +277,31 @@ void BRepBndLib::AddOptimal(const TopoDS_Shape& S, Bnd_Box& B,
else
{
const Handle(Geom_Surface)& GS = BRep_Tool::Surface(F, l);
if (!GS.IsNull()) {
if (!GS.IsNull())
{
BS.Initialize(F, Standard_False);
if (CanUseEdges(BS)) {
if (CanUseEdges(BS))
{
TopExp_Explorer ex2(F, TopAbs_EDGE);
if (!ex2.More()) {
if (!ex2.More())
{
BS.Initialize(F);
Standard_Real Tol = useShapeTolerance? BRep_Tool::Tolerance(F) : 0.;
Standard_Real Tol = useShapeTolerance ? BRep_Tool::Tolerance(F) : 0.;
BndLib_AddSurface::AddOptimal(BS, Tol, aLocBox);
}
else
{
Standard_Real Tol;
for (;ex2.More();ex2.Next()) {
Bnd_Box anEBox;
for (; ex2.More(); ex2.Next())
{
Bnd_Box anEBox;
const TopoDS_Edge& anE = TopoDS::Edge(ex2.Current());
if (BRep_Tool::Degenerated (anE) || !BRep_Tool::IsGeometric (anE))
if (BRep_Tool::Degenerated(anE) || !BRep_Tool::IsGeometric(anE))
{
continue;
}
BC.Initialize(anE);
Tol = useShapeTolerance? BRep_Tool::Tolerance(anE) : 0.;
Tol = useShapeTolerance ? BRep_Tool::Tolerance(anE) : 0.;
BndLib_Add3dCurve::AddOptimal(BC, Tol, anEBox);
aLocBox.Add(anEBox);
}
@@ -283,32 +309,31 @@ void BRepBndLib::AddOptimal(const TopoDS_Shape& S, Bnd_Box& B,
}
else
{
Standard_Real umin, umax, vmin, vmax;
Standard_Real umin, umax, vmin, vmax;
Standard_Boolean isNaturalRestriction = Standard_False;
Standard_Real Tol = useShapeTolerance? BRep_Tool::Tolerance(F) : 0.;
Standard_Real Tol = useShapeTolerance ? BRep_Tool::Tolerance(F) : 0.;
FindExactUVBounds(F, umin, umax, vmin, vmax, Tol, isNaturalRestriction);
BndLib_AddSurface::AddOptimal(BS, umin, umax, vmin, vmax,
Tol, aLocBox);
BndLib_AddSurface::AddOptimal(BS, umin, umax, vmin, vmax, Tol, aLocBox);
//
if(!isNaturalRestriction)
if (!isNaturalRestriction)
{
TopExp_Explorer ex2(F, TopAbs_EDGE);
Bnd_Box EBox;
for (;ex2.More();ex2.Next()) {
Bnd_Box anEBox;
Bnd_Box EBox;
for (; ex2.More(); ex2.Next())
{
Bnd_Box anEBox;
const TopoDS_Edge& anE = TopoDS::Edge(ex2.Current());
if (BRep_Tool::Degenerated (anE) || !BRep_Tool::IsGeometric (anE))
if (BRep_Tool::Degenerated(anE) || !BRep_Tool::IsGeometric(anE))
{
continue;
}
BC.Initialize(anE);
Tol = useShapeTolerance? BRep_Tool::Tolerance(anE) : 0.;
Tol = useShapeTolerance ? BRep_Tool::Tolerance(anE) : 0.;
BndLib_Add3dCurve::AddOptimal(BC, Tol, anEBox);
EBox.Add(anEBox);
}
Tol = useShapeTolerance? BRep_Tool::Tolerance(F) : 0.;
AdjustFaceBox(BS, umin, umax, vmin, vmax, aLocBox, EBox,
Tol);
Tol = useShapeTolerance ? BRep_Tool::Tolerance(F) : 0.;
AdjustFaceBox(BS, umin, umax, vmin, vmax, aLocBox, EBox, Tol);
}
}
@@ -323,24 +348,26 @@ void BRepBndLib::AddOptimal(const TopoDS_Shape& S, Bnd_Box& B,
}
// Add the edges not in faces
Handle(TColStd_HArray1OfInteger) HIndices;
Handle(TColStd_HArray1OfInteger) HIndices;
Handle(Poly_PolygonOnTriangulation) Poly;
for (ex.Init(S,TopAbs_EDGE,TopAbs_FACE); ex.More(); ex.Next())
for (ex.Init(S, TopAbs_EDGE, TopAbs_FACE); ex.More(); ex.Next())
{
const TopoDS_Edge& E = TopoDS::Edge(ex.Current());
Bnd_Box aLocBox;
const TopoDS_Edge& E = TopoDS::Edge(ex.Current());
Bnd_Box aLocBox;
Handle(Poly_Polygon3D) P3d = BRep_Tool::Polygon3D(E, l);
if (useTriangulation && !P3d.IsNull() && P3d->NbNodes() > 0)
{
const TColgp_Array1OfPnt& Nodes = P3d->Nodes();
nbNodes = P3d->NbNodes();
nbNodes = P3d->NbNodes();
for (i = 1; i <= nbNodes; i++)
{
if (l.IsIdentity()) aLocBox.Add(Nodes[i]);
else aLocBox.Add(Nodes[i].Transformed(l));
if (l.IsIdentity())
aLocBox.Add(Nodes[i]);
else
aLocBox.Add(Nodes[i].Transformed(l));
}
Standard_Real Tol = useShapeTolerance? BRep_Tool::Tolerance(E) : 0.;
Standard_Real Tol = useShapeTolerance ? BRep_Tool::Tolerance(E) : 0.;
aLocBox.Enlarge(P3d->Deflection() + Tol);
}
else
@@ -349,26 +376,27 @@ void BRepBndLib::AddOptimal(const TopoDS_Shape& S, Bnd_Box& B,
if (useTriangulation && !Poly.IsNull() && !T.IsNull() && T->NbNodes() > 0)
{
const TColStd_Array1OfInteger& Indices = Poly->Nodes();
nbNodes = Indices.Length();
nbNodes = Indices.Length();
for (i = 1; i <= nbNodes; i++)
{
if (l.IsIdentity())
{
aLocBox.Add (T->Node (Indices[i]));
aLocBox.Add(T->Node(Indices[i]));
}
else
{
aLocBox.Add (T->Node (Indices[i]).Transformed (l));
aLocBox.Add(T->Node(Indices[i]).Transformed(l));
}
}
Standard_Real Tol = useShapeTolerance? BRep_Tool::Tolerance(E) : 0.;
Standard_Real Tol = useShapeTolerance ? BRep_Tool::Tolerance(E) : 0.;
aLocBox.Enlarge(Poly->Deflection() + Tol);
}
else {
else
{
if (BRep_Tool::IsGeometric(E))
{
BC.Initialize(E);
Standard_Real Tol = useShapeTolerance? BRep_Tool::Tolerance(E) : 0.;
Standard_Real Tol = useShapeTolerance ? BRep_Tool::Tolerance(E) : 0.;
BndLib_Add3dCurve::AddOptimal(BC, Tol, aLocBox);
}
}
@@ -383,11 +411,12 @@ void BRepBndLib::AddOptimal(const TopoDS_Shape& S, Bnd_Box& B,
// Add the vertices not in edges
for (ex.Init(S,TopAbs_VERTEX,TopAbs_EDGE); ex.More(); ex.Next()) {
Bnd_Box aLocBox;
for (ex.Init(S, TopAbs_VERTEX, TopAbs_EDGE); ex.More(); ex.Next())
{
Bnd_Box aLocBox;
const TopoDS_Vertex& aV = TopoDS::Vertex(ex.Current());
aLocBox.Add(BRep_Tool::Pnt(aV));
Standard_Real Tol = useShapeTolerance? BRep_Tool::Tolerance(aV) : 0.;
Standard_Real Tol = useShapeTolerance ? BRep_Tool::Tolerance(aV) : 0.;
aLocBox.Enlarge(Tol);
Standard_Real xmin, ymin, zmin, xmax, ymax, zmax;
aLocBox.Get(xmin, ymin, zmin, xmax, ymax, zmax);
@@ -396,24 +425,22 @@ void BRepBndLib::AddOptimal(const TopoDS_Shape& S, Bnd_Box& B,
}
//=======================================================================
//function : CanUseEdges
//purpose : Define is it possible using only edges bnd boxes
// function : CanUseEdges
// purpose : Define is it possible using only edges bnd boxes
// to get face bnd box
//=======================================================================
Standard_Boolean CanUseEdges(const Adaptor3d_Surface& BS)
{
GeomAbs_SurfaceType aST = BS.GetType();
if(aST == GeomAbs_Plane ||
aST == GeomAbs_Cylinder ||
aST == GeomAbs_Cone ||
aST == GeomAbs_SurfaceOfExtrusion)
if (aST == GeomAbs_Plane || aST == GeomAbs_Cylinder || aST == GeomAbs_Cone
|| aST == GeomAbs_SurfaceOfExtrusion)
{
return Standard_True;
}
else if(aST == GeomAbs_SurfaceOfRevolution)
else if (aST == GeomAbs_SurfaceOfRevolution)
{
const Handle(Adaptor3d_Curve)& aBC = BS.BasisCurve();
if(aBC->GetType() == GeomAbs_Line)
if (aBC->GetType() == GeomAbs_Line)
{
return Standard_True;
}
@@ -422,16 +449,16 @@ Standard_Boolean CanUseEdges(const Adaptor3d_Surface& BS)
return Standard_False;
}
}
else if(aST == GeomAbs_OffsetSurface)
else if (aST == GeomAbs_OffsetSurface)
{
const Handle(Adaptor3d_Surface)& aS = BS.BasisSurface();
return CanUseEdges (*aS);
return CanUseEdges(*aS);
}
else if(aST == GeomAbs_BSplineSurface)
else if (aST == GeomAbs_BSplineSurface)
{
Handle(Geom_BSplineSurface) aBSpl = BS.BSpline();
if((aBSpl->UDegree() == 1 && aBSpl->NbUKnots() == 2) ||
(aBSpl->VDegree() == 1 && aBSpl->NbVKnots() == 2))
if ((aBSpl->UDegree() == 1 && aBSpl->NbUKnots() == 2)
|| (aBSpl->VDegree() == 1 && aBSpl->NbVKnots() == 2))
{
return Standard_True;
}
@@ -440,11 +467,10 @@ Standard_Boolean CanUseEdges(const Adaptor3d_Surface& BS)
return Standard_False;
}
}
else if(aST == GeomAbs_BezierSurface)
else if (aST == GeomAbs_BezierSurface)
{
Handle(Geom_BezierSurface) aBz = BS.Bezier();
if((aBz->UDegree() == 1 ) ||
(aBz->VDegree() == 1 ))
if ((aBz->UDegree() == 1) || (aBz->VDegree() == 1))
{
return Standard_True;
}
@@ -456,54 +482,55 @@ Standard_Boolean CanUseEdges(const Adaptor3d_Surface& BS)
return Standard_False;
}
//=======================================================================
//function : FindExactUVBounds
//purpose :
//=======================================================================
void FindExactUVBounds(const TopoDS_Face& FF,
Standard_Real& umin, Standard_Real& umax,
Standard_Real& vmin, Standard_Real& vmax,
const Standard_Real Tol,
Standard_Boolean& isNaturalRestriction)
//=================================================================================================
void FindExactUVBounds(const TopoDS_Face& FF,
Standard_Real& umin,
Standard_Real& umax,
Standard_Real& vmin,
Standard_Real& vmax,
const Standard_Real Tol,
Standard_Boolean& isNaturalRestriction)
{
TopoDS_Face F = FF;
F.Orientation(TopAbs_FORWARD);
TopExp_Explorer ex(F,TopAbs_EDGE);
TopExp_Explorer ex(F, TopAbs_EDGE);
//
//Check Natural restriction
isNaturalRestriction = BRep_Tool::NaturalRestriction(F); //Can we trust this flag?
// Check Natural restriction
isNaturalRestriction = BRep_Tool::NaturalRestriction(F); // Can we trust this flag?
BRepAdaptor_Surface aBAS(F, Standard_False);
if(!isNaturalRestriction)
if (!isNaturalRestriction)
{
//Check by comparing pcurves and surface boundaries
umin = aBAS.FirstUParameter();
umax = aBAS.LastUParameter();
vmin = aBAS.FirstVParameter();
vmax = aBAS.LastVParameter();
// Check by comparing pcurves and surface boundaries
umin = aBAS.FirstUParameter();
umax = aBAS.LastUParameter();
vmin = aBAS.FirstVParameter();
vmax = aBAS.LastVParameter();
Standard_Boolean isUperiodic = aBAS.IsUPeriodic(), isVperiodic = aBAS.IsVPeriodic();
Standard_Real aT1, aT2;
Standard_Real TolU = Max(aBAS.UResolution(Tol), Precision::PConfusion());
Standard_Real TolV = Max(aBAS.VResolution(Tol), Precision::PConfusion());
Standard_Real aT1, aT2;
Standard_Real TolU = Max(aBAS.UResolution(Tol), Precision::PConfusion());
Standard_Real TolV = Max(aBAS.VResolution(Tol), Precision::PConfusion());
Standard_Integer Nu = 0, Nv = 0, NbEdges = 0;
gp_Vec2d Du(1, 0), Dv(0, 1);
gp_Pnt2d aP;
gp_Vec2d aV;
for (;ex.More();ex.Next()) {
gp_Vec2d Du(1, 0), Dv(0, 1);
gp_Pnt2d aP;
gp_Vec2d aV;
for (; ex.More(); ex.Next())
{
NbEdges++;
if(NbEdges > 4)
if (NbEdges > 4)
{
break;
}
const TopoDS_Edge& aE = TopoDS::Edge(ex.Current());
const TopoDS_Edge& aE = TopoDS::Edge(ex.Current());
const Handle(Geom2d_Curve) aC2D = BRep_Tool::CurveOnSurface(aE, F, aT1, aT2);
if (aC2D.IsNull())
if (aC2D.IsNull())
{
break;
}
//
aC2D->D1((aT1 + aT2)/2., aP, aV);
aC2D->D1((aT1 + aT2) / 2., aP, aV);
Standard_Real magn = aV.SquareMagnitude();
if(magn < gp::Resolution())
if (magn < gp::Resolution())
{
break;
}
@@ -512,22 +539,22 @@ void FindExactUVBounds(const TopoDS_Face& FF,
aV /= Sqrt(magn);
}
Standard_Real u = aP.X(), v = aP.Y();
if(isUperiodic)
if (isUperiodic)
{
ElCLib::InPeriod(u, umin, umax);
}
if(isVperiodic)
if (isVperiodic)
{
ElCLib::InPeriod(v, vmin, vmax);
}
//
if(Abs(u - umin) <= TolU || Abs(u - umax) <= TolU)
if (Abs(u - umin) <= TolU || Abs(u - umax) <= TolU)
{
Standard_Real d = Dv * aV;
if(1. - Abs(d) <= Precision::PConfusion())
if (1. - Abs(d) <= Precision::PConfusion())
{
Nu++;
if(Nu > 2)
if (Nu > 2)
{
break;
}
@@ -537,13 +564,13 @@ void FindExactUVBounds(const TopoDS_Face& FF,
break;
}
}
else if(Abs(v - vmin) <= TolV || Abs(v - vmax) <= TolV)
else if (Abs(v - vmin) <= TolV || Abs(v - vmax) <= TolV)
{
Standard_Real d = Du * aV;
if(1. - Abs(d) <= Precision::PConfusion())
if (1. - Abs(d) <= Precision::PConfusion())
{
Nv++;
if(Nv > 2)
if (Nv > 2)
{
break;
}
@@ -558,13 +585,13 @@ void FindExactUVBounds(const TopoDS_Face& FF,
break;
}
}
if(Nu == 2 && Nv == 2)
if (Nu == 2 && Nv == 2)
{
isNaturalRestriction = Standard_True;
}
}
//
if(isNaturalRestriction)
if (isNaturalRestriction)
{
umin = aBAS.FirstUParameter();
umax = aBAS.LastUParameter();
@@ -575,15 +602,16 @@ void FindExactUVBounds(const TopoDS_Face& FF,
// fill box for the given face
Standard_Real aT1, aT2;
Standard_Real TolU = Max(aBAS.UResolution(Tol), Precision::PConfusion());
Standard_Real TolV = Max(aBAS.VResolution(Tol), Precision::PConfusion());
Standard_Real TolU = Max(aBAS.UResolution(Tol), Precision::PConfusion());
Standard_Real TolV = Max(aBAS.VResolution(Tol), Precision::PConfusion());
Standard_Real TolUV = Max(TolU, TolV);
Bnd_Box2d aBox;
ex.Init(F,TopAbs_EDGE);
for (;ex.More();ex.Next()) {
const TopoDS_Edge& aE = TopoDS::Edge(ex.Current());
Bnd_Box2d aBox;
ex.Init(F, TopAbs_EDGE);
for (; ex.More(); ex.Next())
{
const TopoDS_Edge& aE = TopoDS::Edge(ex.Current());
const Handle(Geom2d_Curve) aC2D = BRep_Tool::CurveOnSurface(aE, F, aT1, aT2);
if (aC2D.IsNull())
if (aC2D.IsNull())
{
continue;
}
@@ -594,89 +622,91 @@ void FindExactUVBounds(const TopoDS_Face& FF,
//
aBox.Get(umin, vmin, umax, vmax);
//
TopLoc_Location aLoc;
TopLoc_Location aLoc;
Handle(Geom_Surface) aS = BRep_Tool::Surface(FF, aLoc);
Standard_Real aUmin, aUmax, aVmin, aVmax;
Standard_Real aUmin, aUmax, aVmin, aVmax;
aS->Bounds(aUmin, aUmax, aVmin, aVmax);
if(!aS->IsUPeriodic())
if (!aS->IsUPeriodic())
{
umin = Max(aUmin, umin);
umax = Min(aUmax, umax);
}
else
{
if(umax - umin > aS->UPeriod())
if (umax - umin > aS->UPeriod())
{
Standard_Real delta = umax - umin - aS->UPeriod();
umin += delta/2.;
umax -= delta/2;
umin += delta / 2.;
umax -= delta / 2;
}
}
//
if(!aS->IsVPeriodic())
if (!aS->IsVPeriodic())
{
vmin = Max(aVmin, vmin);
vmax = Min(aVmax, vmax);
}
else
{
if(vmax - vmin > aS->VPeriod())
if (vmax - vmin > aS->VPeriod())
{
Standard_Real delta = vmax - vmin - aS->VPeriod();
vmin += delta/2.;
vmax -= delta/2;
vmin += delta / 2.;
vmax -= delta / 2;
}
}
}
//=======================================================================
//function : Reorder
//purpose :
//=======================================================================
//=================================================================================================
inline void Reorder(Standard_Real& a, Standard_Real& b)
{
if(a > b)
if (a > b)
{
Standard_Real t = a;
a = b;
b = t;
a = b;
b = t;
}
}
//=======================================================================
//function : IsModifySize
//purpose :
//=======================================================================
Standard_Boolean IsModifySize(const BRepAdaptor_Surface& theBS,
const gp_Pln& thePln, const gp_Pnt& theP,
const Standard_Real umin, const Standard_Real umax,
const Standard_Real vmin, const Standard_Real vmax,
//=================================================================================================
Standard_Boolean IsModifySize(const BRepAdaptor_Surface& theBS,
const gp_Pln& thePln,
const gp_Pnt& theP,
const Standard_Real umin,
const Standard_Real umax,
const Standard_Real vmin,
const Standard_Real vmax,
const BRepTopAdaptor_FClass2d& theFClass,
const Standard_Real theTolU, const Standard_Real theTolV)
const Standard_Real theTolU,
const Standard_Real theTolV)
{
Standard_Real pu1 = 0, pu2, pv1 = 0, pv2;
ElSLib::PlaneParameters(thePln.Position(), theP, pu2, pv2);
Reorder(pu1, pu2);
Reorder(pv1, pv2);
Handle(Geom_Plane) aPlane = new Geom_Plane(thePln);
Handle(Geom_Plane) aPlane = new Geom_Plane(thePln);
GeomAdaptor_Surface aGAPln(aPlane, pu1, pu2, pv1, pv2);
Extrema_ExtSS anExtr(aGAPln, theBS, pu1, pu2, pv1, pv2, umin, umax, vmin, vmax, theTolU, theTolV);
if(anExtr.IsDone())
if (anExtr.IsDone())
{
if(anExtr.NbExt() > 0)
if (anExtr.NbExt() > 0)
{
Standard_Integer i, imin = 0;
Standard_Real dmin = RealLast();
Standard_Real uextr = 0., vextr = 0.;
Extrema_POnSurf P1, P2;
for(i = 1; i <= anExtr.NbExt(); ++i)
Standard_Real dmin = RealLast();
Standard_Real uextr = 0., vextr = 0.;
Extrema_POnSurf P1, P2;
for (i = 1; i <= anExtr.NbExt(); ++i)
{
Standard_Real d = anExtr.SquareDistance(i);
if(d < dmin)
if (d < dmin)
{
imin = i;
dmin = d;
}
}
if(imin > 0)
if (imin > 0)
{
anExtr.Points(imin, P1, P2);
P2.Parameter(uextr, vextr);
@@ -686,31 +716,33 @@ Standard_Boolean IsModifySize(const BRepAdaptor_Surface& theBS,
return Standard_False;
}
//
gp_Pnt2d aP2d(uextr, vextr);
gp_Pnt2d aP2d(uextr, vextr);
TopAbs_State aSt = theFClass.Perform(aP2d);
if(aSt != TopAbs_IN)
if (aSt != TopAbs_IN)
{
return Standard_True;
}
}
else
{
return Standard_True; //extrema point seems to be out of face UV bounds
return Standard_True; // extrema point seems to be out of face UV bounds
}
}
//
return Standard_False;
}
//
//=======================================================================
//function : AdjustFaceBox
//purpose :
//=======================================================================
void AdjustFaceBox(const BRepAdaptor_Surface& BS,
const Standard_Real umin, const Standard_Real umax,
const Standard_Real vmin, const Standard_Real vmax,
Bnd_Box& FaceBox,
const Bnd_Box& EdgeBox, const Standard_Real Tol)
//=================================================================================================
void AdjustFaceBox(const BRepAdaptor_Surface& BS,
const Standard_Real umin,
const Standard_Real umax,
const Standard_Real vmin,
const Standard_Real vmax,
Bnd_Box& FaceBox,
const Bnd_Box& EdgeBox,
const Standard_Real Tol)
{
if (EdgeBox.IsVoid())
{
@@ -728,90 +760,83 @@ void AdjustFaceBox(const BRepAdaptor_Surface& BS,
FaceBox.Get(fxmin, fymin, fzmin, fxmax, fymax, fzmax);
EdgeBox.Get(exmin, eymin, ezmin, exmax, eymax, ezmax);
//
Standard_Real TolU = Max(BS.UResolution(Tol), Precision::PConfusion());
Standard_Real TolV = Max(BS.VResolution(Tol), Precision::PConfusion());
Standard_Real TolU = Max(BS.UResolution(Tol), Precision::PConfusion());
Standard_Real TolV = Max(BS.VResolution(Tol), Precision::PConfusion());
BRepTopAdaptor_FClass2d FClass(BS.Face(), Max(TolU, TolV));
//
Standard_Boolean isModified = Standard_False;
if(exmin > fxmin)
if (exmin > fxmin)
{
//
gp_Pln pl(gp_Ax3(gp_Pnt(fxmin, fymin, fzmin), gp::DX()));
gp_Pnt aP(fxmin, fymax, fzmax);
if(IsModifySize(BS, pl, aP,
umin, umax, vmin, vmax, FClass, TolU, TolV))
if (IsModifySize(BS, pl, aP, umin, umax, vmin, vmax, FClass, TolU, TolV))
{
fxmin = exmin;
fxmin = exmin;
isModified = Standard_True;
}
}
if(exmax < fxmax)
if (exmax < fxmax)
{
//
gp_Pln pl(gp_Ax3(gp_Pnt(fxmax, fymax, fzmax), gp::DX()));
gp_Pnt aP(fxmax, fymin, fzmin);
if(IsModifySize(BS, pl, aP,
umin, umax, vmin, vmax, FClass, TolU, TolV))
if (IsModifySize(BS, pl, aP, umin, umax, vmin, vmax, FClass, TolU, TolV))
{
fxmax = exmax;
fxmax = exmax;
isModified = Standard_True;
}
}
//
if(eymin > fymin)
if (eymin > fymin)
{
//
gp_Pln pl(gp_Ax3(gp_Pnt(fxmin, fymin, fzmin), gp::DY()));
gp_Pnt aP(fxmax, fymin, fzmax);
if(IsModifySize(BS, pl, aP,
umin, umax, vmin, vmax, FClass, TolU, TolV))
if (IsModifySize(BS, pl, aP, umin, umax, vmin, vmax, FClass, TolU, TolV))
{
fymin = eymin;
fymin = eymin;
isModified = Standard_True;
}
}
if(eymax < fymax)
if (eymax < fymax)
{
//
gp_Pln pl(gp_Ax3(gp_Pnt(fxmax, fymax, fzmax), gp::DY()));
gp_Pnt aP(fxmin, fymax, fzmin);
if(IsModifySize(BS, pl, aP,
umin, umax, vmin, vmax, FClass, TolU, TolV))
if (IsModifySize(BS, pl, aP, umin, umax, vmin, vmax, FClass, TolU, TolV))
{
fymax = eymax;
fymax = eymax;
isModified = Standard_True;
}
}
//
if(ezmin > fzmin)
if (ezmin > fzmin)
{
//
gp_Pln pl(gp_Ax3(gp_Pnt(fxmin, fymin, fzmin), gp::DZ()));
gp_Pnt aP(fxmax, fymax, fzmin);
if(IsModifySize(BS, pl, aP,
umin, umax, vmin, vmax, FClass, TolU, TolV))
if (IsModifySize(BS, pl, aP, umin, umax, vmin, vmax, FClass, TolU, TolV))
{
fzmin = ezmin;
fzmin = ezmin;
isModified = Standard_True;
}
}
if(ezmax < fzmax)
if (ezmax < fzmax)
{
//
gp_Pln pl(gp_Ax3(gp_Pnt(fxmax, fymax, fzmax), gp::DZ()));
gp_Pnt aP(fxmin, fymin, fzmax);
if(IsModifySize(BS, pl, aP,
umin, umax, vmin, vmax, FClass, TolU, TolV))
if (IsModifySize(BS, pl, aP, umin, umax, vmin, vmax, FClass, TolU, TolV))
{
fzmax = ezmax;
fzmax = ezmax;
isModified = Standard_True;
}
}
//
if(isModified)
if (isModified)
{
FaceBox.SetVoid();
FaceBox.Update(fxmin, fymin, fzmin, fxmax, fymax, fzmax);
}
}

View File

@@ -24,17 +24,14 @@ class TopoDS_Shape;
class Bnd_Box;
class Bnd_OBB;
//! This package provides the bounding boxes for curves
//! and surfaces from BRepAdaptor.
//! Functions to add a topological shape to a bounding box
class BRepBndLib
class BRepBndLib
{
public:
DEFINE_STANDARD_ALLOC
//! Adds the shape S to the bounding box B.
//! More precisely are successively added to B:
//! - each face of S; the triangulation of the face is used if it exists,
@@ -52,8 +49,10 @@ public:
//! - This algorithm is time consuming if triangulation has not
//! been inserted inside the data structure of the shape S.
//! - The resulting bounding box may be somewhat larger than the object.
Standard_EXPORT static void Add (const TopoDS_Shape& S, Bnd_Box& B, const Standard_Boolean useTriangulation = Standard_True);
Standard_EXPORT static void Add(const TopoDS_Shape& S,
Bnd_Box& B,
const Standard_Boolean useTriangulation = Standard_True);
//! Adds the shape S to the bounding box B.
//! This is a quick algorithm but only works if the shape S is
//! composed of polygonal planar faces, as is the case if S is
@@ -65,21 +64,21 @@ public:
//! tolerance value of the sub-shapes as is the case with the
//! Add function. So the added part of the resulting bounding
//! box is closer to the shape S.
Standard_EXPORT static void AddClose (const TopoDS_Shape& S, Bnd_Box& B);
Standard_EXPORT static void AddClose(const TopoDS_Shape& S, Bnd_Box& B);
//! Adds the shape S to the bounding box B.
//! This algorithm builds precise bounding box,
//! which differs from exact geometry boundaries of shape only on shape entities tolerances
//! Algorithm is the same as for method Add(..), but uses more precise methods for building boxes
//! Algorithm is the same as for method Add(..), but uses more precise methods for building boxes
//! for geometry objects.
//! If useShapeTolerance = True, bounding box is enlardged by shape tolerances and
//! these tolerances are used for numerical methods of bounding box size calculations,
//! If useShapeTolerance = True, bounding box is enlardged by shape tolerances and
//! these tolerances are used for numerical methods of bounding box size calculations,
//! otherwise bounding box is built according to sizes of uderlined geometrical entities,
//! numerical calculation use tolerance Precision::Confusion().
Standard_EXPORT static void AddOptimal (const TopoDS_Shape& S, Bnd_Box& B,
const Standard_Boolean useTriangulation = Standard_True,
const Standard_Boolean useShapeTolerance = Standard_False);
Standard_EXPORT static void AddOptimal(const TopoDS_Shape& S,
Bnd_Box& B,
const Standard_Boolean useTriangulation = Standard_True,
const Standard_Boolean useShapeTolerance = Standard_False);
//! Computes the Oriented Bounding box for the shape <theS>.
//! Two independent methods of computation are implemented:
@@ -88,36 +87,20 @@ public:
//! The second method is based on use of inertia axes and is called
//! if use of the first method is impossible.
//! If theIsTriangulationUsed == FALSE then the triangulation will
//! be ignored at all.
//! be ignored at all.
//! If theIsShapeToleranceUsed == TRUE then resulting box will be
//! extended on the tolerance of the shape.
//! theIsOptimal flag defines whether to look for the more tight
//! OBB for the cost of performance or not.
Standard_EXPORT static
void AddOBB(const TopoDS_Shape& theS,
Bnd_OBB& theOBB,
const Standard_Boolean theIsTriangulationUsed = Standard_True,
const Standard_Boolean theIsOptimal = Standard_False,
const Standard_Boolean theIsShapeToleranceUsed = Standard_True);
Standard_EXPORT static void AddOBB(
const TopoDS_Shape& theS,
Bnd_OBB& theOBB,
const Standard_Boolean theIsTriangulationUsed = Standard_True,
const Standard_Boolean theIsOptimal = Standard_False,
const Standard_Boolean theIsShapeToleranceUsed = Standard_True);
protected:
private:
};
#endif // _BRepBndLib_HeaderFile

View File

@@ -38,22 +38,21 @@
static Standard_Boolean IsLinear(const Adaptor3d_Curve& theC)
{
const GeomAbs_CurveType aCT = theC.GetType();
if(aCT == GeomAbs_OffsetCurve)
if (aCT == GeomAbs_OffsetCurve)
{
return IsLinear(GeomAdaptor_Curve(theC.OffsetCurve()->BasisCurve()));
}
if((aCT == GeomAbs_BSplineCurve) || (aCT == GeomAbs_BezierCurve))
if ((aCT == GeomAbs_BSplineCurve) || (aCT == GeomAbs_BezierCurve))
{
// Indeed, curves with C0-continuity and degree==1, may be
// Indeed, curves with C0-continuity and degree==1, may be
// represented with set of points. It will be possible made
// in the future.
return ((theC.Degree() == 1) &&
(theC.Continuity() != GeomAbs_C0));
return ((theC.Degree() == 1) && (theC.Continuity() != GeomAbs_C0));
}
if(aCT == GeomAbs_Line)
if (aCT == GeomAbs_Line)
{
return Standard_True;
}
@@ -68,29 +67,29 @@ static Standard_Boolean IsLinear(const Adaptor3d_Curve& theC)
static Standard_Boolean IsPlanar(const Adaptor3d_Surface& theS)
{
const GeomAbs_SurfaceType aST = theS.GetType();
if(aST == GeomAbs_OffsetSurface)
if (aST == GeomAbs_OffsetSurface)
{
return IsPlanar (*theS.BasisSurface());
return IsPlanar(*theS.BasisSurface());
}
if(aST == GeomAbs_SurfaceOfExtrusion)
if (aST == GeomAbs_SurfaceOfExtrusion)
{
return IsLinear (*theS.BasisCurve());
return IsLinear(*theS.BasisCurve());
}
if((aST == GeomAbs_BSplineSurface) || (aST == GeomAbs_BezierSurface))
if ((aST == GeomAbs_BSplineSurface) || (aST == GeomAbs_BezierSurface))
{
if((theS.UDegree() != 1) || (theS.VDegree() != 1))
if ((theS.UDegree() != 1) || (theS.VDegree() != 1))
return Standard_False;
// Indeed, surfaces with C0-continuity and degree==1, may be
// Indeed, surfaces with C0-continuity and degree==1, may be
// represented with set of points. It will be possible made
// in the future.
return ((theS.UContinuity() != GeomAbs_C0) && (theS.VContinuity() != GeomAbs_C0));
}
if(aST == GeomAbs_Plane)
if (aST == GeomAbs_Plane)
{
return Standard_True;
}
@@ -102,45 +101,45 @@ static Standard_Boolean IsPlanar(const Adaptor3d_Surface& theS)
// Function : PointsForOBB
// purpose : Returns number of points for array.
//
// Attention!!!
// Attention!!!
// 1. Start index for thePts must be 0 strictly.
// 2. Currently, infinite edges/faces (e.g. half-space) are not
// processed correctly because computation of UV-bounds is a costly operation.
//=======================================================================
static Standard_Integer PointsForOBB(const TopoDS_Shape& theS,
static Standard_Integer PointsForOBB(const TopoDS_Shape& theS,
const Standard_Boolean theIsTriangulationUsed,
TColgp_Array1OfPnt* thePts = 0,
TColStd_Array1OfReal* theArrOfToler = 0)
TColgp_Array1OfPnt* thePts = 0,
TColStd_Array1OfReal* theArrOfToler = 0)
{
Standard_Integer aRetVal = 0;
TopExp_Explorer anExpF, anExpE;
TopExp_Explorer anExpF, anExpE;
// get all vertices from the shape
for(anExpF.Init(theS, TopAbs_VERTEX); anExpF.More(); anExpF.Next())
for (anExpF.Init(theS, TopAbs_VERTEX); anExpF.More(); anExpF.Next())
{
const TopoDS_Vertex &aVert = TopoDS::Vertex(anExpF.Current());
if(thePts)
const TopoDS_Vertex& aVert = TopoDS::Vertex(anExpF.Current());
if (thePts)
{
const gp_Pnt aP = BRep_Tool::Pnt(aVert);
const gp_Pnt aP = BRep_Tool::Pnt(aVert);
(*thePts)(aRetVal) = aP;
}
if(theArrOfToler)
if (theArrOfToler)
{
(*theArrOfToler) (aRetVal) = BRep_Tool::Tolerance(aVert);
(*theArrOfToler)(aRetVal) = BRep_Tool::Tolerance(aVert);
}
++aRetVal;
}
if(aRetVal == 0)
if (aRetVal == 0)
return 0;
// analyze the faces of the shape on planarity and existence of triangulation
TopLoc_Location aLoc;
for(anExpF.Init(theS, TopAbs_FACE); anExpF.More(); anExpF.Next())
for (anExpF.Init(theS, TopAbs_FACE); anExpF.More(); anExpF.Next())
{
const TopoDS_Face &aF = TopoDS::Face(anExpF.Current());
const TopoDS_Face& aF = TopoDS::Face(anExpF.Current());
const BRepAdaptor_Surface anAS(aF, Standard_False);
if (!IsPlanar(anAS.Surface()))
@@ -152,10 +151,10 @@ static Standard_Integer PointsForOBB(const TopoDS_Shape& theS,
else
{
// planar face
for(anExpE.Init(aF, TopAbs_EDGE); anExpE.More(); anExpE.Next())
for (anExpE.Init(aF, TopAbs_EDGE); anExpE.More(); anExpE.Next())
{
const TopoDS_Edge &anE = TopoDS::Edge(anExpE.Current());
if (BRep_Tool::IsGeometric (anE))
const TopoDS_Edge& anE = TopoDS::Edge(anExpE.Current());
if (BRep_Tool::IsGeometric(anE))
{
const BRepAdaptor_Curve anAC(anE);
if (!IsLinear(anAC))
@@ -175,7 +174,7 @@ static Standard_Integer PointsForOBB(const TopoDS_Shape& theS,
}
// Use triangulation of the face
const Handle(Poly_Triangulation)& aTrng = BRep_Tool::Triangulation (aF, aLoc);
const Handle(Poly_Triangulation)& aTrng = BRep_Tool::Triangulation(aF, aLoc);
if (aTrng.IsNull())
{
// no triangulation on the face
@@ -183,20 +182,19 @@ static Standard_Integer PointsForOBB(const TopoDS_Shape& theS,
}
const Standard_Integer aCNode = aTrng->NbNodes();
const gp_Trsf aTrsf = aLoc;
const gp_Trsf aTrsf = aLoc;
for (Standard_Integer i = 1; i <= aCNode; i++)
{
if (thePts != NULL)
{
const gp_Pnt aP = aTrsf.Form() == gp_Identity
? aTrng->Node (i)
: aTrng->Node (i).Transformed (aTrsf);
const gp_Pnt aP =
aTrsf.Form() == gp_Identity ? aTrng->Node(i) : aTrng->Node(i).Transformed(aTrsf);
(*thePts)(aRetVal) = aP;
}
if (theArrOfToler != NULL)
{
(*theArrOfToler) (aRetVal) = aTrng->Deflection();
(*theArrOfToler)(aRetVal) = aTrng->Deflection();
}
++aRetVal;
@@ -205,10 +203,10 @@ static Standard_Integer PointsForOBB(const TopoDS_Shape& theS,
// Consider edges without faces
for(anExpE.Init(theS, TopAbs_EDGE, TopAbs_FACE); anExpE.More(); anExpE.Next())
for (anExpE.Init(theS, TopAbs_EDGE, TopAbs_FACE); anExpE.More(); anExpE.Next())
{
const TopoDS_Edge &anE = TopoDS::Edge(anExpE.Current());
if (BRep_Tool::IsGeometric (anE))
const TopoDS_Edge& anE = TopoDS::Edge(anExpE.Current());
if (BRep_Tool::IsGeometric(anE))
{
const BRepAdaptor_Curve anAC(anE);
if (IsLinear(anAC))
@@ -222,24 +220,23 @@ static Standard_Integer PointsForOBB(const TopoDS_Shape& theS,
// not linear and triangulation usage disabled
return 0;
const Handle(Poly_Polygon3D) &aPolygon = BRep_Tool::Polygon3D(anE, aLoc);
const Handle(Poly_Polygon3D)& aPolygon = BRep_Tool::Polygon3D(anE, aLoc);
if (aPolygon.IsNull())
return 0;
const Standard_Integer aCNode = aPolygon->NbNodes();
const Standard_Integer aCNode = aPolygon->NbNodes();
const TColgp_Array1OfPnt& aNodesArr = aPolygon->Nodes();
for (Standard_Integer i = 1; i <= aCNode; i++)
{
if (thePts)
{
const gp_Pnt aP = aLoc.IsIdentity() ? aNodesArr[i] :
aNodesArr[i].Transformed(aLoc);
const gp_Pnt aP = aLoc.IsIdentity() ? aNodesArr[i] : aNodesArr[i].Transformed(aLoc);
(*thePts)(aRetVal) = aP;
}
if (theArrOfToler)
{
(*theArrOfToler) (aRetVal) = aPolygon->Deflection();
(*theArrOfToler)(aRetVal) = aPolygon->Deflection();
}
++aRetVal;
@@ -256,23 +253,19 @@ static Standard_Integer PointsForOBB(const TopoDS_Shape& theS,
//=======================================================================
static Standard_Integer IsWCS(const gp_Dir& theDir)
{
constexpr Standard_Real aToler = Precision::Angular()*Precision::Angular();
constexpr Standard_Real aToler = Precision::Angular() * Precision::Angular();
const Standard_Real aX = theDir.X(),
aY = theDir.Y(),
aZ = theDir.Z();
const Standard_Real aX = theDir.X(), aY = theDir.Y(), aZ = theDir.Z();
const Standard_Real aVx = aY*aY + aZ*aZ,
aVy = aX*aX + aZ*aZ,
aVz = aX*aX + aY*aY;
const Standard_Real aVx = aY * aY + aZ * aZ, aVy = aX * aX + aZ * aZ, aVz = aX * aX + aY * aY;
if(aVz < aToler)
if (aVz < aToler)
return 3; // Z-axis
if(aVy < aToler)
if (aVy < aToler)
return 2; // Y-axis
if(aVx < aToler)
if (aVx < aToler)
return 1; // X-axis
return 0;
@@ -284,30 +277,30 @@ static Standard_Integer IsWCS(const gp_Dir& theDir)
// linear/planar shapes and shapes having triangulation
// (http://www.idt.mdh.se/~tla/publ/FastOBBs.pdf).
//=======================================================================
static Standard_Boolean CheckPoints(const TopoDS_Shape& theS,
static Standard_Boolean CheckPoints(const TopoDS_Shape& theS,
const Standard_Boolean theIsTriangulationUsed,
const Standard_Boolean theIsOptimal,
const Standard_Boolean theIsShapeToleranceUsed,
Bnd_OBB& theOBB)
Bnd_OBB& theOBB)
{
const Standard_Integer aNbPnts = PointsForOBB(theS, theIsTriangulationUsed);
if(aNbPnts < 1)
if (aNbPnts < 1)
return Standard_False;
TColgp_Array1OfPnt anArrPnts(0, theOBB.IsVoid() ? aNbPnts - 1 : aNbPnts + 7);
TColgp_Array1OfPnt anArrPnts(0, theOBB.IsVoid() ? aNbPnts - 1 : aNbPnts + 7);
TColStd_Array1OfReal anArrOfTolerances;
if(theIsShapeToleranceUsed)
if (theIsShapeToleranceUsed)
{
anArrOfTolerances.Resize(anArrPnts.Lower(), anArrPnts.Upper(), Standard_False);
anArrOfTolerances.Init(0.0);
}
TColStd_Array1OfReal *aPtrArrTol = theIsShapeToleranceUsed ? &anArrOfTolerances : 0;
TColStd_Array1OfReal* aPtrArrTol = theIsShapeToleranceUsed ? &anArrOfTolerances : 0;
PointsForOBB(theS, theIsTriangulationUsed, &anArrPnts, aPtrArrTol);
if(!theOBB.IsVoid())
if (!theOBB.IsVoid())
{
// All points of old OBB have zero-tolerance
theOBB.GetVertex(&anArrPnts(aNbPnts));
@@ -332,32 +325,31 @@ static Standard_Boolean CheckPoints(const TopoDS_Shape& theS,
// Function : ComputeProperties
// purpose : Computes properties of theS.
//=======================================================================
static void ComputeProperties(const TopoDS_Shape& theS,
GProp_GProps& theGCommon)
static void ComputeProperties(const TopoDS_Shape& theS, GProp_GProps& theGCommon)
{
TopExp_Explorer anExp;
for(anExp.Init(theS, TopAbs_SOLID); anExp.More(); anExp.Next())
for (anExp.Init(theS, TopAbs_SOLID); anExp.More(); anExp.Next())
{
GProp_GProps aG;
BRepGProp::VolumeProperties(anExp.Current(), aG, Standard_True);
theGCommon.Add(aG);
}
for(anExp.Init(theS, TopAbs_FACE, TopAbs_SOLID); anExp.More(); anExp.Next())
for (anExp.Init(theS, TopAbs_FACE, TopAbs_SOLID); anExp.More(); anExp.Next())
{
GProp_GProps aG;
BRepGProp::SurfaceProperties(anExp.Current(), aG, Standard_True);
theGCommon.Add(aG);
}
for(anExp.Init(theS, TopAbs_EDGE, TopAbs_FACE); anExp.More(); anExp.Next())
for (anExp.Init(theS, TopAbs_EDGE, TopAbs_FACE); anExp.More(); anExp.Next())
{
GProp_GProps aG;
BRepGProp::LinearProperties(anExp.Current(), aG, Standard_True);
theGCommon.Add(aG);
}
for(anExp.Init(theS, TopAbs_VERTEX, TopAbs_EDGE); anExp.More(); anExp.Next())
for (anExp.Init(theS, TopAbs_VERTEX, TopAbs_EDGE); anExp.More(); anExp.Next())
{
GProp_GProps aG(BRep_Tool::Pnt(TopoDS::Vertex(anExp.Current())));
theGCommon.Add(aG);
@@ -368,8 +360,8 @@ static void ComputeProperties(const TopoDS_Shape& theS,
// Function : ComputePCA
// purpose : Creates OBB with axes of inertia.
//=======================================================================
static void ComputePCA(const TopoDS_Shape& theS,
Bnd_OBB& theOBB,
static void ComputePCA(const TopoDS_Shape& theS,
Bnd_OBB& theOBB,
const Standard_Boolean theIsTriangulationUsed,
const Standard_Boolean theIsOptimal,
const Standard_Boolean theIsShapeToleranceUsed)
@@ -381,12 +373,10 @@ static void ComputePCA(const TopoDS_Shape& theS,
// Transform the shape to the local coordinate system
gp_Trsf aTrsf;
const Standard_Integer anIdx1 =
IsWCS(aGCommon.PrincipalProperties().FirstAxisOfInertia());
const Standard_Integer anIdx2 =
IsWCS(aGCommon.PrincipalProperties().SecondAxisOfInertia());
const Standard_Integer anIdx1 = IsWCS(aGCommon.PrincipalProperties().FirstAxisOfInertia());
const Standard_Integer anIdx2 = IsWCS(aGCommon.PrincipalProperties().SecondAxisOfInertia());
if((anIdx1 == 0) || (anIdx2 == 0))
if ((anIdx1 == 0) || (anIdx2 == 0))
{
// Coordinate system in which the shape will have the optimal bounding box
gp_Ax3 aLocCoordSys(aGCommon.CentreOfMass(),
@@ -395,12 +385,12 @@ static void ComputePCA(const TopoDS_Shape& theS,
aTrsf.SetTransformation(aLocCoordSys);
}
const TopoDS_Shape aST = (aTrsf.Form() == gp_Identity) ? theS :
theS.Moved(TopLoc_Location(aTrsf));
const TopoDS_Shape aST =
(aTrsf.Form() == gp_Identity) ? theS : theS.Moved(TopLoc_Location(aTrsf));
// Initial axis-aligned BndBox
Bnd_Box aShapeBox;
if(theIsOptimal)
if (theIsOptimal)
{
BRepBndLib::AddOptimal(aST, aShapeBox, theIsTriangulationUsed, theIsShapeToleranceUsed);
}
@@ -428,20 +418,20 @@ static void ComputePCA(const TopoDS_Shape& theS,
gp_XYZ anOBBHSize = (aPMax.XYZ() - aPMin.XYZ()) / 2.;
// Apply transformation if necessary
if(aTrsf.Form() != gp_Identity)
if (aTrsf.Form() != gp_Identity)
{
aTrsf.Invert();
aTrsf.Transforms(aCenter);
// Make transformation
const Standard_Real * aMat = &aTrsf.HVectorialPart().Value(1, 1);
const Standard_Real* aMat = &aTrsf.HVectorialPart().Value(1, 1);
// Compute axes directions of the box
aXDir = gp_XYZ(aMat[0], aMat[3], aMat[6]);
aYDir = gp_XYZ(aMat[1], aMat[4], aMat[7]);
aZDir = gp_XYZ(aMat[2], aMat[5], aMat[8]);
}
if(theOBB.IsVoid())
if (theOBB.IsVoid())
{
// Create the OBB box
@@ -464,30 +454,26 @@ static void ComputePCA(const TopoDS_Shape& theS,
const Standard_Real aY = anOBBHSize.Y();
const Standard_Real aZ = anOBBHSize.Z();
const gp_XYZ aXext = aX*aXDir,
aYext = aY*aYDir,
aZext = aZ*aZDir;
const gp_XYZ aXext = aX * aXDir, aYext = aY * aYDir, aZext = aZ * aZDir;
Standard_Integer aPntIdx = 8;
aListOfPnts(aPntIdx++) = aCenter - aXext - aYext - aZext;
aListOfPnts(aPntIdx++) = aCenter + aXext - aYext - aZext;
aListOfPnts(aPntIdx++) = aCenter - aXext + aYext - aZext;
aListOfPnts(aPntIdx++) = aCenter + aXext + aYext - aZext;
aListOfPnts(aPntIdx++) = aCenter - aXext - aYext + aZext;
aListOfPnts(aPntIdx++) = aCenter + aXext - aYext + aZext;
aListOfPnts(aPntIdx++) = aCenter - aXext + aYext + aZext;
aListOfPnts(aPntIdx++) = aCenter + aXext + aYext + aZext;
aListOfPnts(aPntIdx++) = aCenter - aXext - aYext - aZext;
aListOfPnts(aPntIdx++) = aCenter + aXext - aYext - aZext;
aListOfPnts(aPntIdx++) = aCenter - aXext + aYext - aZext;
aListOfPnts(aPntIdx++) = aCenter + aXext + aYext - aZext;
aListOfPnts(aPntIdx++) = aCenter - aXext - aYext + aZext;
aListOfPnts(aPntIdx++) = aCenter + aXext - aYext + aZext;
aListOfPnts(aPntIdx++) = aCenter - aXext + aYext + aZext;
aListOfPnts(aPntIdx++) = aCenter + aXext + aYext + aZext;
theOBB.ReBuild(aListOfPnts);
}
}
//=======================================================================
// Function : AddOBB
// purpose :
//=======================================================================
void BRepBndLib::AddOBB(const TopoDS_Shape& theS,
Bnd_OBB& theOBB,
//=================================================================================================
void BRepBndLib::AddOBB(const TopoDS_Shape& theS,
Bnd_OBB& theOBB,
const Standard_Boolean theIsTriangulationUsed,
const Standard_Boolean theIsOptimal,
const Standard_Boolean theIsShapeToleranceUsed)