org.opensourcephysics.media.core
Class ImageCoordSystem

java.lang.Object
  extended by org.opensourcephysics.media.core.ImageCoordSystem

public class ImageCoordSystem
extends java.lang.Object

This manages point and vector transformations between imagespace and worldspace coordinates. Imagespace coordinates of a point refer to its pixel position (to sub-pixel precision) relative to the top left corner of an image. Worldspace coordinates of the point are its scaled position relative to a world reference frame origin and axes. Transformations between coordinate spaces depend on the scale (image units per world unit), the origin (image position of the origin of the world reference frame) and the x-axis direction (angle of the world x-axis measured ccw from the image x-axis). Any or all of these may vary with frame number.

Version:
1.0
Author:
Douglas Brown

Nested Class Summary
static class ImageCoordSystem.Loader
          A class to save and load ImageCoordSystem data.
 
Constructor Summary
ImageCoordSystem()
          Constructs an ImageCoordSystem with a default initial array length.
ImageCoordSystem(int length)
          Constructs an ImageCoordSystem with a specified initial array length.
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Adds a PropertyChangeListener to this coordinate system.
 void addPropertyChangeListener(java.lang.String property, java.beans.PropertyChangeListener listener)
          Adds a PropertyChangeListener to this coordinate system.
 double getAngle(int n)
          Gets the angle of the world x-axis measured ccw from the image x-axis for the specified frame number.
 double getCosine(int n)
          Gets the cosine of the angle of the world x-axis measured ccw from the image x-axis for the specified frame number.
 java.lang.String getDataString(int n)
          Returns a String containing all the data for a single frame number.
 int getLength()
          Gets the length of this image coordinate system.
static XML.ObjectLoader getLoader()
          Returns an XML.ObjectLoader to save and load ImageCoordSystem data.
 double getOriginX(int n)
          Gets the image x position of the world origin for the specified frame number.
 double getOriginY(int n)
          Gets the image y position of the world origin for the specified frame number.
 double getScaleX(int n)
          Gets the scale factor (image units per world unit) along the image x-axis (width direction) for the specified frame number.
 double getScaleY(int n)
          Gets the scale factor (image units per world unit) along the image y-axis (height direction) for the specified frame number.
 double getSine(int n)
          Gets the sine of the angle of the world x-axis measured ccw from the image x-axis for the specified frame number.
 java.awt.geom.AffineTransform getToImageTransform(int n)
          Gets a copy of the affine transform used to convert from worldspace to imagespace for the specified frame number.
 java.awt.geom.AffineTransform getToWorldTransform(int n)
          Gets a copy of the affine transform used to convert from imagespace to worldspace for the specified frame number.
 double imageToWorldX(int n, double imageX, double imageY)
          Converts the specified image position to a world x position for the specified frame number.
 double imageToWorldXComponent(int n, double imageX, double imageY)
          Converts the specified image vector components to a world vector x component for the specified frame number.
 double imageToWorldY(int n, double imageX, double imageY)
          Converts the specified image position to a world y position for the specified frame number.
 double imageToWorldYComponent(int n, double imageX, double imageY)
          Converts the specified image vector components to a world vector y component for the specified frame number.
 boolean isAdjusting()
          Gets the adjusting flag.
 boolean isFixedAngle()
          Gets the fixed angle property.
 boolean isFixedOrigin()
          Gets the fixed origin property.
 boolean isFixedScale()
          Gets the fixed scale property.
 boolean isLocked()
          Gets the locked property.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Removes a PropertyChangeListener from this coordinate system.
 void removePropertyChangeListener(java.lang.String property, java.beans.PropertyChangeListener listener)
          Removes a PropertyChangeListener for a specified property.
 void setAdjusting(boolean adjusting)
          Sets the adjusting flag.
 void setAllAngles(double theta)
          Sets the angle of the world x-axis measured ccw from the image x-axis for all frames.
 void setAllCosineSines(double cos, double sin)
          Sets the cosine and sine of the angle of the world x-axis measured ccw from the image x-axis for all frames.
 void setAllOriginsXY(double valueX, double valueY)
          Sets the image position of the world origin for all frames.
 void setAllScalesX(double value)
          Sets the scale factor (image units per world unit) along the image x-axis (width direction) for all frames.
 void setAllScalesXY(double valueX, double valueY)
          Sets the scale factors (image units per world unit) along the x-axis and y-axis of the image for all frames.
 void setAllScalesY(double value)
          Sets the scale factor (image units per world unit) along the image y-axis (height direction) for all frames.
 void setAllValuesToFrame(int n)
          Sets all origins, angles and scales to those at the specified frame.
 void setAngle(int n, double theta)
          Sets the angle of the world x-axis measured ccw from the image x-axis for the specified frame number.
 void setCosineSine(int n, double cos, double sin)
          Sets the cosine and sine of the angle of the world x-axis measured ccw from the image x-axis for the specified frame number.
 void setCosineSines(int start, int end, double cos, double sin)
          Sets the cosine and sine for all frames in a specified range.
 void setFixedAngle(boolean fixed)
          Sets the fixed angle property.
 void setFixedAngle(boolean fixed, int n)
          Sets the fixed angle property.
 void setFixedOrigin(boolean fixed)
          Sets the fixed origin property.
 void setFixedOrigin(boolean fixed, int n)
          Sets the fixed origin property.
 void setFixedScale(boolean fixed)
          Sets the fixed scale property.
 void setFixedScale(boolean fixed, int n)
          Sets the fixed scale property.
 void setLength(int count)
          Sets the length of this image coordinate system.
 void setLocked(boolean locked)
          Sets the locked property.
 void setOriginsXY(int start, int end, double valueX, double valueY)
          Sets the image position of the world origin for all frames in a specified range.
 void setOriginXY(int n, double valueX, double valueY)
          Sets the image position of the world origin for the specified frame number.
 void setScalesX(int start, int end, double value)
          Sets the horizontal scale factor for all frames in a specified range.
 void setScalesXY(int start, int end, double valueX, double valueY)
          Sets the scale factors for all frames in a specified range.
 void setScalesY(int start, int end, double value)
          Sets the vertical scale factor for all frames in a specified range.
 void setScaleX(int n, double value)
          Sets the scale factor (image units per world unit) along the image x-axis (width direction) for the specified frame number.
 void setScaleXY(int n, double valueX, double valueY)
          Sets the scale factors (image units per world unit) along the x-axis and y-axis of the image for the specified frame number.
 void setScaleY(int n, double value)
          Sets the scale factor (image units per world unit) along the image y-axis (height direction) for the specified frame number.
 double worldToImageX(int n, double worldX, double worldY)
          Converts the specified world position to an image x position for the specified frame number.
 double worldToImageXComponent(int n, double worldX, double worldY)
          Converts the specified world vector components to an image vector x component for the specified frame number.
 double worldToImageY(int n, double worldX, double worldY)
          Converts the specified world position to an image y position for the specified frame number.
 double worldToImageYComponent(int n, double worldX, double worldY)
          Converts the specified world vector components to an image vector y component for the specified frame number.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageCoordSystem

public ImageCoordSystem()
Constructs an ImageCoordSystem with a default initial array length.


ImageCoordSystem

public ImageCoordSystem(int length)
Constructs an ImageCoordSystem with a specified initial array length.

Parameters:
length - the initial length
Method Detail

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a PropertyChangeListener to this coordinate system.

Parameters:
listener - the object requesting property change notification

addPropertyChangeListener

public void addPropertyChangeListener(java.lang.String property,
                                      java.beans.PropertyChangeListener listener)
Adds a PropertyChangeListener to this coordinate system.

Parameters:
property - the name of the property of interest to the listener
listener - the object requesting property change notification

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes a PropertyChangeListener from this coordinate system.

Parameters:
listener - the listener requesting removal

removePropertyChangeListener

public void removePropertyChangeListener(java.lang.String property,
                                         java.beans.PropertyChangeListener listener)
Removes a PropertyChangeListener for a specified property.

Parameters:
property - the name of the property
listener - the listener to remove

setLocked

public void setLocked(boolean locked)
Sets the locked property. When locked, no changes are allowed.

Parameters:
locked - true to lock the coordinate system

isLocked

public boolean isLocked()
Gets the locked property. When locked, no changes are allowed.

Returns:
true if this is locked

setAllValuesToFrame

public void setAllValuesToFrame(int n)
Sets all origins, angles and scales to those at the specified frame.

Parameters:
n - the frame number

setFixedOrigin

public void setFixedOrigin(boolean fixed)
Sets the fixed origin property. When it is fixed, it is in the same position at all times. When setting fixed origin to true, this sets all origins to the position of the origin at frame 0.

Parameters:
fixed - true to fix the origin

setFixedOrigin

public void setFixedOrigin(boolean fixed,
                           int n)
Sets the fixed origin property. When it is fixed, it is in the same position at all times. When setting fixed origin to true, this sets all origins to the position of the origin at frame n.

Parameters:
fixed - true to fix the origin
n - the frame number

isFixedOrigin

public boolean isFixedOrigin()
Gets the fixed origin property.

Returns:
true if origin is fixed

setFixedAngle

public void setFixedAngle(boolean fixed)
Sets the fixed angle property. When it is fixed, it is the same at all times. When setting fixed angle to true, this sets all angles to the angle at frame 0.

Parameters:
fixed - true to fix the angle

setFixedAngle

public void setFixedAngle(boolean fixed,
                          int n)
Sets the fixed angle property. When it is fixed, it is the same at all times. When setting fixed angle to true, this sets all angles to the angle at frame n.

Parameters:
fixed - true to fix the angle
n - the frame number

isFixedAngle

public boolean isFixedAngle()
Gets the fixed angle property.

Returns:
true if angle is fixed

setFixedScale

public void setFixedScale(boolean fixed)
Sets the fixed scale property. When it is fixed, it is the same at all times. When setting fixed scale to true, this sets all scales to the scale at frame 0.

Parameters:
fixed - true to fix the scale

setFixedScale

public void setFixedScale(boolean fixed,
                          int n)
Sets the fixed scale property. When it is fixed, it is the same at all times. When setting fixed scale to true, this sets all scales to the scale at frame n.

Parameters:
fixed - true to fix the scale
n - the frame number

isFixedScale

public boolean isFixedScale()
Gets the fixed scale property.

Returns:
true if scale is fixed

getScaleX

public double getScaleX(int n)
Gets the scale factor (image units per world unit) along the image x-axis (width direction) for the specified frame number.

Parameters:
n - the frame number
Returns:
the x-axis scale factor

getScaleY

public double getScaleY(int n)
Gets the scale factor (image units per world unit) along the image y-axis (height direction) for the specified frame number.

Parameters:
n - the frame number
Returns:
the y-axis scale factor

setScaleX

public void setScaleX(int n,
                      double value)
Sets the scale factor (image units per world unit) along the image x-axis (width direction) for the specified frame number.

Parameters:
n - the frame number
value - the x scale factor

setAllScalesX

public void setAllScalesX(double value)
Sets the scale factor (image units per world unit) along the image x-axis (width direction) for all frames.

Parameters:
value - the x scale factor

setScalesX

public void setScalesX(int start,
                       int end,
                       double value)
Sets the horizontal scale factor for all frames in a specified range.

Parameters:
start - the start frame
end - the end frame
value - the x scale factor

setScaleY

public void setScaleY(int n,
                      double value)
Sets the scale factor (image units per world unit) along the image y-axis (height direction) for the specified frame number.

Parameters:
n - the frame number
value - the y scale factor

setAllScalesY

public void setAllScalesY(double value)
Sets the scale factor (image units per world unit) along the image y-axis (height direction) for all frames.

Parameters:
value - the y scale factor

setScalesY

public void setScalesY(int start,
                       int end,
                       double value)
Sets the vertical scale factor for all frames in a specified range.

Parameters:
start - the start frame
end - the end frame
value - the y scale factor

setScaleXY

public void setScaleXY(int n,
                       double valueX,
                       double valueY)
Sets the scale factors (image units per world unit) along the x-axis and y-axis of the image for the specified frame number.

Parameters:
n - the frame number
valueX - the x scale factor
valueY - the y scale factor

setAllScalesXY

public void setAllScalesXY(double valueX,
                           double valueY)
Sets the scale factors (image units per world unit) along the x-axis and y-axis of the image for all frames.

Parameters:
valueX - the x scale factor
valueY - the y scale factor

setScalesXY

public void setScalesXY(int start,
                        int end,
                        double valueX,
                        double valueY)
Sets the scale factors for all frames in a specified range.

Parameters:
start - the start frame
end - the end frame
valueX - the x scale factor
valueY - the y scale factor

getOriginX

public double getOriginX(int n)
Gets the image x position of the world origin for the specified frame number.

Parameters:
n - the frame number
Returns:
the image x position of the world origin

getOriginY

public double getOriginY(int n)
Gets the image y position of the world origin for the specified frame number.

Parameters:
n - the frame number
Returns:
the image y position of the world origin

setOriginXY

public void setOriginXY(int n,
                        double valueX,
                        double valueY)
Sets the image position of the world origin for the specified frame number.

Parameters:
n - the frame number
valueX - the image x position of the world origin
valueY - the image y position of the world origin

setAllOriginsXY

public void setAllOriginsXY(double valueX,
                            double valueY)
Sets the image position of the world origin for all frames.

Parameters:
valueX - the image x position of the world origin
valueY - the image y position of the world origin

setOriginsXY

public void setOriginsXY(int start,
                         int end,
                         double valueX,
                         double valueY)
Sets the image position of the world origin for all frames in a specified range.

Parameters:
start - the start frame
end - the end frame
valueX - the image x position of the world origin
valueY - the image y position of the world origin

getCosine

public double getCosine(int n)
Gets the cosine of the angle of the world x-axis measured ccw from the image x-axis for the specified frame number.

Parameters:
n - the frame number
Returns:
the cosine of the angle

getSine

public double getSine(int n)
Gets the sine of the angle of the world x-axis measured ccw from the image x-axis for the specified frame number.

Parameters:
n - the frame number
Returns:
the sine of the angle

setCosineSine

public void setCosineSine(int n,
                          double cos,
                          double sin)
Sets the cosine and sine of the angle of the world x-axis measured ccw from the image x-axis for the specified frame number.

Parameters:
n - the frame number
cos - the cosine of the angle
sin - the sine of the angle

setAllCosineSines

public void setAllCosineSines(double cos,
                              double sin)
Sets the cosine and sine of the angle of the world x-axis measured ccw from the image x-axis for all frames.

Parameters:
cos - the cosine of the angle
sin - the sine of the angle

setCosineSines

public void setCosineSines(int start,
                           int end,
                           double cos,
                           double sin)
Sets the cosine and sine for all frames in a specified range.

Parameters:
start - the start frame
end - the end frame
cos - the cosine of the angle
sin - the sine of the angle

getAngle

public double getAngle(int n)
Gets the angle of the world x-axis measured ccw from the image x-axis for the specified frame number.

Parameters:
n - the frame number
Returns:
the angle in radians

setAngle

public void setAngle(int n,
                     double theta)
Sets the angle of the world x-axis measured ccw from the image x-axis for the specified frame number.

Parameters:
n - the frame number
theta - the angle in radians

setAllAngles

public void setAllAngles(double theta)
Sets the angle of the world x-axis measured ccw from the image x-axis for all frames.

Parameters:
theta - the angle in radians

setLength

public void setLength(int count)
Sets the length of this image coordinate system.

Parameters:
count - the total number of frames

getLength

public int getLength()
Gets the length of this image coordinate system.

Returns:
the length

imageToWorldX

public double imageToWorldX(int n,
                            double imageX,
                            double imageY)
Converts the specified image position to a world x position for the specified frame number.

Parameters:
n - the frame number
imageX - the image x position
imageY - the image y position
Returns:
the x coordinate in world space

imageToWorldY

public double imageToWorldY(int n,
                            double imageX,
                            double imageY)
Converts the specified image position to a world y position for the specified frame number.

Parameters:
n - the frame number
imageX - the image x position
imageY - the image y position
Returns:
the y coordinate in world space

worldToImageX

public double worldToImageX(int n,
                            double worldX,
                            double worldY)
Converts the specified world position to an image x position for the specified frame number.

Parameters:
n - the frame number
worldX - the world x position
worldY - the world y position
Returns:
the x coordinate in image space

worldToImageY

public double worldToImageY(int n,
                            double worldX,
                            double worldY)
Converts the specified world position to an image y position for the specified frame number.

Parameters:
n - the frame number
worldX - the world x position
worldY - the world y position
Returns:
the y coordinate in image space

imageToWorldXComponent

public double imageToWorldXComponent(int n,
                                     double imageX,
                                     double imageY)
Converts the specified image vector components to a world vector x component for the specified frame number.

Parameters:
n - the frame number
imageX - the image x components
imageY - the image y components
Returns:
the vector x component in world space

imageToWorldYComponent

public double imageToWorldYComponent(int n,
                                     double imageX,
                                     double imageY)
Converts the specified image vector components to a world vector y component for the specified frame number.

Parameters:
n - the frame number
imageX - the image x components
imageY - the image y components
Returns:
the vector y component in world space

worldToImageXComponent

public double worldToImageXComponent(int n,
                                     double worldX,
                                     double worldY)
Converts the specified world vector components to an image vector x component for the specified frame number.

Parameters:
n - the frame number
worldX - the world x position
worldY - the world y position
Returns:
the vector x component in image space

worldToImageYComponent

public double worldToImageYComponent(int n,
                                     double worldX,
                                     double worldY)
Converts the specified world vector components to an image vector y component for the specified frame number.

Parameters:
n - the frame number
worldX - the world x position
worldY - the world y position
Returns:
the vector y component in image space

getToImageTransform

public java.awt.geom.AffineTransform getToImageTransform(int n)
Gets a copy of the affine transform used to convert from worldspace to imagespace for the specified frame number.

Parameters:
n - the frame number
Returns:
the worldspace to imagespace transform

getToWorldTransform

public java.awt.geom.AffineTransform getToWorldTransform(int n)
Gets a copy of the affine transform used to convert from imagespace to worldspace for the specified frame number.

Parameters:
n - the frame number
Returns:
the imagespace to worldspace transform

setAdjusting

public void setAdjusting(boolean adjusting)
Sets the adjusting flag.

Parameters:
adjusting - true if adjusting

isAdjusting

public boolean isAdjusting()
Gets the adjusting flag.

Returns:
true if adjusting

getDataString

public java.lang.String getDataString(int n)
Returns a String containing all the data for a single frame number. Note: this will be deprecated since its functionality has been replaced by the inner FrameData and FrameDataLoader classes.

Parameters:
n - the frame number
Returns:
the data string

getLoader

public static XML.ObjectLoader getLoader()
Returns an XML.ObjectLoader to save and load ImageCoordSystem data.

Returns:
the object loader