public class NumericList extends java.lang.Object implements java.lang.Cloneable, java.lang.Iterable<NumericListKnot>, Scannable
A numeric list can be constructed to contain a set of subvectors representing rotations, using a representation specified by a RotationRep. For Linear, Cubic and CubicStep interpolation, rotation subvectors are interpolated as curves on the surface of SO(3), as originally described by Ken Shoemake in his SIGGRAPH 1985 paper "Animating Rotation with Quaternion Curves".
Modifier and Type | Field and Description |
---|---|
boolean |
debug |
Constructor and Description |
---|
NumericList(int vsize)
Creates an empty numeric list for holding vectors of a prescribed size.
|
NumericList(int vsize,
RotationRep rotRep,
int[] offsets)
Creates an empty numeric list containing rotation subvectors with
specified representation and offsets.
|
Modifier and Type | Method and Description |
---|---|
NumericListKnot |
add(double t,
double... vals)
Creates a knot with the specified values and time and adds it into this
numeric list.
|
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.
|
NumericListKnot |
addAndAdjustRotations(NumericListKnot knot)
Adds a knot into this numeric list, and adjust the value of any rotation
subvector to the (redundant) representation "closest" to that in
the nearest existing knot.
|
void |
adjustRotationValues(VectorNd vr,
VectorNd v,
double t)
Copies the values
v into vr , while adjusting the value of
any rotation subvector to the (redundant) representation "closest" to
that in the knot nearest to t . |
NumericListKnot |
adjustRotationValues(VectorNd vr,
VectorNd v,
double t,
NumericListKnot last)
Copies the values
v into vr , while adjusting the value of
any rotation subvector to the (redundant) representation "closest" to
that in the knot nearest to t . |
void |
applyMovingAverageSmoothing(int winSize)
Smooths the values in this list by applying a mean average filter over a
moving window of specified size.
|
void |
applySavitzkyGolaySmoothing(int winSize,
int deg)
Smooths the values in this list by applying Savitzky-Golay smoothing over
a moving window of specified size.
|
static void |
checkRotationSubvecOffsets(int[] offsets,
RotationRep rotRep,
int vsize)
Checks a set of specified rotation subvector offsets to ensure that
they do not overlap and all fit within the overall vector.
|
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) |
int |
getDerivSize()
Returns the size of the derivative vector associated with this list.
|
NumericListKnot |
getFirst()
Returns the first knot in this list.
|
Interpolation |
getInterpolation()
Returns the interpolation method for this list.
|
Interpolation.Order |
getInterpolationOrder()
Returns the interpolation order for this list.
|
NumericListKnot |
getKnot(int idx)
Returns the idx-th knot in this list, or
null if so such
knot exists; |
NumericListKnot |
getLast()
Returns the last knot in this list.
|
VectorNd |
getMaxValues()
Returns a vector giving the maximum values across all knots in this list.
|
void |
getMinMaxValues(double[] minMax) |
void |
getMinMaxValues(VectorNd min,
VectorNd max) |
VectorNd |
getMinValues()
Returns a vector giving the minimum values across all knots in this list.
|
int |
getNumKnots()
Returns the number of knots in this list.
|
RotationRep |
getRotationRep()
Returns the representation associated with rotation subvectors of this
list, or null if there are no rotation subvectors.
|
int[] |
getRotationSubvecOffsets()
Returns an array giving the offsets of any rotation subvectors associated
with this list.
|
void |
getSumSquaredValues(VectorNd sumsqr)
Returns the sum of the square of each vector element over all the knots.
|
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)
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 method,
NumericListKnot last) |
void |
interpolateCubic(VectorNd v,
NumericListKnot prev,
double t) |
void |
interpolateDeriv(VectorNd v,
double t)
Finds the derivative associated with a particular value of t, by
differentiating the function implied by the knot points and the list's
interpolation method, as returned by
getInterpolation() . |
NumericListKnot |
interpolateDeriv(VectorNd v,
double t,
Interpolation.Order order,
NumericListKnot last)
Finds the derivative associated with a particular value of t, by
differentiating the function implied by the knot points and the
interpolation order specified by
order . |
NumericListKnot |
interpolateDeriv(VectorNd v,
double t,
Interpolation method,
NumericListKnot last) |
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.
|
void |
numericalDeriv(VectorNd v,
double t)
Finds the derivative associated with a particular value of t, based on
numerical differentation of the current knot points.
|
NumericListKnot |
numericalDeriv(VectorNd v,
double t,
NumericListKnot last)
Finds the derivative associated with a particular value of t, based on
numerical differentation of the current knot points.
|
int |
numRotationSubvecs()
Queries the number of rotation subvectors.
|
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 |
scale(double s)
Uniformly scales all the values in this 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 |
setInterpolationOrder(Interpolation.Order order)
Sets the interpolation order for this list.
|
void |
setValues(double[][] vals)
Sets the values of this numeric list from a two dimensional array of
doubles.
|
void |
setValues(NumericList src,
double tscale,
double toffset)
Sets the values of this numeric list from those of another numeric list.
|
void |
shiftTime(double t) |
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.
|
public NumericList(int vsize)
vsize
- size of the vectors that will form this listpublic NumericList(int vsize, RotationRep rotRep, int[] offsets)
vsize
- size of the vectors that will form this listrotRep
- how rotations are represented with the subvectorsoffsets
- offsets for the rotation subvectorspublic void setInterpolation(Interpolation method)
Step
with no end data extension.method
- new interpolation method.public void setInterpolationOrder(Interpolation.Order order)
Step
.order
- new interpolation order;public Interpolation getInterpolation()
setInterpolation(maspack.interpolation.Interpolation)
public Interpolation.Order getInterpolationOrder()
setInterpolationOrder(maspack.interpolation.Interpolation.Order)
public int getVectorSize()
public int getDerivSize()
public RotationRep getRotationRep()
public int[] getRotationSubvecOffsets()
public static void checkRotationSubvecOffsets(int[] offsets, RotationRep rotRep, int vsize)
offsets
- offset values to be checkedrotRep
- rotation representation associated with the subvectorsvsize
- overall vector sizepublic int numRotationSubvecs()
public NumericListKnot add(NumericListKnot knot)
knot
- knot to add to the listjava.lang.IllegalArgumentException
- if the knot's vector has a size not equal to the vector size for this
list.getVectorSize()
public NumericListKnot addAndAdjustRotations(NumericListKnot knot)
knot
- knot to add to the listjava.lang.IllegalArgumentException
- if the knot's vector has a size not equal to the vector size for this
list.getVectorSize()
public NumericListKnot add(Vector vals, double t)
vals
- values for the knott
- time at which the knot should be addedjava.lang.IllegalArgumentException
- if values
has a size less than the vector size for this
list.getVectorSize()
public NumericListKnot add(double t, double... vals)
t
- time at which the knot should be addedvals
- values for the knot; the number must be >=
the list's vector
sizejava.lang.IllegalArgumentException
- if values
has a size less than the vector size for this
list.getVectorSize()
public NumericListKnot add(NumericListKnot knot, NumericListKnot last)
public void shiftTime(double t)
public VectorNd getMinValues()
public VectorNd getMaxValues()
public void getMinMaxValues(double[] minMax)
public void getSumSquaredValues(VectorNd sumsqr)
sumsqr
- returns the mean square valuespublic NumericListKnot remove(double t)
t
- time of the knot to removepublic void remove(NumericListKnot knot)
knot
- knot to removepublic void clearAfter(NumericListKnot knot)
knot
- all knots following this one will be removedpublic NumericListKnot findKnotAtOrBefore(double t, NumericListKnot last)
t
- specified valuepublic NumericListKnot findKnotClosest(double t)
t
- specified valuepublic NumericListKnot findKnotClosest(double t, NumericListKnot last)
public void interpolate(VectorNd v, double t)
getInterpolation()
.
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.v
- stores the interpolation resultt
- value to interpolate forpublic void interpolateDeriv(VectorNd v, double t)
getInterpolation()
. If t lies
before the start or after the end of the list, the derivative will be
zero.v
- stores the derivative resultt
- value to find the derivative atpublic void numericalDeriv(VectorNd v, double t)
v
- stores the derivative resultt
- value to find the derivative forpublic void adjustRotationValues(VectorNd vr, VectorNd v, double t)
v
into vr
, while adjusting the value of
any rotation subvector to the (redundant) representation "closest" to
that in the knot nearest to t
.vr
- stores the resultv
- values to copy and adjust if neededt
- time associated with the valuespublic NumericListKnot adjustRotationValues(VectorNd vr, VectorNd v, double t, NumericListKnot last)
v
into vr
, while adjusting the value of
any rotation subvector to the (redundant) representation "closest" to
that in the knot nearest to t
.
The method returns the knot that is nearest to t
. By using
this returned value as the last
argument in subsequent method
calls, one can traverse forward or backward (in time) along the list with
O(1) complexity.
vr
- stores the resultv
- values to copy and adjust if neededt
- time associated with the valueslast
- knot point used to start the search for the knot containing t
t
public void interpolateCubic(VectorNd v, NumericListKnot prev, double t)
public NumericListKnot interpolate(VectorNd v, double t, Interpolation method, NumericListKnot last)
public NumericListKnot interpolateDeriv(VectorNd v, double t, Interpolation method, NumericListKnot last)
public NumericListKnot interpolate(VectorNd v, double t, Interpolation.Order order, boolean extendData, NumericListKnot last)
order
. If t lies before the start or after the end of the
list, the interpolation value is set to either the first or last knot
value, or zero, depending on whether extendData
is true
or false
.
The method returns the nearest knot that is at or before t
.
By using this returned value as the last
argument in subsequent
method calls, one can traverse forward or backward (in time) along the
list with O(1) complexity.
v
- stores the interpolation resultt
- value to interpolate fororder
- interpolation orderextendData
- if true
, data is extended beyond the start and end of the list
based on the first and last knot valueslast
- knot point used to start the search for the knot containing t
t
public NumericListKnot interpolateDeriv(VectorNd v, double t, Interpolation.Order order, NumericListKnot last)
order
. If t lies before the
start or after the end of the list, the derivative will be zero.
The method returns the nearest knot that is at or before t
.
By using this returned value as the last
argument in subsequent
method calls, one can traverse forward or backward (in time) along the
list with O(1) complexity.
v
- stores the derivative resultt
- value to find the derivative atorder
- interpolation orderlast
- knot point used to start the search for the knot containing t
t
public NumericListKnot numericalDeriv(VectorNd v, double t, NumericListKnot last)
The method returns the nearest knot that is at or before t
.
By using this returned value as the last
argument in subsequent
method calls, one can traverse forward or backward (in time) along the
list with O(1) complexity.
v
- stores the derivative resultt
- value to find the derivative forlast
- knot point used to start the search for the knot containing t
t
public NumericListKnot getFirst()
public NumericListKnot getLast()
public NumericListKnot getKnot(int idx)
null
if so such
knot exists;public int getNumKnots()
public boolean isEmpty()
public void clear()
public void scale(double s)
s
- scale factorpublic void applyMovingAverageSmoothing(int winSize)
winSize
- size of the averaging window. The value should be odd; if
it is even, it will be incremented internally to be odd. The method does
nothing if the value is is less than 1. Finally, winSize
will be
reduced if necessary to fit the number of knots.public void applySavitzkyGolaySmoothing(int winSize, int deg)
deg
, and then using this to recompute the value in the middle of the
window. The polynomial is also used to interpolate the first and last
winSize/2
values, since it is not possible to center the window
on these.deg
- degree of the smoothing polynomial. Must be at least 1.winSize
- size of the averaging window. The value must be >=
deg+1
and should also be odd; if it is even, it will be incremented
internally to be odd. Finally, winSize
will be reduced if
necessary to fit the number of knots.public java.util.Iterator<NumericListKnot> iterator()
iterator
in interface java.lang.Iterable<NumericListKnot>
public double[][] getValues()
public void setValues(double[][] vals)
getValues()
.vals
- Values used to set this numeric listpublic void setValues(NumericList src, double tscale, double toffset)
The time values t
in this list are set from the time values
ts
in the source list according to
t = tscale ts + toffset
src
- numeric list to copy values fromtscale
- scale factor for source time valuestoffset
- offset for source time valuespublic boolean equals(NumericList list)
list
- numeric list to compare withpublic java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(java.lang.String fmtStr)
printf
style format string.
For a description of the format string syntax, see NumberFormat
.fmtStr
- numeric format specificationpublic java.lang.String toString(NumberFormat fmt)
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.fmt
- numeric formatpublic java.lang.String toStringSuper()
public java.lang.Object clone()
clone
in class java.lang.Object
public boolean isWritable()
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.isWritable
in interface Scannable
true
if this component should be written to
secondary storage.public void write(java.io.PrintWriter pw, NumberFormat fmt, java.lang.Object ref) throws java.io.IOException
scan
and complete
enough to allow full reconstruction of the element.public void scan(ReaderTokenizer rtok, java.lang.Object ref) throws java.io.IOException
write
.