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