CUGL 2.1
Cornell University Game Library
Public Member Functions | List of all members
cugl::SplinePather Class Reference

#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
 
Path2getPath (Path2 *buffer) const
 
std::vector< float > getParameters () const
 
size_t getParameters (std::vector< float > &buffer)
 
std::vector< Vec2getTangents () const
 
size_t getTangents (std::vector< Vec2 > &buffer)
 
std::vector< Vec2getNormals () const
 
size_t getNormals (std::vector< Vec2 > &buffer)
 
Poly2 getAnchors (float radius, int segments=4) const
 
Poly2getAnchors (Poly2 *buffer, float radius, int segments=4) const
 
Poly2 getHandles (float radius, int segments=4) const
 
Poly2getHandles (Poly2 *buffer, float radius, int segments=4) const
 
Spline2 getRefinement () const
 
Spline2getRefinement (Spline2 *buffer) const
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ SplinePather() [1/2]

cugl::SplinePather::SplinePather ( )
inline

Creates a spline approximator with no spline data.

◆ SplinePather() [2/2]

cugl::SplinePather::SplinePather ( const Spline2 spline)
inline

Creates a spline approximator with the given spline as its initial data.

Parameters
splineThe spline to approximate

◆ ~SplinePather()

cugl::SplinePather::~SplinePather ( )
inline

Deletes this spline approximator, releasing all resources.

Member Function Documentation

◆ calculate()

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 thread-safe. If you are using this method in a task thread, you should copy the spline first before starting the calculation.

◆ clear()

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.

◆ getAnchors() [1/2]

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.

Parameters
radiusthe radius of each handle
segmentsthe number of segments in the handle "circle"
Returns
a Poly2 representing handles for the anchor points

◆ getAnchors() [2/2]

Poly2* cugl::SplinePather::getAnchors ( Poly2 buffer,
float  radius,
int  segments = 4 
) const

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.

Parameters
bufferThe buffer to store the vertex data
radiusThe radius of each handle
segmentsThe number of segments in the handle "circle"
Returns
a reference to the buffer for chaining.

◆ getHandles() [1/2]

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.

Parameters
radiusthe radius of each handle
segmentsthe number of segments in the handle "circle"
Returns
a Poly2 representing handles for the tangent points

◆ getHandles() [2/2]

Poly2* cugl::SplinePather::getHandles ( Poly2 buffer,
float  radius,
int  segments = 4 
) const

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.

Parameters
bufferThe buffer to store the vertex data
radiusthe radius of each handle
segmentsthe number of segments in the handle "circle"
Returns
a reference to the buffer for chaining.

◆ getNormals() [1/2]

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.

Returns
a list of normals for a polygon approximation

◆ getNormals() [2/2]

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.

Returns
the number of elements added to the buffer

◆ getParameters() [1/2]

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.

Returns
a list of parameters for a polygon approximation

◆ getParameters() [2/2]

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.

Parameters
bufferThe buffer to store the parameter data
Returns
the number of elements added to the buffer

◆ getPath() [1/2]

Path2 cugl::SplinePather::getPath ( ) const

Returns a new path approximating this spline.

Returns
a new polygon approximating this spline.

◆ getPath() [2/2]

Path2* cugl::SplinePather::getPath ( Path2 buffer) const

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.

Parameters
bufferThe buffer to store the vertex data
Returns
a reference to the buffer for chaining.

◆ getRefinement() [1/2]

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.

Returns
an expanded version of this spline

◆ getRefinement() [2/2]

Spline2* cugl::SplinePather::getRefinement ( Spline2 buffer) const

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.

Parameters
bufferThe buffer to store the vertex data
Returns
a reference to the buffer for chaining.

◆ getTangents() [1/2]

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(n-1) 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.

Returns
a list of tangents for a polygon approximation

◆ getTangents() [2/2]

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(n-1) 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.

Returns
the number of elements added to the buffer

◆ reset()

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.

◆ set()

void cugl::SplinePather::set ( const Spline2 spline)
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.

Parameters
splineThe spline to approximate

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