artofillusion
Class ViewerCanvas

java.lang.Object
  extended by CustomWidget
      extended by artofillusion.ViewerCanvas
Direct Known Subclasses:
ObjectPreviewCanvas, ObjectViewer, SceneViewer

public abstract class ViewerCanvas
extends CustomWidget

ViewerCanvas is the abstract superclass of all components which display objects, and allow the user to manipulate them with EditingTools.


Field Summary
static java.awt.Color backgroundColor
           
static java.awt.Color disabledColor
           
static java.awt.Color handleColor
           
static java.awt.Color highlightColor
           
static RGBColor highValueColor
           
static java.awt.Color lineColor
           
static RGBColor lowValueColor
           
static int RENDER_FLAT
           
static int RENDER_RENDERED
           
static int RENDER_SMOOTH
           
static int RENDER_TEXTURED
           
static int RENDER_TRANSPARENT
           
static int RENDER_WIREFRAME
           
static java.awt.Color specialHighlightColor
           
static java.awt.Color surfaceColor
           
static RGBColor surfaceRGBColor
           
static RGBColor transparentColor
           
static int VIEW_BACK
           
static int VIEW_BOTTOM
           
static int VIEW_FRONT
           
static int VIEW_LEFT
           
static int VIEW_OTHER
           
static int VIEW_RIGHT
           
static int VIEW_TOP
           
 
Constructor Summary
ViewerCanvas()
           
ViewerCanvas(boolean useOpenGL)
           
 
Method Summary
static void addViewerControl(int index, ViewerControl control)
          Add a new ViewerControl that will be added to each new ViewerCanvas.
static void addViewerControl(ViewerControl control)
          Add a new ViewerControl that will be added to each new ViewerCanvas.
 void adjustCamera(boolean perspective)
           
 void copyOrientationFromCamera()
          If there is a camera bound to this view, copy the coordinates from it.
 void drawBorder()
          Draw a border around the rendered image.
 void drawBox(int x, int y, int width, int height, java.awt.Color color)
          Draw a filled box in the rendered image.
 void drawBoxes(java.util.List<java.awt.Rectangle> box, java.awt.Color color)
          Draw a set of filled boxes in the rendered image.
 void drawDraggedShape(java.awt.Shape shape)
          Show feedback to the user in response to a mouse drag, by drawing a Shape over the image.
 void drawHRule(int y, java.awt.Color color)
          Draw a horizontal line across the rendered image.
 void drawImage(java.awt.Image image, int x, int y)
          Draw an image onto the canvas.
 void drawLine(java.awt.Point p1, java.awt.Point p2, java.awt.Color color)
          Draw a line into the rendered image.
 void drawShape(java.awt.Shape shape, java.awt.Color color)
          Draw the outline of a Shape into the canvas.
 void drawString(java.lang.String text, int x, int y, java.awt.Color color)
          Draw a piece of text onto the canvas.
 void drawVRule(int x, java.awt.Color color)
          Draw a vertical line across the rendered image.
abstract  double[] estimateDepthRange()
          Estimate the range of depth values that the camera will need to render.
 void fillShape(java.awt.Shape shape, java.awt.Color color)
          Draw a filled Shape onto the canvas.
 void frameBox(BoundingBox bb)
          Adjust the camera position and magnification so that the specified box fills the view.
 ActionProcessor getActionProcessor()
          Get the ActionProcessor which is currently in use for processing mouse events (may be null).
 ObjectInfo getBoundCamera()
          Get the SceneCamera (if any) which is bound to this view.
 Camera getCamera()
           
 CanvasDrawer getCanvasDrawer()
          Get the CanvasDrawer which is rendering the image for this canvas.
 EditingTool getCurrentTool()
          Get the currently selected tool.
 Vec3 getDefaultRotationCenter()
          Get the default location around which the view should be rotated.
 boolean getDrawFocus()
          Get whether a focus ring should be drawn around this component.
 double getGridSpacing()
          Get the grid spacing.
 java.awt.Dimension getMinimumSize()
           
 int getOrientation()
          Get the current orientation mode.
 java.awt.Dimension getPreferredSize()
           
 int getRenderMode()
           
 Vec3 getRotationCenter()
          Get the location around which the view should be rotated.
 double getScale()
          Get the current scale factor for the view.
 Scene getScene()
          Get the Scene being displayed in this canvas.
 boolean getShowAxes()
          Determine whether the coordinate axes are currently showing.
 boolean getShowGrid()
          Get whether the grid is shown.
 boolean getSnapToGrid()
          Get whether Snap To Grid is enabled.
 int getSnapToSubdivisions()
          Get the number of "snap to" subdivisions between grid lines.
 java.awt.Image getTemplateImage()
          Get the template image.
 boolean getTemplateShown()
          Determine whether the template image is currently showing.
static java.util.List getViewerControls()
          Get the list of ViewerControls which will be added to each new ViewerCanvas.
 java.util.Map getViewerControlWidgets()
          Get a Map whose keys are the defined ViewerControls, and whose values are the corresponding Widgets for this canvas.
static boolean isOpenGLAvailable()
          Determine whether OpenGL rendering is available.
 boolean isPerspective()
          Determine whether the view is currently is perspective mode.
 void prepareCameraForRendering()
          This should be called by the CanvasDrawer just before rendering an image.
static void removeViewerControl(ViewerControl control)
          Remove a ViewerControl from the list of ones to be added to each new ViewerCanvas.
 void renderBox(int x, int y, int width, int height, double depth, java.awt.Color color)
          Render a filled box at a specified depth in the rendered image.
 void renderBoxes(java.util.List<java.awt.Rectangle> box, java.util.List<java.lang.Double> depth, java.awt.Color color)
          Render a set of filled boxes at specified depths in the rendered image.
 void renderImage(java.awt.Image image, Vec3 p1, Vec3 p2, Vec3 p3, Vec3 p4)
          Render an image onto the canvas.
 void renderLine(Vec2 p1, double zf1, Vec2 p2, double zf2, Camera cam, java.awt.Color color)
          Render a line into the image.
 void renderLine(Vec3 p1, Vec3 p2, Camera cam, java.awt.Color color)
          Render a line into the image.
 void renderMesh(RenderingMesh mesh, VertexShader shader, Camera cam, boolean closed, boolean[] hideFace)
          Render a mesh to the canvas.
 void renderMeshTransparent(RenderingMesh mesh, VertexShader shader, Camera cam, Vec3 viewDir, boolean[] hideFace)
          Render an object with flat shading in subtractive (transparent) mode.
 void renderWireframe(WireframeMesh mesh, Camera cam, java.awt.Color color)
          Render a wireframe object.
 void setAltTool(EditingTool tool)
          Set the tool which should be active when the alt key is pressed.
 void setBoundCamera(ObjectInfo boundCamera)
          Set the SceneCamera which is bound to this view (may be null).
 void setDrawFocus(boolean draw)
          Set whether a focus ring should be drawn around this component.
 void setGrid(double spacing, int subdivisions, boolean show, boolean snap)
          Set the grid parameters for this view.
 void setMetaTool(EditingTool tool)
          Set the tool which should be active when the meta key is pressed.
 void setOrientation(int which)
          Set the view orientation to any of the values shown in the choice menu.
 void setPerspective(boolean perspective)
          Set whether to display perspective or parallel mode.
 void setPopupMenuManager(PopupMenuManager manager)
          Set the PopupMenuManager for this canvas.
 void setPreferredSize(java.awt.Dimension size)
          This needs to be overridden, since the component may not be a JComponent.
 void setRenderMode(int mode)
           
 void setRotationCenter(Vec3 rotationCenter)
          Set the location around which the view should be rotated.
 void setScale(double scale)
          Set the scale factor for the view.
 void setShowAxes(boolean show)
          Set whether the coordinate axes should be displayed.
 void setShowTemplate(boolean show)
          Set whether the template image should be displayed.
 void setTemplateImage(java.io.File f)
          Set the template image based on an image file.
 void setTemplateImage(java.awt.Image im)
          Set the template image.
 void setTool(EditingTool tool)
          Set the currently selected tool.
 void updateImage()
          Subclasses should override this to draw the contents of the canvas, but should begin by calling super.updateImage() to display the grid.
 void viewChanged(boolean selectionOnly)
          This is called when the content of the view has changed.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

backgroundColor

public static java.awt.Color backgroundColor

lineColor

public static java.awt.Color lineColor

handleColor

public static java.awt.Color handleColor

highlightColor

public static java.awt.Color highlightColor

specialHighlightColor

public static java.awt.Color specialHighlightColor

disabledColor

public static java.awt.Color disabledColor

surfaceColor

public static java.awt.Color surfaceColor

surfaceRGBColor

public static RGBColor surfaceRGBColor

transparentColor

public static RGBColor transparentColor

lowValueColor

public static RGBColor lowValueColor

highValueColor

public static RGBColor highValueColor

RENDER_WIREFRAME

public static final int RENDER_WIREFRAME
See Also:
Constant Field Values

RENDER_FLAT

public static final int RENDER_FLAT
See Also:
Constant Field Values

RENDER_SMOOTH

public static final int RENDER_SMOOTH
See Also:
Constant Field Values

RENDER_TEXTURED

public static final int RENDER_TEXTURED
See Also:
Constant Field Values

RENDER_TRANSPARENT

public static final int RENDER_TRANSPARENT
See Also:
Constant Field Values

RENDER_RENDERED

public static final int RENDER_RENDERED
See Also:
Constant Field Values

VIEW_FRONT

public static final int VIEW_FRONT
See Also:
Constant Field Values

VIEW_BACK

public static final int VIEW_BACK
See Also:
Constant Field Values

VIEW_LEFT

public static final int VIEW_LEFT
See Also:
Constant Field Values

VIEW_RIGHT

public static final int VIEW_RIGHT
See Also:
Constant Field Values

VIEW_TOP

public static final int VIEW_TOP
See Also:
Constant Field Values

VIEW_BOTTOM

public static final int VIEW_BOTTOM
See Also:
Constant Field Values

VIEW_OTHER

public static final int VIEW_OTHER
See Also:
Constant Field Values
Constructor Detail

ViewerCanvas

public ViewerCanvas()

ViewerCanvas

public ViewerCanvas(boolean useOpenGL)
Method Detail

getCanvasDrawer

public CanvasDrawer getCanvasDrawer()
Get the CanvasDrawer which is rendering the image for this canvas.


setPreferredSize

public void setPreferredSize(java.awt.Dimension size)
This needs to be overridden, since the component may not be a JComponent.


getPreferredSize

public java.awt.Dimension getPreferredSize()

getMinimumSize

public java.awt.Dimension getMinimumSize()

getActionProcessor

public ActionProcessor getActionProcessor()
Get the ActionProcessor which is currently in use for processing mouse events (may be null).


getCamera

public Camera getCamera()

getScene

public Scene getScene()
Get the Scene being displayed in this canvas. The default implementation returns null. Subclasses may override it to return an appropriate Scene.


setTool

public void setTool(EditingTool tool)
Set the currently selected tool.


getCurrentTool

public EditingTool getCurrentTool()
Get the currently selected tool.


setMetaTool

public void setMetaTool(EditingTool tool)
Set the tool which should be active when the meta key is pressed.


setAltTool

public void setAltTool(EditingTool tool)
Set the tool which should be active when the alt key is pressed.


setPerspective

public void setPerspective(boolean perspective)
Set whether to display perspective or parallel mode.


isPerspective

public boolean isPerspective()
Determine whether the view is currently is perspective mode.


getScale

public double getScale()
Get the current scale factor for the view.


setScale

public void setScale(double scale)
Set the scale factor for the view.


getDrawFocus

public boolean getDrawFocus()
Get whether a focus ring should be drawn around this component.


setDrawFocus

public void setDrawFocus(boolean draw)
Set whether a focus ring should be drawn around this component.


getShowAxes

public boolean getShowAxes()
Determine whether the coordinate axes are currently showing.


setShowAxes

public void setShowAxes(boolean show)
Set whether the coordinate axes should be displayed.


getTemplateShown

public boolean getTemplateShown()
Determine whether the template image is currently showing.


setShowTemplate

public void setShowTemplate(boolean show)
Set whether the template image should be displayed.


getTemplateImage

public java.awt.Image getTemplateImage()
Get the template image.


setTemplateImage

public void setTemplateImage(java.awt.Image im)
Set the template image.


setTemplateImage

public void setTemplateImage(java.io.File f)
                      throws java.lang.InterruptedException
Set the template image based on an image file.

Throws:
java.lang.InterruptedException

getRotationCenter

public Vec3 getRotationCenter()
Get the location around which the view should be rotated. This may be null, in which case the value returned by getDefaultRotationCenter() will be used instead.


setRotationCenter

public void setRotationCenter(Vec3 rotationCenter)
Set the location around which the view should be rotated. This may be null, in which case the value returned by getDefaultRotationCenter() will be used instead.


getDefaultRotationCenter

public Vec3 getDefaultRotationCenter()
Get the default location around which the view should be rotated. This value will be used if getRotationCenter() returns null.


setPopupMenuManager

public void setPopupMenuManager(PopupMenuManager manager)
Set the PopupMenuManager for this canvas.


adjustCamera

public void adjustCamera(boolean perspective)

getBoundCamera

public ObjectInfo getBoundCamera()
Get the SceneCamera (if any) which is bound to this view.


setBoundCamera

public void setBoundCamera(ObjectInfo boundCamera)
Set the SceneCamera which is bound to this view (may be null).


setGrid

public void setGrid(double spacing,
                    int subdivisions,
                    boolean show,
                    boolean snap)
Set the grid parameters for this view.


getShowGrid

public boolean getShowGrid()
Get whether the grid is shown.


getSnapToGrid

public boolean getSnapToGrid()
Get whether Snap To Grid is enabled.


getGridSpacing

public double getGridSpacing()
Get the grid spacing.


getSnapToSubdivisions

public int getSnapToSubdivisions()
Get the number of "snap to" subdivisions between grid lines.


frameBox

public void frameBox(BoundingBox bb)
Adjust the camera position and magnification so that the specified box fills the view. This has no effect if there is a camera point to this view.


prepareCameraForRendering

public void prepareCameraForRendering()
This should be called by the CanvasDrawer just before rendering an image. It sets up the camera correctly.


estimateDepthRange

public abstract double[] estimateDepthRange()
Estimate the range of depth values that the camera will need to render. This need not be exact, but should err on the side of returning bounds that are slightly too large.

Returns:
the two element array {minDepth, maxDepth}

viewChanged

public void viewChanged(boolean selectionOnly)
This is called when the content of the view has changed.

Parameters:
selectionOnly - if true, the only change to the view is what is currently selected

updateImage

public void updateImage()
Subclasses should override this to draw the contents of the canvas, but should begin by calling super.updateImage() to display the grid.


getRenderMode

public int getRenderMode()

setRenderMode

public void setRenderMode(int mode)

getOrientation

public int getOrientation()
Get the current orientation mode.


setOrientation

public void setOrientation(int which)
Set the view orientation to any of the values shown in the choice menu.


copyOrientationFromCamera

public void copyOrientationFromCamera()
If there is a camera bound to this view, copy the coordinates from it.


drawDraggedShape

public void drawDraggedShape(java.awt.Shape shape)
Show feedback to the user in response to a mouse drag, by drawing a Shape over the image. This method should only ever be called from the event dispatch thread.


drawBorder

public void drawBorder()
Draw a border around the rendered image.


drawHRule

public void drawHRule(int y,
                      java.awt.Color color)
Draw a horizontal line across the rendered image. The parameters are the y coordinate of the line and the line color.


drawVRule

public void drawVRule(int x,
                      java.awt.Color color)
Draw a vertical line across the rendered image. The parameters are the x coordinate of the line and the line color.


drawBox

public void drawBox(int x,
                    int y,
                    int width,
                    int height,
                    java.awt.Color color)
Draw a filled box in the rendered image.


drawBoxes

public void drawBoxes(java.util.List<java.awt.Rectangle> box,
                      java.awt.Color color)
Draw a set of filled boxes in the rendered image.


renderBox

public void renderBox(int x,
                      int y,
                      int width,
                      int height,
                      double depth,
                      java.awt.Color color)
Render a filled box at a specified depth in the rendered image.


renderBoxes

public void renderBoxes(java.util.List<java.awt.Rectangle> box,
                        java.util.List<java.lang.Double> depth,
                        java.awt.Color color)
Render a set of filled boxes at specified depths in the rendered image.


drawLine

public void drawLine(java.awt.Point p1,
                     java.awt.Point p2,
                     java.awt.Color color)
Draw a line into the rendered image.


renderLine

public void renderLine(Vec3 p1,
                       Vec3 p2,
                       Camera cam,
                       java.awt.Color color)
Render a line into the image.

Parameters:
p1 - the first endpoint of the line
p2 - the second endpoint of the line
cam - the camera from which to draw the line
color - the line color

renderLine

public void renderLine(Vec2 p1,
                       double zf1,
                       Vec2 p2,
                       double zf2,
                       Camera cam,
                       java.awt.Color color)
Render a line into the image.

Parameters:
p1 - the first endpoint of the line, in screen coordinates
zf1 - the z coordinate of the first endpoint, in view coordinates
p2 - the second endpoint of the line, in screen coordinates
zf2 - the z coordinate of the second endpoint, in view coordinates
cam - the camera from which to draw the line
color - the line color

renderWireframe

public void renderWireframe(WireframeMesh mesh,
                            Camera cam,
                            java.awt.Color color)
Render a wireframe object.


renderMeshTransparent

public void renderMeshTransparent(RenderingMesh mesh,
                                  VertexShader shader,
                                  Camera cam,
                                  Vec3 viewDir,
                                  boolean[] hideFace)
Render an object with flat shading in subtractive (transparent) mode.


renderMesh

public void renderMesh(RenderingMesh mesh,
                       VertexShader shader,
                       Camera cam,
                       boolean closed,
                       boolean[] hideFace)
Render a mesh to the canvas.


drawString

public void drawString(java.lang.String text,
                       int x,
                       int y,
                       java.awt.Color color)
Draw a piece of text onto the canvas.


drawImage

public void drawImage(java.awt.Image image,
                      int x,
                      int y)
Draw an image onto the canvas.


renderImage

public void renderImage(java.awt.Image image,
                        Vec3 p1,
                        Vec3 p2,
                        Vec3 p3,
                        Vec3 p4)
Render an image onto the canvas. The image is drawn as a planar rectangle in 3D space, which you specify by its four corners in clockwise order, starting from the top left.

Parameters:
image - the image to render
p1 - the coordinates of the first corner of the image
p2 - the coordinates of the second corner of the image
p3 - the coordinates of the third corner of the image
p4 - the coordinates of the fourth corner of the image

drawShape

public void drawShape(java.awt.Shape shape,
                      java.awt.Color color)
Draw the outline of a Shape into the canvas.


fillShape

public void fillShape(java.awt.Shape shape,
                      java.awt.Color color)
Draw a filled Shape onto the canvas.


isOpenGLAvailable

public static boolean isOpenGLAvailable()
Determine whether OpenGL rendering is available.


getViewerControls

public static java.util.List getViewerControls()
Get the list of ViewerControls which will be added to each new ViewerCanvas.


addViewerControl

public static void addViewerControl(ViewerControl control)
Add a new ViewerControl that will be added to each new ViewerCanvas.

Parameters:
control - the ViewerControl to add

addViewerControl

public static void addViewerControl(int index,
                                    ViewerControl control)
Add a new ViewerControl that will be added to each new ViewerCanvas.

Parameters:
index - the position (from left to right) at which the new control should be added
control - the ViewerControl to add

removeViewerControl

public static void removeViewerControl(ViewerControl control)
Remove a ViewerControl from the list of ones to be added to each new ViewerCanvas.

Parameters:
control - the ViewerControl to remove

getViewerControlWidgets

public java.util.Map getViewerControlWidgets()
Get a Map whose keys are the defined ViewerControls, and whose values are the corresponding Widgets for this canvas.



Copyright © 1999-2011 by Peter Eastman.