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 d09856d..0b8e372
@@ -1,24 +1,18 @@
 // Created on: 1998-07-02
 // Created by: Joelle CHAUVET
 // Copyright (c) 1998-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
 //
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
+// This file is part of Open CASCADE Technology software library.
 //
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+// 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.
 //
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
 
 #include <BRepFill_CompatibleWires.ixx>
 
@@ -69,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, 
@@ -120,7 +114,7 @@ static void EdgesFromVertex (const TopoDS_Wire&   W,
   }
 }
                                      
-
+#endif
 static void SeqOfVertices (const TopoDS_Wire&   W,
                           TopTools_SequenceOfShape& S)
 {
@@ -1461,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);
@@ -1476,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,11 +1496,6 @@ void BRepFill_CompatibleWires::ComputeOrigin(const  Standard_Boolean /*polar*/ )
       else
        for (j = 1; j <= theLength; j++)
          {
-            // get a vector to superpose SeqVertices(j) on PrevSeq(1)
-            const TopoDS_Vertex& Vprev = TopoDS::Vertex( PrevSeq(1) );
-            const TopoDS_Vertex& V = TopoDS::Vertex( SeqVertices(j) );
-            gp_Vec curToPrevVec( BRep_Tool::Pnt(V), BRep_Tool::Pnt(Vprev) );
-
            //Forward
            Standard_Real SumDist = 0.;
            for (k = j, n = 1; k <= theLength; k++, n++)
@@ -1499,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).XYZ() + curToPrevVec.XYZ();
+               gp_Pnt P = BRep_Tool::Pnt(V).XYZ() + Offset.XYZ();
                SumDist += Pprev.Distance(P);
                 if (NbSamples > 0)
                 {
@@ -1518,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).XYZ() + curToPrevVec.XYZ();
+                    gp_Pnt PonCur = Ecurve.Value(ParOnCur).XYZ() + Offset.XYZ();
                     SumDist += PonPrev.Distance(PonCur);
                   }
                 }
@@ -1528,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).XYZ() + curToPrevVec.XYZ();
+               gp_Pnt P = BRep_Tool::Pnt(V).XYZ() + Offset.XYZ();
                SumDist += Pprev.Distance(P);
                 if (NbSamples > 0)
                 {
@@ -1547,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).XYZ() + curToPrevVec.XYZ();
+                    gp_Pnt PonCur = Ecurve.Value(ParOnCur).XYZ() + Offset.XYZ();
                     SumDist += PonPrev.Distance(PonCur);
                   }
                 }
@@ -1566,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).XYZ() + curToPrevVec.XYZ();
+               gp_Pnt P = BRep_Tool::Pnt(V).XYZ() + Offset.XYZ();
                SumDist += Pprev.Distance(P);
                 if (NbSamples > 0)
                 {
@@ -1588,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).XYZ() + curToPrevVec.XYZ();
+                    gp_Pnt PonCur = Ecurve.Value(ParOnCur).XYZ() + Offset.XYZ();
                     SumDist += PonPrev.Distance(PonCur);
                   }
                 }
@@ -1598,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).XYZ() + curToPrevVec.XYZ();
+               gp_Pnt P = BRep_Tool::Pnt(V).XYZ() + Offset.XYZ();
                SumDist += Pprev.Distance(P);
                 if (NbSamples > 0)
                 {
@@ -1617,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).XYZ() + curToPrevVec.XYZ();
+                    gp_Pnt PonCur = Ecurve.Value(ParOnCur).XYZ() + Offset.XYZ();
                     SumDist += PonPrev.Distance(PonCur);
                   }
                 }
@@ -1673,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));
@@ -1924,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);