00001 #ifndef _RR_NURBS_H_
00002 #define _RR_NURBS_H_
00003
00004 #include <vector>
00005 #include <vrs/sharedobj.h>
00006 #include <vrs/vector.h>
00007
00008
00009 namespace random_racer
00010 {
00011
00017 class Nurbs : public VRS::SharedObj
00018 {
00019 public:
00027 Nurbs(unsigned int dimension, float spacing, unsigned int bufferZone=1);
00028
00029 virtual ~Nurbs();
00030
00035 void clear();
00036
00044 void evaluate(unsigned int levelOfDetail, std::vector<VRS::Vector>* target);
00045
00057 template <class T>
00058 void fill(T pointIteratorBegin, T pointIteratorEnd,
00059 double offsetX, double offsetY);
00060
00065 inline void setCorrection(float correctX, float correctY)
00066 {
00067 m_correctX = correctX;
00068 m_correctY = correctY;
00069 }
00070
00074 struct Point
00075 {
00076 float x;
00077 float y;
00078 float z;
00079 };
00080
00081 private:
00082 unsigned int m_dimension, m_bufferZone;
00083 float m_spacing, m_correctX, m_correctY;
00084 float* m_controlPoints;
00085
00086 unsigned int m_degree;
00087 unsigned int m_order;
00088 unsigned int m_numCvs;
00089
00090 unsigned int m_numKnots;
00091 float* m_knots;
00092
00093
00094 Point* m_tempPoints;
00095
00096 void fillKnotsVector(unsigned int order, unsigned int numPoints,
00097 float* knots);
00098
00105 float coxDeBoor(float u, int i, int k, const float* knots);
00106
00107 Point calculateU(float t, int row);
00108
00109 Point calculateV(float t, Point* pnts);
00110
00111 Point calculate(float u, float v, Point* tempPoints);
00112
00113 float min();
00114 float max();
00115
00121 inline unsigned int mapsArrayIndex( int row, int column )
00122 {
00123 return ( (row + m_bufferZone) * (m_dimension + (2 * m_bufferZone) ) ) +
00124 (column + m_bufferZone);
00125 }
00126
00127
00128 inline unsigned int mapsIndex( unsigned int row, unsigned int column )
00129 {
00130 return (row * (m_dimension + 2*m_bufferZone)) + column;
00131 }
00132
00133 };
00134
00135 }
00136
00137 #include "Nurbs.tcc"
00138
00139 #endif // _RR_NURBS_H_
00140