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 _BSplSLib_Cache_Headerfile |
15 | #define _BSplSLib_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 | #include <gp_Pnt.hxx> |
23 | #include <gp_Vec.hxx> |
24 | |
b7c077b9 |
25 | #include <TColgp_Array2OfPnt.hxx> |
26 | #include <TColStd_Array1OfInteger.hxx> |
27 | #include <TColStd_HArray2OfReal.hxx> |
28 | #include <TColStd_HArray1OfReal.hxx> |
29 | #include <TColStd_Array1OfReal.hxx> |
30 | #include <TColStd_Array2OfReal.hxx> |
94f71cad |
31 | |
32 | #ifndef NOWEIGHTS_SURF |
33 | #define NOWEIGHTS_SURF (*((TColStd_Array2OfReal*) NULL)) |
34 | #endif |
35 | |
36 | //! \brief A cache class for B-spline surfaces. |
37 | //! |
38 | //! Defines all data, that can be cached on a span of B-spline surface. |
39 | //! The data should be recalculated in going from span to span. |
40 | class BSplSLib_Cache : public Standard_Transient |
41 | { |
42 | public: |
43 | //! Default constructor |
44 | Standard_EXPORT BSplSLib_Cache(); |
45 | //! Constructor for caching of the span for B-spline surface |
46 | //! \param theDegreeU degree along the first parameter (U) of the B-spline |
47 | //! \param thePeriodicU identify the B-spline is periodical along U axis |
48 | //! \param theFlatKnotsU knots of B-spline curve (with repetition) along U axis |
49 | //! \param theDegreeV degree alogn the second parameter (V) of the B-spline |
50 | //! \param thePeriodicV identify the B-spline is periodical along V axis |
51 | //! \param theFlatKnotsV knots of B-spline curve (with repetition) along V axis |
52 | //! \param thePoles array of poles of the B-spline surface |
53 | //! \param theWeights array of weights of corresponding poles |
54 | Standard_EXPORT BSplSLib_Cache(const Standard_Integer& theDegreeU, |
55 | const Standard_Boolean& thePeriodicU, |
56 | const TColStd_Array1OfReal& theFlatKnotsU, |
57 | const Standard_Integer& theDegreeV, |
58 | const Standard_Boolean& thePeriodicV, |
59 | const TColStd_Array1OfReal& theFlatKnotsV, |
60 | const TColgp_Array2OfPnt& thePoles, |
61 | const TColStd_Array2OfReal& theWeights = NOWEIGHTS_SURF); |
62 | |
63 | //! Verifies validity of the cache using parameters of the point |
64 | //! \param theParameterU first parameter of the point placed in the span |
65 | //! \param theParameterV second parameter of the point placed in the span |
66 | Standard_EXPORT Standard_Boolean IsCacheValid(Standard_Real theParameterU, |
67 | Standard_Real theParameterV) const; |
68 | |
69 | //! Recomputes the cache data. Does not verify validity of the cache |
70 | //! \param theParameterU the parametric value on the U axis to identify the span |
71 | //! \param theParameterV the parametric value on the V axis to identify the span |
72 | //! \param theDegreeU degree of the B-spline along U axis |
73 | //! \param thePeriodicU identify the B-spline is periodic along U axis |
74 | //! \param theFlatKnotsU flat knots of B-spline surface along U axis |
75 | //! \param theDegreeV degree of the B-spline along V axis |
76 | //! \param thePeriodicV identify the B-spline is periodic along V axis |
77 | //! \param theFlatKnotsV flat knots of B-spline surface along V axis |
78 | //! \param thePoles array of poles of B-spline |
79 | //! \param theWeights array of weights of corresponding poles |
80 | Standard_EXPORT void BuildCache(const Standard_Real& theParameterU, |
81 | const Standard_Real& theParameterV, |
82 | const Standard_Integer& theDegreeU, |
83 | const Standard_Boolean& thePeriodicU, |
84 | const TColStd_Array1OfReal& theFlatKnotsU, |
85 | const Standard_Integer& theDegreeV, |
86 | const Standard_Boolean& thePeriodicV, |
87 | const TColStd_Array1OfReal& theFlatKnotsV, |
88 | const TColgp_Array2OfPnt& thePoles, |
89 | const TColStd_Array2OfReal& theWeights = NOWEIGHTS_SURF); |
90 | |
91 | //! Calculates the point on B-spline for specified parameters |
92 | //! \param[in] theU first parameter for calculation of the value |
93 | //! \param[in] theV second parameter for calculation of the value |
94 | //! \param[out] thePoint the result of calculation (the point on the B-spline) |
95 | Standard_EXPORT void D0(const Standard_Real& theU, const Standard_Real& theV, gp_Pnt& thePoint) const; |
96 | |
97 | //! Calculates the point on B-spline and its first derivative |
98 | //! \param[in] theU first parameter of calculation of the value |
99 | //! \param[in] theV second parameter of calculation of the value |
100 | //! \param[out] thePoint the result of calculation (the point on the B-spline) |
101 | //! \param[out] theTangentU tangent vector along U axis in the calculated point |
102 | //! \param[out] theTangentV tangent vector along V axis in the calculated point |
103 | Standard_EXPORT void D1(const Standard_Real& theU, |
104 | const Standard_Real& theV, |
105 | gp_Pnt& thePoint, |
106 | gp_Vec& theTangentU, |
107 | gp_Vec& theTangentV) const; |
108 | |
109 | //! Calculates the point on B-spline and derivatives till second order |
110 | //! \param[in] theU first parameter of calculation of the value |
111 | //! \param[in] theV second parameter of calculation of the value |
112 | //! \param[out] thePoint the result of calculation (the point on B-spline) |
113 | //! \param[out] theTangentU tangent vector along U axis in the calculated point |
114 | //! \param[out] theTangentV tangent vector along V axis in the calculated point |
115 | //! \param[out] theCurvatureU curvature vector (2nd derivative on U) along U axis |
116 | //! \param[out] theCurvatureV curvature vector (2nd derivative on V) along V axis |
117 | //! \param[out] theCurvatureUV 2nd mixed derivative on U anv V |
118 | Standard_EXPORT void D2(const Standard_Real& theU, |
119 | const Standard_Real& theV, |
120 | gp_Pnt& thePoint, |
121 | gp_Vec& theTangentU, |
122 | gp_Vec& theTangentV, |
123 | gp_Vec& theCurvatureU, |
124 | gp_Vec& theCurvatureV, |
125 | gp_Vec& theCurvatureUV) const; |
126 | |
127 | |
ec357c5c |
128 | DEFINE_STANDARD_RTTI(BSplSLib_Cache, Standard_Transient) |
94f71cad |
129 | |
130 | protected: |
131 | //! Normalizes the parameter for periodical B-splines |
132 | //! \param[in] theDegree degree of B-spline along selected direction |
133 | //! \param[in] theFlatKnots knots with repetitions along selected direction |
134 | //! \param[in,out] theParameter the value to be normalized into the knots array |
135 | void PeriodicNormalization(const Standard_Integer& theDegree, |
136 | const TColStd_Array1OfReal& theFlatKnots, |
137 | Standard_Real& theParameter) const; |
138 | |
139 | private: |
140 | Handle(TColStd_HArray2OfReal) myPolesWeights; ///< array of poles and weights of calculated cache |
141 | // the array has following structure: |
142 | // x11 y11 z11 [w11] x12 y12 z12 [w12] ... |
143 | // x21 y21 z21 [w21] x22 y22 z22 [w22] etc |
144 | // for non-rational surfaces there is no weight; |
145 | // size of array: (max(myDegree)+1) * A*(min(myDegree)+1), where A = 4 or 3 |
146 | |
147 | Standard_Boolean myIsRational; ///< identifies the rationality of B-spline |
148 | Standard_Real mySpanStart[2]; ///< parameters (u, v) for the frst point of the span |
149 | Standard_Real mySpanLength[2]; ///< lengths of the span along corresponding parameter |
150 | Standard_Integer mySpanIndex[2]; ///< indexes of the span on B-spline surface |
151 | Standard_Integer mySpanIndexMax[2]; ///< maximal indexes of span |
152 | Standard_Integer myDegree[2]; ///< degrees of B-spline for each parameter |
153 | Handle(TColStd_HArray1OfReal) myFlatKnots[2]; ///< arrays of knots of B-spline |
154 | // (used for periodic normalization of parameters, Null for non-periodical splines) |
155 | }; |
156 | |
157 | DEFINE_STANDARD_HANDLE(BSplSLib_Cache, Standard_Transient) |
158 | |
159 | #endif |