0026949: Geom(2d)Adaptor_Curve/Surface should not do down casts in evaluation
authorIstvan Csanady <istvancsanady@gmail.com>
Thu, 3 Dec 2015 16:13:08 +0000 (17:13 +0100)
committerbugmaster <bugmaster@opencascade.com>
Thu, 10 Dec 2015 12:48:33 +0000 (15:48 +0300)
Prevent downcasting in curve evaluation in GeomAdaptor classes

src/Geom2dAdaptor/Geom2dAdaptor_Curve.cxx
src/Geom2dAdaptor/Geom2dAdaptor_Curve.hxx
src/GeomAdaptor/GeomAdaptor_Curve.cxx
src/GeomAdaptor/GeomAdaptor_Curve.hxx
src/GeomAdaptor/GeomAdaptor_Surface.cxx
src/GeomAdaptor/GeomAdaptor_Surface.hxx

index 432b317..983e46c 100644 (file)
@@ -75,22 +75,20 @@ static const Standard_Real PosTol = Precision::PConfusion() / 2;
 //=======================================================================
 
 GeomAbs_Shape Geom2dAdaptor_Curve::LocalContinuity(const Standard_Real U1, 
-                                                  const Standard_Real U2) 
-     const {
-
+                                                  const Standard_Real U2) const
+{
        Standard_NoSuchObject_Raise_if(myTypeCurve!=GeomAbs_BSplineCurve," ");
-       Handle(Geom2d_BSplineCurve) aBspl = Handle(Geom2d_BSplineCurve)::DownCast(myCurve);
-       Standard_Integer Nb = aBspl->NbKnots();
+       Standard_Integer Nb = myBSplineCurve->NbKnots();
        Standard_Integer Index1 = 0;
        Standard_Integer Index2 = 0;
        Standard_Real newFirst, newLast;
        TColStd_Array1OfReal    TK(1,Nb);
        TColStd_Array1OfInteger TM(1,Nb);
-       aBspl->Knots(TK);
-       aBspl->Multiplicities(TM);
-       BSplCLib::LocateParameter(aBspl->Degree(),TK,TM,U1,aBspl->IsPeriodic(),
+       myBSplineCurve->Knots(TK);
+       myBSplineCurve->Multiplicities(TM);
+       BSplCLib::LocateParameter(myBSplineCurve->Degree(),TK,TM,U1,myBSplineCurve->IsPeriodic(),
                                 1,Nb,Index1,newFirst);
-       BSplCLib::LocateParameter(aBspl->Degree(),TK,TM,U2,aBspl->IsPeriodic(),
+       BSplCLib::LocateParameter(myBSplineCurve->Degree(),TK,TM,U2,myBSplineCurve->IsPeriodic(),
                                 1,Nb,Index2,newLast);
        if ( Abs(newFirst-TK(Index1+1))<Precision::PConfusion()) { 
         if (Index1 < Nb)Index1++;
@@ -99,7 +97,7 @@ GeomAbs_Shape Geom2dAdaptor_Curve::LocalContinuity(const Standard_Real U1,
         Index2--;
        Standard_Integer MultMax;
        // attention aux courbes peridiques.
-       if ( (aBspl->IsPeriodic()) && (Index1 == Nb) )
+       if ( myBSplineCurve->IsPeriodic() && Index1 == Nb )
         Index1 = 1;
 
        if ( Index2 - Index1 <= 0) {
@@ -110,7 +108,7 @@ GeomAbs_Shape Geom2dAdaptor_Curve::LocalContinuity(const Standard_Real U1,
         for(Standard_Integer i = Index1+1;i<=Index2;i++) {
           if ( TM(i)>MultMax) MultMax=TM(i);
         }
-        MultMax = aBspl->Degree() - MultMax;
+        MultMax = myBSplineCurve->Degree() - MultMax;
        }
        if ( MultMax <= 0) {
         return GeomAbs_C0;
@@ -127,7 +125,7 @@ GeomAbs_Shape Geom2dAdaptor_Curve::LocalContinuity(const Standard_Real U1,
        else { 
         return GeomAbs_CN;
        }
-     }
+}
 
 
 //=======================================================================
@@ -185,8 +183,9 @@ void Geom2dAdaptor_Curve::load(const Handle(Geom2d_Curve)& C,
 
   if ( myCurve != C) {
     myCurve = C;
-    myCurveCache = Handle(BSplCLib_Cache)();
-    myNestedEvaluator = Handle(Geom2dEvaluator_Curve)();
+    myCurveCache.Nullify();
+    myNestedEvaluator.Nullify();
+    myBSplineCurve.Nullify();
 
     Handle(Standard_Type) TheType = C->DynamicType();
     if ( TheType == STANDARD_TYPE(Geom2d_TrimmedCurve)) {
@@ -221,6 +220,7 @@ void Geom2dAdaptor_Curve::load(const Handle(Geom2d_Curve)& C,
       myTypeCurve = GeomAbs_BSplineCurve;
       // Create cache for B-spline
       Handle(Geom2d_BSplineCurve) aBspl = Handle(Geom2d_BSplineCurve)::DownCast(myCurve);
+      myBSplineCurve = aBspl;
       myCurveCache = new BSplCLib_Cache(aBspl->Degree(), aBspl->IsPeriodic(),
           aBspl->KnotSequence(), aBspl->Poles(), aBspl->Weights());
     }
@@ -290,9 +290,8 @@ Standard_Integer Geom2dAdaptor_Curve::NbIntervals(const GeomAbs_Shape S) const
   Standard_Integer myNbIntervals = 1;
   Standard_Integer NbSplit;
   if (myTypeCurve == GeomAbs_BSplineCurve) {
-    Handle(Geom2d_BSplineCurve) aBspl = Handle(Geom2d_BSplineCurve)::DownCast(myCurve);
-    Standard_Integer FirstIndex = aBspl->FirstUKnotIndex();
-    Standard_Integer LastIndex  = aBspl->LastUKnotIndex();
+    Standard_Integer FirstIndex = myBSplineCurve->FirstUKnotIndex();
+    Standard_Integer LastIndex  = myBSplineCurve->LastUKnotIndex();
     TColStd_Array1OfInteger Inter (1, LastIndex-FirstIndex+1);
     if ( S > Continuity()) {
       Standard_Integer Cont;
@@ -312,11 +311,11 @@ Standard_Integer Geom2dAdaptor_Curve::NbIntervals(const GeomAbs_Shape S) const
          if      ( S == GeomAbs_C1) Cont = 1;
          else if ( S == GeomAbs_C2) Cont = 2;
          else if ( S == GeomAbs_C3) Cont = 3;
-         else                       Cont = aBspl->Degree();
-          Standard_Integer Degree = aBspl->Degree();
-          Standard_Integer NbKnots = aBspl->NbKnots();
+         else                       Cont = myBSplineCurve->Degree();
+          Standard_Integer Degree = myBSplineCurve->Degree();
+          Standard_Integer NbKnots = myBSplineCurve->NbKnots();
           TColStd_Array1OfInteger Mults (1, NbKnots);
-          aBspl->Multiplicities (Mults);
+          myBSplineCurve->Multiplicities (Mults);
           NbSplit = 1;
           Standard_Integer Index   = FirstIndex;
           Inter (NbSplit) = Index;
@@ -335,19 +334,19 @@ Standard_Integer Geom2dAdaptor_Curve::NbIntervals(const GeomAbs_Shape S) const
 
           Standard_Integer NbInt = NbSplit-1;
          
-         Standard_Integer Nb = aBspl->NbKnots();
+         Standard_Integer Nb = myBSplineCurve->NbKnots();
          Standard_Integer Index1 = 0;
          Standard_Integer Index2 = 0;
          Standard_Real newFirst, newLast;
          TColStd_Array1OfReal    TK(1,Nb);
          TColStd_Array1OfInteger TM(1,Nb);
-         aBspl->Knots(TK);
-         aBspl->Multiplicities(TM);
-         BSplCLib::LocateParameter(aBspl->Degree(),TK,TM,myFirst,
-                                   aBspl->IsPeriodic(),
+         myBSplineCurve->Knots(TK);
+         myBSplineCurve->Multiplicities(TM);
+         BSplCLib::LocateParameter(myBSplineCurve->Degree(),TK,TM,myFirst,
+                                   myBSplineCurve->IsPeriodic(),
                                    1,Nb,Index1,newFirst);
-         BSplCLib::LocateParameter(aBspl->Degree(),TK,TM,myLast,
-                                   aBspl->IsPeriodic(),
+         BSplCLib::LocateParameter(myBSplineCurve->Degree(),TK,TM,myLast,
+                                   myBSplineCurve->IsPeriodic(),
                                    1,Nb,Index2,newLast);
 
          // On decale eventuellement les indices  
@@ -396,9 +395,8 @@ void Geom2dAdaptor_Curve::Intervals(TColStd_Array1OfReal& T,
   Standard_Integer myNbIntervals = 1;
   Standard_Integer NbSplit;
   if (myTypeCurve == GeomAbs_BSplineCurve) {
-    Handle(Geom2d_BSplineCurve) aBspl = Handle(Geom2d_BSplineCurve)::DownCast(myCurve);
-    Standard_Integer FirstIndex = aBspl->FirstUKnotIndex();
-    Standard_Integer LastIndex  = aBspl->LastUKnotIndex();
+    Standard_Integer FirstIndex = myBSplineCurve->FirstUKnotIndex();
+    Standard_Integer LastIndex  = myBSplineCurve->LastUKnotIndex();
     TColStd_Array1OfInteger Inter (1, LastIndex-FirstIndex+1);
     if ( S > Continuity()) {
       Standard_Integer Cont;
@@ -418,11 +416,11 @@ void Geom2dAdaptor_Curve::Intervals(TColStd_Array1OfReal& T,
          if      ( S == GeomAbs_C1) Cont = 1;
          else if ( S == GeomAbs_C2) Cont = 2;
          else if ( S == GeomAbs_C3) Cont = 3;
-         else                       Cont = aBspl->Degree();
-          Standard_Integer Degree = aBspl->Degree();
-          Standard_Integer NbKnots = aBspl->NbKnots();
+         else                       Cont = myBSplineCurve->Degree();
+          Standard_Integer Degree = myBSplineCurve->Degree();
+          Standard_Integer NbKnots = myBSplineCurve->NbKnots();
           TColStd_Array1OfInteger Mults (1, NbKnots);
-          aBspl->Multiplicities (Mults);
+          myBSplineCurve->Multiplicities (Mults);
           NbSplit = 1;
           Standard_Integer Index   = FirstIndex;
           Inter (NbSplit) = Index;
@@ -440,19 +438,19 @@ void Geom2dAdaptor_Curve::Intervals(TColStd_Array1OfReal& T,
          Inter (NbSplit) = Index;
           Standard_Integer NbInt = NbSplit-1;
          
-         Standard_Integer Nb = aBspl->NbKnots();
+         Standard_Integer Nb = myBSplineCurve->NbKnots();
          Standard_Integer Index1 = 0;
          Standard_Integer Index2 = 0;
          Standard_Real newFirst, newLast;
          TColStd_Array1OfReal    TK(1,Nb);
          TColStd_Array1OfInteger TM(1,Nb);
-         aBspl->Knots(TK);
-         aBspl->Multiplicities(TM);
-         BSplCLib::LocateParameter(aBspl->Degree(),TK,TM,myFirst,
-                                   aBspl->IsPeriodic(),
+         myBSplineCurve->Knots(TK);
+         myBSplineCurve->Multiplicities(TM);
+         BSplCLib::LocateParameter(myBSplineCurve->Degree(),TK,TM,myFirst,
+                                   myBSplineCurve->IsPeriodic(),
                                    1,Nb,Index1,newFirst);
-         BSplCLib::LocateParameter(aBspl->Degree(),TK,TM,myLast,
-                                   aBspl->IsPeriodic(),
+         BSplCLib::LocateParameter(myBSplineCurve->Degree(),TK,TM,myLast,
+                                   myBSplineCurve->IsPeriodic(),
                                    1,Nb,Index2,newLast);
 
 
@@ -577,10 +575,9 @@ void Geom2dAdaptor_Curve::RebuildCache(const Standard_Real theParameter) const
   }
   else if (myTypeCurve == GeomAbs_BSplineCurve)
   {
-    Handle(Geom2d_BSplineCurve) aBspl = Handle(Geom2d_BSplineCurve)::DownCast(myCurve);
-    myCurveCache->BuildCache(theParameter, aBspl->Degree(),
-      aBspl->IsPeriodic(), aBspl->KnotSequence(),
-      aBspl->Poles(), aBspl->Weights());
+    myCurveCache->BuildCache(theParameter, myBSplineCurve->Degree(),
+      myBSplineCurve->IsPeriodic(), myBSplineCurve->KnotSequence(),
+      myBSplineCurve->Poles(), myBSplineCurve->Weights());
   }
 }
 
@@ -592,12 +589,11 @@ Standard_Boolean Geom2dAdaptor_Curve::IsBoundary(const Standard_Real theU,
                                                  Standard_Integer& theSpanStart,
                                                  Standard_Integer& theSpanFinish) const
 {
-  Handle(Geom2d_BSplineCurve) aBspl = Handle(Geom2d_BSplineCurve)::DownCast(myCurve);
-  if (!aBspl.IsNull() && (theU == myFirst || theU == myLast))
+  if (!myBSplineCurve.IsNull() && (theU == myFirst || theU == myLast))
   {
     if (theU == myFirst)
     {
-      aBspl->LocateU(myFirst, PosTol, theSpanStart, theSpanFinish);
+      myBSplineCurve->LocateU(myFirst, PosTol, theSpanStart, theSpanFinish);
       if (theSpanStart < 1)
         theSpanStart = 1;
       if (theSpanStart >= theSpanFinish)
@@ -605,9 +601,9 @@ Standard_Boolean Geom2dAdaptor_Curve::IsBoundary(const Standard_Real theU,
     }
     else if (theU == myLast)
     {
-      aBspl->LocateU(myLast, PosTol, theSpanStart, theSpanFinish);
-      if (theSpanFinish > aBspl->NbKnots())
-        theSpanFinish = aBspl->NbKnots();
+      myBSplineCurve->LocateU(myLast, PosTol, theSpanStart, theSpanFinish);
+      if (theSpanFinish > myBSplineCurve->NbKnots())
+        theSpanFinish = myBSplineCurve->NbKnots();
       if (theSpanStart >= theSpanFinish)
         theSpanStart = theSpanFinish - 1;
     }
@@ -643,8 +639,7 @@ void Geom2dAdaptor_Curve::D0(const Standard_Real U, gp_Pnt2d& P) const
     Standard_Integer aStart = 0, aFinish = 0;
     if (IsBoundary(U, aStart, aFinish))
     {
-      Handle(Geom2d_BSplineCurve) aBspl = Handle(Geom2d_BSplineCurve)::DownCast(myCurve);
-      aBspl->LocalD0(U, aStart, aFinish, P);
+      myBSplineCurve->LocalD0(U, aStart, aFinish, P);
     }
     else if (!myCurveCache.IsNull()) // use cached data
     {
@@ -682,8 +677,7 @@ void Geom2dAdaptor_Curve::D1(const Standard_Real U,
     Standard_Integer aStart = 0, aFinish = 0;
     if (IsBoundary(U, aStart, aFinish))
     {
-      Handle(Geom2d_BSplineCurve) aBspl = Handle(Geom2d_BSplineCurve)::DownCast(myCurve);
-      aBspl->LocalD1(U, aStart, aFinish, P, V);
+      myBSplineCurve->LocalD1(U, aStart, aFinish, P, V);
     }
     else if (!myCurveCache.IsNull()) // use cached data
     {
@@ -721,8 +715,7 @@ void Geom2dAdaptor_Curve::D2(const Standard_Real U,
     Standard_Integer aStart = 0, aFinish = 0;
     if (IsBoundary(U, aStart, aFinish))
     {
-      Handle(Geom2d_BSplineCurve) aBspl = Handle(Geom2d_BSplineCurve)::DownCast(myCurve);
-      aBspl->LocalD2(U, aStart, aFinish, P, V1, V2);
+      myBSplineCurve->LocalD2(U, aStart, aFinish, P, V1, V2);
     }
     else if (!myCurveCache.IsNull()) // use cached data
     {
@@ -761,8 +754,7 @@ void Geom2dAdaptor_Curve::D3(const Standard_Real U,
     Standard_Integer aStart = 0, aFinish = 0;
     if (IsBoundary(U, aStart, aFinish))
     {
-      Handle(Geom2d_BSplineCurve) aBspl = Handle(Geom2d_BSplineCurve)::DownCast(myCurve);
-      aBspl->LocalD3(U, aStart, aFinish, P, V1, V2, V3);
+      myBSplineCurve->LocalD3(U, aStart, aFinish, P, V1, V2, V3);
     }
     else if (!myCurveCache.IsNull()) // use cached data
     {
@@ -800,8 +792,7 @@ gp_Vec2d Geom2dAdaptor_Curve::DN(const Standard_Real U,
     Standard_Integer aStart = 0, aFinish = 0;
     if (IsBoundary(U, aStart, aFinish))
     {
-      Handle(Geom2d_BSplineCurve) aBspl = Handle(Geom2d_BSplineCurve)::DownCast(myCurve);
-      return aBspl->LocalDN(U, aStart, aFinish, N);
+      myBSplineCurve->LocalDN(U, aStart, aFinish, N);
     }
     else
       return myCurve->DN(U, N);
@@ -923,7 +914,7 @@ Standard_Integer Geom2dAdaptor_Curve::Degree() const
   if (myTypeCurve == GeomAbs_BezierCurve)
     return Handle(Geom2d_BezierCurve)::DownCast (myCurve)->Degree();
   else if (myTypeCurve == GeomAbs_BSplineCurve)
-    return Handle(Geom2d_BSplineCurve)::DownCast (myCurve)->Degree();
+    return myBSplineCurve->Degree();
   else
     Standard_NoSuchObject::Raise();
   // portage WNT 
@@ -938,7 +929,7 @@ Standard_Integer Geom2dAdaptor_Curve::Degree() const
 Standard_Boolean Geom2dAdaptor_Curve::IsRational() const {
   switch( myTypeCurve) {
   case GeomAbs_BSplineCurve:
-    return Handle(Geom2d_BSplineCurve)::DownCast (myCurve)->IsRational();
+    return myBSplineCurve->IsRational();
   case GeomAbs_BezierCurve:
     return Handle(Geom2d_BezierCurve)::DownCast (myCurve)->IsRational();
   default:
@@ -956,7 +947,7 @@ Standard_Integer Geom2dAdaptor_Curve::NbPoles() const
   if (myTypeCurve == GeomAbs_BezierCurve)
     return Handle(Geom2d_BezierCurve)::DownCast (myCurve)->NbPoles();
   else if (myTypeCurve == GeomAbs_BSplineCurve)
-    return Handle(Geom2d_BSplineCurve)::DownCast (myCurve)->NbPoles();
+    return myBSplineCurve->NbPoles();
   else
     Standard_NoSuchObject::Raise();
   // portage WNT 
@@ -968,11 +959,11 @@ Standard_Integer Geom2dAdaptor_Curve::NbPoles() const
 //purpose  : 
 //=======================================================================
 
-Standard_Integer Geom2dAdaptor_Curve::NbKnots() const {
+Standard_Integer Geom2dAdaptor_Curve::NbKnots() const
+{
   if ( myTypeCurve != GeomAbs_BSplineCurve)
     Standard_NoSuchObject::Raise("Geom2dAdaptor_Curve::NbKnots");
-  return Handle(Geom2d_BSplineCurve)::DownCast (myCurve)->NbKnots();
-
+  return myBSplineCurve->NbKnots();
 }
 
 //=======================================================================
@@ -992,7 +983,7 @@ Handle(Geom2d_BezierCurve) Geom2dAdaptor_Curve::Bezier() const
 
 Handle(Geom2d_BSplineCurve) Geom2dAdaptor_Curve::BSpline() const 
 {
-  return Handle(Geom2d_BSplineCurve)::DownCast (myCurve);
+  return myBSplineCurve;
 }
 
 static Standard_Integer nbPoints(const Handle(Geom2d_Curve)& theCurve) 
@@ -1025,7 +1016,7 @@ static Standard_Integer nbPoints(const Handle(Geom2d_Curve)& theCurve)
   if(nbs>300)
     nbs = 300;
   return nbs;
-  
+
 }
 
 Standard_Integer Geom2dAdaptor_Curve::NbSamples() const
index 89b51cd..3c0b7d5 100644 (file)
@@ -192,6 +192,8 @@ private:
   GeomAbs_CurveType myTypeCurve;
   Standard_Real myFirst;
   Standard_Real myLast;
+
+  Handle(Geom2d_BSplineCurve) myBSplineCurve; ///< B-spline representation to prevent castings
   Handle(BSplCLib_Cache) myCurveCache; ///< Cached data for B-spline or Bezier curve
   Handle(Geom2dEvaluator_Curve) myNestedEvaluator; ///< Calculates value of offset curve
 
index 56e8af3..39647ad 100644 (file)
@@ -77,18 +77,17 @@ GeomAbs_Shape GeomAdaptor_Curve::LocalContinuity(const Standard_Real U1,
      const 
 {
   Standard_NoSuchObject_Raise_if(myTypeCurve!=GeomAbs_BSplineCurve," ");
-  Handle(Geom_BSplineCurve) aBspl = Handle(Geom_BSplineCurve)::DownCast(myCurve);
-  Standard_Integer Nb = aBspl->NbKnots();
+  Standard_Integer Nb = myBSplineCurve->NbKnots();
   Standard_Integer Index1 = 0;
   Standard_Integer Index2 = 0;
   Standard_Real newFirst, newLast;
   TColStd_Array1OfReal    TK(1,Nb);
   TColStd_Array1OfInteger TM(1,Nb);
-  aBspl->Knots(TK);
-  aBspl->Multiplicities(TM);
-  BSplCLib::LocateParameter(aBspl->Degree(),TK,TM,U1,aBspl->IsPeriodic(),
+  myBSplineCurve->Knots(TK);
+  myBSplineCurve->Multiplicities(TM);
+  BSplCLib::LocateParameter(myBSplineCurve->Degree(),TK,TM,U1,myBSplineCurve->IsPeriodic(),
                            1,Nb,Index1,newFirst);
-  BSplCLib::LocateParameter(aBspl->Degree(),TK,TM,U2,aBspl->IsPeriodic(),
+  BSplCLib::LocateParameter(myBSplineCurve->Degree(),TK,TM,U2,myBSplineCurve->IsPeriodic(),
                            1,Nb,Index2,newLast);
   if ( Abs(newFirst-TK(Index1+1))<Precision::PConfusion()) { 
     if (Index1 < Nb) Index1++;
@@ -97,7 +96,7 @@ GeomAbs_Shape GeomAdaptor_Curve::LocalContinuity(const Standard_Real U1,
     Index2--;
   Standard_Integer MultMax;
   // attention aux courbes peridiques.
-  if ( (aBspl->IsPeriodic()) && (Index1 == Nb) )
+  if ( (myBSplineCurve->IsPeriodic()) && (Index1 == Nb) )
     Index1 = 1;
 
   if ( Index2 - Index1 <= 0) {
@@ -108,7 +107,7 @@ GeomAbs_Shape GeomAdaptor_Curve::LocalContinuity(const Standard_Real U1,
     for(Standard_Integer i = Index1+1;i<=Index2;i++) {
       if ( TM(i)>MultMax) MultMax=TM(i);
     }
-    MultMax = aBspl->Degree() - MultMax;
+    MultMax = myBSplineCurve->Degree() - MultMax;
   }
   if ( MultMax <= 0) {
     return GeomAbs_C0;
@@ -142,8 +141,9 @@ void GeomAdaptor_Curve::load(const Handle(Geom_Curve)& C,
 
   if ( myCurve != C) {
     myCurve = C;
-    myCurveCache = Handle(BSplCLib_Cache)();
-    myNestedEvaluator = Handle(GeomEvaluator_Curve)();
+    myCurveCache.Nullify();
+    myNestedEvaluator.Nullify();
+    myBSplineCurve.Nullify();
 
     const Handle(Standard_Type)& TheType = C->DynamicType();
     if ( TheType == STANDARD_TYPE(Geom_TrimmedCurve)) {
@@ -177,6 +177,7 @@ void GeomAdaptor_Curve::load(const Handle(Geom_Curve)& C,
       myTypeCurve = GeomAbs_BSplineCurve;
       // Create cache for B-spline
       Handle(Geom_BSplineCurve) aBspl = Handle(Geom_BSplineCurve)::DownCast(myCurve);
+      myBSplineCurve = aBspl;
       myCurveCache = new BSplCLib_Cache(aBspl->Degree(), aBspl->IsPeriodic(),
           aBspl->KnotSequence(), aBspl->Poles(), aBspl->Weights());
     }
@@ -242,9 +243,8 @@ Standard_Integer GeomAdaptor_Curve::NbIntervals(const GeomAbs_Shape S) const
   Standard_Integer myNbIntervals = 1;
   Standard_Integer NbSplit;
   if (myTypeCurve == GeomAbs_BSplineCurve) {
-    Handle(Geom_BSplineCurve) aBspl = Handle(Geom_BSplineCurve)::DownCast(myCurve);
-    Standard_Integer FirstIndex = aBspl->FirstUKnotIndex();
-    Standard_Integer LastIndex  = aBspl->LastUKnotIndex();
+    Standard_Integer FirstIndex = myBSplineCurve->FirstUKnotIndex();
+    Standard_Integer LastIndex  = myBSplineCurve->LastUKnotIndex();
     TColStd_Array1OfInteger Inter (1, LastIndex-FirstIndex+1);
     if ( S > Continuity()) {
       Standard_Integer Cont;
@@ -264,11 +264,11 @@ Standard_Integer GeomAdaptor_Curve::NbIntervals(const GeomAbs_Shape S) const
           if      ( S == GeomAbs_C1) Cont = 1;
           else if ( S == GeomAbs_C2) Cont = 2;
           else if ( S == GeomAbs_C3) Cont = 3;
-          else                       Cont = aBspl->Degree();
-          Standard_Integer Degree = aBspl->Degree();
-          Standard_Integer NbKnots = aBspl->NbKnots();
+          else                       Cont = myBSplineCurve->Degree();
+          Standard_Integer Degree = myBSplineCurve->Degree();
+          Standard_Integer NbKnots = myBSplineCurve->NbKnots();
           TColStd_Array1OfInteger Mults (1, NbKnots);
-          aBspl->Multiplicities (Mults);
+          myBSplineCurve->Multiplicities (Mults);
           NbSplit = 1;
           Standard_Integer Index   = FirstIndex;
           Inter (NbSplit) = Index;
@@ -287,19 +287,19 @@ Standard_Integer GeomAdaptor_Curve::NbIntervals(const GeomAbs_Shape S) const
 
           Standard_Integer NbInt = NbSplit-1;
           
-          Standard_Integer Nb = aBspl->NbKnots();
+          Standard_Integer Nb = myBSplineCurve->NbKnots();
           Standard_Integer Index1 = 0;
           Standard_Integer Index2 = 0;
           Standard_Real newFirst, newLast;
           TColStd_Array1OfReal    TK(1,Nb);
           TColStd_Array1OfInteger TM(1,Nb);
-          aBspl->Knots(TK);
-          aBspl->Multiplicities(TM);
-          BSplCLib::LocateParameter(aBspl->Degree(),TK,TM,myFirst,
-                                    aBspl->IsPeriodic(),
+          myBSplineCurve->Knots(TK);
+          myBSplineCurve->Multiplicities(TM);
+          BSplCLib::LocateParameter(myBSplineCurve->Degree(),TK,TM,myFirst,
+                                    myBSplineCurve->IsPeriodic(),
                                     1,Nb,Index1,newFirst);
-          BSplCLib::LocateParameter(aBspl->Degree(),TK,TM,myLast,
-                                    aBspl->IsPeriodic(),
+          BSplCLib::LocateParameter(myBSplineCurve->Degree(),TK,TM,myLast,
+                                    myBSplineCurve->IsPeriodic(),
                                     1,Nb,Index2,newLast);
 
           // On decale eventuellement les indices  
@@ -364,9 +364,8 @@ void GeomAdaptor_Curve::Intervals(TColStd_Array1OfReal& T,
 
   if (myTypeCurve == GeomAbs_BSplineCurve) 
     {
-      Handle(Geom_BSplineCurve) aBspl = Handle(Geom_BSplineCurve)::DownCast(myCurve);
-      Standard_Integer FirstIndex = aBspl->FirstUKnotIndex();
-      Standard_Integer LastIndex  = aBspl->LastUKnotIndex();
+      Standard_Integer FirstIndex = myBSplineCurve->FirstUKnotIndex();
+      Standard_Integer LastIndex  = myBSplineCurve->LastUKnotIndex();
       TColStd_Array1OfInteger Inter (1, LastIndex-FirstIndex+1);
       
       if ( S > Continuity()) {
@@ -387,11 +386,11 @@ void GeomAdaptor_Curve::Intervals(TColStd_Array1OfReal& T,
            if      ( S == GeomAbs_C1) Cont = 1;
            else if ( S == GeomAbs_C2) Cont = 2;
            else if ( S == GeomAbs_C3) Cont = 3;
-           else                       Cont = aBspl->Degree();
-           Standard_Integer Degree = aBspl->Degree();
-           Standard_Integer NbKnots = aBspl->NbKnots();
+           else                       Cont = myBSplineCurve->Degree();
+           Standard_Integer Degree = myBSplineCurve->Degree();
+           Standard_Integer NbKnots = myBSplineCurve->NbKnots();
            TColStd_Array1OfInteger Mults (1, NbKnots);
-           aBspl->Multiplicities (Mults);
+           myBSplineCurve->Multiplicities (Mults);
            NbSplit = 1;
            Standard_Integer Index   = FirstIndex;
            Inter (NbSplit) = Index;
@@ -413,19 +412,19 @@ void GeomAdaptor_Curve::Intervals(TColStd_Array1OfReal& T,
            //        TColStd_Array1OfInteger Inter(1,NbInt+1);
            //        Convector.Splitting( Inter);
            
-           Standard_Integer Nb = aBspl->NbKnots();
+           Standard_Integer Nb = myBSplineCurve->NbKnots();
            Standard_Integer Index1 = 0;
            Standard_Integer Index2 = 0;
            Standard_Real newFirst, newLast;
            TColStd_Array1OfReal    TK(1,Nb);
            TColStd_Array1OfInteger TM(1,Nb);
-           aBspl->Knots(TK);
-           aBspl->Multiplicities(TM);
-           BSplCLib::LocateParameter(aBspl->Degree(),TK,TM,myFirst,
-                                     aBspl->IsPeriodic(),
+           myBSplineCurve->Knots(TK);
+           myBSplineCurve->Multiplicities(TM);
+           BSplCLib::LocateParameter(myBSplineCurve->Degree(),TK,TM,myFirst,
+                                     myBSplineCurve->IsPeriodic(),
                                      1,Nb,Index1,newFirst);
-           BSplCLib::LocateParameter(aBspl->Degree(),TK,TM,myLast,
-                                     aBspl->IsPeriodic(),
+           BSplCLib::LocateParameter(myBSplineCurve->Degree(),TK,TM,myLast,
+                                     myBSplineCurve->IsPeriodic(),
                                      1,Nb,Index2,newLast);
             FirstParam = newFirst;
             LastParam = newLast;
@@ -557,10 +556,9 @@ void GeomAdaptor_Curve::RebuildCache(const Standard_Real theParameter) const
   }
   else if (myTypeCurve == GeomAbs_BSplineCurve)
   {
-    Handle(Geom_BSplineCurve) aBspl = Handle(Geom_BSplineCurve)::DownCast(myCurve);
-    myCurveCache->BuildCache(theParameter, aBspl->Degree(),
-        aBspl->IsPeriodic(), aBspl->KnotSequence(),
-        aBspl->Poles(), aBspl->Weights());
+    myCurveCache->BuildCache(theParameter, myBSplineCurve->Degree(),
+        myBSplineCurve->IsPeriodic(), myBSplineCurve->KnotSequence(),
+        myBSplineCurve->Poles(), myBSplineCurve->Weights());
   }
 }
 
@@ -572,12 +570,11 @@ Standard_Boolean GeomAdaptor_Curve::IsBoundary(const Standard_Real theU,
                                                Standard_Integer& theSpanStart,
                                                Standard_Integer& theSpanFinish) const
 {
-  Handle(Geom_BSplineCurve) aBspl = Handle(Geom_BSplineCurve)::DownCast(myCurve);
-  if (!aBspl.IsNull() && (theU == myFirst || theU == myLast))
+  if (!myBSplineCurve.IsNull() && (theU == myFirst || theU == myLast))
   {
     if (theU == myFirst)
     {
-      aBspl->LocateU(myFirst, PosTol, theSpanStart, theSpanFinish);
+      myBSplineCurve->LocateU(myFirst, PosTol, theSpanStart, theSpanFinish);
       if (theSpanStart < 1)
         theSpanStart = 1;
       if (theSpanStart >= theSpanFinish)
@@ -585,9 +582,9 @@ Standard_Boolean GeomAdaptor_Curve::IsBoundary(const Standard_Real theU,
     }
     else if (theU == myLast)
     {
-      aBspl->LocateU(myLast, PosTol, theSpanStart, theSpanFinish);
-      if (theSpanFinish > aBspl->NbKnots())
-        theSpanFinish = aBspl->NbKnots();
+      myBSplineCurve->LocateU(myLast, PosTol, theSpanStart, theSpanFinish);
+      if (theSpanFinish > myBSplineCurve->NbKnots())
+        theSpanFinish = myBSplineCurve->NbKnots();
       if (theSpanStart >= theSpanFinish)
         theSpanStart = theSpanFinish - 1;
     }
@@ -623,8 +620,7 @@ void GeomAdaptor_Curve::D0(const Standard_Real U, gp_Pnt& P) const
     Standard_Integer aStart = 0, aFinish = 0;
     if (IsBoundary(U, aStart, aFinish))
     {
-      Handle(Geom_BSplineCurve) aBspl = Handle(Geom_BSplineCurve)::DownCast(myCurve);
-      aBspl->LocalD0(U, aStart, aFinish, P);
+      myBSplineCurve->LocalD0(U, aStart, aFinish, P);
     }
     else if (!myCurveCache.IsNull()) // use cached data
     {
@@ -661,8 +657,7 @@ void GeomAdaptor_Curve::D1(const Standard_Real U, gp_Pnt& P, gp_Vec& V) const
     Standard_Integer aStart = 0, aFinish = 0;
     if (IsBoundary(U, aStart, aFinish))
     {
-      Handle(Geom_BSplineCurve) aBspl = Handle(Geom_BSplineCurve)::DownCast(myCurve);
-      aBspl->LocalD1(U, aStart, aFinish, P, V);
+      myBSplineCurve->LocalD1(U, aStart, aFinish, P, V);
     }
     else if (!myCurveCache.IsNull()) // use cached data
     {
@@ -700,8 +695,7 @@ void GeomAdaptor_Curve::D2(const Standard_Real U,
     Standard_Integer aStart = 0, aFinish = 0;
     if (IsBoundary(U, aStart, aFinish))
     {
-      Handle(Geom_BSplineCurve) aBspl = Handle(Geom_BSplineCurve)::DownCast(myCurve);
-      aBspl->LocalD2(U, aStart, aFinish, P, V1, V2);
+      myBSplineCurve->LocalD2(U, aStart, aFinish, P, V1, V2);
     }
     else if (!myCurveCache.IsNull()) // use cached data
     {
@@ -740,8 +734,7 @@ void GeomAdaptor_Curve::D3(const Standard_Real U,
     Standard_Integer aStart = 0, aFinish = 0;
     if (IsBoundary(U, aStart, aFinish))
     {
-      Handle(Geom_BSplineCurve) aBspl = Handle(Geom_BSplineCurve)::DownCast(myCurve);
-      aBspl->LocalD3(U, aStart, aFinish, P, V1, V2, V3);
+      myBSplineCurve->LocalD3(U, aStart, aFinish, P, V1, V2, V3);
     }
     else if (!myCurveCache.IsNull()) // use cached data
     {
@@ -779,8 +772,7 @@ gp_Vec GeomAdaptor_Curve::DN(const Standard_Real    U,
     Standard_Integer aStart = 0, aFinish = 0;
     if (IsBoundary(U, aStart, aFinish))
     {
-      Handle(Geom_BSplineCurve) aBspl = Handle(Geom_BSplineCurve)::DownCast(myCurve);
-      return aBspl->LocalDN(U, aStart, aFinish, N);
+      return myBSplineCurve->LocalDN(U, aStart, aFinish, N);
     }
     else
       return myCurve->DN(U, N);
@@ -824,7 +816,7 @@ Standard_Real GeomAdaptor_Curve::Resolution(const Standard_Real R3D) const
   }
   case GeomAbs_BSplineCurve: {
     Standard_Real res;
-    Handle(Geom_BSplineCurve)::DownCast (myCurve)->Resolution(R3D,res);
+    myBSplineCurve->Resolution(R3D,res);
     return res;
   }
   default:
@@ -903,7 +895,7 @@ Standard_Integer GeomAdaptor_Curve::Degree() const
   if (myTypeCurve == GeomAbs_BezierCurve)
     return Handle(Geom_BezierCurve)::DownCast (myCurve)->Degree();
   else if (myTypeCurve == GeomAbs_BSplineCurve)
-    return Handle(Geom_BSplineCurve)::DownCast (myCurve)->Degree();
+    return myBSplineCurve->Degree();
   else
     Standard_NoSuchObject::Raise();
   // portage WNT 
@@ -918,7 +910,7 @@ Standard_Integer GeomAdaptor_Curve::Degree() const
 Standard_Boolean GeomAdaptor_Curve::IsRational() const {
   switch( myTypeCurve) {
   case GeomAbs_BSplineCurve:
-    return Handle(Geom_BSplineCurve)::DownCast (myCurve)->IsRational();
+    return myBSplineCurve->IsRational();
   case GeomAbs_BezierCurve:
     return Handle(Geom_BezierCurve)::DownCast (myCurve)->IsRational();
   default:
@@ -936,7 +928,7 @@ Standard_Integer GeomAdaptor_Curve::NbPoles() const
   if (myTypeCurve == GeomAbs_BezierCurve)
     return Handle(Geom_BezierCurve)::DownCast (myCurve)->NbPoles();
   else if (myTypeCurve == GeomAbs_BSplineCurve)
-    return Handle(Geom_BSplineCurve)::DownCast (myCurve)->NbPoles();
+    return myBSplineCurve->NbPoles();
   else
     Standard_NoSuchObject::Raise();
   // portage WNT
@@ -952,7 +944,7 @@ Standard_Integer GeomAdaptor_Curve::NbKnots() const
 {
   if ( myTypeCurve != GeomAbs_BSplineCurve)
     Standard_NoSuchObject::Raise("GeomAdaptor_Curve::NbKnots");
-  return Handle(Geom_BSplineCurve)::DownCast (myCurve)->NbKnots();
+  return myBSplineCurve->NbKnots();
 }
 
 //=======================================================================
@@ -977,5 +969,5 @@ Handle(Geom_BSplineCurve) GeomAdaptor_Curve::BSpline() const
  if ( myTypeCurve != GeomAbs_BSplineCurve)
     Standard_NoSuchObject::Raise("GeomAdaptor_Curve::BSpline");
 
-  return Handle(Geom_BSplineCurve)::DownCast (myCurve);
+  return myBSplineCurve;
 }
index f74bbdc..7cf42e6 100644 (file)
@@ -231,6 +231,8 @@ private:
   GeomAbs_CurveType myTypeCurve;
   Standard_Real myFirst;
   Standard_Real myLast;
+  
+  Handle(Geom_BSplineCurve) myBSplineCurve; ///< B-spline representation to prevent castings
   Handle(BSplCLib_Cache) myCurveCache; ///< Cached data for B-spline or Bezier curve
   Handle(GeomEvaluator_Curve) myNestedEvaluator; ///< Calculates value of offset curve
 
index f3423df..973b915 100644 (file)
@@ -135,8 +135,9 @@ void GeomAdaptor_Surface::load(const Handle(Geom_Surface)& S,
 
   if ( mySurface != S) {
     mySurface = S;
-    mySurfaceCache = Handle(BSplSLib_Cache)();
-    myNestedEvaluator = Handle(GeomEvaluator_Surface)();
+    mySurfaceCache.Nullify();
+    myNestedEvaluator.Nullify();
+    myBSplineSurface.Nullify();
 
     const Handle(Standard_Type)& TheType = S->DynamicType();
     if (TheType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
@@ -195,6 +196,7 @@ void GeomAdaptor_Surface::load(const Handle(Geom_Surface)& S,
     else if (TheType == STANDARD_TYPE(Geom_BSplineSurface)) {
       mySurfaceType = GeomAbs_BSplineSurface;
       Handle(Geom_BSplineSurface) myBspl = Handle(Geom_BSplineSurface)::DownCast(mySurface);
+      myBSplineSurface = myBspl;
       // Create cache for B-spline
       mySurfaceCache = new BSplSLib_Cache( 
         myBspl->UDegree(), myBspl->IsUPeriodic(), myBspl->UKnotSequence(), 
@@ -233,13 +235,12 @@ GeomAbs_Shape GeomAdaptor_Surface::UContinuity() const
   {
     case GeomAbs_BSplineSurface:
     {
-      Handle(Geom_BSplineSurface) myBspl = Handle(Geom_BSplineSurface)::DownCast(mySurface);
-      const Standard_Integer N = myBspl->NbUKnots();
+      const Standard_Integer N = myBSplineSurface->NbUKnots();
       TColStd_Array1OfReal TK(1,N);
       TColStd_Array1OfInteger TM(1,N);
-      myBspl->UKnots(TK);
-      myBspl->UMultiplicities(TM);
-      return LocalContinuity(myBspl->UDegree(), myBspl->NbUKnots(), TK, TM,
+      myBSplineSurface->UKnots(TK);
+      myBSplineSurface->UMultiplicities(TM);
+      return LocalContinuity(myBSplineSurface->UDegree(), myBSplineSurface->NbUKnots(), TK, TM,
                              myUFirst, myULast, IsUPeriodic());
     }
     case GeomAbs_OffsetSurface:
@@ -288,13 +289,12 @@ GeomAbs_Shape GeomAdaptor_Surface::VContinuity() const
   {
     case GeomAbs_BSplineSurface:
     {
-      Handle(Geom_BSplineSurface) myBspl = Handle(Geom_BSplineSurface)::DownCast(mySurface);
-      const Standard_Integer N = myBspl->NbVKnots();
+      const Standard_Integer N = myBSplineSurface->NbVKnots();
       TColStd_Array1OfReal TK(1,N);
       TColStd_Array1OfInteger TM(1,N);
-      myBspl->VKnots(TK);
-      myBspl->VMultiplicities(TM);
-      return LocalContinuity(myBspl->VDegree(), myBspl->NbVKnots(), TK, TM,
+      myBSplineSurface->VKnots(TK);
+      myBSplineSurface->VMultiplicities(TM);
+      return LocalContinuity(myBSplineSurface->VDegree(), myBSplineSurface->NbVKnots(), TK, TM,
                              myVFirst, myVLast, IsVPeriodic());
     }
     case GeomAbs_OffsetSurface:
@@ -343,9 +343,8 @@ Standard_Integer GeomAdaptor_Surface::NbUIntervals(const GeomAbs_Shape S) const
   {
     case GeomAbs_BSplineSurface:
     {
-      Handle(Geom_BSplineSurface) myBspl = Handle(Geom_BSplineSurface)::DownCast(mySurface);
       GeomAdaptor_Curve myBasisCurve
-        (myBspl->VIso(myBspl->VKnot(myBspl->FirstVKnotIndex())),myUFirst,myULast);
+        (myBSplineSurface->VIso(myBSplineSurface->VKnot(myBSplineSurface->FirstVKnotIndex())),myUFirst,myULast);
       return myBasisCurve.NbIntervals(S);
     }
          case GeomAbs_SurfaceOfExtrusion:
@@ -397,9 +396,8 @@ Standard_Integer GeomAdaptor_Surface::NbVIntervals(const GeomAbs_Shape S) const
   {
     case GeomAbs_BSplineSurface:
     {
-      Handle(Geom_BSplineSurface) myBspl = Handle(Geom_BSplineSurface)::DownCast(mySurface);
       GeomAdaptor_Curve myBasisCurve
-        (myBspl->UIso(myBspl->UKnot(myBspl->FirstUKnotIndex())),myVFirst,myVLast);
+        (myBSplineSurface->UIso(myBSplineSurface->UKnot(myBSplineSurface->FirstUKnotIndex())),myVFirst,myVLast);
       return myBasisCurve.NbIntervals(S);
     }
     case GeomAbs_SurfaceOfRevolution:
@@ -453,9 +451,8 @@ void GeomAdaptor_Surface::UIntervals(TColStd_Array1OfReal& T, const GeomAbs_Shap
   {
     case GeomAbs_BSplineSurface:
     {
-      Handle(Geom_BSplineSurface) myBspl = Handle(Geom_BSplineSurface)::DownCast(mySurface);
       GeomAdaptor_Curve myBasisCurve
-        (myBspl->VIso(myBspl->VKnot(myBspl->FirstVKnotIndex())),myUFirst,myULast);
+        (myBSplineSurface->VIso(myBSplineSurface->VKnot(myBSplineSurface->FirstVKnotIndex())),myUFirst,myULast);
       myNbUIntervals = myBasisCurve.NbIntervals(S);
       myBasisCurve.Intervals(T,S);
       break;
@@ -516,9 +513,8 @@ void GeomAdaptor_Surface::VIntervals(TColStd_Array1OfReal& T, const GeomAbs_Shap
   {
     case GeomAbs_BSplineSurface:
     {
-      Handle(Geom_BSplineSurface) myBspl = Handle(Geom_BSplineSurface)::DownCast(mySurface);
       GeomAdaptor_Curve myBasisCurve
-        (myBspl->UIso(myBspl->UKnot(myBspl->FirstUKnotIndex())),myVFirst,myVLast);
+        (myBSplineSurface->UIso(myBSplineSurface->UKnot(myBSplineSurface->FirstUKnotIndex())),myVFirst,myVLast);
       myNbVIntervals = myBasisCurve.NbIntervals(S);
       myBasisCurve.Intervals(T,S);
       break;
@@ -694,11 +690,10 @@ void GeomAdaptor_Surface::RebuildCache(const Standard_Real theU,
   }
   else if (mySurfaceType == GeomAbs_BSplineSurface)
   {
-    Handle(Geom_BSplineSurface) myBspl = Handle(Geom_BSplineSurface)::DownCast(mySurface);
       mySurfaceCache->BuildCache(theU, theV,
-        myBspl->UDegree(), myBspl->IsUPeriodic(), myBspl->UKnotSequence(),
-        myBspl->VDegree(), myBspl->IsVPeriodic(), myBspl->VKnotSequence(),
-        myBspl->Poles(), myBspl->Weights());
+        myBSplineSurface->UDegree(), myBSplineSurface->IsUPeriodic(), myBSplineSurface->UKnotSequence(),
+        myBSplineSurface->VDegree(), myBSplineSurface->IsVPeriodic(), myBSplineSurface->VKnotSequence(),
+        myBSplineSurface->Poles(), myBSplineSurface->Weights());
   }
 }
 
@@ -772,11 +767,10 @@ void GeomAdaptor_Surface::D1(const Standard_Real U,
   switch(mySurfaceType) {
   case GeomAbs_BezierSurface:
   case GeomAbs_BSplineSurface: {
-    Handle(Geom_BSplineSurface) myBspl = Handle(Geom_BSplineSurface)::DownCast(mySurface);
-    if (!myBspl.IsNull() &&
+    if (!myBSplineSurface.IsNull() &&
         (USide != 0 || VSide != 0) && 
         IfUVBound(u, v, Ideb, Ifin, IVdeb, IVfin, USide, VSide))
-      myBspl->LocalD1(u, v, Ideb, Ifin, IVdeb, IVfin, P, D1U, D1V);
+      myBSplineSurface->LocalD1(u, v, Ideb, Ifin, IVdeb, IVfin, P, D1U, D1V);
     else if (!mySurfaceCache.IsNull())
     {
       if (!mySurfaceCache->IsCacheValid(U, V))
@@ -825,11 +819,10 @@ void GeomAdaptor_Surface::D2(const Standard_Real U,
   switch(mySurfaceType) {
   case GeomAbs_BezierSurface:
   case  GeomAbs_BSplineSurface: {
-    Handle(Geom_BSplineSurface) myBspl = Handle(Geom_BSplineSurface)::DownCast(mySurface);
-    if (!myBspl.IsNull() &&
+    if (!myBSplineSurface.IsNull() &&
         (USide != 0 || VSide != 0) && 
         IfUVBound(u, v, Ideb, Ifin, IVdeb, IVfin, USide, VSide))
-      myBspl->LocalD2(u, v, Ideb, Ifin, IVdeb, IVfin, P, D1U, D1V, D2U, D2V, D2UV);
+      myBSplineSurface->LocalD2(u, v, Ideb, Ifin, IVdeb, IVfin, P, D1U, D1V, D2U, D2V, D2UV);
     else if (!mySurfaceCache.IsNull())
     {
       if (!mySurfaceCache->IsCacheValid(U, V))
@@ -875,15 +868,14 @@ void GeomAdaptor_Surface::D3(const Standard_Real U, const Standard_Real V,
 
   switch(mySurfaceType) {
   case  GeomAbs_BSplineSurface: {
-    Handle(Geom_BSplineSurface) myBspl = Handle(Geom_BSplineSurface)::DownCast(mySurface);
     if ((USide == 0) && (VSide == 0))
-      myBspl->D3(u, v, P, D1U, D1V, D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV);
+      myBSplineSurface->D3(u, v, P, D1U, D1V, D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV);
     else {
       if (IfUVBound(u, v, Ideb, Ifin, IVdeb, IVfin, USide, VSide))
-        myBspl->LocalD3(u, v, Ideb, Ifin, IVdeb, IVfin,
+        myBSplineSurface->LocalD3(u, v, Ideb, Ifin, IVdeb, IVfin,
                         P, D1U, D1V, D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV);
       else
-        myBspl->D3(u, v, P, D1U, D1V, D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV);
+        myBSplineSurface->D3(u, v, P, D1U, D1V, D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV);
     }
     break;
   }
@@ -921,14 +913,13 @@ gp_Vec GeomAdaptor_Surface::DN(const Standard_Real    U,
   switch(mySurfaceType) 
   {
   case GeomAbs_BSplineSurface: {
-    Handle(Geom_BSplineSurface) myBspl = Handle(Geom_BSplineSurface)::DownCast(mySurface);
     if ((USide == 0) && (VSide == 0))
-      return myBspl->DN(u, v, Nu, Nv);
+      return myBSplineSurface->DN(u, v, Nu, Nv);
     else {
       if (IfUVBound(u, v, Ideb, Ifin, IVdeb, IVfin, USide, VSide))
-        return myBspl->LocalDN(u, v, Ideb, Ifin, IVdeb, IVfin, Nu, Nv);
+        return myBSplineSurface->LocalDN(u, v, Ideb, Ifin, IVdeb, IVfin, Nu, Nv);
       else
-        return myBspl->DN(u, v, Nu, Nv);
+        return myBSplineSurface->DN(u, v, Nu, Nv);
     }
   }
 
@@ -971,7 +962,7 @@ Standard_Real GeomAdaptor_Surface::UResolution(const Standard_Real R3d) const
         (Handle(Geom_SurfaceOfLinearExtrusion)::DownCast (mySurface)->BasisCurve(),myUFirst,myULast);
       return myBasisCurve.Resolution(R3d);
     }
-       case GeomAbs_Torus:
+    case GeomAbs_Torus:
     {
       Handle(Geom_ToroidalSurface) S (Handle(Geom_ToroidalSurface)::DownCast (mySurface));
       const Standard_Real R = S->MajorRadius() + S->MinorRadius();
@@ -979,7 +970,7 @@ Standard_Real GeomAdaptor_Surface::UResolution(const Standard_Real R3d) const
         Res = R3d/(2.*R);
          break;
     }
-       case GeomAbs_Sphere:
+    case GeomAbs_Sphere:
     {
       Handle(Geom_SphericalSurface) S (Handle(Geom_SphericalSurface)::DownCast (mySurface));
       const Standard_Real R = S->Radius();
@@ -987,7 +978,7 @@ Standard_Real GeomAdaptor_Surface::UResolution(const Standard_Real R3d) const
         Res = R3d/(2.*R);
          break;
     }
-       case GeomAbs_Cylinder:
+    case GeomAbs_Cylinder:
     {
       Handle(Geom_CylindricalSurface) S (Handle(Geom_CylindricalSurface)::DownCast (mySurface));
       const Standard_Real R = S->Radius();
@@ -995,7 +986,7 @@ Standard_Real GeomAdaptor_Surface::UResolution(const Standard_Real R3d) const
         Res = R3d/(2.*R);
          break;
     }
-       case GeomAbs_Cone:
+    case GeomAbs_Cone:
     {
       if (myVLast - myVFirst > 1.e10) {
         // Pas vraiment borne => resolution inconnue
@@ -1006,32 +997,32 @@ Standard_Real GeomAdaptor_Surface::UResolution(const Standard_Real R3d) const
       const Standard_Real Rayon1 = Handle(Geom_Circle)::DownCast (C)->Radius();
       C = S->VIso(myVFirst);
       const Standard_Real Rayon2 = Handle(Geom_Circle)::DownCast (C)->Radius();
-         const Standard_Real R = (Rayon1 > Rayon2)? Rayon1 : Rayon2;
-         return (R>Precision::Confusion()? (R3d / R) : 0.);
+      const Standard_Real R = (Rayon1 > Rayon2)? Rayon1 : Rayon2;
+      return (R>Precision::Confusion()? (R3d / R) : 0.);
     }
-       case GeomAbs_Plane:
+    case GeomAbs_Plane:
     {
       return R3d;
     }
-       case GeomAbs_BezierSurface:
+    case GeomAbs_BezierSurface:
     {
       Standard_Real Ures,Vres;
       Handle(Geom_BezierSurface)::DownCast (mySurface)->Resolution(R3d,Ures,Vres);
       return Ures;
     }
-       case GeomAbs_BSplineSurface:
+    case GeomAbs_BSplineSurface:
     {
       Standard_Real Ures,Vres;
-      Handle(Geom_BSplineSurface)::DownCast (mySurface)->Resolution(R3d,Ures,Vres);
+      myBSplineSurface->Resolution(R3d,Ures,Vres);
       return Ures;
     }
-       case GeomAbs_OffsetSurface:
+    case GeomAbs_OffsetSurface:
     {
       Handle(Geom_Surface) base = Handle(Geom_OffsetSurface)::DownCast (mySurface)->BasisSurface();
       GeomAdaptor_Surface gabase(base,myUFirst,myULast,myVFirst,myVLast);
       return gabase.UResolution(R3d);
     }
-       default: return Precision::Parametric(R3d);
+    default: return Precision::Parametric(R3d);
   }
 
   if ( Res <= 1.)  
@@ -1057,7 +1048,7 @@ Standard_Real GeomAdaptor_Surface::VResolution(const Standard_Real R3d) const
         (Handle(Geom_SurfaceOfRevolution)::DownCast (mySurface)->BasisCurve(),myUFirst,myULast);
       return myBasisCurve.Resolution(R3d);
     }
-       case GeomAbs_Torus:
+    case GeomAbs_Torus:
     {
       Handle(Geom_ToroidalSurface) S (Handle(Geom_ToroidalSurface)::DownCast (mySurface));
       const Standard_Real R = S->MinorRadius();
@@ -1065,7 +1056,7 @@ Standard_Real GeomAdaptor_Surface::VResolution(const Standard_Real R3d) const
         Res = R3d/(2.*R);
       break;
     }
-       case GeomAbs_Sphere:
+    case GeomAbs_Sphere:
     {
       Handle(Geom_SphericalSurface) S (Handle(Geom_SphericalSurface)::DownCast (mySurface));
       const Standard_Real R = S->Radius();
@@ -1073,32 +1064,32 @@ Standard_Real GeomAdaptor_Surface::VResolution(const Standard_Real R3d) const
         Res = R3d/(2.*R);
       break;
     }
-       case GeomAbs_SurfaceOfExtrusion:
-       case GeomAbs_Cylinder:
-       case GeomAbs_Cone:
-       case GeomAbs_Plane:
+    case GeomAbs_SurfaceOfExtrusion:
+    case GeomAbs_Cylinder:
+    case GeomAbs_Cone:
+    case GeomAbs_Plane:
     {
       return R3d;
     }
-       case GeomAbs_BezierSurface:
+    case GeomAbs_BezierSurface:
     {
       Standard_Real Ures,Vres;
       Handle(Geom_BezierSurface)::DownCast (mySurface)->Resolution(R3d,Ures,Vres);
       return Vres;
     }
-       case GeomAbs_BSplineSurface:
+    case GeomAbs_BSplineSurface:
     {
       Standard_Real Ures,Vres;
-      Handle(Geom_BSplineSurface)::DownCast (mySurface)->Resolution(R3d,Ures,Vres);
+      myBSplineSurface->Resolution(R3d,Ures,Vres);
       return Vres;
     }
-       case GeomAbs_OffsetSurface:
+    case GeomAbs_OffsetSurface:
     {
       Handle(Geom_Surface) base = Handle(Geom_OffsetSurface)::DownCast (mySurface)->BasisSurface();
       GeomAdaptor_Surface gabase(base,myUFirst,myULast,myVFirst,myVLast);
       return gabase.VResolution(R3d);
     }
-       default: return Precision::Parametric(R3d);
+    default: return Precision::Parametric(R3d);
   }
 
   if ( Res <= 1.) 
@@ -1175,7 +1166,7 @@ gp_Torus GeomAdaptor_Surface::Torus() const
 Standard_Integer GeomAdaptor_Surface::UDegree() const
 {
   if (mySurfaceType == GeomAbs_BSplineSurface)
-    return Handle(Geom_BSplineSurface)::DownCast (mySurface)->UDegree(); 
+    return myBSplineSurface->UDegree();
   if ( mySurfaceType == GeomAbs_BezierSurface)
     return Handle(Geom_BezierSurface)::DownCast (mySurface)->UDegree(); 
   if ( mySurfaceType == GeomAbs_SurfaceOfExtrusion)
@@ -1196,7 +1187,7 @@ Standard_Integer GeomAdaptor_Surface::UDegree() const
 Standard_Integer GeomAdaptor_Surface::NbUPoles() const
 {
   if (mySurfaceType == GeomAbs_BSplineSurface)
-    return Handle(Geom_BSplineSurface)::DownCast (mySurface)->NbUPoles();
+    return myBSplineSurface->NbUPoles();
   if ( mySurfaceType == GeomAbs_BezierSurface)
     return Handle(Geom_BezierSurface)::DownCast (mySurface)->NbUPoles(); 
   if ( mySurfaceType == GeomAbs_SurfaceOfExtrusion)
@@ -1217,7 +1208,7 @@ Standard_Integer GeomAdaptor_Surface::NbUPoles() const
 Standard_Integer GeomAdaptor_Surface::VDegree() const
 {
   if (mySurfaceType == GeomAbs_BSplineSurface)
-    return Handle(Geom_BSplineSurface)::DownCast (mySurface)->VDegree(); 
+    return myBSplineSurface->VDegree();
   if ( mySurfaceType == GeomAbs_BezierSurface)
     return Handle(Geom_BezierSurface)::DownCast (mySurface)->VDegree(); 
   if ( mySurfaceType == GeomAbs_SurfaceOfRevolution)
@@ -1238,7 +1229,7 @@ Standard_Integer GeomAdaptor_Surface::VDegree() const
 Standard_Integer GeomAdaptor_Surface::NbVPoles() const
 {
   if (mySurfaceType == GeomAbs_BSplineSurface)
-    return Handle(Geom_BSplineSurface)::DownCast (mySurface)->NbVPoles(); 
+    return myBSplineSurface->NbVPoles();
   if ( mySurfaceType == GeomAbs_BezierSurface)
     return Handle(Geom_BezierSurface)::DownCast (mySurface)->NbVPoles(); 
   if ( mySurfaceType == GeomAbs_SurfaceOfRevolution)
@@ -1259,7 +1250,7 @@ Standard_Integer GeomAdaptor_Surface::NbVPoles() const
 Standard_Integer GeomAdaptor_Surface::NbUKnots() const
 {
   if (mySurfaceType == GeomAbs_BSplineSurface)
-    return Handle(Geom_BSplineSurface)::DownCast (mySurface)->NbUKnots(); 
+    return myBSplineSurface->NbUKnots();
   if ( mySurfaceType == GeomAbs_SurfaceOfExtrusion)
   {
     GeomAdaptor_Curve myBasisCurve
@@ -1278,7 +1269,7 @@ Standard_Integer GeomAdaptor_Surface::NbUKnots() const
 Standard_Integer GeomAdaptor_Surface::NbVKnots() const 
 {
   if (mySurfaceType == GeomAbs_BSplineSurface)
-    return Handle(Geom_BSplineSurface)::DownCast (mySurface)->NbVKnots(); 
+    return myBSplineSurface->NbVKnots();
   Standard_NoSuchObject::Raise("GeomAdaptor_Surface::NbVKnots");
   return 0;
 }
@@ -1290,7 +1281,7 @@ Standard_Integer GeomAdaptor_Surface::NbVKnots() const
 Standard_Boolean GeomAdaptor_Surface::IsURational() const
 {
   if (mySurfaceType == GeomAbs_BSplineSurface)
-    return Handle(Geom_BSplineSurface)::DownCast (mySurface)->IsURational(); 
+    return myBSplineSurface->IsURational();
   if (mySurfaceType == GeomAbs_BezierSurface)
     return Handle(Geom_BezierSurface)::DownCast (mySurface)->IsURational(); 
   return Standard_False;
@@ -1304,7 +1295,7 @@ Standard_Boolean GeomAdaptor_Surface::IsURational() const
 Standard_Boolean GeomAdaptor_Surface::IsVRational() const
 {
   if (mySurfaceType == GeomAbs_BSplineSurface)
-    return Handle(Geom_BSplineSurface)::DownCast (mySurface)->IsVRational(); 
+    return myBSplineSurface->IsVRational();
   if (mySurfaceType == GeomAbs_BezierSurface)
     return Handle(Geom_BezierSurface)::DownCast (mySurface)->IsVRational(); 
   return Standard_False;
@@ -1331,7 +1322,7 @@ Handle(Geom_BSplineSurface) GeomAdaptor_Surface::BSpline() const
 {
   if (mySurfaceType != GeomAbs_BSplineSurface)  
     Standard_NoSuchObject::Raise("GeomAdaptor_Surface::BSpline");
-  return Handle(Geom_BSplineSurface)::DownCast (mySurface);
+  return myBSplineSurface;
 }
 
 //=======================================================================
@@ -1418,15 +1409,14 @@ Standard_Boolean GeomAdaptor_Surface::IfUVBound(const Standard_Real U,
                                                 const Standard_Integer VSide) const
 {
   Standard_Integer Ideb,Ifin;
-  Handle(Geom_BSplineSurface) myBspl = Handle(Geom_BSplineSurface)::DownCast(mySurface);
-  Standard_Integer anUFKIndx = myBspl->FirstUKnotIndex(),
-    anULKIndx = myBspl->LastUKnotIndex(), 
-    aVFKIndx = myBspl->FirstVKnotIndex(), aVLKIndx = myBspl->LastVKnotIndex();
-  myBspl->LocateU(U, PosTol, Ideb, Ifin, Standard_False);
+  Standard_Integer anUFKIndx = myBSplineSurface->FirstUKnotIndex(),
+    anULKIndx = myBSplineSurface->LastUKnotIndex(), 
+    aVFKIndx = myBSplineSurface->FirstVKnotIndex(), aVLKIndx = myBSplineSurface->LastVKnotIndex();
+  myBSplineSurface->LocateU(U, PosTol, Ideb, Ifin, Standard_False);
   Standard_Boolean Local = (Ideb == Ifin);
   Span(USide,Ideb,Ifin,Ideb,Ifin,anUFKIndx,anULKIndx);
   Standard_Integer IVdeb,IVfin;
-  myBspl->LocateV(V, PosTol, IVdeb, IVfin, Standard_False); 
+  myBSplineSurface->LocateV(V, PosTol, IVdeb, IVfin, Standard_False); 
   if(IVdeb == IVfin) Local = Standard_True;
   Span(VSide,IVdeb,IVfin,IVdeb,IVfin,aVFKIndx,aVLKIndx);
 
index 6851273..b03243f 100644 (file)
@@ -266,6 +266,8 @@ private:
   Standard_Real myVLast;
   Standard_Real myTolU;
   Standard_Real myTolV;
+  
+  Handle(Geom_BSplineSurface) myBSplineSurface; ///< B-spline representation to prevent downcasts
   Handle(BSplSLib_Cache) mySurfaceCache; ///< Cached data for B-spline or Bezier surface
 
 protected: