NGL  6.5
The NCCA Graphics Library
ngl::BezierCurve Class Reference

Generic Bezier Curve Class allowing the user to generate basic curves using a number of different constriction methods, such as array of Vectors, array of numbers etc The class can automatically generate knot vectors as well or the user can specify their own. More...

#include <BezierCurve.h>

+ Collaboration diagram for ngl::BezierCurve:

Public Member Functions

 BezierCurve () noexcept
 default ctor sets initial values for Curve to be used with AddPoint , AddKnot etc More...
 
 BezierCurve (const Vec3 *_p, unsigned int _nPoints, const Real *_k, unsigned int _nKnots) noexcept
 Ctor passing in an Array of CP's and and Array of knots. More...
 
 BezierCurve (const Real *_p, unsigned int _nPoints) noexcept
 ctor passing in an array of points, note the knot vector will be automatically calculated as an open vector using a call to create knots More...
 
 BezierCurve (const BezierCurve &_c) noexcept
 copy ctor More...
 
 ~BezierCurve () noexcept
 destructor More...
 
void draw () const noexcept
 Draw method to draw the curve Note this will be slow as it calls the CoxDeBoor function to calculate each time it is much quicker to create a display list and use this. More...
 
void drawControlPoints () const noexcept
 draw the control points More...
 
void drawHull () const noexcept
 Draw the control hull. More...
 
Vec3 getPointOnCurve (Real _value) const noexcept
 get a point on the curve in the range of 0 - 1 based on the control points More...
 
void addPoint (const Vec3 &_p) noexcept
 add a control point to the Curve More...
 
void addPoint (Real _x, Real _y, Real _z) noexcept
 add a point to the curve using x,y,z values More...
 
void addKnot (Real _k) noexcept
 add a knot value to the curve More...
 
void createKnots () noexcept
 create a knot vector array based as an Open Vector (half 0.0 half 1.0) More...
 
Real coxDeBoor (Real _u, unsigned int _i, unsigned int _k, const std::vector< Real > &_knots) const noexcept
 implementation of the CoxDeBoor algorithm for Bezier Curves borrowed from Rob Bateman's example and modified to make it work with the class. NOTE, this is a recursive function More...
 
void setLOD (int _lod) noexcept
 set the Level of Detail for Drawing More...
 
void createVAO () noexcept
 set the Level of Detail for Drawing More...
 

Protected Attributes

GLuint m_listIndex
 the display list index created from glCreateLists More...
 
unsigned int m_order
 The Order of the Curve = Degree +1. More...
 
unsigned int m_lod
 The level of detail used to calculate how much detail to draw. More...
 
unsigned int m_numCP
 The ammount of Control Points in the Curve. More...
 
unsigned int m_degree
 The degree of the curve, Calculated from the Number of Control Points. More...
 
unsigned int m_numKnots
 The knot vector always has as many values as the numer of verts (cp) + the degree. More...
 
std::vector< Vec3m_cp
 the contol points for the curve More...
 
std::vector< Realm_knots
 the knot vector for the curve More...
 
AbstractVAOm_vaoCurve
 a vertex array object for our curve drawing More...
 
AbstractVAOm_vaoPoints
 a vertex array object for our point drawing More...
 

Detailed Description

Generic Bezier Curve Class allowing the user to generate basic curves using a number of different constriction methods, such as array of Vectors, array of numbers etc The class can automatically generate knot vectors as well or the user can specify their own.

Author
Rob Bateman modified and augmented by Jonathan Macey
Version
3.0
Date
Last Revision 27/09/09 Updated to NCCA Coding standard and V2.0 History : /06/08 Initial class written
Todo:
update this class to run the CoxDeBoor algo once and then store the points in a dynamic array based on the LOD value passed in. This will speed up the execution for static curves as at present we calculate each time. Also this array can then be used to draw with VertexArrays and we will not need to create the DisplayLists

Definition at line 45 of file BezierCurve.h.

Constructor & Destructor Documentation

ngl::BezierCurve::BezierCurve ( )
noexcept

default ctor sets initial values for Curve to be used with AddPoint , AddKnot etc

Definition at line 26 of file BezierCurve.cpp.

References m_degree, m_listIndex, m_lod, m_numCP, m_numKnots, m_order, m_vaoCurve, and m_vaoPoints.

+ Here is the caller graph for this function:

ngl::BezierCurve::BezierCurve ( const Vec3 _p,
unsigned int  _nPoints,
const Real _k,
unsigned int  _nKnots 
)
noexcept

Ctor passing in an Array of CP's and and Array of knots.

Parameters
[in]_pan array of Vector objects which are the control
[in]_nPointsthe size of the Point Array
[in]_kand array of knot values
[in]_nKnotsthe size of the knot array
ngl::BezierCurve::BezierCurve ( const Real _p,
unsigned int  _nPoints 
)
noexcept

ctor passing in an array of points, note the knot vector will be automatically calculated as an open vector using a call to create knots

Parameters
[in]_pthe array of CP values expressed as groups of 3 float x,y,z values
[in]_nPointsthe size of the array *p (note this is the total size of the array)
ngl::BezierCurve::BezierCurve ( const BezierCurve _c)
noexcept

copy ctor

Parameters
_cthe curve to copy

Definition at line 47 of file BezierCurve.cpp.

References BezierCurve(), createKnots(), m_cp, m_degree, m_knots, m_lod, m_numCP, m_numKnots, m_order, m_vaoCurve, and m_vaoPoints.

+ Here is the call graph for this function:

ngl::BezierCurve::~BezierCurve ( )
noexcept

destructor

Definition at line 100 of file BezierCurve.cpp.

References m_cp, m_knots, m_vaoCurve, m_vaoPoints, ngl::AbstractVAO::removeVAO(), and ngl::AbstractVAO::unbind().

+ Here is the call graph for this function:

Member Function Documentation

void ngl::BezierCurve::addKnot ( Real  _k)
noexcept

add a knot value to the curve

Parameters
[in]_kthe value of the knot (note this is added to the end of the curve

Definition at line 220 of file BezierCurve.cpp.

References m_knots, m_numCP, m_numKnots, and m_order.

void ngl::BezierCurve::addPoint ( const Vec3 _p)
noexcept

add a control point to the Curve

Parameters
[in]&_pthe point to add

Definition at line 194 of file BezierCurve.cpp.

References m_cp, m_degree, m_numCP, m_numKnots, and m_order.

void ngl::BezierCurve::addPoint ( Real  _x,
Real  _y,
Real  _z 
)
noexcept

add a point to the curve using x,y,z values

Parameters
[in]_xx value of point
[in]_yy value of point
[in]_zz value of point

Definition at line 207 of file BezierCurve.cpp.

References m_cp, m_degree, m_numCP, m_numKnots, and m_order.

Real ngl::BezierCurve::coxDeBoor ( Real  _u,
unsigned int  _i,
unsigned int  _k,
const std::vector< Real > &  _knots 
) const
noexcept

implementation of the CoxDeBoor algorithm for Bezier Curves borrowed from Rob Bateman's example and modified to make it work with the class. NOTE, this is a recursive function

Returns
Real the evaluation of the weight at the current value
Parameters
[in]_u
[in]_i
[in]_k
[in]_knotsthe array of knots for the curve

Definition at line 114 of file BezierCurve.cpp.

References coxDeBoor().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ngl::BezierCurve::createKnots ( )
noexcept

create a knot vector array based as an Open Vector (half 0.0 half 1.0)

Definition at line 38 of file BezierCurve.cpp.

References m_knots, and m_numKnots.

+ Here is the caller graph for this function:

void ngl::BezierCurve::draw ( ) const
noexcept

Draw method to draw the curve Note this will be slow as it calls the CoxDeBoor function to calculate each time it is much quicker to create a display list and use this.

Todo:
Modify this to use faster method than display lists

Definition at line 160 of file BezierCurve.cpp.

References ngl::AbstractVAO::bind(), ngl::AbstractVAO::draw(), m_vaoCurve, and ngl::AbstractVAO::unbind().

+ Here is the call graph for this function:

void ngl::BezierCurve::drawControlPoints ( ) const
noexcept

draw the control points

Definition at line 140 of file BezierCurve.cpp.

References ngl::AbstractVAO::bind(), ngl::AbstractVAO::draw(), GL_POINTS, m_vaoPoints, ngl::AbstractVAO::setMode(), and ngl::AbstractVAO::unbind().

+ Here is the call graph for this function:

void ngl::BezierCurve::drawHull ( ) const
noexcept

Draw the control hull.

Definition at line 151 of file BezierCurve.cpp.

References ngl::AbstractVAO::bind(), ngl::AbstractVAO::draw(), GL_LINE_STRIP, m_vaoPoints, ngl::AbstractVAO::setMode(), and ngl::AbstractVAO::unbind().

+ Here is the call graph for this function:

Vec3 ngl::BezierCurve::getPointOnCurve ( Real  _value) const
noexcept

get a point on the curve in the range of 0 - 1 based on the control points

Parameters
[in]_valuethe point to evaluate between 0 and 1
Returns
the value of the point at t

Definition at line 168 of file BezierCurve.cpp.

References coxDeBoor(), m_cp, m_degree, m_knots, and m_numCP.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ngl::BezierCurve::setLOD ( int  _lod)
inlinenoexcept

set the Level of Detail for Drawing

Note
this will have no Effect if the createVAO has been called before
Parameters
[in]_lodthe level of detail to use when creating the display list for drawing the higher the number the finer the drawing

Definition at line 138 of file BezierCurve.h.

+ Here is the caller graph for this function:

Member Data Documentation

std::vector<Vec3> ngl::BezierCurve::m_cp
protected

the contol points for the curve

Definition at line 172 of file BezierCurve.h.

unsigned int ngl::BezierCurve::m_degree
protected

The degree of the curve, Calculated from the Number of Control Points.

Definition at line 164 of file BezierCurve.h.

std::vector<Real> ngl::BezierCurve::m_knots
protected

the knot vector for the curve

Definition at line 176 of file BezierCurve.h.

GLuint ngl::BezierCurve::m_listIndex
protected

the display list index created from glCreateLists

Definition at line 148 of file BezierCurve.h.

unsigned int ngl::BezierCurve::m_lod
protected

The level of detail used to calculate how much detail to draw.

Definition at line 156 of file BezierCurve.h.

unsigned int ngl::BezierCurve::m_numCP
protected

The ammount of Control Points in the Curve.

Definition at line 160 of file BezierCurve.h.

unsigned int ngl::BezierCurve::m_numKnots
protected

The knot vector always has as many values as the numer of verts (cp) + the degree.

Definition at line 168 of file BezierCurve.h.

unsigned int ngl::BezierCurve::m_order
protected

The Order of the Curve = Degree +1.

Definition at line 152 of file BezierCurve.h.

AbstractVAO* ngl::BezierCurve::m_vaoCurve
protected

a vertex array object for our curve drawing

Definition at line 180 of file BezierCurve.h.

AbstractVAO* ngl::BezierCurve::m_vaoPoints
protected

a vertex array object for our point drawing

Definition at line 184 of file BezierCurve.h.


The documentation for this class was generated from the following files: