Class FlyPathBehavior
- java.lang.Object
-
- javax.media.j3d.SceneGraphObject
-
- javax.media.j3d.Node
-
- javax.media.j3d.Leaf
-
- javax.media.j3d.Behavior
-
- gov.nih.mipav.view.renderer.J3D.surfaceview.flythruview.FlyPathBehavior
-
- All Implemented Interfaces:
java.awt.event.KeyListener,java.util.EventListener
public class FlyPathBehavior extends javax.media.j3d.Behavior implements java.awt.event.KeyListenerBehavior which allows for flying down a specified path and looking around.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classFlyPathBehavior.BranchStateDOCUMENT ME!static interfaceFlyPathBehavior.CallbackInstances which want to be notified of updates to this behavior should implement this interface by providing the viewChanged method implementation.(package private) classFlyPathBehavior.StandardKeyClass used to send Standard key events to the canvas.
-
Field Summary
Fields Modifier and Type Field Description (package private) longcurrEventTimecurrent and previous key press time.static intEVENT_CHANGE_ALLDOCUMENT ME!static intEVENT_CHANGE_BRANCHDOCUMENT ME!static intEVENT_CHANGE_ORIENTATIONDOCUMENT ME!static intEVENT_CHANGE_POSITIONDOCUMENT ME!private FlyPathBehavior.BranchState[]m_akBranchChoiceWhen a branch point along the current branch is reached, this array is filled with the possible BranchState instances that the user can select from for following.private FlyPathBehavior.BranchState[]m_akBranchStateIdentifies the current state of traversing the current branch.private booleanm_bChooseBranchWhen a branch point along the current branch is reached, this flag is set until the user selects a branch to follow.floatm_fGazeDistHow far ahead down the path should the view be aimed.floatm_fPathStepWhat is the increment in distance along the path that each step takes.private intm_iAnnotateListItemSelectedDOCUMENT ME!private intm_iBranchChoiceIndexDOCUMENT ME!private FlyPathAnnotateListm_kAnnotateListKeep reference to instance which describes the annotation points.private FlyPathBehavior.BranchStatem_kBranchStateDOCUMENT ME!private FlyPathBehavior.Callbackm_kCallbackInstance which implements the Callback interface whose viewChanged method is to be called whenever anything about this behavior changes.private FlyPathGraphCurvem_kFlyPathGraphKeep reference to instance which describes the path.private javax.media.j3d.Transform3Dm_kTransformTransform created for multiple use to avoid new'ing it each time.private javax.media.j3d.TransformGroupm_kTransformDirectionView direction component for this view transform.private javax.media.j3d.TransformGroupm_kTransformOrientationOrientation (yaw/pitch) component for this view transform.private javax.media.j3d.TransformGroupm_kTransformPositionPosition-only component for this view transform.private javax.media.j3d.Transform3Dm_kTransformRotDOCUMENT ME!private javax.vecmath.Vector3dm_kViewup1The desired view up vector is a normalized average of these two orthogonal axes vectors.private javax.vecmath.Vector3dm_kViewup2DOCUMENT ME!private javax.media.j3d.WakeupConditionm_kWakeupConditionConditions which contain the events we want to "wakeup" on.private FlythruRenderparentSceneParent frame references.private booleanpressedIf any of the mouse move button pressed.(package private) longprevEventTimecurrent and previous key press time.-
Fields inherited from class javax.media.j3d.Node
ALLOW_AUTO_COMPUTE_BOUNDS_READ, ALLOW_AUTO_COMPUTE_BOUNDS_WRITE, ALLOW_BOUNDS_READ, ALLOW_BOUNDS_WRITE, ALLOW_COLLIDABLE_READ, ALLOW_COLLIDABLE_WRITE, ALLOW_LOCAL_TO_VWORLD_READ, ALLOW_LOCALE_READ, ALLOW_PARENT_READ, ALLOW_PICKABLE_READ, ALLOW_PICKABLE_WRITE, ENABLE_COLLISION_REPORTING, ENABLE_PICK_REPORTING
-
-
Constructor Summary
Constructors Constructor Description FlyPathBehavior(FlyPathGraphCurve kFlyPathGraph, FlyPathAnnotateList kAnnotateList, javax.media.j3d.TransformGroup kTransformPosition, javax.media.j3d.TransformGroup kTransformDirection, javax.media.j3d.TransformGroup kTransformOrientation, FlythruRender _parentScene)Setup to fly along the specified path and look around.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidautoRun()One round trip path walk through.private static voidbeep()Sound a beep.private floatclampNormalizedPathDistance(float fDistance)Clamp the input normalized path distance to the range [0,1].private voiddoPathStep(int iNumSteps)Take the specified number of steps along the current path using the current path step size.WildMagic.LibFoundation.Curves.Curve3fgetBranchCurve()Access the curve in the path graph currently positioned along.floatgetBranchDistUnvisitedMax()Access the normalized distance traveled from the end of the current branch path.floatgetBranchDistUnvisitedMin()Access the normalized distance traveled from the beginning of the current branch path.intgetBranchIndex()Access the index of the curve in the path graph currrently positioned along.FlyPathBehavior.BranchStategetBranchState()Get the current state of traversing.floatgetGazeDistance()Get the current distance ahead for looking down the path.floatgetNormalizedPathDistance()Get the normalized distance along the current path.floatgetPathDist()Get the current position distance along the path.floatgetPathDistance()Get the current distance along the path.floatgetPathLength()Get the total length of the current path.javax.vecmath.Point3fgetPathPosition()Get the location of the current position along the path.floatgetPathStep()Get the current distance increment for moving along the path.intgetSelectedBranchIndex()Access the index of the currently selected branch at a branch point.javax.vecmath.Vector3fgetViewDirection()Retrieve the current base direction vector for viewing.javax.vecmath.Matrix3fgetViewOrientation()Retrieve the current relative orientation transform matrix for viewing which is relative to the current base direction transform for viewing.voidinitialize()Implementation of the Behavior abstract method.booleanisPathMoveForward()Get indication of whether the movement along the current path is in the forward or reverse direction.voidkeyPressed(java.awt.event.KeyEvent event)Handle the key pressed event from the text field.voidkeyReleased(java.awt.event.KeyEvent event)Handle the key released event from the text field.voidkeyTyped(java.awt.event.KeyEvent event)Does nothing.voidmove(java.lang.String command)Call from the JPanelFlythruMove.voidmoveAlongPath(int _step)Move along the path step width.private voidnotifyCallback(int iEvent)Call the implementation of the callback's notification method, if a callback instance has been defined.voidprocessStimulus(java.util.Enumeration kCriteria)Implementation of the Behavior abstract method.private voidsetBranch(int iBranch)Make the specified branch be the current state for following.private voidsetBranch(FlyPathBehavior.BranchState kBranchState)Make the specified branch be the current state for following.voidsetBranch(java.lang.Object _kBranchState)Make the specified branch be the current state for following.private voidsetClosestChoiceBranch()Loop through all of the possible branch choices and select the one that is the closest to the current view direction vector.private voidsetCurvePathAnnotateItem(int iItem)Set the annotation point along the path.private voidsetIdentityViewOrientation()Reset the view orientation transformation to the identity.private voidsetPathDist(float fNormalizedDist)Update the camera position along the path based on the specified distance from the beginning.private voidsetupBranchChoices(int iBranchParent, int iBranchPoint)Create the array of branch choices and set the mode which forces the user to select from among the branch choices.voidsetupCallback(FlyPathBehavior.Callback kCallback)Identify the instance which implements the Callback interface.private voidsetView(javax.vecmath.Point3d kViewPoint, javax.vecmath.Vector3d kViewdirVector)Set the camera to the specified be located at the specified view point and looking in the specified direction.-
Methods inherited from class javax.media.j3d.Behavior
getEnable, getNumSchedulingIntervals, getSchedulingBoundingLeaf, getSchedulingBounds, getSchedulingInterval, getView, getWakeupCondition, postId, setEnable, setSchedulingBoundingLeaf, setSchedulingBounds, setSchedulingInterval, updateNodeReferences, wakeupOn
-
Methods inherited from class javax.media.j3d.Node
cloneNode, cloneTree, cloneTree, cloneTree, cloneTree, cloneTree, cloneTree, duplicateNode, getBounds, getBoundsAutoCompute, getCollidable, getLocale, getLocalToVworld, getLocalToVworld, getParent, getPickable, setBounds, setBoundsAutoCompute, setCollidable, setPickable
-
-
-
-
Field Detail
-
EVENT_CHANGE_ALL
public static final int EVENT_CHANGE_ALL
DOCUMENT ME!- See Also:
- Constant Field Values
-
EVENT_CHANGE_POSITION
public static final int EVENT_CHANGE_POSITION
DOCUMENT ME!- See Also:
- Constant Field Values
-
EVENT_CHANGE_ORIENTATION
public static final int EVENT_CHANGE_ORIENTATION
DOCUMENT ME!- See Also:
- Constant Field Values
-
EVENT_CHANGE_BRANCH
public static final int EVENT_CHANGE_BRANCH
DOCUMENT ME!- See Also:
- Constant Field Values
-
m_fGazeDist
public float m_fGazeDist
How far ahead down the path should the view be aimed. If zero, then the view direction is the tangent to the curve. If positive, the the view direction is to look at that point along the path.
-
m_fPathStep
public float m_fPathStep
What is the increment in distance along the path that each step takes. Increment may be negative indicating that the path is being followed in the opposite direction.
-
currEventTime
long currEventTime
current and previous key press time.
-
prevEventTime
long prevEventTime
current and previous key press time.
-
m_akBranchChoice
private FlyPathBehavior.BranchState[] m_akBranchChoice
When a branch point along the current branch is reached, this array is filled with the possible BranchState instances that the user can select from for following. Once movement is made along one of those selected from the list, then this list is cleared. An index is maintained to indicate which branch in the list is currently selected.
-
m_akBranchState
private FlyPathBehavior.BranchState[] m_akBranchState
Identifies the current state of traversing the current branch.
-
m_bChooseBranch
private boolean m_bChooseBranch
When a branch point along the current branch is reached, this flag is set until the user selects a branch to follow.
-
m_iAnnotateListItemSelected
private int m_iAnnotateListItemSelected
DOCUMENT ME!
-
m_iBranchChoiceIndex
private int m_iBranchChoiceIndex
DOCUMENT ME!
-
m_kAnnotateList
private FlyPathAnnotateList m_kAnnotateList
Keep reference to instance which describes the annotation points.
-
m_kBranchState
private FlyPathBehavior.BranchState m_kBranchState
DOCUMENT ME!
-
m_kCallback
private FlyPathBehavior.Callback m_kCallback
Instance which implements the Callback interface whose viewChanged method is to be called whenever anything about this behavior changes.
-
m_kFlyPathGraph
private FlyPathGraphCurve m_kFlyPathGraph
Keep reference to instance which describes the path.
-
m_kTransform
private javax.media.j3d.Transform3D m_kTransform
Transform created for multiple use to avoid new'ing it each time.
-
m_kTransformDirection
private javax.media.j3d.TransformGroup m_kTransformDirection
View direction component for this view transform. This assumes a viewup vector (see m_kVectorViewup member). This transform causes the view to look down the path when the yaw=pitch=roll=0.
-
m_kTransformOrientation
private javax.media.j3d.TransformGroup m_kTransformOrientation
Orientation (yaw/pitch) component for this view transform.
-
m_kTransformPosition
private javax.media.j3d.TransformGroup m_kTransformPosition
Position-only component for this view transform.
-
m_kTransformRot
private javax.media.j3d.Transform3D m_kTransformRot
DOCUMENT ME!
-
m_kViewup1
private javax.vecmath.Vector3d m_kViewup1
The desired view up vector is a normalized average of these two orthogonal axes vectors. The problem is that if just one desired view up vector is chosen, then when the view direction vector is "aligned" with that vector, some other view up vector would have to be chosen and some rule would have to be defined for that.
-
m_kViewup2
private javax.vecmath.Vector3d m_kViewup2
DOCUMENT ME!
-
m_kWakeupCondition
private final javax.media.j3d.WakeupCondition m_kWakeupCondition
Conditions which contain the events we want to "wakeup" on.
-
parentScene
private FlythruRender parentScene
Parent frame references.
-
pressed
private boolean pressed
If any of the mouse move button pressed.
-
-
Constructor Detail
-
FlyPathBehavior
public FlyPathBehavior(FlyPathGraphCurve kFlyPathGraph, FlyPathAnnotateList kAnnotateList, javax.media.j3d.TransformGroup kTransformPosition, javax.media.j3d.TransformGroup kTransformDirection, javax.media.j3d.TransformGroup kTransformOrientation, FlythruRender _parentScene)
Setup to fly along the specified path and look around.- Parameters:
kFlyPathGraph- FlyPathGraphCurve contains the information regarding the graph representation of 3D path segments represented by Curve3 instanceskAnnotateList- FlyPathAnnotateList contains the list of annotation points.kTransformPosition- TransformGroup contains the Transform3D for the current viewing position.kTransformDirection- TransformGroup contains the Transform3D for the current viewing direction.kTransformOrientation- TransformGroup contains the Transform3D for the current viewing orientation._parentScene- the parent frame which hold Canvas3D.
-
-
Method Detail
-
autoRun
public void autoRun()
One round trip path walk through.
-
getBranchCurve
public WildMagic.LibFoundation.Curves.Curve3f getBranchCurve()
Access the curve in the path graph currently positioned along.- Returns:
- Curve3 Reference to Curve3 instance in path graph.
-
getBranchDistUnvisitedMax
public float getBranchDistUnvisitedMax()
Access the normalized distance traveled from the end of the current branch path. Also represents the maximum of the range that has been unvisited.- Returns:
- float Normalized distance along the current branch path that is maximum of the unvisited range.
-
getBranchDistUnvisitedMin
public float getBranchDistUnvisitedMin()
Access the normalized distance traveled from the beginning of the current branch path. Also represents the minimum of the range that has been unvisited.- Returns:
- float Normalized distance along the current branch path that is minimum of the unvisited range.
-
getBranchIndex
public int getBranchIndex()
Access the index of the curve in the path graph currrently positioned along.- Returns:
- int Index of Curve3 instance in path graph.
-
getBranchState
public FlyPathBehavior.BranchState getBranchState()
Get the current state of traversing.- Returns:
- BranchState
-
getGazeDistance
public float getGazeDistance()
Get the current distance ahead for looking down the path. If this distance is zero, then the view direction is the tangent to the path curve at the current position.- Returns:
- float Distance ahead for looking down the path.
-
getNormalizedPathDistance
public float getNormalizedPathDistance()
Get the normalized distance along the current path.- Returns:
- float Value in the range [0,1].
-
getPathDist
public float getPathDist()
Get the current position distance along the path.- Returns:
- float path distance.
-
getPathDistance
public float getPathDistance()
Get the current distance along the path.- Returns:
- distance along the path.
-
getPathLength
public float getPathLength()
Get the total length of the current path.- Returns:
- float Length of the path.
-
getPathPosition
public javax.vecmath.Point3f getPathPosition()
Get the location of the current position along the path.- Returns:
- location of current position
-
getPathStep
public float getPathStep()
Get the current distance increment for moving along the path.- Returns:
- distance increment for moving along path. Always positive regardless of which direction moving along the path.
-
getSelectedBranchIndex
public int getSelectedBranchIndex()
Access the index of the currently selected branch at a branch point.- Returns:
- int Index of currently selected branch; -1 if not currently at a branch point.
-
getViewDirection
public javax.vecmath.Vector3f getViewDirection()
Retrieve the current base direction vector for viewing.- Returns:
- normalized direction vector
-
getViewOrientation
public javax.vecmath.Matrix3f getViewOrientation()
Retrieve the current relative orientation transform matrix for viewing which is relative to the current base direction transform for viewing.- Returns:
- 3x3 matrix containing orientation transform
-
initialize
public void initialize()
Implementation of the Behavior abstract method.- Specified by:
initializein classjavax.media.j3d.Behavior
-
isPathMoveForward
public boolean isPathMoveForward()
Get indication of whether the movement along the current path is in the forward or reverse direction.- Returns:
- boolean True if the movement is along the forward direction along the path.
-
keyPressed
public void keyPressed(java.awt.event.KeyEvent event)
Handle the key pressed event from the text field.- Specified by:
keyPressedin interfacejava.awt.event.KeyListener- Parameters:
event- key event to handle
-
keyReleased
public void keyReleased(java.awt.event.KeyEvent event)
Handle the key released event from the text field.- Specified by:
keyReleasedin interfacejava.awt.event.KeyListener- Parameters:
event- key event to handle
-
keyTyped
public void keyTyped(java.awt.event.KeyEvent event)
Does nothing.- Specified by:
keyTypedin interfacejava.awt.event.KeyListener- Parameters:
event- key event to handle
-
move
public void move(java.lang.String command)
Call from the JPanelFlythruMove.- Parameters:
command- move command.
-
moveAlongPath
public void moveAlongPath(int _step)
Move along the path step width.- Parameters:
_step- step size.
-
processStimulus
public void processStimulus(java.util.Enumeration kCriteria)
Implementation of the Behavior abstract method. Process events in the criteria which are the ones we setup for.- Specified by:
processStimulusin classjavax.media.j3d.Behavior- Parameters:
kCriteria- collection of WakeupCriterion to which this Behavior is responding to events.
-
setBranch
public void setBranch(java.lang.Object _kBranchState)
Make the specified branch be the current state for following.- Parameters:
_kBranchState- BranchState Instance which describes the state of the branch.
-
setupCallback
public void setupCallback(FlyPathBehavior.Callback kCallback)
Identify the instance which implements the Callback interface. The viewChanged method of the Callback interface will be called whenever anything about this behavior changes.- Parameters:
kCallback- reference to instance implementing the Callback interface; may pass null reference to disable the callback
-
beep
private static void beep()
Sound a beep.
-
clampNormalizedPathDistance
private float clampNormalizedPathDistance(float fDistance)
Clamp the input normalized path distance to the range [0,1]. If the value is outside that range, then sound a beep.- Parameters:
fDistance- float Input normalized path distance.- Returns:
- float Input distance clamped to the range [0,1].
-
doPathStep
private void doPathStep(int iNumSteps)
Take the specified number of steps along the current path using the current path step size. If the number of steps is negative, then the steps are taken in reverse.- Parameters:
iNumSteps- int Number of steps to take along the current path.
-
notifyCallback
private void notifyCallback(int iEvent)
Call the implementation of the callback's notification method, if a callback instance has been defined.- Parameters:
iEvent- Bitmask identifies the event(s) which caused the view to change. Bitmask created from OR of EVENT_* defintions.
-
setBranch
private void setBranch(int iBranch)
Make the specified branch be the current state for following.- Parameters:
iBranch- int Index of the branch path to follow.
-
setBranch
private void setBranch(FlyPathBehavior.BranchState kBranchState)
Make the specified branch be the current state for following.- Parameters:
kBranchState- BranchState Instance which describes the state of the branch.
-
setClosestChoiceBranch
private void setClosestChoiceBranch()
Loop through all of the possible branch choices and select the one that is the closest to the current view direction vector. Take a vector from the current view point to a point along each choice branch. Compute the dot-product between the current view direction vector and each of these branch direction vectors and take the one with the largest positive value, i.e., most in alignment.
-
setCurvePathAnnotateItem
private void setCurvePathAnnotateItem(int iItem)
Set the annotation point along the path.- Parameters:
iItem- int
-
setIdentityViewOrientation
private void setIdentityViewOrientation()
Reset the view orientation transformation to the identity. That is, remove all yaw/pitch/roll.
-
setPathDist
private void setPathDist(float fNormalizedDist)
Update the camera position along the path based on the specified distance from the beginning.- Parameters:
fNormalizedDist- normalized distance from the beginning of the path for the location of the camera for viewing
-
setupBranchChoices
private void setupBranchChoices(int iBranchParent, int iBranchPoint)Create the array of branch choices and set the mode which forces the user to select from among the branch choices.- Parameters:
iBranchParent- int Index which identifies the parent branch.iBranchPoint- int Index which identifies the point along the branch path where the branching occurs for the choices.
-
setView
private void setView(javax.vecmath.Point3d kViewPoint, javax.vecmath.Vector3d kViewdirVector)Set the camera to the specified be located at the specified view point and looking in the specified direction.- Parameters:
kViewPoint- coordinates of the camera view pointkViewdirVector- coordinates of the camera view direction vector. This vector must be normalized.
-
-