CUGL 2.3
Cornell University Game Library

#include <CUPathSmoother.h>
Public Member Functions  
PathSmoother ()  
PathSmoother (const std::vector< Vec2 > &points)  
~PathSmoother ()  
void  set (const std::vector< Vec2 > &points) 
void  set (const Path2 &path) 
void  setEpsilon (float epsilon) 
float  getEpsilon () const 
void  reset () 
void  clear () 
void  calculate () 
std::vector< Vec2 >  getPoints () const 
size_t  getPoints (std::vector< Vec2 > &buffer) const 
Path2  getPath () const 
Path2 *  getPath (Path2 *buffer) const 
This class smooths a continuous path of points, reducing the number needed.
A common temptation with mobile games is to track the player's finger gesture by recording all of the finger positions over time. Except that this is a lot of points (and attempting to draw all these points exposed some serious flaws in earlier versions of SpriteBatch
). If points are too close together, then some of them can be safely removed without altering the shape of the path.
This class uses the DouglasPeuker algorithm, as described here:
https://en.wikipedia.org/wiki/Ramerâ€“Douglasâ€“Peucker_algorithm
The correct epsilon value to use should be found with experimentation. In particular, it depends on the scale of the path being smoothed.
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 set of vertices or another Poly2) 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, note that this factory is not thread safe in that you cannot access data while it is still in midcalculation.
cugl::PathSmoother::PathSmoother  (  ) 
Creates a path smoother with no vertex data.
cugl::PathSmoother::PathSmoother  (  const std::vector< Vec2 > &  points  ) 
Creates a path smoother with the given vertex data.
The vertex data is copied. The smother does not retain any references to the original data.
points  The vertices to triangulate 

inline 
Deletes this path smoother, releasing all resources.
void cugl::PathSmoother::calculate  (  ) 
Performs a triangulation of the current vertex data.
void cugl::PathSmoother::clear  (  ) 
Clears all internal data, the initial vertex data.
When this method is called, you will need to set a new vertices before calling calculate.

inline 
Returns the epsilon value for the smoothing algorithm.
The epsilon value specifies the tolerance for the algorithm. At each step, any point that is with epsilon of a line segment is considered to be part of that line segment.
Typically this value is found by experimentation. However, because this is typically used to smooth touch paths (which have integer coordinates), the value should be at least 1 (which is the default).
Path2 cugl::PathSmoother::getPath  (  )  const 
Returns a path object representing the smoothed result.
The resulting path is open.
If the calculation is not yet performed, this method will return the empty path.
Stores the smoothed path in the given buffer.
If the buffer is not empty, the vertices will be appended to the end of the buffer.
If the calculation is not yet performed, this method will do nothing.
buffer  The buffer to store the smoothed path 
std::vector< Vec2 > cugl::PathSmoother::getPoints  (  )  const 
Returns a list of points representing the smoothed path.
The result is guaranteed to be a subset of the original vertex path, order preserved. The smoother does not retain a reference to the returned list; it is safe to modify it.
If the calculation is not yet performed, this method will return the empty list.
size_t cugl::PathSmoother::getPoints  (  std::vector< Vec2 > &  buffer  )  const 
Stores the triangulation indices in the given buffer.
The result is guaranteed to be a subset of the original vertex path, order preserved. The points will be appended to the provided vector. You should clear the vector first if you do not want to preserve the original data.
If the calculation is not yet performed, this method will do nothing.
void cugl::PathSmoother::reset  (  ) 
Clears all internal data, but still maintains the initial vertex data.

inline 
Sets the vertex data for this path smoother.
The vertex data is copied. The smother does not retain any references to the original data. In addition, only the vertex data is copied. Whether or not the path is closed is ignored.
This method resets all interal data. You will need to reperform the calculation before accessing data.
path  The path to smooth 

inline 
Sets the vertex data for this path smoother.
The vertex data is copied. The smother does not retain any references to the original data.
This method resets all interal data. You will need to reperform the calculation before accessing data.
points  The vertices to triangulate 

inline 
Sets the epsilon value for the smoothing algorithm.
The epsilon value specifies the tolerance for the algorithm. At each step, any point that is with epsilon of a line segment is considered to be part of that line segment.
Typically this value is found by experimentation. However, because this is typically used to smooth touch paths (which have integer coordinates), the value should be at least 1 (which is the default).
epsilon  The epsilon value for the smoothing algorithm. 