edu.d.umn.geometry
Class ElevationSegment

java.lang.Object
  extended by javax.media.j3d.SceneGraphObject
      extended by javax.media.j3d.Node
          extended by javax.media.j3d.Leaf
              extended by javax.media.j3d.Shape3D
                  extended by edu.d.umn.geometry.ElevationSegment

public class ElevationSegment
extends javax.media.j3d.Shape3D

ElevationSegment is a specialization of Shape3d. It creates a 3D map of terrain data using an interleaved triangle strip array. Terrain data is passed into ElevationSegment as a two dimensional array of elevations. These are converted into a series of triangle strips to represent their geometry.


Field Summary
protected static int COORD_OFFSET
           
protected static int FLOATSPERVERTEX
           
protected  javax.vecmath.Color3f matColor
           
protected static int NORMAL_OFFSET
           
protected static int TEXT_OFFSET
           
protected  InterleavedTriangleStripArray tstrip
           
protected  float[] vertexData
           
 
Fields inherited from class javax.media.j3d.Shape3D
ALLOW_APPEARANCE_OVERRIDE_READ, ALLOW_APPEARANCE_OVERRIDE_WRITE, ALLOW_APPEARANCE_READ, ALLOW_APPEARANCE_WRITE, ALLOW_COLLISION_BOUNDS_READ, ALLOW_COLLISION_BOUNDS_WRITE, ALLOW_GEOMETRY_READ, ALLOW_GEOMETRY_WRITE
 
Fields inherited from class javax.media.j3d.Node
ALLOW_AUTO_COMPUTE_BOUNDS_READ, ALLOW_AUTO_COMPUTE_BOUNDS_WRITE, ALLOW_BOUNDS_READ, ALLOW_BOUNDS_WRITE, ALLOW_COLLIDABLE_READ, ALLOW_COLLIDABLE_WRITE, ALLOW_LOCAL_TO_VWORLD_READ, ALLOW_LOCALE_READ, ALLOW_PARENT_READ, ALLOW_PICKABLE_READ, ALLOW_PICKABLE_WRITE, ENABLE_COLLISION_REPORTING, ENABLE_PICK_REPORTING
 
Constructor Summary
ElevationSegment(int[][] elevations, int startRow, int startColumn, int stopRow, int stopColumn, int minEl, int maxEl, float exageration, float lowX, float highX, float lowZ, float highZ, int resolution, float modelWidth, float modelLength)
          Constructor is reponsible for setting up the appearance/material, computing the triangle strip values (colors, normals, coordinates) stored in vertexData, then creating the actual JAVA 3D geometry.
 
Method Summary
 void changeExageration(float oldAmount, float newAmount)
          Method to get at the triangle strip's change exageration method.
 float getElevationAt(float x, float z)
          Fetches the elevation at a particular location on the terrain map given the x,z coordinates.
 void recalcNormals()
          Recalculates the normal values so that the lighting effects change when the elevation exageration change.
 void setColor(java.awt.Color color)
           
 void setColor(int i)
          store color data into vertex data array.
 void setColor(int i, int elevation, int minElevation, int maxElevation)
          store color data into vertex data array, compute color based on the elevation's distance between min and max elevations
 void setCoordinate(int[][] elevations, int i, int row, int col, int startRow, int startColumn, float exageration)
          store coordinate data into vertex data array
 void setTexture(javax.media.j3d.Texture2D texture)
          Change the texture currently being used.
protected  void setTextureCoordinates(int i, double x, double y)
          Stores texture coordinates into vertex data array.
protected  void setupAppearance()
          setup the material properties and coloring attributes
 void stitchRight(ElevationSegment other)
          stitch right of this segment to left of other segment, stitching consists of averaging the normals on the common boundary vertices between segments.
 void stitchTop(ElevationSegment other)
          stitch top of this segment to bottom of other segment, stitching consists of averaging the normals on the common boundary vertices between segments.
 
Methods inherited from class javax.media.j3d.Shape3D
addGeometry, cloneNode, duplicateNode, getAllGeometries, getAppearance, getAppearanceOverrideEnable, getBounds, getCollisionBounds, getGeometry, getGeometry, indexOfGeometry, insertGeometry, intersect, intersect, intersect, numGeometries, removeAllGeometries, removeGeometry, removeGeometry, setAppearance, setAppearanceOverrideEnable, setCollisionBounds, setGeometry, setGeometry
 
Methods inherited from class javax.media.j3d.Node
cloneTree, cloneTree, cloneTree, cloneTree, cloneTree, cloneTree, getBoundsAutoCompute, getCollidable, getLocale, getLocalToVworld, getLocalToVworld, getParent, getPickable, setBounds, setBoundsAutoCompute, setCollidable, setPickable
 
Methods inherited from class javax.media.j3d.SceneGraphObject
clearCapability, clearCapabilityIsFrequent, duplicateSceneGraphObject, getCapability, getCapabilityIsFrequent, getName, getUserData, isCompiled, isLive, setCapability, setCapabilityIsFrequent, setName, setUserData, toString, updateNodeReferences
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

tstrip

protected InterleavedTriangleStripArray tstrip

FLOATSPERVERTEX

protected static final int FLOATSPERVERTEX
See Also:
Constant Field Values

TEXT_OFFSET

protected static final int TEXT_OFFSET
See Also:
Constant Field Values

NORMAL_OFFSET

protected static final int NORMAL_OFFSET
See Also:
Constant Field Values

COORD_OFFSET

protected static final int COORD_OFFSET
See Also:
Constant Field Values

vertexData

protected float[] vertexData

matColor

protected javax.vecmath.Color3f matColor
Constructor Detail

ElevationSegment

public ElevationSegment(int[][] elevations,
                        int startRow,
                        int startColumn,
                        int stopRow,
                        int stopColumn,
                        int minEl,
                        int maxEl,
                        float exageration,
                        float lowX,
                        float highX,
                        float lowZ,
                        float highZ,
                        int resolution,
                        float modelWidth,
                        float modelLength)
Constructor is reponsible for setting up the appearance/material, computing the triangle strip values (colors, normals, coordinates) stored in vertexData, then creating the actual JAVA 3D geometry.

Parameters:
modelWidth - the width of the ElevationModel that this segment belongs to.
modelLength - The Length of the ElevationModel to which this segment belongs.
elevations - two dimensional array of terrain elevation data in meters
startRow - first row of data to use from elevations
startColumn - first column of data to use from elevations
stopRow - last row of data to use from elevations
stopColumn - last column of data to use from elevations
minEl - minimum elevation in elevations
maxEl - maximum elevation in elevations
exageration - amount to exagerate(multiply) elevations by
lowX - starting x coordinate in meters
highX - stopping x coordinate in meters
lowZ - starting z coordinate in meters
highZ - stopping z coordinate in meters
resolution - number of rows/columns of elevation data to skip when mapping. A resolution of 1 implies mapping every elevation point, a resolution of 10 implies mapping every 10th point.
Method Detail

setupAppearance

protected void setupAppearance()
setup the material properties and coloring attributes


setCoordinate

public void setCoordinate(int[][] elevations,
                          int i,
                          int row,
                          int col,
                          int startRow,
                          int startColumn,
                          float exageration)
store coordinate data into vertex data array

Parameters:
startColumn - first column used in elevations
elevations - array of elevations
i - index into vertexData to store coordinate
row - elevation row
col - elevation column
startRow - first row used in elevations
exageration - elevation exageration factor

setColor

public void setColor(int i,
                     int elevation,
                     int minElevation,
                     int maxElevation)
store color data into vertex data array, compute color based on the elevation's distance between min and max elevations

Parameters:
i - index into vertexData to store coordinate
elevation - vertex elevation (no exageration)
minElevation - minimum elevation in model
maxElevation - maximum elevation in model

setColor

public void setColor(int i)
store color data into vertex data array. This is a flat color, as opposed to the other setColor method which changes color based on elevation.

Parameters:
i - The index into the vertexData array.

setColor

public void setColor(java.awt.Color color)

stitchRight

public void stitchRight(ElevationSegment other)
stitch right of this segment to left of other segment, stitching consists of averaging the normals on the common boundary vertices between segments. That is, since adjacent segments have the same vertices in common (the left side of one is the same as the right side of the other), then these normals should be the same as well to prevent visible seams.

Parameters:
other - reference to the segment to the right of this one

stitchTop

public void stitchTop(ElevationSegment other)
stitch top of this segment to bottom of other segment, stitching consists of averaging the normals on the common boundary vertices between segments. That is, since adjacent segments have the same vertices in common (the top of one is the same as the bottom of the other), then these normals should be the same as well to prevent visible seams.

Parameters:
other - reference to the segment to the right of this one

getElevationAt

public float getElevationAt(float x,
                            float z)
Fetches the elevation at a particular location on the terrain map given the x,z coordinates. X,Z coordinates represent the distance in meters from the center of the terrain image

Parameters:
x - x coordinate
z - z coordinate
Returns:
the elevation (y coordinate) in meters (adjusted for exageration)

changeExageration

public void changeExageration(float oldAmount,
                              float newAmount)
Method to get at the triangle strip's change exageration method.

Parameters:
oldAmount - The old value of the exageration. Used to reset to natural elevation.
newAmount - The new exageration to change to.

setTextureCoordinates

protected void setTextureCoordinates(int i,
                                     double x,
                                     double y)
Stores texture coordinates into vertex data array.

Parameters:
i - index into vertexData to store coordinate
x - x component of the texture coordinates
y - y component of the texture coordinates

setTexture

public void setTexture(javax.media.j3d.Texture2D texture)
Change the texture currently being used.

Parameters:
texture - The new Texture2D to use.

recalcNormals

public void recalcNormals()
Recalculates the normal values so that the lighting effects change when the elevation exageration change.