0027271: Unifysamedomain invalid result
authorjgv <jgv@opencascade.com>
Fri, 25 Mar 2016 14:40:07 +0000 (17:40 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 8 Apr 2016 08:50:58 +0000 (11:50 +0300)
Prevent merging of faces along periodic direction.

Test case "bugs heal bug27000_1" has been corrected to actual state of the algorithm.

src/ShapeUpgrade/ShapeUpgrade_UnifySameDomain.cxx
tests/bugs/heal/bug27000_1
tests/bugs/modalg_6/bug27271 [new file with mode: 0644]

index d6d435f..b36a1f7 100644 (file)
@@ -86,6 +86,8 @@
 #include <gp_Circ.hxx>
 #include <BRepAdaptor_Curve.hxx>
 #include <BRepClass_FaceClassifier.hxx>
+#include <BRepAdaptor_Curve2d.hxx>
+#include <gp_Vec2d.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(ShapeUpgrade_UnifySameDomain,MMgt_TShared)
 
@@ -95,6 +97,42 @@ struct SubSequenceOfEdges
   TopoDS_Edge UnionEdges;
 };
 
+static Standard_Boolean IsLikeSeam(const TopoDS_Edge& anEdge,
+                                   const TopoDS_Face& aFace,
+                                   const Handle(Geom_Surface)& aBaseSurface)
+{
+  if (!aBaseSurface->IsUPeriodic() && !aBaseSurface->IsVPeriodic())
+    return Standard_False;
+
+  BRepAdaptor_Curve2d BAcurve2d(anEdge, aFace);
+  gp_Pnt2d FirstPoint, LastPoint;
+  gp_Vec2d FirstDir, LastDir;
+  BAcurve2d.D1(BAcurve2d.FirstParameter(), FirstPoint, FirstDir);
+  BAcurve2d.D1(BAcurve2d.LastParameter(),  LastPoint,  LastDir);
+  Standard_Real Length = FirstDir.Magnitude();
+  if (Length <= gp::Resolution())
+    return Standard_False;
+  else
+    FirstDir /= Length;
+  Length = LastDir.Magnitude();
+  if (Length <= gp::Resolution())
+    return Standard_False;
+  else
+    LastDir /= Length;
+  
+  Standard_Real Tol = 1.e-7;
+  if (aBaseSurface->IsUPeriodic() &&
+    (Abs(FirstDir.X()) < Tol) &&
+    (Abs(LastDir.X()) < Tol))
+    return Standard_True;
+
+  if (aBaseSurface->IsVPeriodic() &&
+    (Abs(FirstDir.Y()) < Tol) &&
+    (Abs(LastDir.Y()) < Tol))
+    return Standard_True;
+
+  return Standard_False;
+}
 
 //=======================================================================
 //function : AddOrdinaryEdges
@@ -641,11 +679,11 @@ static Standard_Boolean MergeSubSeq(const TopTools_SequenceOfShape& aChain, Topo
       }
       if (Abs(FP) < Precision::PConfusion())
       {
-      B.MakeEdge (E,Cir,Precision::Confusion());
-      B.Add(E,V1);
-      B.Add(E,V2);
-      E.Orientation(FE.Orientation());
-    }
+        B.MakeEdge (E,Cir, Precision::Confusion());
+        B.Add(E,V1);
+        B.Add(E,V2);
+        E.Orientation(FE.Orientation());
+      }
       else
       {
         GC_MakeCircle MC1 (adef.Value(FP), adef.Value((FP + LP) * 0.5), adef.Value(LP));
@@ -869,7 +907,7 @@ static Standard_Boolean MergeEdges(TopTools_SequenceOfShape& SeqEdges,
           if (!aMapVE.Contains(aV))
             aMapVE.Add(aV, TopTools_ListOfShape());
           aMapVE.ChangeFromKey(aV).Append(anEdge);
-        }
+  }
       }
     }
   }
@@ -891,7 +929,7 @@ static Standard_Boolean MergeEdges(TopTools_SequenceOfShape& SeqEdges,
 
     // make chain for unite
     TopTools_SequenceOfShape aChain;
-    aChain.Append(edge);
+        aChain.Append(edge);
     aUsedEdges.Add(edge);
     TopoDS_Vertex V[2];
     TopExp::Vertices(edge, V[0], V[1], Standard_True);
@@ -912,7 +950,7 @@ static Standard_Boolean MergeEdges(TopTools_SequenceOfShape& SeqEdges,
           if (!aUsedEdges.Contains(edge))
           {
             if (j == 0)
-              aChain.Prepend(edge);
+        aChain.Prepend(edge);
             else
               aChain.Append(edge);
             aUsedEdges.Add(edge);
@@ -921,17 +959,17 @@ static Standard_Boolean MergeEdges(TopTools_SequenceOfShape& SeqEdges,
             V[j] = (VF2.IsSame(V[j]) ? VL2 : VF2);
             isAdded = Standard_True;
             break;
-          }
-        }
       }
     }
+  }
+    }
 
     if (aChain.Length() < 2)
       continue;
 
-    Standard_Boolean IsClosed = Standard_False;
+  Standard_Boolean IsClosed = Standard_False;
     if (V[0].IsSame ( V[1] ))
-      IsClosed = Standard_True;
+    IsClosed = Standard_True;
 
     // split chain by vertices at which merging is not possible
     NCollection_Sequence<SubSequenceOfEdges> aOneSeq;
@@ -1200,6 +1238,10 @@ void ShapeUpgrade_UnifySameDomain::UnifyFaces()
 
           if (IsSameDomain(aFace,anCheckedFace)) {
 
+            // hotfix for 27271: prevent merging along periodic direction.
+            if (IsLikeSeam(edge, aFace, aBaseSurface))
+              continue;
+
             // replacing pcurves
             TopoDS_Face aMockUpFace;
             BRep_Builder B;
@@ -1483,11 +1525,11 @@ void ShapeUpgrade_UnifySameDomain::UnifyFaces()
             }
             else
             {
-              Handle(ShapeExtend_WireData) sbwd =
+            Handle(ShapeExtend_WireData) sbwd =
                 new ShapeExtend_WireData (aWire);
-              ShapeFix_WireSegment seg ( sbwd, TopAbs_REVERSED );
-              wires.Append(seg);
-            }
+            ShapeFix_WireSegment seg ( sbwd, TopAbs_REVERSED );
+            wires.Append(seg);
+          }
           }
 
           CompShell.DispatchWires ( parts,wires );
index 066ee4f..d9472c1 100644 (file)
@@ -1,4 +1,4 @@
 restore [locate_data_file bug27000_1.brep] shape
 unifysamedom result shape
 checkshape result
-checknbshapes result -vertex 60 -edge 87 -wire 35 -face 33 -shell 2 -solid 2 -compsolid 0 -compound 1 -shape 220
\ No newline at end of file
+checknbshapes result -vertex 62 -edge 90 -wire 36 -face 34 -shell 2 -solid 2 -compsolid 0 -compound 1 -shape 227
\ No newline at end of file
diff --git a/tests/bugs/modalg_6/bug27271 b/tests/bugs/modalg_6/bug27271
new file mode 100644 (file)
index 0000000..467e306
--- /dev/null
@@ -0,0 +1,11 @@
+puts "============"
+puts "OCC27271"
+puts "============"
+puts ""
+###########################################################################################################
+# Unifysamedomain invalid result
+###########################################################################################################
+
+restore [locate_data_file bug27271_Shape.brep] a
+unifysamedom result a
+checkshape result
\ No newline at end of file