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

Constructor Index

 o Scaler2D()
default - world coords are 0-1, 0-1
 o Scaler2D(Real2Range)
there are only two constructors you are allowed - there must be a Real2Range for the drawing coordinates (WorldCoordinates).
 o Scaler2D(Real2Range, Int2Range)
See above, but with the additon of a screen area (in screen coordinates)
 o Scaler2D(Scaler2D)
copy constructor

Method Index

 o clearWorkStationViewPort(Graphics)
clears everything within WorkStationViewPort
 o clipToBoundingBox(Graphics)
clip to boundingBox.
 o clipToScreenBoundingBox(Graphics)
clip to screen limits (usually larger than object bounding box
 o draw(Graphics, RealArray)
draw a simple graph of a RealArray with connecting lines
 o drawBoundingBox(Graphics)
only useful if continually redrawn...
 o drawCircle(Graphics, double, double, int)
 o drawLine(Graphics, double, double, double, double)
analogues of awt.Graphics, but in double WC coords;
 o drawManipulatorBox(Graphics)
default manipulator is whole screen port (WorkStationViewPort)
 o drawManipulatorBox(Graphics, Int2Range)
screen coordinates drawing of manipulator box
 o drawManipulatorBox(Graphics, Real2Range)
WorldCoords drawing of manipulator box
 o drawRect(Graphics, double, double, double, double)
 o drawRect(Graphics, Int2Range)
draw a box in screen coords - should be in Util...
 o drawRect(Graphics, Real2Range)
 o drawString(Graphics, String, double, double)
 o drawWorkStationViewPort(Graphics)
draws box round limits of screen VP.
 o getScaleNDC2Screen()
 o getScaleWC2NDC()
 o getScaleWC2Screen()
 o getScreen()
 o getScreenBoundingBox()
this gets the screen coordinates RELATING TO THE WC BOUNDING BOX.
 o getSquareSize()
gets the size of the little green squares and the pick tolerance
 o getViewPort()
 o getWCBoundingBox()
get bounding box in world coordinates
 o getWindow()
 o getWorkStationViewPort()
synonymous with getScreen()
 o getWorkStationWindow()
 o hasBeenRescaled()
ask if object has been rescaled since we last asked.
 o resetWindow()
reset window to intial value
 o screen2NDC(Int2Range)
 o screen2NDC(IntRange, IntRange)
 o screen2WC(Int2Range)
 o screen2WC(IntRange, IntRange)
 o screenDeltaXtoWC(int)
scale a screen distance to a WC distance (don't confuse with coords)
 o screenDeltaYtoWC(int)
scale a screen distance to a WC distance (don't confuse with coords)
 o selectManipulatorBox(Int2, Int2Range)
does the point x,y select part of a manipulator box? (tolerance for corners and edges is `+-square`.
 o setIsometric(boolean)
Changes aspect ratio of screen to be isometric

Routine is used to provide orthogonal space for plotting.

 o setSquareSize(int)
sets the size of the little green squares and the pick tolerance
 o 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.

 o setWindow(double, double, double, double)
sets a drawing window in world coordinates; similar to GSWN in GKS

Maps drawing area onto NDC.

 o setWindow(Real2Range)
set new window in World Coordinates
 o setWindow(RealRange, RealRange)
alternative form of setWindow taking Ranges as arguments
 o setWorkStationViewPort(int, int, int, int)
Defines screen area to be used in graphics.
 o setWorkStationViewPort(Int2Range)
as above, but using an Int2Range for screen limits
 o setWorkStationWindow(double, double, double, double)
Defines workStation window to be used in graphics.
 o toString()
 o wc2Screen(Real2Range)
convert a WC box to screen coords
 o xNDC2Screen(double)
 o xScreen2NDC(int)
 o xScreen2WC(int)
 o xWC2Screen(double)
 o yNDC2Screen(double)
 o yScreen2NDC(int)
 o yScreen2WC(int)
 o yWC2Screen(double)

Constructors

 o Scaler2D
  public Scaler2D()
default - world coords are 0-1, 0-1
 o 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.)
 o 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.)
 o Scaler2D
  public Scaler2D(Scaler2D s)
copy constructor

Methods

 o resetWindow
  public void resetWindow()
reset window to intial value
 o getWindow
  public Real2Range getWindow()
 o getViewPort
  public Real2Range getViewPort()
 o getWorkStationWindow
  public Real2Range getWorkStationWindow()
 o getScreen
  public Int2Range getScreen()
 o getWorkStationViewPort
  public Int2Range getWorkStationViewPort()
synonymous with getScreen()
 o getScaleWC2NDC
  public Real2 getScaleWC2NDC()
 o getScaleNDC2Screen
  public Real2 getScaleNDC2Screen()
 o getScaleWC2Screen
  public Real2 getScaleWC2Screen()
 o screenDeltaXtoWC
  public double screenDeltaXtoWC(int deltax)
scale a screen distance to a WC distance (don't confuse with coords)
 o screenDeltaYtoWC
  public double screenDeltaYtoWC(int deltay)
scale a screen distance to a WC distance (don't confuse with coords)
 o 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.

 o 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
 o 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.)
 o 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.)
 o setWorkStationViewPort
  public void setWorkStationViewPort(Int2Range screenLimits) throws InvalidArgumentsException
as above, but using an Int2Range for screen limits
Throws: InvalidArgumentsException
bad range (max < min, etc.)
 o 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.)
 o 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.)
 o 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.)
 o setWindow
  public void setWindow(Real2Range box) throws InvalidArgumentsException
set new window in World Coordinates
Throws: InvalidArgumentsException
bad range (max < min, etc.)
 o drawBoundingBox
  public void drawBoundingBox(Graphics g)
only useful if continually redrawn...
 o drawWorkStationViewPort
  public void drawWorkStationViewPort(Graphics g)
draws box round limits of screen VP. Might be different from object's bounding box
 o clearWorkStationViewPort
  public void clearWorkStationViewPort(Graphics g)
clears everything within WorkStationViewPort
 o drawManipulatorBox
  public void drawManipulatorBox(Graphics g)
default manipulator is whole screen port (WorkStationViewPort)
 o drawManipulatorBox
  public void drawManipulatorBox(Graphics g,
                                 Real2Range box)
WorldCoords drawing of manipulator box
 o setSquareSize
  public void setSquareSize(int size)
sets the size of the little green squares and the pick tolerance
 o getSquareSize
  public int getSquareSize()
gets the size of the little green squares and the pick tolerance
 o drawManipulatorBox
  public void drawManipulatorBox(Graphics g,
                                 Int2Range ibox)
screen coordinates drawing of manipulator box
 o 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

 o 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
 o getWCBoundingBox
  public Real2Range getWCBoundingBox()
get bounding box in world coordinates
 o 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
 o clipToScreenBoundingBox
  public Graphics clipToScreenBoundingBox(Graphics g)
clip to screen limits (usually larger than object bounding box
 o wc2Screen
  public Int2Range wc2Screen(Real2Range box)
convert a WC box to screen coords
 o drawRect
  public void drawRect(Graphics g,
                       Int2Range ibox)
draw a box in screen coords - should be in Util...
 o drawLine
  public void drawLine(Graphics g,
                       double x1,
                       double y1,
                       double x2,
                       double y2)
analogues of awt.Graphics, but in double WC coords;
 o drawRect
  public void drawRect(Graphics g,
                       double xleft,
                       double ytop,
                       double width,
                       double height)
 o drawRect
  public void drawRect(Graphics g,
                       Real2Range box)
 o drawString
  public void drawString(Graphics g,
                         String text,
                         double x,
                         double y)
 o drawCircle
  public void drawCircle(Graphics g,
                         double x,
                         double y,
                         int radius)
 o 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
 o xWC2Screen
  public int xWC2Screen(double coord)
 o yWC2Screen
  public int yWC2Screen(double coord)
 o xScreen2WC
  public double xScreen2WC(int coord)
 o yScreen2WC
  public double yScreen2WC(int coord)
 o screen2WC
  public Real2Range screen2WC(Int2Range xyr)
 o screen2WC
  public Real2Range screen2WC(IntRange xr,
                              IntRange yr)
 o xNDC2Screen
  public int xNDC2Screen(double coord)
 o yNDC2Screen
  public int yNDC2Screen(double coord)
 o xScreen2NDC
  public double xScreen2NDC(int coord)
 o yScreen2NDC
  public double yScreen2NDC(int coord)
 o screen2NDC
  public Real2Range screen2NDC(Int2Range xyr)
 o screen2NDC
  public Real2Range screen2NDC(IntRange xr,
                               IntRange yr)
 o toString
  public String toString()
Overrides:
toString in class Object

All Packages  Class Hierarchy  This Package  Previous  Next  Index