0025662: Project command produce wrong 2dcurve
authoraml <aml@opencascade.com>
Thu, 15 Jan 2015 12:40:25 +0000 (15:40 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 15 Jan 2015 12:41:26 +0000 (15:41 +0300)
Concatenation algorithm fixed to work over periodic bspline surfaces.

Test case for issue CR25662

src/ProjLib/ProjLib_ComputeApproxOnPolarSurface.cxx
tests/bugs/moddata_3/bug25662 [new file with mode: 0644]

index 911b94b..fc458c0 100644 (file)
@@ -426,7 +426,9 @@ ProjLib_ComputeApproxOnPolarSurface::ProjLib_ComputeApproxOnPolarSurface
 } 
 
 static Handle(Geom2d_BSplineCurve) Concat(Handle(Geom2d_BSplineCurve) C1,
-                                         Handle(Geom2d_BSplineCurve) C2)
+                                          Handle(Geom2d_BSplineCurve) C2,
+                                          Standard_Real theUJump,
+                                          Standard_Real theVJump)
 {
   Standard_Integer deg, deg1, deg2;
   deg1 = C1->Degree();
@@ -483,7 +485,8 @@ static Handle(Geom2d_BSplineCurve) Concat(Handle(Geom2d_BSplineCurve) C1,
   }
   for (i = 2; i <= np2; i++) {
     count++;
-    P(count) = P2(i);
+    P(count).SetX(P2(i).X() + theUJump);
+    P(count).SetY(P2(i).Y() + theVJump);
   }
 
   Handle(Geom2d_BSplineCurve) BS = 
@@ -679,11 +682,36 @@ Handle(Geom2d_BSplineCurve) ProjLib_ComputeApproxOnPolarSurface::Perform
       Handle(Geom2d_BSplineCurve) CurBS;
       CurBS = Handle(Geom2d_BSplineCurve)::DownCast(LOfBSpline2d.First());
       LOfBSpline2d.RemoveFirst();
-      for (Standard_Integer ii = 2; ii <= NbC; ii++) {
-       Handle(Geom2d_BSplineCurve) BS = 
-         Handle(Geom2d_BSplineCurve)::DownCast(LOfBSpline2d.First());
-       CurBS = Concat(CurBS,BS);
-       LOfBSpline2d.RemoveFirst();
+      for (Standard_Integer ii = 2; ii <= NbC; ii++)
+      {
+        Handle(Geom2d_BSplineCurve) BS = 
+          Handle(Geom2d_BSplineCurve)::DownCast(LOfBSpline2d.First());
+
+        //Check for period jump in point of contact.
+        gp_Pnt2d aC1End = CurBS->Pole(CurBS->NbPoles()); // End of C1.
+        gp_Pnt2d aC2Beg = BS->Pole(1); // Beginning of C2.
+        Standard_Real anUJump = 0.0, anVJump = 0.0;
+
+        if (S->IsUPeriodic() || S->IsUClosed())
+        {
+          if (Abs (aC1End.X() - aC2Beg.X()) > (S->LastUParameter() - S->FirstUParameter() ) / 2.01)
+          {
+            Standard_Real aMultCoeff =  aC2Beg.X() < aC1End.X() ? 1.0 : -1.0;
+            anUJump = (S->LastUParameter() - S->FirstUParameter() ) * aMultCoeff;
+          }
+        }
+
+        if (S->IsVPeriodic() || S->IsVClosed())
+        {
+          if (Abs (aC1End.Y() - aC2Beg.Y()) > (S->LastVParameter() - S->FirstVParameter() ) / 2.01)
+          {
+            Standard_Real aMultCoeff =  aC2Beg.Y() < aC1End.Y() ? 1.0 : -1.0;
+            anVJump = (S->LastVParameter() - S->FirstVParameter() ) * aMultCoeff;
+          }
+        }
+
+        CurBS = Concat(CurBS,BS, anUJump, anVJump);
+        LOfBSpline2d.RemoveFirst();
       }
       return CurBS;
     }
diff --git a/tests/bugs/moddata_3/bug25662 b/tests/bugs/moddata_3/bug25662
new file mode 100644 (file)
index 0000000..9b3045a
--- /dev/null
@@ -0,0 +1,49 @@
+puts "================"
+puts "OCC25662"
+puts "================"
+puts ""
+#######################################################################
+# Project command produce wrong 2dcurve
+#######################################################################
+
+restore [locate_data_file bug25662_c3d.draw] c3d
+restore [locate_data_file bug25662_surf.draw] surf
+
+project c2d c3d surf
+
+set log [dump c2d]
+
+regexp {Degree +([-0-9.+eE]+), +([-0-9.+eE]+) Poles, +([-0-9.+eE]+)} ${log} full Degree Poles KnotsPoles
+puts "Degree=${Degree}"
+puts "Poles=${Poles}"
+puts "KnotsPoles=${KnotsPoles}"
+puts ""
+
+set tol_abs 1.e-7
+set tol_rel 0.01
+set V_i 0
+
+for {set i 1} {${i} <= ${Poles}} {incr i} {
+   set V_i_1 ${V_i}
+   set exp_string " +${i} : +(\[-0-9.+eE\]+), +(\[-0-9.+eE\]+)"
+   regexp ${exp_string} ${log} full U_i V_i
+   #puts "i=${i} U_i=${U_i} V_i=${V_i}"
+   if { ${i} == 1 } {
+      # First pole
+      puts "V_first=${V_i}"
+      set expected_V_first 36.9997986855584
+      checkreal "V_first" ${V_i} ${expected_V_first} ${tol_abs} ${tol_rel}
+   }
+   if { ${i} == ${Poles} } {
+      # Last pole
+      puts "V_last=${V_i}"
+      set expected_V_last 55.0007653583147
+      checkreal "V_last" ${V_i} ${expected_V_last} ${tol_abs} ${tol_rel}
+   }
+   if { ${i} > 1 } {
+      #puts "i=${i} U_i=${U_i} V_i=${V_i} V_i_1=${V_i_1}"
+      if { ${V_i_1} >= ${V_i} } {
+         puts "Error: Bad value of V in string: ${i} :${U_i}, ${V_i}"
+      }
+   }
+}