JPBRT 0.5

org.jpbrt.core
Class Shape

java.lang.Object
  extended by org.jpbrt.core.Shape
Direct Known Subclasses:
Box, Cone, Cylinder, Disk, Hyperboloid, Paraboloid, Sphere, Triangle, TriangleMesh

public abstract class Shape
extends java.lang.Object

Shape represents a geometric primitive.

All shapes are defined in object coordinate space; for example, all spheres are defined in a coordinate system where the center of the sphere is at the origin. In order to place sphere at another position in the scene, a transformation that describes the mapping from object space to world space must be provided.

References:
M. Pharr, G. Humphreys. (2004). Physically Based Rendering. Morgan Kaufmann.
Page 90.

Version:
$Id: Shape.java 19 2010-09-30 07:46:55Z rawcoder $
Author:
Werner Randelshofer

Field Summary
 Transform objectToWorld
          Transformation from object to world space.
 boolean reverseOrientation
          Indicates whether the surface normal directions should be reversed from the default.
 int shapeId
           
 boolean transformSwapsHandedness
          Caches the result of the Transform.swapsHandedness() call.
 Transform worldToObject
          inverse of the transformation from object to world space.
 
Constructor Summary
Shape(Transform o2w, Transform w2o, boolean reverseOrientation)
          Creates a new shape.
 
Method Summary
 boolean canIntersect()
          Returns true if the shape is intersectable.
abstract  float getArea()
          This method may only be called with intersectable shapes.
abstract  BBox getObjectBounds()
          Returns a bounding box in object coordinates.
 DifferentialGeometry getShadingGeometry(Transform obj2world, DifferentialGeometry dg)
          Some shapes (notably triangle meshes) support the idea of having two types of geometry at a point on the surface: the true geometry, which accurately reflects the local properties of the surface, and the shading geometry, which may have normals and tangents that are different than those in the true differential geometry.
 BBox getWorldBounds()
          Returns a bounding box in world coordinates.
abstract  boolean intersect(Ray r, float[] thit, float[] rayEpsilon, DifferentialGeometry dg)
          Returns geometric information about the first ray-shape intersection, if any, in the [mint,maxt] parametric range along the ray.
abstract  boolean intersectP(Ray ray)
          Determines whether the ray intersects with the shape without returning any details about the intersection itself.
 float pdf(Point Pshape)
          Takes a point on the surface of the shape and returns the value of the corresponding Probability Distribution Function.
 float pdf(Point p, Vector wi)
          Given a point on the surface p and direction wi, the method determines the probability that the shape would have chosen the direction wi.
 void refine(java.util.List<Shape> r)
          If a shape can not be intersected directly, it must provide a refine method which splits the shape into a group of new shapes, some of which may be intersectable and some of which may need further refinement.
 Point sample(float u1, float u2, Normal Ns)
          Chooses a point on the surface using some sampling distribution with respect to surface area on the shape and returns its position and writes its normal in the output variable Ns.
 Point sample(Point P, float u1, float u2, Normal Ns)
          Chooses a point on the surface visible from the given surface point P using some sampling distribution function, returns its position and writes its normal in the output variable Ns.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

objectToWorld

public Transform objectToWorld
Transformation from object to world space.


worldToObject

public Transform worldToObject
inverse of the transformation from object to world space.


reverseOrientation

public boolean reverseOrientation
Indicates whether the surface normal directions should be reversed from the default. Surface normals are used for determining which side of a shape is the "outside". This is used for two-sided material properties.


transformSwapsHandedness

public boolean transformSwapsHandedness
Caches the result of the Transform.swapsHandedness() call. This value is needed by the DifferentialGeometry constructor that will be called each time a ray intersection is found.


shapeId

public int shapeId
Constructor Detail

Shape

public Shape(Transform o2w,
             Transform w2o,
             boolean reverseOrientation)
Creates a new shape.

Parameters:
o2w - Object-to-world transformation.
reverseOrientation - Whether surface normals should be reversed.
Method Detail

getWorldBounds

public BBox getWorldBounds()
Returns a bounding box in world coordinates.


getObjectBounds

public abstract BBox getObjectBounds()
Returns a bounding box in object coordinates.


canIntersect

public boolean canIntersect()
Returns true if the shape is intersectable.

Not every shape needs to capable of determining whether a ray intersects it. For example, a complex surfce might first be tesselated into triangles, which can then be intersected directly. Another possibility is a shape that is a placeholder for a larger amount of geometry that is stored on disk.

The default implementation returns true, so that only shapes which are non-intersectable need to override this method.


intersectP

public abstract boolean intersectP(Ray ray)
Determines whether the ray intersects with the shape without returning any details about the intersection itself.


intersect

public abstract boolean intersect(Ray r,
                                  float[] thit,
                                  float[] rayEpsilon,
                                  DifferentialGeometry dg)
Returns geometric information about the first ray-shape intersection, if any, in the [mint,maxt] parametric range along the ray. The intersection routine must ignore any intersection that do not occur inside this range on the ray.

Parameters:
r - The ray used for intersection testing.
thit - Output parameter (array of length one) which stores the distance from the origin of the ray to the intersection.
dg - Information about the local geometry is stored here if an intersection was found.
Returns:
Returns true if an intersection was found.

refine

public void refine(java.util.List<Shape> r)
If a shape can not be intersected directly, it must provide a refine method which splits the shape into a group of new shapes, some of which may be intersectable and some of which may need further refinement.

The default implementation throws an InternalError; thus shapes that are intersectable (which is the common case) do not have to provide an empty instance of this method.

Parameters:
r -

getShadingGeometry

public DifferentialGeometry getShadingGeometry(Transform obj2world,
                                               DifferentialGeometry dg)
Some shapes (notably triangle meshes) support the idea of having two types of geometry at a point on the surface: the true geometry, which accurately reflects the local properties of the surface, and the shading geometry, which may have normals and tangents that are different than those in the true differential geometry.

Implementations which return a new differential geometry object must use the provided object-to-world transformation rather than their own in order to support multiple object instancing in a scene.

The default implementation of this method returns the passed in differential geometry object.


getArea

public abstract float getArea()
This method may only be called with intersectable shapes.

Returns:
Returns the surface area of the shape in object space.

sample

public Point sample(float u1,
                    float u2,
                    Normal Ns)
Chooses a point on the surface using some sampling distribution with respect to surface area on the shape and returns its position and writes its normal in the output variable Ns.

This method takes two uniform random numbers in the range (0,1) which are used to select the point on the surface area. In almost all cases the shape will sample uniformly by area on its surface.

Note: The implementation in this class throws UnsupportedOperationException.

References: pbrt-v2, page 716.

Parameters:
u1 - Uniform random number 1.
u2 - Uniform random number 2.
Ns - The normal of the selected point.
Returns:
Returns the position of the selected point.

pdf

public float pdf(Point Pshape)
Takes a point on the surface of the shape and returns the value of the corresponding Probability Distribution Function.

Note: The implementation in this class returns the reciprocal of the surface area.

Parameters:
Pshape - A point on the surface of the shape.
Returns:
The PDF value for this point.

sample

public Point sample(Point P,
                    float u1,
                    float u2,
                    Normal Ns)
Chooses a point on the surface visible from the given surface point P using some sampling distribution function, returns its position and writes its normal in the output variable Ns.

Only the portion of the shape is sampled that is potentially visible from the given point P. This is particularly useful for lighting, since the caller can pass in the point to be lit.

This method takes two uniform random numbers in the range (0,1) which are used to select the point on the surface area.

Note: The implementation in this class ignores the given point P and just calls method sample(float,float,Normal).

References: pbrt-v2, page 716.

Parameters:
P - The point from which the surface of the shape is being integrated over.
u1 - Uniform random number 1.
u2 - Uniform random number 2.
Ns - The normal of the selected point.
Returns:
Returns the position of the selected point.

pdf

public float pdf(Point p,
                 Vector wi)
Given a point on the surface p and direction wi, the method determines the probability that the shape would have chosen the direction wi.

The method determines if the ray (p, wi) intersects the shape. If the ray doesn't intersect the shape at all, the probability that the shape would have chosen the direction wi can be assumed to be zero. References: pbrt-v2, page 717.

Parameters:
p -
wi -
Returns:

Copyright 2010 © by the authors and contributors of the JPBRT project.
Some rights reserved.