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