Class pmr.simplegraph.Scaler2D
All Packages Class Hierarchy This Package Previous Next Index
Class pmr.simplegraph.Scaler2D
java.lang.Object
|
+----pmr.simplegraph.Scaler2D
- public class Scaler2D
- extends Object
Scaler2D provdies a
simple viewport manager for 2D graphics based on GKS-like strategy
A graphical Object (e.g. a pmr.simplegraph.DrawableObject) can contain a
Scaler2D. This allows for scaling and translation with/without aspect
ratio constancy (but NOT oblique or perspective transformations). The
object is drawn in world coordinates (WC) which are Real, and rendered in
Screen or WorkStationViewPort coordinates which are Int. In its simplest
mode, the Scaler2D can be created with the XYRange of the object to be
drawn and will scale it automatically to the desired screen view port.
GKS allows for two other intermediate coordinate systems/viewports , which can
be explored and use Normalised Device coordinates (NDC).
The Scaler2D can be configured to react to Frames being resized so that
the drawing area can be automatically scaled
- Author:
- (C) P. Murray-Rust, 1996
-
Scaler2D()
- default - world coords are 0-1, 0-1
-
Scaler2D(Real2Range)
- there are only two constructors you are allowed - there must be a
Real2Range for the drawing coordinates (WorldCoordinates).
-
Scaler2D(Real2Range, Int2Range)
- See above, but with the additon of a screen area (in screen coordinates)
-
Scaler2D(Scaler2D)
- copy constructor
-
clearWorkStationViewPort(Graphics)
- clears everything within WorkStationViewPort
-
clipToBoundingBox(Graphics)
- clip to boundingBox.
-
clipToScreenBoundingBox(Graphics)
- clip to screen limits (usually larger than object bounding box
-
draw(Graphics, RealArray)
- draw a simple graph of a RealArray with connecting lines
-
drawBoundingBox(Graphics)
- only useful if continually redrawn...
-
drawCircle(Graphics, double, double, int)
-
-
drawLine(Graphics, double, double, double, double)
- analogues of awt.Graphics, but in double WC coords;
-
drawManipulatorBox(Graphics)
- default manipulator is whole screen port (WorkStationViewPort)
-
drawManipulatorBox(Graphics, Int2Range)
- screen coordinates drawing of manipulator box
-
drawManipulatorBox(Graphics, Real2Range)
- WorldCoords drawing of manipulator box
-
drawRect(Graphics, double, double, double, double)
-
-
drawRect(Graphics, Int2Range)
- draw a box in screen coords - should be in Util...
-
drawRect(Graphics, Real2Range)
-
-
drawString(Graphics, String, double, double)
-
-
drawWorkStationViewPort(Graphics)
- draws box round limits of screen VP.
-
getScaleNDC2Screen()
-
-
getScaleWC2NDC()
-
-
getScaleWC2Screen()
-
-
getScreen()
-
-
getScreenBoundingBox()
- this gets the screen coordinates RELATING TO THE WC BOUNDING BOX.
-
getSquareSize()
- gets the size of the little green squares and the pick tolerance
-
getViewPort()
-
-
getWCBoundingBox()
- get bounding box in world coordinates
-
getWindow()
-
-
getWorkStationViewPort()
- synonymous with getScreen()
-
getWorkStationWindow()
-
-
hasBeenRescaled()
- ask if object has been rescaled since we last asked.
-
resetWindow()
- reset window to intial value
-
screen2NDC(Int2Range)
-
-
screen2NDC(IntRange, IntRange)
-
-
screen2WC(Int2Range)
-
-
screen2WC(IntRange, IntRange)
-
-
screenDeltaXtoWC(int)
- scale a screen distance to a WC distance (don't confuse with coords)
-
screenDeltaYtoWC(int)
- scale a screen distance to a WC distance (don't confuse with coords)
-
selectManipulatorBox(Int2, Int2Range)
- does the point x,y select part of a manipulator box? (tolerance for
corners and edges is `+-square`.
-
setIsometric(boolean)
- Changes aspect ratio of screen to be isometric
Routine is used to provide orthogonal space for plotting.
-
setSquareSize(int)
- sets the size of the little green squares and the pick tolerance
-
setViewPort(double, double, double, double)
- Maps world coordinates to a viewport (in Normalised device coordinates)
Similar to GSVP in GKS
maps drawing area onto NDC.
-
setWindow(double, double, double, double)
- sets a drawing window in world coordinates;
similar to GSWN in GKS
Maps drawing area onto NDC.
-
setWindow(Real2Range)
- set new window in World Coordinates
-
setWindow(RealRange, RealRange)
- alternative form of setWindow taking Ranges as arguments
-
setWorkStationViewPort(int, int, int, int)
- Defines screen area to be used in graphics.
-
setWorkStationViewPort(Int2Range)
- as above, but using an Int2Range for screen limits
-
setWorkStationWindow(double, double, double, double)
- Defines workStation window to be used in graphics.
-
toString()
-
-
wc2Screen(Real2Range)
- convert a WC box to screen coords
-
xNDC2Screen(double)
-
-
xScreen2NDC(int)
-
-
xScreen2WC(int)
-
-
xWC2Screen(double)
-
-
yNDC2Screen(double)
-
-
yScreen2NDC(int)
-
-
yScreen2WC(int)
-
-
yWC2Screen(double)
-
Scaler2D
public Scaler2D()
- default - world coords are 0-1, 0-1
Scaler2D
public Scaler2D(Real2Range box) throws InvalidArgumentsException
- there are only two constructors you are allowed - there must be a
Real2Range for the drawing coordinates (WorldCoordinates). This
constructor uses the default screen area.
- Throws: InvalidArgumentsException
- bad range (max < min, etc.)
Scaler2D
public Scaler2D(Real2Range box,
Int2Range screenLimits) throws InvalidArgumentsException
- See above, but with the additon of a screen area (in screen coordinates)
- Throws: InvalidArgumentsException
- bad range (max < min, etc.)
Scaler2D
public Scaler2D(Scaler2D s)
- copy constructor
resetWindow
public void resetWindow()
- reset window to intial value
getWindow
public Real2Range getWindow()
getViewPort
public Real2Range getViewPort()
getWorkStationWindow
public Real2Range getWorkStationWindow()
getScreen
public Int2Range getScreen()
getWorkStationViewPort
public Int2Range getWorkStationViewPort()
- synonymous with getScreen()
getScaleWC2NDC
public Real2 getScaleWC2NDC()
getScaleNDC2Screen
public Real2 getScaleNDC2Screen()
getScaleWC2Screen
public Real2 getScaleWC2Screen()
screenDeltaXtoWC
public double screenDeltaXtoWC(int deltax)
- scale a screen distance to a WC distance (don't confuse with coords)
screenDeltaYtoWC
public double screenDeltaYtoWC(int deltay)
- scale a screen distance to a WC distance (don't confuse with coords)
setIsometric
public void setIsometric(boolean iso)
- Changes aspect ratio of screen to be isometric
Routine is used to provide orthogonal space for plotting.
If the screen is square
World coordinates are set equal to the screen coordinates and
are necessarily isometric.
For an oblong screen the routine maps the largest possible
square onto the screen.
hasBeenRescaled
public boolean hasBeenRescaled()
- ask if object has been rescaled since we last asked. This can be useful
if coordinates are cached and we need to know whether to recalculate
setViewPort
public void setViewPort(double xmin,
double xmax,
double ymin,
double ymax) throws InvalidArgumentsException
- Maps world coordinates to a viewport (in Normalised device coordinates)
Similar to GSVP in GKS
maps drawing area onto NDC. Thus the user will normally
draw within the limits XMIN to XMAX and YMIN to YMAX.
This will then be mapped by default onto the screen (This mapping
can be altered with setWorkStationWindow and setWorkStationViewPort)
- Throws: InvalidArgumentsException
- bad range (max < min, etc.)
setWorkStationViewPort
public void setWorkStationViewPort(int xmin,
int xmax,
int ymin,
int ymax) throws InvalidArgumentsException
- Defines screen area to be used in graphics. Similar to GSWKVP in GKS
Maps NDC onto screen limits (XMIN to YMAX); use with care as you will
need to know how the screen space is being managed.
- Throws: InvalidArgumentsException
- bad range (max < min, etc.)
setWorkStationViewPort
public void setWorkStationViewPort(Int2Range screenLimits) throws InvalidArgumentsException
- as above, but using an Int2Range for screen limits
- Throws: InvalidArgumentsException
- bad range (max < min, etc.)
setWorkStationWindow
public void setWorkStationWindow(double xmin,
double xmax,
double ymin,
double ymax) throws InvalidArgumentsException
- Defines workStation window to be used in graphics.
Similar to GSWKWN in GKS
- Throws: InvalidArgumentsException
- bad range (max < min, etc.)
setWindow
public void setWindow(double xmin,
double xmax,
double ymin,
double ymax) throws InvalidArgumentsException
- sets a drawing window in world coordinates;
similar to GSWN in GKS
Maps drawing area onto NDC. Thus the user will normally
draw within the limits XMIN to XMAX and YMIN to YMAX.
The result will be mapped by default onto a square 0.0,1.0 0.0,1.0.
This mapping can be altered with setViewPort().
This will then be mapped by default onto the screen (This mapping
can be altered with setWorkStationWindow and setWorkStationViewPort).
If metric properties are to be preserved, use setIsometric()
- Throws: InvalidArgumentsException
- bad range (max < min, etc.)
setWindow
public void setWindow(RealRange xrange,
RealRange yrange) throws InvalidArgumentsException
- alternative form of setWindow taking Ranges as arguments
- Throws: InvalidArgumentsException
- bad range (max < min, etc.)
setWindow
public void setWindow(Real2Range box) throws InvalidArgumentsException
- set new window in World Coordinates
- Throws: InvalidArgumentsException
- bad range (max < min, etc.)
drawBoundingBox
public void drawBoundingBox(Graphics g)
- only useful if continually redrawn...
drawWorkStationViewPort
public void drawWorkStationViewPort(Graphics g)
- draws box round limits of screen VP. Might be different from
object's bounding box
clearWorkStationViewPort
public void clearWorkStationViewPort(Graphics g)
- clears everything within WorkStationViewPort
drawManipulatorBox
public void drawManipulatorBox(Graphics g)
- default manipulator is whole screen port (WorkStationViewPort)
drawManipulatorBox
public void drawManipulatorBox(Graphics g,
Real2Range box)
- WorldCoords drawing of manipulator box
setSquareSize
public void setSquareSize(int size)
- sets the size of the little green squares and the pick tolerance
getSquareSize
public int getSquareSize()
- gets the size of the little green squares and the pick tolerance
drawManipulatorBox
public void drawManipulatorBox(Graphics g,
Int2Range ibox)
- screen coordinates drawing of manipulator box
selectManipulatorBox
public static Int2 selectManipulatorBox(Int2 point,
Int2Range ibox)
- does the point x,y select part of a manipulator box? (tolerance for
corners and edges is `+-square`. If not, returns null; else returns
LEFT,TOP; LEFT, BOTTOM; RIGHT, TOP; RIGHT, BOTTOM for the corners
LEFT,MID; MID, BOTTOM; RIGHT, MID; MID, TOP for the Mmipoints
MID, MID if any edge is selected
Returns null if either arg is null
getScreenBoundingBox
public Int2Range getScreenBoundingBox()
- this gets the screen coordinates RELATING TO THE WC BOUNDING BOX.
It may not be the same as the WorkStationViewPort (due to ViewPort and
isometric scaling
getWCBoundingBox
public Real2Range getWCBoundingBox()
- get bounding box in world coordinates
clipToBoundingBox
public Graphics clipToBoundingBox(Graphics g)
- clip to boundingBox. returns a new, clipped Graphics object to
which subsequent drawing should be done if clipping required
clipToScreenBoundingBox
public Graphics clipToScreenBoundingBox(Graphics g)
- clip to screen limits (usually larger than object bounding box
wc2Screen
public Int2Range wc2Screen(Real2Range box)
- convert a WC box to screen coords
drawRect
public void drawRect(Graphics g,
Int2Range ibox)
- draw a box in screen coords - should be in Util...
drawLine
public void drawLine(Graphics g,
double x1,
double y1,
double x2,
double y2)
- analogues of awt.Graphics, but in double WC coords;
drawRect
public void drawRect(Graphics g,
double xleft,
double ytop,
double width,
double height)
drawRect
public void drawRect(Graphics g,
Real2Range box)
drawString
public void drawString(Graphics g,
String text,
double x,
double y)
drawCircle
public void drawCircle(Graphics g,
double x,
double y,
int radius)
draw
public void draw(Graphics g,
RealArray f) throws ArrayTooSmallException
- draw a simple graph of a RealArray with connecting lines
- Throws: ArrayTooSmallException
- array has 1 or 0 values
xWC2Screen
public int xWC2Screen(double coord)
yWC2Screen
public int yWC2Screen(double coord)
xScreen2WC
public double xScreen2WC(int coord)
yScreen2WC
public double yScreen2WC(int coord)
screen2WC
public Real2Range screen2WC(Int2Range xyr)
screen2WC
public Real2Range screen2WC(IntRange xr,
IntRange yr)
xNDC2Screen
public int xNDC2Screen(double coord)
yNDC2Screen
public int yNDC2Screen(double coord)
xScreen2NDC
public double xScreen2NDC(int coord)
yScreen2NDC
public double yScreen2NDC(int coord)
screen2NDC
public Real2Range screen2NDC(Int2Range xyr)
screen2NDC
public Real2Range screen2NDC(IntRange xr,
IntRange yr)
toString
public String toString()
- Overrides:
- toString in class Object
All Packages Class Hierarchy This Package Previous Next Index