BezierCurve.h 2.64 KB
Newer Older
1
/**
2
* \file bezier_curve.h
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
* \brief class allowing to create a Bezier curve of dimension 1 <= n <= 3.
* \author Steve T.
* \version 0.1
* \date 06/17/2013
*/


#ifndef _CLASS_BEZIERCURVE
#define _CLASS_BEZIERCURVE

#include "Curve_ABC.h"

#include "Exports.h"
#include "MathDefs.h"

#include <vector>

namespace spline
{
22
23
24
25
26
27
28
29
30
31
32
/// \class BezierCurve
/// \brief Represents a curve
///
template<typename Time= double, typename Numeric=Time, int Dim=3, bool Safe=false
, typename Point= Eigen::Matrix<Numeric, Dim, 1> >
struct bezier_curve : public  curve_abc<Time, Numeric, Dim, Safe, Point>
{
	typedef Point 	point_t;
	typedef Time 	time_t;
	typedef Numeric	num_t;

33
34
/* Constructors - destructors */
	public:
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
	///\brief Constructor
	///\param PointsBegin, PointsEnd : the points parametering the Bezier curve
	///\TODO : so far size above 3 is ignored
	template<typename In>
	SPLINE_API bezier_curve(In PointsBegin, In PointsEnd, const time_t minBound=0, const time_t maxBound=1)
	: minBound_(minBound)
	, maxBound_(maxBound)
	, size_(std::distance(PointsBegin, PointsEnd))
	{
		In it(PointsBegin);
		if(Safe && (size_<=1 || minBound == maxBound))
		{
			throw; // TODO 
		}
		for(; it != PointsEnd; ++it)
		{
			pts_.push_back(*it);
		}
	}
54

55
56
57
58
59
	///\brief Destructor
	SPLINE_API ~bezier_curve()
	{
		// NOTHING
	}
60
61

	private:
62
63
	bezier_curve(const bezier_curve&);
	bezier_curve& operator=(const bezier_curve&);
64
65
66
/* Constructors - destructors */

/*Operations*/
67
	public:
68
69
70
	public:
	///  \brief Evaluation of the cubic spline at time t.
	///  \param t : the time when to evaluate the spine
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
	///  \param return : the value x(t)
	SPLINE_API virtual point_t operator()(time_t t) const
	{
		num_t nT = (t - minBound_) / (maxBound_ - minBound_);
		if(Safe &! (0 <= nT && nT <= 1))
		{
			throw; // TODO
		}
		else
		{
			num_t dt = (1 - nT);
			switch(size_)
			{	
				case 2 :
					return pts_[0] * dt +  nT * pts_[1];
				break;
				case 3 :
					return 	pts_[0] * dt * dt 
                       				+ 2 * pts_[1] * nT * dt
						+ pts_[2] * nT * nT;
				break;
				default :
					return 	pts_[0] * dt * dt * dt
						+ 3 * pts_[1] * nT * dt * dt 
						+ 3 * pts_[2] * nT * nT * dt 
						+ pts_[3] * nT * nT *nT;
				break;
			}
		}
	}
101
/*Operations*/
102
103
104
105

/*Helpers*/
	SPLINE_API virtual time_t MinBound() const{return minBound_;}
	SPLINE_API virtual time_t MaxBound() const{return minBound_;}
106
107
108
/*Helpers*/

	public:
109
110
	const int size_;
	const time_t minBound_, maxBound_;
111
112
	
	private:
113
114
115
	typedef std::vector<Point,Eigen::aligned_allocator<Point> > T_Vector;
	T_Vector  pts_;
};
116
117
118
}
#endif //_CLASS_BEZIERCURVE