1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

0023620: Follow up of 0022939 - make Bezier curve/surface evaluation thread-safe

1. Remove cache from Geom_BezierCurve, Geom2d_BezierCurve and Geom_BezierSurface
2. Add cache for Bezier curves into GeomAdaptor_Curve, Geom2dAdaptor_Curve and GeomAdaptor_Surface
3. Update comments in corresponding cache classes
4. Avoid frequent down-casting to B-splines in adaptors
This commit is contained in:
azv
2015-11-02 09:33:04 +03:00
committed by bugmaster
parent 525ec87c53
commit c8b5b3d89e
11 changed files with 555 additions and 883 deletions

View File

@@ -28,7 +28,6 @@
#define No_Standard_DimensionError
#include <BSplCLib.hxx>
#include <Geom2d_BezierCurve.hxx>
#include <Geom2d_Geometry.hxx>
#include <gp.hxx>
@@ -67,8 +66,7 @@ static Standard_Boolean Rational(const TColStd_Array1OfReal& W)
//=======================================================================
Geom2d_BezierCurve::Geom2d_BezierCurve
(const TColgp_Array1OfPnt2d& Poles):
validcache(0), parametercache(0.), spanlenghtcache(1.)
(const TColgp_Array1OfPnt2d& Poles)
{
// copy the poles
@@ -89,9 +87,8 @@ Geom2d_BezierCurve::Geom2d_BezierCurve
//=======================================================================
Geom2d_BezierCurve::Geom2d_BezierCurve
(const TColgp_Array1OfPnt2d& Poles,
const TColStd_Array1OfReal& Weights):
validcache(0), parametercache(0.), spanlenghtcache(1.)
(const TColgp_Array1OfPnt2d& Poles,
const TColStd_Array1OfReal& Weights)
{
// copy the poles
@@ -346,8 +343,6 @@ void Geom2d_BezierCurve::Reverse ()
cweights(nbpoles-i+1) = w;
}
}
UpdateCoefficients();
}
@@ -376,18 +371,21 @@ void Geom2d_BezierCurve::Segment
// WARNING : when calling trimming be carefull that the cache
// is computed regarding 0.0e0 and not 1.0e0
//
TColStd_Array1OfReal bidflatknots(BSplCLib::FlatBezierKnots(Degree()), 1, 2 * (Degree() + 1));
TColgp_Array1OfPnt2d coeffs(1, poles->Size());
if (IsRational()) {
PLib::Trimming(U1,U2,coeffs->ChangeArray1(),&wcoeffs->ChangeArray1());
PLib::CoefficientsPoles(coeffs->Array1(),&wcoeffs->Array1(),
poles->ChangeArray1(),&weights->ChangeArray1());
TColStd_Array1OfReal wcoeffs(1, poles->Size());
BSplCLib::BuildCache(0.0, 1.0, 0, Degree(), bidflatknots,
poles->Array1(), &weights->Array1(), coeffs, &wcoeffs);
PLib::Trimming(U1, U2, coeffs, &wcoeffs);
PLib::CoefficientsPoles(coeffs, &wcoeffs, poles->ChangeArray1(), &weights->ChangeArray1());
}
else {
PLib::Trimming(U1,U2,coeffs->ChangeArray1(), PLib::NoWeights());
PLib::CoefficientsPoles(coeffs->Array1(), PLib::NoWeights(),
poles->ChangeArray1(), PLib::NoWeights());
BSplCLib::BuildCache(0.0, 1.0, 0, Degree(), bidflatknots,
poles->Array1(), BSplCLib::NoWeights(), coeffs, BSplCLib::NoWeights());
PLib::Trimming(U1, U2, coeffs, PLib::NoWeights());
PLib::CoefficientsPoles(coeffs, PLib::NoWeights(), poles->ChangeArray1(), PLib::NoWeights());
}
UpdateCoefficients();
}
@@ -409,8 +407,6 @@ void Geom2d_BezierCurve::SetPole
if (Index == 1 || Index == cpoles.Length()) {
closed = (cpoles(1).Distance(cpoles(NbPoles())) <= gp::Resolution());
}
UpdateCoefficients();
}
@@ -456,7 +452,6 @@ void Geom2d_BezierCurve::SetWeight
// set weights of 1.
weights = new TColStd_HArray1OfReal(1,nbpoles);
wcoeffs = new TColStd_HArray1OfReal(1,nbpoles);
weights->Init(1.);
}
@@ -464,14 +459,8 @@ void Geom2d_BezierCurve::SetWeight
cweights(Index) = Weight;
// is it turning into non rational
if (wasrat) {
if (!Rational(cweights)) {
weights.Nullify();
wcoeffs.Nullify();
}
}
UpdateCoefficients();
if (wasrat && !Rational(cweights))
weights.Nullify();
}
@@ -548,16 +537,7 @@ Standard_Integer Geom2d_BezierCurve::Degree () const
void Geom2d_BezierCurve::D0 (const Standard_Real U, gp_Pnt2d& P ) const
{
// Idee lumineuse sacrifiee sur l autel des performances.
//
// if(!CoefficientsOK(U))
// ((Geom2d_BezierCurve*)(void*)this)->UpdateCoefficients(U);
if (IsRational())
BSplCLib::CacheD0(U,Degree(),parametercache,spanlenghtcache,
coeffs->Array1(),&wcoeffs->Array1(),P);
else
BSplCLib::CacheD0(U,Degree(),parametercache,spanlenghtcache,
coeffs->Array1(), BSplCLib::NoWeights(), P);
BSplCLib::D0(U, Poles(), Weights(), P);
}
//=======================================================================
@@ -569,16 +549,7 @@ void Geom2d_BezierCurve::D1(const Standard_Real U,
gp_Pnt2d& P,
gp_Vec2d& V1) const
{
// Idee lumineuse sacrifiee sur l autel des performances.
//
// if(!CoefficientsOK(U))
// ((Geom2d_BezierCurve*)(void*)this)->UpdateCoefficients(U);
if (IsRational())
BSplCLib::CacheD1(U,Degree(),parametercache,spanlenghtcache,
coeffs->Array1(),&wcoeffs->Array1(),P,V1);
else
BSplCLib::CacheD1(U,Degree(),parametercache,spanlenghtcache,
coeffs->Array1(), BSplCLib::NoWeights(), P,V1);
BSplCLib::D1(U, Poles(), Weights(), P, V1);
}
//=======================================================================
@@ -591,16 +562,7 @@ void Geom2d_BezierCurve::D2 (const Standard_Real U,
gp_Vec2d& V1,
gp_Vec2d& V2) const
{
// Idee lumineuse sacrifiee sur l autel des performances.
//
// if(!CoefficientsOK(U))
// ((Geom2d_BezierCurve*)(void*)this)->UpdateCoefficients(U);
if (IsRational())
BSplCLib::CacheD2(U,Degree(),parametercache,spanlenghtcache,
coeffs->Array1(),&wcoeffs->Array1(),P,V1,V2);
else
BSplCLib::CacheD2(U,Degree(),parametercache,spanlenghtcache,
coeffs->Array1(), BSplCLib::NoWeights(), P,V1,V2);
BSplCLib::D2(U, Poles(), Weights(), P, V1, V2);
}
//=======================================================================
@@ -614,16 +576,7 @@ void Geom2d_BezierCurve::D3 (const Standard_Real U,
gp_Vec2d& V2,
gp_Vec2d& V3) const
{
// Idee lumineuse sacrifiee sur l autel des performances.
//
// if(!CoefficientsOK(U))
// ((Geom2d_BezierCurve*)(void*)this)->UpdateCoefficients(U);
if (IsRational())
BSplCLib::CacheD3(U,Degree(),parametercache,spanlenghtcache,
coeffs->Array1(),&wcoeffs->Array1(),P,V1,V2,V3);
else
BSplCLib::CacheD3(U,Degree(),parametercache,spanlenghtcache,
coeffs->Array1(), BSplCLib::NoWeights(), P,V1,V2,V3);
BSplCLib::D3(U, Poles(), Weights(), P, V1, V2, V3);
}
//=======================================================================
@@ -784,8 +737,6 @@ void Geom2d_BezierCurve::Transform (const gp_Trsf2d& T)
for (Standard_Integer i = 1; i <= nbpoles; i++)
cpoles (i).Transform(T);
UpdateCoefficients();
}
@@ -862,60 +813,10 @@ void Geom2d_BezierCurve::Init
rational = !Weights.IsNull();
// set fields
poles = Poles;
coeffs = new TColgp_HArray1OfPnt2d (1,nbpoles);
if (rational) {
poles = Poles;
if (rational)
weights = Weights;
wcoeffs = new TColStd_HArray1OfReal (1, nbpoles, 0.0);
}
else {
weights.Nullify();
wcoeffs.Nullify();
}
UpdateCoefficients();
}
//=======================================================================
//function : CoefficientsOK
//purpose :
//=======================================================================
//Standard_Boolean Geom2d_BezierCurve::CoefficientsOK(const Standard_Real U)const
Standard_Boolean Geom2d_BezierCurve::CoefficientsOK(const Standard_Real )const
{
return (validcache) ;
}
//=======================================================================
//function : UpdateCoefficients
//purpose :
//=======================================================================
//void Geom2d_BezierCurve::UpdateCoefficients(const Standard_Real U)
void Geom2d_BezierCurve::UpdateCoefficients(const Standard_Real )
{
maxderivinvok = 0;
parametercache = 0.;
//
// Idee lumineuse sacrifiee sur l autel des performances.
// if (U >= 1.) parametercache = 1.;
TColStd_Array1OfReal bidflatknots(BSplCLib::FlatBezierKnots(Degree()),
1, 2*(Degree()+1));
if (IsRational())
BSplCLib::BuildCache(parametercache,spanlenghtcache,0,Degree(),
bidflatknots,poles->Array1(),&weights->Array1(),
coeffs->ChangeArray1(),&wcoeffs->ChangeArray1());
else
BSplCLib::BuildCache(parametercache,spanlenghtcache,0,Degree(),
bidflatknots,poles->Array1(),
BSplCLib::NoWeights(),
coeffs->ChangeArray1(),
BSplCLib::NoWeights());
validcache = 1;
weights.Nullify();
}

View File

@@ -29,6 +29,8 @@
#include <TColgp_Array1OfPnt2d.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <GeomAbs_Shape.hxx>
#include <BSplCLib.hxx>
class Standard_ConstructionError;
class Standard_DimensionError;
class Standard_RangeError;
@@ -271,6 +273,11 @@ public:
//! Raised if the length of P is not equal to the number of poles.
Standard_EXPORT void Poles (TColgp_Array1OfPnt2d& P) const;
//! Returns all the poles of the curve.
const TColgp_Array1OfPnt2d& Poles() const
{
return poles->Array1();
}
//! Returns Value (U=1), it is the first control point
//! of the curve.
@@ -284,7 +291,15 @@ public:
//!
//! Raised if the length of W is not equal to the number of poles.
Standard_EXPORT void Weights (TColStd_Array1OfReal& W) const;
//! Returns all the weights of the curve.
const TColStd_Array1OfReal* Weights() const
{
if (!weights.IsNull())
return &weights->Array1();
return BSplCLib::NoWeights();
}
//! Applies the transformation T to this Bezier curve.
Standard_EXPORT void Transform (const gp_Trsf2d& T) Standard_OVERRIDE;
@@ -327,25 +342,13 @@ private:
//! Update rational and closed.
//!
//! if nbpoles < 2 or nbboles > MaDegree + 1
Standard_EXPORT void Init (const Handle(TColgp_HArray1OfPnt2d)& Poles, const Handle(TColStd_HArray1OfReal)& Weights);
//! returns true if the coefficients have been
//! computed with the right value of cacheparameter
//! for the given U value.
Standard_EXPORT Standard_Boolean CoefficientsOK (const Standard_Real U) const;
//! Recompute the coeficients.
Standard_EXPORT void UpdateCoefficients (const Standard_Real U = 0.0);
void Init (const Handle(TColgp_HArray1OfPnt2d)& Poles, const Handle(TColStd_HArray1OfReal)& Weights);
Standard_Boolean rational;
Standard_Boolean closed;
Handle(TColgp_HArray1OfPnt2d) poles;
Handle(TColStd_HArray1OfReal) weights;
Handle(TColgp_HArray1OfPnt2d) coeffs;
Handle(TColStd_HArray1OfReal) wcoeffs;
Standard_Integer validcache;
Standard_Real parametercache;
Standard_Real spanlenghtcache;
Standard_Real maxderivinv;
Standard_Boolean maxderivinvok;