net.sf.j3d.threeD.raytracer.primitives
Class Mesh

java.lang.Object
  extended by net.sf.j3d.threeD.raytracer.engine.AbstractSurface
      extended by net.sf.j3d.threeD.raytracer.engine.SurfaceGroup
          extended by net.sf.j3d.threeD.raytracer.engine.SpacePartition
              extended by net.sf.j3d.threeD.raytracer.primitives.Mesh
All Implemented Interfaces:
Surface

public class Mesh
extends SpacePartition

A Mesh object stores a set of points (Vector objects) and allows triangles to be specified using those points.

Author:
Mike Murray

Nested Class Summary
static class Mesh.MeshFile
           
static class Mesh.Vertex
           
static interface Mesh.VertexData
           
 
Field Summary
 
Fields inherited from class net.sf.j3d.threeD.raytracer.engine.SpacePartition
l, r, s
 
Constructor Summary
Mesh()
          Constructs a new Mesh object.
Mesh(Mesh.VertexData data)
           
Mesh(Vector[] points, int[][] triangles)
          Constructs a new Mesh object.
 
Method Summary
 void addSurface(Surface s)
          Adds the specified Surface object to this SurfaceGroup object and sets its parent to this SurfaceGroup object (if it is an instance of AbstractSurface).
 int addTriangle(int p1, int p2, int p3)
          Adds the triangle described by the specified points to the mesh represented by this Mesh object.
 int addVector(Vector p)
          Adds the point defined by the specified Vector object to the mesh represented by this Mesh object.
 void clearIgnoreCache()
           
 void clearIntersectionCache()
           
 void clearTriangleCache()
           
 int downsample(double l, double p)
          Downsamples this mesh by setting the ignore flag for some triangles.
 Object encode()
           
 int extrudeFace(int face, double l)
          Extrudes the specified face in the direction of its surface normal by the distance specified.
 int extrudeFace(int p1, int p2, int p3, Vector n)
          Extrudes the specified face with an offset of the specified vector.
 int extrudeFace(int face, Vector n)
          Extrudes the specified face with an offset of the specified vector.~ This method probably does not work properly.
 int getIndex(Vector v)
           
 boolean getInterpolateColor()
           
 Vector getNormalAt(Vector point)
          Returns null.
 boolean getRemoveBackFaces()
           
 boolean getSmooth()
           
 Surface getSurface(int index)
          Returns the Surface object stored by this SurfaceGroup object at the specified index.
 Surface[] getSurfaces()
          Returns the Surface objects stored by this SurfaceGroup object as a Surface array.
 Triangle getTriangle(int face)
          Checks triangle cache for the specified face index, and constructs a Triangle object if it is not present.
 Triangle getTriangle(int face, boolean cache)
          Checks triangle cache for the specified face index, and constructs a Triangle object if it is not present.
 int[][] getTriangleData()
           
 int[][] getTriangleData(boolean b)
           
 Triangle[] getTriangles()
           
 Mesh.Vertex[] getVectors()
           
 Mesh.Vertex[] getVectors(boolean b)
           
 int indexOf(Vector v)
           
 boolean intersect(Ray ray)
          Returns true if the ray represented by the specified Ray object intersects any of the surfaces represented by this SurfaceGroup object.
 Intersection intersectAt(Ray ray)
          Returns an Intersection object that represents the ray-surface intersections for the AbstractSurface object which is intersected closest to the origin of the ray (>= 0).
 Iterator iterateVectors()
           
 void loadTree()
           
 void loadTriangles()
           
 void removeSurface(int index)
          Removes the Surface object stored at the specified index from this SurfaceGroup object and sets the parent of the removed Surface object to null (if it is an instance of AbstractSurface).
 void setInterpolateColor(boolean c)
           
 void setRemoveBackFaces(boolean b)
           
 void setSmooth(boolean smooth)
          Sets the smooth flag for this Mesh object.
 void setSurfaces(Surface[] surfaces)
          Does nothing.
 void setTriangleData(int[][] data)
           
 void setVectors(Mesh.Vertex[] p)
          Removes all points stored by this Mesh and adds those stored in the specified array.
 Mesh triangulate()
           
 
Methods inherited from class net.sf.j3d.threeD.raytracer.engine.SpacePartition
isTreeLoaded, loadTree
 
Methods inherited from class net.sf.j3d.threeD.raytracer.engine.SurfaceGroup
shade
 
Methods inherited from class net.sf.j3d.threeD.raytracer.engine.AbstractSurface
addShader, addTexture, addTransform, calculateTransform, getColor, getColorAt, getColorAt, getIndexOfRefraction, getIndexOfRefraction, getLocation, getParent, getReflectedPercentage, getReflectedPercentage, getRefractedPercentage, getRefractedPercentage, getRotationCoefficients, getScaleCoefficients, getShadeBack, getShadeFront, getShaderSet, getSize, getTexture, getTextures, getTextureSet, getTransform, getTransform, getTransforms, removeTexture, removeTransform, setColor, setIndexOfRefraction, setLocation, setParent, setReflectedPercentage, setRefractedPercentage, setRotationCoefficients, setScaleCoefficients, setShadeBack, setShadeFront, setShaders, setShaders, setSize, setTexture, setTextures, setTransform, setTransforms
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Mesh

public Mesh()
Constructs a new Mesh object.


Mesh

public Mesh(Vector[] points,
            int[][] triangles)
Constructs a new Mesh object.

Parameters:
points - Array of points to use.
triangles - {{x0, y0, z0}, {x1, y1, z1},...} Where the int values are indices in the points array.

Mesh

public Mesh(Mesh.VertexData data)
Method Detail

addVector

public int addVector(Vector p)
Adds the point defined by the specified Vector object to the mesh represented by this Mesh object.

Parameters:
p - Vector object to add.
Returns:
The unique index of the point to be used when adding triangles.

addTriangle

public int addTriangle(int p1,
                       int p2,
                       int p3)
Adds the triangle described by the specified points to the mesh represented by this Mesh object.

Parameters:
p1 - Index of first point.
p2 - Index of second point.
p3 - Index of third point.
Returns:
The unique index of the triangle added or -1 if it is not added (if any point indicies are the same).
Throws:
IllegalArgumentException - if any of the indicies specified are not valid.

clearIgnoreCache

public void clearIgnoreCache()

loadTree

public void loadTree()
Overrides:
loadTree in class SpacePartition

loadTriangles

public void loadTriangles()

clearTriangleCache

public void clearTriangleCache()

clearIntersectionCache

public void clearIntersectionCache()

setVectors

public void setVectors(Mesh.Vertex[] p)
Removes all points stored by this Mesh and adds those stored in the specified array.

Parameters:
p - Array of Vertex objects to add.

getVectors

public Mesh.Vertex[] getVectors()
Returns:
An array of Mesh.Vertex objects stored by this Mesh object.

getVectors

public Mesh.Vertex[] getVectors(boolean b)

iterateVectors

public Iterator iterateVectors()

setTriangleData

public void setTriangleData(int[][] data)

getTriangleData

public int[][] getTriangleData()

getTriangleData

public int[][] getTriangleData(boolean b)

getTriangles

public Triangle[] getTriangles()
Returns:
An array of Triangle objects stored by this Mesh object.

getTriangle

public Triangle getTriangle(int face)
Checks triangle cache for the specified face index, and constructs a Triangle object if it is not present.

Parameters:
face - Index of face.
Returns:
The Traingle object requested.

getTriangle

public Triangle getTriangle(int face,
                            boolean cache)
Checks triangle cache for the specified face index, and constructs a Triangle object if it is not present. This Mesh object makes no guarantee that Triangle objects stored in the triangle cache will reflect changes to the state of the Mesh made after the cache is made. See the clearTriangleCache method...

Parameters:
face - Index of face.
cache - True if Triangle should be cached if it is created, false otherwise.
Returns:
The Triangle object requested.

indexOf

public int indexOf(Vector v)
Parameters:
v - Vector to return index of.
Returns:
The integer index of the specified Vector object stored by this mesh, -1 if the it is not found.

getNormalAt

public Vector getNormalAt(Vector point)
Description copied from class: SurfaceGroup
Returns null.

Specified by:
getNormalAt in interface Surface
Overrides:
getNormalAt in class SurfaceGroup
Returns:
null.

setSmooth

public void setSmooth(boolean smooth)
Sets the smooth flag for this Mesh object. If the flag is true, the surface normals will be interpolated to produce a smoothing effect.

Parameters:
smooth - Boolean flag to use.

getSmooth

public boolean getSmooth()
Returns:
True if this Mesh object will be smoothed when rendered, false otherwise.

setRemoveBackFaces

public void setRemoveBackFaces(boolean b)
Parameters:
b - True if bace faces should be ignored, false if they should be included.

getRemoveBackFaces

public boolean getRemoveBackFaces()
Returns:
True if back faces will be ignored, false if they will be included.

setInterpolateColor

public void setInterpolateColor(boolean c)
Parameters:
c - If set to true, color will be interpolated based on vertex colors.

getInterpolateColor

public boolean getInterpolateColor()
Returns:
True if color will be interpolated based on vertex colors, false otherwise.

getIndex

public int getIndex(Vector v)

downsample

public int downsample(double l,
                      double p)
Downsamples this mesh by setting the ignore flag for some triangles. Each triangle is given an 'l' value that is the sum of the side lengths. If this value is below the specified threshold, it is ignored with a with the specified probability. This can be undone by calling clearIgnoreCache. Also note that the cache must be loaded for this to work, so before using it you must call clearIgnoreCache.

Parameters:
l - Threshold perimeter value.
p - Probability of elimination (0.0 - 1.0).
Returns:
The number of ignored triangles.

extrudeFace

public int extrudeFace(int face,
                       double l)
Extrudes the specified face in the direction of its surface normal by the distance specified.

Parameters:
face - Index of triangle to extrude.
l - Length to extrude.
Returns:
The index of the triangle at the opposite end of the prisim that is created by extrusion.

extrudeFace

public int extrudeFace(int face,
                       Vector n)
Extrudes the specified face with an offset of the specified vector.~ This method probably does not work properly.

Parameters:
face - Index of triangle to extrude.
n - Normal to offset by.
Returns:
The index of the triangle at the opposite end of the prisim that is created by extrusion.

extrudeFace

public int extrudeFace(int p1,
                       int p2,
                       int p3,
                       Vector n)
Extrudes the specified face with an offset of the specified vector.

Parameters:
p1 - Index of first point of triangle to extrude.
p1 - Index of second point of triangle to extrude.
p1 - Index of third point of triangle to extrude.
n - Normal to offset by.
Returns:
The index of the triangle at the opposite end of the prisim that is created by extrusion.

triangulate

public Mesh triangulate()
Overrides:
triangulate in class SurfaceGroup
Returns:
this.

intersect

public boolean intersect(Ray ray)
Description copied from class: SurfaceGroup
Returns true if the ray represented by the specified Ray object intersects any of the surfaces represented by this SurfaceGroup object.

Specified by:
intersect in interface Surface
Overrides:
intersect in class SpacePartition
See Also:
Surface.intersect(net.sf.j3d.threeD.raytracer.engine.Ray)

intersectAt

public Intersection intersectAt(Ray ray)
Description copied from class: SurfaceGroup
Returns an Intersection object that represents the ray-surface intersections for the AbstractSurface object which is intersected closest to the origin of the ray (>= 0). If there is no intersection >= 0 along the ray, null is returned.

Specified by:
intersectAt in interface Surface
Overrides:
intersectAt in class SpacePartition
See Also:
Surface.intersectAt(net.sf.j3d.threeD.raytracer.engine.Ray)

setSurfaces

public void setSurfaces(Surface[] surfaces)
Does nothing.

Overrides:
setSurfaces in class SurfaceGroup

addSurface

public void addSurface(Surface s)
Description copied from class: SurfaceGroup
Adds the specified Surface object to this SurfaceGroup object and sets its parent to this SurfaceGroup object (if it is an instance of AbstractSurface).

Overrides:
addSurface in class SurfaceGroup

removeSurface

public void removeSurface(int index)
Description copied from class: SurfaceGroup
Removes the Surface object stored at the specified index from this SurfaceGroup object and sets the parent of the removed Surface object to null (if it is an instance of AbstractSurface).

Overrides:
removeSurface in class SurfaceGroup

getSurfaces

public Surface[] getSurfaces()
Description copied from class: SurfaceGroup
Returns the Surface objects stored by this SurfaceGroup object as a Surface array.

Overrides:
getSurfaces in class SurfaceGroup

getSurface

public Surface getSurface(int index)
Description copied from class: SurfaceGroup
Returns the Surface object stored by this SurfaceGroup object at the specified index.

Overrides:
getSurface in class SurfaceGroup
Returns:
The Triangle object stored by this Mesh object with the specified index.

encode

public Object encode()