Class JStereoWindow
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- java.awt.Window
-
- java.awt.Frame
-
- javax.swing.JFrame
-
- gov.nih.mipav.view.renderer.J3D.surfaceview.JStereoWindow
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.awt.event.ComponentListener
,java.awt.event.MouseMotionListener
,java.awt.event.WindowListener
,java.awt.image.ImageObserver
,java.awt.MenuContainer
,java.io.Serializable
,java.util.EventListener
,javax.accessibility.Accessible
,javax.swing.event.ChangeListener
,javax.swing.RootPaneContainer
,javax.swing.WindowConstants
public class JStereoWindow extends javax.swing.JFrame implements java.awt.event.WindowListener, java.awt.event.ActionListener, javax.swing.event.ChangeListener, java.awt.event.ComponentListener, java.awt.event.MouseMotionListener
Class JStereoWindow:Creates a stereo viewing window for both ModelTriangleMesh surfaces and arbitrary Group Nodes, including the NodeVolumeTextureRender. Objects are presented on three canvases: left-eye view, right-eye view, and a anaglyph color view. The user can change the eye separation with a slider that adjusts the focal length.
The stereo rendering algorithm for creating the left and right-eye viewing transformations and anaglyph display is based on Paul Bourke's web information at http://astronomy.swin.edu.au/~pbourke/stereographics/
- Author:
- Alexandra Bokinsky
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class javax.swing.JFrame
javax.swing.JFrame.AccessibleJFrame
-
Nested classes/interfaces inherited from class java.awt.Window
java.awt.Window.AccessibleAWTWindow, java.awt.Window.Type
-
-
Field Summary
Fields Modifier and Type Field Description private com.sun.j3d.utils.universe.SimpleUniverse[]
m_akUniverse
Three SimpleUniverses, one for each canavas:.private double
m_dEyeSeparation
Original eye separation, read from the canvas.view.physicalbody.private int
m_iCurrentUniverse
The current universe to be initialized:.private int
m_iStereoUpdateCount
First time the stereo canvas is rendered, set to true:.private java.awt.Dimension
m_kD
BufferedImage Dimensions (power of two).private javax.swing.JSplitPane
m_kDisplayPane
The JSplitPane displaying the left and right eye views:.private javax.swing.JSlider
m_kEyeSep_Slider
Focal-length, (eye separation) slider.private VolumeCanvas3D
m_kLeftCanvas
Left-eye view canvas:.private javax.swing.JPanel
m_kLeftImagePanel
Left Image Panel, holds the canvas for the left-eye view:.private javax.swing.JSplitPane
m_kMainPane
The JSplitPane displaying different views and the user-interface:.private java.awt.image.BufferedImage
m_kRGStereo
BufferedImage containing the Anagyphy stereo image:.private VolumeCanvas3D
m_kRightCanvas
Right-eye view canvas:.private javax.swing.JPanel
m_kRightImagePanel
Right Image Panel, holds the canvas for the right-eye view:.private VolumeCanvas3D
m_kStereoCanvas
Stereo canvas:.private javax.swing.JSplitPane
m_kStereoPane
The JSplitPane displaying the left and right eye views and the stereo view:.private javax.swing.JPanel
m_kStereoPanel
Stereo Image Panel, holds the canvas for the Anaglyph stereo view:.private javax.media.j3d.Shape3D
m_kStereoShape
Texture-mapped polygon for displaying the Anaglyph stereo image as a texture:.private static long
serialVersionUID
Use serialVersionUID for interoperability.-
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
-
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
-
Constructor Summary
Constructors Constructor Description JStereoWindow(SurfaceAttributes kSurface, javax.media.j3d.Transform3D kTransform)
Constructs a JStereoWindow with a ModelTriangleMesh and Transform3D representing the model transformation for the surface.JStereoWindow(javax.media.j3d.Group kNode1, javax.media.j3d.Group kNode2, javax.media.j3d.Transform3D kTransform, SurfaceRender kSurface)
Constructs a JStereoWindow with two nodes, one copy for each of the left and right eye views.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
actionPerformed(java.awt.event.ActionEvent kEvent)
Called when a button is pressed:private javax.media.j3d.BranchGroup
addBranchGroup(javax.media.j3d.Node kNode, javax.media.j3d.Transform3D kTransform)
Creates a BranchGroup containing the input Node and Transform3D, and returns the BranchGroup.private void
blendBuffers(java.awt.image.BufferedImage kLeft, java.awt.image.BufferedImage kRight)
Blend two BufferedImages, representing the left and right-eye views into a Red-Cyan stereo anaglyph.private int
blendColor(int iLeftC, int iRightC)
Blends two packed-integer colors (RGB) to create a Red-Cyan anaglyph.void
componentHidden(java.awt.event.ComponentEvent e)
componentHidden.void
componentMoved(java.awt.event.ComponentEvent e)
componentMoved.void
componentResized(java.awt.event.ComponentEvent e)
componentResized.void
componentShown(java.awt.event.ComponentEvent e)
componentShown.private VolumeCanvas3D
createCanvas(javax.media.j3d.Node kNode, javax.swing.JPanel kPanel)
Creates a canvas containing the input Node object, with the input viewing transformation.private void
createTexturedPolygon()
Creates the texture-mapped polygon displayed in the stereo canvas.void
dispose()
Deletes all local data members.private void
getFrameBuffer(java.awt.image.BufferedImage kImage, VolumeCanvas3D kCanvas)
Read the frame buffer from the input VolumeCanvas3D and store the result in the input BufferedImage:private void
init(javax.media.j3d.BranchGroup kNode1, javax.media.j3d.BranchGroup kNode2)
Initialize the scene graphs and left, right, and stereo canvases for this JStereoWindow.void
mouseDragged(java.awt.event.MouseEvent e)
mouseDragged.void
mouseMoved(java.awt.event.MouseEvent e)
mouseMoved.private void
setupInterface()
Sets up the user interface.void
stateChanged(javax.swing.event.ChangeEvent event)
Called when the slider values have changed.private void
updateStereo()
Reads the left and right-eye buffers from the left and right-eye canvases and blends them into the Red-Cyan Anaglyph stereo buffer, which is then texture-mapped on the a polygon and rendered in the stereo canvas.void
windowActivated(java.awt.event.WindowEvent e)
windowActivated.void
windowClosed(java.awt.event.WindowEvent e)
windowClosed.void
windowClosing(java.awt.event.WindowEvent e)
windowClosing Catch the windowClosing event so that the local data memebrs can be destroyed.void
windowDeactivated(java.awt.event.WindowEvent e)
windowDeactivated.void
windowDeiconified(java.awt.event.WindowEvent e)
windowDeiconified.void
windowIconified(java.awt.event.WindowEvent e)
windowIconified.void
windowOpened(java.awt.event.WindowEvent e)
windowOpened.-
Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
-
Methods inherited from class java.awt.Frame
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setBackground, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setOpacity, setResizable, setShape, setState, setTitle, setUndecorated
-
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, getBackground, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, pack, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setAutoRequestFocus, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setType, setVisible, show, toBack, toFront
-
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusDownCycle, validate, validateTree
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, resize, resize, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setMixingCutoutShape, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Use serialVersionUID for interoperability.- See Also:
- Constant Field Values
-
m_akUniverse
private com.sun.j3d.utils.universe.SimpleUniverse[] m_akUniverse
Three SimpleUniverses, one for each canavas:.
-
m_dEyeSeparation
private double m_dEyeSeparation
Original eye separation, read from the canvas.view.physicalbody.
-
m_iCurrentUniverse
private int m_iCurrentUniverse
The current universe to be initialized:.
-
m_iStereoUpdateCount
private int m_iStereoUpdateCount
First time the stereo canvas is rendered, set to true:.
-
m_kD
private java.awt.Dimension m_kD
BufferedImage Dimensions (power of two).
-
m_kDisplayPane
private javax.swing.JSplitPane m_kDisplayPane
The JSplitPane displaying the left and right eye views:.
-
m_kEyeSep_Slider
private javax.swing.JSlider m_kEyeSep_Slider
Focal-length, (eye separation) slider.
-
m_kLeftCanvas
private VolumeCanvas3D m_kLeftCanvas
Left-eye view canvas:.
-
m_kLeftImagePanel
private javax.swing.JPanel m_kLeftImagePanel
Left Image Panel, holds the canvas for the left-eye view:.
-
m_kMainPane
private javax.swing.JSplitPane m_kMainPane
The JSplitPane displaying different views and the user-interface:.
-
m_kRGStereo
private java.awt.image.BufferedImage m_kRGStereo
BufferedImage containing the Anagyphy stereo image:.
-
m_kRightCanvas
private VolumeCanvas3D m_kRightCanvas
Right-eye view canvas:.
-
m_kRightImagePanel
private javax.swing.JPanel m_kRightImagePanel
Right Image Panel, holds the canvas for the right-eye view:.
-
m_kStereoCanvas
private VolumeCanvas3D m_kStereoCanvas
Stereo canvas:.
-
m_kStereoPane
private javax.swing.JSplitPane m_kStereoPane
The JSplitPane displaying the left and right eye views and the stereo view:.
-
m_kStereoPanel
private javax.swing.JPanel m_kStereoPanel
Stereo Image Panel, holds the canvas for the Anaglyph stereo view:.
-
m_kStereoShape
private javax.media.j3d.Shape3D m_kStereoShape
Texture-mapped polygon for displaying the Anaglyph stereo image as a texture:.
-
-
Constructor Detail
-
JStereoWindow
public JStereoWindow(SurfaceAttributes kSurface, javax.media.j3d.Transform3D kTransform)
Constructs a JStereoWindow with a ModelTriangleMesh and Transform3D representing the model transformation for the surface.- Parameters:
kMesh
- the displayed surfacekTransform
- the current model transformation (rotation, scale, translation) for the surface.
-
JStereoWindow
public JStereoWindow(javax.media.j3d.Group kNode1, javax.media.j3d.Group kNode2, javax.media.j3d.Transform3D kTransform, SurfaceRender kSurface)
Constructs a JStereoWindow with two nodes, one copy for each of the left and right eye views. The input nodes are identical. The Transform3D represents the model transformation for the nodes.- Parameters:
kNode1
- 1st copy of the displayed object (NodeVolumeTextureRender)kNode2
- 2nd copy of the displayed object (NodeVolumeTextureRender)kTransform
- the current model transformation (rotation, scale, translation) for the nodes.kSurface
- the parent window.
-
-
Method Detail
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent kEvent)
Called when a button is pressed:- Specified by:
actionPerformed
in interfacejava.awt.event.ActionListener
- Parameters:
kEvent
- action event
-
componentHidden
public void componentHidden(java.awt.event.ComponentEvent e)
componentHidden.- Specified by:
componentHidden
in interfacejava.awt.event.ComponentListener
- Parameters:
e
- ComponentEvent
-
componentMoved
public void componentMoved(java.awt.event.ComponentEvent e)
componentMoved.- Specified by:
componentMoved
in interfacejava.awt.event.ComponentListener
- Parameters:
e
- ComponentEvent
-
componentResized
public void componentResized(java.awt.event.ComponentEvent e)
componentResized.- Specified by:
componentResized
in interfacejava.awt.event.ComponentListener
- Parameters:
e
- ComponentEvent
-
componentShown
public void componentShown(java.awt.event.ComponentEvent e)
componentShown.- Specified by:
componentShown
in interfacejava.awt.event.ComponentListener
- Parameters:
e
- ComponentEvent
-
dispose
public void dispose()
Deletes all local data members.- Overrides:
dispose
in classjava.awt.Window
-
mouseDragged
public void mouseDragged(java.awt.event.MouseEvent e)
mouseDragged.- Specified by:
mouseDragged
in interfacejava.awt.event.MouseMotionListener
- Parameters:
e
- MouseEvent
-
mouseMoved
public void mouseMoved(java.awt.event.MouseEvent e)
mouseMoved.- Specified by:
mouseMoved
in interfacejava.awt.event.MouseMotionListener
- Parameters:
e
- MouseEvent
-
stateChanged
public void stateChanged(javax.swing.event.ChangeEvent event)
Called when the slider values have changed. Reads the new focal-length value and recalculates the viewing transformations for the left and right-eye views.- Specified by:
stateChanged
in interfacejavax.swing.event.ChangeListener
- Parameters:
event
- ChangeEvent state change event.
-
windowActivated
public void windowActivated(java.awt.event.WindowEvent e)
windowActivated.- Specified by:
windowActivated
in interfacejava.awt.event.WindowListener
- Parameters:
e
- WindowEvent
-
windowClosed
public void windowClosed(java.awt.event.WindowEvent e)
windowClosed.- Specified by:
windowClosed
in interfacejava.awt.event.WindowListener
- Parameters:
e
- WindowEvent
-
windowClosing
public void windowClosing(java.awt.event.WindowEvent e)
windowClosing Catch the windowClosing event so that the local data memebrs can be destroyed.- Specified by:
windowClosing
in interfacejava.awt.event.WindowListener
- Parameters:
e
- WindowEvent
-
windowDeactivated
public void windowDeactivated(java.awt.event.WindowEvent e)
windowDeactivated.- Specified by:
windowDeactivated
in interfacejava.awt.event.WindowListener
- Parameters:
e
- WindowEvent
-
windowDeiconified
public void windowDeiconified(java.awt.event.WindowEvent e)
windowDeiconified.- Specified by:
windowDeiconified
in interfacejava.awt.event.WindowListener
- Parameters:
e
- WindowEvent
-
windowIconified
public void windowIconified(java.awt.event.WindowEvent e)
windowIconified.- Specified by:
windowIconified
in interfacejava.awt.event.WindowListener
- Parameters:
e
- WindowEvent
-
windowOpened
public void windowOpened(java.awt.event.WindowEvent e)
windowOpened.- Specified by:
windowOpened
in interfacejava.awt.event.WindowListener
- Parameters:
e
- WindowEvent
-
addBranchGroup
private javax.media.j3d.BranchGroup addBranchGroup(javax.media.j3d.Node kNode, javax.media.j3d.Transform3D kTransform)
Creates a BranchGroup containing the input Node and Transform3D, and returns the BranchGroup.- Parameters:
kNode
- the Node to add to the BranchGroupkTransform
- the transform for the input Node- Returns:
- the Branch of the SceneGraph containing the node and transform.
-
blendBuffers
private void blendBuffers(java.awt.image.BufferedImage kLeft, java.awt.image.BufferedImage kRight)
Blend two BufferedImages, representing the left and right-eye views into a Red-Cyan stereo anaglyph.- Parameters:
kLeft
- the frame buffer from the left-eye rendering.kRight
- the frame buffer from the right-eye rendering. This function does not return a value, but it sets the BufferedImage member variable m_kStereo and the Dimension member variable m_kD.
-
blendColor
private int blendColor(int iLeftC, int iRightC)
Blends two packed-integer colors (RGB) to create a Red-Cyan anaglyph.- Parameters:
iLeftC
- the color from the left-eye view.iRightC
- the color from the right-eye view.- Returns:
- the anaglyph color (packed-int) with the red component from the left-eye view and the green and blue components from the right-eye view, creating a Red-Cyan stereo.
-
createCanvas
private VolumeCanvas3D createCanvas(javax.media.j3d.Node kNode, javax.swing.JPanel kPanel)
Creates a canvas containing the input Node object, with the input viewing transformation. The canvas is displayed in the input JPanel:- Parameters:
kNode
- the object displayed in this canvas.kPanel
- the window panel containing this canvas.- Returns:
- the new canvas.
-
createTexturedPolygon
private void createTexturedPolygon()
Creates the texture-mapped polygon displayed in the stereo canvas. The left and right-eye views are read from the left and right-eye canvases and the images blended into a stereo view. The blended image is used as a texture and displayed on the texture-mapped polygon created in the function:
-
getFrameBuffer
private void getFrameBuffer(java.awt.image.BufferedImage kImage, VolumeCanvas3D kCanvas)
Read the frame buffer from the input VolumeCanvas3D and store the result in the input BufferedImage:- Parameters:
kImage
- the image the frame buffer is stored into.kCanvas
- the canvas from that is read.
-
init
private void init(javax.media.j3d.BranchGroup kNode1, javax.media.j3d.BranchGroup kNode2)
Initialize the scene graphs and left, right, and stereo canvases for this JStereoWindow.- Parameters:
kNode1
- the left-eye objectkNode2
- the right-eye object
-
setupInterface
private void setupInterface()
Sets up the user interface. "OK" Button and focal-length slider.
-
updateStereo
private void updateStereo()
Reads the left and right-eye buffers from the left and right-eye canvases and blends them into the Red-Cyan Anaglyph stereo buffer, which is then texture-mapped on the a polygon and rendered in the stereo canvas.
-
-