edu.mines.jtk.sgl
Class TriangleGroup

java.lang.Object
  extended by edu.mines.jtk.sgl.Node
      extended by edu.mines.jtk.sgl.Group
          extended by edu.mines.jtk.sgl.TriangleGroup
All Implemented Interfaces:
Selectable

public class TriangleGroup
extends Group
implements Selectable

A group of triangles that represents a triangulated surface.

Triangles may be specified by providing an array of packed vertex (x,y,z) coordinates and an array of packed (i,j,k) vertex indices. Each triplet (i,j,k) of vertex indices corresponds to one triangle.

Alternatively, triangles may be specified by providing only the array of packed vertex (x,y,z) coordinates. In this case, a vertex index is assigned automatically to each vertex.

Normal vectors are computed for each vertex as an area-weighted average of the vectors normal to all triangles that reference that vertex with the same index. These area-weighted normal vectors are used in lighting.

Version:
2006.06.27
Author:
Dave Hale, Christine Brady, Adam McCormick, Zachary Pember, Danielle Schulte, Colorado School of Mines

Constructor Summary
TriangleGroup(boolean vn, float[] xyz)
          Constructs a triangle group with specified vertex coordinates.
TriangleGroup(boolean vn, float[] xyz, float[] rgb)
          Constructs a triangle group with specified vertex coordinates.
TriangleGroup(boolean vn, Sampling sx, Sampling sy, float[][] z)
          Constructs a triangle group for a sampled function z = f(x,y).
TriangleGroup(boolean vn, Sampling sx, Sampling sy, float[][] z, float[][] r, float[][] g, float[][] b)
          Constructs a triangle group for a sampled function z = f(x,y).
TriangleGroup(float[] xyz, float[] uvw)
          Constructs a triangle group with specified vertex coordinates.
TriangleGroup(float[] xyz, float[] uvw, float[] rgb)
          Constructs a triangle group with specified vertex coordinates and optional corresponding normal vectors and colors.
TriangleGroup(int[] ijk, float[] xyz)
          Constructs a triangle group with specified vertex coordinates.
TriangleGroup(int[] ijk, float[] xyz, float[] uvw)
          Constructs a triangle group with specified vertex coordinates.
TriangleGroup(int[] ijk, float[] xyz, float[] uvw, float[] rgb)
          Constructs a triangle group with specified vertex coordinates and optional corresponding normal vectors and colors.
 
Method Summary
static int[] indexVertices(boolean sequential, float[] xyz)
          Computes indices ijk for triangle vertex coordinates xyz.
protected  void selectedChanged()
          This method is called when the selected state of this node has changed.
 void setColor(java.awt.Color color)
          Sets the color of the triangles in this triangle group.
 
Methods inherited from class edu.mines.jtk.sgl.Group
addChild, computeBoundingSphere, countChildren, cull, draw, getAttributeBits, getChildren, pick, removeChild
 
Methods inherited from class edu.mines.jtk.sgl.Node
countParents, cullApply, cullBegin, cullEnd, dirtyBoundingSphere, dirtyDraw, drawApply, drawBegin, drawEnd, getBoundingSphere, getParents, getStates, getWorld, isSelected, pickApply, pickBegin, pickEnd, setSelected, setStates
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface edu.mines.jtk.sgl.Selectable
isSelected, setSelected
 

Constructor Detail

TriangleGroup

public TriangleGroup(boolean vn,
                     float[] xyz)
Constructs a triangle group with specified vertex coordinates.

The (x,y,z) coordinates of vertices are packed into the specified array xyz. The number of vertices is nv = xyz.length/3. The number of triangles is nt = nv/3 = xyz.length/9.

Normal vectors may be computed for either vertices or triangles. When computed for a vertex, a normal vector is the area-weighted average of the normal vectors for all triangles with that vertex.

If no vertices have the same (x,y,z) coordinates, then vertex and triangle normal vectors are the same vectors, but triangle normal vectors are less costly to compute.

Parameters:
vn - true, for vertex normals; false, for triangle normals.
xyz - array[3*nv] of packed vertex coordinates.

TriangleGroup

public TriangleGroup(boolean vn,
                     float[] xyz,
                     float[] rgb)
Constructs a triangle group with specified vertex coordinates.

The (x,y,z) coordinates of vertices are packed into the specified array xyz. The number of vertices is nv = xyz.length/3. The number of triangles is nt = nv/3 = xyz.length/9.

The (r,g,b) components of colors are packed into the specified array rgb. The number of colors equals the number of vertices.

Normal vectors may be computed for either vertices or triangles. When computed for a vertex, a normal vector is the area-weighted average of the normal vectors for all triangles with that vertex.

If no vertices have the same (x,y,z) coordinates, then vertex and triangle normal vectors are the same vectors, but triangle normal vectors are less costly to compute.

Parameters:
vn - true, for vertex normals; false, for triangle normals.
xyz - array[3*nv] of packed vertex coordinates.
rgb - array[3*nv] of packed color components.

TriangleGroup

public TriangleGroup(boolean vn,
                     Sampling sx,
                     Sampling sy,
                     float[][] z)
Constructs a triangle group for a sampled function z = f(x,y).

Parameters:
vn - true, for vertex normals; false, for triangle normals.
sx - sampling of x coordinates; may be non-uniform.
sy - sampling of y coordinates; may be non-uniform.
z - array[nx][ny] of z coordinates z = f(x,y).

TriangleGroup

public TriangleGroup(boolean vn,
                     Sampling sx,
                     Sampling sy,
                     float[][] z,
                     float[][] r,
                     float[][] g,
                     float[][] b)
Constructs a triangle group for a sampled function z = f(x,y).

Parameters:
vn - true, for vertex normals; false, for triangle normals.
sx - sampling of x coordinates; may be non-uniform.
sy - sampling of y coordinates; may be non-uniform.
z - array[nx][ny] of z coordinates z = f(x,y).
r - array[nx][ny] of red color components.
g - array[nx][ny] of green color components.
b - array[nx][ny] of blue color components.

TriangleGroup

public TriangleGroup(int[] ijk,
                     float[] xyz)
Constructs a triangle group with specified vertex coordinates.

Triangles are specified by triplets of vertex indices (i,j,k), one triplet per triangle, packed into the specified array of integers ijk. The number of triangles is nt = ijk.length/3.

The (x,y,z) coordinates of vertices are packed into the specified array xyz. The number of vertices is nv = xyz.length/3.

For any vertex with index iv, this method computes a normal vector as an area-weighted average of the normal vectors for all triangles specified with index iv.

Parameters:
ijk - array[3*nt] of packed vertex indices.
xyz - array[3*nv] of packed vertex coordinates.

TriangleGroup

public TriangleGroup(float[] xyz,
                     float[] uvw)
Constructs a triangle group with specified vertex coordinates.

The (x,y,z) coordinates of vertices are packed into the specified array xyz. The number of vertices is nv = xyz.length/3.

The (u,v,w) components of normal vectors are packed into the specified array uvw. The number of normal vectors equals the number of vertices.

Parameters:
xyz - array[3*nv] of packed vertex coordinates.
uvw - array[3*nv] of packed normal vector components.

TriangleGroup

public TriangleGroup(int[] ijk,
                     float[] xyz,
                     float[] uvw)
Constructs a triangle group with specified vertex coordinates.

Triangles are specified by triplets of vertex indices (i,j,k), one triplet per triangle, packed into the specified array of integers ijk. The number of triangles is nt = ijk.length/3.

The (x,y,z) coordinates of vertices are packed into the specified array xyz. The number of vertices is nv = xyz.length/3.

The (u,v,w) components of normal vectors are packed into the specified array uvw. The number of normal vectors equals the number of vertices.

Parameters:
ijk - array[3*nt] of packed vertex indices.
xyz - array[3*nv] of packed vertex coordinates.
uvw - array[3*nv] of packed normal vector components.

TriangleGroup

public TriangleGroup(float[] xyz,
                     float[] uvw,
                     float[] rgb)
Constructs a triangle group with specified vertex coordinates and optional corresponding normal vectors and colors.

The (x,y,z) coordinates of vertices are packed into the specified array xyz. The number of vertices is nv = xyz.length/3.

The (u,v,w) components of normal vectors are packed into the specified array uvw. The number of normal vectors equals the number of vertices.

The (r,g,b) components of colors are packed into the specified array rgb. The number of colors equals the number of vertices.

Parameters:
xyz - array[3*nv] of packed vertex coordinates.
uvw - array[3*nv] of packed normal vector components.
rgb - array[3*nv] of packed color components.

TriangleGroup

public TriangleGroup(int[] ijk,
                     float[] xyz,
                     float[] uvw,
                     float[] rgb)
Constructs a triangle group with specified vertex coordinates and optional corresponding normal vectors and colors.

Triangles are specified by triplets of vertex indices (i,j,k), one triplet per triangle, packed into the specified array of integers ijk. The number of triangles is nt = ijk.length/3.

The (x,y,z) coordinates of vertices are packed into the specified array xyz. The number of vertices is nv = xyz.length/3.

The (u,v,w) components of normal vectors are packed into the specified array uvw. If not null, the number of normal vectors equals the number of vertices.

The (r,g,b) components of colors are packed into the specified array rgb. If not null, the number of colors equals the number of vertices.

Parameters:
ijk - array[3*nt] of packed vertex indices.
xyz - array[3*nv] of packed vertex coordinates.
uvw - array[3*nv] of packed normal vector components.
rgb - array[3*nv] of packed color components.
Method Detail

indexVertices

public static int[] indexVertices(boolean sequential,
                                  float[] xyz)
Computes indices ijk for triangle vertex coordinates xyz.

The (x,y,z) coordinates of vertices are packed into the specified array xyz. The number of vertices is nv = xyz.length/3. The number of triangles is nt = nv/3 = xyz.length/9.

For each triangle, this method computes a triplet (i,j,k) of integer vertex indices. A vertex index is an integer in the range [0,nv-1]. The (x,y,z) coordinates of a vertex with index iv are xyz[3*iv+0], xyz[3*iv+1] and xyz[3*iv+2], respectively.

The simplest indexing is the sequence {0, 1, 2, ..., nv-1}. In this case, indices are assigned sequentially, so that every vertex of every triangle has a different index.

In non-sequential indexing, vertices with the same (x,y,z) coordinates are assigned the same index. Again, index vertices will be in the range [0,nv-1], but some integers in this range may not be used. Whereas sequential indexing would assign integers ia and ib to two vertices that have the same (x,y,z) coordinates, non-sequential indexing will assign the smaller index min(ia,ib) to both vertices; the larger index max(ia,ib) will be unused.

Triplets of indices (i,j,k), one triplet per triangle, are packed into the returned array of integers ijk, which has length 3*nt.

Parameters:
sequential - true, for sequential indexing; false, otherwise.
xyz - array[3*nv] of packed vertex coordinates.
Returns:
an array[3*nt] of packed vertex indices.

setColor

public void setColor(java.awt.Color color)
Sets the color of the triangles in this triangle group. Note that if per-vertex colors were specified when this triangle group was constructed, then the color specified here is not used.

Parameters:
color - the color.

selectedChanged

protected void selectedChanged()
Description copied from class: Node
This method is called when the selected state of this node has changed. Classes that extend this abstract base class typically override this method to alter this node's appearance when selected or deselected.

This implementation does nothing.

Overrides:
selectedChanged in class Node