94f71cad |
1 | // Copyright (c) 2014 OPEN CASCADE SAS |
2 | // |
3 | // This file is part of Open CASCADE Technology software library. |
4 | // |
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. |
10 | // |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
13 | |
14 | #ifndef _BSplCLib_Cache_Headerfile |
15 | #define _BSplCLib_Cache_Headerfile |
16 | |
17 | #include <Standard.hxx> |
18 | #include <Standard_Macro.hxx> |
ec357c5c |
19 | #include <Standard_Type.hxx> |
94f71cad |
20 | #include <Standard_Transient.hxx> |
21 | |
94f71cad |
22 | |
23 | #include <gp_Pnt2d.hxx> |
24 | #include <gp_Pnt.hxx> |
25 | #include <gp_Vec2d.hxx> |
26 | #include <gp_Vec.hxx> |
27 | |
b7c077b9 |
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> |
94f71cad |
33 | |
c8b5b3d8 |
34 | //! \brief A cache class for Bezier and B-spline curves. |
94f71cad |
35 | //! |
c8b5b3d8 |
36 | //! Defines all data, that can be cached on a span of a curve. |
94f71cad |
37 | //! The data should be recalculated in going from span to span. |
38 | class BSplCLib_Cache : public Standard_Transient |
39 | { |
40 | public: |
41 | //! Default constructor |
42 | Standard_EXPORT BSplCLib_Cache(); |
43 | //! Constructor for caching of 2D curves |
c8b5b3d8 |
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 |
94f71cad |
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, |
0e14656b |
53 | const TColStd_Array1OfReal* theWeights = NULL); |
94f71cad |
54 | //! Constructor for caching of 3D curves |
c8b5b3d8 |
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 |
94f71cad |
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, |
0e14656b |
64 | const TColStd_Array1OfReal* theWeights = NULL); |
94f71cad |
65 | |
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; |
69 | |
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 |
c8b5b3d8 |
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 |
94f71cad |
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, |
0e14656b |
82 | const TColStd_Array1OfReal* theWeights = NULL); |
94f71cad |
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 |
c8b5b3d8 |
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 |
94f71cad |
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, |
0e14656b |
95 | const TColStd_Array1OfReal* theWeights = NULL); |
94f71cad |
96 | |
c8b5b3d8 |
97 | //! Calculates the point on the curve in the specified parameter |
94f71cad |
98 | //! \param[in] theParameter parameter of calculation of the value |
c8b5b3d8 |
99 | //! \param[out] thePoint the result of calculation (the point on the curve) |
94f71cad |
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; |
102 | |
c8b5b3d8 |
103 | //! Calculates the point on the curve and its first derivative in the specified parameter |
94f71cad |
104 | //! \param[in] theParameter parameter of calculation of the value |
c8b5b3d8 |
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 |
94f71cad |
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; |
109 | |
c8b5b3d8 |
110 | //! Calculates the point on the curve and two derivatives in the specified parameter |
94f71cad |
111 | //! \param[in] theParameter parameter of calculation of the value |
c8b5b3d8 |
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 |
94f71cad |
115 | Standard_EXPORT void D2(const Standard_Real& theParameter, |
116 | gp_Pnt2d& thePoint, |
117 | gp_Vec2d& theTangent, |
118 | gp_Vec2d& theCurvature) const; |
119 | Standard_EXPORT void D2(const Standard_Real& theParameter, |
120 | gp_Pnt& thePoint, |
121 | gp_Vec& theTangent, |
122 | gp_Vec& theCurvature) const; |
123 | |
c8b5b3d8 |
124 | //! Calculates the point on the curve and three derivatives in the specified parameter |
94f71cad |
125 | //! \param[in] theParameter parameter of calculation of the value |
c8b5b3d8 |
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 |
94f71cad |
130 | Standard_EXPORT void D3(const Standard_Real& theParameter, |
131 | gp_Pnt2d& thePoint, |
132 | gp_Vec2d& theTangent, |
133 | gp_Vec2d& theCurvature, |
134 | gp_Vec2d& theTorsion) const; |
135 | Standard_EXPORT void D3(const Standard_Real& theParameter, |
136 | gp_Pnt& thePoint, |
137 | gp_Vec& theTangent, |
138 | gp_Vec& theCurvature, |
139 | gp_Vec& theTorsion) const; |
140 | |
141 | |
92efcf78 |
142 | DEFINE_STANDARD_RTTIEXT(BSplCLib_Cache,Standard_Transient) |
94f71cad |
143 | |
144 | protected: |
c8b5b3d8 |
145 | //! Normalizes the parameter for periodical curves |
94f71cad |
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; |
149 | |
c8b5b3d8 |
150 | //! Fills array of derivatives in the selected point of the curve |
94f71cad |
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), |
c8b5b3d8 |
154 | //! where PntDim = 2 or 3 is a dimension of the curve) |
94f71cad |
155 | void CalculateDerivative(const Standard_Real& theParameter, |
156 | const Standard_Integer& theDerivative, |
157 | Standard_Real& theDerivArray) const; |
158 | |
159 | private: |
160 | Handle(TColStd_HArray2OfReal) myPolesWeights; ///< array of poles and weights of calculated cache |
161 | // the array has following structure: |
162 | // x1 y1 [z1] [w1] |
163 | // x2 y2 [z2] [w2] etc |
164 | // for 2D-curves there is no z conponent, for non-rational curves there is no weight |
165 | |
c8b5b3d8 |
166 | Standard_Boolean myIsRational; ///< identifies the rationality of Bezier/B-spline curve |
94f71cad |
167 | Standard_Real mySpanStart; ///< parameter for the first point of the span |
168 | Standard_Real mySpanLength; ///< length of the span |
c8b5b3d8 |
169 | Standard_Integer mySpanIndex; ///< index of the span on Bezier/B-spline curve |
170 | Standard_Integer mySpanIndexMax; ///< maximal number of spans on Bezier/B-spline curve |
171 | Standard_Integer myDegree; ///< degree of Bezier/B-spline |
172 | Handle(TColStd_HArray1OfReal) myFlatKnots; ///< knots of Bezier/B-spline (used for periodic normalization of parameters, exists only for periodical splines) |
94f71cad |
173 | }; |
174 | |
175 | DEFINE_STANDARD_HANDLE(BSplCLib_Cache, Standard_Transient) |
176 | |
177 | #endif |