jwo.landserf.gui3d
Class SurfaceRenderer

java.lang.Object
  extended by jwo.landserf.gui3d.SurfaceRenderer
All Implemented Interfaces:
EventListener, javax.media.opengl.GLEventListener

public class SurfaceRenderer
extends Object
implements javax.media.opengl.GLEventListener

Creates and draws spatial objects in 3D coordinate space. Uses the JOGL OpenGL bindings.

Version:
2.3, 11th September, 2008.
Author:
Jo Wood

Field Summary
static int BMP
          Indicates a Windows bitmap format image file
static int GIF
          Indicates a GIF format image file
static int JPG
          Indicates a JPEG format image file
static int PNG
          Indicates a Portable Network Graphics format file
 
Constructor Summary
SurfaceRenderer(GUI3d gui)
          Creates a surface to display from the given 3d GUI.
 
Method Summary
 boolean canUseMultiTextures()
          Reports whether multi-textures can be used.
 void cleanup()
          Releases texture and other 3d resources before quitting.
 void createSnapshot(SnapshotListener snapListener)
          Performs a screen snapshot for printing or animation.
 void display(javax.media.opengl.GLAutoDrawable drawable)
          Called by the drawable class to render.
 void displayChanged(javax.media.opengl.GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged)
          Called by the drawable when the display mode or the display device associated with the GLDrawable has changed.
 Camera getCamera()
          Supplies the camera that is used to control view of the surface.
 float getEasting(float x)
          Converts the given rendering x coordinate to its geographical equivalent.
 float getElevation(float z)
          Converts the given rendering z coordinate to its geographical equivalent.
 Color getFogColour()
          Reports the current fog colour.
 boolean getGridded()
          Reports whether the surface is represented as a gridded lattice or a TIN.
 float getHoverHeight()
          Reports the minimum height of camera above surface.
 int getImageFormat()
          Reports the format used to save snapshots.
 String getImageOutBase()
          Reports the full path of the snapshot or animation base name.
 String getImageOutputFileName()
          Reports the full path of the last file that was written if snapshot or animation was to be recorded.
 boolean getLined()
          Reports whether the surface is to be drawn as lines or not.
 float getNorthing(float y)
          Converts the given rendering y coordinate to its geographical equivalent.
 String[] getOpenGLInfo()
          Reports OpenGL implementation information.
 float getPointSize()
          Gets the size of the point feature representation.
 int getSampleInterval()
          Reports the current sample interval for the surface mesh.
 Color getSeaColour()
          Reports the current sea colour.
 Color getSkyColour()
          Reports the current sky colour.
 float getTriangleHeight(float x, float y)
          Gets the planar interpolated height at the given location based on the current surface triangulation.
 float getVectHeight()
          Reports height that vectors are drawn above the surface.
 float getVectorDepth()
          Reports the depth setting for vectors.
 float getVectorObliqueDepth()
          Reports the oblique depth setting for vectors.
 float getVectWidth()
          Reports the width that vectors are drawn.
 float getVerticalScale()
          Reports the current vertical scaling factor.
 Color getWallColour()
          Reports the current surface wall colour.
 float getX(float easting)
          Converts the given geographical coordinate to its rendering x coordinate equivalent.
 float getY(float northing)
          Converts the given geographical coordinate to its rendering y coordinate equivalent.
 float getZ(float elevation)
          Converts the given geographical coordinate to its rendering z coordinate equivalent.
 void hugSurface(boolean hug)
          Sets movement to hug surface (ie no flying).
 void init(javax.media.opengl.GLAutoDrawable drawable)
          Called by the drawable class immediately after the OpenGL context is initialised.
 void initVector(GISFrame gisFrame)
          Initialises the vector map representation.
 boolean isDrawDetail()
          Reports if the detailed texture is drawn or not.
 boolean isFadeDetail()
          Reports if the detailed texture fades with distance.
 boolean isVectClipped()
          Reports whether vectors are to be depth clipped.
 boolean isVectSmoothed()
          Reports whether vectors displayed as smoothed.
 void makeDetailTexture(Image detailImage, float transparency)
          Creates the detail texture to be used with close views.
 void makeTexture(int textureSize, boolean smooth)
          Creates a texture from the currently selected drape.
 void rescale()
          Recalculates the local scaling of the model.
 void reshape(javax.media.opengl.GLAutoDrawable drawable, int x, int y, int width, int height)
          Recalculates viewing volume and updates field of view.
 void setDetailSize(float size)
          Sets the size of the detail texture relative to 1 grid cell.
 void setDrapeImage(Image image)
          Sets the image to be draped over the surface.
 void setDrawDetail(boolean detail)
          Determines if the detailed texture is to be drawn or not.
 void setFadeDetail(boolean fadeDetail)
          Determines if the detailed texture is to fade with distance.
 void setFogColour(Color colour)
          Sets a new fog colour.
 void setFogDensity(float density)
          Sets a new fog density.
 void setFOV(float fov)
          Sets a new field of view.
 void setGridded(boolean useGrid)
          Sets the rendering to use a gridded lattice or a TIN.
 void setHoverHeight(float skimHeight)
          Sets the minimum height of camera above surface.
 void setImageFormat(int format)
          Determines the format used to save snapshots.
 void setImageOutBase(String imageOutBase)
          Determines the base-name of the files to write snapshots and animations.
 void setLined(boolean lines)
          Allows the surface to be drawn as lines or solid polygons.
 void setPointSize(float pointSize)
          Sets the size of the point feature representation.
 void setSampleInterval(int interval)
          Sets a new sample interval for the surface mesh triangulation.
 void setSeaColour(Color colour)
          Sets a new sea colour.
 void setSky(boolean sky)
          Turns the sky on or off.
 void setSkyColour(Color colour)
          Sets a new sky colour.
 void setSmoothed(boolean smoothed)
          Sets texture mapping to smoothed or unsmoothed.
 void setVectClipped(boolean clipVect)
          Sets whether vectors are drawn with (true) or without (false) depth clipping.
 void setVectHeight(float vectHeight)
          Sets the height that vectors are drawn above the surface.
 void setVectorDepth(float depth)
          Sets the depth value for vector display.
 void setVectorObliqueDepth(float obliqueDepth)
          Sets the oblique depth value for vector display.
 void setVectSmoothed(boolean smoothed)
          Sets whether vectors displayed as smoothed.
 void setVectWidth(float vectWidth)
          Sets the line width of vectors.
 void setVerticalScale(float zScale)
          Sets a new vertical scaling
 void setWallColour(Color colour)
          Sets a new colour for the vertical walls bounding a surface.
 void setWriteAnimFiles(boolean writeAnim, SnapshotListener snapListener)
          Determines if graphical output is written as a sequence of bitmapped files.
 void showVector(boolean vect)
          Identifies whether a vector is drawn or not.
 void updateTexture(int textureSize0, int textureSize, boolean smooth)
          Updates a texture at a given texture size.
 void writeSnapshot(SnapshotListener snapListener)
          Performs a screen snapshot and writes the result to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BMP

public static final int BMP
Indicates a Windows bitmap format image file

See Also:
Constant Field Values

GIF

public static final int GIF
Indicates a GIF format image file

See Also:
Constant Field Values

JPG

public static final int JPG
Indicates a JPEG format image file

See Also:
Constant Field Values

PNG

public static final int PNG
Indicates a Portable Network Graphics format file

See Also:
Constant Field Values
Constructor Detail

SurfaceRenderer

public SurfaceRenderer(GUI3d gui)
Creates a surface to display from the given 3d GUI.

Parameters:
gui - Parent GUI controlling 3d view.
Method Detail

init

public void init(javax.media.opengl.GLAutoDrawable drawable)
Called by the drawable class immediately after the OpenGL context is initialised. The GLContext has already been made current when this method is called. Initialises camera position, lighting properties etc.

Specified by:
init in interface javax.media.opengl.GLEventListener
Parameters:
drawable - The drawable class that this renders into.

display

public void display(javax.media.opengl.GLAutoDrawable drawable)
Called by the drawable class to render.

Specified by:
display in interface javax.media.opengl.GLEventListener
Parameters:
drawable - The drawable class that this renders into.

cleanup

public void cleanup()
Releases texture and other 3d resources before quitting.


reshape

public void reshape(javax.media.opengl.GLAutoDrawable drawable,
                    int x,
                    int y,
                    int width,
                    int height)
Recalculates viewing volume and updates field of view. This is called whenever the drawable area is moved or resized.

Specified by:
reshape in interface javax.media.opengl.GLEventListener
Parameters:
drawable - The drawable class that this renders into.
x - X-coordinate of the left of the drawable area.
y - Y-coordinate of the top of the drawable area.
width - Width of the drawable area.
height - Height of the drawable area.

displayChanged

public void displayChanged(javax.media.opengl.GLAutoDrawable drawable,
                           boolean modeChanged,
                           boolean deviceChanged)
Called by the drawable when the display mode or the display device associated with the GLDrawable has changed. The two boolean parameters indicate the types of change(s) that have occurred. Does nothing in this case.

Specified by:
displayChanged in interface javax.media.opengl.GLEventListener
Parameters:
drawable - Drawable object that made a call to this method (ignored).
modeChanged - True if mode has changed (e.g. from 16 to 32 bit colour) (ignored).
deviceChanged - True if device has changed (e.g. dragging window from one monitor to another) (ignored).

rescale

public void rescale()
Recalculates the local scaling of the model.


makeTexture

public void makeTexture(int textureSize,
                        boolean smooth)
Creates a texture from the currently selected drape.

Parameters:
textureSize - Size of 1 side of (square) texture to drape. This should be a power of 2 from 64 to 2048.
smooth - Texture is smoothed if true.

updateTexture

public void updateTexture(int textureSize0,
                          int textureSize,
                          boolean smooth)
Updates a texture at a given texture size. This allows different mipmap levels to store independent images. To change the image, a call must be made to setDrapeImage() before calling this method.

Parameters:
textureSize0 - Currently selected maximum texture size.
textureSize - Size of 1 side of (square) texture to drape. This should be a power of 2 from 1 to 2048.
smooth - Texture is smoothed if true.

makeDetailTexture

public void makeDetailTexture(Image detailImage,
                              float transparency)
Creates the detail texture to be used with close views.

Parameters:
detailImage - Image providing the detailed texture.
transparency - Level of transparency for texture.

createSnapshot

public void createSnapshot(SnapshotListener snapListener)
Performs a screen snapshot for printing or animation. Note that this is not a synchronous operation. Response to the request for a snapshot should be handled by the given snapshot listener. For synchronous response call, writeSnapshot() which will write the snapshot to a file.

Parameters:
snapListener - Snapshot listener to be informed when picture is ready.

writeSnapshot

public void writeSnapshot(SnapshotListener snapListener)
Performs a screen snapshot and writes the result to a file. The name of the file is determined by the base name supplied by setImageOutBase() and will be appended with the number of the snapshot written.

Parameters:
snapListener - Snapshot listener to be informed when picture is ready.

setWriteAnimFiles

public void setWriteAnimFiles(boolean writeAnim,
                              SnapshotListener snapListener)
Determines if graphical output is written as a sequence of bitmapped files. The name of the files is determined by the base name supplied by setImageOutBase() and will be appended with the number of the snapshot written.

Parameters:
writeAnim - Will force renderer to write each frame of animation out as a bitmap.
snapListener - Snapshot listener to be informed when picture is ready.

setImageOutBase

public void setImageOutBase(String imageOutBase)
Determines the base-name of the files to write snapshots and animations. If not a full path, this name will be relative to the LandSerf start directory.

Parameters:
imageOutBase - Base name of image output files. (e.g. 'anim' will result in a sequence of files called anim0001.bmp, anum0002.bmp etc. being written).

getImageOutBase

public String getImageOutBase()
Reports the full path of the snapshot or animation base name.

Returns:
Name of image output base name.

setImageFormat

public void setImageFormat(int format)
Determines the format used to save snapshots.

Parameters:
format - Image format to use.

getImageFormat

public int getImageFormat()
Reports the format used to save snapshots.

Returns:
Image format use to save snapshots.

getImageOutputFileName

public String getImageOutputFileName()
Reports the full path of the last file that was written if snapshot or animation was to be recorded. If no file has been written in this session, the file number will be '0000'

Returns:
Name of image output file.

setSmoothed

public void setSmoothed(boolean smoothed)
Sets texture mapping to smoothed or unsmoothed.

Parameters:
smoothed - Texture is smoothed if true.

setSampleInterval

public void setSampleInterval(int interval)
Sets a new sample interval for the surface mesh triangulation. Restricts new sample interval between 1 and smallest dimension of the grid.

Parameters:
interval - New sample interval - 1 is full resolution, 32 sample every 32nd cell etc.

setDetailSize

public void setDetailSize(float size)
Sets the size of the detail texture relative to 1 grid cell.

Parameters:
size - Number of grid cells occupied by the detail texture.

getSampleInterval

public int getSampleInterval()
Reports the current sample interval for the surface mesh.

Returns:
Current sample interval.

getVerticalScale

public float getVerticalScale()
Reports the current vertical scaling factor.

Returns:
Current sample interval.

getHoverHeight

public float getHoverHeight()
Reports the minimum height of camera above surface.

Returns:
Minimum height of camera above surface. 0 indicates no collision detection, 1-10 varying hover height.

getPointSize

public float getPointSize()
Gets the size of the point feature representation.

Returns:
Size of point features represented on surface. Scaled between 0 and 10. If 0, no point features shown.

getGridded

public boolean getGridded()
Reports whether the surface is represented as a gridded lattice or a TIN.

Returns:
True if gridded lattice, false if TIN.

setGridded

public void setGridded(boolean useGrid)
Sets the rendering to use a gridded lattice or a TIN.

Parameters:
useGrid - Uses a gridded lattice if true, a TIN if false.

getLined

public boolean getLined()
Reports whether the surface is to be drawn as lines or not.

Returns:
True if surface is to be drawn as lines.

getVectHeight

public float getVectHeight()
Reports height that vectors are drawn above the surface.

Returns:
Reports height of vectors above surface.

getVectWidth

public float getVectWidth()
Reports the width that vectors are drawn.

Returns:
Vector width in pixels. This can be non-integer if anti-aliasing is turned on.

isVectClipped

public boolean isVectClipped()
Reports whether vectors are to be depth clipped. Depth clipping will hide parts of vectors that are 'behind' part of the surface.

Returns:
True if vectors are depth clipped.

isVectSmoothed

public boolean isVectSmoothed()
Reports whether vectors displayed as smoothed. If smoothed (via anti-aliasing) vector widths can be non-integers.

Returns:
True if vectors are smoothed.

getOpenGLInfo

public String[] getOpenGLInfo()
Reports OpenGL implementation information.

Returns:
Information describing OpenGL implementation. Array of strings contain the version in the first element, the vendor in the second, the renderer in the third, the availability of key OpenGL extensions in the fourth and the maximum texture size in the last.

setDrawDetail

public void setDrawDetail(boolean detail)
Determines if the detailed texture is to be drawn or not. Note that if multiTextures cannot be created, this method will always set draw detail to false.

Parameters:
detail - True if detail is to be drawn.

isDrawDetail

public boolean isDrawDetail()
Reports if the detailed texture is drawn or not.

Returns:
True if detail is drawn.

setFadeDetail

public void setFadeDetail(boolean fadeDetail)
Determines if the detailed texture is to fade with distance. Note that if multiTextures cannot be created, this method will always set fade detail to false.

Parameters:
fadeDetail - True if detail is to fade with distance.

isFadeDetail

public boolean isFadeDetail()
Reports if the detailed texture fades with distance.

Returns:
True if detail fades with distance.

setLined

public void setLined(boolean lines)
Allows the surface to be drawn as lines or solid polygons.

Parameters:
lines - True if surface is to be drawn with lines.

showVector

public void showVector(boolean vect)
Identifies whether a vector is drawn or not.

Parameters:
vect - Draws a vector over surface if true.

initVector

public void initVector(GISFrame gisFrame)
Initialises the vector map representation. Includes the initialisation of the TIN triangulation if contained within the vector

Parameters:
gisFrame - GUI holding vector representation.

hugSurface

public void hugSurface(boolean hug)
Sets movement to hug surface (ie no flying).

Parameters:
hug - Camera will hug surface if true.

setHoverHeight

public void setHoverHeight(float skimHeight)
Sets the minimum height of camera above surface.

Parameters:
skimHeight - Minimum height of camera above surface. 0 indicates no collision detection, 1-10 varying hover height.

setPointSize

public void setPointSize(float pointSize)
Sets the size of the point feature representation.

Parameters:
pointSize - Size of point features represented on surface. Scaled between 0 and 10. If 0, no point features shown.

setVerticalScale

public void setVerticalScale(float zScale)
Sets a new vertical scaling

Parameters:
zScale - New vertical scaling.

setFOV

public void setFOV(float fov)
Sets a new field of view.

Parameters:
fov - New field of view in degrees (1-180).

setFogDensity

public void setFogDensity(float density)
Sets a new fog density.

Parameters:
density - New fog density.

setVectClipped

public void setVectClipped(boolean clipVect)
Sets whether vectors are drawn with (true) or without (false) depth clipping.

Parameters:
clipVect - Determines whether vectors are depth clipped.

setVectSmoothed

public void setVectSmoothed(boolean smoothed)
Sets whether vectors displayed as smoothed. If smoothed (via anti-aliasing) vector widths can be non-integers.

Parameters:
smoothed - True if vectors are to be smoothed.

setVectHeight

public void setVectHeight(float vectHeight)
Sets the height that vectors are drawn above the surface.

Parameters:
vectHeight - Vector height in elevation units.

setVectWidth

public void setVectWidth(float vectWidth)
Sets the line width of vectors. Can be non integer when smoothed.

Parameters:
vectWidth - Vector width in rendering units.

setSky

public void setSky(boolean sky)
Turns the sky on or off.

Parameters:
sky - Sky is shown if true.

setSkyColour

public void setSkyColour(Color colour)
Sets a new sky colour. Note that the display of the sky will also depend on the current fog colour too.

Parameters:
colour - New sky colour.

setFogColour

public void setFogColour(Color colour)
Sets a new fog colour.

Parameters:
colour - New fog colour.

setSeaColour

public void setSeaColour(Color colour)
Sets a new sea colour.

Parameters:
colour - New sea colour.

setWallColour

public void setWallColour(Color colour)
Sets a new colour for the vertical walls bounding a surface.

Parameters:
colour - New wall colour.

setDrapeImage

public void setDrapeImage(Image image)
Sets the image to be draped over the surface. Note the new image will not be displayed until makeTexture() is called.

Parameters:
image - Image to be draped over surface.

getEasting

public float getEasting(float x)
Converts the given rendering x coordinate to its geographical equivalent.

Parameters:
x - Rendering x coordinate.
Returns:
Geographical coordinate.

getNorthing

public float getNorthing(float y)
Converts the given rendering y coordinate to its geographical equivalent.

Parameters:
y - Rendering y coordinate.
Returns:
Geographical coordinate.

getTriangleHeight

public float getTriangleHeight(float x,
                               float y)
Gets the planar interpolated height at the given location based on the current surface triangulation. Returns SpatialObject.OUT_OF_BOUNDS if location is outside current surface.

Parameters:
x - x coordinate of location to query in rendering coordinates.
y - y coordinate of location to query in rendering coordinates.
Returns:
Interpolated height in rendering coordinates.

getElevation

public float getElevation(float z)
Converts the given rendering z coordinate to its geographical equivalent.

Parameters:
z - Rendering z coordinate.
Returns:
Geographical coordinate.

getX

public float getX(float easting)
Converts the given geographical coordinate to its rendering x coordinate equivalent.

Parameters:
easting - Geographical coordinate.
Returns:
Rendering x coordinate.

getY

public float getY(float northing)
Converts the given geographical coordinate to its rendering y coordinate equivalent.

Parameters:
northing - Geographical coordinate.
Returns:
Rendering y coordinate.

getZ

public float getZ(float elevation)
Converts the given geographical coordinate to its rendering z coordinate equivalent.

Parameters:
elevation - Geographical coordinate.
Returns:
Rendering z coordinate.

getCamera

public Camera getCamera()
Supplies the camera that is used to control view of the surface.

Returns:
Camera used to control view.

getSkyColour

public Color getSkyColour()
Reports the current sky colour.

Returns:
Current sky colour.

getFogColour

public Color getFogColour()
Reports the current fog colour.

Returns:
Current fog colour.

getSeaColour

public Color getSeaColour()
Reports the current sea colour.

Returns:
Current sea colour.

getWallColour

public Color getWallColour()
Reports the current surface wall colour.

Returns:
Current wall colour.

canUseMultiTextures

public boolean canUseMultiTextures()
Reports whether multi-textures can be used.

Returns:
True if multi-textures are available.

getVectorObliqueDepth

public float getVectorObliqueDepth()
Reports the oblique depth setting for vectors. This value represents how much below the surface a vector can be and still be displayed. It is used to overcome 'z-fighting' when a vector segment is co-planar with a portion of the surface. This oblique setting applies to surface segments that are seen close to edge on. The higher the value, the further from edge-on, the view has to be for the surface segment to appear transparent.

Returns:
Oblique depth setting (typically between 0 and 20).

getVectorDepth

public float getVectorDepth()
Reports the depth setting for vectors. This value represents how much below the surface a vector can be and still be displayed. It is used to overcome 'z-fighting' when a vector segment is co-planar with a portion of the surface.

Returns:
Vector depth setting (typically between 0 and 50).

setVectorObliqueDepth

public void setVectorObliqueDepth(float obliqueDepth)
Sets the oblique depth value for vector display. This is used to overcome 'z-fighting' when a vector segment is co-planar with a portion of the surface. The oblique setting applies to surface segments that are seen close to edge-on. The higher the value, the further from edge-on, the view has to be for the surface segment to appear transparent.

Parameters:
obliqueDepth - Oblique depth setting (typically between 0 and 20).

setVectorDepth

public void setVectorDepth(float depth)
Sets the depth value for vector display. Represents how much below the surface a vector can be and still be displayed. This is used to overcome 'z-fighting' when a vector segment is co-planar with a portion of the surface.

Parameters:
depth - Vector depth setting (typically between 0 and 50).


Copyright Jo Wood, 1996-2009, last modified, 17th April, 2009