Class 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 AbstractViewportManagers such as the rendering the scene or an AWTImageViewport 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 AxisBox for embedding the Scene and getting values along axes.
    Author:
    Martin Pernollet
    • Field Detail

      • LOGGER

        protected static org.apache.logging.log4j.Logger LOGGER
      • backgroundColor

        protected Color backgroundColor
      • axisDisplayed

        protected boolean axisDisplayed
      • squared

        protected boolean squared
      • view2DLayout

        protected View2DLayout view2DLayout
        Settings for the layout of a 2D chart
      • cameraRenderingSphereRadiusFactor

        protected float cameraRenderingSphereRadiusFactor
      • maintainAllObjectsInView

        protected boolean maintainAllObjectsInView
        force to have all object maintained in screen, meaning axebox won't always keep the same size.
      • displayAxisWholeBounds

        protected boolean displayAxisWholeBounds
        display a magenta parallelepiped around the "whole bounds" of the axis (box + labels) for debugging purpose.
      • axis

        protected IAxis axis
      • quality

        protected Quality quality
      • scene

        protected Scene scene
      • annotations

        protected Scene annotations
      • viewpoint

        protected Coord3d viewpoint
      • scaling

        protected Coord3d scaling
      • chart

        protected Chart chart
      • wasOnTopAtLastRendering

        protected boolean wasOnTopAtLastRendering
      • first

        protected boolean first
      • hidpi

        protected HiDPI hidpi
      • pixelScale

        protected Coord2d pixelScale
      • initialized

        protected boolean initialized
      • VIEWPOINT_X_Y_MIN_NEAR_VIEWER

        public static final Coord3d VIEWPOINT_X_Y_MIN_NEAR_VIEWER
        A viewpoint allowing to have min X and Y values near viewer, growing toward horizon.
      • VIEWPOINT_AXIS_CORNER_TOUCH_BORDER

        public static final Coord3d VIEWPOINT_AXIS_CORNER_TOUCH_BORDER
        A viewpoint where two corners of the axis box touch top and bottom lines of the canvas.
      • VIEWPOINT_DEFAULT

        public static final Coord3d VIEWPOINT_DEFAULT
        A nice viewpoint to start the chart
      • VIEWPOINT_DEFAULT_OLD

        public static final Coord3d VIEWPOINT_DEFAULT_OLD
        A nice viewpoint to start the chart
      • 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
      • factorViewPointDistance

        protected float factorViewPointDistance
        Applies a factor to the default camera distance which is set to the radius of the scene bounds. Changing this value also change the camera clipping planes.
      • slave

        protected boolean slave
        A slave view won't clear its color and depth buffer before rendering
    • Constructor Detail

      • View

        public View​(IChartFactory factory,
                    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

      • initInstance

        public void initInstance​(IChartFactory factory,
                                 Scene scene,
                                 ICanvas canvas,
                                 Quality quality)
        Initialize a view object. Invoked by constructor Method name is made clear to avoid confusion with init() which initialize open GL context.
        Parameters:
        factory -
        scene -
        canvas -
        quality -
      • configureHiDPIListener

        protected void configureHiDPIListener​(ICanvas canvas)
        Upon pixel scale change, either at startup or during execution of the program, the listener will reconfigure the default font according to current HiDPI settings. This will reconfigure anything that draws based on AxisLayout.getFont(), hence:
        • the font of the axis text renderer
        • the font of the colorbar
      • getPixelScale

        public Coord2d getPixelScale()
        Return a copy of the currently known pixel scale as notified by the canvas. If the View received no pixel scale change event, the pixel scale will be 0.
      • getHiDPI

        public HiDPI getHiDPI()
        Return HiDPI status as ACTUALLY possible by the ICanvas on the current screen and computer, regardless of the {@link Quality#setHiDPIEnabled(true)}. Will always return HiDPI.OFF is chart is set to {@link Quality#setHiDPIEnabled(false)} as this forces the canvas to NOT make use of HiDPI.
        Returns:
      • get2DLayout

        public View2DLayout get2DLayout()
        Return the configuration of a 2D layout
      • get2DProcessing

        public View2DProcessing get2DProcessing()
        Return the result of processing a 2D layout using the layout configured with the instance returned by get2DLayout()
      • getPainter

        public IPainter getPainter()
      • getChart

        public Chart getChart()
      • setChart

        public void setChart​(Chart chart)
      • isSlave

        public boolean isSlave()
      • setSlave

        public void setSlave​(boolean slave)
      • 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()
        Perform the 2d projection of all Selectable objects of the scene. The result of the projection can be retrieved on the objects's instances.
      • projectMouse

        public Coord3d projectMouse​(int x,
                                    int y)
        Perform the 3d projection of a 2d coordinate.
      • markDimensionDirty

        public void markDimensionDirty()
        Might be invoked by a IScreenCanvas to indicate that dimension changed and that elements should be reprocessed at next rendering, e.g. 2d projections.
      • 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)
        Z scale.
      • setScale

        public void setScale​(Scale scale,
                             boolean notify)
        Z scale.
      • setScaleX

        public void setScaleX​(Scale scale)
      • setScaleX

        public void setScaleX​(Scale scale,
                              boolean notify)
      • setScaleY

        public void setScaleY​(Scale scale)
      • setScaleY

        public void setScaleY​(Scale scale,
                              boolean notify)
      • setScaleZ

        public void setScaleZ​(Scale scale)
      • setScaleZ

        public void setScaleZ​(Scale scale,
                              boolean notify)
      • getScale

        public Scale getScale()
      • lookToBox

        public void lookToBox​(BoundingBox3d box)
        Set the surrounding AxisBox dimensions, the Camera target and the colorbar range.
      • is2D

        public boolean is2D()
      • is3D

        public boolean is3D()
      • getScaling

        public Coord3d getScaling()
        Return the stretch ratio applied to the 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). Only X and Y dimensions are required, as the distance to center will be computed automatically by updateCamera(). The input coordinate is polar and considers
        • x is azimuth in [0;2xPI]
        • y is elevation in [-PI/2;+PI/2]. Will be clamped if out of bounds
        • z is range (distance to center) but ignored there as it is processed automatically
      • setViewPoint

        public void setViewPoint​(Coord3d polar)
        Set the viewpoint and query a view update.
      • getViewPoint

        public Coord3d getViewPoint()
        Get the viewpoint. The Z dimension is the one defined by updateCamera(), which depends on the view scaling.
      • getLastViewScaling

        public Coord3d getLastViewScaling()
        Return the last used view scaling that was set according to the setSquared(boolean) status.
      • setAxis

        public void setAxis​(IAxis axis)
      • getAxis

        public IAxis getAxis()
      • getAxisLayout

        public AxisLayout getAxisLayout()
      • getSquared

        public boolean getSquared()
      • setSquared

        public void setSquared​(boolean status)
      • isAxisDisplayed

        public boolean isAxisDisplayed()
      • setAxisDisplayed

        public void setAxisDisplayed​(boolean axisDisplayed)
      • setBackgroundColor

        public void setBackgroundColor​(Color color)
      • getBackgroundColor

        public Color getBackgroundColor()
      • 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.
      • setMaximized

        public void setMaximized​(boolean status)
      • isMaximized

        public boolean isMaximized()
      • getCameraRenderingSphereRadiusFactor

        public float getCameraRenderingSphereRadiusFactor()
        See Also:
        setter
      • setCameraRenderingSphereRadiusFactor

        public void setCameraRenderingSphereRadiusFactor​(float cameraRenderingSphereRadiusFactor)
        This allows zooming the 3d scene by editing the camera rendering sphere.
        • A value of 1 allows having an AxisBox with corners touching the top/bottom part of the canvas.
        • A value greater than 1 makes the rendering sphere bigger, hence the AxisBox appears smaller.
      • isMaintainAllObjectsInView

        public boolean isMaintainAllObjectsInView()
      • setMaintainAllObjectsInView

        public void setMaintainAllObjectsInView​(boolean maintainAllObjectsInView)
      • isDisplayAxisWholeBounds

        public boolean isDisplayAxisWholeBounds()
      • setDisplayAxisWholeBounds

        public void setDisplayAxisWholeBounds​(boolean displayAxisWholeBounds)
      • getScene

        public Scene getScene()
      • getSceneViewportRectangle

        public Rectangle getSceneViewportRectangle()
      • getCanvas

        public ICanvas getCanvas()
      • getAnnotations

        public Graph getAnnotations()
      • addViewEventListener

        public boolean addViewEventListener​(IViewEventListener listener)
      • removeViewOnTopEventListener

        public boolean removeViewOnTopEventListener​(IViewEventListener listener)
      • fireViewOnTopEvent

        protected void fireViewOnTopEvent​(boolean isOnTop)
      • fireViewFirstRenderStarts

        protected void fireViewFirstRenderStarts()
      • fireViewLifecycleHasInit

        protected void fireViewLifecycleHasInit​(ViewLifecycleEvent e)
      • fireViewLifecycleWillRender

        protected void fireViewLifecycleWillRender​(ViewLifecycleEvent 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 {@link Camera.shoot()}.
      • getSceneGraphBounds

        public BoundingBox3d getSceneGraphBounds()
      • updateBoundsForceUpdate

        public void updateBoundsForceUpdate​(boolean refresh)
        Update the bounds according to the scene graph whatever is the current ViewBoundMode, and orders a {@link 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.
      • init

        public void init()
        The initialization function:
        • specifies general GL settings that impact the rendering quality and performance (computation speed).
        • enable light management
        • load all required texture resources
        • fix the current view bounds to the whole scene graph bounds

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

      • initBounds

        protected void initBounds()
      • initQuality

        public void initQuality()
      • initLights

        public void initLights()
      • initLights

        public void initLights​(Scene scene)
      • initResources

        public void initResources()
      • clear

        public void clear()
        Clear the color and depth buffer.
      • render

        public void render()
      • renderBackground

        public void renderBackground​(float left,
                                     float right)
        To be implemented (see AWTView)
      • renderBackground

        public void renderBackground​(ViewportConfiguration backgroundViewPort)
        To be implemented (see AWTView)
      • renderScene

        public void renderScene()
      • renderScene

        public void renderScene​(float left,
                                float right)
      • updateQuality

        @Deprecated
        public void updateQuality()
        Deprecated.
        Not called anymore as alpha and blending setting are not supposed to change during lifetime of a chart. If this should change, then the entire initQuality() method should be invoked
      • squarify

        protected Coord3d squarify()
      • squarify

        protected Coord3d squarify​(Scene scene,
                                   ViewBoundMode boundmode,
                                   BoundingBox3d manualViewBounds,
                                   SpaceTransformer spaceTransformer)
        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.
      • squarifyGetSceneGraphBounds

        protected BoundingBox3d squarifyGetSceneGraphBounds​(Scene scene)
      • squarifyComputeBoundsRanges

        protected Coord3d squarifyComputeBoundsRanges​(BoundingBox3d bounds)
      • computeScaledViewBounds

        public BoundingBox3d computeScaledViewBounds()
      • computeSceneScaling

        public Coord3d computeSceneScaling()
      • computeViewpointDistance

        public float computeViewpointDistance​(BoundingBox3d bounds,
                                              float sceneRadiusScaled,
                                              float factorViewPointDistance)
      • computeCameraTarget

        protected Coord3d computeCameraTarget()
      • computeCameraEye

        protected Coord3d computeCameraEye​(Coord3d target)
      • computeCameraEyeProfile

        protected Coord3d computeCameraEyeProfile​(Coord3d viewpoint,
                                                  Coord3d target)
        Parameters:
        viewpoint -
        target -
      • triggerCameraUpEvents

        protected void triggerCameraUpEvents​(Coord3d viewpoint)
      • computeCameraUp

        protected Coord3d computeCameraUp​(Coord3d viewpoint)
      • computeCameraRenderingVolume

        protected void computeCameraRenderingVolume​(Camera cam,
                                                    ViewportConfiguration viewport,
                                                    BoundingBox3d bounds)
        Configure the camera so that it will capture a given volume in the scene. Rendering in 3D requires capturing a sphere defined by the bounding box radius. Rendering in 2D requires capturing a square defined by the bounding box with additional white space for labels and margins.
      • computeCamera3D_RenderingSphere

        protected void computeCamera3D_RenderingSphere​(Camera cam,
                                                       ViewportConfiguration viewport,
                                                       BoundingBox3d bounds)
        Camera clipping planes configuration for a rendering sphere (3D) Assume that axis labels are positioned accordingly (AxisLabelProcessor#axisLabelPosition_3D()
      • computeCamera2D_RenderingSquare

        protected void computeCamera2D_RenderingSquare​(Camera cam,
                                                       ViewportConfiguration viewport,
                                                       BoundingBox3d bounds)
        Camera clipping planes configuration for a rendering plane (2D)
      • correctCameraPositionForIncludingTextLabels

        @Deprecated
        protected void correctCameraPositionForIncludingTextLabels​(IPainter painter,
                                                                   ViewportConfiguration viewport)
        Deprecated.
        Only used for top/2D views. Performs a rendering to get the whole bounds occupied by the Axis Box and its text labels. Then edit the camera position to fit within this new bounds AND modify the clipping planes.
        Parameters:
        painter -
        viewport -
      • renderAxeBox

        protected void renderAxeBox()
      • renderAxeBox

        protected void renderAxeBox​(IAxis axe,
                                    Scene scene,
                                    Camera camera,
                                    Coord3d scaling,
                                    boolean axeBoxDisplayed)
      • renderSceneGraph

        public void renderSceneGraph()
      • renderSceneGraph

        public void renderSceneGraph​(boolean light)
      • renderSceneGraph

        public void renderSceneGraph​(boolean light,
                                     Camera camera,
                                     Scene scene,
                                     Coord3d scaling)
      • renderOverlay

        public void renderOverlay()
      • renderAnnotations

        public void renderAnnotations​(Camera camera)
      • setSpaceTransformer

        public void setSpaceTransformer​(SpaceTransformer transformer)
      • setSquarifier

        public void setSquarifier​(ISquarifier squarifier)
      • isInitialized

        public boolean isInitialized()