Class ImageCoordSystem

java.lang.Object
org.opensourcephysics.display.OSPRuntime.Supported
org.opensourcephysics.media.core.ImageCoordSystem
Direct Known Subclasses:
ReferenceFrame

public class ImageCoordSystem extends OSPRuntime.Supported
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

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Inner class containing the coords data for a single frame number.
    static class 
    A class to save and load ImageCoordSystem data.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected boolean
     
    protected boolean
     
    static final String
     
    static final String
     
    static final String
     
    static final String
     
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs an ImageCoordSystem with a default initial array length.
    ImageCoordSystem(int length)
    Constructs an ImageCoordSystem with a specified initial array length.
    ImageCoordSystem(int frameCount, Video adapter)
    Not at all clear why this is useful.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    void
     
    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.
    Gets the set of key frames.
    int
    Gets the length of this image coordinate system.
    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.
    Gets a copy of the affine transform used to convert from worldspace to imagespace for the specified frame number.
    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
    Gets the adjusting flag.
    boolean
    Gets the fixed angle property.
    boolean
    Gets the fixed origin property.
    boolean
    Gets the fixed scale property.
    boolean
    Gets the locked 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
    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.
    boolean
    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.
    protected void
    Updates all transforms used to convert between drawing spaces.
    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

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • PROPERTY_COORDS_TRANSFORM

      public static final String PROPERTY_COORDS_TRANSFORM
      See Also:
    • PROPERTY_COORDS_LOCKED

      public static final String PROPERTY_COORDS_LOCKED
      See Also:
    • PROPERTY_COORDS_FIXEDSCALE

      public static final String PROPERTY_COORDS_FIXEDSCALE
      See Also:
    • PROPERTY_COORDS_FIXEDORIGIN

      public static final String PROPERTY_COORDS_FIXEDORIGIN
      See Also:
    • PROPERTY_COORDS_FIXEDANGLE

      public static final String PROPERTY_COORDS_FIXEDANGLE
      See Also:
    • ignoreUpdateRequests

      protected boolean ignoreUpdateRequests
    • firePropChange

      protected boolean firePropChange
  • Constructor Details

    • 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
    • ImageCoordSystem

      public ImageCoordSystem(int frameCount, Video adapter)
      Not at all clear why this is useful. Do the Videos somehow need this?
      Parameters:
      frameCount -
      adapter -
  • Method Details

    • 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 boolean 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 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 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
    • getKeyFrames

      public TreeSet<Integer> getKeyFrames()
      Gets the set of key frames. This returns the actual Set, not a copy, so the entries can be converted when exporting a video clip/tracker panel combination.
      Returns:
      the Set
    • getLoader

      public static XML.ObjectLoader getLoader()
      Returns an XML.ObjectLoader to save and load ImageCoordSystem data.
      Returns:
      the object loader
    • updateAllTransforms

      protected void updateAllTransforms()
      Updates all transforms used to convert between drawing spaces.
    • addPropertyChangeListenerSafely

      public void addPropertyChangeListenerSafely(PropertyChangeListener listener)
      Overrides:
      addPropertyChangeListenerSafely in class OSPRuntime.Supported
    • dispose

      public void dispose()
      Overrides:
      dispose in class OSPRuntime.Supported