0025706: SIGSEGV after making existing BSplineCurve rational
authorazv <azv@opencascade.com>
Wed, 14 Jan 2015 07:00:06 +0000 (10:00 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 29 Jan 2015 09:54:52 +0000 (12:54 +0300)
1. Eliminated exception after conversion non-rational B-spline to rational
2. Implemented DRAW command setweight to change weights of B-spline
3. Test cases were added

src/Geom/Geom_BSplineCurve.cxx
src/Geom/Geom_BSplineSurface.cxx
src/Geom2d/Geom2d_BSplineCurve.cxx
src/GeomliteTest/GeomliteTest_ModificationCommands.cxx
tests/bugs/moddata_3/bug25706_1 [new file with mode: 0644]
tests/bugs/moddata_3/bug25706_2 [new file with mode: 0644]
tests/bugs/moddata_3/bug25706_3 [new file with mode: 0644]

index 4019dac..01a3a06 100644 (file)
@@ -1212,12 +1212,16 @@ void Geom_BSplineCurve::ValidateCache(const Standard_Real  Parameter)
   //
   // check if the degree did not change
   //
-  if (cachepoles->Upper() < deg + 1) {
+  if (cachepoles->Upper() < deg + 1)
     cachepoles = new TColgp_HArray1OfPnt(1,deg + 1);
-    if (rational) {
-      cacheweights  = new TColStd_HArray1OfReal(1,deg + 1);
-    }
+  if (rational)
+  {
+    if (cacheweights.IsNull() || cacheweights->Upper() < deg + 1)
+     cacheweights  = new TColStd_HArray1OfReal(1,deg + 1);
   }
+  else if (!cacheweights.IsNull())
+    cacheweights.Nullify();
+
   BSplCLib::LocateParameter(deg,
                            (flatknots->Array1()),
                            (BSplCLib::NoMults()),
index b50548a..a24a6be 100644 (file)
@@ -1401,6 +1401,8 @@ void Geom_BSplineSurface::ValidateCache(const Standard_Real  Uparameter,
       }
     }
   }
+  else if (!cacheweights.IsNull())
+    cacheweights.Nullify();
 
   BSplCLib::LocateParameter(udeg,
                            (ufknots->Array1()),
index db9f68e..580beb6 100644 (file)
@@ -1326,12 +1326,15 @@ void Geom2d_BSplineCurve::ValidateCache(const Standard_Real  Parameter)
   //
   // check if the degree did not change
   //
-  if (cachepoles->Upper() < deg + 1) {
+  if (cachepoles->Upper() < deg + 1)
     cachepoles = new TColgp_HArray1OfPnt2d(1,deg + 1);
-    if (rational) {
-      cacheweights  = new TColStd_HArray1OfReal(1,deg + 1);
-    }
+  if (rational)
+  {
+    if (cacheweights.IsNull() || cacheweights->Upper() < deg + 1)
+     cacheweights  = new TColStd_HArray1OfReal(1,deg + 1);
   }
+  else if (!cacheweights.IsNull())
+    cacheweights.Nullify();
 
   BSplCLib::LocateParameter(deg,
                            (flatknots->Array1()),
index f910ed2..b492617 100644 (file)
 #include <Precision.hxx>
 #include <GeomLib.hxx>
 
+#include <Geom2d_BezierCurve.hxx>
+#include <Geom2d_BSplineCurve.hxx>
+#include <Geom_BezierCurve.hxx>
+#include <Geom_BezierSurface.hxx>
+#include <Geom_BSplineCurve.hxx>
+#include <Geom_BSplineSurface.hxx>
+
 #ifdef WNT
 #include <stdio.h>
 //#define strcasecmp strcmp Already defined
@@ -125,6 +132,75 @@ static Standard_Integer samerange (Draw_Interpretor& /*di*/, Standard_Integer n,
 
 }
 
+//=======================================================================
+//function : setweight
+//purpose  : Changes a weight of a pole on B-spline curve/surface
+//=======================================================================
+
+static Standard_Integer setweight(Draw_Interpretor& di, Standard_Integer n, const char** a)
+{
+  if (n < 4 || n > 5)
+  {
+    std::cout << "Wrong parameters" << std::endl;
+    return 1;
+  }
+
+  Standard_Integer anIndex1 = Draw::Atoi(a[2]);
+  Standard_Integer anIndex2 = n == 5 ? Draw::Atoi(a[3]) : 0;
+  Standard_Real    aWeight  = Draw::Atof(a[n-1]);
+
+  Handle(Geom_BSplineCurve) aBSplCurve = DrawTrSurf::GetBSplineCurve(a[1]);
+  if (!aBSplCurve.IsNull())
+  {
+    aBSplCurve->SetWeight(anIndex1, aWeight);
+    return 0;
+  }
+
+  Handle(Geom_BezierCurve) aBezCurve = DrawTrSurf::GetBezierCurve(a[1]);
+  if (!aBezCurve.IsNull())
+  {
+    aBezCurve->SetWeight(anIndex1, aWeight);
+    return 0;
+  }
+
+  Handle(Geom2d_BSplineCurve) aBSplCurve2d = DrawTrSurf::GetBSplineCurve2d(a[1]);
+  if (!aBSplCurve2d.IsNull())
+  {
+    aBSplCurve2d->SetWeight(anIndex1, aWeight);
+    return 0;
+  }
+
+  Handle(Geom2d_BezierCurve) aBezCurve2d = DrawTrSurf::GetBezierCurve2d(a[1]);
+  if (!aBezCurve2d.IsNull())
+  {
+    aBezCurve2d->SetWeight(anIndex1, aWeight);
+    return 0;
+  }
+
+  Handle(Geom_BSplineSurface) aBSplSurf = DrawTrSurf::GetBSplineSurface(a[1]);
+  Handle(Geom_BezierSurface) aBezSurf = DrawTrSurf::GetBezierSurface(a[1]);
+  if (n != 5 && (!aBSplSurf.IsNull() || !aBezSurf.IsNull()))
+  {
+    std::cout << "Incorrect parameters" << std::endl;
+    return 1;
+  }
+
+  if (!aBSplSurf.IsNull())
+  {
+    aBSplSurf->SetWeight(anIndex1, anIndex2, aWeight);
+    return 0;
+  }
+
+  if (!aBezSurf.IsNull())
+  {
+    aBezSurf->SetWeight(anIndex1, anIndex2, aWeight);
+    return 0;
+  }
+
+  std::cout << a[1] << " is not a B-spline nor a Bezier curve/surface" << std::endl;
+  return 1;
+}
+
 //=======================================================================
 //function : ModificationCommands
 //purpose  : 
@@ -161,6 +237,12 @@ void  GeomliteTest::ModificationCommands(Draw_Interpretor& theCommands)
                  __FILE__,
                   samerange, g);
 
+  theCommands.Add("setweight",
+                  "setweight curve/surf index1 [index2] weight"
+                  "\n\t\tchanges a weight of a pole of B-spline curve/surface (index2 is useful for surfaces only)",
+                  __FILE__,
+                  setweight,g);
+
 }
 
 
diff --git a/tests/bugs/moddata_3/bug25706_1 b/tests/bugs/moddata_3/bug25706_1
new file mode 100644 (file)
index 0000000..2c5744a
--- /dev/null
@@ -0,0 +1,25 @@
+puts "================"
+puts "OCC25706"
+puts "================"
+puts ""
+#######################################################################
+# Exception in conversion B-spline to rational
+#######################################################################
+
+bsplinecurve bc 2 2  0.0 3  1.0 3  0 0 0 1.0  0.5 1 0 1.0  1 0 0 1.0
+mkedge e1 bc
+
+dump bc
+
+setweight bc 2 0.5
+
+set info [dump bc]
+if { [regexp {rational} ${info}] } {
+    puts "OK : B-spline is rational"
+} else {
+    puts "Error : B-spline is non-rational"
+}
+
+mkedge result bc
+
+set 2dviewer 1
diff --git a/tests/bugs/moddata_3/bug25706_2 b/tests/bugs/moddata_3/bug25706_2
new file mode 100644 (file)
index 0000000..f1a0003
--- /dev/null
@@ -0,0 +1,25 @@
+puts "================"
+puts "OCC25706"
+puts "================"
+puts ""
+#######################################################################
+# Exception in conversion B-spline to rational
+#######################################################################
+
+2dbsplinecurve bc 2 2  0.0 3  1.0 3  0 0 1.0  0.5 1 1.0  1 0 1.0
+mkedge e1 bc
+
+dump bc
+
+setweight bc 2 0.5
+
+set info [dump bc]
+if { [regexp {rational} ${info}] } {
+    puts "OK : B-spline is rational"
+} else {
+    puts "Error : B-spline is non-rational"
+}
+
+mkedge result bc
+
+set 2dviewer 1
diff --git a/tests/bugs/moddata_3/bug25706_3 b/tests/bugs/moddata_3/bug25706_3
new file mode 100644 (file)
index 0000000..9b965b5
--- /dev/null
@@ -0,0 +1,30 @@
+puts "================"
+puts "OCC25706"
+puts "================"
+puts ""
+#######################################################################
+# Exception in conversion B-spline to rational
+#######################################################################
+
+bsplinesurf s \
+  2 2  0 3  1 3 \
+  2 2  0 3  1 3 \
+  0.0 0.0 0.0 1  0.5 0.0 0.0 1  1.0 0.0 0.0 1 \
+  0.0 0.5 0.0 1  0.5 0.5 1.0 1  1.0 0.5 0.0 1 \
+  0.0 1.0 0.0 1  0.5 1.0 0.0 1  1.0 1.0 0.0 1
+mkface f1 s
+
+dump s
+
+setweight s 2 2 0.5
+
+set info [dump s]
+if { [regexp {rational} ${info}] } {
+    puts "OK : B-spline is rational"
+} else {
+    puts "Error : B-spline is non-rational"
+}
+
+mkface result s
+
+set 2dviewer 1