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_Type.hxx>
20 #include <Standard_Transient.hxx>
23 #include <gp_Pnt2d.hxx>
25 #include <gp_Vec2d.hxx>
28 #include <TColStd_HArray2OfReal.hxx>
29 #include <TColStd_HArray1OfReal.hxx>
30 #include <TColStd_Array1OfReal.hxx>
31 #include <TColgp_Array1OfPnt.hxx>
32 #include <TColgp_Array1OfPnt2d.hxx>
34 //! \brief A cache class for Bezier and B-spline curves.
36 //! Defines all data, that can be cached on a span of a curve.
37 //! The data should be recalculated in going from span to span.
38 class BSplCLib_Cache : public Standard_Transient
41 //! Default constructor
42 Standard_EXPORT BSplCLib_Cache();
43 //! Constructor for caching of 2D curves
44 //! \param theDegree degree of the curve
45 //! \param thePeriodic identify the curve is periodic
46 //! \param theFlatKnots knots of Bezier/B-spline curve (with repetitions)
47 //! \param thePoles2d array of poles of 2D curve
48 //! \param theWeights array of weights of corresponding poles
49 Standard_EXPORT BSplCLib_Cache(const Standard_Integer& theDegree,
50 const Standard_Boolean& thePeriodic,
51 const TColStd_Array1OfReal& theFlatKnots,
52 const TColgp_Array1OfPnt2d& thePoles2d,
53 const TColStd_Array1OfReal* theWeights = NULL);
54 //! Constructor for caching of 3D curves
55 //! \param theDegree degree of the curve
56 //! \param thePeriodic identify the curve is periodic
57 //! \param theFlatKnots knots of Bezier/B-spline curve (with repetitions)
58 //! \param thePoles array of poles of 3D curve
59 //! \param theWeights array of weights of corresponding poles
60 Standard_EXPORT BSplCLib_Cache(const Standard_Integer& theDegree,
61 const Standard_Boolean& thePeriodic,
62 const TColStd_Array1OfReal& theFlatKnots,
63 const TColgp_Array1OfPnt& thePoles,
64 const TColStd_Array1OfReal* theWeights = NULL);
66 //! Verifies validity of the cache using flat parameter of the point
67 //! \param theParameter parameter of the point placed in the span
68 Standard_EXPORT Standard_Boolean IsCacheValid(Standard_Real theParameter) const;
70 //! Recomputes the cache data for 2D curves. Does not verify validity of the cache
71 //! \param theParameter the value on the knot's axis to identify the span
72 //! \param theDegree degree of the curve
73 //! \param thePeriodic identify the curve is periodic
74 //! \param theFlatKnots knots of Bezier/B-spline curve (with repetitions)
75 //! \param thePoles2d array of poles of 2D curve
76 //! \param theWeights array of weights of corresponding poles
77 Standard_EXPORT void BuildCache(const Standard_Real& theParameter,
78 const Standard_Integer& theDegree,
79 const Standard_Boolean& thePeriodic,
80 const TColStd_Array1OfReal& theFlatKnots,
81 const TColgp_Array1OfPnt2d& thePoles2d,
82 const TColStd_Array1OfReal* theWeights = NULL);
83 //! Recomputes the cache data for 3D curves. Does not verify validity of the cache
84 //! \param theParameter the value on the knot's axis to identify the span
85 //! \param theDegree degree of the curve
86 //! \param thePeriodic identify the curve is periodic
87 //! \param theFlatKnots knots of Bezier/B-spline curve (with repetitions)
88 //! \param thePoles array of poles of 3D curve
89 //! \param theWeights array of weights of corresponding poles
90 Standard_EXPORT void BuildCache(const Standard_Real& theParameter,
91 const Standard_Integer& theDegree,
92 const Standard_Boolean& thePeriodic,
93 const TColStd_Array1OfReal& theFlatKnots,
94 const TColgp_Array1OfPnt& thePoles,
95 const TColStd_Array1OfReal* theWeights = NULL);
97 //! Calculates the point on the curve in the specified parameter
98 //! \param[in] theParameter parameter of calculation of the value
99 //! \param[out] thePoint the result of calculation (the point on the curve)
100 Standard_EXPORT void D0(const Standard_Real& theParameter, gp_Pnt2d& thePoint) const;
101 Standard_EXPORT void D0(const Standard_Real& theParameter, gp_Pnt& thePoint) const;
103 //! Calculates the point on the curve and its first derivative in the specified parameter
104 //! \param[in] theParameter parameter of calculation of the value
105 //! \param[out] thePoint the result of calculation (the point on the curve)
106 //! \param[out] theTangent tangent vector (first derivatives) for the curve in the calculated point
107 Standard_EXPORT void D1(const Standard_Real& theParameter, gp_Pnt2d& thePoint, gp_Vec2d& theTangent) const;
108 Standard_EXPORT void D1(const Standard_Real& theParameter, gp_Pnt& thePoint, gp_Vec& theTangent) const;
110 //! Calculates the point on the curve and two derivatives in the specified parameter
111 //! \param[in] theParameter parameter of calculation of the value
112 //! \param[out] thePoint the result of calculation (the point on the curve)
113 //! \param[out] theTangent tangent vector (1st derivatives) for the curve in the calculated point
114 //! \param[out] theCurvature curvature vector (2nd derivatives) for the curve in the calculated point
115 Standard_EXPORT void D2(const Standard_Real& theParameter,
117 gp_Vec2d& theTangent,
118 gp_Vec2d& theCurvature) const;
119 Standard_EXPORT void D2(const Standard_Real& theParameter,
122 gp_Vec& theCurvature) const;
124 //! Calculates the point on the curve and three derivatives in the specified parameter
125 //! \param[in] theParameter parameter of calculation of the value
126 //! \param[out] thePoint the result of calculation (the point on the curve)
127 //! \param[out] theTangent tangent vector (1st derivatives) for the curve in the calculated point
128 //! \param[out] theCurvature curvature vector (2nd derivatives) for the curve in the calculated point
129 //! \param[out] theTorsion second curvature vector (3rd derivatives) for the curve in the calculated point
130 Standard_EXPORT void D3(const Standard_Real& theParameter,
132 gp_Vec2d& theTangent,
133 gp_Vec2d& theCurvature,
134 gp_Vec2d& theTorsion) const;
135 Standard_EXPORT void D3(const Standard_Real& theParameter,
138 gp_Vec& theCurvature,
139 gp_Vec& theTorsion) const;
142 DEFINE_STANDARD_RTTIEXT(BSplCLib_Cache,Standard_Transient)
145 //! Normalizes the parameter for periodical curves
146 //! \param theFlatKnots knots with repetitions
147 //! \param theParameter the value to be normalized into the knots array
148 void PeriodicNormalization(const TColStd_Array1OfReal& theFlatKnots, Standard_Real& theParameter) const;
150 //! Fills array of derivatives in the selected point of the curve
151 //! \param[in] theParameter parameter of the calculation
152 //! \param[in] theDerivative maximal derivative to be calculated (computes all derivatives lesser than specified)
153 //! \param[out] theDerivArray result array of derivatives (with size (theDerivative+1)*(PntDim+1),
154 //! where PntDim = 2 or 3 is a dimension of the curve)
155 void CalculateDerivative(const Standard_Real& theParameter,
156 const Standard_Integer& theDerivative,
157 Standard_Real& theDerivArray) const;
160 Handle(TColStd_HArray2OfReal) myPolesWeights; ///< array of poles and weights of calculated cache
161 // the array has following structure:
163 // x2 y2 [z2] [w2] etc
164 // for 2D-curves there is no z conponent, for non-rational curves there is no weight
166 Standard_Boolean myIsRational; ///< identifies the rationality of Bezier/B-spline curve
167 Standard_Real mySpanStart; ///< parameter for the first point of the span
168 Standard_Real mySpanLength; ///< length of the span
169 Standard_Integer mySpanIndex; ///< index of the span on Bezier/B-spline curve
170 Standard_Integer mySpanIndexMin; ///< minimal index of span on Bezier/B-spline curve
171 Standard_Integer mySpanIndexMax; ///< maximal number of spans on Bezier/B-spline curve
172 Standard_Integer myDegree; ///< degree of Bezier/B-spline
173 Handle(TColStd_HArray1OfReal) myFlatKnots; ///< knots of Bezier/B-spline (used for periodic normalization of parameters, exists only for periodical splines)
176 DEFINE_STANDARD_HANDLE(BSplCLib_Cache, Standard_Transient)