0029858: Modeling Data - Regression in GeomAPI_ExtremaCurveCurve
[occt.git] / src / ChFi3d / ChFi3d_Builder_CnCrn.cxx
old mode 100755 (executable)
new mode 100644 (file)
index a736a10..65a2de2
@@ -1,22 +1,18 @@
 // Created on: 1997-03-01
 // Created by: MPS  
 // Copyright (c) 1997-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 License 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.
 
 // Modified by  MPS (14-04-97)  traitement des cas  ou il n'y a pas
 //                              d'intersection entre les stripes 
 //                              consecutives   
 // Traitement des coins                 
 
-#include <Adaptor3d_HCurveOnSurface.hxx>
+#include <Adaptor2d_HCurve2d.hxx>
 #include <Adaptor3d_CurveOnSurface.hxx>
+#include <Adaptor3d_HCurveOnSurface.hxx>
+#include <Adaptor3d_HSurface.hxx>
+#include <Adaptor3d_TopolTool.hxx>
+#include <AppBlend_Approx.hxx>
+#include <Blend_CurvPointFuncInv.hxx>
+#include <Blend_FuncInv.hxx>
+#include <Blend_Function.hxx>
+#include <Blend_RstRstFunction.hxx>
+#include <Blend_SurfCurvFuncInv.hxx>
+#include <Blend_SurfPointFuncInv.hxx>
+#include <Blend_SurfRstFunction.hxx>
 #include <Bnd_Box2d.hxx>
 #include <BndLib_Add2dCurve.hxx>
 #include <BRep_Tool.hxx>
-#include <BRepTools.hxx>
+#include <BRepAdaptor_HCurve2d.hxx>
+#include <BRepAdaptor_HSurface.hxx>
 #include <BRepAlgo_NormalProjection.hxx>
-#include <BRepLib_MakeEdge.hxx>  
-#include <ChFi3d_Builder.jxx>
+#include <BRepBlend_Line.hxx>
+#include <BRepLib_MakeEdge.hxx>
+#include <BRepLib_MakeFace.hxx>
+#include <BRepTools.hxx>
+#include <BRepTopAdaptor_TopolTool.hxx>
+#include <ChFi3d_Builder.hxx>
 #include <ChFi3d_Builder_0.hxx>
+#include <ChFiDS_CommonPoint.hxx>
 #include <ChFiDS_FaceInterference.hxx>
+#include <ChFiDS_HData.hxx>
+#include <ChFiDS_HElSpine.hxx>
 #include <ChFiDS_ListIteratorOfListOfStripe.hxx>
-#include <ChFiDS_SurfData.hxx>
+#include <ChFiDS_Regul.hxx>
 #include <ChFiDS_SequenceOfSurfData.hxx>
+#include <ChFiDS_Spine.hxx>
 #include <ChFiDS_Stripe.hxx>
-#include <ChFiDS_HData.hxx>
-#include <ChFiDS_CommonPoint.hxx>
-#include <ChFiDS_Regul.hxx>
 #include <ChFiDS_StripeArray1.hxx>
-#include <Extrema_ExtPC.hxx>
+#include <ChFiDS_SurfData.hxx>
 #include <Extrema_ExtCC.hxx>
-#include <Extrema_POnCurv.hxx>
-#include <GeomLib.hxx>
 #include <Extrema_ExtPC.hxx>
+#include <Extrema_POnCurv.hxx>
+#include <FairCurve_Batten.hxx>
 #include <Geom2d_BSplineCurve.hxx>
-#include <GeomAdaptor_HSurface.hxx>
+#include <Geom2d_Curve.hxx>
 #include <Geom2d_Line.hxx>
-#include <Geom_Line.hxx>
-#include <Geom_Curve.hxx>
 #include <Geom2d_TrimmedCurve.hxx>
+#include <Geom2dAdaptor_HCurve.hxx>
+#include <Geom2dLProp_CLProps2d.hxx>
+#include <Geom_BezierCurve.hxx>
+#include <Geom_BSplineSurface.hxx>
+#include <Geom_Curve.hxx>
+#include <Geom_Line.hxx>
+#include <Geom_Surface.hxx>
+#include <GeomAdaptor.hxx>
+#include <GeomAdaptor_HSurface.hxx>
 #include <GeomInt_IntSS.hxx>
 #include <GeomLib.hxx>
-#include <GeomAdaptor.hxx>
-#include <Geom2dAdaptor_HCurve.hxx>
 #include <GeomPlate_BuildPlateSurface.hxx>
-#include <GeomPlate_Surface.hxx>
+#include <GeomPlate_CurveConstraint.hxx>
+#include <GeomPlate_HArray1OfHCurve.hxx>
 #include <GeomPlate_MakeApprox.hxx>
 #include <GeomPlate_PlateG0Criterion.hxx>
-#include <GeomPlate_HArray1OfHCurveOnSurface.hxx>
-#include <Geom_Surface.hxx>
-#include <Geom_BezierCurve.hxx>
-#include <Geom2dLProp_CLProps2d.hxx>
-#include <GeomPlate_CurveConstraint.hxx>
-#include <FairCurve_Batten.hxx>
-#include <Geom2d_BSplineCurve.hxx>
+#include <GeomPlate_Surface.hxx>
+#include <gp_Dir2d.hxx>
 #include <gp_Pnt.hxx>
 #include <gp_Pnt2d.hxx>
-#include <gp_Dir2d.hxx>
 #include <math_Matrix.hxx>
 #include <PLib.hxx>
-#include <TColStd_HArray1OfInteger.hxx>
-#include <TColStd_ListOfInteger.hxx>
-#include <TColgp_SequenceOfXY.hxx>
-#include <TColgp_SequenceOfXYZ.hxx>
-#include <TColgp_Array1OfXYZ.hxx>
+#include <Precision.hxx>
+#include <Standard_ConstructionError.hxx>
+#include <Standard_NoSuchObject.hxx>
+#include <Standard_OutOfRange.hxx>
+#include <TColGeom2d_Array1OfCurve.hxx>
+#include <TColGeom2d_HArray1OfCurve.hxx>
+#include <TColGeom2d_SequenceOfCurve.hxx>
+#include <TColGeom_Array1OfCurve.hxx>
+#include <TColGeom_SequenceOfCurve.hxx>
 #include <TColgp_Array1OfPnt.hxx>
 #include <TColgp_Array1OfPnt2d.hxx>
-#include <TopTools_IndexedMapOfShape.hxx>
-#include <TColStd_Array1OfInteger.hxx>
+#include <TColgp_Array1OfXYZ.hxx>
+#include <TColgp_SequenceOfXY.hxx>
+#include <TColgp_SequenceOfXYZ.hxx>
 #include <TColStd_Array1OfBoolean.hxx>
-#include <TColStd_Array2OfInteger.hxx>
+#include <TColStd_Array1OfInteger.hxx>
 #include <TColStd_Array1OfReal.hxx>
+#include <TColStd_Array2OfInteger.hxx>
 #include <TColStd_Array2OfReal.hxx>
-#include <TColGeom2d_Array1OfCurve.hxx>
-#include <TColGeom2d_SequenceOfCurve.hxx>
-#include <TColGeom_Array1OfCurve.hxx>
-#include <TColGeom_SequenceOfCurve.hxx>
-#include <TColGeom2d_HArray1OfCurve.hxx>
+#include <TColStd_HArray1OfInteger.hxx>
+#include <TColStd_ListOfInteger.hxx>
 #include <TopAbs_Orientation.hxx>
 #include <TopExp.hxx>
-#include <TopExp_Explorer.hxx>    
-#include <TopOpeBRepDS_DataStructure.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Face.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <TopOpeBRepBuild_HBuilder.hxx>
 #include <TopOpeBRepDS_Curve.hxx>
-#include <TopOpeBRepDS_Point.hxx>
-#include <TopOpeBRepDS_Surface.hxx> 
+#include <TopOpeBRepDS_CurvePointInterference.hxx>
+#include <TopOpeBRepDS_DataStructure.hxx>
+#include <TopOpeBRepDS_HDataStructure.hxx>
+#include <TopOpeBRepDS_Kind.hxx>
 #include <TopOpeBRepDS_ListOfInterference.hxx>
+#include <TopOpeBRepDS_Point.hxx>
 #include <TopOpeBRepDS_SolidSurfaceInterference.hxx>
-#include <TopOpeBRepDS_Kind.hxx>
-#include <TopOpeBRepDS_Transition.hxx>
-#include <TopOpeBRepDS_CurvePointInterference.hxx>
+#include <TopOpeBRepDS_Surface.hxx>
 #include <TopOpeBRepDS_SurfaceCurveInterference.hxx>
+#include <TopOpeBRepDS_Transition.hxx>
 #include <TopTools_Array2OfShape.hxx>
-#include <BRepLib_MakeFace.hxx> 
-#include <Precision.hxx>
+#include <TopTools_IndexedMapOfShape.hxx>
+
 // performances 
-#ifdef DEB
+#ifdef OCCT_DEBUG
 #include <OSD_Chronometer.hxx>
 extern Standard_Real  t_plate ,t_approxplate,t_batten; 
 extern void ChFi3d_InitChron(OSD_Chronometer& ch);
 extern void ChFi3d_ResultChron(OSD_Chronometer & ch,Standard_Real& time);
 #endif
 
-//  Modified by Sergey KHROMOV - Fri Dec 21 17:08:19 2001 Begin
-Standard_Boolean isTangentFaces(const TopoDS_Edge &theEdge,
-                               const TopoDS_Face &theFace1,
-                               const TopoDS_Face &theFace2);
-//  Modified by Sergey KHROMOV - Fri Dec 21 17:08:19 2001 End
 
 //=======================================================================
 //function : Indices
@@ -420,10 +437,20 @@ static void CurveHermite (const TopOpeBRepDS_DataStructure& DStr,
     GeomAdaptor_Curve L (Bezier);
     Extrema_ExtCC ext (C,L);
     if (ext.IsDone()){ 
-      if (ext.NbExt()!=0){ 
+      if (!ext.IsParallel() && ext.NbExt()!=0){ 
         Extrema_POnCurv POnC, POnL;
         ext.Points(1, POnC, POnL);
-        param.ChangeValue(nb) =POnC.Parameter();
+        if (POnC.Value().Distance(POnL.Value()) < Precision::Confusion())
+          param.ChangeValue(nb) =POnC.Parameter();
+        else
+        {
+          if (!cproj.Value(nb).IsNull()) {
+            cproj.Value(nb)->D0(cproj.Value(nb)->LastParameter(),p01);
+          }
+          else if (!cproj.Value(nb+1).IsNull()) {
+            cproj.Value(nb+1)->D0(cproj.Value(nb+1)->FirstParameter(),p01);
+          }
+        }
       }
     }
     if (!ext.IsDone()||ext.NbExt()==0) {
@@ -519,10 +546,10 @@ static void CalculBatten (const Handle (GeomAdaptor_HSurface) ASurf,
     FairCurve_AnalysisCode Iana; 
     Standard_Boolean Ok;
     Ok = Bat.Compute(Iana,25,1.e-2);
-#if DEB
+#ifdef OCCT_DEBUG
     if (!Ok) { 
-      cout<<"no batten :";
-      Bat.Dump(cout);
+      std::cout<<"no batten :";
+      Bat.Dump(std::cout);
     }    
 #endif  
     if (Ok) {
@@ -658,7 +685,7 @@ static void PerformTwoCornerSameExt(TopOpeBRepDS_DataStructure& DStr,
   ChFiDS_CommonPoint& Com12= stripe1->SetOfSurfData()->Value(index1)->ChangeVertex (isfirst,2);
   isfirst=sens2==1;
   ChFiDS_CommonPoint& Com21= stripe2->SetOfSurfData()->Value(index2)->ChangeVertex (isfirst,1);
-#ifdef DEB
+#ifdef OCCT_DEBUG
 //  ChFiDS_CommonPoint& Com22= 
 //    stripe2->SetOfSurfData()->Value(index2)->ChangeVertex (isfirst,2);
 #endif
@@ -917,7 +944,6 @@ static Standard_Integer SurfIndex(const ChFiDS_StripeArray1& StripeArray1,
   case FACE2:       return aSurfData->IndexOfS2();
   default:          return -1;
   }
-  return -1;
 }
 
 //=======================================================================
@@ -983,7 +1009,7 @@ void  ChFi3d_Builder::PerformMoreThreeCorner(const Standard_Integer Jndex,
 //    ========================================
 //             Initialisations
 //     ========================================
-#ifdef DEB
+#ifdef OCCT_DEBUG
   OSD_Chronometer ch;
 #endif 
   TopOpeBRepDS_DataStructure& DStr=myDS->ChangeDS();  
@@ -1043,13 +1069,13 @@ void  ChFi3d_Builder::PerformMoreThreeCorner(const Standard_Integer Jndex,
   ChFiDS_ListIteratorOfListOfStripe It;
   Handle(ChFiDS_Stripe) cd2,cdbid,cnext;
   TopoDS_Face face;
-  Standard_Integer jfp,ii;
+  Standard_Integer jfp = 0,ii;
   Standard_Integer ic,icplus,icmoins,icplus2,
-                   sense,index,indice,isurf1,isurf2;
-  Standard_Integer cbplus=0, n3d=0,IVtx,nb;
+                   sense,index = 0,indice,isurf1,isurf2;
+  Standard_Integer cbplus=0, n3d=0,IVtx = 0,nb;
   Standard_Boolean sameside,trouve,isfirst;
   Standard_Real pardeb ,parfin,xdir,ydir;
-  Standard_Real tolapp=1.e-4,maxapp,maxapp1,avedev;
+  Standard_Real tolapp=1.e-4,maxapp = 0.,maxapp1 = 0.,avedev;
   Handle (TopOpeBRepDS_CurvePointInterference) Interfp1, Interfp2;
   Handle (TopOpeBRepDS_SurfaceCurveInterference) Interfc;
   Handle(Geom_Curve) Curv3d;
@@ -1058,7 +1084,7 @@ void  ChFi3d_Builder::PerformMoreThreeCorner(const Standard_Integer Jndex,
   Standard_Integer num;
   TopoDS_Edge Ecur; 
   TopTools_ListIteratorOfListOfShape ItF;
-#ifdef DEB
+#ifdef OCCT_DEBUG
 //  Standard_Integer nface=ChFi3d_nbface(myVFMap(V1));
 #endif
   TopoDS_Face F1,F2;
@@ -1112,8 +1138,7 @@ void  ChFi3d_Builder::PerformMoreThreeCorner(const Standard_Integer Jndex,
       nbcouture++;
     }
     else ChFi3d_cherche_edge(V1,Evive,Fcur,Enext,VV);
-    if (Enext.IsNull())Standard_Failure::Raise
-    ("PerformMoreThreeCorner: pb in the parsing of edges and faces"); 
+    if (Enext.IsNull())throw Standard_Failure("PerformMoreThreeCorner: pb in the parsing of edges and faces");
     if (Enext.IsSame(edgelibre1)|| Enext.IsSame(edgelibre2)) {
       CD.SetValue(ii, cdbid);
       Index.SetValue(ii, 0);
@@ -1236,7 +1261,7 @@ void  ChFi3d_Builder::PerformMoreThreeCorner(const Standard_Integer Jndex,
 //  Modified by Sergey KHROMOV - Fri Dec 21 18:11:02 2001 Begin
 //     regul.SetValue(ic,BRep_Tool::Continuity(TopoDS::Edge(Evive.Value(ic)),F1,F2)
 //                  !=GeomAbs_C0); 
-       regul.SetValue(ic,isTangentFaces(TopoDS::Edge(Evive.Value(ic)),F1,F2)); 
+       regul.SetValue(ic, ChFi3d_isTangentFaces(TopoDS::Edge(Evive.Value(ic)),F1,F2)); 
 //  Modified by Sergey KHROMOV - Fri Dec 21 18:11:07 2001 End
       }
     }
@@ -1325,8 +1350,8 @@ void  ChFi3d_Builder::PerformMoreThreeCorner(const Standard_Integer Jndex,
     isOnSameDiff = isOnSame && isOnDiff;
   }
   if ( isOnSameDiff ) {
-#ifdef DEB
-    cout << "OnSame + OnDiff, PerformMoreThreeCorner() calls PerformOneCorner()" << endl;
+#ifdef OCCT_DEBUG
+    std::cout << "OnSame + OnDiff, PerformMoreThreeCorner() calls PerformOneCorner()" << std::endl;
 #endif
     PerformOneCorner (Jndex, Standard_True);
   }
@@ -1453,9 +1478,9 @@ void  ChFi3d_Builder::PerformMoreThreeCorner(const Standard_Integer Jndex,
       oksea.SetValue(ic, Standard_False);
     }
     else {
-      Standard_Integer jf1;
-      Standard_Integer i1,i2;
-      Standard_Real pa1,pa2;
+      Standard_Integer jf1 = 0;
+      Standard_Integer i1 = 0,i2 = 0;
+      Standard_Real pa1 = 0.,pa2;
       Standard_Boolean ok;
       Handle(ChFiDS_Stripe) strip;
       Standard_Real angedg;
@@ -1825,7 +1850,7 @@ void  ChFi3d_Builder::PerformMoreThreeCorner(const Standard_Integer Jndex,
 // Then this courbe3d is projected on all faces (nbface) that
 // separate icmoins and indfin
   Standard_Integer nbface = 0;
-  Standard_Real  error;
+  Standard_Real  error = 0.;
   TColGeom2d_Array1OfCurve proj2d1(0,size);
   TColGeom2d_Array1OfCurve proj2d2(0,size);
   TColGeom_Array1OfCurve cproj1(0,size);
@@ -2036,7 +2061,7 @@ void  ChFi3d_Builder::PerformMoreThreeCorner(const Standard_Integer Jndex,
       jfp = 3 - jf.Value(ic);
       Calcul_P2dOnSurf(CD.Value(ic),jfp,i.Value(ic,icmoins),p.Value(ic,icmoins),p2d1);
       Calcul_P2dOnSurf(CD.Value(ic),jf.Value(ic),i.Value(ic,icplus),p.Value(ic,icplus),p2d2);
-//      if (i[ic][icplus]!=  i[ic][icmoins]) cout<<"probleme surface"<<endl;
+//      if (i[ic][icplus]!=  i[ic][icmoins]) std::cout<<"probleme surface"<<std::endl;
       indice= SurfIndex(CD, ic, i.Value(ic,icplus), ChFiSURFACE);
       Handle (GeomAdaptor_HSurface) Asurf =
        new GeomAdaptor_HSurface(DStr.Surface(indice).Surface());
@@ -2293,7 +2318,7 @@ void  ChFi3d_Builder::PerformMoreThreeCorner(const Standard_Integer Jndex,
           Standard_Boolean contraint1=Standard_True,
                             contraint2=Standard_True;
           if (raccordbatten) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
            ChFi3d_InitChron(ch);// initial performances for  battens  
 #endif  
             Standard_Boolean inverseic,inverseicplus;
@@ -2319,7 +2344,7 @@ void  ChFi3d_Builder::PerformMoreThreeCorner(const Standard_Integer Jndex,
             contraint2=Standard_False;
            CalculBatten(Asurf,TopoDS::Face(Fvive(ic,icplus)),xdir,ydir,p2d1,p2d2,contraint1,contraint2,curv2d1,curv2d2,p.Value(ic,icplus),
                         p.Value(icplus,ic),inverseic,inverseicplus,pcurve);
-#ifdef DEB
+#ifdef OCCT_DEBUG
            ChFi3d_ResultChron( ch,t_batten);  // resulting performances for battens 
 #endif 
           }
@@ -2591,19 +2616,19 @@ void  ChFi3d_Builder::PerformMoreThreeCorner(const Standard_Integer Jndex,
       }
   } 
  
-#ifdef DEB
+#ifdef OCCT_DEBUG
   ChFi3d_InitChron(ch); // init performances for plate 
 #endif
 
   PSurf.Perform();
 
-#ifdef DEB  
+#ifdef OCCT_DEBUG
   ChFi3d_ResultChron(ch, t_plate); //result performances for plate 
 #endif 
 
   // call of approx  
  
-#ifdef DEB
+#ifdef OCCT_DEBUG
   ChFi3d_InitChron(ch);  // init performances for approxplate
 #endif
   if (PSurf.IsDone()) {
@@ -2625,14 +2650,14 @@ void  ChFi3d_Builder::PerformMoreThreeCorner(const Standard_Integer Jndex,
     Standard_Real coef = 1.1 ,apperror;
     apperror=Mapp.CriterionError()*coef;
 
-#ifdef DEB  
+#ifdef OCCT_DEBUG
   ChFi3d_ResultChron(ch, t_approxplate); // result performances for approxplate
 #endif
   
 //  Storage of the surface plate and corresponding curves in the DS 
 
     TopAbs_Orientation orplate,orsurfdata,orpcurve,orien;
-#ifdef DEB
+#ifdef OCCT_DEBUG
 //    Standard_Real ang1=PSurf.G1Error();
 #endif
 //     gp_Vec n1,n2,du,dv,du1,dv1;