visad.bom.annotations
Class ScreenAnnotatorUtils

java.lang.Object
  extended by visad.bom.annotations.ScreenAnnotatorUtils

public class ScreenAnnotatorUtils
extends Object

This is a collection of static methods to help with the construction of java3D objects used for annotating a VisAD display. The objects are intended to be drawn directly to the screen using screen pixel locations. See ScreenAnnotator. This is meant to contain as much of the Java3D dependencies as posible.


Constructor Summary
ScreenAnnotatorUtils()
           
 
Method Summary
static void adjustZ(DisplayImplJ3D display, Canvas3D canvas, double z, Point3d[] points)
          This adjusts a set of points so that the drawn object has the same appearance even though the Z value is adjusted to a user given setting.
static void ditherPoints(Canvas3D canvas, double frac, Point3d[] points)
          Java3D seems to calculate a floating point pixel value and then take the integer part for the screen coordinate.
static Shape3D makeImageShape3D(DisplayImplJ3D display, Image image, int position, int x, int y, int width, int height, double zValue, double scale)
          Transforms an Image object into a Shape3D.
static BranchGroup makeJLabelShape3D(DisplayImplJ3D display, String text, int x, int y, float[] colour, Font font, double zValue, double fontSizeInPixels, int align, int path)
          Construct a BranchGroup object from a routine description of a Label using Text3D.
static Shape3D makeLabelShape3D(DisplayImplJ3D display, String text, int x, int y, float[] colour, Font font, HersheyFont hfont, double zValue, double scaleFactor, boolean filled, double thickness, double orientation, TextControl.Justification horizontal, TextControl.Justification vertical, double charRotation)
          Construct a Shape3D object from a routine description of a Label using 2D fonts.
static Shape3D makeLineShape3D(DisplayImplJ3D display, int style, int x1, int y1, int x2, int y2, float[] colour, double z, double thickness)
          Construct a Shape3D object from a routine description of a Line.
static Shape3D makePointShape3D(DisplayImplJ3D display, int x1, int y1, float[] colour, double z, double thickness)
          Construct a Shape3D object from a routine description of a Point.
static Shape3D makeQuadrilateralShape3D(DisplayImplJ3D display, int style, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, float[] colour, double z, double thickness)
          Construct a Shape3D object from a routine description of a Quadrilateral.
static Shape3D makeTriangleShape3D(DisplayImplJ3D display, int style, int x1, int y1, int x2, int y2, int x3, int y3, float[] colour, double z, double thickness)
          Construct a Shape3D object from a routine description of a Triangle.
static Point3d[] screenToVworld(int[][] screenXY, Canvas3D canvas)
          Convert an array of Pixel points to Point3d array in the Virtual World.
static int[][] vworldToScreen(Point3d[] points, Canvas3D canvas)
          Convert an array of Vworld points to int[][] array in Screen coordinates.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScreenAnnotatorUtils

public ScreenAnnotatorUtils()
Method Detail

makeJLabelShape3D

public static BranchGroup makeJLabelShape3D(DisplayImplJ3D display,
                                            String text,
                                            int x,
                                            int y,
                                            float[] colour,
                                            Font font,
                                            double zValue,
                                            double fontSizeInPixels,
                                            int align,
                                            int path)
Construct a BranchGroup object from a routine description of a Label using Text3D. A label is a Text string with attributes used for drawing it.

Parameters:
display - the VisAD display for this Label.
text - the string.
x - x screen coordinate of the text.
y - y screen coordinate of the text.
colour - red green blue triple; each value in [0.0, 1.0].
font - Font to use.
zValue - Virtual world value; larger z is in front.
fontSizeInPixels - height of text.
align - one of:
  • Text3D.ALIGN_FIRST
  • Text3D.ALIGN_CENTER
  • Text3D.ALIGN_LAST
path - one of:
  • Text3D.PATH_RIGHT
  • Text3D.PATH_LEFT
  • Text3D.PATH_DOWN
  • Text3D.PATH_UP
Returns:
the BranchGroup, suitably scaled, representing the label.

makeLabelShape3D

public static Shape3D makeLabelShape3D(DisplayImplJ3D display,
                                       String text,
                                       int x,
                                       int y,
                                       float[] colour,
                                       Font font,
                                       HersheyFont hfont,
                                       double zValue,
                                       double scaleFactor,
                                       boolean filled,
                                       double thickness,
                                       double orientation,
                                       TextControl.Justification horizontal,
                                       TextControl.Justification vertical,
                                       double charRotation)
                                throws VisADException
Construct a Shape3D object from a routine description of a Label using 2D fonts. A label is a Text string with attributes used drawing it.

Parameters:
display - the VisAD display for this Label.
text - the string.
x - x screen coordinate of the text.
y - y screen coordinate of the text.
colour - red green blue triple; each value in [0.0, 1.0].
font - Font to use.
hfont - Hershey font to use; if both fonts are null then use the default VisAD line font.
zValue - Virtual world value; larger z is in front.
scaleFactor - scale the font by this factor; by default characters are 1 pixel in size.
filled - if true the font is rendered as filled, if false just the triangles are drawn.
thickness - line width to use if just drawing triangles; usually 1.0 is the most useful.
orientation - angle of rotation of the text anticlockwise from the horizontal.
horizontal - one of:
  • TextControl.Justification.LEFT - Left justified text (ie: normal text)
  • TextControl.Justification.CENTER - Centered text
  • TextControl.Justification.RIGHT - Right justified text
vertical - one of:
  • TextControl.Justification.BOTTOM - Bottom justified text (normal).
  • TextControl.Justification.TOP - Top justified text
  • TextControl.Justification.CENTER - Centered text
charRotation - rotate each character charRotation degrees clockwise from base line.
Returns:
the Label description as a Shape3D.
Throws:
VisADException - VisAD couldn't make the geometry array.

adjustZ

public static void adjustZ(DisplayImplJ3D display,
                           Canvas3D canvas,
                           double z,
                           Point3d[] points)
This adjusts a set of points so that the drawn object has the same appearance even though the Z value is adjusted to a user given setting. Important for Perspective view.

Parameters:
display - the VisAD display.
canvas - Java3D canvas being drawn on
z - Virtual world value; larger z is in front.
points - array of values to have their z value adjusted.

makeQuadrilateralShape3D

public static Shape3D makeQuadrilateralShape3D(DisplayImplJ3D display,
                                               int style,
                                               int x1,
                                               int y1,
                                               int x2,
                                               int y2,
                                               int x3,
                                               int y3,
                                               int x4,
                                               int y4,
                                               float[] colour,
                                               double z,
                                               double thickness)
Construct a Shape3D object from a routine description of a Quadrilateral.

Parameters:
display - the VisAD display for this Quadrilateral.
style - one of:
  • QuadrilateralJ3D.FILL
  • QuadrilateralJ3D.LINE
  • QuadrilateralJ3D.POINT
x1 - x screen coordinate of the first point.
y1 - y screen coordinate of the first point.
x2 - x screen coordinate of the second point.
y2 - y screen coordinate of the second point.
x3 - x screen coordinate of the third point.
y3 - y screen coordinate of the third point.
x4 - x screen coordinate of the fourth point.
y4 - y screen coordinate of the fourth point.
colour - red green blue triple; each value in [0.0, 1.0].
z - Virtual world value; larger z is in front.
thickness - used for LINE and POINT node.
Returns:
the QuadrilateralJ3D description as a Shape3D.

makeTriangleShape3D

public static Shape3D makeTriangleShape3D(DisplayImplJ3D display,
                                          int style,
                                          int x1,
                                          int y1,
                                          int x2,
                                          int y2,
                                          int x3,
                                          int y3,
                                          float[] colour,
                                          double z,
                                          double thickness)
Construct a Shape3D object from a routine description of a Triangle.

Parameters:
display - the VisAD display for this Point.
style - one of
  • TriangleJ3D.FILL,
  • TriangleJ3D.LINE,
  • TriangleJ3D.POINT
x1 - x screen coordinate of the first point.
y1 - y screen coordinate of the first point.
x2 - x screen coordinate of the second point.
y2 - y screen coordinate of the second point.
x3 - x screen coordinate of the third point.
y3 - y screen coordinate of the third point.
colour - red green blue triple; each value in [0.0, 1.0].
z - Virtual world value; larger z is in front.
thickness - used for LINE and POINT node.
Returns:
the Triangle description as a Shape3D.

makeLineShape3D

public static Shape3D makeLineShape3D(DisplayImplJ3D display,
                                      int style,
                                      int x1,
                                      int y1,
                                      int x2,
                                      int y2,
                                      float[] colour,
                                      double z,
                                      double thickness)
Construct a Shape3D object from a routine description of a Line.

Parameters:
display - the VisAD display for this Point.
style - one of:
  • LineJ3D.SOLID
  • LineJ3D.DASH
  • LineJ3D.DOT
  • LineJ3D.DASH_DOT
x1 - x screen coordinate of the first point.
y1 - y screen coordinate of the first point.
x2 - x screen coordinate of the second point.
y2 - y screen coordinate of the second point.
colour - red green blue triple; each value in [0.0, 1.0].
z - Virtual world value; larger z is in front.
thickness - for the line.
Returns:
the LineJ3D description as a Shape3D.

makePointShape3D

public static Shape3D makePointShape3D(DisplayImplJ3D display,
                                       int x1,
                                       int y1,
                                       float[] colour,
                                       double z,
                                       double thickness)
Construct a Shape3D object from a routine description of a Point.

Parameters:
display - the VisAD display for this Point.
x1 - x screen coordinate of the point.
y1 - y screen coordinate of the point.
colour - red green blue triple; each value in [0.0, 1.0].
z - Virtual world value; larger z is in front.
thickness - gives the size of the Point.
Returns:
the Point description as a Shape3D.

screenToVworld

public static Point3d[] screenToVworld(int[][] screenXY,
                                       Canvas3D canvas)
Convert an array of Pixel points to Point3d array in the Virtual World.

Parameters:
canvas - for the virtual world of interest.
screenXY - the screen points in x, y pairs.
Returns:
- array of Point3d values representing the Virtual World values for the Screen points.

vworldToScreen

public static int[][] vworldToScreen(Point3d[] points,
                                     Canvas3D canvas)
Convert an array of Vworld points to int[][] array in Screen coordinates.

Parameters:
canvas - for the virtual world of interest.
points - array of Point3d of Vworld coordinates.
Returns:
- int[2][] array of values representing the Screen points.

ditherPoints

public static void ditherPoints(Canvas3D canvas,
                                double frac,
                                Point3d[] points)
Java3D seems to calculate a floating point pixel value and then take the integer part for the screen coordinate. This routine allows the user to move the x, y value of a Vworld set of points. If these points represent Vworld values for some pixels then it allows the coordinate to be moved to the interior of the pixel rather than the top left. Consequently converting back from Vworld values to floating point screen values should ensure the integer part is mapping back to the original pixel. The intended use is in mapping screen coordinates to Vworld, allow some adjustments, and then be able to map back to the same screen coordinates. An example is adjusting the z value in Vworld so the point is closer to (or further from) the eye but have the image occupy the same pixel. Get the original Vworld coordinate, use this routine to adjust to a Vworld point interior (centre?) of the pixel, and then adjust the z value. Java 3D uses positive y down the screen for pixel values, and negative y up the screen in Vworld coordinates. So this routine is written accordinagly for doing fractional adjustments.

Parameters:
canvas - where the points are displayed.
frac - amount of interpoint spacing to use for adjustment; it is clamped between [0.1, 0.9].
points - array of values to have their x, y values adjusted.

makeImageShape3D

public static Shape3D makeImageShape3D(DisplayImplJ3D display,
                                       Image image,
                                       int position,
                                       int x,
                                       int y,
                                       int width,
                                       int height,
                                       double zValue,
                                       double scale)
                                throws VisADException
Transforms an Image object into a Shape3D. The image object may be scaled.

Parameters:
display - the VisAD display for this Point.
image - to be converted to Shape3D.
position - how to place the image relative to (x, y); one of:
  • Image.TOP_LEFT (default)
  • Image.TOP_RIGHT
  • Image.BOTTOM_RIGHT
  • Image.BOTTOM_LEFT
  • Image.CENTER
x - x screen coordinate to place the image.
y - y screen coordinate to place the image.
width - of image in pixels.
height - of image in pixels.
zValue - Virtual world value; larger z is in front.
scale - scale factor for image magnification; greater than 0.0.
Returns:
the Image description as a Shape3D.
Throws:
VisADException - if the image can't be accessed for some reason.