Newton Dynamics  4.00
ndBezierSpline.h
1 /* Copyright (c) <2003-2022> <Newton Game Dynamics>
2 *
3 * This software is provided 'as-is', without any express or implied
4 * warranty. In no event will the authors be held liable for any damages
5 * arising from the use of this software.
6 *
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely
10 */
11 
12 #include "ndCoreStdafx.h"
13 #include "ndArray.h"
14 #include "ndClassAlloc.h"
15 
16 #ifndef __ND_BEZIER_SPLINE_H__
17 #define __ND_BEZIER_SPLINE_H__
18 
20 {
21  public:
22 
23  // empty spline
24  D_CORE_API ndBezierSpline ();
25  D_CORE_API ndBezierSpline (const ndBezierSpline& src);
26 
27  // create from knot vector and control points
28  D_CORE_API virtual ~ndBezierSpline ();
29 
30  D_CORE_API ndBezierSpline& operator = (const ndBezierSpline &copy) ;
31 
32  D_CORE_API ndInt32 GetDegree () const;
33 
34  D_CORE_API ndBigVector CurvePoint (ndFloat64 u) const;
35  D_CORE_API ndBigVector CurveDerivative (ndFloat64 u, ndInt32 index = 1) const;
36  D_CORE_API ndInt32 CurveAllDerivatives (ndFloat64 u, ndBigVector* const defivatives) const;
37 
38  D_CORE_API ndFloat64 CalculateLength (ndFloat64 tol) const;
39 
40  D_CORE_API void GlobalCubicInterpolation (ndInt32 count, const ndBigVector* const points, const ndBigVector& firstTangent, const ndBigVector& lastTangent);
41  D_CORE_API void CreateFromKnotVectorAndControlPoints (ndInt32 degree, ndInt32 knotCount, const ndFloat64* const knotVector, const ndBigVector* const controlPoints);
42 
43  D_CORE_API void InsertKnot (ndFloat64 u);
44  D_CORE_API bool RemoveKnot (ndFloat64 u, ndFloat64 tol);
45 
46  D_CORE_API ndInt32 GetControlPointCount() const;
47  D_CORE_API ndArray<ndBigVector>& GetControlPointArray();
48  D_CORE_API const ndArray<ndBigVector>& GetControlPointArray() const;
49 
50  D_CORE_API ndBigVector GetControlPoint(ndInt32 i) const;
51  D_CORE_API void SetControlPoint(ndInt32 i, const ndBigVector& point);
52 
53  D_CORE_API ndInt32 GetKnotCount() const;
54  D_CORE_API ndArray<ndFloat64>& GetKnotArray();
55  D_CORE_API const ndArray<ndFloat64>& GetKnotArray() const;
56 
57  D_CORE_API ndFloat64 GetKnot(ndInt32 i) const;
58  D_CORE_API ndFloat64 FindClosestKnot (ndBigVector& closestPointOnCurve, const ndBigVector& point, ndInt32 subdivitionSteps = 2) const;
59 
60  D_CORE_API void Trace() const;
61 
62 
63  private:
64  void Clear();
65  ndInt32 GetSpan(ndFloat64 u) const;
66 
67  ndBigVector CurvePoint (ndFloat64 u, ndInt32 span) const;
68  void CreateCubicKnotVector(ndInt32 count, const ndBigVector* const points);
69  void CreateCubicControlPoints(ndInt32 count, const ndBigVector* const points, const ndBigVector& firstTangent, const ndBigVector& lastTangent);
70 
71  void BasicsFunctions (ndFloat64 u, ndInt32 span, ndFloat64* const functionOut) const;
72  void BasicsFunctionsDerivatives (ndFloat64 u, ndInt32 span, ndFloat64* const derivatyivesOut) const;
73 
74  ndArray<ndFloat64> m_knotVector;
75  ndArray<ndBigVector> m_controlPoints;
76 
77  ndInt32 m_degree;
78  ndInt32 m_knotsCount;
79  ndInt32 m_controlPointsCount;
80 };
81 #endif
82 
ndClassAlloc
Base class for providing memory allocation for all other engine classes.
Definition: ndClassAlloc.h:30
ndArray< ndBigVector >
ndBezierSpline
Definition: ndBezierSpline.h:20
ndBigVector
Definition: ndVectorArmNeon.h:463