de.grogra.imp3d.ray2
Class SceneVisitor

java.lang.Object
  extended by de.grogra.imp3d.Visitor3D
      extended by de.grogra.imp3d.DisplayVisitor
          extended by de.grogra.imp3d.ray2.SceneVisitor
All Implemented Interfaces:
Visitor, ProgressMonitor, Scene, Disposable, java.lang.Cloneable

public class SceneVisitor
extends DisplayVisitor
implements Scene, ProgressMonitor, java.lang.Cloneable, Disposable

A SceneVisitor is used to traverse a graph, collect the geometry and lights of this graph and represent them as a Scene.

Author:
Ole Kniemeyer
See Also:
SceneVisitor(de.grogra.pf.ui.Workbench, de.grogra.graph.Graph, float, de.grogra.ray2.Options, de.grogra.imp3d.ViewConfig3D, boolean[], de.grogra.imp3d.ray2.VolumeListener, de.grogra.ray.physics.Spectrum)

Field Summary
static int MIN_OBJ
           
 
Fields inherited from class de.grogra.imp3d.DisplayVisitor
lastEntered, lastEnteredIsNode
 
Fields inherited from class de.grogra.imp3d.Visitor3D
layer, state, transformation
 
Fields inherited from interface de.grogra.ray2.ProgressMonitor
DONE_PROGRESS, INDETERMINATE_PROGRESS
 
Fields inherited from interface de.grogra.graph.Visitor
STOP
 
Constructor Summary
SceneVisitor(Workbench wb, Graph graph, float epsilon, Options opts, ViewConfig3D view, boolean[] visibleLayers, VolumeListener mapping, Spectrum spectrumFactory)
          Constructs a new SceneVisitor which traverses the given graph to obtain the complete geometry and light information and represent it as a Scene.
 
Method Summary
 void appendStatistics(java.lang.StringBuffer stats)
          Appends some statistics information about the scene to stats.
 boolean computeIntersections(Line ray, int which, IntersectionList list, Intersection excludeStart, Intersection excludeEnd)
          Computes intersections between the boundary surface of the objects of the scene and the specified line.
 Spectrum createSpectrum()
          This factory method creates a new spectrum which shall be used for light computations within the context of this scene.
 void dispose()
           
 Scene dup()
          Returns a clone of this Scene.
 BoundingBox getBoundingBox()
          Returns a bounding box which contains all finite geometric objects of the scene.
 java.lang.Object getGraph()
          Returns an object identifying the underlying scene graph.
 Interior getInterior(Volume v)
          Returns the interior which is associated with volume v.
 Matrix4d getInverseLightTransformation(int light)
          Returns the affine light transformation from global world coordinates to local light coordinates for the light having index light in Scene.getLights().
 Matrix4d getInverseSensorTransformation(int sensor)
          Returns the affine sensor transformation from global world coordinates to local sensor coordinates for the sensor having index sensor in Scene.getSensors().
 int getLight(Volume v)
          Returns the index in Scene.getLights() of the light which is associated with volume v, or -1 if no such light exists.
 Light[] getLights()
          Returns an array of all lights in the scene.
 Matrix4d getLightTransformation(int light)
          Returns the affine light transformation from local light coordinates to global world coordinates for the light having index light in Scene.getLights().
 OctreeUnion getOctree()
           
 int getSensor(Volume v)
          Returns the index in Scene.getSensors() of the sensor which is associated with volume v, or -1 if no such sensor exists.
 Sensor[] getSensors()
          Returns an array of all sensors in the scene.
 Matrix4d getSensorTransformation(int sensor)
          Returns the affine sensor transformation from local sensor coordinates to global world coordinates for the sensor having index sensor in Scene.getSensors().
 Shader getShader(Volume v)
          Returns the shader which is associated with volume v.
 int getStamp()
          Returns a modification stamp for the underlying scene graph.
 java.lang.String getUniqueName()
          Returns a unique name for the current scene, so that the test whether two scenes are identical can be performed.
protected  boolean isInVisibleLayer(java.lang.Object o, boolean asNode)
           
protected  Shader resolveShader(Shader shader)
           
 void setProgress(java.lang.String text, float progress)
          This method is invoked by the renderer to monitor its progress.
 void showMessage(java.lang.String message)
          This method is invoked by the renderer to show a message, e.g., the statistics after rendering has completed.
 void transform(Volume v, Tuple3d global, Tuple3d localOut)
          Transforms a point in global world coordinates to local object coordinates of the volume v.
protected  void visitEnterImpl(java.lang.Object object, boolean asNode, Path path)
          This method has to be implemented by subclasses.
protected  void visitImpl(java.lang.Object object, boolean asNode, Shader s, Path path)
           
 java.lang.Object visitInstanceEnter()
          Informs this visitor about the beginning of an instantiation.
 boolean visitInstanceLeave(java.lang.Object o)
          Informs this visitor that an instantiation has been processed completely.
protected  void visitLeaveImpl(java.lang.Object object, boolean asNode, Path path)
          This method has to be implemented by subclasses.
 
Methods inherited from class de.grogra.imp3d.DisplayVisitor
getCurrentShader, init
 
Methods inherited from class de.grogra.imp3d.Visitor3D
getCurrentTransformation, getGraphState, init, visitEnter, visitEnter, visitLeave
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MIN_OBJ

public static int MIN_OBJ
Constructor Detail

SceneVisitor

public SceneVisitor(Workbench wb,
                    Graph graph,
                    float epsilon,
                    Options opts,
                    ViewConfig3D view,
                    boolean[] visibleLayers,
                    VolumeListener mapping,
                    Spectrum spectrumFactory)
Constructs a new SceneVisitor which traverses the given graph to obtain the complete geometry and light information and represent it as a Scene. Note that the traversal is already part of the constructor, so no additional method invocation is required to obtain the geometry.

Parameters:
wb - the workbench to use
graph - x
epsilon - only objects whose magnitude is larger than this value are considered
opts - options for the construction of geometry
view - if the scene is used to render a 3D view, this has to be specified in this parameter. Otherwise view is null, this is interpreted such that a radiation model is to be computed
visibleLayers - layers which are visible for the scene visitor, or null if view shall be used to determine the visibility
mapping - if not null, mappings from graph objects to volumes are reported to this parameter
spectrumFactory - instance of spectrum to be used as factory (i.e., new spectra are allocated using spectrumFactory.newInstance())
Method Detail

appendStatistics

public void appendStatistics(java.lang.StringBuffer stats)
Description copied from interface: Scene
Appends some statistics information about the scene to stats.

Specified by:
appendStatistics in interface Scene
Parameters:
stats - buffer for statistics information

computeIntersections

public boolean computeIntersections(Line ray,
                                    int which,
                                    IntersectionList list,
                                    Intersection excludeStart,
                                    Intersection excludeEnd)
Description copied from interface: Scene
Computes intersections between the boundary surface of the objects of the scene and the specified line. For the precise behaviour and the meaning of the parameters, see Volume.computeIntersections(de.grogra.vecmath.geom.Line, int, de.grogra.vecmath.geom.IntersectionList, de.grogra.vecmath.geom.Intersection, de.grogra.vecmath.geom.Intersection).

Specified by:
computeIntersections in interface Scene
Parameters:
ray - 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
See Also:
Volume.computeIntersections(de.grogra.vecmath.geom.Line, int, de.grogra.vecmath.geom.IntersectionList, de.grogra.vecmath.geom.Intersection, de.grogra.vecmath.geom.Intersection)

createSpectrum

public Spectrum createSpectrum()
Description copied from interface: Scene
This factory method creates a new spectrum which shall be used for light computations within the context of this scene.

Specified by:
createSpectrum in interface Scene
Returns:
new spectrum instance for use in computations

dispose

public void dispose()
Specified by:
dispose in interface Disposable

dup

public Scene dup()
Description copied from interface: Scene
Returns a clone of this Scene. All constant variables which are related to the structure of the scene are copied shallowly, state variables are newly created without copying.

Specified by:
dup in interface Scene
Returns:
clone of this scene

getBoundingBox

public BoundingBox getBoundingBox()
Description copied from interface: Scene
Returns a bounding box which contains all finite geometric objects of the scene. The returned box must not be modified.

Specified by:
getBoundingBox in interface Scene
Returns:
bounding box of finite geometry

getGraph

public java.lang.Object getGraph()
Description copied from interface: Scene
Returns an object identifying the underlying scene graph.

Specified by:
getGraph in interface Scene
Returns:
scene graph

getInterior

public Interior getInterior(Volume v)
Description copied from interface: Scene
Returns the interior which is associated with volume v.

Specified by:
getInterior in interface Scene
Parameters:
v - a volume
Returns:
corresponding interior

getInverseLightTransformation

public Matrix4d getInverseLightTransformation(int light)
Description copied from interface: Scene
Returns the affine light transformation from global world coordinates to local light coordinates for the light having index light in Scene.getLights().

Specified by:
getInverseLightTransformation in interface Scene
Parameters:
light - index of light in Scene.getLights()
Returns:
inverse light transformation for light
See Also:
Scene.getLights()

getInverseSensorTransformation

public Matrix4d getInverseSensorTransformation(int sensor)
Description copied from interface: Scene
Returns the affine sensor transformation from global world coordinates to local sensor coordinates for the sensor having index sensor in Scene.getSensors().

Specified by:
getInverseSensorTransformation in interface Scene
Parameters:
sensor - index of sensor in Scene.getSensors()
Returns:
inverse sensor transformation for sensor
See Also:
Scene.getSensors()

getLight

public int getLight(Volume v)
Description copied from interface: Scene
Returns the index in Scene.getLights() of the light which is associated with volume v, or -1 if no such light exists.

Specified by:
getLight in interface Scene
Parameters:
v - a volume
Returns:
index of corresponding light in Scene.getLights()

getLights

public Light[] getLights()
Description copied from interface: Scene
Returns an array of all lights in the scene. The returned array must not be modified. The corresponding coordinate transformations are obtained by Scene.getLightTransformation(int).

Specified by:
getLights in interface Scene
Returns:
array of all lights

getLightTransformation

public Matrix4d getLightTransformation(int light)
Description copied from interface: Scene
Returns the affine light transformation from local light coordinates to global world coordinates for the light having index light in Scene.getLights().

Specified by:
getLightTransformation in interface Scene
Parameters:
light - index of light in Scene.getLights()
Returns:
light transformation for light
See Also:
Scene.getLights()

getOctree

public OctreeUnion getOctree()
Specified by:
getOctree in interface Scene

getSensor

public int getSensor(Volume v)
Description copied from interface: Scene
Returns the index in Scene.getSensors() of the sensor which is associated with volume v, or -1 if no such sensor exists.

Specified by:
getSensor in interface Scene
Parameters:
v - a volume
Returns:
index of corresponding sensor in Scene.getSensors()

getSensors

public Sensor[] getSensors()
Description copied from interface: Scene
Returns an array of all sensors in the scene. The returned array must not be modified. The corresponding coordinate transformations are obtained by Scene.getSensorTransformation(int).

Specified by:
getSensors in interface Scene
Returns:
array of all sensors

getSensorTransformation

public Matrix4d getSensorTransformation(int sensor)
Description copied from interface: Scene
Returns the affine sensor transformation from local sensor coordinates to global world coordinates for the sensor having index sensor in Scene.getSensors().

Specified by:
getSensorTransformation in interface Scene
Parameters:
sensor - index of sensor in Scene.getSensors()
Returns:
sensor transformation for sensor
See Also:
Scene.getSensors()

getShader

public Shader getShader(Volume v)
Description copied from interface: Scene
Returns the shader which is associated with volume v.

Specified by:
getShader in interface Scene
Parameters:
v - a volume
Returns:
corresponding shader

getStamp

public int getStamp()
Description copied from interface: Scene
Returns a modification stamp for the underlying scene graph. Each modification increments the value, so that the test whether some modification occured can be simply performed on values of the stamp.

Specified by:
getStamp in interface Scene
Returns:
a stamp for the whole graph

getUniqueName

public java.lang.String getUniqueName()
Description copied from interface: Scene
Returns a unique name for the current scene, so that the test whether two scenes are identical can be performed.

Specified by:
getUniqueName in interface Scene

isInVisibleLayer

protected boolean isInVisibleLayer(java.lang.Object o,
                                   boolean asNode)
Overrides:
isInVisibleLayer in class DisplayVisitor

resolveShader

protected Shader resolveShader(Shader shader)
Overrides:
resolveShader in class DisplayVisitor

setProgress

public void setProgress(java.lang.String text,
                        float progress)
Description copied from interface: ProgressMonitor
This method is invoked by the renderer to monitor its progress.

Specified by:
setProgress in interface ProgressMonitor
Parameters:
text - short text to display
progress - state of progress from 0 to 1, or one of the constants ProgressMonitor.INDETERMINATE_PROGRESS, ProgressMonitor.DONE_PROGRESS

showMessage

public void showMessage(java.lang.String message)
Description copied from interface: ProgressMonitor
This method is invoked by the renderer to show a message, e.g., the statistics after rendering has completed.

Specified by:
showMessage in interface ProgressMonitor
Parameters:
message - message to display

transform

public void transform(Volume v,
                      Tuple3d global,
                      Tuple3d localOut)
Description copied from interface: Scene
Transforms a point in global world coordinates to local object coordinates of the volume v.

Specified by:
transform in interface Scene
Parameters:
v - volume which defines the local object coordinates
global - input point in global world coordinates
localOut - output point in local object coordinates

visitEnterImpl

protected void visitEnterImpl(java.lang.Object object,
                              boolean asNode,
                              Path path)
Description copied from class: Visitor3D
This method has to be implemented by subclasses. It is invoked when object is entered.

Overrides:
visitEnterImpl in class DisplayVisitor
Parameters:
object - the object being entered
asNode - is object a node or an edge?
path - the path to object if object is a node, the path to the node where object points to if object is an edge

visitImpl

protected void visitImpl(java.lang.Object object,
                         boolean asNode,
                         Shader s,
                         Path path)
Specified by:
visitImpl in class DisplayVisitor

visitInstanceEnter

public java.lang.Object visitInstanceEnter()
Description copied from interface: Visitor
Informs this visitor about the beginning of an instantiation. This method invokation is nested immediately within visitEnter/visitLeave of a node. Later on, Visitor.visitInstanceLeave(Object) will be invoked with the returned value of this invocation as argument. If this method returns Visitor.STOP, the visitInstanceLeave-method will be invoked immediately after this method, i.e., the visitor does not dive into the instantiation. Otherwise, the instantiation is performed, starting with an edge.

Specified by:
visitInstanceEnter in interface Visitor
Overrides:
visitInstanceEnter in class Visitor3D
Returns:
value to pass to visitInstanceLeave, may be Visitor.STOP

visitInstanceLeave

public boolean visitInstanceLeave(java.lang.Object o)
Description copied from interface: Visitor
Informs this visitor that an instantiation has been processed completely. The value o is the return value of the corresponding invocation of Visitor.visitInstanceEnter(). If this invocation returns false, no further instantiations or edges of the current level of hierarchy will be passed to this visitor, i.e., the visitLeave method for the enclosing node will be invoked immediately.

Specified by:
visitInstanceLeave in interface Visitor
Overrides:
visitInstanceLeave in class Visitor3D
Parameters:
o - returned value of visitInstanceEnter
Returns:
true iff processing of current level shall be continued

visitLeaveImpl

protected void visitLeaveImpl(java.lang.Object object,
                              boolean asNode,
                              Path path)
Description copied from class: Visitor3D
This method has to be implemented by subclasses. It is invoked when object is left.

Overrides:
visitLeaveImpl in class DisplayVisitor
Parameters:
object - the object being left
asNode - is object a node or an edge?
path - the path to object if object is a node, the path to the node where object points to if object is an edge