1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-06 18:26:22 +03:00

0026949: Geom(2d)Adaptor_Curve/Surface should not do down casts in evaluation

Prevent downcasting in curve evaluation in GeomAdaptor classes
This commit is contained in:
Istvan Csanady 2015-12-03 17:13:08 +01:00 committed by bugmaster
parent 92efcf78a6
commit 3b25c0e867
6 changed files with 189 additions and 210 deletions

View File

@ -75,22 +75,20 @@ static const Standard_Real PosTol = Precision::PConfusion() / 2;
//======================================================================= //=======================================================================
GeomAbs_Shape Geom2dAdaptor_Curve::LocalContinuity(const Standard_Real U1, GeomAbs_Shape Geom2dAdaptor_Curve::LocalContinuity(const Standard_Real U1,
const Standard_Real U2) const Standard_Real U2) const
const { {
Standard_NoSuchObject_Raise_if(myTypeCurve!=GeomAbs_BSplineCurve," "); Standard_NoSuchObject_Raise_if(myTypeCurve!=GeomAbs_BSplineCurve," ");
Handle(Geom2d_BSplineCurve) aBspl = Handle(Geom2d_BSplineCurve)::DownCast(myCurve); Standard_Integer Nb = myBSplineCurve->NbKnots();
Standard_Integer Nb = aBspl->NbKnots();
Standard_Integer Index1 = 0; Standard_Integer Index1 = 0;
Standard_Integer Index2 = 0; Standard_Integer Index2 = 0;
Standard_Real newFirst, newLast; Standard_Real newFirst, newLast;
TColStd_Array1OfReal TK(1,Nb); TColStd_Array1OfReal TK(1,Nb);
TColStd_Array1OfInteger TM(1,Nb); TColStd_Array1OfInteger TM(1,Nb);
aBspl->Knots(TK); myBSplineCurve->Knots(TK);
aBspl->Multiplicities(TM); myBSplineCurve->Multiplicities(TM);
BSplCLib::LocateParameter(aBspl->Degree(),TK,TM,U1,aBspl->IsPeriodic(), BSplCLib::LocateParameter(myBSplineCurve->Degree(),TK,TM,U1,myBSplineCurve->IsPeriodic(),
1,Nb,Index1,newFirst); 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); 1,Nb,Index2,newLast);
if ( Abs(newFirst-TK(Index1+1))<Precision::PConfusion()) { if ( Abs(newFirst-TK(Index1+1))<Precision::PConfusion()) {
if (Index1 < Nb)Index1++; if (Index1 < Nb)Index1++;
@ -99,7 +97,7 @@ GeomAbs_Shape Geom2dAdaptor_Curve::LocalContinuity(const Standard_Real U1,
Index2--; Index2--;
Standard_Integer MultMax; Standard_Integer MultMax;
// attention aux courbes peridiques. // attention aux courbes peridiques.
if ( (aBspl->IsPeriodic()) && (Index1 == Nb) ) if ( myBSplineCurve->IsPeriodic() && Index1 == Nb )
Index1 = 1; Index1 = 1;
if ( Index2 - Index1 <= 0) { 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++) { for(Standard_Integer i = Index1+1;i<=Index2;i++) {
if ( TM(i)>MultMax) MultMax=TM(i); if ( TM(i)>MultMax) MultMax=TM(i);
} }
MultMax = aBspl->Degree() - MultMax; MultMax = myBSplineCurve->Degree() - MultMax;
} }
if ( MultMax <= 0) { if ( MultMax <= 0) {
return GeomAbs_C0; return GeomAbs_C0;
@ -127,7 +125,7 @@ GeomAbs_Shape Geom2dAdaptor_Curve::LocalContinuity(const Standard_Real U1,
else { else {
return GeomAbs_CN; return GeomAbs_CN;
} }
} }
//======================================================================= //=======================================================================
@ -185,8 +183,9 @@ void Geom2dAdaptor_Curve::load(const Handle(Geom2d_Curve)& C,
if ( myCurve != C) { if ( myCurve != C) {
myCurve = C; myCurve = C;
myCurveCache = Handle(BSplCLib_Cache)(); myCurveCache.Nullify();
myNestedEvaluator = Handle(Geom2dEvaluator_Curve)(); myNestedEvaluator.Nullify();
myBSplineCurve.Nullify();
Handle(Standard_Type) TheType = C->DynamicType(); Handle(Standard_Type) TheType = C->DynamicType();
if ( TheType == STANDARD_TYPE(Geom2d_TrimmedCurve)) { if ( TheType == STANDARD_TYPE(Geom2d_TrimmedCurve)) {
@ -221,6 +220,7 @@ void Geom2dAdaptor_Curve::load(const Handle(Geom2d_Curve)& C,
myTypeCurve = GeomAbs_BSplineCurve; myTypeCurve = GeomAbs_BSplineCurve;
// Create cache for B-spline // Create cache for B-spline
Handle(Geom2d_BSplineCurve) aBspl = Handle(Geom2d_BSplineCurve)::DownCast(myCurve); Handle(Geom2d_BSplineCurve) aBspl = Handle(Geom2d_BSplineCurve)::DownCast(myCurve);
myBSplineCurve = aBspl;
myCurveCache = new BSplCLib_Cache(aBspl->Degree(), aBspl->IsPeriodic(), myCurveCache = new BSplCLib_Cache(aBspl->Degree(), aBspl->IsPeriodic(),
aBspl->KnotSequence(), aBspl->Poles(), aBspl->Weights()); 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 myNbIntervals = 1;
Standard_Integer NbSplit; Standard_Integer NbSplit;
if (myTypeCurve == GeomAbs_BSplineCurve) { if (myTypeCurve == GeomAbs_BSplineCurve) {
Handle(Geom2d_BSplineCurve) aBspl = Handle(Geom2d_BSplineCurve)::DownCast(myCurve); Standard_Integer FirstIndex = myBSplineCurve->FirstUKnotIndex();
Standard_Integer FirstIndex = aBspl->FirstUKnotIndex(); Standard_Integer LastIndex = myBSplineCurve->LastUKnotIndex();
Standard_Integer LastIndex = aBspl->LastUKnotIndex();
TColStd_Array1OfInteger Inter (1, LastIndex-FirstIndex+1); TColStd_Array1OfInteger Inter (1, LastIndex-FirstIndex+1);
if ( S > Continuity()) { if ( S > Continuity()) {
Standard_Integer Cont; Standard_Integer Cont;
@ -312,11 +311,11 @@ Standard_Integer Geom2dAdaptor_Curve::NbIntervals(const GeomAbs_Shape S) const
if ( S == GeomAbs_C1) Cont = 1; if ( S == GeomAbs_C1) Cont = 1;
else if ( S == GeomAbs_C2) Cont = 2; else if ( S == GeomAbs_C2) Cont = 2;
else if ( S == GeomAbs_C3) Cont = 3; else if ( S == GeomAbs_C3) Cont = 3;
else Cont = aBspl->Degree(); else Cont = myBSplineCurve->Degree();
Standard_Integer Degree = aBspl->Degree(); Standard_Integer Degree = myBSplineCurve->Degree();
Standard_Integer NbKnots = aBspl->NbKnots(); Standard_Integer NbKnots = myBSplineCurve->NbKnots();
TColStd_Array1OfInteger Mults (1, NbKnots); TColStd_Array1OfInteger Mults (1, NbKnots);
aBspl->Multiplicities (Mults); myBSplineCurve->Multiplicities (Mults);
NbSplit = 1; NbSplit = 1;
Standard_Integer Index = FirstIndex; Standard_Integer Index = FirstIndex;
Inter (NbSplit) = Index; Inter (NbSplit) = Index;
@ -335,19 +334,19 @@ Standard_Integer Geom2dAdaptor_Curve::NbIntervals(const GeomAbs_Shape S) const
Standard_Integer NbInt = NbSplit-1; Standard_Integer NbInt = NbSplit-1;
Standard_Integer Nb = aBspl->NbKnots(); Standard_Integer Nb = myBSplineCurve->NbKnots();
Standard_Integer Index1 = 0; Standard_Integer Index1 = 0;
Standard_Integer Index2 = 0; Standard_Integer Index2 = 0;
Standard_Real newFirst, newLast; Standard_Real newFirst, newLast;
TColStd_Array1OfReal TK(1,Nb); TColStd_Array1OfReal TK(1,Nb);
TColStd_Array1OfInteger TM(1,Nb); TColStd_Array1OfInteger TM(1,Nb);
aBspl->Knots(TK); myBSplineCurve->Knots(TK);
aBspl->Multiplicities(TM); myBSplineCurve->Multiplicities(TM);
BSplCLib::LocateParameter(aBspl->Degree(),TK,TM,myFirst, BSplCLib::LocateParameter(myBSplineCurve->Degree(),TK,TM,myFirst,
aBspl->IsPeriodic(), myBSplineCurve->IsPeriodic(),
1,Nb,Index1,newFirst); 1,Nb,Index1,newFirst);
BSplCLib::LocateParameter(aBspl->Degree(),TK,TM,myLast, BSplCLib::LocateParameter(myBSplineCurve->Degree(),TK,TM,myLast,
aBspl->IsPeriodic(), myBSplineCurve->IsPeriodic(),
1,Nb,Index2,newLast); 1,Nb,Index2,newLast);
// On decale eventuellement les indices // On decale eventuellement les indices
@ -396,9 +395,8 @@ void Geom2dAdaptor_Curve::Intervals(TColStd_Array1OfReal& T,
Standard_Integer myNbIntervals = 1; Standard_Integer myNbIntervals = 1;
Standard_Integer NbSplit; Standard_Integer NbSplit;
if (myTypeCurve == GeomAbs_BSplineCurve) { if (myTypeCurve == GeomAbs_BSplineCurve) {
Handle(Geom2d_BSplineCurve) aBspl = Handle(Geom2d_BSplineCurve)::DownCast(myCurve); Standard_Integer FirstIndex = myBSplineCurve->FirstUKnotIndex();
Standard_Integer FirstIndex = aBspl->FirstUKnotIndex(); Standard_Integer LastIndex = myBSplineCurve->LastUKnotIndex();
Standard_Integer LastIndex = aBspl->LastUKnotIndex();
TColStd_Array1OfInteger Inter (1, LastIndex-FirstIndex+1); TColStd_Array1OfInteger Inter (1, LastIndex-FirstIndex+1);
if ( S > Continuity()) { if ( S > Continuity()) {
Standard_Integer Cont; Standard_Integer Cont;
@ -418,11 +416,11 @@ void Geom2dAdaptor_Curve::Intervals(TColStd_Array1OfReal& T,
if ( S == GeomAbs_C1) Cont = 1; if ( S == GeomAbs_C1) Cont = 1;
else if ( S == GeomAbs_C2) Cont = 2; else if ( S == GeomAbs_C2) Cont = 2;
else if ( S == GeomAbs_C3) Cont = 3; else if ( S == GeomAbs_C3) Cont = 3;
else Cont = aBspl->Degree(); else Cont = myBSplineCurve->Degree();
Standard_Integer Degree = aBspl->Degree(); Standard_Integer Degree = myBSplineCurve->Degree();
Standard_Integer NbKnots = aBspl->NbKnots(); Standard_Integer NbKnots = myBSplineCurve->NbKnots();
TColStd_Array1OfInteger Mults (1, NbKnots); TColStd_Array1OfInteger Mults (1, NbKnots);
aBspl->Multiplicities (Mults); myBSplineCurve->Multiplicities (Mults);
NbSplit = 1; NbSplit = 1;
Standard_Integer Index = FirstIndex; Standard_Integer Index = FirstIndex;
Inter (NbSplit) = Index; Inter (NbSplit) = Index;
@ -440,19 +438,19 @@ void Geom2dAdaptor_Curve::Intervals(TColStd_Array1OfReal& T,
Inter (NbSplit) = Index; Inter (NbSplit) = Index;
Standard_Integer NbInt = NbSplit-1; Standard_Integer NbInt = NbSplit-1;
Standard_Integer Nb = aBspl->NbKnots(); Standard_Integer Nb = myBSplineCurve->NbKnots();
Standard_Integer Index1 = 0; Standard_Integer Index1 = 0;
Standard_Integer Index2 = 0; Standard_Integer Index2 = 0;
Standard_Real newFirst, newLast; Standard_Real newFirst, newLast;
TColStd_Array1OfReal TK(1,Nb); TColStd_Array1OfReal TK(1,Nb);
TColStd_Array1OfInteger TM(1,Nb); TColStd_Array1OfInteger TM(1,Nb);
aBspl->Knots(TK); myBSplineCurve->Knots(TK);
aBspl->Multiplicities(TM); myBSplineCurve->Multiplicities(TM);
BSplCLib::LocateParameter(aBspl->Degree(),TK,TM,myFirst, BSplCLib::LocateParameter(myBSplineCurve->Degree(),TK,TM,myFirst,
aBspl->IsPeriodic(), myBSplineCurve->IsPeriodic(),
1,Nb,Index1,newFirst); 1,Nb,Index1,newFirst);
BSplCLib::LocateParameter(aBspl->Degree(),TK,TM,myLast, BSplCLib::LocateParameter(myBSplineCurve->Degree(),TK,TM,myLast,
aBspl->IsPeriodic(), myBSplineCurve->IsPeriodic(),
1,Nb,Index2,newLast); 1,Nb,Index2,newLast);
@ -577,10 +575,9 @@ void Geom2dAdaptor_Curve::RebuildCache(const Standard_Real theParameter) const
} }
else if (myTypeCurve == GeomAbs_BSplineCurve) else if (myTypeCurve == GeomAbs_BSplineCurve)
{ {
Handle(Geom2d_BSplineCurve) aBspl = Handle(Geom2d_BSplineCurve)::DownCast(myCurve); myCurveCache->BuildCache(theParameter, myBSplineCurve->Degree(),
myCurveCache->BuildCache(theParameter, aBspl->Degree(), myBSplineCurve->IsPeriodic(), myBSplineCurve->KnotSequence(),
aBspl->IsPeriodic(), aBspl->KnotSequence(), myBSplineCurve->Poles(), myBSplineCurve->Weights());
aBspl->Poles(), aBspl->Weights());
} }
} }
@ -592,12 +589,11 @@ Standard_Boolean Geom2dAdaptor_Curve::IsBoundary(const Standard_Real theU,
Standard_Integer& theSpanStart, Standard_Integer& theSpanStart,
Standard_Integer& theSpanFinish) const Standard_Integer& theSpanFinish) const
{ {
Handle(Geom2d_BSplineCurve) aBspl = Handle(Geom2d_BSplineCurve)::DownCast(myCurve); if (!myBSplineCurve.IsNull() && (theU == myFirst || theU == myLast))
if (!aBspl.IsNull() && (theU == myFirst || theU == myLast))
{ {
if (theU == myFirst) if (theU == myFirst)
{ {
aBspl->LocateU(myFirst, PosTol, theSpanStart, theSpanFinish); myBSplineCurve->LocateU(myFirst, PosTol, theSpanStart, theSpanFinish);
if (theSpanStart < 1) if (theSpanStart < 1)
theSpanStart = 1; theSpanStart = 1;
if (theSpanStart >= theSpanFinish) if (theSpanStart >= theSpanFinish)
@ -605,9 +601,9 @@ Standard_Boolean Geom2dAdaptor_Curve::IsBoundary(const Standard_Real theU,
} }
else if (theU == myLast) else if (theU == myLast)
{ {
aBspl->LocateU(myLast, PosTol, theSpanStart, theSpanFinish); myBSplineCurve->LocateU(myLast, PosTol, theSpanStart, theSpanFinish);
if (theSpanFinish > aBspl->NbKnots()) if (theSpanFinish > myBSplineCurve->NbKnots())
theSpanFinish = aBspl->NbKnots(); theSpanFinish = myBSplineCurve->NbKnots();
if (theSpanStart >= theSpanFinish) if (theSpanStart >= theSpanFinish)
theSpanStart = theSpanFinish - 1; 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; Standard_Integer aStart = 0, aFinish = 0;
if (IsBoundary(U, aStart, aFinish)) if (IsBoundary(U, aStart, aFinish))
{ {
Handle(Geom2d_BSplineCurve) aBspl = Handle(Geom2d_BSplineCurve)::DownCast(myCurve); myBSplineCurve->LocalD0(U, aStart, aFinish, P);
aBspl->LocalD0(U, aStart, aFinish, P);
} }
else if (!myCurveCache.IsNull()) // use cached data 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; Standard_Integer aStart = 0, aFinish = 0;
if (IsBoundary(U, aStart, aFinish)) if (IsBoundary(U, aStart, aFinish))
{ {
Handle(Geom2d_BSplineCurve) aBspl = Handle(Geom2d_BSplineCurve)::DownCast(myCurve); myBSplineCurve->LocalD1(U, aStart, aFinish, P, V);
aBspl->LocalD1(U, aStart, aFinish, P, V);
} }
else if (!myCurveCache.IsNull()) // use cached data 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; Standard_Integer aStart = 0, aFinish = 0;
if (IsBoundary(U, aStart, aFinish)) if (IsBoundary(U, aStart, aFinish))
{ {
Handle(Geom2d_BSplineCurve) aBspl = Handle(Geom2d_BSplineCurve)::DownCast(myCurve); myBSplineCurve->LocalD2(U, aStart, aFinish, P, V1, V2);
aBspl->LocalD2(U, aStart, aFinish, P, V1, V2);
} }
else if (!myCurveCache.IsNull()) // use cached data 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; Standard_Integer aStart = 0, aFinish = 0;
if (IsBoundary(U, aStart, aFinish)) if (IsBoundary(U, aStart, aFinish))
{ {
Handle(Geom2d_BSplineCurve) aBspl = Handle(Geom2d_BSplineCurve)::DownCast(myCurve); myBSplineCurve->LocalD3(U, aStart, aFinish, P, V1, V2, V3);
aBspl->LocalD3(U, aStart, aFinish, P, V1, V2, V3);
} }
else if (!myCurveCache.IsNull()) // use cached data 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; Standard_Integer aStart = 0, aFinish = 0;
if (IsBoundary(U, aStart, aFinish)) if (IsBoundary(U, aStart, aFinish))
{ {
Handle(Geom2d_BSplineCurve) aBspl = Handle(Geom2d_BSplineCurve)::DownCast(myCurve); myBSplineCurve->LocalDN(U, aStart, aFinish, N);
return aBspl->LocalDN(U, aStart, aFinish, N);
} }
else else
return myCurve->DN(U, N); return myCurve->DN(U, N);
@ -923,7 +914,7 @@ Standard_Integer Geom2dAdaptor_Curve::Degree() const
if (myTypeCurve == GeomAbs_BezierCurve) if (myTypeCurve == GeomAbs_BezierCurve)
return Handle(Geom2d_BezierCurve)::DownCast (myCurve)->Degree(); return Handle(Geom2d_BezierCurve)::DownCast (myCurve)->Degree();
else if (myTypeCurve == GeomAbs_BSplineCurve) else if (myTypeCurve == GeomAbs_BSplineCurve)
return Handle(Geom2d_BSplineCurve)::DownCast (myCurve)->Degree(); return myBSplineCurve->Degree();
else else
Standard_NoSuchObject::Raise(); Standard_NoSuchObject::Raise();
// portage WNT // portage WNT
@ -938,7 +929,7 @@ Standard_Integer Geom2dAdaptor_Curve::Degree() const
Standard_Boolean Geom2dAdaptor_Curve::IsRational() const { Standard_Boolean Geom2dAdaptor_Curve::IsRational() const {
switch( myTypeCurve) { switch( myTypeCurve) {
case GeomAbs_BSplineCurve: case GeomAbs_BSplineCurve:
return Handle(Geom2d_BSplineCurve)::DownCast (myCurve)->IsRational(); return myBSplineCurve->IsRational();
case GeomAbs_BezierCurve: case GeomAbs_BezierCurve:
return Handle(Geom2d_BezierCurve)::DownCast (myCurve)->IsRational(); return Handle(Geom2d_BezierCurve)::DownCast (myCurve)->IsRational();
default: default:
@ -956,7 +947,7 @@ Standard_Integer Geom2dAdaptor_Curve::NbPoles() const
if (myTypeCurve == GeomAbs_BezierCurve) if (myTypeCurve == GeomAbs_BezierCurve)
return Handle(Geom2d_BezierCurve)::DownCast (myCurve)->NbPoles(); return Handle(Geom2d_BezierCurve)::DownCast (myCurve)->NbPoles();
else if (myTypeCurve == GeomAbs_BSplineCurve) else if (myTypeCurve == GeomAbs_BSplineCurve)
return Handle(Geom2d_BSplineCurve)::DownCast (myCurve)->NbPoles(); return myBSplineCurve->NbPoles();
else else
Standard_NoSuchObject::Raise(); Standard_NoSuchObject::Raise();
// portage WNT // portage WNT
@ -968,11 +959,11 @@ Standard_Integer Geom2dAdaptor_Curve::NbPoles() const
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Integer Geom2dAdaptor_Curve::NbKnots() const { Standard_Integer Geom2dAdaptor_Curve::NbKnots() const
{
if ( myTypeCurve != GeomAbs_BSplineCurve) if ( myTypeCurve != GeomAbs_BSplineCurve)
Standard_NoSuchObject::Raise("Geom2dAdaptor_Curve::NbKnots"); 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 Handle(Geom2d_BSplineCurve) Geom2dAdaptor_Curve::BSpline() const
{ {
return Handle(Geom2d_BSplineCurve)::DownCast (myCurve); return myBSplineCurve;
} }
static Standard_Integer nbPoints(const Handle(Geom2d_Curve)& theCurve) static Standard_Integer nbPoints(const Handle(Geom2d_Curve)& theCurve)

View File

@ -192,6 +192,8 @@ private:
GeomAbs_CurveType myTypeCurve; GeomAbs_CurveType myTypeCurve;
Standard_Real myFirst; Standard_Real myFirst;
Standard_Real myLast; 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(BSplCLib_Cache) myCurveCache; ///< Cached data for B-spline or Bezier curve
Handle(Geom2dEvaluator_Curve) myNestedEvaluator; ///< Calculates value of offset curve Handle(Geom2dEvaluator_Curve) myNestedEvaluator; ///< Calculates value of offset curve

View File

@ -77,18 +77,17 @@ GeomAbs_Shape GeomAdaptor_Curve::LocalContinuity(const Standard_Real U1,
const const
{ {
Standard_NoSuchObject_Raise_if(myTypeCurve!=GeomAbs_BSplineCurve," "); Standard_NoSuchObject_Raise_if(myTypeCurve!=GeomAbs_BSplineCurve," ");
Handle(Geom_BSplineCurve) aBspl = Handle(Geom_BSplineCurve)::DownCast(myCurve); Standard_Integer Nb = myBSplineCurve->NbKnots();
Standard_Integer Nb = aBspl->NbKnots();
Standard_Integer Index1 = 0; Standard_Integer Index1 = 0;
Standard_Integer Index2 = 0; Standard_Integer Index2 = 0;
Standard_Real newFirst, newLast; Standard_Real newFirst, newLast;
TColStd_Array1OfReal TK(1,Nb); TColStd_Array1OfReal TK(1,Nb);
TColStd_Array1OfInteger TM(1,Nb); TColStd_Array1OfInteger TM(1,Nb);
aBspl->Knots(TK); myBSplineCurve->Knots(TK);
aBspl->Multiplicities(TM); myBSplineCurve->Multiplicities(TM);
BSplCLib::LocateParameter(aBspl->Degree(),TK,TM,U1,aBspl->IsPeriodic(), BSplCLib::LocateParameter(myBSplineCurve->Degree(),TK,TM,U1,myBSplineCurve->IsPeriodic(),
1,Nb,Index1,newFirst); 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); 1,Nb,Index2,newLast);
if ( Abs(newFirst-TK(Index1+1))<Precision::PConfusion()) { if ( Abs(newFirst-TK(Index1+1))<Precision::PConfusion()) {
if (Index1 < Nb) Index1++; if (Index1 < Nb) Index1++;
@ -97,7 +96,7 @@ GeomAbs_Shape GeomAdaptor_Curve::LocalContinuity(const Standard_Real U1,
Index2--; Index2--;
Standard_Integer MultMax; Standard_Integer MultMax;
// attention aux courbes peridiques. // attention aux courbes peridiques.
if ( (aBspl->IsPeriodic()) && (Index1 == Nb) ) if ( (myBSplineCurve->IsPeriodic()) && (Index1 == Nb) )
Index1 = 1; Index1 = 1;
if ( Index2 - Index1 <= 0) { 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++) { for(Standard_Integer i = Index1+1;i<=Index2;i++) {
if ( TM(i)>MultMax) MultMax=TM(i); if ( TM(i)>MultMax) MultMax=TM(i);
} }
MultMax = aBspl->Degree() - MultMax; MultMax = myBSplineCurve->Degree() - MultMax;
} }
if ( MultMax <= 0) { if ( MultMax <= 0) {
return GeomAbs_C0; return GeomAbs_C0;
@ -142,8 +141,9 @@ void GeomAdaptor_Curve::load(const Handle(Geom_Curve)& C,
if ( myCurve != C) { if ( myCurve != C) {
myCurve = C; myCurve = C;
myCurveCache = Handle(BSplCLib_Cache)(); myCurveCache.Nullify();
myNestedEvaluator = Handle(GeomEvaluator_Curve)(); myNestedEvaluator.Nullify();
myBSplineCurve.Nullify();
const Handle(Standard_Type)& TheType = C->DynamicType(); const Handle(Standard_Type)& TheType = C->DynamicType();
if ( TheType == STANDARD_TYPE(Geom_TrimmedCurve)) { if ( TheType == STANDARD_TYPE(Geom_TrimmedCurve)) {
@ -177,6 +177,7 @@ void GeomAdaptor_Curve::load(const Handle(Geom_Curve)& C,
myTypeCurve = GeomAbs_BSplineCurve; myTypeCurve = GeomAbs_BSplineCurve;
// Create cache for B-spline // Create cache for B-spline
Handle(Geom_BSplineCurve) aBspl = Handle(Geom_BSplineCurve)::DownCast(myCurve); Handle(Geom_BSplineCurve) aBspl = Handle(Geom_BSplineCurve)::DownCast(myCurve);
myBSplineCurve = aBspl;
myCurveCache = new BSplCLib_Cache(aBspl->Degree(), aBspl->IsPeriodic(), myCurveCache = new BSplCLib_Cache(aBspl->Degree(), aBspl->IsPeriodic(),
aBspl->KnotSequence(), aBspl->Poles(), aBspl->Weights()); 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 myNbIntervals = 1;
Standard_Integer NbSplit; Standard_Integer NbSplit;
if (myTypeCurve == GeomAbs_BSplineCurve) { if (myTypeCurve == GeomAbs_BSplineCurve) {
Handle(Geom_BSplineCurve) aBspl = Handle(Geom_BSplineCurve)::DownCast(myCurve); Standard_Integer FirstIndex = myBSplineCurve->FirstUKnotIndex();
Standard_Integer FirstIndex = aBspl->FirstUKnotIndex(); Standard_Integer LastIndex = myBSplineCurve->LastUKnotIndex();
Standard_Integer LastIndex = aBspl->LastUKnotIndex();
TColStd_Array1OfInteger Inter (1, LastIndex-FirstIndex+1); TColStd_Array1OfInteger Inter (1, LastIndex-FirstIndex+1);
if ( S > Continuity()) { if ( S > Continuity()) {
Standard_Integer Cont; Standard_Integer Cont;
@ -264,11 +264,11 @@ Standard_Integer GeomAdaptor_Curve::NbIntervals(const GeomAbs_Shape S) const
if ( S == GeomAbs_C1) Cont = 1; if ( S == GeomAbs_C1) Cont = 1;
else if ( S == GeomAbs_C2) Cont = 2; else if ( S == GeomAbs_C2) Cont = 2;
else if ( S == GeomAbs_C3) Cont = 3; else if ( S == GeomAbs_C3) Cont = 3;
else Cont = aBspl->Degree(); else Cont = myBSplineCurve->Degree();
Standard_Integer Degree = aBspl->Degree(); Standard_Integer Degree = myBSplineCurve->Degree();
Standard_Integer NbKnots = aBspl->NbKnots(); Standard_Integer NbKnots = myBSplineCurve->NbKnots();
TColStd_Array1OfInteger Mults (1, NbKnots); TColStd_Array1OfInteger Mults (1, NbKnots);
aBspl->Multiplicities (Mults); myBSplineCurve->Multiplicities (Mults);
NbSplit = 1; NbSplit = 1;
Standard_Integer Index = FirstIndex; Standard_Integer Index = FirstIndex;
Inter (NbSplit) = Index; Inter (NbSplit) = Index;
@ -287,19 +287,19 @@ Standard_Integer GeomAdaptor_Curve::NbIntervals(const GeomAbs_Shape S) const
Standard_Integer NbInt = NbSplit-1; Standard_Integer NbInt = NbSplit-1;
Standard_Integer Nb = aBspl->NbKnots(); Standard_Integer Nb = myBSplineCurve->NbKnots();
Standard_Integer Index1 = 0; Standard_Integer Index1 = 0;
Standard_Integer Index2 = 0; Standard_Integer Index2 = 0;
Standard_Real newFirst, newLast; Standard_Real newFirst, newLast;
TColStd_Array1OfReal TK(1,Nb); TColStd_Array1OfReal TK(1,Nb);
TColStd_Array1OfInteger TM(1,Nb); TColStd_Array1OfInteger TM(1,Nb);
aBspl->Knots(TK); myBSplineCurve->Knots(TK);
aBspl->Multiplicities(TM); myBSplineCurve->Multiplicities(TM);
BSplCLib::LocateParameter(aBspl->Degree(),TK,TM,myFirst, BSplCLib::LocateParameter(myBSplineCurve->Degree(),TK,TM,myFirst,
aBspl->IsPeriodic(), myBSplineCurve->IsPeriodic(),
1,Nb,Index1,newFirst); 1,Nb,Index1,newFirst);
BSplCLib::LocateParameter(aBspl->Degree(),TK,TM,myLast, BSplCLib::LocateParameter(myBSplineCurve->Degree(),TK,TM,myLast,
aBspl->IsPeriodic(), myBSplineCurve->IsPeriodic(),
1,Nb,Index2,newLast); 1,Nb,Index2,newLast);
// On decale eventuellement les indices // On decale eventuellement les indices
@ -364,9 +364,8 @@ void GeomAdaptor_Curve::Intervals(TColStd_Array1OfReal& T,
if (myTypeCurve == GeomAbs_BSplineCurve) if (myTypeCurve == GeomAbs_BSplineCurve)
{ {
Handle(Geom_BSplineCurve) aBspl = Handle(Geom_BSplineCurve)::DownCast(myCurve); Standard_Integer FirstIndex = myBSplineCurve->FirstUKnotIndex();
Standard_Integer FirstIndex = aBspl->FirstUKnotIndex(); Standard_Integer LastIndex = myBSplineCurve->LastUKnotIndex();
Standard_Integer LastIndex = aBspl->LastUKnotIndex();
TColStd_Array1OfInteger Inter (1, LastIndex-FirstIndex+1); TColStd_Array1OfInteger Inter (1, LastIndex-FirstIndex+1);
if ( S > Continuity()) { if ( S > Continuity()) {
@ -387,11 +386,11 @@ void GeomAdaptor_Curve::Intervals(TColStd_Array1OfReal& T,
if ( S == GeomAbs_C1) Cont = 1; if ( S == GeomAbs_C1) Cont = 1;
else if ( S == GeomAbs_C2) Cont = 2; else if ( S == GeomAbs_C2) Cont = 2;
else if ( S == GeomAbs_C3) Cont = 3; else if ( S == GeomAbs_C3) Cont = 3;
else Cont = aBspl->Degree(); else Cont = myBSplineCurve->Degree();
Standard_Integer Degree = aBspl->Degree(); Standard_Integer Degree = myBSplineCurve->Degree();
Standard_Integer NbKnots = aBspl->NbKnots(); Standard_Integer NbKnots = myBSplineCurve->NbKnots();
TColStd_Array1OfInteger Mults (1, NbKnots); TColStd_Array1OfInteger Mults (1, NbKnots);
aBspl->Multiplicities (Mults); myBSplineCurve->Multiplicities (Mults);
NbSplit = 1; NbSplit = 1;
Standard_Integer Index = FirstIndex; Standard_Integer Index = FirstIndex;
Inter (NbSplit) = Index; Inter (NbSplit) = Index;
@ -413,19 +412,19 @@ void GeomAdaptor_Curve::Intervals(TColStd_Array1OfReal& T,
// TColStd_Array1OfInteger Inter(1,NbInt+1); // TColStd_Array1OfInteger Inter(1,NbInt+1);
// Convector.Splitting( Inter); // Convector.Splitting( Inter);
Standard_Integer Nb = aBspl->NbKnots(); Standard_Integer Nb = myBSplineCurve->NbKnots();
Standard_Integer Index1 = 0; Standard_Integer Index1 = 0;
Standard_Integer Index2 = 0; Standard_Integer Index2 = 0;
Standard_Real newFirst, newLast; Standard_Real newFirst, newLast;
TColStd_Array1OfReal TK(1,Nb); TColStd_Array1OfReal TK(1,Nb);
TColStd_Array1OfInteger TM(1,Nb); TColStd_Array1OfInteger TM(1,Nb);
aBspl->Knots(TK); myBSplineCurve->Knots(TK);
aBspl->Multiplicities(TM); myBSplineCurve->Multiplicities(TM);
BSplCLib::LocateParameter(aBspl->Degree(),TK,TM,myFirst, BSplCLib::LocateParameter(myBSplineCurve->Degree(),TK,TM,myFirst,
aBspl->IsPeriodic(), myBSplineCurve->IsPeriodic(),
1,Nb,Index1,newFirst); 1,Nb,Index1,newFirst);
BSplCLib::LocateParameter(aBspl->Degree(),TK,TM,myLast, BSplCLib::LocateParameter(myBSplineCurve->Degree(),TK,TM,myLast,
aBspl->IsPeriodic(), myBSplineCurve->IsPeriodic(),
1,Nb,Index2,newLast); 1,Nb,Index2,newLast);
FirstParam = newFirst; FirstParam = newFirst;
LastParam = newLast; LastParam = newLast;
@ -557,10 +556,9 @@ void GeomAdaptor_Curve::RebuildCache(const Standard_Real theParameter) const
} }
else if (myTypeCurve == GeomAbs_BSplineCurve) else if (myTypeCurve == GeomAbs_BSplineCurve)
{ {
Handle(Geom_BSplineCurve) aBspl = Handle(Geom_BSplineCurve)::DownCast(myCurve); myCurveCache->BuildCache(theParameter, myBSplineCurve->Degree(),
myCurveCache->BuildCache(theParameter, aBspl->Degree(), myBSplineCurve->IsPeriodic(), myBSplineCurve->KnotSequence(),
aBspl->IsPeriodic(), aBspl->KnotSequence(), myBSplineCurve->Poles(), myBSplineCurve->Weights());
aBspl->Poles(), aBspl->Weights());
} }
} }
@ -572,12 +570,11 @@ Standard_Boolean GeomAdaptor_Curve::IsBoundary(const Standard_Real theU,
Standard_Integer& theSpanStart, Standard_Integer& theSpanStart,
Standard_Integer& theSpanFinish) const Standard_Integer& theSpanFinish) const
{ {
Handle(Geom_BSplineCurve) aBspl = Handle(Geom_BSplineCurve)::DownCast(myCurve); if (!myBSplineCurve.IsNull() && (theU == myFirst || theU == myLast))
if (!aBspl.IsNull() && (theU == myFirst || theU == myLast))
{ {
if (theU == myFirst) if (theU == myFirst)
{ {
aBspl->LocateU(myFirst, PosTol, theSpanStart, theSpanFinish); myBSplineCurve->LocateU(myFirst, PosTol, theSpanStart, theSpanFinish);
if (theSpanStart < 1) if (theSpanStart < 1)
theSpanStart = 1; theSpanStart = 1;
if (theSpanStart >= theSpanFinish) if (theSpanStart >= theSpanFinish)
@ -585,9 +582,9 @@ Standard_Boolean GeomAdaptor_Curve::IsBoundary(const Standard_Real theU,
} }
else if (theU == myLast) else if (theU == myLast)
{ {
aBspl->LocateU(myLast, PosTol, theSpanStart, theSpanFinish); myBSplineCurve->LocateU(myLast, PosTol, theSpanStart, theSpanFinish);
if (theSpanFinish > aBspl->NbKnots()) if (theSpanFinish > myBSplineCurve->NbKnots())
theSpanFinish = aBspl->NbKnots(); theSpanFinish = myBSplineCurve->NbKnots();
if (theSpanStart >= theSpanFinish) if (theSpanStart >= theSpanFinish)
theSpanStart = theSpanFinish - 1; 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; Standard_Integer aStart = 0, aFinish = 0;
if (IsBoundary(U, aStart, aFinish)) if (IsBoundary(U, aStart, aFinish))
{ {
Handle(Geom_BSplineCurve) aBspl = Handle(Geom_BSplineCurve)::DownCast(myCurve); myBSplineCurve->LocalD0(U, aStart, aFinish, P);
aBspl->LocalD0(U, aStart, aFinish, P);
} }
else if (!myCurveCache.IsNull()) // use cached data 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; Standard_Integer aStart = 0, aFinish = 0;
if (IsBoundary(U, aStart, aFinish)) if (IsBoundary(U, aStart, aFinish))
{ {
Handle(Geom_BSplineCurve) aBspl = Handle(Geom_BSplineCurve)::DownCast(myCurve); myBSplineCurve->LocalD1(U, aStart, aFinish, P, V);
aBspl->LocalD1(U, aStart, aFinish, P, V);
} }
else if (!myCurveCache.IsNull()) // use cached data 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; Standard_Integer aStart = 0, aFinish = 0;
if (IsBoundary(U, aStart, aFinish)) if (IsBoundary(U, aStart, aFinish))
{ {
Handle(Geom_BSplineCurve) aBspl = Handle(Geom_BSplineCurve)::DownCast(myCurve); myBSplineCurve->LocalD2(U, aStart, aFinish, P, V1, V2);
aBspl->LocalD2(U, aStart, aFinish, P, V1, V2);
} }
else if (!myCurveCache.IsNull()) // use cached data 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; Standard_Integer aStart = 0, aFinish = 0;
if (IsBoundary(U, aStart, aFinish)) if (IsBoundary(U, aStart, aFinish))
{ {
Handle(Geom_BSplineCurve) aBspl = Handle(Geom_BSplineCurve)::DownCast(myCurve); myBSplineCurve->LocalD3(U, aStart, aFinish, P, V1, V2, V3);
aBspl->LocalD3(U, aStart, aFinish, P, V1, V2, V3);
} }
else if (!myCurveCache.IsNull()) // use cached data 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; Standard_Integer aStart = 0, aFinish = 0;
if (IsBoundary(U, aStart, aFinish)) if (IsBoundary(U, aStart, aFinish))
{ {
Handle(Geom_BSplineCurve) aBspl = Handle(Geom_BSplineCurve)::DownCast(myCurve); return myBSplineCurve->LocalDN(U, aStart, aFinish, N);
return aBspl->LocalDN(U, aStart, aFinish, N);
} }
else else
return myCurve->DN(U, N); return myCurve->DN(U, N);
@ -824,7 +816,7 @@ Standard_Real GeomAdaptor_Curve::Resolution(const Standard_Real R3D) const
} }
case GeomAbs_BSplineCurve: { case GeomAbs_BSplineCurve: {
Standard_Real res; Standard_Real res;
Handle(Geom_BSplineCurve)::DownCast (myCurve)->Resolution(R3D,res); myBSplineCurve->Resolution(R3D,res);
return res; return res;
} }
default: default:
@ -903,7 +895,7 @@ Standard_Integer GeomAdaptor_Curve::Degree() const
if (myTypeCurve == GeomAbs_BezierCurve) if (myTypeCurve == GeomAbs_BezierCurve)
return Handle(Geom_BezierCurve)::DownCast (myCurve)->Degree(); return Handle(Geom_BezierCurve)::DownCast (myCurve)->Degree();
else if (myTypeCurve == GeomAbs_BSplineCurve) else if (myTypeCurve == GeomAbs_BSplineCurve)
return Handle(Geom_BSplineCurve)::DownCast (myCurve)->Degree(); return myBSplineCurve->Degree();
else else
Standard_NoSuchObject::Raise(); Standard_NoSuchObject::Raise();
// portage WNT // portage WNT
@ -918,7 +910,7 @@ Standard_Integer GeomAdaptor_Curve::Degree() const
Standard_Boolean GeomAdaptor_Curve::IsRational() const { Standard_Boolean GeomAdaptor_Curve::IsRational() const {
switch( myTypeCurve) { switch( myTypeCurve) {
case GeomAbs_BSplineCurve: case GeomAbs_BSplineCurve:
return Handle(Geom_BSplineCurve)::DownCast (myCurve)->IsRational(); return myBSplineCurve->IsRational();
case GeomAbs_BezierCurve: case GeomAbs_BezierCurve:
return Handle(Geom_BezierCurve)::DownCast (myCurve)->IsRational(); return Handle(Geom_BezierCurve)::DownCast (myCurve)->IsRational();
default: default:
@ -936,7 +928,7 @@ Standard_Integer GeomAdaptor_Curve::NbPoles() const
if (myTypeCurve == GeomAbs_BezierCurve) if (myTypeCurve == GeomAbs_BezierCurve)
return Handle(Geom_BezierCurve)::DownCast (myCurve)->NbPoles(); return Handle(Geom_BezierCurve)::DownCast (myCurve)->NbPoles();
else if (myTypeCurve == GeomAbs_BSplineCurve) else if (myTypeCurve == GeomAbs_BSplineCurve)
return Handle(Geom_BSplineCurve)::DownCast (myCurve)->NbPoles(); return myBSplineCurve->NbPoles();
else else
Standard_NoSuchObject::Raise(); Standard_NoSuchObject::Raise();
// portage WNT // portage WNT
@ -952,7 +944,7 @@ Standard_Integer GeomAdaptor_Curve::NbKnots() const
{ {
if ( myTypeCurve != GeomAbs_BSplineCurve) if ( myTypeCurve != GeomAbs_BSplineCurve)
Standard_NoSuchObject::Raise("GeomAdaptor_Curve::NbKnots"); 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) if ( myTypeCurve != GeomAbs_BSplineCurve)
Standard_NoSuchObject::Raise("GeomAdaptor_Curve::BSpline"); Standard_NoSuchObject::Raise("GeomAdaptor_Curve::BSpline");
return Handle(Geom_BSplineCurve)::DownCast (myCurve); return myBSplineCurve;
} }

View File

@ -231,6 +231,8 @@ private:
GeomAbs_CurveType myTypeCurve; GeomAbs_CurveType myTypeCurve;
Standard_Real myFirst; Standard_Real myFirst;
Standard_Real myLast; 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(BSplCLib_Cache) myCurveCache; ///< Cached data for B-spline or Bezier curve
Handle(GeomEvaluator_Curve) myNestedEvaluator; ///< Calculates value of offset curve Handle(GeomEvaluator_Curve) myNestedEvaluator; ///< Calculates value of offset curve

View File

@ -135,8 +135,9 @@ void GeomAdaptor_Surface::load(const Handle(Geom_Surface)& S,
if ( mySurface != S) { if ( mySurface != S) {
mySurface = S; mySurface = S;
mySurfaceCache = Handle(BSplSLib_Cache)(); mySurfaceCache.Nullify();
myNestedEvaluator = Handle(GeomEvaluator_Surface)(); myNestedEvaluator.Nullify();
myBSplineSurface.Nullify();
const Handle(Standard_Type)& TheType = S->DynamicType(); const Handle(Standard_Type)& TheType = S->DynamicType();
if (TheType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) { 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)) { else if (TheType == STANDARD_TYPE(Geom_BSplineSurface)) {
mySurfaceType = GeomAbs_BSplineSurface; mySurfaceType = GeomAbs_BSplineSurface;
Handle(Geom_BSplineSurface) myBspl = Handle(Geom_BSplineSurface)::DownCast(mySurface); Handle(Geom_BSplineSurface) myBspl = Handle(Geom_BSplineSurface)::DownCast(mySurface);
myBSplineSurface = myBspl;
// Create cache for B-spline // Create cache for B-spline
mySurfaceCache = new BSplSLib_Cache( mySurfaceCache = new BSplSLib_Cache(
myBspl->UDegree(), myBspl->IsUPeriodic(), myBspl->UKnotSequence(), myBspl->UDegree(), myBspl->IsUPeriodic(), myBspl->UKnotSequence(),
@ -233,13 +235,12 @@ GeomAbs_Shape GeomAdaptor_Surface::UContinuity() const
{ {
case GeomAbs_BSplineSurface: case GeomAbs_BSplineSurface:
{ {
Handle(Geom_BSplineSurface) myBspl = Handle(Geom_BSplineSurface)::DownCast(mySurface); const Standard_Integer N = myBSplineSurface->NbUKnots();
const Standard_Integer N = myBspl->NbUKnots();
TColStd_Array1OfReal TK(1,N); TColStd_Array1OfReal TK(1,N);
TColStd_Array1OfInteger TM(1,N); TColStd_Array1OfInteger TM(1,N);
myBspl->UKnots(TK); myBSplineSurface->UKnots(TK);
myBspl->UMultiplicities(TM); myBSplineSurface->UMultiplicities(TM);
return LocalContinuity(myBspl->UDegree(), myBspl->NbUKnots(), TK, TM, return LocalContinuity(myBSplineSurface->UDegree(), myBSplineSurface->NbUKnots(), TK, TM,
myUFirst, myULast, IsUPeriodic()); myUFirst, myULast, IsUPeriodic());
} }
case GeomAbs_OffsetSurface: case GeomAbs_OffsetSurface:
@ -288,13 +289,12 @@ GeomAbs_Shape GeomAdaptor_Surface::VContinuity() const
{ {
case GeomAbs_BSplineSurface: case GeomAbs_BSplineSurface:
{ {
Handle(Geom_BSplineSurface) myBspl = Handle(Geom_BSplineSurface)::DownCast(mySurface); const Standard_Integer N = myBSplineSurface->NbVKnots();
const Standard_Integer N = myBspl->NbVKnots();
TColStd_Array1OfReal TK(1,N); TColStd_Array1OfReal TK(1,N);
TColStd_Array1OfInteger TM(1,N); TColStd_Array1OfInteger TM(1,N);
myBspl->VKnots(TK); myBSplineSurface->VKnots(TK);
myBspl->VMultiplicities(TM); myBSplineSurface->VMultiplicities(TM);
return LocalContinuity(myBspl->VDegree(), myBspl->NbVKnots(), TK, TM, return LocalContinuity(myBSplineSurface->VDegree(), myBSplineSurface->NbVKnots(), TK, TM,
myVFirst, myVLast, IsVPeriodic()); myVFirst, myVLast, IsVPeriodic());
} }
case GeomAbs_OffsetSurface: case GeomAbs_OffsetSurface:
@ -343,9 +343,8 @@ Standard_Integer GeomAdaptor_Surface::NbUIntervals(const GeomAbs_Shape S) const
{ {
case GeomAbs_BSplineSurface: case GeomAbs_BSplineSurface:
{ {
Handle(Geom_BSplineSurface) myBspl = Handle(Geom_BSplineSurface)::DownCast(mySurface);
GeomAdaptor_Curve myBasisCurve GeomAdaptor_Curve myBasisCurve
(myBspl->VIso(myBspl->VKnot(myBspl->FirstVKnotIndex())),myUFirst,myULast); (myBSplineSurface->VIso(myBSplineSurface->VKnot(myBSplineSurface->FirstVKnotIndex())),myUFirst,myULast);
return myBasisCurve.NbIntervals(S); return myBasisCurve.NbIntervals(S);
} }
case GeomAbs_SurfaceOfExtrusion: case GeomAbs_SurfaceOfExtrusion:
@ -397,9 +396,8 @@ Standard_Integer GeomAdaptor_Surface::NbVIntervals(const GeomAbs_Shape S) const
{ {
case GeomAbs_BSplineSurface: case GeomAbs_BSplineSurface:
{ {
Handle(Geom_BSplineSurface) myBspl = Handle(Geom_BSplineSurface)::DownCast(mySurface);
GeomAdaptor_Curve myBasisCurve GeomAdaptor_Curve myBasisCurve
(myBspl->UIso(myBspl->UKnot(myBspl->FirstUKnotIndex())),myVFirst,myVLast); (myBSplineSurface->UIso(myBSplineSurface->UKnot(myBSplineSurface->FirstUKnotIndex())),myVFirst,myVLast);
return myBasisCurve.NbIntervals(S); return myBasisCurve.NbIntervals(S);
} }
case GeomAbs_SurfaceOfRevolution: case GeomAbs_SurfaceOfRevolution:
@ -453,9 +451,8 @@ void GeomAdaptor_Surface::UIntervals(TColStd_Array1OfReal& T, const GeomAbs_Shap
{ {
case GeomAbs_BSplineSurface: case GeomAbs_BSplineSurface:
{ {
Handle(Geom_BSplineSurface) myBspl = Handle(Geom_BSplineSurface)::DownCast(mySurface);
GeomAdaptor_Curve myBasisCurve GeomAdaptor_Curve myBasisCurve
(myBspl->VIso(myBspl->VKnot(myBspl->FirstVKnotIndex())),myUFirst,myULast); (myBSplineSurface->VIso(myBSplineSurface->VKnot(myBSplineSurface->FirstVKnotIndex())),myUFirst,myULast);
myNbUIntervals = myBasisCurve.NbIntervals(S); myNbUIntervals = myBasisCurve.NbIntervals(S);
myBasisCurve.Intervals(T,S); myBasisCurve.Intervals(T,S);
break; break;
@ -516,9 +513,8 @@ void GeomAdaptor_Surface::VIntervals(TColStd_Array1OfReal& T, const GeomAbs_Shap
{ {
case GeomAbs_BSplineSurface: case GeomAbs_BSplineSurface:
{ {
Handle(Geom_BSplineSurface) myBspl = Handle(Geom_BSplineSurface)::DownCast(mySurface);
GeomAdaptor_Curve myBasisCurve GeomAdaptor_Curve myBasisCurve
(myBspl->UIso(myBspl->UKnot(myBspl->FirstUKnotIndex())),myVFirst,myVLast); (myBSplineSurface->UIso(myBSplineSurface->UKnot(myBSplineSurface->FirstUKnotIndex())),myVFirst,myVLast);
myNbVIntervals = myBasisCurve.NbIntervals(S); myNbVIntervals = myBasisCurve.NbIntervals(S);
myBasisCurve.Intervals(T,S); myBasisCurve.Intervals(T,S);
break; break;
@ -694,11 +690,10 @@ void GeomAdaptor_Surface::RebuildCache(const Standard_Real theU,
} }
else if (mySurfaceType == GeomAbs_BSplineSurface) else if (mySurfaceType == GeomAbs_BSplineSurface)
{ {
Handle(Geom_BSplineSurface) myBspl = Handle(Geom_BSplineSurface)::DownCast(mySurface);
mySurfaceCache->BuildCache(theU, theV, mySurfaceCache->BuildCache(theU, theV,
myBspl->UDegree(), myBspl->IsUPeriodic(), myBspl->UKnotSequence(), myBSplineSurface->UDegree(), myBSplineSurface->IsUPeriodic(), myBSplineSurface->UKnotSequence(),
myBspl->VDegree(), myBspl->IsVPeriodic(), myBspl->VKnotSequence(), myBSplineSurface->VDegree(), myBSplineSurface->IsVPeriodic(), myBSplineSurface->VKnotSequence(),
myBspl->Poles(), myBspl->Weights()); myBSplineSurface->Poles(), myBSplineSurface->Weights());
} }
} }
@ -772,11 +767,10 @@ void GeomAdaptor_Surface::D1(const Standard_Real U,
switch(mySurfaceType) { switch(mySurfaceType) {
case GeomAbs_BezierSurface: case GeomAbs_BezierSurface:
case GeomAbs_BSplineSurface: { case GeomAbs_BSplineSurface: {
Handle(Geom_BSplineSurface) myBspl = Handle(Geom_BSplineSurface)::DownCast(mySurface); if (!myBSplineSurface.IsNull() &&
if (!myBspl.IsNull() &&
(USide != 0 || VSide != 0) && (USide != 0 || VSide != 0) &&
IfUVBound(u, v, Ideb, Ifin, IVdeb, IVfin, USide, VSide)) 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()) else if (!mySurfaceCache.IsNull())
{ {
if (!mySurfaceCache->IsCacheValid(U, V)) if (!mySurfaceCache->IsCacheValid(U, V))
@ -825,11 +819,10 @@ void GeomAdaptor_Surface::D2(const Standard_Real U,
switch(mySurfaceType) { switch(mySurfaceType) {
case GeomAbs_BezierSurface: case GeomAbs_BezierSurface:
case GeomAbs_BSplineSurface: { case GeomAbs_BSplineSurface: {
Handle(Geom_BSplineSurface) myBspl = Handle(Geom_BSplineSurface)::DownCast(mySurface); if (!myBSplineSurface.IsNull() &&
if (!myBspl.IsNull() &&
(USide != 0 || VSide != 0) && (USide != 0 || VSide != 0) &&
IfUVBound(u, v, Ideb, Ifin, IVdeb, IVfin, USide, VSide)) 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()) else if (!mySurfaceCache.IsNull())
{ {
if (!mySurfaceCache->IsCacheValid(U, V)) if (!mySurfaceCache->IsCacheValid(U, V))
@ -875,15 +868,14 @@ void GeomAdaptor_Surface::D3(const Standard_Real U, const Standard_Real V,
switch(mySurfaceType) { switch(mySurfaceType) {
case GeomAbs_BSplineSurface: { case GeomAbs_BSplineSurface: {
Handle(Geom_BSplineSurface) myBspl = Handle(Geom_BSplineSurface)::DownCast(mySurface);
if ((USide == 0) && (VSide == 0)) 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 { else {
if (IfUVBound(u, v, Ideb, Ifin, IVdeb, IVfin, USide, VSide)) 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); P, D1U, D1V, D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV);
else 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; break;
} }
@ -921,14 +913,13 @@ gp_Vec GeomAdaptor_Surface::DN(const Standard_Real U,
switch(mySurfaceType) switch(mySurfaceType)
{ {
case GeomAbs_BSplineSurface: { case GeomAbs_BSplineSurface: {
Handle(Geom_BSplineSurface) myBspl = Handle(Geom_BSplineSurface)::DownCast(mySurface);
if ((USide == 0) && (VSide == 0)) if ((USide == 0) && (VSide == 0))
return myBspl->DN(u, v, Nu, Nv); return myBSplineSurface->DN(u, v, Nu, Nv);
else { else {
if (IfUVBound(u, v, Ideb, Ifin, IVdeb, IVfin, USide, VSide)) 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 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); (Handle(Geom_SurfaceOfLinearExtrusion)::DownCast (mySurface)->BasisCurve(),myUFirst,myULast);
return myBasisCurve.Resolution(R3d); return myBasisCurve.Resolution(R3d);
} }
case GeomAbs_Torus: case GeomAbs_Torus:
{ {
Handle(Geom_ToroidalSurface) S (Handle(Geom_ToroidalSurface)::DownCast (mySurface)); Handle(Geom_ToroidalSurface) S (Handle(Geom_ToroidalSurface)::DownCast (mySurface));
const Standard_Real R = S->MajorRadius() + S->MinorRadius(); 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); Res = R3d/(2.*R);
break; break;
} }
case GeomAbs_Sphere: case GeomAbs_Sphere:
{ {
Handle(Geom_SphericalSurface) S (Handle(Geom_SphericalSurface)::DownCast (mySurface)); Handle(Geom_SphericalSurface) S (Handle(Geom_SphericalSurface)::DownCast (mySurface));
const Standard_Real R = S->Radius(); const Standard_Real R = S->Radius();
@ -987,7 +978,7 @@ Standard_Real GeomAdaptor_Surface::UResolution(const Standard_Real R3d) const
Res = R3d/(2.*R); Res = R3d/(2.*R);
break; break;
} }
case GeomAbs_Cylinder: case GeomAbs_Cylinder:
{ {
Handle(Geom_CylindricalSurface) S (Handle(Geom_CylindricalSurface)::DownCast (mySurface)); Handle(Geom_CylindricalSurface) S (Handle(Geom_CylindricalSurface)::DownCast (mySurface));
const Standard_Real R = S->Radius(); const Standard_Real R = S->Radius();
@ -995,7 +986,7 @@ Standard_Real GeomAdaptor_Surface::UResolution(const Standard_Real R3d) const
Res = R3d/(2.*R); Res = R3d/(2.*R);
break; break;
} }
case GeomAbs_Cone: case GeomAbs_Cone:
{ {
if (myVLast - myVFirst > 1.e10) { if (myVLast - myVFirst > 1.e10) {
// Pas vraiment borne => resolution inconnue // 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(); const Standard_Real Rayon1 = Handle(Geom_Circle)::DownCast (C)->Radius();
C = S->VIso(myVFirst); C = S->VIso(myVFirst);
const Standard_Real Rayon2 = Handle(Geom_Circle)::DownCast (C)->Radius(); const Standard_Real Rayon2 = Handle(Geom_Circle)::DownCast (C)->Radius();
const Standard_Real R = (Rayon1 > Rayon2)? Rayon1 : Rayon2; const Standard_Real R = (Rayon1 > Rayon2)? Rayon1 : Rayon2;
return (R>Precision::Confusion()? (R3d / R) : 0.); return (R>Precision::Confusion()? (R3d / R) : 0.);
} }
case GeomAbs_Plane: case GeomAbs_Plane:
{ {
return R3d; return R3d;
} }
case GeomAbs_BezierSurface: case GeomAbs_BezierSurface:
{ {
Standard_Real Ures,Vres; Standard_Real Ures,Vres;
Handle(Geom_BezierSurface)::DownCast (mySurface)->Resolution(R3d,Ures,Vres); Handle(Geom_BezierSurface)::DownCast (mySurface)->Resolution(R3d,Ures,Vres);
return Ures; return Ures;
} }
case GeomAbs_BSplineSurface: case GeomAbs_BSplineSurface:
{ {
Standard_Real Ures,Vres; Standard_Real Ures,Vres;
Handle(Geom_BSplineSurface)::DownCast (mySurface)->Resolution(R3d,Ures,Vres); myBSplineSurface->Resolution(R3d,Ures,Vres);
return Ures; return Ures;
} }
case GeomAbs_OffsetSurface: case GeomAbs_OffsetSurface:
{ {
Handle(Geom_Surface) base = Handle(Geom_OffsetSurface)::DownCast (mySurface)->BasisSurface(); Handle(Geom_Surface) base = Handle(Geom_OffsetSurface)::DownCast (mySurface)->BasisSurface();
GeomAdaptor_Surface gabase(base,myUFirst,myULast,myVFirst,myVLast); GeomAdaptor_Surface gabase(base,myUFirst,myULast,myVFirst,myVLast);
return gabase.UResolution(R3d); return gabase.UResolution(R3d);
} }
default: return Precision::Parametric(R3d); default: return Precision::Parametric(R3d);
} }
if ( Res <= 1.) 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); (Handle(Geom_SurfaceOfRevolution)::DownCast (mySurface)->BasisCurve(),myUFirst,myULast);
return myBasisCurve.Resolution(R3d); return myBasisCurve.Resolution(R3d);
} }
case GeomAbs_Torus: case GeomAbs_Torus:
{ {
Handle(Geom_ToroidalSurface) S (Handle(Geom_ToroidalSurface)::DownCast (mySurface)); Handle(Geom_ToroidalSurface) S (Handle(Geom_ToroidalSurface)::DownCast (mySurface));
const Standard_Real R = S->MinorRadius(); const Standard_Real R = S->MinorRadius();
@ -1065,7 +1056,7 @@ Standard_Real GeomAdaptor_Surface::VResolution(const Standard_Real R3d) const
Res = R3d/(2.*R); Res = R3d/(2.*R);
break; break;
} }
case GeomAbs_Sphere: case GeomAbs_Sphere:
{ {
Handle(Geom_SphericalSurface) S (Handle(Geom_SphericalSurface)::DownCast (mySurface)); Handle(Geom_SphericalSurface) S (Handle(Geom_SphericalSurface)::DownCast (mySurface));
const Standard_Real R = S->Radius(); const Standard_Real R = S->Radius();
@ -1073,32 +1064,32 @@ Standard_Real GeomAdaptor_Surface::VResolution(const Standard_Real R3d) const
Res = R3d/(2.*R); Res = R3d/(2.*R);
break; break;
} }
case GeomAbs_SurfaceOfExtrusion: case GeomAbs_SurfaceOfExtrusion:
case GeomAbs_Cylinder: case GeomAbs_Cylinder:
case GeomAbs_Cone: case GeomAbs_Cone:
case GeomAbs_Plane: case GeomAbs_Plane:
{ {
return R3d; return R3d;
} }
case GeomAbs_BezierSurface: case GeomAbs_BezierSurface:
{ {
Standard_Real Ures,Vres; Standard_Real Ures,Vres;
Handle(Geom_BezierSurface)::DownCast (mySurface)->Resolution(R3d,Ures,Vres); Handle(Geom_BezierSurface)::DownCast (mySurface)->Resolution(R3d,Ures,Vres);
return Vres; return Vres;
} }
case GeomAbs_BSplineSurface: case GeomAbs_BSplineSurface:
{ {
Standard_Real Ures,Vres; Standard_Real Ures,Vres;
Handle(Geom_BSplineSurface)::DownCast (mySurface)->Resolution(R3d,Ures,Vres); myBSplineSurface->Resolution(R3d,Ures,Vres);
return Vres; return Vres;
} }
case GeomAbs_OffsetSurface: case GeomAbs_OffsetSurface:
{ {
Handle(Geom_Surface) base = Handle(Geom_OffsetSurface)::DownCast (mySurface)->BasisSurface(); Handle(Geom_Surface) base = Handle(Geom_OffsetSurface)::DownCast (mySurface)->BasisSurface();
GeomAdaptor_Surface gabase(base,myUFirst,myULast,myVFirst,myVLast); GeomAdaptor_Surface gabase(base,myUFirst,myULast,myVFirst,myVLast);
return gabase.VResolution(R3d); return gabase.VResolution(R3d);
} }
default: return Precision::Parametric(R3d); default: return Precision::Parametric(R3d);
} }
if ( Res <= 1.) if ( Res <= 1.)
@ -1175,7 +1166,7 @@ gp_Torus GeomAdaptor_Surface::Torus() const
Standard_Integer GeomAdaptor_Surface::UDegree() const Standard_Integer GeomAdaptor_Surface::UDegree() const
{ {
if (mySurfaceType == GeomAbs_BSplineSurface) if (mySurfaceType == GeomAbs_BSplineSurface)
return Handle(Geom_BSplineSurface)::DownCast (mySurface)->UDegree(); return myBSplineSurface->UDegree();
if ( mySurfaceType == GeomAbs_BezierSurface) if ( mySurfaceType == GeomAbs_BezierSurface)
return Handle(Geom_BezierSurface)::DownCast (mySurface)->UDegree(); return Handle(Geom_BezierSurface)::DownCast (mySurface)->UDegree();
if ( mySurfaceType == GeomAbs_SurfaceOfExtrusion) if ( mySurfaceType == GeomAbs_SurfaceOfExtrusion)
@ -1196,7 +1187,7 @@ Standard_Integer GeomAdaptor_Surface::UDegree() const
Standard_Integer GeomAdaptor_Surface::NbUPoles() const Standard_Integer GeomAdaptor_Surface::NbUPoles() const
{ {
if (mySurfaceType == GeomAbs_BSplineSurface) if (mySurfaceType == GeomAbs_BSplineSurface)
return Handle(Geom_BSplineSurface)::DownCast (mySurface)->NbUPoles(); return myBSplineSurface->NbUPoles();
if ( mySurfaceType == GeomAbs_BezierSurface) if ( mySurfaceType == GeomAbs_BezierSurface)
return Handle(Geom_BezierSurface)::DownCast (mySurface)->NbUPoles(); return Handle(Geom_BezierSurface)::DownCast (mySurface)->NbUPoles();
if ( mySurfaceType == GeomAbs_SurfaceOfExtrusion) if ( mySurfaceType == GeomAbs_SurfaceOfExtrusion)
@ -1217,7 +1208,7 @@ Standard_Integer GeomAdaptor_Surface::NbUPoles() const
Standard_Integer GeomAdaptor_Surface::VDegree() const Standard_Integer GeomAdaptor_Surface::VDegree() const
{ {
if (mySurfaceType == GeomAbs_BSplineSurface) if (mySurfaceType == GeomAbs_BSplineSurface)
return Handle(Geom_BSplineSurface)::DownCast (mySurface)->VDegree(); return myBSplineSurface->VDegree();
if ( mySurfaceType == GeomAbs_BezierSurface) if ( mySurfaceType == GeomAbs_BezierSurface)
return Handle(Geom_BezierSurface)::DownCast (mySurface)->VDegree(); return Handle(Geom_BezierSurface)::DownCast (mySurface)->VDegree();
if ( mySurfaceType == GeomAbs_SurfaceOfRevolution) if ( mySurfaceType == GeomAbs_SurfaceOfRevolution)
@ -1238,7 +1229,7 @@ Standard_Integer GeomAdaptor_Surface::VDegree() const
Standard_Integer GeomAdaptor_Surface::NbVPoles() const Standard_Integer GeomAdaptor_Surface::NbVPoles() const
{ {
if (mySurfaceType == GeomAbs_BSplineSurface) if (mySurfaceType == GeomAbs_BSplineSurface)
return Handle(Geom_BSplineSurface)::DownCast (mySurface)->NbVPoles(); return myBSplineSurface->NbVPoles();
if ( mySurfaceType == GeomAbs_BezierSurface) if ( mySurfaceType == GeomAbs_BezierSurface)
return Handle(Geom_BezierSurface)::DownCast (mySurface)->NbVPoles(); return Handle(Geom_BezierSurface)::DownCast (mySurface)->NbVPoles();
if ( mySurfaceType == GeomAbs_SurfaceOfRevolution) if ( mySurfaceType == GeomAbs_SurfaceOfRevolution)
@ -1259,7 +1250,7 @@ Standard_Integer GeomAdaptor_Surface::NbVPoles() const
Standard_Integer GeomAdaptor_Surface::NbUKnots() const Standard_Integer GeomAdaptor_Surface::NbUKnots() const
{ {
if (mySurfaceType == GeomAbs_BSplineSurface) if (mySurfaceType == GeomAbs_BSplineSurface)
return Handle(Geom_BSplineSurface)::DownCast (mySurface)->NbUKnots(); return myBSplineSurface->NbUKnots();
if ( mySurfaceType == GeomAbs_SurfaceOfExtrusion) if ( mySurfaceType == GeomAbs_SurfaceOfExtrusion)
{ {
GeomAdaptor_Curve myBasisCurve GeomAdaptor_Curve myBasisCurve
@ -1278,7 +1269,7 @@ Standard_Integer GeomAdaptor_Surface::NbUKnots() const
Standard_Integer GeomAdaptor_Surface::NbVKnots() const Standard_Integer GeomAdaptor_Surface::NbVKnots() const
{ {
if (mySurfaceType == GeomAbs_BSplineSurface) if (mySurfaceType == GeomAbs_BSplineSurface)
return Handle(Geom_BSplineSurface)::DownCast (mySurface)->NbVKnots(); return myBSplineSurface->NbVKnots();
Standard_NoSuchObject::Raise("GeomAdaptor_Surface::NbVKnots"); Standard_NoSuchObject::Raise("GeomAdaptor_Surface::NbVKnots");
return 0; return 0;
} }
@ -1290,7 +1281,7 @@ Standard_Integer GeomAdaptor_Surface::NbVKnots() const
Standard_Boolean GeomAdaptor_Surface::IsURational() const Standard_Boolean GeomAdaptor_Surface::IsURational() const
{ {
if (mySurfaceType == GeomAbs_BSplineSurface) if (mySurfaceType == GeomAbs_BSplineSurface)
return Handle(Geom_BSplineSurface)::DownCast (mySurface)->IsURational(); return myBSplineSurface->IsURational();
if (mySurfaceType == GeomAbs_BezierSurface) if (mySurfaceType == GeomAbs_BezierSurface)
return Handle(Geom_BezierSurface)::DownCast (mySurface)->IsURational(); return Handle(Geom_BezierSurface)::DownCast (mySurface)->IsURational();
return Standard_False; return Standard_False;
@ -1304,7 +1295,7 @@ Standard_Boolean GeomAdaptor_Surface::IsURational() const
Standard_Boolean GeomAdaptor_Surface::IsVRational() const Standard_Boolean GeomAdaptor_Surface::IsVRational() const
{ {
if (mySurfaceType == GeomAbs_BSplineSurface) if (mySurfaceType == GeomAbs_BSplineSurface)
return Handle(Geom_BSplineSurface)::DownCast (mySurface)->IsVRational(); return myBSplineSurface->IsVRational();
if (mySurfaceType == GeomAbs_BezierSurface) if (mySurfaceType == GeomAbs_BezierSurface)
return Handle(Geom_BezierSurface)::DownCast (mySurface)->IsVRational(); return Handle(Geom_BezierSurface)::DownCast (mySurface)->IsVRational();
return Standard_False; return Standard_False;
@ -1331,7 +1322,7 @@ Handle(Geom_BSplineSurface) GeomAdaptor_Surface::BSpline() const
{ {
if (mySurfaceType != GeomAbs_BSplineSurface) if (mySurfaceType != GeomAbs_BSplineSurface)
Standard_NoSuchObject::Raise("GeomAdaptor_Surface::BSpline"); 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 const Standard_Integer VSide) const
{ {
Standard_Integer Ideb,Ifin; Standard_Integer Ideb,Ifin;
Handle(Geom_BSplineSurface) myBspl = Handle(Geom_BSplineSurface)::DownCast(mySurface); Standard_Integer anUFKIndx = myBSplineSurface->FirstUKnotIndex(),
Standard_Integer anUFKIndx = myBspl->FirstUKnotIndex(), anULKIndx = myBSplineSurface->LastUKnotIndex(),
anULKIndx = myBspl->LastUKnotIndex(), aVFKIndx = myBSplineSurface->FirstVKnotIndex(), aVLKIndx = myBSplineSurface->LastVKnotIndex();
aVFKIndx = myBspl->FirstVKnotIndex(), aVLKIndx = myBspl->LastVKnotIndex(); myBSplineSurface->LocateU(U, PosTol, Ideb, Ifin, Standard_False);
myBspl->LocateU(U, PosTol, Ideb, Ifin, Standard_False);
Standard_Boolean Local = (Ideb == Ifin); Standard_Boolean Local = (Ideb == Ifin);
Span(USide,Ideb,Ifin,Ideb,Ifin,anUFKIndx,anULKIndx); Span(USide,Ideb,Ifin,Ideb,Ifin,anUFKIndx,anULKIndx);
Standard_Integer IVdeb,IVfin; 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; if(IVdeb == IVfin) Local = Standard_True;
Span(VSide,IVdeb,IVfin,IVdeb,IVfin,aVFKIndx,aVLKIndx); Span(VSide,IVdeb,IVfin,IVdeb,IVfin,aVFKIndx,aVLKIndx);

View File

@ -266,6 +266,8 @@ private:
Standard_Real myVLast; Standard_Real myVLast;
Standard_Real myTolU; Standard_Real myTolU;
Standard_Real myTolV; 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 Handle(BSplSLib_Cache) mySurfaceCache; ///< Cached data for B-spline or Bezier surface
protected: protected: