a4bfd46abba37ebe7b7cfaaed9b86630aae1aefa
[occt.git] / src / BSplCLib / BSplCLib_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 _BSplCLib_Cache_Headerfile
15 #define _BSplCLib_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 <gp_Pnt2d.hxx>
23 #include <gp_Pnt.hxx>
24 #include <gp_Vec2d.hxx>
25 #include <gp_Vec.hxx>
26
27 #include <TColStd_HArray2OfReal.hxx>
28 #include <TColStd_HArray1OfReal.hxx>
29 #include <TColStd_Array1OfReal.hxx>
30 #include <TColgp_Array1OfPnt.hxx>
31 #include <TColgp_Array1OfPnt2d.hxx>
32
33 #include <BSplCLib_CacheParams.hxx>
34
35 //! \brief A cache class for Bezier and B-spline curves.
36 //!
37 //! Defines all data, that can be cached on a span of a curve.
38 //! The data should be recalculated in going from span to span.
39 class BSplCLib_Cache : public Standard_Transient
40 {
41 public:
42
43   //! Constructor, prepares data structures for caching values on a 2d curve.
44   //! \param theDegree     degree of the curve
45   //! \param thePeriodic   identify whether 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
55   //! Constructor, prepares data structures for caching values on a 3d curve.
56   //! \param theDegree     degree of the curve
57   //! \param thePeriodic   identify whether the curve is periodic
58   //! \param theFlatKnots  knots of Bezier/B-spline curve (with repetitions)
59   //! \param thePoles      array of poles of 3D curve
60   //! \param theWeights    array of weights of corresponding poles
61   Standard_EXPORT BSplCLib_Cache(const Standard_Integer&        theDegree,
62                                  const Standard_Boolean&        thePeriodic,
63                                  const TColStd_Array1OfReal&    theFlatKnots,
64                                  const TColgp_Array1OfPnt&      thePoles,
65                                  const TColStd_Array1OfReal*    theWeights = NULL);
66
67   //! Verifies validity of the cache using flat parameter of the point
68   //! \param theParameter parameter of the point placed in the span
69   Standard_EXPORT Standard_Boolean IsCacheValid(Standard_Real theParameter) const;
70
71   //! Recomputes the cache data for 2D curves. Does not verify validity of the cache
72   //! \param theParameter  the value on the knot's axis to identify the span
73   //! \param theFlatKnots  knots of Bezier/B-spline curve (with repetitions)
74   //! \param thePoles2d    array of poles of 2D curve
75   //! \param theWeights    array of weights of corresponding poles
76   Standard_EXPORT void BuildCache(const Standard_Real&           theParameter,
77                                   const TColStd_Array1OfReal&    theFlatKnots,
78                                   const TColgp_Array1OfPnt2d&    thePoles2d,
79                                   const TColStd_Array1OfReal*    theWeights);
80
81   //! Recomputes the cache data for 3D curves. Does not verify validity of the cache
82   //! \param theParameter  the value on the knot's axis to identify the span
83   //! \param theFlatKnots  knots of Bezier/B-spline curve (with repetitions)
84   //! \param thePoles      array of poles of 3D curve
85   //! \param theWeights    array of weights of corresponding poles
86   Standard_EXPORT void BuildCache(const Standard_Real&           theParameter,
87                                   const TColStd_Array1OfReal&    theFlatKnots,
88                                   const TColgp_Array1OfPnt&      thePoles,
89                                   const TColStd_Array1OfReal*    theWeights = NULL);
90
91   //! Calculates the point on the curve in the specified parameter
92   //! \param[in]  theParameter parameter of calculation of the value
93   //! \param[out] thePoint     the result of calculation (the point on the curve)
94   Standard_EXPORT void D0(const Standard_Real& theParameter, gp_Pnt2d& thePoint) const;
95   Standard_EXPORT void D0(const Standard_Real& theParameter, gp_Pnt&   thePoint) const;
96
97   //! Calculates the point on the curve and its first derivative 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   //! \param[out] theTangent   tangent vector (first derivatives) for the curve in the calculated point
101   Standard_EXPORT void D1(const Standard_Real& theParameter, gp_Pnt2d& thePoint, gp_Vec2d& theTangent) const;
102   Standard_EXPORT void D1(const Standard_Real& theParameter, gp_Pnt&   thePoint, gp_Vec&   theTangent) const;
103
104   //! Calculates the point on the curve and two derivatives in the specified parameter
105   //! \param[in]  theParameter parameter of calculation of the value
106   //! \param[out] thePoint     the result of calculation (the point on the curve)
107   //! \param[out] theTangent   tangent vector (1st derivatives) for the curve in the calculated point
108   //! \param[out] theCurvature curvature vector (2nd derivatives) for the curve in the calculated point
109   Standard_EXPORT void D2(const Standard_Real& theParameter, 
110                                 gp_Pnt2d&      thePoint, 
111                                 gp_Vec2d&      theTangent, 
112                                 gp_Vec2d&      theCurvature) const;
113   Standard_EXPORT void D2(const Standard_Real& theParameter, 
114                                 gp_Pnt&        thePoint, 
115                                 gp_Vec&        theTangent, 
116                                 gp_Vec&        theCurvature) const;
117
118   //! Calculates the point on the curve and three derivatives in the specified parameter
119   //! \param[in]  theParameter parameter of calculation of the value
120   //! \param[out] thePoint     the result of calculation (the point on the curve)
121   //! \param[out] theTangent   tangent vector (1st derivatives) for the curve in the calculated point
122   //! \param[out] theCurvature curvature vector (2nd derivatives) for the curve in the calculated point
123   //! \param[out] theTorsion   second curvature vector (3rd derivatives) for the curve in the calculated point
124   Standard_EXPORT void D3(const Standard_Real& theParameter, 
125                                 gp_Pnt2d&      thePoint, 
126                                 gp_Vec2d&      theTangent, 
127                                 gp_Vec2d&      theCurvature,
128                                 gp_Vec2d&      theTorsion) const;
129   Standard_EXPORT void D3(const Standard_Real& theParameter, 
130                                 gp_Pnt&        thePoint, 
131                                 gp_Vec&        theTangent, 
132                                 gp_Vec&        theCurvature,
133                                 gp_Vec&        theTorsion) const;
134
135
136   DEFINE_STANDARD_RTTIEXT(BSplCLib_Cache,Standard_Transient)
137
138 protected:
139
140   //! Fills array of derivatives in the selected point of the curve
141   //! \param[in]  theParameter  parameter of the calculation
142   //! \param[in]  theDerivative maximal derivative to be calculated (computes all derivatives lesser than specified)
143   //! \param[out] theDerivArray result array of derivatives (with size (theDerivative+1)*(PntDim+1), 
144   //!                           where PntDim = 2 or 3 is a dimension of the curve)
145   void CalculateDerivative(const Standard_Real&    theParameter, 
146                            const Standard_Integer& theDerivative, 
147                                  Standard_Real&    theDerivArray) const;
148
149   // copying is prohibited
150   BSplCLib_Cache (const BSplCLib_Cache&);
151   void operator = (const BSplCLib_Cache&);
152
153 private:
154   Standard_Boolean myIsRational;                //!< identifies the rationality of Bezier/B-spline curve
155   BSplCLib_CacheParams myParams;                //!< cache parameters
156   Handle(TColStd_HArray2OfReal) myPolesWeights; //!< array of poles and weights of calculated cache
157                                                 // the array has following structure:
158                                                 //       x1 y1 [z1] [w1]
159                                                 //       x2 y2 [z2] [w2] etc
160                                                 // for 2D-curves there is no z conponent, for non-rational curves there is no weight
161 };
162
163 DEFINE_STANDARD_HANDLE(BSplCLib_Cache, Standard_Transient)
164
165 #endif