Class FlyPathBehavior_WM
- java.lang.Object
-
- gov.nih.mipav.view.renderer.WildMagic.flythroughview.FlyPathBehavior_WM
-
- All Implemented Interfaces:
java.awt.event.KeyListener
,java.util.EventListener
public class FlyPathBehavior_WM extends java.lang.Object implements java.awt.event.KeyListener
Behavior which allows for flying down a specified path and looking around.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
FlyPathBehavior_WM.BranchState
Branch information.static interface
FlyPathBehavior_WM.Callback
Instances which want to be notified of updates to this behavior should implement this interface by providing the viewChanged method implementation.
-
Field Summary
Fields Modifier and Type Field Description (package private) long
currEventTime
current and previous key press time.static int
EVENT_CHANGE_ALL
on a viewChanged event change both the view position and direction vectorstatic int
EVENT_CHANGE_BRANCH
on a viewChanged event change the fly path branchstatic int
EVENT_CHANGE_POSITION
on a viewChanged event change just the view positionstatic int
EVENT_CHANGE_VIEW
on a viewChanged event change just the view directionstatic int
EVENT_RESET_ORIENTATION
on a viewChanged event change just the view orientationprivate FlyPathBehavior_WM.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.private FlyPathBehavior_WM.BranchState[]
m_akBranchState
Identifies the current state of traversing the current branch.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.float
m_fGazeDist
How far ahead down the path should the view be aimed.float
m_fPathStep
What is the increment in distance along the path that each step takes.private int
m_iAnnotateListItemSelected
Current annotation in the list.private int
m_iBranchChoiceIndex
Index of the closest branch at a fork in the path.private FlyPathAnnotateList_WM
m_kAnnotateList
Keep reference to instance which describes the annotation points.private FlyPathBehavior_WM.BranchState
m_kBranchState
Current branch state of traversing the fly path.private FlyPathBehavior_WM.Callback
m_kCallback
Instance which implements the Callback interface whose viewChanged method is to be called whenever anything about this behavior changes.private FlyPathGraphCurve
m_kFlyPathGraph
Keep reference to instance which describes the path.private WildMagic.LibFoundation.Mathematics.Vector3f
m_kViewDirection
Current view direction along the path.private WildMagic.LibFoundation.Mathematics.Vector3f
m_kViewPoint
Current view position along the path.private WildMagic.LibFoundation.Mathematics.Vector3f
m_kViewUp
Current view up vector.private WildMagic.LibFoundation.Mathematics.Vector3f
m_kViewup1
The desired view up vector is a normalized average of these two orthogonal axes vectors.private WildMagic.LibFoundation.Mathematics.Vector3f
m_kViewup2
For calculating the view up vector.private FlyThroughRender
parentScene
Parent frame references.(package private) long
prevEventTime
current and previous key press time.
-
Constructor Summary
Constructors Constructor Description FlyPathBehavior_WM(FlyPathGraphCurve kFlyPathGraph, FlyPathAnnotateList_WM kAnnotateList, FlyThroughRender _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 void
autoRun()
One round trip path walk through.private static void
beep()
Sound a beep.private float
clampNormalizedPathDistance(float fDistance)
Clamp the input normalized path distance to the range [0,1].private void
doPathStep(int iNumSteps)
Take the specified number of steps along the current path using the current path step size.WildMagic.LibFoundation.Curves.Curve3f
getBranchCurve()
Access the curve in the path graph currently positioned along.float
getBranchDistUnvisitedMax()
Access the normalized distance traveled from the end of the current branch path.float
getBranchDistUnvisitedMin()
Access the normalized distance traveled from the beginning of the current branch path.int
getBranchIndex()
Access the index of the curve in the path graph currrently positioned along.FlyPathBehavior_WM.BranchState
getBranchState()
Get the current state of traversing.float
getGazeDistance()
Get the current distance ahead for looking down the path.float
getNormalizedPathDistance()
Get the normalized distance along the current path.float
getPathDist()
Get the current position distance along the path.float
getPathDistance()
Get the current distance along the path.float
getPathLength()
Get the total length of the current path.float
getPathStep()
Get the current distance increment for moving along the path.int
getSelectedBranchIndex()
Access the index of the currently selected branch at a branch point.WildMagic.LibFoundation.Mathematics.Vector3f
getViewDirection()
Returns the view direction vector at the current position on the path.WildMagic.LibFoundation.Mathematics.Vector3f
getViewPoint()
Returns the current position on the path.WildMagic.LibFoundation.Mathematics.Vector3f
getViewUp()
Returns the view up vector at the current position on the path.boolean
isPathMoveForward()
Get indication of whether the movement along the current path is in the forward or reverse direction.void
keyPressed(java.awt.event.KeyEvent event)
Handle the key pressed event from the text field.void
keyReleased(java.awt.event.KeyEvent event)
void
keyTyped(java.awt.event.KeyEvent event)
void
move(java.lang.String command)
Call from the JPanelFlythruMove.void
moveAlongPath(int _step)
Move along the path step width.private void
notifyCallback(int iEvent)
Call the implementation of the callback's notification method, if a callback instance has been defined.private void
setBranch(int iBranch)
Make the specified branch be the current state for following.private void
setBranch(FlyPathBehavior_WM.BranchState kBranchState)
Make the specified branch be the current state for following.void
setBranch(java.lang.Object _kBranchState)
Make the specified branch be the current state for following.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.private void
setCurvePathAnnotateItem(int iItem)
Set the annotation point along the path.private void
setIdentityViewOrientation()
Reset the view orientation transformation to the identity.private void
setPathDist(float fNormalizedDist)
Update the camera position along the path based on the specified distance from the beginning.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.void
setupCallback(FlyPathBehavior_WM.Callback kCallback)
Identify the instance which implements the Callback interface.private void
setView(WildMagic.LibFoundation.Mathematics.Vector3f kViewPoint, WildMagic.LibFoundation.Mathematics.Vector3f kViewdirVector)
Set the camera to the specified be located at the specified view point and looking in the specified direction.
-
-
-
Field Detail
-
EVENT_CHANGE_ALL
public static final int EVENT_CHANGE_ALL
on a viewChanged event change both the view position and direction vector- See Also:
- Constant Field Values
-
EVENT_CHANGE_POSITION
public static final int EVENT_CHANGE_POSITION
on a viewChanged event change just the view position- See Also:
- Constant Field Values
-
EVENT_CHANGE_VIEW
public static final int EVENT_CHANGE_VIEW
on a viewChanged event change just the view direction- See Also:
- Constant Field Values
-
EVENT_RESET_ORIENTATION
public static final int EVENT_RESET_ORIENTATION
on a viewChanged event change just the view orientation- See Also:
- Constant Field Values
-
EVENT_CHANGE_BRANCH
public static final int EVENT_CHANGE_BRANCH
on a viewChanged event change the fly path branch- See Also:
- Constant Field Values
-
currEventTime
long currEventTime
current and previous key press time.
-
prevEventTime
long prevEventTime
current and previous key press time.
-
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.
-
m_akBranchChoice
private FlyPathBehavior_WM.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_WM.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
Current annotation in the list.
-
m_iBranchChoiceIndex
private int m_iBranchChoiceIndex
Index of the closest branch at a fork in the path.
-
m_kAnnotateList
private FlyPathAnnotateList_WM m_kAnnotateList
Keep reference to instance which describes the annotation points.
-
m_kBranchState
private FlyPathBehavior_WM.BranchState m_kBranchState
Current branch state of traversing the fly path.
-
m_kCallback
private FlyPathBehavior_WM.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_kViewup1
private WildMagic.LibFoundation.Mathematics.Vector3f 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 WildMagic.LibFoundation.Mathematics.Vector3f m_kViewup2
For calculating the view up vector.
-
parentScene
private FlyThroughRender parentScene
Parent frame references.
-
m_kViewPoint
private WildMagic.LibFoundation.Mathematics.Vector3f m_kViewPoint
Current view position along the path.
-
m_kViewDirection
private WildMagic.LibFoundation.Mathematics.Vector3f m_kViewDirection
Current view direction along the path.
-
m_kViewUp
private WildMagic.LibFoundation.Mathematics.Vector3f m_kViewUp
Current view up vector.
-
-
Constructor Detail
-
FlyPathBehavior_WM
public FlyPathBehavior_WM(FlyPathGraphCurve kFlyPathGraph, FlyPathAnnotateList_WM kAnnotateList, FlyThroughRender _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
-
beep
private static void beep()
Sound a beep.
-
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_WM.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.
-
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 WildMagic.LibFoundation.Mathematics.Vector3f getViewDirection()
Returns the view direction vector at the current position on the path.- Returns:
- view direction vector at the current position on the path.
-
getViewPoint
public WildMagic.LibFoundation.Mathematics.Vector3f getViewPoint()
Returns the current position on the path.- Returns:
- current position on the path.
-
getViewUp
public WildMagic.LibFoundation.Mathematics.Vector3f getViewUp()
Returns the view up vector at the current position on the path.- Returns:
- view up vector at the current position on the path.
-
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:
keyPressed
in interfacejava.awt.event.KeyListener
- Parameters:
event
- key event to handle
-
keyReleased
public void keyReleased(java.awt.event.KeyEvent event)
- Specified by:
keyReleased
in interfacejava.awt.event.KeyListener
-
keyTyped
public void keyTyped(java.awt.event.KeyEvent event)
- Specified by:
keyTyped
in interfacejava.awt.event.KeyListener
-
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.
-
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_WM.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
-
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(FlyPathBehavior_WM.BranchState kBranchState)
Make the specified branch be the current state for following.- Parameters:
kBranchState
- BranchState Instance which describes the state of the branch.
-
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.
-
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(WildMagic.LibFoundation.Mathematics.Vector3f kViewPoint, WildMagic.LibFoundation.Mathematics.Vector3f 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.
-
-