1 // Copyright (c) 2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #ifndef _BSplCLib_Cache_Headerfile
15 #define _BSplCLib_Cache_Headerfile
17 #include <Standard.hxx>
18 #include <Standard_Macro.hxx>
19 #include <Standard_DefineHandle.hxx>
20 #include <Standard_Transient.hxx>
22 #include <Handle_TColStd_HArray1OfReal.hxx>
23 #include <Handle_TColStd_HArray2OfReal.hxx>
25 #include <gp_Pnt2d.hxx>
27 #include <gp_Vec2d.hxx>
30 class Handle(BSplCLib_Cache);
31 class TColStd_Array1OfReal;
32 class TColgp_Array1OfPnt;
33 class TColgp_Array1OfPnt2d;
35 #ifndef NOWEIGHTS_CURVE
36 #define NOWEIGHTS_CURVE (*((TColStd_Array1OfReal*) NULL))
39 //! \brief A cache class for B-spline curves.
41 //! Defines all data, that can be cached on a span of B-spline curve.
42 //! The data should be recalculated in going from span to span.
43 class BSplCLib_Cache : public Standard_Transient
46 //! Default constructor
47 Standard_EXPORT BSplCLib_Cache();
48 //! Constructor for caching of 2D curves
49 //! \param theDegree degree of the B-spline
50 //! \param thePeriodic identify the B-spline is periodic
51 //! \param theFlatKnots knots of B-spline curve (with repetitions)
52 //! \param thePoles2d array of poles of 2D B-spline
53 //! \param theWeights array of weights of corresponding poles
54 Standard_EXPORT BSplCLib_Cache(const Standard_Integer& theDegree,
55 const Standard_Boolean& thePeriodic,
56 const TColStd_Array1OfReal& theFlatKnots,
57 const TColgp_Array1OfPnt2d& thePoles2d,
58 const TColStd_Array1OfReal& theWeights = NOWEIGHTS_CURVE);
59 //! Constructor for caching of 3D curves
60 //! \param theDegree degree of the B-spline
61 //! \param thePeriodic identify the B-spline is periodic
62 //! \param theFlatKnots knots of B-spline curve (with repetitions)
63 //! \param thePoles array of poles of 3D B-spline
64 //! \param theWeights array of weights of corresponding poles
65 Standard_EXPORT BSplCLib_Cache(const Standard_Integer& theDegree,
66 const Standard_Boolean& thePeriodic,
67 const TColStd_Array1OfReal& theFlatKnots,
68 const TColgp_Array1OfPnt& thePoles,
69 const TColStd_Array1OfReal& theWeights = NOWEIGHTS_CURVE);
71 //! Verifies validity of the cache using flat parameter of the point
72 //! \param theParameter parameter of the point placed in the span
73 Standard_EXPORT Standard_Boolean IsCacheValid(Standard_Real theParameter) const;
75 //! Recomputes the cache data for 2D curves. Does not verify validity of the cache
76 //! \param theParameter the value on the knot's axis to identify the span
77 //! \param theDegree degree of the B-spline
78 //! \param thePeriodic identify the B-spline is periodic
79 //! \param theFlatKnots knots of B-spline curve (with repetitions)
80 //! \param thePoles2d array of poles of 2D B-spline
81 //! \param theWeights array of weights of corresponding poles
82 Standard_EXPORT void BuildCache(const Standard_Real& theParameter,
83 const Standard_Integer& theDegree,
84 const Standard_Boolean& thePeriodic,
85 const TColStd_Array1OfReal& theFlatKnots,
86 const TColgp_Array1OfPnt2d& thePoles2d,
87 const TColStd_Array1OfReal& theWeights = NOWEIGHTS_CURVE);
88 //! Recomputes the cache data for 3D curves. Does not verify validity of the cache
89 //! \param theParameter the value on the knot's axis to identify the span
90 //! \param theDegree degree of the B-spline
91 //! \param thePeriodic identify the B-spline is periodic
92 //! \param theFlatKnots knots of B-spline curve (with repetitions)
93 //! \param thePoles array of poles of 3D B-spline
94 //! \param theWeights array of weights of corresponding poles
95 Standard_EXPORT void BuildCache(const Standard_Real& theParameter,
96 const Standard_Integer& theDegree,
97 const Standard_Boolean& thePeriodic,
98 const TColStd_Array1OfReal& theFlatKnots,
99 const TColgp_Array1OfPnt& thePoles,
100 const TColStd_Array1OfReal& theWeights = NOWEIGHTS_CURVE);
102 //! Calculates the point on B-spline in the selected point
103 //! \param[in] theParameter parameter of calculation of the value
104 //! \param[out] thePoint the result of calculation (the point on B-spline)
105 Standard_EXPORT void D0(const Standard_Real& theParameter, gp_Pnt2d& thePoint) const;
106 Standard_EXPORT void D0(const Standard_Real& theParameter, gp_Pnt& thePoint) const;
108 //! Calculates the point on B-spline and its first derivative in the selected point
109 //! \param[in] theParameter parameter of calculation of the value
110 //! \param[out] thePoint the result of calculation (the point on B-spline)
111 //! \param[out] theTangent tangent vector (first derivatives) for B-spline in the calculated point
112 Standard_EXPORT void D1(const Standard_Real& theParameter, gp_Pnt2d& thePoint, gp_Vec2d& theTangent) const;
113 Standard_EXPORT void D1(const Standard_Real& theParameter, gp_Pnt& thePoint, gp_Vec& theTangent) const;
115 //! Calculates the point on B-spline and two derivatives in the selected point
116 //! \param[in] theParameter parameter of calculation of the value
117 //! \param[out] thePoint the result of calculation (the point on B-spline)
118 //! \param[out] theTangent tangent vector (1st derivatives) for B-spline in the calculated point
119 //! \param[out] theCurvature curvature vector (2nd derivatives) for B-spline in the calculated point
120 Standard_EXPORT void D2(const Standard_Real& theParameter,
122 gp_Vec2d& theTangent,
123 gp_Vec2d& theCurvature) const;
124 Standard_EXPORT void D2(const Standard_Real& theParameter,
127 gp_Vec& theCurvature) const;
129 //! Calculates the point on B-spline and three derivatives in the selected point
130 //! \param[in] theParameter parameter of calculation of the value
131 //! \param[out] thePoint the result of calculation (the point on B-spline)
132 //! \param[out] theTangent tangent vector (1st derivatives) for B-spline in the calculated point
133 //! \param[out] theCurvature curvature vector (2nd derivatives) for B-spline in the calculated point
134 //! \param[out] theTorsion second curvature vector (3rd derivatives) for B-spline in the calculated point
135 Standard_EXPORT void D3(const Standard_Real& theParameter,
137 gp_Vec2d& theTangent,
138 gp_Vec2d& theCurvature,
139 gp_Vec2d& theTorsion) const;
140 Standard_EXPORT void D3(const Standard_Real& theParameter,
143 gp_Vec& theCurvature,
144 gp_Vec& theTorsion) const;
147 DEFINE_STANDARD_RTTI(BSplCLib_Cache)
150 //! Normalizes the parameter for periodical B-splines
151 //! \param theFlatKnots knots with repetitions
152 //! \param theParameter the value to be normalized into the knots array
153 void PeriodicNormalization(const TColStd_Array1OfReal& theFlatKnots, Standard_Real& theParameter) const;
155 //! Fills array of derivatives in the selected point of the B-spline
156 //! \param[in] theParameter parameter of the calculation
157 //! \param[in] theDerivative maximal derivative to be calculated (computes all derivatives lesser than specified)
158 //! \param[out] theDerivArray result array of derivatives (with size (theDerivative+1)*(PntDim+1),
159 //! where PntDim = 2 or 3 is a dimension of B-spline curve)
160 void CalculateDerivative(const Standard_Real& theParameter,
161 const Standard_Integer& theDerivative,
162 Standard_Real& theDerivArray) const;
165 Handle(TColStd_HArray2OfReal) myPolesWeights; ///< array of poles and weights of calculated cache
166 // the array has following structure:
168 // x2 y2 [z2] [w2] etc
169 // for 2D-curves there is no z conponent, for non-rational curves there is no weight
171 Standard_Boolean myIsRational; ///< identifies the rationality of B-spline
172 Standard_Real mySpanStart; ///< parameter for the first point of the span
173 Standard_Real mySpanLength; ///< length of the span
174 Standard_Integer mySpanIndex; ///< index of the span on B-spline curve
175 Standard_Integer mySpanIndexMax; ///< maximal number of spans on B-spline curve
176 Standard_Integer myDegree; ///< degree of B-spline
177 Handle(TColStd_HArray1OfReal) myFlatKnots; ///< knots of B-spline (used for periodic normalization of parameters, exists only for periodical splines)
180 DEFINE_STANDARD_HANDLE(BSplCLib_Cache, Standard_Transient)