org.robokind.api.animation
Class PathInterpolator

java.lang.Object
  extended by org.robokind.api.animation.PathInterpolator
All Implemented Interfaces:
Interpolator
Direct Known Subclasses:
MotionPath

public class PathInterpolator
extends Object
implements Interpolator

Wraps an Interpolator to provide certain guarantees for animating. The PathInterpolator ensures that all Control points are ordered by X-values. It also ensures that the X-values of interpolated points are non-decreasing. The underlying Interpolator type can be changed using either the Class or full class name of the desired interpolator.

Author:
Matthew Stevenson

Field Summary
protected  List<Double> myXVals
          A sorted List of the points' x-values.
 
Constructor Summary
PathInterpolator(InterpolatorFactory factory)
          Creates an empty AnimationInterpolater with an Interpolator from the given InterpolatorFactory.
 
Method Summary
 Point2D addPoint(double x, double y)
          Adds a point with the given coordinates.
 void addPoints(int i, List<Point2D> points)
          Adds points with the given coordinates.
 void addPoints(List<Point2D> points)
          Adds given points.
 void clear()
          Removes all control points from the MotionPath.
 boolean equals(Object obj)
           
 List<Point2D> getControlPoints()
          Returns the control points for the interpolator.
 List<Point2D> getInterpolatedPoints()
          Returns the positions interpolated from the control points.
 InterpolatorFactory getInterpolatorFactory()
          Returns the factory for the underlying Interpolator.
 org.robokind.api.common.config.VersionProperty getInterpolatorVersion()
          Returns the version of the underlying Interpolator.
 int hashCode()
           
 Point2D insertPoint(int i, double x, double y)
          Adds a point with the given coordinates.
protected  boolean interpolate()
          Iterates through the underlying interpolated points and ensures that the time is always increasing.
 boolean interpolationChanged()
          Returns if the control points have been modified and needs to be interpolated.
protected  void moveControlPoint(int i, double x, double y)
          WARNING! This method bypasses the sorting! You must ensure all points are sorted after using this method.
 boolean overlaps(PathInterpolator b)
          Checks if values of another interpolator overlap this one.
 Point2D removePoint(int i)
          Remove point at given index.
 void removePoint(Point2D p)
          Removes given point.
 void setInterpolatorFactory(InterpolatorFactory factory)
          Changes underlying interpolator to the given type.
 Point2D setPoint(int i, double x, double y)
          Updates the point at index i.
 boolean touchesControlPoints()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

myXVals

protected List<Double> myXVals
A sorted List of the points' x-values.

Constructor Detail

PathInterpolator

public PathInterpolator(InterpolatorFactory factory)
Creates an empty AnimationInterpolater with an Interpolator from the given InterpolatorFactory.

Parameters:
factory - the given InterpolatorFactor
Method Detail

setInterpolatorFactory

public void setInterpolatorFactory(InterpolatorFactory factory)
Changes underlying interpolator to the given type.

Parameters:
factory - a factory for creating the underlying interpolator

getInterpolatorFactory

public InterpolatorFactory getInterpolatorFactory()
Returns the factory for the underlying Interpolator.

Returns:
the factory for the underlying Interpolator

addPoint

public Point2D addPoint(double x,
                        double y)
Adds a point with the given coordinates. Ensures points are sorted by X-value.

Specified by:
addPoint in interface Interpolator
Parameters:
x - time in milliseconds
y - servo position (0 <= y <= 1)
Returns:
the Point2D that was added

addPoints

public void addPoints(List<Point2D> points)
Adds given points. Ensures points are sorted by X-value.

Specified by:
addPoints in interface Interpolator
Parameters:
points - points to add

setPoint

public Point2D setPoint(int i,
                        double x,
                        double y)
Updates the point at index i. Ensures points are sorted by X-value. Removes the point at i, then adds a new point with given values.

Specified by:
setPoint in interface Interpolator
Parameters:
i - index of point to update
x - new x value
y - new y value
Returns:
point with new values

removePoint

public void removePoint(Point2D p)
Removes given point.

Specified by:
removePoint in interface Interpolator
Parameters:
p - point to remove

removePoint

public Point2D removePoint(int i)
Remove point at given index.

Specified by:
removePoint in interface Interpolator
Parameters:
i - index of point to remove
Returns:
removed point

getControlPoints

public List<Point2D> getControlPoints()
Returns the control points for the interpolator.

Specified by:
getControlPoints in interface Interpolator
Returns:
list of points which define the interpolation

getInterpolatedPoints

public List<Point2D> getInterpolatedPoints()
Returns the positions interpolated from the control points.

Specified by:
getInterpolatedPoints in interface Interpolator
Returns:
list of interpolated points

interpolate

protected boolean interpolate()
Iterates through the underlying interpolated points and ensures that the time is always increasing. Some IInterpolators, such as the CSpline, are not functions of time i.e. f(x), and as such may have multiple positions for a given time.

Returns:
true if interpolation has changed since the interpolated points have last been accessed, otherwise returns false

interpolationChanged

public boolean interpolationChanged()
Returns if the control points have been modified and needs to be interpolated.

Specified by:
interpolationChanged in interface Interpolator
Returns:
true if interpolation is needed, otherwise false

overlaps

public boolean overlaps(PathInterpolator b)
Checks if values of another interpolator overlap this one.

Parameters:
b - interpolator to check
Returns:
true if overlap otherwise false

insertPoint

public Point2D insertPoint(int i,
                           double x,
                           double y)
Adds a point with the given coordinates. Ensures points are sorted by X-value.

Specified by:
insertPoint in interface Interpolator
Parameters:
i - ignored
x - time in milliseconds
y - servo position (0 <= y <= 1)
Returns:
Point2D inserted

addPoints

public void addPoints(int i,
                      List<Point2D> points)
Adds points with the given coordinates. Ensures points are sorted by X-value.

Specified by:
addPoints in interface Interpolator
Parameters:
i - ignored
points - List of Points to add

clear

public void clear()
Removes all control points from the MotionPath.

Specified by:
clear in interface Interpolator

moveControlPoint

protected void moveControlPoint(int i,
                                double x,
                                double y)
WARNING! This method bypasses the sorting! You must ensure all points are sorted after using this method.

Parameters:
i -
x -
y -

getInterpolatorVersion

public org.robokind.api.common.config.VersionProperty getInterpolatorVersion()
Returns the version of the underlying Interpolator.

Specified by:
getInterpolatorVersion in interface Interpolator
Returns:
the version of the underlying Interpolator

touchesControlPoints

public boolean touchesControlPoints()
Specified by:
touchesControlPoints in interface Interpolator

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object


Copyright © 2011-2013. All Rights Reserved.