0026173: Wrong result of ChFi3d_ChBuilder algorithm: incorrect processing of G1 junct...
[occt.git] / src / ChFi3d / ChFi3d_Builder_1.cxx
index 6c1c97a..8526465 100644 (file)
@@ -90,83 +90,6 @@ static TopOpeBRepDS_BuildTool mkbuildtool()
   return BT;
 }
 
-//  Modified by Sergey KHROMOV - Tue Dec 18 18:02:55 2001 Begin
-Standard_Boolean isTangentFaces(const TopoDS_Edge &theEdge,
-                               const TopoDS_Face &theFace1,
-                               const TopoDS_Face &theFace2)
-{
-  if (BRep_Tool::Continuity( theEdge, theFace1, theFace2 ) != GeomAbs_C0)
-    return Standard_True;
-
-  Standard_Real TolC0 = Max(0.001, 1.5*BRep_Tool::Tolerance(theEdge));
-
-  Standard_Real aFirst;
-  Standard_Real aLast;
-    
-// Obtaining of pcurves of edge on two faces.
-  const Handle(Geom2d_Curve) aC2d1 = BRep_Tool::CurveOnSurface
-                                                (theEdge, theFace1, aFirst, aLast);
-  const Handle(Geom2d_Curve) aC2d2 = BRep_Tool::CurveOnSurface
-                                                (theEdge, theFace2, aFirst, aLast);
-  if (aC2d1.IsNull() || aC2d2.IsNull())
-    return Standard_False;
-
-// Obtaining of two surfaces from adjacent faces.
-  Handle(Geom_Surface) aSurf1 = BRep_Tool::Surface(theFace1);
-  Handle(Geom_Surface) aSurf2 = BRep_Tool::Surface(theFace2);
-
-  if (aSurf1.IsNull() || aSurf2.IsNull())
-    return Standard_False;
-
-// Computation of the number of samples on the edge.
-  BRepAdaptor_Surface              aBAS1(theFace1);
-  BRepAdaptor_Surface              aBAS2(theFace2);
-  Handle(BRepAdaptor_HSurface)     aBAHS1      = new BRepAdaptor_HSurface(aBAS1);
-  Handle(BRepAdaptor_HSurface)     aBAHS2      = new BRepAdaptor_HSurface(aBAS2);
-  Handle(BRepTopAdaptor_TopolTool) aTool1      = new BRepTopAdaptor_TopolTool(aBAHS1);
-  Handle(BRepTopAdaptor_TopolTool) aTool2      = new BRepTopAdaptor_TopolTool(aBAHS2);
-  Standard_Integer                 aNbSamples1 =     aTool1->NbSamples();
-  Standard_Integer                 aNbSamples2 =     aTool2->NbSamples();
-  Standard_Integer                 aNbSamples  =     Max(aNbSamples1, aNbSamples2);
-
-
-// Computation of the continuity.
-  Standard_Real    aPar;
-  Standard_Real    aDelta = (aLast - aFirst)/(aNbSamples - 1);
-  Standard_Integer i, nbNotDone = 0;
-
-  for (i = 1, aPar = aFirst; i <= aNbSamples; i++, aPar += aDelta) {
-    if (i == aNbSamples) aPar = aLast;
-
-    LocalAnalysis_SurfaceContinuity aCont(aC2d1,  aC2d2,  aPar,
-                                         aSurf1, aSurf2, GeomAbs_G1,
-                                         0.001, TolC0, 0.1, 0.1, 0.1);
-    if (!aCont.IsDone())
-      {
-       nbNotDone++;
-       continue;
-      }
-    if (!aCont.IsG1())
-      return Standard_False;
-  }
-  
-  if (nbNotDone == aNbSamples)
-    return Standard_False;
-
-  //Compare normals of tangent faces in the middle point
-  Standard_Real MidPar = (aFirst + aLast)/2.;
-  gp_Pnt2d uv1 = aC2d1->Value(MidPar);
-  gp_Pnt2d uv2 = aC2d2->Value(MidPar);
-  gp_Dir normal1, normal2;
-  TopOpeBRepTool_TOOL::Nt( uv1, theFace1, normal1 );
-  TopOpeBRepTool_TOOL::Nt( uv2, theFace2, normal2 );
-  Standard_Real dot = normal1.Dot(normal2);
-  if (dot < 0.)
-    return Standard_False;
-  return Standard_True;
-}
-//  Modified by Sergey KHROMOV - Tue Dec 18 18:02:56 2001 End
-
 //=======================================================================
 //function : ChFi3d_Builder
 //purpose  : 
@@ -429,7 +352,7 @@ Standard_Boolean ChFi3d_Builder::FaceTangency(const TopoDS_Edge& E0,
   if(Nbf < 2) return Standard_False;
 //  Modified by Sergey KHROMOV - Fri Dec 21 17:44:19 2001 Begin
 //if (BRep_Tool::Continuity(E1,F[0],F[1]) != GeomAbs_C0) {
-  if (isTangentFaces(E1,F[0],F[1])) {
+  if (ChFi3d_isTangentFaces(E1,F[0],F[1])) {
 //  Modified by Sergey KHROMOV - Fri Dec 21 17:44:21 2001 End
     return Standard_False;
   }
@@ -448,7 +371,7 @@ Standard_Boolean ChFi3d_Builder::FaceTangency(const TopoDS_Edge& E0,
       if(Nbf < 2) return Standard_False;
 //  Modified by Sergey KHROMOV - Tue Dec 18 18:10:40 2001 Begin
 //    if (BRep_Tool::Continuity(Ec,F[0],F[1]) < GeomAbs_G1) {
-      if (!isTangentFaces(Ec,F[0],F[1])) {
+      if (!ChFi3d_isTangentFaces(Ec,F[0],F[1])) {
 //  Modified by Sergey KHROMOV - Tue Dec 18 18:10:41 2001 End
        return Standard_False;
       }
@@ -533,6 +456,8 @@ static Standard_Boolean TangentOnVertex(const TopoDS_Vertex&    V,
 
 void ChFi3d_Builder::PerformExtremity (const Handle(ChFiDS_Spine)& Spine) 
 {
+  Standard_Integer NbG1Connections = 0;
+  
   for(Standard_Integer ii = 1; ii <= 2; ii++){
     TopoDS_Edge E[3],Ec;
     TopoDS_Vertex V;
@@ -559,34 +484,41 @@ void ChFi3d_Builder::PerformExtremity (const Handle(ChFiDS_Spine)& Spine)
 
     if(sst == ChFiDS_BreakPoint){
       TopTools_ListIteratorOfListOfShape It;//,Jt;
-      Standard_Integer i = 0, j;
+      Standard_Integer i = 0;
       Standard_Boolean sommetpourri = Standard_False;
-      for (It.Initialize(myVEMap(V));It.More();It.Next()){
-       Ec = TopoDS::Edge(It.Value());
+      TopTools_IndexedMapOfShape EdgesOfV;
+      //to avoid repeating of edges
+      for (It.Initialize(myVEMap(V)); It.More(); It.Next())
+        EdgesOfV.Add(It.Value());
+      for (Standard_Integer ind = 1; ind <= EdgesOfV.Extent(); ind++) {
+       Ec = TopoDS::Edge(EdgesOfV(ind));
        Standard_Boolean bonedge = !BRep_Tool::Degenerated(Ec);
+        if (bonedge)
+        {
+          TopoDS_Face F1, F2;
+          ChFi3d_conexfaces(Ec, F1, F2, myEFMap);
+          if (!F2.IsNull() && ChFi3d_isTangentFaces(Ec, F1, F2, GeomAbs_G2))
+          {
+            bonedge = Standard_False;
+            if (!F1.IsSame(F2))
+              NbG1Connections++;
+          }
+        }
        if(bonedge){
-         Standard_Boolean eclosed = BRep_Tool::IsClosed(Ec);
-         Standard_Integer nboc = 0;
-         for(j = 0; j <= i && bonedge; j++){ 
-           if(!eclosed) bonedge = !Ec.IsSame(E[j]); 
-           else if(Ec.IsSame(E[j])){
-             nboc++;
-             bonedge = nboc<2;
-           }
-         }
-       }
-       if(bonedge){
-         if( i < 2 ){
-           i++;
-           E[i] = Ec;
-         }
-         else{
+          if (!Ec.IsSame(E[0]))
+          {
+            if( i < 2 ){
+              i++;
+              E[i] = Ec;
+            }
+            else{
 #ifdef OCCT_DEBUG
            cout<<"top has more than 3 edges"<<endl;
 #endif
-           sommetpourri = Standard_True;
-           break;
-         }
+              sommetpourri = Standard_True;
+              break;
+            }
+          }
        }
       }
       if(i != 2) sommetpourri = Standard_True;
@@ -610,6 +542,7 @@ void ChFi3d_Builder::PerformExtremity (const Handle(ChFiDS_Spine)& Spine)
       }
       if(kf == jf) nbf++;
     }
+    nbf -= NbG1Connections;
     if(nbf>3) {
       Spine->SetFirstStatus(ChFiDS_BreakPoint);
 #ifdef OCCT_DEBUG
@@ -626,6 +559,7 @@ void ChFi3d_Builder::PerformExtremity (const Handle(ChFiDS_Spine)& Spine)
       }
       if(kf == jf) nbf++;
     }
+    nbf -= NbG1Connections;
     if(nbf>3) {
       Spine->SetLastStatus(ChFiDS_BreakPoint);
 #ifdef OCCT_DEBUG
@@ -661,7 +595,7 @@ Standard_Boolean ChFi3d_Builder::PerformElement(const Handle(ChFiDS_Spine)& Spin
   if(ff1.IsNull() || ff2.IsNull()) return 0;
 //  Modified by Sergey KHROMOV - Fri Dec 21 17:46:22 2001 End
 //if(BRep_Tool::Continuity(Ec,ff1,ff2) != GeomAbs_C0) return 0;
-  if (isTangentFaces(Ec,ff1,ff2)) return 0;
+  if (ChFi3d_isTangentFaces(Ec,ff1,ff2)) return 0;
 //  Modified by Sergey KHROMOV - Fri Dec 21 17:46:24 2001 Begin
   
   BRepAdaptor_Curve CEc,CEv;