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:
ActionListener,ComponentListener,MouseMotionListener,WindowListener,ImageObserver,MenuContainer,Serializable,EventListener,Accessible,ChangeListener,RootPaneContainer,WindowConstants
public class JStereoWindow
extends JFrame
implements WindowListener, ActionListener, ChangeListener, ComponentListener, 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:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JFrame
JFrame.AccessibleJFrameNested classes/interfaces inherited from class java.awt.Frame
Frame.AccessibleAWTFrameNested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow, Window.TypeNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate com.sun.j3d.utils.universe.SimpleUniverse[]Three SimpleUniverses, one for each canavas:.private doubleOriginal eye separation, read from the canvas.view.physicalbody.private intThe current universe to be initialized:.private intFirst time the stereo canvas is rendered, set to true:.private DimensionBufferedImage Dimensions (power of two).private JSplitPaneThe JSplitPane displaying the left and right eye views:.private JSliderFocal-length, (eye separation) slider.private VolumeCanvas3DLeft-eye view canvas:.private JPanelLeft Image Panel, holds the canvas for the left-eye view:.private JSplitPaneThe JSplitPane displaying different views and the user-interface:.private BufferedImageBufferedImage containing the Anagyphy stereo image:.private VolumeCanvas3DRight-eye view canvas:.private JPanelRight Image Panel, holds the canvas for the right-eye view:.private VolumeCanvas3DStereo canvas:.private JSplitPaneThe JSplitPane displaying the left and right eye views and the stereo view:.private JPanelStereo Image Panel, holds the canvas for the Anaglyph stereo view:.private javax.media.j3d.Shape3DTexture-mapped polygon for displaying the Anaglyph stereo image as a texture:.private static final longUse serialVersionUID for interoperability.Fields inherited from class javax.swing.JFrame
accessibleContext, rootPane, rootPaneCheckingEnabledFields 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_CURSORFields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE -
Constructor Summary
ConstructorsConstructorDescriptionJStereoWindow(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
Modifier and TypeMethodDescriptionvoidactionPerformed(ActionEvent kEvent) Called when a button is pressed:private javax.media.j3d.BranchGroupaddBranchGroup(javax.media.j3d.Node kNode, javax.media.j3d.Transform3D kTransform) Creates a BranchGroup containing the input Node and Transform3D, and returns the BranchGroup.private voidblendBuffers(BufferedImage kLeft, BufferedImage kRight) Blend two BufferedImages, representing the left and right-eye views into a Red-Cyan stereo anaglyph.private intblendColor(int iLeftC, int iRightC) Blends two packed-integer colors (RGB) to create a Red-Cyan anaglyph.voidcomponentHidden.voidcomponentMoved.voidcomponentResized.voidcomponentShown.private VolumeCanvas3DcreateCanvas(javax.media.j3d.Node kNode, JPanel kPanel) Creates a canvas containing the input Node object, with the input viewing transformation.private voidCreates the texture-mapped polygon displayed in the stereo canvas.voiddispose()Deletes all local data members.private voidgetFrameBuffer(BufferedImage kImage, VolumeCanvas3D kCanvas) Read the frame buffer from the input VolumeCanvas3D and store the result in the input BufferedImage:private voidinit(javax.media.j3d.BranchGroup kNode1, javax.media.j3d.BranchGroup kNode2) Initialize the scene graphs and left, right, and stereo canvases for this JStereoWindow.voidmouseDragged.voidmouseMoved.private voidSets up the user interface.voidstateChanged(ChangeEvent event) Called when the slider values have changed.private voidReads 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.voidwindowActivated.voidwindowClosed.voidwindowClosing Catch the windowClosing event so that the local data memebrs can be destroyed.voidwindowDeactivated.voidwindowDeiconified.voidwindowIconified.voidwindowOpened.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, updateMethods 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, setUndecoratedMethods 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, toFrontMethods 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, validateTreeMethods 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, transferFocusUpCycleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.awt.MenuContainer
getFont, postEvent
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDUse serialVersionUID for interoperability.- See Also:
-
m_akUniverse
private com.sun.j3d.utils.universe.SimpleUniverse[] m_akUniverseThree SimpleUniverses, one for each canavas:. -
m_dEyeSeparation
private double m_dEyeSeparationOriginal eye separation, read from the canvas.view.physicalbody. -
m_iCurrentUniverse
private int m_iCurrentUniverseThe current universe to be initialized:. -
m_iStereoUpdateCount
private int m_iStereoUpdateCountFirst time the stereo canvas is rendered, set to true:. -
m_kD
BufferedImage Dimensions (power of two). -
m_kDisplayPane
The JSplitPane displaying the left and right eye views:. -
m_kEyeSep_Slider
Focal-length, (eye separation) slider. -
m_kLeftCanvas
Left-eye view canvas:. -
m_kLeftImagePanel
Left Image Panel, holds the canvas for the left-eye view:. -
m_kMainPane
The JSplitPane displaying different views and the user-interface:. -
m_kRGStereo
BufferedImage containing the Anagyphy stereo image:. -
m_kRightCanvas
Right-eye view canvas:. -
m_kRightImagePanel
Right Image Panel, holds the canvas for the right-eye view:. -
m_kStereoCanvas
Stereo canvas:. -
m_kStereoPane
The JSplitPane displaying the left and right eye views and the stereo view:. -
m_kStereoPanel
Stereo Image Panel, holds the canvas for the Anaglyph stereo view:. -
m_kStereoShape
private javax.media.j3d.Shape3D m_kStereoShapeTexture-mapped polygon for displaying the Anaglyph stereo image as a texture:.
-
-
Constructor Details
-
JStereoWindow
Constructs a JStereoWindow with a ModelTriangleMesh and Transform3D representing the model transformation for the surface.- Parameters:
kTransform- the current model transformation (rotation, scale, translation) for the surface.kMesh- the displayed 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 Details
-
actionPerformed
Called when a button is pressed:- Specified by:
actionPerformedin interfaceActionListener- Parameters:
kEvent- action event
-
componentHidden
componentHidden.- Specified by:
componentHiddenin interfaceComponentListener- Parameters:
e- ComponentEvent
-
componentMoved
componentMoved.- Specified by:
componentMovedin interfaceComponentListener- Parameters:
e- ComponentEvent
-
componentResized
componentResized.- Specified by:
componentResizedin interfaceComponentListener- Parameters:
e- ComponentEvent
-
componentShown
componentShown.- Specified by:
componentShownin interfaceComponentListener- Parameters:
e- ComponentEvent
-
dispose
public void dispose()Deletes all local data members. -
mouseDragged
mouseDragged.- Specified by:
mouseDraggedin interfaceMouseMotionListener- Parameters:
e- MouseEvent
-
mouseMoved
mouseMoved.- Specified by:
mouseMovedin interfaceMouseMotionListener- Parameters:
e- MouseEvent
-
stateChanged
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:
stateChangedin interfaceChangeListener- Parameters:
event- ChangeEvent state change event.
-
windowActivated
windowActivated.- Specified by:
windowActivatedin interfaceWindowListener- Parameters:
e- WindowEvent
-
windowClosed
windowClosed.- Specified by:
windowClosedin interfaceWindowListener- Parameters:
e- WindowEvent
-
windowClosing
windowClosing Catch the windowClosing event so that the local data memebrs can be destroyed.- Specified by:
windowClosingin interfaceWindowListener- Parameters:
e- WindowEvent
-
windowDeactivated
windowDeactivated.- Specified by:
windowDeactivatedin interfaceWindowListener- Parameters:
e- WindowEvent
-
windowDeiconified
windowDeiconified.- Specified by:
windowDeiconifiedin interfaceWindowListener- Parameters:
e- WindowEvent
-
windowIconified
windowIconified.- Specified by:
windowIconifiedin interfaceWindowListener- Parameters:
e- WindowEvent
-
windowOpened
windowOpened.- Specified by:
windowOpenedin interfaceWindowListener- 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
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
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
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.
-