0023620: Follow up of 0022939 - make Bezier curve/surface evaluation thread-safe
[occt.git] / src / Geom / Geom_BezierSurface.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 8e7411f..a4a34e6
@@ -1,10 +1,19 @@
-// File:       Geom_BezierSurface.cxx
-// Created:    Tue Mar  9 19:52:37 1993
-// Author:     JCV
-//             <fid@phylox>
-// Copyright:  Matra Datavision 1993
+// Created on: 1993-03-09
+// Created by: JCV
+// Copyright (c) 1993-1999 Matra Datavision
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
 
-//File Geom_BezierSurface.cxx  Septembre 1990
 //Passage en classe persistante - 23/01/91
 //Modif suite a la deuxieme revue de projet toolkit Geometry -23/01/91
 // pmn : 21/10/95 ; Correction de la methode segment (PRO5853)
 #define No_Standard_OutOfRange
 #define No_Standard_DimensionError
 
-#include <Geom_BezierSurface.ixx>
-#include <Geom_BezierCurve.hxx>
 
+#include <BSplCLib.hxx>
+#include <Geom_BezierCurve.hxx>
+#include <Geom_BezierSurface.hxx>
+#include <Geom_Curve.hxx>
+#include <Geom_Geometry.hxx>
 #include <gp.hxx>
+#include <gp_Pnt.hxx>
+#include <gp_Trsf.hxx>
+#include <gp_Vec.hxx>
 #include <gp_XYZ.hxx>
 #include <PLib.hxx>
-#include <BSplCLib.hxx>
-#include <BSplSLib.hxx>
 #include <Precision.hxx>
-
+#include <Standard_ConstructionError.hxx>
+#include <Standard_DimensionError.hxx>
 #include <Standard_OutOfRange.hxx>
 #include <Standard_RangeError.hxx>
-#include <Standard_DimensionError.hxx>
-#include <Standard_ConstructionError.hxx>
+#include <Standard_Type.hxx>
 #include <TColStd_Array1OfInteger.hxx>
 
 //=======================================================================
 //function : Rational
 //purpose  : check rationality of an array of weights
 //=======================================================================
-
 static void Rational(const TColStd_Array2OfReal& Weights,
                     Standard_Boolean& Urational,
                     Standard_Boolean& Vrational)
@@ -349,11 +361,6 @@ static void DeleteRatPoleRow
 
 Geom_BezierSurface::Geom_BezierSurface 
 (const TColgp_Array2OfPnt& SurfacePoles):
- ucacheparameter(0.),
- vcacheparameter(0.),
- ucachespanlenght(1.),
- vcachespanlenght(1.),
- validcache(0),
  maxderivinvok(Standard_False)
 {
   Standard_Integer NbUPoles = SurfacePoles.ColLength();
@@ -384,11 +391,6 @@ Geom_BezierSurface::Geom_BezierSurface
 Geom_BezierSurface::Geom_BezierSurface 
   (const TColgp_Array2OfPnt&   SurfacePoles,
    const TColStd_Array2OfReal& PoleWeights  ):
- ucacheparameter(0.),
- vcacheparameter(0.),
- ucachespanlenght(1.),
- vcachespanlenght(1.),
- validcache(0),
  maxderivinvok(Standard_False)
 {
   Standard_Integer NbUPoles = SurfacePoles.ColLength();
@@ -459,20 +461,13 @@ Geom_BezierSurface::Geom_BezierSurface
 
 Geom_BezierSurface::Geom_BezierSurface
   (const Handle(TColgp_HArray2OfPnt)&   SurfacePoles,
-   const Handle(TColgp_HArray2OfPnt)&   SurfaceCoefs,
    const Handle(TColStd_HArray2OfReal)& PoleWeights,
-   const Handle(TColStd_HArray2OfReal)& CoefWeights,
    const Standard_Boolean               IsURational,
    const Standard_Boolean               IsVRational)
 :maxderivinvok(Standard_False)
 {
   urational = IsURational;
   vrational = IsVRational;
-  ucachespanlenght = 1.;
-  vcachespanlenght = 1.;
-  validcache = 1;
-  ucacheparameter =0.; 
-  vcacheparameter = 0.;
   Standard_Integer NbUPoles = SurfacePoles->ColLength();
   Standard_Integer NbVPoles = SurfacePoles->RowLength();
 
@@ -480,17 +475,9 @@ Geom_BezierSurface::Geom_BezierSurface
                                        1,NbVPoles) ;
   poles->ChangeArray2() = SurfacePoles->Array2();
 
-  coeffs   = new TColgp_HArray2OfPnt   (1,SurfaceCoefs->ColLength(),
-                                       1,SurfaceCoefs->RowLength()) ;
-  coeffs->ChangeArray2() = SurfaceCoefs->Array2();
-
   if ( urational || vrational) {
     weights  = new TColStd_HArray2OfReal (1,NbUPoles,1,NbVPoles);
     weights->ChangeArray2() = PoleWeights->Array2();
-    
-    wcoeffs  = new TColStd_HArray2OfReal (1,SurfaceCoefs->ColLength(),
-                                         1,SurfaceCoefs->RowLength()) ;
-    wcoeffs->ChangeArray2() = CoefWeights->Array2();
   }
 }
 
@@ -541,10 +528,6 @@ void Geom_BezierSurface::ExchangeUV ()
   Standard_Boolean temp = urational;
   urational = vrational;
   vrational = temp;
-  coeffs  = new TColgp_HArray2OfPnt   (LC, UC, LR, UR);
-  wcoeffs = new TColStd_HArray2OfReal (LC, UC, LR, UR);
-
-  UpdateCoefficients();
 }
 
 //=======================================================================
@@ -581,20 +564,20 @@ void Geom_BezierSurface::Increase (const Standard_Integer UDeg,
       
       BSplSLib::IncreaseDegree(1, oldUDeg, UDeg, 0,
                               poles->Array2(),
-                              weights->Array2(),
+                              &weights->Array2(),
                               biduknots, bidumults,
                               npoles->ChangeArray2(), 
-                              nweights->ChangeArray2(),
+                              &nweights->ChangeArray2(),
                               biduknots, bidumults);
       weights = nweights;
     }
     else {
       BSplSLib::IncreaseDegree(1, oldUDeg, UDeg, 0,
                               poles->Array2(),
-                              *((TColStd_Array2OfReal*) NULL),
+                              BSplSLib::NoWeights(),
                               biduknots, bidumults,
                               npoles->ChangeArray2(), 
-                              *((TColStd_Array2OfReal*) NULL),
+                              BSplSLib::NoWeights(),
                               biduknots, bidumults);
     }
     poles   = npoles;
@@ -607,20 +590,20 @@ void Geom_BezierSurface::Increase (const Standard_Integer UDeg,
       
       BSplSLib::IncreaseDegree(0, oldVDeg, VDeg, 0,
                               poles->Array2(),
-                              weights->Array2(),
+                              &weights->Array2(),
                               bidvknots, bidvmults,
                               npoles->ChangeArray2(), 
-                              nweights->ChangeArray2(),
+                              &nweights->ChangeArray2(),
                               bidvknots, bidvmults);
       weights = nweights;
     }
     else {
       BSplSLib::IncreaseDegree(0, oldVDeg, VDeg, 0,
                               poles->Array2(),
-                              *((TColStd_Array2OfReal*) NULL),
+                              BSplSLib::NoWeights(),
                               bidvknots, bidvmults,
                               npoles->ChangeArray2(), 
-                              *((TColStd_Array2OfReal*) NULL),
+                              BSplSLib::NoWeights(),
                               bidvknots, bidvmults);
       
     }
@@ -667,11 +650,6 @@ void Geom_BezierSurface::InsertPoleColAfter
   }
   poles   = npoles;
   weights = nweights;
-  coeffs  = new TColgp_HArray2OfPnt(1,poles->ColLength(),
-                                   1,poles->RowLength());
-  wcoeffs = new TColStd_HArray2OfReal(1,poles->ColLength(),
-                                     1,poles->RowLength());
-  UpdateCoefficients();
 }
 
 //=======================================================================
@@ -710,14 +688,8 @@ void Geom_BezierSurface::InsertPoleColAfter
 
   poles   = npoles;
   weights = nweights;
-  coeffs  = new TColgp_HArray2OfPnt(1,poles->ColLength(),
-                                   1,poles->RowLength());
-  wcoeffs = new TColStd_HArray2OfReal(1,poles->ColLength(),
-                                     1,poles->RowLength());
 
   Rational(weights->Array2(), urational, vrational);
-
-  UpdateCoefficients();
 }
 
 //=======================================================================
@@ -783,12 +755,6 @@ void Geom_BezierSurface::InsertPoleRowAfter (const Standard_Integer UIndex,
   }
   poles   = npoles;
   weights = nweights;
-  coeffs  = new TColgp_HArray2OfPnt(1,poles->ColLength(),
-                                   1,poles->RowLength());
-  wcoeffs = new TColStd_HArray2OfReal(1,poles->ColLength(),
-                                     1,poles->RowLength());
-
-  UpdateCoefficients();
 }
 
 //=======================================================================
@@ -827,14 +793,8 @@ void Geom_BezierSurface::InsertPoleRowAfter
 
   poles   = npoles;
   weights = nweights;
-  coeffs  = new TColgp_HArray2OfPnt(1,poles->ColLength(),
-                                   1,poles->RowLength());
-  wcoeffs = new TColStd_HArray2OfReal(1,poles->ColLength(),
-                                     1,poles->RowLength());    
 
   Rational(weights->Array2(), urational, vrational);
-
-  UpdateCoefficients();
 }
 
 //=======================================================================
@@ -894,11 +854,6 @@ void Geom_BezierSurface::RemovePoleCol (const Standard_Integer VIndex)
   }
   poles   = npoles;
   weights = nweights;
-  coeffs  = new TColgp_HArray2OfPnt(1,poles->ColLength(),
-                                   1,poles->RowLength());
-  wcoeffs = new TColStd_HArray2OfReal(1,poles->ColLength(),
-                                     1,poles->RowLength());
-  UpdateCoefficients(); 
 }
 
 //=======================================================================
@@ -935,11 +890,6 @@ void Geom_BezierSurface::RemovePoleRow (const Standard_Integer UIndex)
   }
   poles   = npoles;
   weights = nweights;
-  coeffs  = new TColgp_HArray2OfPnt(1,poles->ColLength(),
-                                   1,poles->RowLength());
-  wcoeffs = new TColStd_HArray2OfReal(1,poles->ColLength(),
-                                     1,poles->RowLength());
-  UpdateCoefficients();
 }
 
 //=======================================================================
@@ -957,11 +907,46 @@ void Geom_BezierSurface::Segment
   Handle(TColgp_HArray2OfPnt)  Coefs;
   Handle(TColStd_HArray2OfReal) WCoefs;
   
-  if (validcache == 0) UpdateCoefficients(0., 0.);
+  Standard_Integer aMinDegree = UDegree() <= VDegree() ? UDegree() : VDegree();
+  Standard_Integer aMaxDegree = UDegree() >  VDegree() ? UDegree() : VDegree();
+  Coefs = new TColgp_HArray2OfPnt(1, aMaxDegree + 1, 1, aMinDegree + 1);
+  if (rat)
+    WCoefs = new TColStd_HArray2OfReal(1, aMaxDegree + 1, 1, aMinDegree + 1);
+
+  TColStd_Array1OfReal biduflatknots(BSplCLib::FlatBezierKnots(UDegree()), 1, 2 * (UDegree() + 1));
+  TColStd_Array1OfReal bidvflatknots(BSplCLib::FlatBezierKnots(VDegree()), 1, 2 * (VDegree() + 1));
+
+  Standard_Real uparameter_11 = 0.5;
+  Standard_Real uspanlenght_11 = 0.5;
+  Standard_Real vparameter_11 = 0.5;
+  Standard_Real vspanlenght_11 = 0.5;
+
+  if (urational || vrational) {
+    BSplSLib::BuildCache(uparameter_11, vparameter_11,
+      uspanlenght_11, vspanlenght_11, 0, 0,
+      UDegree(), VDegree(), 0, 0,
+      biduflatknots, bidvflatknots,
+      poles->Array2(),
+      &weights->Array2(),
+      Coefs->ChangeArray2(),
+      &WCoefs->ChangeArray2());
+  }
+  else {
+    BSplSLib::BuildCache(uparameter_11, vparameter_11,
+      uspanlenght_11, vspanlenght_11, 0, 0,
+      UDegree(), VDegree(), 0, 0,
+      biduflatknots, bidvflatknots,
+      poles->Array2(),
+      BSplSLib::NoWeights(),
+      Coefs->ChangeArray2(),
+      BSplSLib::NoWeights());
+  }
 
   // Attention si udeg <= vdeg u et v sont intervertis 
   // dans les coeffs, il faut donc tout transposer.
   if(UDegree() <= VDegree()) {
+    Handle(TColgp_HArray2OfPnt)  coeffs = Coefs;
+    Handle(TColStd_HArray2OfReal) wcoeffs = WCoefs;
     Standard_Integer ii, jj;
     Coefs = new  (TColgp_HArray2OfPnt)(1,UDegree()+1,1,VDegree()+1);
     if (rat) {
@@ -973,10 +958,6 @@ void Geom_BezierSurface::Segment
        if (rat)  WCoefs->SetValue(ii, jj, wcoeffs->Value(jj,ii));
       }
   }
-  else {
-   Coefs = coeffs;
-   if (rat)  {WCoefs =  wcoeffs;}
- }
 
 // Trim dans la base cannonique et Update des Poles et Coeffs
 
@@ -987,25 +968,20 @@ void Geom_BezierSurface::Segment
                 vlast  = 2*(V2 - 0.5);
   if (rat) {
     PLib::UTrimming (ufirst, ulast, Coefs->ChangeArray2(),
-                    WCoefs->ChangeArray2());
+                    &WCoefs->ChangeArray2());
     PLib::VTrimming (vfirst, vlast, Coefs->ChangeArray2(),
-                    WCoefs->ChangeArray2());
+                    &WCoefs->ChangeArray2());
     PLib::CoefficientsPoles(Coefs->Array2(),
-                           WCoefs->Array2(),
+                           &WCoefs->Array2(),
                            poles->ChangeArray2(),
-                           weights->ChangeArray2());
+                           &weights->ChangeArray2());
   }
   else {
-    PLib::UTrimming (ufirst, ulast, Coefs->ChangeArray2(),
-                    *((TColStd_Array2OfReal*) NULL));
-    PLib::VTrimming (vfirst, vlast, Coefs->ChangeArray2(),
-                    *((TColStd_Array2OfReal*) NULL));
-    PLib::CoefficientsPoles (Coefs->Array2(),
-                            *((TColStd_Array2OfReal*) NULL),
-                            poles->ChangeArray2(),
-                            *((TColStd_Array2OfReal*) NULL));
+    PLib::UTrimming (ufirst, ulast, Coefs->ChangeArray2(), PLib::NoWeights2());
+    PLib::VTrimming (vfirst, vlast, Coefs->ChangeArray2(), PLib::NoWeights2());
+    PLib::CoefficientsPoles (Coefs->Array2(), PLib::NoWeights2(),
+                                              poles->ChangeArray2(), PLib::NoWeights2());
   }
-  UpdateCoefficients();
 }
 
 //=======================================================================
@@ -1025,7 +1001,6 @@ void Geom_BezierSurface::SetPole
       VIndex > Poles.RowLength() )    Standard_OutOfRange::Raise();
   
   Poles (UIndex, VIndex) = P;
-  UpdateCoefficients();
 }
 
 //=======================================================================
@@ -1102,8 +1077,6 @@ void Geom_BezierSurface::SetPoleCol (const Standard_Integer      VIndex,
   for (Standard_Integer I = CPoles.Lower(); I <= CPoles.Upper(); I++) {
     Poles (I, VIndex) = CPoles (I);
   }
-
-  UpdateCoefficients();
 }
 
 //=======================================================================
@@ -1125,7 +1098,6 @@ void Geom_BezierSurface::SetPoleRow (const Standard_Integer    UIndex,
   for (Standard_Integer I = CPoles.Lower(); I <= CPoles.Upper(); I++) {
     Poles (UIndex, I) = CPoles (I);
   }
-  UpdateCoefficients();
 }
 
 //=======================================================================
@@ -1172,16 +1144,12 @@ void Geom_BezierSurface::SetWeight (const Standard_Integer UIndex,
   Standard_Boolean wasrat = (urational||vrational);
   if (!wasrat) {
     // a weight of 1. does not turn to rational
-    if (Abs(Weight - 1.) <= gp::Resolution()) {
-      UpdateCoefficients(); //Pour l'appel via SetPole 
+    if (Abs(Weight - 1.) <= gp::Resolution())
       return;
-    }
-    
+
     // set weights of 1.
     weights = new TColStd_HArray2OfReal (1, poles->ColLength(),
                                         1, poles->RowLength(), 1.);
-    wcoeffs = new TColStd_HArray2OfReal (1, poles->ColLength(),
-                                        1, poles->RowLength());
   }
 
   TColStd_Array2OfReal & Weights = weights->ChangeArray2();
@@ -1199,14 +1167,8 @@ void Geom_BezierSurface::SetWeight (const Standard_Integer UIndex,
   }
 
  // is it turning into non rational
-  if (wasrat) {
-    if (!(urational || vrational)) {
-      weights.Nullify();
-      wcoeffs.Nullify();
-    }
-  }
-
-  UpdateCoefficients(); //Dans tous cas :Attention a SetPoleCol !
+  if (wasrat && !(urational || vrational))
+    weights.Nullify();
 }
 
 //=======================================================================
@@ -1225,8 +1187,6 @@ void Geom_BezierSurface::SetWeightCol
     // set weights of 1.
     weights = new TColStd_HArray2OfReal (1, poles->ColLength(),
                                         1, poles->RowLength(), 1.);
-    wcoeffs = new TColStd_HArray2OfReal (1, poles->ColLength(),
-                                        1, poles->RowLength());
   }
 
   TColStd_Array2OfReal & Weights = weights->ChangeArray2();
@@ -1248,14 +1208,8 @@ void Geom_BezierSurface::SetWeightCol
  Rational(Weights, urational, vrational);
 
  // is it turning into non rational
-  if (wasrat) {
-    if (!(urational || vrational)) {
-      weights.Nullify();
-      wcoeffs.Nullify();
-    }
-  }
-
-  UpdateCoefficients();
+ if (wasrat && !(urational || vrational))
+   weights.Nullify();
 }
 
 //=======================================================================
@@ -1274,8 +1228,6 @@ void Geom_BezierSurface::SetWeightRow
     // set weights of 1.
     weights = new TColStd_HArray2OfReal (1, poles->ColLength(),
                                         1, poles->RowLength(), 1.);
-    wcoeffs = new TColStd_HArray2OfReal (1, poles->ColLength(),
-                                        1, poles->RowLength());
   }
 
   TColStd_Array2OfReal & Weights = weights->ChangeArray2();
@@ -1300,14 +1252,8 @@ void Geom_BezierSurface::SetWeightRow
   Rational(Weights, urational, vrational);
 
  // is it turning into non rational
-  if (wasrat) {
-    if (!(urational || vrational)) {
-      weights.Nullify();
-      wcoeffs.Nullify();
-    }
-  }
-
-  UpdateCoefficients();
+  if (wasrat && !(urational || vrational))
+    weights.Nullify();
 }
 
 //=======================================================================
@@ -1343,7 +1289,6 @@ void Geom_BezierSurface::UReverse ()
       }
     }
   }
-  UpdateCoefficients();
 }
 
 //=======================================================================
@@ -1390,7 +1335,6 @@ void Geom_BezierSurface::VReverse ()
       }
     }
   }
-  UpdateCoefficients();
 }
 
 //=======================================================================
@@ -1439,60 +1383,30 @@ void Geom_BezierSurface::D0 (const Standard_Real U,
                             const Standard_Real V,
                                   gp_Pnt&       P ) const
 {
-
-  if (validcache == 1) {
-    //
-    // XAB : cet algorithme devient instable pour les hauts degres
-    // RBD : Beaucoup moins maintenant avec le calcul d'un nouveau cache
-    //       sur [-1,1].
-    //
-    Standard_Real uparameter_11 = (2*ucacheparameter + ucachespanlenght)/2,
-                  uspanlenght_11 = ucachespanlenght/2,
-                  vparameter_11 = (2*vcacheparameter + vcachespanlenght)/2,
-                  vspanlenght_11 = vcachespanlenght/2 ;
-    if (urational || vrational) { 
-      BSplSLib::CacheD0(U, V, UDegree(), VDegree(), 
-                       uparameter_11, vparameter_11,
-                       uspanlenght_11, vspanlenght_11,
-                       coeffs->Array2(),
-                       wcoeffs->Array2(),
-                       P);
-    }
-    else { 
-      BSplSLib::CacheD0(U, V, UDegree(), VDegree(), 
-                       uparameter_11, vparameter_11,
-                       uspanlenght_11, vspanlenght_11,
-                       coeffs->Array2(),
-                       *((TColStd_Array2OfReal*) NULL),
-                       P);
-    }
+  Standard_Real array_u[2];
+  Standard_Real array_v[2];
+  Standard_Integer mult_u[2];
+  Standard_Integer mult_v[2];
+  TColStd_Array1OfReal biduknots(array_u[0], 1, 2); biduknots(1) = 0.; biduknots(2) = 1.;
+  TColStd_Array1OfInteger bidumults(mult_u[0], 1, 2); bidumults.Init(UDegree() + 1);
+  TColStd_Array1OfReal bidvknots(array_v[0], 1, 2); bidvknots(1) = 0.; bidvknots(2) = 1.;
+  TColStd_Array1OfInteger bidvmults(mult_v[0], 1, 2); bidvmults.Init(VDegree() + 1);
+  if (urational || vrational) {
+    BSplSLib::D0(U, V, 1, 1, poles->Array2(),
+      &weights->Array2(),
+      biduknots, bidvknots, &bidumults, &bidvmults,
+      UDegree(), VDegree(),
+      urational, vrational, Standard_False, Standard_False,
+      P);
   }
   else {
-    Standard_Real array_u[2] ;
-    Standard_Real array_v[2] ;
-    Standard_Integer mult_u[2] ;
-    Standard_Integer mult_v[2] ;
-    TColStd_Array1OfReal biduknots(array_u[0],1,2); biduknots(1) = 0.; biduknots(2) = 1.;
-    TColStd_Array1OfInteger bidumults(mult_u[0],1,2); bidumults.Init(UDegree() + 1);
-    TColStd_Array1OfReal bidvknots(array_v[0],1,2); bidvknots(1) = 0.; bidvknots(2) = 1.;
-    TColStd_Array1OfInteger bidvmults(mult_v[0],1,2); bidvmults.Init(VDegree() + 1);
-    if (urational || vrational) { 
-        BSplSLib::D0(U, V, 1,1,poles->Array2(),
-                    weights->Array2(),
-                    biduknots,bidvknots,bidumults,bidvmults,
-                    UDegree(),VDegree(),
-                    urational,vrational,Standard_False,Standard_False,
-                    P) ;
-    }
-    else {
-      
-      BSplSLib::D0(U, V, 1,1,poles->Array2(),
-                  *((TColStd_Array2OfReal*) NULL),
-                  biduknots,bidvknots,bidumults,bidvmults,
-                  UDegree(),VDegree(),
-                  urational,vrational,Standard_False,Standard_False,
-                  P) ;
-    }
+
+    BSplSLib::D0(U, V, 1, 1, poles->Array2(),
+      BSplSLib::NoWeights(),
+      biduknots, bidvknots, &bidumults, &bidvmults,
+      UDegree(), VDegree(),
+      urational, vrational, Standard_False, Standard_False,
+      P);
   }
 }
 
@@ -1508,59 +1422,29 @@ void Geom_BezierSurface::D1
          gp_Vec&       D1U,
          gp_Vec&       D1V ) const
 {
-
-  if (validcache == 1) {
-    //
-    // XAB : cet algorithme devient instable pour les hauts degres
-    // RBD : Beaucoup moins maintenant avec le calcul d'un nouveau cache
-    //       sur [-1,1].
-    //
-    Standard_Real uparameter_11 = (2*ucacheparameter + ucachespanlenght)/2,
-                  uspanlenght_11 = ucachespanlenght/2,
-                  vparameter_11 = (2*vcacheparameter + vcachespanlenght)/2,
-                  vspanlenght_11 = vcachespanlenght/2 ;
-   if (urational || vrational) { 
-     BSplSLib::CacheD1(U, V, UDegree(), VDegree(), 
-                      uparameter_11, vparameter_11,
-                      uspanlenght_11, vspanlenght_11,
-                      coeffs->Array2(),
-                      wcoeffs->Array2(), 
-                      P, D1U, D1V);
-   }
-   else { 
-     BSplSLib::CacheD1(U, V, UDegree(), VDegree(), 
-                      uparameter_11, vparameter_11,
-                      uspanlenght_11, vspanlenght_11,
-                      coeffs->Array2(),
-                      *((TColStd_Array2OfReal*) NULL), 
-                      P, D1U, D1V);
-   }
+  Standard_Real array_u[2];
+  Standard_Real array_v[2];
+  Standard_Integer mult_u[2];
+  Standard_Integer mult_v[2];
+  TColStd_Array1OfReal biduknots(array_u[0], 1, 2); biduknots(1) = 0.; biduknots(2) = 1.;
+  TColStd_Array1OfInteger bidumults(mult_u[0], 1, 2); bidumults.Init(UDegree() + 1);
+  TColStd_Array1OfReal bidvknots(array_v[0], 1, 2); bidvknots(1) = 0.; bidvknots(2) = 1.;
+  TColStd_Array1OfInteger bidvmults(mult_v[0], 1, 2); bidvmults.Init(VDegree() + 1);
+  if (urational || vrational) {
+    BSplSLib::D1(U, V, 1, 1, poles->Array2(),
+      &weights->Array2(),
+      biduknots, bidvknots, &bidumults, &bidvmults,
+      UDegree(), VDegree(),
+      urational, vrational, Standard_False, Standard_False,
+      P, D1U, D1V);
   }
   else {
-    Standard_Real array_u[2] ;
-    Standard_Real array_v[2] ;
-    Standard_Integer mult_u[2] ;
-    Standard_Integer mult_v[2] ;
-    TColStd_Array1OfReal biduknots(array_u[0],1,2); biduknots(1) = 0.; biduknots(2) = 1.;
-    TColStd_Array1OfInteger bidumults(mult_u[0],1,2); bidumults.Init(UDegree() + 1);
-    TColStd_Array1OfReal bidvknots(array_v[0],1,2); bidvknots(1) = 0.; bidvknots(2) = 1.;
-    TColStd_Array1OfInteger bidvmults(mult_v[0],1,2); bidvmults.Init(VDegree() + 1);
-    if (urational || vrational) { 
-      BSplSLib::D1(U, V, 1,1,poles->Array2(),
-                  weights->Array2(),
-                  biduknots,bidvknots,bidumults,bidvmults,
-                  UDegree(),VDegree(),
-                  urational,vrational,Standard_False,Standard_False,
-                  P,D1U, D1V) ;
-    }
-    else {
-      BSplSLib::D1(U, V, 1,1,poles->Array2(),
-                  *((TColStd_Array2OfReal*) NULL),
-                  biduknots,bidvknots,bidumults,bidvmults,
-                  UDegree(),VDegree(),
-                  urational,vrational,Standard_False,Standard_False,
-                  P,D1U, D1V) ;
-    }
+    BSplSLib::D1(U, V, 1, 1, poles->Array2(),
+      BSplSLib::NoWeights(),
+      biduknots, bidvknots, &bidumults, &bidvmults,
+      UDegree(), VDegree(),
+      urational, vrational, Standard_False, Standard_False,
+      P, D1U, D1V);
   }
 }
 
@@ -1576,63 +1460,31 @@ void Geom_BezierSurface::D2
          gp_Vec&       D1U, gp_Vec& D1V, 
          gp_Vec&       D2U, gp_Vec& D2V, gp_Vec& D2UV ) const
 {
-
-  if (validcache == 1) {
-    //
-    // XAB : cet algorithme devient instable pour les hauts degres
-    // RBD : Beaucoup moins maintenant avec le calcul d'un nouveau cache
-    //       sur [-1,1].
-    //
-    Standard_Real uparameter_11 = (2*ucacheparameter + ucachespanlenght)/2,
-                  uspanlenght_11 = ucachespanlenght/2,
-                  vparameter_11 = (2*vcacheparameter + vcachespanlenght)/2,
-                  vspanlenght_11 = vcachespanlenght/2 ;
-    if (urational || vrational) { 
-      //-- ATTENTION a l'ORDRE d'appel ds BSPLSLIB 
-      BSplSLib::CacheD2(U, V, UDegree(), VDegree(), 
-                       uparameter_11, vparameter_11,
-                       uspanlenght_11, vspanlenght_11,
-                       coeffs->Array2(),
-                       wcoeffs->Array2(), 
-                       P, D1U, D1V, D2U, D2UV , D2V);
-    }
-    else { 
-      //-- ATTENTION a l'ORDRE d'appel ds BSPLSLIB 
-      BSplSLib::CacheD2(U, V, UDegree(), VDegree(), 
-                       uparameter_11, vparameter_11,
-                       uspanlenght_11, vspanlenght_11,
-                       coeffs->Array2(),
-                       *((TColStd_Array2OfReal*) NULL), 
-                       P, D1U, D1V, D2U, D2UV , D2V);
-    }
+  Standard_Real array_u[2];
+  Standard_Real array_v[2];
+  Standard_Integer mult_u[2];
+  Standard_Integer mult_v[2];
+  TColStd_Array1OfReal biduknots(array_u[0], 1, 2); biduknots(1) = 0.; biduknots(2) = 1.;
+  TColStd_Array1OfInteger bidumults(mult_u[0], 1, 2); bidumults.Init(UDegree() + 1);
+  TColStd_Array1OfReal bidvknots(array_v[0], 1, 2); bidvknots(1) = 0.; bidvknots(2) = 1.;
+  TColStd_Array1OfInteger bidvmults(mult_v[0], 1, 2); bidvmults.Init(VDegree() + 1);
+  if (urational || vrational) {
+    //-- ATTENTION a l'ORDRE d'appel ds BSPLSLIB 
+    BSplSLib::D2(U, V, 1, 1, poles->Array2(),
+      &weights->Array2(),
+      biduknots, bidvknots, &bidumults, &bidvmults,
+      UDegree(), VDegree(),
+      urational, vrational, Standard_False, Standard_False,
+      P, D1U, D1V, D2U, D2V, D2UV);
   }
   else {
-    Standard_Real array_u[2] ;
-    Standard_Real array_v[2] ;
-    Standard_Integer mult_u[2] ;
-    Standard_Integer mult_v[2] ;
-    TColStd_Array1OfReal biduknots(array_u[0],1,2); biduknots(1) = 0.; biduknots(2) = 1.;
-    TColStd_Array1OfInteger bidumults(mult_u[0],1,2); bidumults.Init(UDegree() + 1);
-    TColStd_Array1OfReal bidvknots(array_v[0],1,2); bidvknots(1) = 0.; bidvknots(2) = 1.;
-    TColStd_Array1OfInteger bidvmults(mult_v[0],1,2); bidvmults.Init(VDegree() + 1);
-    if (urational || vrational) { 
-      //-- ATTENTION a l'ORDRE d'appel ds BSPLSLIB 
-      BSplSLib::D2(U, V, 1,1,poles->Array2(),
-                  weights->Array2(),
-                  biduknots,bidvknots,bidumults,bidvmults,
-                  UDegree(),VDegree(),
-                  urational,vrational,Standard_False,Standard_False,
-                  P,D1U, D1V, D2U, D2V , D2UV) ;
-    }
-    else {
-      //-- ATTENTION a l'ORDRE d'appel ds BSPLSLIB 
-      BSplSLib::D2(U, V, 1,1,poles->Array2(),
-                  *((TColStd_Array2OfReal*) NULL),
-                  biduknots,bidvknots,bidumults,bidvmults,
-                  UDegree(),VDegree(),
-                  urational,vrational,Standard_False,Standard_False,
-                  P,D1U, D1V, D2U, D2V, D2UV ) ;
-    }
+    //-- ATTENTION a l'ORDRE d'appel ds BSPLSLIB 
+    BSplSLib::D2(U, V, 1, 1, poles->Array2(),
+      BSplSLib::NoWeights(),
+      biduknots, bidvknots, &bidumults, &bidvmults,
+      UDegree(), VDegree(),
+      urational, vrational, Standard_False, Standard_False,
+      P, D1U, D1V, D2U, D2V, D2UV);
   }
 }
 
@@ -1654,8 +1506,8 @@ void Geom_BezierSurface::D3
   TColStd_Array1OfInteger bidvmults(1,2); bidvmults.Init(VDegree() + 1);
   if (urational || vrational) { 
     BSplSLib::D3 (U, V, 0, 0, poles->Array2(),
-                 weights->Array2(),
-                 biduknots, bidvknots, bidumults, bidvmults,
+                 &weights->Array2(),
+                 biduknots, bidvknots, &bidumults, &bidvmults,
                  UDegree(), VDegree(), urational, vrational, 0, 0,
                  P,
                  D1U, D1V,
@@ -1664,8 +1516,8 @@ void Geom_BezierSurface::D3
   }
   else { 
     BSplSLib::D3 (U, V, 0, 0, poles->Array2(),
-                 *((TColStd_Array2OfReal*) NULL),
-                 biduknots, bidvknots, bidumults, bidvmults,
+                 BSplSLib::NoWeights(),
+                 biduknots, bidvknots, &bidumults, &bidvmults,
                  UDegree(), VDegree(), urational, vrational, 0, 0,
                  P,
                  D1U, D1V,
@@ -1693,15 +1545,15 @@ gp_Vec Geom_BezierSurface::DN
   TColStd_Array1OfInteger bidvmults(1,2); bidvmults.Init(VDegree() + 1);
   if (urational || vrational) { 
     BSplSLib::DN (U, V, Nu, Nv, 0, 0, poles->Array2(),
-                 weights->Array2(),
-                 biduknots, bidvknots, bidumults, bidvmults,
+                 &weights->Array2(),
+                 biduknots, bidvknots, &bidumults, &bidvmults,
                  UDegree(), VDegree(), urational, vrational, 0, 0,
                  Derivative);
   }
   else { 
     BSplSLib::DN (U, V, Nu, Nv, 0, 0, poles->Array2(),
-                 *((TColStd_Array2OfReal*) NULL),
-                 biduknots, bidvknots, bidumults, bidvmults,
+                 BSplSLib::NoWeights(),
+                 biduknots, bidvknots, &bidumults, &bidvmults,
                  UDegree(), VDegree(), urational, vrational, 0, 0,
                  Derivative);
   }
@@ -1784,9 +1636,9 @@ Handle(Geom_Curve) Geom_BezierSurface::UIso (const Standard_Real U) const
     TColStd_Array1OfReal VCurveWeights 
       (Weights.LowerCol() , Weights.UpperCol());
     BSplSLib::Iso (U, 1, Poles,
-                  Weights,
-                  biduknots, bidumults,
-                  UDegree(), 0, VCurvePoles, VCurveWeights);
+                  &Weights,
+                  biduknots, &bidumults,
+                  UDegree(), 0, VCurvePoles, &VCurveWeights);
     if (urational)
       UIsoCurve = new Geom_BezierCurve (VCurvePoles, VCurveWeights);
     else
@@ -1794,8 +1646,8 @@ Handle(Geom_Curve) Geom_BezierSurface::UIso (const Standard_Real U) const
   }
   else {
     BSplSLib::Iso (U, 1, Poles,
-                  *((TColStd_Array2OfReal*) NULL),
-                  biduknots, bidumults,
+                  BSplSLib::NoWeights(),
+                  biduknots, &bidumults,
                   UDegree(), 0, VCurvePoles, PLib::NoWeights());
     UIsoCurve = new Geom_BezierCurve (VCurvePoles);
   }
@@ -1830,9 +1682,9 @@ Handle(Geom_Curve) Geom_BezierSurface::VIso (const Standard_Real V) const
     TColStd_Array1OfReal VCurveWeights 
       (Weights.LowerRow() , Weights.UpperRow());
     BSplSLib::Iso (V, 0, Poles,
-                  Weights,
-                  bidvknots, bidvmults,
-                  VDegree(), 0, VCurvePoles, VCurveWeights);
+                  &Weights,
+                  bidvknots, &bidvmults,
+                  VDegree(), 0, VCurvePoles, &VCurveWeights);
     if (vrational)
       VIsoCurve = new Geom_BezierCurve (VCurvePoles, VCurveWeights);
     else
@@ -1840,8 +1692,8 @@ Handle(Geom_Curve) Geom_BezierSurface::VIso (const Standard_Real V) const
   }
   else {
     BSplSLib::Iso (V, 0, Poles,
-                  *((TColStd_Array2OfReal*) NULL),
-                  bidvknots, bidvmults,
+                  BSplSLib::NoWeights(),
+                  bidvknots, &bidvmults,
                   VDegree(), 0, VCurvePoles, PLib::NoWeights());
     VIsoCurve = new Geom_BezierCurve (VCurvePoles);
   }
@@ -1937,7 +1789,6 @@ void Geom_BezierSurface::Transform (const gp_Trsf& T)
       Poles (I, J).Transform (T);
     }
   }
-  UpdateCoefficients();
 }
 
 //=======================================================================
@@ -2017,7 +1868,7 @@ void Geom_BezierSurface::Resolution(const Standard_Real  Tolerance3D,
     TColStd_Array1OfInteger bidvmults(1,2); bidvmults.Init(VDegree() + 1);
     if(urational || vrational){
       BSplSLib::Resolution(poles->Array2(),
-                          weights->Array2(),
+                          &weights->Array2(),
                           biduknots,
                           bidvknots,
                           bidumults,
@@ -2034,7 +1885,7 @@ void Geom_BezierSurface::Resolution(const Standard_Real  Tolerance3D,
     }
     else{
       BSplSLib::Resolution(poles->Array2(),
-                          *((TColStd_Array2OfReal*) NULL),
+                          BSplSLib::NoWeights(),
                           biduknots,
                           bidvknots,
                           bidumults,
@@ -2063,7 +1914,7 @@ void Geom_BezierSurface::Resolution(const Standard_Real  Tolerance3D,
 Handle(Geom_Geometry) Geom_BezierSurface::Copy() const
 {
   Handle(Geom_BezierSurface) S = new Geom_BezierSurface
-    (poles, coeffs, weights, wcoeffs, urational, vrational);
+    (poles, weights, urational, vrational);
   return S;
 }
 
@@ -2076,70 +1927,11 @@ void Geom_BezierSurface::Init
   (const Handle(TColgp_HArray2OfPnt)&   Poles, 
    const Handle(TColStd_HArray2OfReal)& Weights)
 {
-  Standard_Integer NbUPoles = Poles->ColLength();
-  Standard_Integer NbVPoles = Poles->RowLength();
-
-  Standard_Integer maxcls = Max(NbUPoles, NbVPoles);
-  Standard_Integer mincls = Min(NbUPoles, NbVPoles);
-
   // set fields
-  poles   = Poles;
-  coeffs  = new TColgp_HArray2OfPnt  (1,maxcls,1,mincls);
-
-  if (urational || vrational) {
+  poles = Poles;
+  if (urational || vrational)
     weights = Weights;
-    wcoeffs = new TColStd_HArray2OfReal (1,maxcls,1,mincls);
-  }
-  else {
+  else
     weights.Nullify();
-    wcoeffs.Nullify();
-  }
-
-  UpdateCoefficients();
-}
-
-
-//=======================================================================
-//function : UpdateCoefficients
-//purpose  : 
-//=======================================================================
-
-void  Geom_BezierSurface::UpdateCoefficients(const Standard_Real ,
-                                            const Standard_Real )
-{
-  maxderivinvok = Standard_False;
-  ucacheparameter = 0.;
-  TColStd_Array1OfReal biduflatknots(BSplCLib::FlatBezierKnots(UDegree()), 
-                                     1, 2*(UDegree()+1));
-  vcacheparameter = 0.;
-  TColStd_Array1OfReal bidvflatknots(BSplCLib::FlatBezierKnots(VDegree()), 
-                                     1, 2*(VDegree()+1));
-
-  Standard_Real uparameter_11 = (2*ucacheparameter + ucachespanlenght)/2,
-                uspanlenght_11 = ucachespanlenght/2,
-                vparameter_11 = (2*vcacheparameter + vcachespanlenght)/2,
-                vspanlenght_11 = vcachespanlenght/2 ;
-
-  if ( urational || vrational ) {
-    BSplSLib::BuildCache(uparameter_11,vparameter_11,
-                        uspanlenght_11,vspanlenght_11,0,0,
-                        UDegree(),VDegree(),0,0,
-                        biduflatknots,bidvflatknots,
-                        poles->Array2(),
-                        weights->Array2(),
-                        coeffs->ChangeArray2(),
-                        wcoeffs->ChangeArray2());
-  }
-  else {
-    BSplSLib::BuildCache(uparameter_11,vparameter_11,
-                        uspanlenght_11,vspanlenght_11,0,0,
-                        UDegree(),VDegree(),0,0,
-                        biduflatknots,bidvflatknots,
-                        poles->Array2(),
-                        *((TColStd_Array2OfReal*) NULL),
-                        coeffs->ChangeArray2(),
-                        *((TColStd_Array2OfReal*) NULL));
-  }
-  validcache = 1;
 }