mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
0024538: BRepFill_CompatibleWires.cxx, implementation of function PlaneOfWire() is suboptimal
Implementation improvements and refactoring in PlaneOfWire() function.
This commit is contained in:
@@ -140,40 +140,59 @@ static Standard_Boolean PlaneOfWire (const TopoDS_Wire& W, gp_Pln& P)
|
|||||||
TopLoc_Location L;
|
TopLoc_Location L;
|
||||||
|
|
||||||
GProp_GProps GP;
|
GProp_GProps GP;
|
||||||
BRepGProp::LinearProperties(W,GP);
|
gp_Pnt Bary;
|
||||||
gp_Pnt Bary = GP.CentreOfMass();
|
Standard_Boolean isBaryDefined = Standard_False;
|
||||||
|
|
||||||
// shielding for particular cases : only one edge circle or ellipse
|
// shielding for particular cases : only one edge circle or ellipse
|
||||||
// on a closed wire !
|
// on a closed wire !
|
||||||
Standard_Integer nbEdges = 0;
|
|
||||||
BRepTools_WireExplorer anExp;
|
|
||||||
anExp.Init(W);
|
|
||||||
Standard_Boolean wClosed = W.Closed();
|
Standard_Boolean wClosed = W.Closed();
|
||||||
if (!wClosed) {
|
if (!wClosed)
|
||||||
|
{
|
||||||
// it is checked if the vertices are the same.
|
// it is checked if the vertices are the same.
|
||||||
TopoDS_Vertex V1, V2;
|
TopoDS_Vertex V1, V2;
|
||||||
TopExp::Vertices(W,V1,V2);
|
TopExp::Vertices(W,V1,V2);
|
||||||
if ( V1.IsSame(V2)) wClosed = Standard_True;
|
if ( V1.IsSame(V2)) wClosed = Standard_True;
|
||||||
}
|
}
|
||||||
TopoDS_Edge Edge = TopoDS::Edge(anExp.Current());
|
|
||||||
Standard_Real first, last;
|
if (wClosed)
|
||||||
Handle(Geom_Curve) curv = BRep_Tool::Curve(Edge, first, last);
|
{
|
||||||
if (wClosed) {
|
Standard_Integer nbEdges = 0;
|
||||||
GeomAdaptor_Curve AdC;
|
TopoDS_Iterator anIter;
|
||||||
AdC.Load(curv);
|
anIter.Initialize(W);
|
||||||
for(; anExp.More(); anExp.Next()) {
|
for(; anIter.More(); anIter.Next())
|
||||||
nbEdges ++;
|
nbEdges ++;
|
||||||
}
|
|
||||||
if ( nbEdges==1 && AdC.GetType() == GeomAbs_Circle ) {
|
if(nbEdges == 1)
|
||||||
|
{
|
||||||
|
GeomAdaptor_Curve AdC;
|
||||||
|
Standard_Real first, last;
|
||||||
|
anIter.Initialize(W);
|
||||||
|
AdC.Load(BRep_Tool::Curve(TopoDS::Edge(anIter.Value()), first, last));
|
||||||
|
|
||||||
|
if (AdC.GetType() == GeomAbs_Circle)
|
||||||
|
{
|
||||||
Bary = AdC.Circle().Location();
|
Bary = AdC.Circle().Location();
|
||||||
|
isBaryDefined = Standard_True;
|
||||||
}
|
}
|
||||||
if ( nbEdges==1 && AdC.GetType() == GeomAbs_Ellipse ) {
|
|
||||||
|
if (AdC.GetType() == GeomAbs_Ellipse)
|
||||||
|
{
|
||||||
Bary = AdC.Ellipse().Location();
|
Bary = AdC.Ellipse().Location();
|
||||||
|
isBaryDefined = Standard_True;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isBaryDefined)
|
||||||
|
{
|
||||||
|
BRepGProp::LinearProperties(W,GP);
|
||||||
|
Bary = GP.CentreOfMass();
|
||||||
|
}
|
||||||
|
|
||||||
findPlanarSurf.Init(W, -1, Standard_True);
|
findPlanarSurf.Init(W, -1, Standard_True);
|
||||||
if ( findPlanarSurf.Found()) {
|
if ( findPlanarSurf.Found())
|
||||||
|
{
|
||||||
S = findPlanarSurf.Surface();
|
S = findPlanarSurf.Surface();
|
||||||
L = findPlanarSurf.Location();
|
L = findPlanarSurf.Location();
|
||||||
if (!L.IsIdentity()) S = Handle(Geom_Surface)::
|
if (!L.IsIdentity()) S = Handle(Geom_Surface)::
|
||||||
@@ -181,7 +200,8 @@ static Standard_Boolean PlaneOfWire (const TopoDS_Wire& W, gp_Pln& P)
|
|||||||
P = (Handle(Geom_Plane)::DownCast(S))->Pln();
|
P = (Handle(Geom_Plane)::DownCast(S))->Pln();
|
||||||
P.SetLocation(Bary);
|
P.SetLocation(Bary);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
// wire not plane !
|
// wire not plane !
|
||||||
GProp_PrincipalProps Pp = GP.PrincipalProperties();
|
GProp_PrincipalProps Pp = GP.PrincipalProperties();
|
||||||
gp_Vec Vec;
|
gp_Vec Vec;
|
||||||
@@ -192,24 +212,31 @@ static Standard_Boolean PlaneOfWire (const TopoDS_Wire& W, gp_Pln& P)
|
|||||||
|| ( Abs(RMax-R1)<Tol && Abs(RMax-R3)<Tol )
|
|| ( Abs(RMax-R1)<Tol && Abs(RMax-R3)<Tol )
|
||||||
|| ( Abs(RMax-R2)<Tol && Abs(RMax-R3)<Tol ) )
|
|| ( Abs(RMax-R2)<Tol && Abs(RMax-R3)<Tol ) )
|
||||||
isplane = Standard_False;
|
isplane = Standard_False;
|
||||||
else {
|
else
|
||||||
if (R1>=R2 && R1>=R3) {
|
{
|
||||||
|
if (R1>=R2 && R1>=R3)
|
||||||
|
{
|
||||||
Vec = Pp.FirstAxisOfInertia();
|
Vec = Pp.FirstAxisOfInertia();
|
||||||
}
|
}
|
||||||
else if (R2>=R1 && R2>=R3) {
|
else if (R2>=R1 && R2>=R3)
|
||||||
|
{
|
||||||
Vec = Pp.SecondAxisOfInertia();
|
Vec = Pp.SecondAxisOfInertia();
|
||||||
}
|
}
|
||||||
else if (R3>=R1 && R3>=R2) {
|
else if (R3>=R1 && R3>=R2)
|
||||||
|
{
|
||||||
Vec = Pp.ThirdAxisOfInertia();
|
Vec = Pp.ThirdAxisOfInertia();
|
||||||
}
|
}
|
||||||
gp_Dir NDir(Vec);
|
gp_Dir NDir(Vec);
|
||||||
if (R3<=R2 && R3<=R1) {
|
if (R3<=R2 && R3<=R1)
|
||||||
|
{
|
||||||
Vec = Pp.ThirdAxisOfInertia();
|
Vec = Pp.ThirdAxisOfInertia();
|
||||||
}
|
}
|
||||||
else if (R2<=R1 && R2<=R3) {
|
else if (R2<=R1 && R2<=R3)
|
||||||
|
{
|
||||||
Vec = Pp.SecondAxisOfInertia();
|
Vec = Pp.SecondAxisOfInertia();
|
||||||
}
|
}
|
||||||
else if (R1<=R2 && R1<=R3) {
|
else if (R1<=R2 && R1<=R3)
|
||||||
|
{
|
||||||
Vec = Pp.FirstAxisOfInertia();
|
Vec = Pp.FirstAxisOfInertia();
|
||||||
}
|
}
|
||||||
gp_Dir XDir(Vec);
|
gp_Dir XDir(Vec);
|
||||||
|
Reference in New Issue
Block a user