j3d.org Code

org.j3d.util.interpolator
Class ColorInterpolator

java.lang.Object
  extended by org.j3d.util.interpolator.Interpolator
      extended by org.j3d.util.interpolator.ColorInterpolator

public class ColorInterpolator
extends Interpolator

An interpolator that works with color components.

The interpolation routine is just a simple linear interpolation between each of the points. The interpolator may take arbitrarily spaced keyframes and compute correct values.

Color interpolation can be done in the standard RGB space (LINEAR) or using the additional type of HSV_LINEAR. This internally converts all color values to HSV space and then interpolates over that instead.

The RGB<->HSV color space conversions have been taken from Foley & van Dam Computer Graphics Principles and Practice, 2nd Edition, Addison Wesley, 1990.

Internationalisation Resource Names

Version:
$Revision: 1.8 $
Author:
Justin Couch

Field Summary
static int HSV_SPACE
          The interpolator should be in HSV color space
static int RGB_SPACE
          The interpolator should be RGB color space
 
Fields inherited from class org.j3d.util.interpolator.Interpolator
allocatedSize, ARRAY_INCREMENT, currentSize, DEFAULT_SIZE, interpolationType, keys, LINEAR, STEP
 
Constructor Summary
ColorInterpolator()
          Create a new linear interpolator instance with the default size for the number of key values and running in RGB color space.
ColorInterpolator(int size)
          Create an linear RGB interpolator with the given basic size.
ColorInterpolator(int size, int colorSpace)
          Create a new linear interpolator instance with the default size for the number of key values and selectable color space.
ColorInterpolator(int size, int colorSpace, int type)
          Create a interpolator with the given basic size using the interpolation type and color space to interpolate over.
 
Method Summary
 void addHSVKeyFrame(float key, javax.vecmath.Color4f pt)
          Add a key frame set of values at the given key point.
 void addHSVKeyFrame(float key, float h, float s, float v, float a)
          Add a key frame set of values at the given key point.
 void addRGBKeyFrame(float key, javax.vecmath.Color4f pt)
          Add a key frame set of values at the given key point.
 void addRGBKeyFrame(float key, float r, float g, float b, float a)
          Add a key frame set of values at the given key point.
 float[] floatHSVValue(float key)
          Get the interpolated value of the point at the given key value as an RGB value.
 float[] floatRGBValue(float key)
          Get the interpolated value of the point at the given key value as an RGB value.
 javax.vecmath.Color4f pointHSVValue(float key)
          Get the interpolated value of the point at the given key value.
 javax.vecmath.Color4f pointRGBValue(float key)
          Get the interpolated HSV value of the point at the given key value.
 java.lang.String toString()
          Create a string representation of this interpolator's values
 
Methods inherited from class org.j3d.util.interpolator.Interpolator
clear, findKeyIndex
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

HSV_SPACE

public static final int HSV_SPACE
The interpolator should be in HSV color space

See Also:
Constant Field Values

RGB_SPACE

public static final int RGB_SPACE
The interpolator should be RGB color space

See Also:
Constant Field Values
Constructor Detail

ColorInterpolator

public ColorInterpolator()
Create a new linear interpolator instance with the default size for the number of key values and running in RGB color space.


ColorInterpolator

public ColorInterpolator(int size)
Create an linear RGB interpolator with the given basic size.

Parameters:
size - The starting number of items in interpolator

ColorInterpolator

public ColorInterpolator(int size,
                         int colorSpace)
Create a new linear interpolator instance with the default size for the number of key values and selectable color space.


ColorInterpolator

public ColorInterpolator(int size,
                         int colorSpace,
                         int type)
Create a interpolator with the given basic size using the interpolation type and color space to interpolate over.

Parameters:
size - The starting number of items in interpolator
type - The type of interpolation scheme to use
Method Detail

addRGBKeyFrame

public void addRGBKeyFrame(float key,
                           float r,
                           float g,
                           float b,
                           float a)
Add a key frame set of values at the given key point. This will insert the values at the correct color within the array for the given key. If two keys have the same value, the new key is inserted before the old one.

Parameters:
key - The value of the key to use
r - The r component of the color at this key
g - The g component of the color at this key
b - The b component of the color at this key
a - The alpha component of the color at this key

addHSVKeyFrame

public void addHSVKeyFrame(float key,
                           float h,
                           float s,
                           float v,
                           float a)
Add a key frame set of values at the given key point. This will insert the values at the correct color within the array for the given key. If two keys have the same value, the new key is inserted before the old one.

Parameters:
key - The value of the key to use
h - The h component of the color at this key
s - The s component of the color at this key
v - The v component of the color at this key
a - The alpha component of the color at this key
Throws:
java.lang.IllegalArgumentException - s is zero and h is not NaN

addRGBKeyFrame

public void addRGBKeyFrame(float key,
                           javax.vecmath.Color4f pt)
Add a key frame set of values at the given key point. This will insert the values at the correct color within the array for the given key. If two keys have the same value, the new key is inserted before the old one.

Parameters:
key - The value of the key to use
pt - The point data to take information from

addHSVKeyFrame

public void addHSVKeyFrame(float key,
                           javax.vecmath.Color4f pt)
Add a key frame set of values at the given key point. This will insert the values at the correct color within the array for the given key. If two keys have the same value, the new key is inserted before the old one.

Parameters:
key - The value of the key to use
pt - The point data to take information from
Throws:
java.lang.IllegalArgumentException - s is zero and h is not NaN

floatRGBValue

public float[] floatRGBValue(float key)
Get the interpolated value of the point at the given key value as an RGB value. If the key lies outside the range of the values defined, it will be clamped to the end point value. For speed reasons, this will return a reusable float array. Do not modify the values or keep a reference to this as it will change values between calls.

The value will be interpolated according to the colorspace that was specified in the constructor.

Parameters:
key - The key value to get the color for
Returns:
A point representation of the HSV value at that color

pointRGBValue

public javax.vecmath.Color4f pointRGBValue(float key)
Get the interpolated HSV value of the point at the given key value. If the key lies outside the range of the values defined, it will be clamped to the end point value. For speed reasons, this will return a reusable point instance. Do not modify the values or keep a reference to this as it will change values between calls.

The value will be interpolated according to the colorspace that was specified in the constructor.

Parameters:
key - The key value to get the color for
Returns:
A point representation of the HSV value at that color

floatHSVValue

public float[] floatHSVValue(float key)
Get the interpolated value of the point at the given key value as an RGB value. If the key lies outside the range of the values defined, it will be clamped to the end point value. For speed reasons, this will return a reusable float array. Do not modify the values or keep a reference to this as it will change values between calls.

The value will be interpolated according to the colorspace that was specified in the constructor.

Parameters:
key - The key value to get the color for
Returns:
A point representation of the HSV value at that color

pointHSVValue

public javax.vecmath.Color4f pointHSVValue(float key)
Get the interpolated value of the point at the given key value. If the key lies outside the range of the values defined, it will be clamped to the end point value. For speed reasons, this will return a reusable float array. Do not modify the values or keep a reference to this as it will change values between calls.

Parameters:
key - The key value to get the color for
Returns:
An array of the values at that color [h, s, v, a]

toString

public java.lang.String toString()
Create a string representation of this interpolator's values

Overrides:
toString in class java.lang.Object
Returns:
A nicely formatted string representation

j3d.org Code

Latest Info from http://code.j3d.org/
Copyright © 2001 - j3d.org