Package org.opensourcephysics.media.core
Class ImageCoordSystem
java.lang.Object
org.opensourcephysics.display.OSPRuntime.Supported
org.opensourcephysics.media.core.ImageCoordSystem
- Direct Known Subclasses:
ReferenceFrame
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 ClassesModifier and TypeClassDescriptionstatic 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 -
Constructor Summary
ConstructorsConstructorDescriptionConstructs 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 TypeMethodDescriptionvoid
void
dispose()
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.static XML.ObjectLoader
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.getToImageTransform
(int n) Gets a copy of the affine transform used to convert from worldspace to imagespace for the specified frame number.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
Gets the adjusting flag.boolean
Gets the fixed angle property.boolean
Gets the fixed origin property.boolean
Gets the fixed scale property.boolean
isLocked()
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
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.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 org.opensourcephysics.display.OSPRuntime.Supported
addListeners, addPropertyChangeListener, addPropertyChangeListener, dispose, firePropertyChange, firePropertyChange, removeListeners, removePropertyChangeListener, removePropertyChangeListener
-
Field Details
-
PROPERTY_COORDS_TRANSFORM
- See Also:
-
PROPERTY_COORDS_LOCKED
- See Also:
-
PROPERTY_COORDS_FIXEDSCALE
- See Also:
-
PROPERTY_COORDS_FIXEDORIGIN
- See Also:
-
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
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 originn
- 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 anglen
- 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 scalen
- 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 numbervalue
- 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 frameend
- the end framevalue
- 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 numbervalue
- 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 frameend
- the end framevalue
- 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 numbervalueX
- the x scale factorvalueY
- 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 factorvalueY
- 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 frameend
- the end framevalueX
- the x scale factorvalueY
- 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 numbervalueX
- the image x position of the world originvalueY
- 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 originvalueY
- 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 frameend
- the end framevalueX
- the image x position of the world originvalueY
- 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 numbercos
- the cosine of the anglesin
- 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 anglesin
- 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 frameend
- the end framecos
- the cosine of the anglesin
- 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 numbertheta
- 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 numberimageX
- the image x positionimageY
- 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 numberimageX
- the image x positionimageY
- 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 numberworldX
- the world x positionworldY
- 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 numberworldX
- the world x positionworldY
- 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 numberimageX
- the image x componentsimageY
- 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 numberimageX
- the image x componentsimageY
- 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 numberworldX
- the world x positionworldY
- 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 numberworldX
- the world x positionworldY
- the world y position- Returns:
- the vector y component in image space
-
getToImageTransform
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
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
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
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
- Overrides:
addPropertyChangeListenerSafely
in classOSPRuntime.Supported
-
dispose
public void dispose()- Overrides:
dispose
in classOSPRuntime.Supported
-