org.jzy3d.plot3d.rendering.view
Class View

java.lang.Object
  extended by org.jzy3d.plot3d.rendering.view.View
Direct Known Subclasses:
ChartView, SelectableView

public class View
extends Object

A View holds a Scene, a LightSet, an ICanvas to render into. It is the responsability to layout a set of concrete AbstractViewports such as the rendering the scene or an ImageViewport for displaying an image in the same window. On can control the Camera with a and get notifyed by a IViewPointChangedListener that the view point has changed. The control is relative to the center of the Scene and is defined using polar coordinates. The View supports post rendering through the addition of Renderer2ds whose implementation can define Java2d calls to render on top on OpenGL2. Last, the View offers the ability to get an AxeBox for embedding the Scene and getting values along axes.

Author:
Martin Pernollet

Field Summary
protected  IAxe axe
           
protected  boolean axeBoxDisplayed
           
protected  Color bgColor
           
protected  BufferedImage bgImg
           
protected  Color bgOverlay
           
protected  ImageViewport bgViewport
           
protected  ViewBoundMode boundmode
           
protected  Camera cam
           
protected  CameraMode cameraMode
           
protected  ICanvas canvas
           
protected  Coord3d center
           
protected static View current
           
static Coord3d DEFAULT_VIEW
           
protected  boolean dimensionDirty
           
protected  boolean DISPLAY_AXE_WHOLE_BOUNDS
           
protected  javax.media.opengl.glu.GLU glu
           
protected  boolean MAINTAIN_ALL_OBJECTS_IN_VIEW
           
protected  com.jogamp.opengl.util.awt.Overlay overlay
           
protected static float PI_div2
           
protected  Quality quality
           
protected  List<Renderer2d> renderers
           
protected  Coord3d scaling
           
protected  Scene scene
           
protected  boolean squared
           
static float STRETCH_RATIO
           
protected  BoundingBox3d targetBox
           
protected  List<ITooltipRenderer> tooltips
           
protected  BoundingBox3d viewbounds
           
protected  boolean viewDirty
          can be set to true by the Renderer3d so that the View knows it is rendering due to a canvas size change
protected  ViewPositionMode viewmode
           
protected  List<IViewIsVerticalEventListener> viewOnTopListeners
           
protected  Coord3d viewpoint
           
protected  List<IViewPointChangedListener> viewPointChangedListeners
           
protected  boolean wasOnTopAtLastRendering
           
 
Constructor Summary
View(Scene scene, ICanvas canvas, Quality quality)
          Create a view attached to a Scene, with its own Camera and Axe.
 
Method Summary
 void addRenderer2d(Renderer2d renderer)
           
 void addTooltip(ITooltipRenderer tooltip)
           
 void addTooltips(List<ITooltipRenderer> tooltip)
           
 boolean addViewOnTopEventListener(IViewIsVerticalEventListener listener)
           
 boolean addViewPointChangedListener(IViewPointChangedListener listener)
           
 void clear(javax.media.opengl.GL2 gl)
          Clear the color and depth buffer.
 void clearColorAndDepth(javax.media.opengl.GL2 gl)
           
 void clearTooltips()
           
 BoundingBox3d computeScaling()
           
protected  void correctCameraPositionForIncludingTextLabels(javax.media.opengl.GL2 gl, javax.media.opengl.glu.GLU glu, ViewPort viewport)
           
static View current()
           
 void dispose()
           
protected  void fireViewOnTopEvent(boolean isOnTop)
           
protected  void fireViewPointChangedEvent(ViewPointChangedEvent e)
           
 IAxe getAxe()
           
 Color getBackgroundColor()
           
 BufferedImage getBackgroundImage()
           
 BoundingBox3d getBounds()
          Get the AxeBox's BoundingBox3d
 ViewBoundMode getBoundsMode()
           
 Camera getCamera()
           
 CameraMode getCameraMode()
          Get the projection of this view, either CameraMode.ORTHOGONAL or CameraMode.PERSPECTIVE.
 ICanvas getCanvas()
           
protected  javax.media.opengl.GLAutoDrawable getCanvasAsGLAutoDrawable()
           
 javax.media.opengl.GLContext getCurrentContext()
           
 javax.media.opengl.GL2 getCurrentGL()
          GL2
 Coord3d getLastViewScaling()
           
 void getMaximized()
           
 Scale getScale()
           
 Scene getScene()
           
 Rectangle getSceneViewportRectangle()
           
 boolean getSquared()
           
 List<ITooltipRenderer> getTooltips()
           
 ViewPositionMode getViewMode()
          Return the ViewPositionMode applied to this view.
 Coord3d getViewPoint()
          Get the viewpoint.
 void init(javax.media.opengl.GL2 gl)
          The init function specifies general GL settings that impact the rendering quality and performance (computation speed).
 void initLights(javax.media.opengl.GL2 gl)
           
 void initQuality(javax.media.opengl.GL2 gl)
           
 boolean isAxeBoxDisplayed()
           
 void lookToBox(BoundingBox3d box)
          Set the surrounding AxeBox dimensions and the Camera target, and the colorbar range.
 void project()
           
 Coord3d projectMouse(int x, int y)
           
 void removeRenderer2d(Renderer2d renderer)
           
 boolean removeViewOnTopEventListener(IViewIsVerticalEventListener listener)
           
 boolean removeViewPointChangedListener(IViewPointChangedListener listener)
           
 void render(javax.media.opengl.GL2 gl, javax.media.opengl.glu.GLU glu)
           
 void renderAxeBox(javax.media.opengl.GL2 gl, javax.media.opengl.glu.GLU glu)
           
 void renderBackground(javax.media.opengl.GL2 gl, javax.media.opengl.glu.GLU glu, float left, float right)
           
 void renderBackground(javax.media.opengl.GL2 gl, javax.media.opengl.glu.GLU glu, ViewPort viewport)
           
 void renderOverlay(javax.media.opengl.GL2 gl)
           
 void renderOverlay(javax.media.opengl.GL2 gl, ViewPort viewport)
          Renders all provided Tooltips and Renderer2ds on top of the scene.
 void renderScene(javax.media.opengl.GL2 gl, javax.media.opengl.glu.GLU glu)
           
 void renderScene(javax.media.opengl.GL2 gl, javax.media.opengl.glu.GLU glu, float left, float right)
           
 void renderScene(javax.media.opengl.GL2 gl, javax.media.opengl.glu.GLU glu, ViewPort viewport)
           
 void renderSceneGraph(javax.media.opengl.GL2 gl, javax.media.opengl.glu.GLU glu)
           
 void renderSceneGraph(javax.media.opengl.GL2 gl, javax.media.opengl.glu.GLU glu, boolean light)
           
 void rotate(Coord2d move)
          GENERAL DISPLAY CONTROLS
 void rotate(Coord2d move, boolean updateView)
           
 void setAxe(AxeBox ax)
          CONTROLS ANNOTATIONS & GENERAL RENDERING
 void setAxeBoxDisplayed(boolean axeBoxDisplayed)
           
 void setBackgroundColor(Color color)
           
 void setBackgroundImage(BufferedImage i)
          Set a buffered image, or null to desactivate background image
 void setBoundManual(BoundingBox3d bounds)
          Set a manual bounding box and switch the bounding mode to {ViewBoundMode.MANUAL}, meaning that any call to updateBounds() will update view bounds to the current bounds.
 void setBoundMode(ViewBoundMode mode)
          Select between an automatic bounding (that allows fitting the entire scene graph), or a custom bounding.
 void setCameraMode(CameraMode mode)
          Set the projection of this view, either Camera.ORTHOGONAL or Camera.PERSPECTIVE.
 void setMaximized(boolean status)
           
 void setScale(Scale scale)
           
 void setScale(Scale scale, boolean notify)
           
 void setSquared(boolean status)
           
 void setTooltip(ITooltipRenderer tooltip)
           
 void setTooltips(List<ITooltipRenderer> tooltip)
           
 void setViewPoint(Coord3d polar)
           
 void setViewPoint(Coord3d polar, boolean updateView)
          Set the viewpoint using polar coordinates relative to the target (i.e.
 void setViewPositionMode(ViewPositionMode mode)
          Set the ViewPositionMode applied to this view.
 void shift(float factor)
           
 void shift(float factor, boolean updateView)
           
 void shoot()
          Current view selection into the mother Scene, and call to target canvas rendering.
protected  Coord3d squarify()
          Return a 3d scaling factor that allows scaling the scene into a square box, according to the current ViewBoundMode.
 void updateBounds()
          Set the bounds of the view according to the current ViewBoundMode , and orders a Camera.shoot().
 void updateBoundsForceUpdate(boolean refresh)
          Update the bounds according to the scene graph whatever is the current ViewBoundMode, and orders a Camera.shoot()
 void updateCamera(javax.media.opengl.GL2 gl, javax.media.opengl.glu.GLU glu, ViewPort viewport, BoundingBox3d boundsScaled)
           
 void updateCamera(javax.media.opengl.GL2 gl, javax.media.opengl.glu.GLU glu, ViewPort viewport, BoundingBox3d boundsScaled, float sceneRadiusScaled)
           
 void updateQuality(javax.media.opengl.GL2 gl)
           
 void zoom(float factor)
           
 void zoom(float factor, boolean updateView)
           
 void zoomX(float factor)
           
 void zoomX(float factor, boolean updateView)
           
 void zoomY(float factor)
           
 void zoomY(float factor, boolean updateView)
           
 void zoomZ(float factor)
           
 void zoomZ(float factor, boolean updateView)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

glu

protected javax.media.opengl.glu.GLU glu

STRETCH_RATIO

public static float STRETCH_RATIO

MAINTAIN_ALL_OBJECTS_IN_VIEW

protected boolean MAINTAIN_ALL_OBJECTS_IN_VIEW

DISPLAY_AXE_WHOLE_BOUNDS

protected boolean DISPLAY_AXE_WHOLE_BOUNDS

axeBoxDisplayed

protected boolean axeBoxDisplayed

squared

protected boolean squared

cam

protected Camera cam

axe

protected IAxe axe

quality

protected Quality quality

overlay

protected com.jogamp.opengl.util.awt.Overlay overlay

scene

protected Scene scene

canvas

protected ICanvas canvas

viewpoint

protected Coord3d viewpoint

center

protected Coord3d center

scaling

protected Coord3d scaling

viewbounds

protected BoundingBox3d viewbounds

cameraMode

protected CameraMode cameraMode

viewmode

protected ViewPositionMode viewmode

boundmode

protected ViewBoundMode boundmode

bgViewport

protected ImageViewport bgViewport

bgImg

protected BufferedImage bgImg

targetBox

protected BoundingBox3d targetBox

bgColor

protected Color bgColor

bgOverlay

protected Color bgOverlay

tooltips

protected List<ITooltipRenderer> tooltips

renderers

protected List<Renderer2d> renderers

viewPointChangedListeners

protected List<IViewPointChangedListener> viewPointChangedListeners

viewOnTopListeners

protected List<IViewIsVerticalEventListener> viewOnTopListeners

wasOnTopAtLastRendering

protected boolean wasOnTopAtLastRendering

PI_div2

protected static final float PI_div2
See Also:
Constant Field Values

DEFAULT_VIEW

public static final Coord3d DEFAULT_VIEW

dimensionDirty

protected boolean dimensionDirty

viewDirty

protected boolean viewDirty
can be set to true by the Renderer3d so that the View knows it is rendering due to a canvas size change


current

protected static View current
Constructor Detail

View

public View(Scene scene,
            ICanvas canvas,
            Quality quality)
Create a view attached to a Scene, with its own Camera and Axe. The initial view point is set at View.DEFAULT_VIEW.

The Quality allows setting the rendering capabilities that are set one time by the init() method.

Method Detail

dispose

public void dispose()

shoot

public void shoot()
Current view selection into the mother Scene, and call to target canvas rendering.


project

public void project()

projectMouse

public Coord3d projectMouse(int x,
                            int y)

rotate

public void rotate(Coord2d move)
GENERAL DISPLAY CONTROLS


rotate

public void rotate(Coord2d move,
                   boolean updateView)

shift

public void shift(float factor)

shift

public void shift(float factor,
                  boolean updateView)

zoom

public void zoom(float factor)

zoom

public void zoom(float factor,
                 boolean updateView)

zoomX

public void zoomX(float factor)

zoomX

public void zoomX(float factor,
                  boolean updateView)

zoomY

public void zoomY(float factor)

zoomY

public void zoomY(float factor,
                  boolean updateView)

zoomZ

public void zoomZ(float factor)

zoomZ

public void zoomZ(float factor,
                  boolean updateView)

setScale

public void setScale(Scale scale)

setScale

public void setScale(Scale scale,
                     boolean notify)

getScale

public Scale getScale()

lookToBox

public void lookToBox(BoundingBox3d box)
Set the surrounding AxeBox dimensions and the Camera target, and the colorbar range.


getBounds

public BoundingBox3d getBounds()
Get the AxeBox's BoundingBox3d


getBoundsMode

public ViewBoundMode getBoundsMode()

setViewPositionMode

public void setViewPositionMode(ViewPositionMode mode)
Set the ViewPositionMode applied to this view.


getViewMode

public ViewPositionMode getViewMode()
Return the ViewPositionMode applied to this view.


setViewPoint

public void setViewPoint(Coord3d polar,
                         boolean updateView)
Set the viewpoint using polar coordinates relative to the target (i.e. the center of the scene).


setViewPoint

public void setViewPoint(Coord3d polar)

getViewPoint

public Coord3d getViewPoint()
Get the viewpoint.


getLastViewScaling

public Coord3d getLastViewScaling()

setAxe

public void setAxe(AxeBox ax)
CONTROLS ANNOTATIONS & GENERAL RENDERING


getAxe

public IAxe getAxe()

getSquared

public boolean getSquared()

setSquared

public void setSquared(boolean status)

isAxeBoxDisplayed

public boolean isAxeBoxDisplayed()

setAxeBoxDisplayed

public void setAxeBoxDisplayed(boolean axeBoxDisplayed)

setBackgroundColor

public void setBackgroundColor(Color color)

getBackgroundColor

public Color getBackgroundColor()

setBackgroundImage

public void setBackgroundImage(BufferedImage i)
Set a buffered image, or null to desactivate background image


getBackgroundImage

public BufferedImage getBackgroundImage()

getCamera

public Camera getCamera()

setCameraMode

public void setCameraMode(CameraMode mode)
Set the projection of this view, either Camera.ORTHOGONAL or Camera.PERSPECTIVE.


getCameraMode

public CameraMode getCameraMode()
Get the projection of this view, either CameraMode.ORTHOGONAL or CameraMode.PERSPECTIVE.


getMaximized

public void getMaximized()

setMaximized

public void setMaximized(boolean status)

getScene

public Scene getScene()

getSceneViewportRectangle

public Rectangle getSceneViewportRectangle()

clearTooltips

public void clearTooltips()

setTooltip

public void setTooltip(ITooltipRenderer tooltip)

addTooltip

public void addTooltip(ITooltipRenderer tooltip)

setTooltips

public void setTooltips(List<ITooltipRenderer> tooltip)

addTooltips

public void addTooltips(List<ITooltipRenderer> tooltip)

getTooltips

public List<ITooltipRenderer> getTooltips()

getCanvas

public ICanvas getCanvas()

addRenderer2d

public void addRenderer2d(Renderer2d renderer)

removeRenderer2d

public void removeRenderer2d(Renderer2d renderer)

addViewOnTopEventListener

public boolean addViewOnTopEventListener(IViewIsVerticalEventListener listener)

removeViewOnTopEventListener

public boolean removeViewOnTopEventListener(IViewIsVerticalEventListener listener)

fireViewOnTopEvent

protected void fireViewOnTopEvent(boolean isOnTop)

addViewPointChangedListener

public boolean addViewPointChangedListener(IViewPointChangedListener listener)

removeViewPointChangedListener

public boolean removeViewPointChangedListener(IViewPointChangedListener listener)

fireViewPointChangedEvent

protected void fireViewPointChangedEvent(ViewPointChangedEvent e)

setBoundMode

public void setBoundMode(ViewBoundMode mode)
Select between an automatic bounding (that allows fitting the entire scene graph), or a custom bounding.


updateBounds

public void updateBounds()
Set the bounds of the view according to the current ViewBoundMode , and orders a Camera.shoot().


updateBoundsForceUpdate

public void updateBoundsForceUpdate(boolean refresh)
Update the bounds according to the scene graph whatever is the current ViewBoundMode, and orders a Camera.shoot()


setBoundManual

public void setBoundManual(BoundingBox3d bounds)
Set a manual bounding box and switch the bounding mode to {ViewBoundMode.MANUAL}, meaning that any call to updateBounds() will update view bounds to the current bounds.


squarify

protected Coord3d squarify()
Return a 3d scaling factor that allows scaling the scene into a square box, according to the current ViewBoundMode.

If the scene bounds are Infinite, NaN or zero, for a given dimension, the scaler will be set to 1 on the given dimension.

Returns:
a scaling factor for each dimension.

getCurrentGL

public javax.media.opengl.GL2 getCurrentGL()
GL2


getCurrentContext

public javax.media.opengl.GLContext getCurrentContext()

getCanvasAsGLAutoDrawable

protected javax.media.opengl.GLAutoDrawable getCanvasAsGLAutoDrawable()

init

public void init(javax.media.opengl.GL2 gl)
The init function specifies general GL settings that impact the rendering quality and performance (computation speed).

The rendering settings are set by the Quality instance given in the constructor parameters.


initQuality

public void initQuality(javax.media.opengl.GL2 gl)

initLights

public void initLights(javax.media.opengl.GL2 gl)

clear

public void clear(javax.media.opengl.GL2 gl)
Clear the color and depth buffer.


clearColorAndDepth

public void clearColorAndDepth(javax.media.opengl.GL2 gl)

render

public void render(javax.media.opengl.GL2 gl,
                   javax.media.opengl.glu.GLU glu)

renderBackground

public void renderBackground(javax.media.opengl.GL2 gl,
                             javax.media.opengl.glu.GLU glu,
                             float left,
                             float right)

renderBackground

public void renderBackground(javax.media.opengl.GL2 gl,
                             javax.media.opengl.glu.GLU glu,
                             ViewPort viewport)

renderScene

public void renderScene(javax.media.opengl.GL2 gl,
                        javax.media.opengl.glu.GLU glu)

renderScene

public void renderScene(javax.media.opengl.GL2 gl,
                        javax.media.opengl.glu.GLU glu,
                        float left,
                        float right)

renderScene

public void renderScene(javax.media.opengl.GL2 gl,
                        javax.media.opengl.glu.GLU glu,
                        ViewPort viewport)

updateQuality

public void updateQuality(javax.media.opengl.GL2 gl)

computeScaling

public BoundingBox3d computeScaling()

updateCamera

public void updateCamera(javax.media.opengl.GL2 gl,
                         javax.media.opengl.glu.GLU glu,
                         ViewPort viewport,
                         BoundingBox3d boundsScaled)

updateCamera

public void updateCamera(javax.media.opengl.GL2 gl,
                         javax.media.opengl.glu.GLU glu,
                         ViewPort viewport,
                         BoundingBox3d boundsScaled,
                         float sceneRadiusScaled)

renderAxeBox

public void renderAxeBox(javax.media.opengl.GL2 gl,
                         javax.media.opengl.glu.GLU glu)

renderSceneGraph

public void renderSceneGraph(javax.media.opengl.GL2 gl,
                             javax.media.opengl.glu.GLU glu)

renderSceneGraph

public void renderSceneGraph(javax.media.opengl.GL2 gl,
                             javax.media.opengl.glu.GLU glu,
                             boolean light)

renderOverlay

public void renderOverlay(javax.media.opengl.GL2 gl)

renderOverlay

public void renderOverlay(javax.media.opengl.GL2 gl,
                          ViewPort viewport)
Renders all provided Tooltips and Renderer2ds on top of the scene. Due to the behaviour of the Overlay implementation, Java2d geometries must be drawn relative to the Chart's IScreenCanvas, BUT will then be stretched to fit in the Camera's viewport. This bug is very important to consider, since the Camera's viewport may not occupy the full IScreenCanvas. Indeed, when View is not maximized (like the default behaviour), the viewport remains square and centered in the canvas, meaning the Overlay won't cover the full canvas area. In other words, the following piece of code draws a border around the View, and not around the complete chart canvas, although queried to occupy chart canvas dimensions: g2d.drawRect(1, 1, chart.getCanvas().getRendererWidth()-2, chart.getCanvas().getRendererHeight()-2); renderOverlay() must be called while the OpenGL2 context for the drawable is current, and after the OpenGL2 scene has been rendered.


correctCameraPositionForIncludingTextLabels

protected void correctCameraPositionForIncludingTextLabels(javax.media.opengl.GL2 gl,
                                                           javax.media.opengl.glu.GLU glu,
                                                           ViewPort viewport)

current

public static View current()