0024174: [regression] BRepBuilderAPI_Sewing returns result with very high tolerance
authorgka <gka@opencascade.com>
Thu, 3 Oct 2013 12:36:52 +0000 (16:36 +0400)
committerbugmaster <bugmaster@opencascade.com>
Thu, 3 Oct 2013 12:38:36 +0000 (16:38 +0400)
Fix for bug 0024174: [regression] BRepBuilderAPI_Sewing returns result with very high tolerance
Test script for CR24174
Test cases for issue CR24174
Small correction of test cases for issue CR24174

src/BRepBuilderAPI/BRepBuilderAPI_Sewing.cxx
tests/bugs/modalg_5/bug24174_1 [new file with mode: 0644]
tests/bugs/modalg_5/bug24174_2 [new file with mode: 0644]
tests/sewing/tol_100/J3

index d1ff3df..027e240 100755 (executable)
@@ -18,6 +18,7 @@
 // purpose or non-infringement. Please see the License for the specific terms
 // and conditions governing the rights and limitations under the License.
 
+
 // dcl          CCI60011 : Correction of degeneratedSection
 //              Improvement of SameParameter Edge to treat case of failure in BRepLib::SameParameter
 // dcl          Thu Aug 20 09:24:49 1998
@@ -729,6 +730,7 @@ TopoDS_Edge BRepBuilderAPI_Sewing::SameParameterEdge(const TopoDS_Edge& edgeFirs
   // Retrieve second PCurves
   TopLoc_Location loc2;
   Handle(Geom_Surface) surf2;
+  
   //Handle(Geom2d_Curve) c2d2, c2d21;
   //  Standard_Real firstOld, lastOld;
 
@@ -796,6 +798,7 @@ TopoDS_Edge BRepBuilderAPI_Sewing::SameParameterEdge(const TopoDS_Edge& edgeFirs
 
       TopLoc_Location loc1;
       Handle(Geom_Surface) surf1 = BRep_Tool::Surface(fac1, loc1);
+      
       Standard_Real first2d, last2d;
       Standard_Boolean isSeam1 = ((IsUClosedSurface(surf1,edge1,loc1) || IsVClosedSurface(surf1,edge1,loc1)) &&
         BRep_Tool::IsClosed(TopoDS::Edge(edge1),fac1));
@@ -869,28 +872,37 @@ TopoDS_Edge BRepBuilderAPI_Sewing::SameParameterEdge(const TopoDS_Edge& edgeFirs
 
     }
   }
-  if(isResEdge)
-    // Try to make the edge sameparameter
+  Standard_Real tolReached = Precision::Infinite();
+  Standard_Boolean isSamePar = Standard_False; 
+  if( isResEdge)
+  {
     SameParameter(edge);
-
-  //  Standard_Real tolReached = BRep_Tool::Tolerance(edge);
-  //if (!BRep_Tool::SameParameter(edge)) return edge; //gka ????????
-
-  if (firstCall && (!BRep_Tool::SameParameter(edge) || !isResEdge)) {
+    if( BRep_Tool::SameParameter(edge))
+    {
+      isSamePar = Standard_True;
+      tolReached = BRep_Tool::Tolerance(edge);
+    }
+  }
+  if (firstCall && ( !isResEdge || !isSamePar || tolReached > myTolerance)) {
     Standard_Integer whichSecn = whichSec;
     // Try to merge on the second section
-    Standard_Boolean second_ok = Standard_True;
+    Standard_Boolean second_ok = Standard_False;
     TopoDS_Edge s_edge = SameParameterEdge(edgeFirst,edgeLast,listFacesFirst,listFacesLast,
       secForward,whichSecn,Standard_False);
-    //if (s_edge.IsNull()) return s_edge; // gka version for free edges
-    if (s_edge.IsNull()) second_ok = Standard_False;
-    else if (!BRep_Tool::SameParameter(s_edge)) second_ok = Standard_False;
-    else {
-      edge = s_edge;
-      whichSec = whichSecn;
+    if( !s_edge.IsNull())
+    {
+      Standard_Real tolReached_2  = BRep_Tool::Tolerance(s_edge);
+      second_ok = ( BRep_Tool::SameParameter(s_edge) && tolReached_2 < tolReached );
+      if( second_ok)
+      {
+        edge = s_edge;
+        whichSec = whichSecn;
+      }
     }
 
-    if (!second_ok) {
+    if (!second_ok && !edge.IsNull()) {
 
       GeomAdaptor_Curve c3dAdapt(c3d);
 
@@ -4241,8 +4253,10 @@ void BRepBuilderAPI_Sewing::ProjectPointsOnCurve(const TColgp_Array1OfPnt& arrPn
   Extrema_ExtPC locProj;
   locProj.Initialize(GAC, first, last);
   gp_Pnt pfirst = GAC.Value(first), plast = GAC.Value(last);
-
-  for (Standard_Integer i1 = 1; i1 <= arrPnt.Length(); i1++) {
+  Standard_Integer find = 1;//(isConsiderEnds ? 1 : 2);
+  Standard_Integer lind = arrPnt.Length();//(isConsiderEnds ? arrPnt.Length() : arrPnt.Length() -1);
+  
+  for (Standard_Integer i1 = find; i1 <= lind ; i1++) {
     gp_Pnt pt = arrPnt(i1);
     Standard_Real worktol = myTolerance;
     Standard_Real distF2 = pfirst.SquareDistance(pt);
@@ -4253,7 +4267,7 @@ void BRepBuilderAPI_Sewing::ProjectPointsOnCurve(const TColgp_Array1OfPnt& arrPn
       // Project current point on curve
       locProj.Perform(pt);
       if (locProj.IsDone() && locProj.NbExt() > 0) {
-        Standard_Real dist2Min = Min(distF2,distL2);
+        Standard_Real dist2Min = (isConsiderEnds || i1 == find || i1 == lind ? Min(distF2,distL2) : Precision::Infinite());
         Standard_Integer ind, indMin = 0;
         for (ind = 1; ind <= locProj.NbExt(); ind++) {
           Standard_Real dProj2 = locProj.SquareDistance(ind);
diff --git a/tests/bugs/modalg_5/bug24174_1 b/tests/bugs/modalg_5/bug24174_1
new file mode 100644 (file)
index 0000000..7730eb9
--- /dev/null
@@ -0,0 +1,47 @@
+puts "========================"
+puts "OCC24174"
+puts "========================" 
+puts ""
+#######################################################################
+# [regression] BRepBuilderAPI_Sewing returns result with very high tolerance
+#######################################################################
+
+pload XSDRAW
+
+restore [locate_data_file  bug24174_Comp1.brep] a
+
+explode a
+sewing result 0.1 a_1 a_2
+
+# 0
+set log_1 [tolmax a_1]
+regexp {max tol = ([-0-9.+eE]+)} ${log_1} full MaxTolerance_a_1
+set log_2 [tolmax a_2]
+regexp {max tol = ([-0-9.+eE]+)} ${log_2} full MaxTolerance_a_2
+set CMP_TOL ${MaxTolerance_a_1}
+if { ${MaxTolerance_a_2} > ${CMP_TOL} } {
+   set CMP_TOL ${MaxTolerance_a_2}
+}
+
+# 1
+checkshape result
+
+# 2
+set log_3 [tolmax result]
+regexp {max tol = ([-0-9.+eE]+)} ${log_3} full MaxTolerance_result
+if { ${MaxTolerance_result} > ${CMP_TOL} } {
+   puts "Error: invalid tolerance"
+}
+
+# 3
+freebounds ${result} 0
+set s [explode result_c e]
+
+set Number [ llength ${s} ]
+puts "Number of free edges is ${Number}"
+set Number_Free_Edges 12
+if { ${Number} != ${Number_Free_Edges} } {
+   puts "Error : Number of free edges is ${Number}"
+}
+
+set 2dviewer 1
diff --git a/tests/bugs/modalg_5/bug24174_2 b/tests/bugs/modalg_5/bug24174_2
new file mode 100644 (file)
index 0000000..fe0c52a
--- /dev/null
@@ -0,0 +1,41 @@
+puts "========================"
+puts "OCC24174"
+puts "========================" 
+puts ""
+#######################################################################
+# [regression] BRepBuilderAPI_Sewing returns result with very high tolerance
+#######################################################################
+
+pload XSDRAW
+
+restore [locate_data_file  bug24174_stitch.brep] a
+
+sewing result 0.1 a
+
+# 0
+set log_1 [tolmax a]
+regexp {max tol = ([-0-9.+eE]+)} ${log_1} full MaxTolerance_a
+set CMP_TOL ${MaxTolerance_a}
+
+# 1
+checkshape result
+
+# 2
+set log_2 [tolmax result]
+regexp {max tol = ([-0-9.+eE]+)} ${log_2} full MaxTolerance_result
+if { ${MaxTolerance_result} > ${CMP_TOL} } {
+   puts "Error: invalid tolerance"
+}
+
+# 3
+freebounds $result 0
+set s [explode result_c e]
+
+set Number [ llength ${s} ]
+puts "Number of free edges is ${Number}"
+set Number_Free_Edges 9
+if { ${Number} != ${Number_Free_Edges} } {
+   puts "Error : Number of free edges is ${Number}"
+}
+
+set 2dviewer 1
index 22515ed..a618497 100644 (file)
@@ -1,2 +1,2 @@
 restore [locate_data_file CIN902_intcqhmp.rle] a
-set nb_f 6
+set nb_f 4