CUGL 2.3
Cornell University Game Library

#include <CUSplinePather.h>
Public Member Functions  
SplinePather ()  
SplinePather (const Spline2 *spline)  
~SplinePather ()  
void  set (const Spline2 *spline) 
void  reset () 
void  clear () 
void  calculate () 
Path2  getPath () const 
Path2 *  getPath (Path2 *buffer) const 
std::vector< float >  getParameters () const 
size_t  getParameters (std::vector< float > &buffer) 
std::vector< Vec2 >  getTangents () const 
size_t  getTangents (std::vector< Vec2 > &buffer) 
std::vector< Vec2 >  getNormals () const 
size_t  getNormals (std::vector< Vec2 > &buffer) 
Poly2  getAnchors (float radius, int segments=4) const 
Poly2 *  getAnchors (Poly2 *buffer, float radius, int segments=4) const 
Poly2  getHandles (float radius, int segments=4) const 
Poly2 *  getHandles (Poly2 *buffer, float radius, int segments=4) const 
Spline2  getRefinement () const 
Spline2 *  getRefinement (Spline2 *buffer) const 
This class is a factory for producing Poly2 objects from a Spline2.
In order to draw a cubic spline, we must first convert it to a Poly2 object. All of our rendering tools are designed around the basic Poly2 class. In addition to generating a Poly2 for the spline path, this class can also generate Poly2 objects for UI elements such as handles and anchors.
As with all factories, the methods are broken up into three phases: initialization, calculation, and materialization. To use the factory, you first set the data (in this case a pointer to a Spline2) with the initialization methods. You then call the calculation method. Finally, you use the materialization methods to access the data in several different ways.
This division allows us to support multithreaded calculation if the data generation takes too long. However, not that this factory keeps a pointer to the spline, and it is unsafe to modify the spline while the calculation is ongoing. If you do multithread the calculation, you should force the user to copy the spline first.

inline 
Creates a spline approximator with no spline data.

inline 
Creates a spline approximator with the given spline as its initial data.
spline  The spline to approximate 

inline 
Deletes this spline approximator, releasing all resources.
void cugl::SplinePather::calculate  (  ) 
Performs an approximation of the current spline
A polygon approximation is creating by recursively calling de Castlejau's until we reach a stopping condition. Currently the only supported stopping condition is the recursion depth.
The calculation uses a reference to the spline; it does not copy it. Hence this method is not threadsafe. If you are using this method in a task thread, you should copy the spline first before starting the calculation.
void cugl::SplinePather::clear  (  ) 
Clears all internal data, including the spline data.
When this method is called, you will need to set a new spline before calling calculate.
Poly2 cugl::SplinePather::getAnchors  (  float  radius, 
int  segments = 4 

)  const 
Returns a Poly2 representing handles for the anchor points
This method returns a collection of vertex information for handles at the anchor points. Handles are circular shapes of a given radius. This information may be drawn to provide a visual representation of the anchor points (as seen in Adobe Illustrator).
If calculate has not been called, this method will choose anchors for the control points on the original spline. This latter option is useful when you want to draw a UI for the original control points.
radius  the radius of each handle 
segments  the number of segments in the handle "circle" 
Stores vertex information representing the anchor points in the buffer.
This method creates a collection of vertex information for handles at the anchor points. Handles are circular shapes of a given radius. This information may be drawn to provide a visual representation of the anchor points (as seen in Adobe Illustrator).
If calculate has not been called, this method will choose anchors for the control points on the original spline. This latter option is useful when you want to draw a UI for the original control points.
The vertices (and indices) will be appended to the the Poly2 if it is not empty. You should clear the Poly2 first if you do not want to preserve the original data.
buffer  The buffer to store the vertex data 
radius  The radius of each handle 
segments  The number of segments in the handle "circle" 
Poly2 cugl::SplinePather::getHandles  (  float  radius, 
int  segments = 4 

)  const 
Returns a Poly2 representing handles for the tangent points
This method returns vertex information for handles at the tangent points. Handles are circular shapes of a given radius. This information may be passed to a PolygonNode to provide a visual representation of the tangent points (as seen in Adobe Illustrator).
If calculate has not been called, this method will choose the tangents from the control points on the original spline. This latter option is useful when you want to draw a UI for the original tangent points.
radius  the radius of each handle 
segments  the number of segments in the handle "circle" 
Stores vertex information representing tangent point handles in the buffer.
This method creates vertex information for handles at the tangent points. Handles are circular shapes of a given radius. This information may be passed to a PolygonNode to provide a visual representation of the tangent points (as seen in Adobe Illustrator).
If calculate has not been called, this method will choose the tangents from the control points on the original spline. This latter option is useful when you want to draw a UI for the original tangent points.
The vertices (and indices) will be appended to the the Poly2 if it is not empty. You should clear the Poly2 first if you do not want to preserve the original data.
buffer  The buffer to store the vertex data 
radius  the radius of each handle 
segments  the number of segments in the handle "circle" 
std::vector< Vec2 > cugl::SplinePather::getNormals  (  )  const 
Returns a list of normals for a polygon approximation
There is one normal per control point. If polygon contains n points, this method will also return n normals. The normals are determined by the right tangents. If the spline is open, then the normal of the last point is determined by its left tangent.
If calculate has not been called, this method will choose normals for the control points on the original spline. This latter option is useful when you want to draw a UI for the control point normals.
size_t cugl::SplinePather::getNormals  (  std::vector< Vec2 > &  buffer  ) 
Stores a list of normals for the approximation in the buffer.
There is one normal per control point. If polygon contains n points, this method will also return n normals. The normals are determined by the right tangents. If the spline is open, then the normal of the last point is determined by its left tangent.
If calculate has not been called, this method will choose normals for the control points on the original spline. This latter option is useful when you want to draw a UI for the control point normals.
The normals will be appended to the buffer vector. You should clear the buffer first if you do not want to preserve the original data.
std::vector< float > cugl::SplinePather::getParameters  (  )  const 
Returns a list of parameters for a polygon approximation
The parameters correspond to the generating values in the spline polynomial. That is, if you evaluate the polynomial on the parameters, {via Spline2#getPoint()
, you will get the points in the approximating polygon.
size_t cugl::SplinePather::getParameters  (  std::vector< float > &  buffer  ) 
Stores a list of parameters for the approximation in the buffer.
The parameters correspond to the generating values in the spline polynomial. That is, if you evaluate the polynomial on the parameters, {via Spline2#getPoint()
, you will get the points in the approximating polygon.
The parameters will be appended to the buffer vector. You should clear the buffer first if you do not want to preserve the original data.
buffer  The buffer to store the parameter data 
Path2 cugl::SplinePather::getPath  (  )  const 
Returns a new path approximating this spline.
Stores vertex information approximating this spline in the buffer.
The vertices (and indices) will be appended to the the Path2 object if it is not empty. You should clear the path first if you do not want to preserve the original data.
buffer  The buffer to store the vertex data 
Spline2 cugl::SplinePather::getRefinement  (  )  const 
Returns an expanded version of this spline
When we use de Castlejau's to approximate the spline, it produces a list of control points that are geometrically equal to this spline (e.g. ignoring parameterization). Instead of flattening this information to a polygon, this method presents this data as a new spline.
If calculate has not been called, this method will copy the original spline.
Stores an expanded version of this spline in the given buffer.
When we use de Castlejau's to approximate the spline, it produces a list of control points that are geometrically equal to this spline (e.g. ignoring parameterization). Instead of flattening this information to a polygon, this method presents this data as a new spline.
The control points will be appended to the the spline if it is not empty. You should clear the spline first if you do not want to preserve the original data.
If calculate has not been called, this method will copy the original spline.
buffer  The buffer to store the vertex data 
std::vector< Vec2 > cugl::SplinePather::getTangents  (  )  const 
Returns a list of tangents for a polygon approximation
These tangent vectors are presented in control point order. First, we have the right tangent of the first point, then the left tangent of the second point, then the right, and so on. Hence if the polygon contains n points, this method will return 2(n1) tangents.
If calculate has not been called, this method will choose tangents for the control points on the original spline. This latter option is useful when you want to draw a UI for the control point tangents.
size_t cugl::SplinePather::getTangents  (  std::vector< Vec2 > &  buffer  ) 
Stores a list of tangents for the approximation in the buffer.
These tangent vectors are presented in control point order. First, we have the right tangent of the first point, then the left tangent of the second point, then the right, and so on. Hence if the polygon contains n points, this method will return 2(n1) tangents.
If calculate has not been called, this method will choose tangents for the control points on the original spline. This latter option is useful when you want to draw a UI for the control point tangents.
The tangents will be appended to the buffer vector. You should clear the buffer first if you do not want to preserve the original data.
void cugl::SplinePather::reset  (  ) 
Clears all internal data, but still maintains a reference to the spline.
Use this method when you want to reperform the approximation at a different resolution.

inline 
Sets the given spline as the data for this spline approximator.
This method resets all interal data. You will need to reperform the calculation before accessing data.
spline  The spline to approximate 