maspack.interpolation
Class NumericList

java.lang.Object
  extended by maspack.interpolation.NumericList
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Iterable<NumericListKnot>, Scannable

public class NumericList
extends java.lang.Object
implements java.lang.Cloneable, java.lang.Iterable<NumericListKnot>, Scannable

A linked list of vector values arranged in order with respect to a parameter t. Can be interpolated to produce a continuous vector function.


Constructor Summary
NumericList(int vsize)
          Creates an empty numeric list for holding vectors of a prescribed size.
 
Method Summary
 NumericListKnot add(NumericListKnot knot)
          Adds a knot into this numeric list.
 NumericListKnot add(NumericListKnot knot, NumericListKnot last)
           
 NumericListKnot add(Vector vals, double t)
          Creates a knot with the specified values and time and adds it into this numeric list.
 void clear()
          Removes all knots in the numeric list.
 void clearAfter(NumericListKnot knot)
          Removes all knots after a specific knot in this list.
 java.lang.Object clone()
          Returns a deep copy of this numeric list.
 boolean equals(NumericList list)
          Returns true if the contents of this numeric list equal the contents of another numeric list.
 NumericListKnot findKnotAtOrBefore(double t, NumericListKnot last)
          Finds the knot whose t value is closest to, and if possible less or equal to, a specified value.
 NumericListKnot findKnotClosest(double t)
          Finds the knot whose t value is closest to a specified value.
 NumericListKnot findKnotClosest(double t, NumericListKnot last)
           
 NumericListKnot getFirst()
          Returns the first knot in this list.
 Interpolation getInterpolation()
          Returns the interpolation method for this list.
 NumericListKnot getLast()
          Returns the last knot in this list.
 void getMinMaxValues(double[] minMax)
           
 int getNumKnots()
          Returns the number of knots in this list.
 double[][] getValues()
          Returns the values of this numeric list as a two dimensional array of doubles.
 int getVectorSize()
          Returns the size of the vectors associated with this list.
 void interpolate(VectorNd v, double t)
          Interpolates the value associated with a particular value of t, based on the current contents of this list.
 NumericListKnot interpolate(VectorNd v, double t, Interpolation.Order order, boolean extendData, NumericListKnot last)
           
 NumericListKnot interpolate(VectorNd v, double t, Interpolation method, NumericListKnot last)
           
 void interpolateCubic(VectorNd v, NumericListKnot prev, double t)
           
 boolean isEmpty()
          Returns true if this list is empty.
 boolean isWritable()
          Returns true if this component should in fact be written to secondary storage.
 java.util.Iterator<NumericListKnot> iterator()
          Returns an iterator over all the knots in this numeric list.
 NumericListKnot remove(double t)
          Removes and return the knot at time t, if any.
 void remove(NumericListKnot knot)
          Removes a knot from this numeric list.
 void scan(ReaderTokenizer rtok, java.lang.Object ref)
          Scans this element from a ReaderTokenizer.
 void setInterpolation(Interpolation method)
          Sets the interpolation method for this list.
 void setValues(double[][] vals)
          Sets the values of this numeric list from a two dimensional array of doubles.
 java.lang.String toString()
          Returns a string representation of this numeric list.
 java.lang.String toString(NumberFormat fmt)
          Returns a String representation of this numeric list, in which each element is formatted using a C printf style as decribed by the parameter NumberFormat.
 java.lang.String toString(java.lang.String fmtStr)
          Returns a String representation of this numeric list, in which each element is formatted using a C printf style format string.
 java.lang.String toStringSuper()
           
 void write(java.io.PrintWriter pw, NumberFormat fmt, java.lang.Object ref)
          Writes a text description of this element to a PrintWriter.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NumericList

public NumericList(int vsize)
Creates an empty numeric list for holding vectors of a prescribed size.

Parameters:
vsize - size of the vectors that will form this list
Method Detail

setInterpolation

public void setInterpolation(Interpolation method)
Sets the interpolation method for this list. The default is Step with no end data extension.

Parameters:
method - new interpolation method.

getInterpolation

public Interpolation getInterpolation()
Returns the interpolation method for this list.

Returns:
interpolation method
See Also:
setInterpolation(maspack.interpolation.Interpolation)

getVectorSize

public int getVectorSize()
Returns the size of the vectors associated with this list.


add

public NumericListKnot add(NumericListKnot knot)
Adds a knot into this numeric list. The knot will be added at the proper location so that all t values are monotonically increasing. Any existing knot which has the same t value as the new knot will be removed and returned.

Parameters:
knot - knot to add to the list
Returns:
existing knot with the same t value, if any
Throws:
java.lang.IllegalArgumentException - if the knot's vector has a size not equal to the vector size for this list.
See Also:
getVectorSize()

add

public NumericListKnot add(Vector vals,
                           double t)
Creates a knot with the specified values and time and adds it into this numeric list. The knot will be added at the proper location so that all t values are monotonically increasing. Any existing knot which has the same t value as the new knot will be removed and returned.

Parameters:
vals - values for the knot
t - time at which the knot should be added
Returns:
existing knot with the same t value, if any
Throws:
java.lang.IllegalArgumentException - if values has a size less than the vector size for this list.
See Also:
getVectorSize()

add

public NumericListKnot add(NumericListKnot knot,
                           NumericListKnot last)

getMinMaxValues

public void getMinMaxValues(double[] minMax)

remove

public NumericListKnot remove(double t)
Removes and return the knot at time t, if any.

Parameters:
t - time of the knot to remove
Returns:
removed knot, if any

remove

public void remove(NumericListKnot knot)
Removes a knot from this numeric list. It is up to the application to ensure that the knot is currently a member of this list.

Parameters:
knot - knot to remove

clearAfter

public void clearAfter(NumericListKnot knot)
Removes all knots after a specific knot in this list. It is up to the application to ensure that the specified knot is a member of the list.

Parameters:
knot - all knots following this one will be removed

findKnotAtOrBefore

public NumericListKnot findKnotAtOrBefore(double t,
                                          NumericListKnot last)
Finds the knot whose t value is closest to, and if possible less or equal to, a specified value.

Parameters:
t - specified value
Returns:
nearest knot less than t

findKnotClosest

public NumericListKnot findKnotClosest(double t)
Finds the knot whose t value is closest to a specified value.

Parameters:
t - specified value
Returns:
knot closest to t

findKnotClosest

public NumericListKnot findKnotClosest(double t,
                                       NumericListKnot last)

interpolate

public void interpolate(VectorNd v,
                        double t)
Interpolates the value associated with a particular value of t, based on the current contents of this list. If t lies before the start or after the end of the list, the interpolation value is set to the first or last knot value.

Parameters:
v - stores the interpolation result
t - value to interpolate for
Throws:
ImproperStateException - if the list is empty

interpolateCubic

public void interpolateCubic(VectorNd v,
                             NumericListKnot prev,
                             double t)

interpolate

public NumericListKnot interpolate(VectorNd v,
                                   double t,
                                   Interpolation method,
                                   NumericListKnot last)

interpolate

public NumericListKnot interpolate(VectorNd v,
                                   double t,
                                   Interpolation.Order order,
                                   boolean extendData,
                                   NumericListKnot last)

getFirst

public NumericListKnot getFirst()
Returns the first knot in this list.

Returns:
first knot in this list

getLast

public NumericListKnot getLast()
Returns the last knot in this list.

Returns:
last knot in this list

getNumKnots

public int getNumKnots()
Returns the number of knots in this list.

Returns:
number of knots

isEmpty

public boolean isEmpty()
Returns true if this list is empty.

Returns:
true if this list is empty

clear

public void clear()
Removes all knots in the numeric list.


iterator

public java.util.Iterator<NumericListKnot> iterator()
Returns an iterator over all the knots in this numeric list.

Specified by:
iterator in interface java.lang.Iterable<NumericListKnot>
Returns:
iterator over ths knots

getValues

public double[][] getValues()
Returns the values of this numeric list as a two dimensional array of doubles. This facilitates reading the values into a matlab array. The array is arranged so that each knot point corresponds to a row, the first column gives the time values, and the remaining columns give the knot point values.

Returns:
Values of this numeric list

setValues

public void setValues(double[][] vals)
Sets the values of this numeric list from a two dimensional array of doubles. This facilitates settings the values from a matlab array. The arrangement of the array is described in getValues().

Parameters:
vals - Values used to set this numeric list

equals

public boolean equals(NumericList list)
Returns true if the contents of this numeric list equal the contents of another numeric list.

Parameters:
list - numeric list to compare with
Returns:
true if the lists are equal

toString

public java.lang.String toString()
Returns a string representation of this numeric list.

Overrides:
toString in class java.lang.Object
Returns:
string representation of this list

toString

public java.lang.String toString(java.lang.String fmtStr)
Returns a String representation of this numeric list, in which each element is formatted using a C printf style format string. For a description of the format string syntax, see NumberFormat.

Parameters:
fmtStr - numeric format specification
Returns:
String representation of this list

toString

public java.lang.String toString(NumberFormat fmt)
Returns a String representation of this numeric list, in which each element is formatted using a C printf style as decribed by the parameter NumberFormat. When called numerous times, this routine can be more efficient than toString(String), because the NumberFormat does not need to be recreated each time from a specification string.

Parameters:
fmt - numeric format
Returns:
String representation of this list

toStringSuper

public java.lang.String toStringSuper()

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Returns a deep copy of this numeric list.

Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

isWritable

public boolean isWritable()
Returns true if this component should in fact be written to secondary storage. This gives subclasses control over whether or not they are actually written out.

Specified by:
isWritable in interface Scannable
Returns:
true if this component should be written to secondary storage.

write

public void write(java.io.PrintWriter pw,
                  NumberFormat fmt,
                  java.lang.Object ref)
           throws java.io.IOException
Writes a text description of this element to a PrintWriter. The text description should be compatable with scan and complete enough to allow full reconstruction of the element.

Specified by:
write in interface Scannable
Parameters:
pw - stream for writing the element
fmt - numeric formating information
ref - optional reference object which can be used for producing references to other objects
Throws:
java.io.IOException - if an I/O error occured

scan

public void scan(ReaderTokenizer rtok,
                 java.lang.Object ref)
          throws java.io.IOException
Scans this element from a ReaderTokenizer. The expected text format is assumed to be compatible with that produced by write.

Specified by:
scan in interface Scannable
Parameters:
rtok - Tokenizer from which to scan the element
ref - optional reference object which can be used for resolving references to other objects
Throws:
java.io.IOException - if an I/O or formatting error occured