0024475: Regression on OCCT6.6.0 relative to OCCT6.5.3: wrong result of ThruSections...
[occt.git] / src / BRepFill / BRepFill_CompatibleWires.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 92b68db..0b8e372
@@ -1,8 +1,18 @@
-// File:       BRepFill_CompatibleWires.cxx
-// Created:    Thu Jul  2 16:47:25 1998
-// Author:     Joelle CHAUVET
-//             <jct@sgi64>
-
+// Created on: 1998-07-02
+// Created by: Joelle CHAUVET
+// Copyright (c) 1998-1999 Matra Datavision
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and / or modify it
+// under the terms of the GNU Lesser General Public version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
 
 #include <BRepFill_CompatibleWires.ixx>
 
@@ -53,7 +63,7 @@
 #include <TColStd_Array1OfReal.hxx>
 #include <TColStd_SequenceOfReal.hxx>
 
-
+#ifdef DEB_EFV
 static void EdgesFromVertex (const TopoDS_Wire&   W,
                             const TopoDS_Vertex& V, 
                             TopoDS_Edge& E1, 
@@ -104,7 +114,7 @@ static void EdgesFromVertex (const TopoDS_Wire&   W,
   }
 }
                                      
-
+#endif
 static void SeqOfVertices (const TopoDS_Wire&   W,
                           TopTools_SequenceOfShape& S)
 {
@@ -475,10 +485,6 @@ static Standard_Boolean EdgeIntersectOnWire (const gp_Pnt& P1,
       TopoDS_Shape aLocalShape = DSS.SupportOnShape2(isol);
       TopoDS_Edge E = TopoDS::Edge(aLocalShape);
 //      TopoDS_Edge E = TopoDS::Edge(DSS.SupportOnShape2(isol));
-#ifdef DEB
-      Standard_Real tol = 
-#endif
-       Precision::PConfusion();
       Standard_Real first,last,param;
       DSS.ParOnEdgeS2(isol,param);
       BRep_Tool::Range(E,first,last);
@@ -554,8 +560,8 @@ static void Transform (const Standard_Boolean WithRotation,
     gp_Ax1 Norm(Pos2,norm2);
     Standard_Real ang = axe1.AngleWithRef(axe2,norm2);
     if (!WithRotation) {
-      if (ang>PI/2) ang = ang - PI;
-      if (ang<-PI/2) ang = ang + PI;
+      if (ang>M_PI/2) ang = ang - M_PI;
+      if (ang<-M_PI/2) ang = ang + M_PI;
     }
     ang *= sign;
     Pnew = Pnew.Rotated (Norm,ang);
@@ -917,11 +923,6 @@ void BRepFill_CompatibleWires::
     
     // extremity of the first wire
     V1 = TopoDS::Vertex(SeqV.Value(1));        
-    // previous wire 
-#ifdef DEB
-    const TopoDS_Wire& wire2 = 
-#endif
-      TopoDS::Wire(myWork(i-1));
     // loop on vertices of wire1
     for (ii=1;ii<=SeqV.Length();ii++) {
       
@@ -1366,7 +1367,7 @@ void BRepFill_CompatibleWires::SameNumberByACR(const  Standard_Boolean  report)
 //purpose  : 
 //=======================================================================
 
-void BRepFill_CompatibleWires::ComputeOrigin(const  Standard_Boolean polar )
+void BRepFill_CompatibleWires::ComputeOrigin(const  Standard_Boolean /*polar*/ )
 {
   // reorganize the wires respecting orientation and origin
   
@@ -1454,9 +1455,24 @@ void BRepFill_CompatibleWires::ComputeOrigin(const  Standard_Boolean polar )
   Standard_Integer nbs, NbSamples = 0;
   if (theLength <= 2)
     NbSamples = 4;
+  gp_Pln FirstPlane;
+  PlaneOfWire(TopoDS::Wire(myWork(ideb)), FirstPlane);
+  gp_Pnt FirstBary = FirstPlane.Location();
+  gp_Vec NormalOfFirstPlane = FirstPlane.Axis().Direction();
   for (i = ideb+1; i <= ifin; i++)
     {
       const TopoDS_Wire& wire = TopoDS::Wire(myWork(i));
+
+      //Compute offset vector as current bary center projected on first plane
+      //to first bary center
+      gp_Pln CurPlane;
+      PlaneOfWire(wire, CurPlane);
+      gp_Pnt CurBary = CurPlane.Location();
+      gp_Vec aVec(FirstBary, CurBary);
+      gp_Vec anOffsetProj = (aVec * NormalOfFirstPlane) * NormalOfFirstPlane;
+      CurBary.Translate(-anOffsetProj); //projected current bary center
+      gp_Vec Offset(CurBary, FirstBary);
+      
       TopoDS_Wire newwire;
       BRep_Builder BB;
       BB.MakeWire(newwire);
@@ -1469,8 +1485,8 @@ void BRepFill_CompatibleWires::ComputeOrigin(const  Standard_Boolean polar )
        }
       
       Standard_Real MinSumDist = Precision::Infinite();
-      Standard_Integer jmin, j, k, n;
-      Standard_Boolean forward;
+      Standard_Integer jmin = 1, j, k, n;
+      Standard_Boolean forward = Standard_False;
       if (i == myWork.Length() && myDegen2)
        {
          // last point section
@@ -1487,7 +1503,7 @@ void BRepFill_CompatibleWires::ComputeOrigin(const  Standard_Boolean polar )
                const TopoDS_Vertex& Vprev = TopoDS::Vertex( PrevSeq(n) );
                gp_Pnt Pprev = BRep_Tool::Pnt(Vprev);
                const TopoDS_Vertex& V = TopoDS::Vertex( SeqVertices(k) );
-               gp_Pnt P = BRep_Tool::Pnt(V);
+               gp_Pnt P = BRep_Tool::Pnt(V).XYZ() + Offset.XYZ();
                SumDist += Pprev.Distance(P);
                 if (NbSamples > 0)
                 {
@@ -1506,7 +1522,7 @@ void BRepFill_CompatibleWires::ComputeOrigin(const  Standard_Boolean polar )
                       (Ecurve.FirstParameter() + nbs*SampleOnCur) :
                       (Ecurve.FirstParameter() + (NbSamples-nbs)*SampleOnCur);
                     gp_Pnt PonPrev = PrevEcurve.Value(ParOnPrev);
-                    gp_Pnt PonCur = Ecurve.Value(ParOnCur);
+                    gp_Pnt PonCur = Ecurve.Value(ParOnCur).XYZ() + Offset.XYZ();
                     SumDist += PonPrev.Distance(PonCur);
                   }
                 }
@@ -1516,7 +1532,7 @@ void BRepFill_CompatibleWires::ComputeOrigin(const  Standard_Boolean polar )
                const TopoDS_Vertex& Vprev = TopoDS::Vertex( PrevSeq(n) );
                gp_Pnt Pprev = BRep_Tool::Pnt(Vprev);
                const TopoDS_Vertex& V = TopoDS::Vertex( SeqVertices(k) );
-               gp_Pnt P = BRep_Tool::Pnt(V);
+               gp_Pnt P = BRep_Tool::Pnt(V).XYZ() + Offset.XYZ();
                SumDist += Pprev.Distance(P);
                 if (NbSamples > 0)
                 {
@@ -1535,7 +1551,7 @@ void BRepFill_CompatibleWires::ComputeOrigin(const  Standard_Boolean polar )
                       (Ecurve.FirstParameter() + nbs*SampleOnCur) :
                       (Ecurve.FirstParameter() + (NbSamples-nbs)*SampleOnCur);
                     gp_Pnt PonPrev = PrevEcurve.Value(ParOnPrev);
-                    gp_Pnt PonCur = Ecurve.Value(ParOnCur);
+                    gp_Pnt PonCur = Ecurve.Value(ParOnCur).XYZ() + Offset.XYZ();
                     SumDist += PonPrev.Distance(PonCur);
                   }
                 }
@@ -1554,7 +1570,7 @@ void BRepFill_CompatibleWires::ComputeOrigin(const  Standard_Boolean polar )
                const TopoDS_Vertex& Vprev = TopoDS::Vertex( PrevSeq(n) );
                gp_Pnt Pprev = BRep_Tool::Pnt(Vprev);
                const TopoDS_Vertex& V = TopoDS::Vertex( SeqVertices(k) );
-               gp_Pnt P = BRep_Tool::Pnt(V);
+               gp_Pnt P = BRep_Tool::Pnt(V).XYZ() + Offset.XYZ();
                SumDist += Pprev.Distance(P);
                 if (NbSamples > 0)
                 {
@@ -1576,7 +1592,7 @@ void BRepFill_CompatibleWires::ComputeOrigin(const  Standard_Boolean polar )
                       (Ecurve.FirstParameter() + (NbSamples-nbs)*SampleOnCur) :
                       (Ecurve.FirstParameter() + nbs*SampleOnCur);
                     gp_Pnt PonPrev = PrevEcurve.Value(ParOnPrev);
-                    gp_Pnt PonCur = Ecurve.Value(ParOnCur);
+                    gp_Pnt PonCur = Ecurve.Value(ParOnCur).XYZ() + Offset.XYZ();
                     SumDist += PonPrev.Distance(PonCur);
                   }
                 }
@@ -1586,7 +1602,7 @@ void BRepFill_CompatibleWires::ComputeOrigin(const  Standard_Boolean polar )
                const TopoDS_Vertex& Vprev = TopoDS::Vertex( PrevSeq(n) );
                gp_Pnt Pprev = BRep_Tool::Pnt(Vprev);
                const TopoDS_Vertex& V = TopoDS::Vertex( SeqVertices(k) );
-               gp_Pnt P = BRep_Tool::Pnt(V);
+               gp_Pnt P = BRep_Tool::Pnt(V).XYZ() + Offset.XYZ();
                SumDist += Pprev.Distance(P);
                 if (NbSamples > 0)
                 {
@@ -1605,7 +1621,7 @@ void BRepFill_CompatibleWires::ComputeOrigin(const  Standard_Boolean polar )
                       (Ecurve.FirstParameter() + (NbSamples-nbs)*SampleOnCur) :
                       (Ecurve.FirstParameter() + nbs*SampleOnCur);
                     gp_Pnt PonPrev = PrevEcurve.Value(ParOnPrev);
-                    gp_Pnt PonCur = Ecurve.Value(ParOnCur);
+                    gp_Pnt PonCur = Ecurve.Value(ParOnCur).XYZ() + Offset.XYZ();
                     SumDist += PonPrev.Distance(PonCur);
                   }
                 }
@@ -1661,8 +1677,8 @@ void BRepFill_CompatibleWires::ComputeOrigin(const  Standard_Boolean polar )
       newwire.Orientation( TopAbs_FORWARD );
       myWork(i) = newwire;
     }
+#ifdef DEB_EFV
 
-/*  
   for ( i=ideb; i<=myWork.Length(); i++) {
     
     const TopoDS_Wire& wire = TopoDS::Wire(myWork(i));
@@ -1742,7 +1758,7 @@ void BRepFill_CompatibleWires::ComputeOrigin(const  Standard_Boolean polar )
        // recherche du vertex correspondant a la projection conique
        Standard_Real angmin, angV, eta = Precision::Angular();
        TopoDS_Vertex Vopti;
-       angmin = PI/2;
+       angmin = M_PI/2;
        distmini = Precision::Infinite();
        gp_Dir dir0(gp_Vec(Pnew,P.Location()));
        for (Standard_Integer ii=1;ii<=SeqV.Length();ii++) {
@@ -1755,7 +1771,7 @@ void BRepFill_CompatibleWires::ComputeOrigin(const  Standard_Boolean polar )
            gp_Dir dir1(gp_Vec(Pnew,P1));
            angV = dir1.Angle(dir0);
          }
-         if (angV>PI/2) angV = PI - angV;
+         if (angV>M_PI/2) angV = M_PI - angV;
          if (angmin>angV+eta) {
            distmini = dist;
            angmin = angV;
@@ -1912,7 +1928,7 @@ void BRepFill_CompatibleWires::ComputeOrigin(const  Standard_Boolean polar )
       if (!Vsuiv.IsNull()) Psuiv=BRep_Tool::Pnt(Vsuiv);
     }
   }
-*/
+#endif
   
   // blocking sections ?
   if (vClosed) myWork(myWork.Length()) = myWork(1);
@@ -2009,11 +2025,11 @@ void BRepFill_CompatibleWires::SearchOrigin()
        norm = vec1 ^ vec2;
        gp_Ax1 Norm(P.Location(),norm);
        Standard_Real ang = vec1.AngleWithRef(vec2,norm);
-       if (ang > PI/2.0)
-         ang = PI - ang;
-       if (ang < -PI/2.0)
-         ang = -PI - ang;
-       if (Abs(ang-PI/2.0)<Precision::Angular()) {
+       if (ang > M_PI/2.0)
+         ang = M_PI - ang;
+       if (ang < -M_PI/2.0)
+         ang = -M_PI - ang;
+       if (Abs(ang-M_PI/2.0)<Precision::Angular()) {
          // cas d'ambiguite
          gp_Vec Vtrans(P0.Location(),P.Location()),Vsign;
          Standard_Real alpha,beta,sign=1;
@@ -2037,7 +2053,7 @@ void BRepFill_CompatibleWires::SearchOrigin()
       };
       gp_Vec VDebFin0(P1o,P2o), VDebFin(P1,P2);
       Standard_Real AStraight = VDebFin0.Angle(VDebFin);
-      parcours = (AStraight < PI/2.0? Standard_True: Standard_False);
+      parcours = (AStraight < M_PI/2.0? Standard_True: Standard_False);
     }
     
     // reconstruction of the wire