de.grogra.vecmath.geom Class MeshVolume

```java.lang.Object de.grogra.vecmath.geom.VolumeBase de.grogra.vecmath.geom.MeshVolume
```
All Implemented Interfaces:
Volume, java.lang.Cloneable
Direct Known Subclasses:
MyMeshVolume

`public class MeshVolumeextends VolumeBaseimplements java.lang.Cloneable`

This class represents a given `Mesh` as a `Volume`. It uses an octree in order to speed up the intersection computation; an octree cell contains a list of those polygons of the mesh which lie within the cell.

The algorithm for a single polygon-line intersection is an extension to general polygonal meshes (with convex, planar polygons) of the algorithm in the paper "Ray Tracing Triangular Meshes" of John Amanatides and Kin Choi. The algorithm uses Plücker coordinates to decide if a line intersects a polygon.

The mesh coordinates are specified in their own coordinate system. The transformation from world coordinates to mesh coordinates is implemented by `worldToMesh`. The advantage of this is that it is possible to create a set of copies of a `MeshVolume` using `dup()` which can then be shifted to another location using `setTransformation(Matrix4d)`.

To set the data of a `MeshVolume`, both methods `setMesh(de.grogra.vecmath.geom.Mesh)` and `setTransformation(javax.vecmath.Matrix4d)` have to be invoked in this order.

Author:
Ole Kniemeyer

Field Summary
`static int` `MIN_CELL_OBJECTS`
Minimum number of polygons which have to be present in an octree cell so that it is considered for subdivision.

Constructor Summary
`MeshVolume()`

Method Summary
` boolean` ```boxContainsBoundary(BoundingBox box, Tuple3d center, double radius, Variables temp)```
Returns `true` if the specified `box` contains (part of) the boundary surface of this volume.
` void` ```computeFaceNormal(Intersection is, Vector3d normal)```
Compute the face normal of the triangle that was hit (is.face).
` boolean` ```computeIntersections(Line line, int which, IntersectionList list, Intersection excludeStart, Intersection excludeEnd)```
Computes intersections between the boundary surface of this object and the specified `line`.
` void` ```computeNormal(Intersection is, Vector3d normal)```
This method computes the unit normal vector of an intersection `is` which has been computed previously by the invocation of `Volume.computeIntersections(de.grogra.vecmath.geom.Line, int, de.grogra.vecmath.geom.IntersectionList, de.grogra.vecmath.geom.Intersection, de.grogra.vecmath.geom.Intersection)` on this volume.
` void` ```computeTangents(Intersection is, Vector3d dpdu, Vector3d dpdv)```
This method computes the derivatives of the surface point (as function of the uv-coordinates, see `Volume.computeUV(de.grogra.vecmath.geom.Intersection, javax.vecmath.Vector2d)`) with respect to u and v at the intersection point.
` void` ```computeUV(Intersection is, Vector2d uv)```
This method computes the uv-coordinates of an intersection point `is` which has been computed previously by the invocation of `Volume.computeIntersections(de.grogra.vecmath.geom.Line, int, de.grogra.vecmath.geom.IntersectionList, de.grogra.vecmath.geom.Intersection, de.grogra.vecmath.geom.Intersection)` on this volume.
` boolean` ```contains(Tuple3d point, boolean open)```
Determines if the given `point` lies within this object.
` MeshVolume` `dup()`
Creates a duplicate of this mesh.
` void` ```getExtent(Tuple3d min, Tuple3d max, Variables temp)```
Computes the extent of this volume, i.e., an axis-aligned bounding box between `min` and `max`.
` Octree` `getOctree()`

` int` `getPolygonCount()`

` void` `setMesh(Mesh mesh)`
Sets the mesh of this volume to the specified `mesh`.
` void` `setTransformation(Matrix4d meshToWorld)`
Sets the transformation from mesh coordinates to global world coordinates.

Methods inherited from class de.grogra.vecmath.geom.VolumeBase
`addConvexIntersections, getId, operator\$and, operator\$com, operator\$or, operator\$sub, setId`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

MIN_CELL_OBJECTS

`public static int MIN_CELL_OBJECTS`
Minimum number of polygons which have to be present in an octree cell so that it is considered for subdivision.

Constructor Detail

MeshVolume

`public MeshVolume()`
Method Detail

boxContainsBoundary

```public boolean boxContainsBoundary(BoundingBox box,
Tuple3d center,
Variables temp)```
Description copied from interface: `Volume`
Returns `true` if the specified `box` contains (part of) the boundary surface of this volume. Otherwise, if box and boundary do not overlap, this method should return `false`, but may also return `true` if an exact computation would be too expensive or complicated.

Note that a box contains the boundary of a closed set S iff both have a non-empty intersection and the box is not contained in the open set of S.

Specified by:
`boxContainsBoundary` in interface `Volume`
Parameters:
`box` - bounding box
`center` - center coordinates of box
`radius` - radius of enclosing sphere
`temp` - has to be provided by the invoker, may be used in implementations
Returns:
`true` if box contains (part of) the boundary of this volume

computeFaceNormal

```public void computeFaceNormal(Intersection is,
Vector3d normal)```
Compute the face normal of the triangle that was hit (is.face). The normal vector is calculated as the cross product between the edge vectors of the triangle.

Parameters:
`is` - intersection between this volume and a ray
`normal` - output memory for computed normal vector

computeIntersections

```public boolean computeIntersections(Line line,
int which,
IntersectionList list,
Intersection excludeStart,
Intersection excludeEnd)```
Description copied from interface: `Volume`
Computes intersections between the boundary surface of this object and the specified `line`. The intersections are added to `list` in ascending order of distance (i.e., of `Intersection.parameter`), where the `parameter` has to lie between `line.start` and `line.end`. Implementations of this method must not clear or modify the existing intersections in `list`.

The parameter `which` has to be one of `Intersection.ALL`, `Intersection.CLOSEST`, `Intersection.ANY`. It determines if all intersections have to be added to the list, only the closest (minimal value of `Intersection.parameter`), or an arbitrary of the set of all intersections. Only in case of `ALL`, the return value of this method is precise.

If specific intersection points should be excluded from the list of computed intersections, they have to be specified in `excludeStart` and `excludeEnd`. The intersection point of `excludeStart` has to be the starting point of `line`, the intersection point of `excludeEnd` has to be the end point of `line`. The exclusion of intersections is a useful feature for ray-tracing, e.g., when a ray is re-emitted at an intersection point in another direction.

Specified by:
`computeIntersections` in interface `Volume`
Parameters:
`line` - a line
`which` - one of `Intersection.ALL`, `Intersection.CLOSEST`, `Intersection.ANY`, this determines which intersections have to be added to `list`
`list` - the intersections are added to this list
`excludeStart` - intersection at start point which shall be excluded, or `null`
`excludeEnd` - intersection at end point which shall be excluded, or `null`
Returns:
`true` iff the beginning of the line lies within the volume (i.e., if the line starts within the volume or enters the volume at the starting point); however note that the returned value is valid only if `which == Intersection.ALL`

computeNormal

```public void computeNormal(Intersection is,
Vector3d normal)```
Description copied from interface: `Volume`
This method computes the unit normal vector of an intersection `is` which has been computed previously by the invocation of `Volume.computeIntersections(de.grogra.vecmath.geom.Line, int, de.grogra.vecmath.geom.IntersectionList, de.grogra.vecmath.geom.Intersection, de.grogra.vecmath.geom.Intersection)` on this volume.

Specified by:
`computeNormal` in interface `Volume`
Parameters:
`is` - a previously computed intersection
`normal` - resulting unit vector is placed in here

computeTangents

```public void computeTangents(Intersection is,
Vector3d dpdu,
Vector3d dpdv)```
Description copied from interface: `Volume`
This method computes the derivatives of the surface point (as function of the uv-coordinates, see `Volume.computeUV(de.grogra.vecmath.geom.Intersection, javax.vecmath.Vector2d)`) with respect to u and v at the intersection point.

Specified by:
`computeTangents` in interface `Volume`
Parameters:
`is` - a previously computed intersection
`dpdu` - resulting derivative with respect to u
`dpdv` - resulting derivative with respect to v

computeUV

```public void computeUV(Intersection is,
Vector2d uv)```
Description copied from interface: `Volume`
This method computes the uv-coordinates of an intersection point `is` which has been computed previously by the invocation of `Volume.computeIntersections(de.grogra.vecmath.geom.Line, int, de.grogra.vecmath.geom.IntersectionList, de.grogra.vecmath.geom.Intersection, de.grogra.vecmath.geom.Intersection)` on this volume.

Specified by:
`computeUV` in interface `Volume`
Parameters:
`is` - a previously computed intersection
`uv` - resulting uv-coordinates are placed in here

contains

```public boolean contains(Tuple3d point,
boolean open)```
Description copied from interface: `Volume`
Determines if the given `point` lies within this object. If `open` is `true`, the interior of the volume is considered (the largest open set contained in the volume, i.e., excluding the boundary), otherwise the closure of the volume.

Specified by:
`contains` in interface `Volume`
Parameters:
`point` - a point in global world coordinates
`open` - consider open or closed set
Returns:
`true` iff `point` is an element of the set

dup

`public MeshVolume dup()`
Creates a duplicate of this mesh. The complete polygon data is simply referenced from the new duplicate, so no new data arrays are allocated. The duplicate can be shifted to another location using `setTransformation(Matrix4d)`.

Returns:
a duplicate of this volume

getExtent

```public void getExtent(Tuple3d min,
Tuple3d max,
Variables temp)```
Description copied from interface: `Volume`
Computes the extent of this volume, i.e., an axis-aligned bounding box between `min` and `max`.

Specified by:
`getExtent` in interface `Volume`
Parameters:
`min` - minimum coordinates of bounding box are placed in here
`max` - maximum coordinates of bounding box are placed in here
`temp` - has to be provided by the invoker, may be used in implementations

getOctree

`public Octree getOctree()`

getPolygonCount

`public int getPolygonCount()`

setMesh

`public void setMesh(Mesh mesh)`
Sets the mesh of this volume to the specified `mesh`. All data is copied, no persistent reference to `mesh` is made. The method `setTransformation(javax.vecmath.Matrix4d)` has to be invoked afterwards to specify the global coordinate transformation.

Parameters:
`mesh` - a mesh

setTransformation

`public void setTransformation(Matrix4d meshToWorld)`
Sets the transformation from mesh coordinates to global world coordinates.

Parameters:
`meshToWorld` - transformation matrix