jAER project on SourceForge

net.sf.jaer.graphics
Class ChipCanvas

java.lang.Object
  extended by net.sf.jaer.graphics.ChipCanvas
All Implemented Interfaces:
java.util.EventListener, java.util.Observer, javax.media.opengl.GLEventListener
Direct Known Subclasses:
RetinaCanvas

public class ChipCanvas
extends java.lang.Object
implements javax.media.opengl.GLEventListener, java.util.Observer

Superclass for classes that paint rendered AE data to graphics devices.

This is Canvas (AWT component) for rendering retina events. Note this is a heavyweight componnent and doesn't understand Swing layering. Thus care must be taken to ensure Swing components show over it. This component also uses a page-flipping BufferStrategy to eliminate tearing by flipping pages on monitor refresh.

The graphics context is obtained here in the component and its origin is the UL corner of the component when using Java2D rendering, or LL corner if using OpenGL rendering. The context is translated to center the rendering in the Canvas. This canvas can either use Java2D or OpenGL to render, and it can either actively or passively render.

If 3-d event rendering is enabled, the raw events are painted out in space-time, with time axis defined by duration from first to last event in the packet.

If 3-d histogramming is enabled, then the image frame from the ChipRenderer is rendered as a 3-d surface that the user can rotate as desired.

Author:
tobi

Nested Class Summary
 class ChipCanvas.Zoom
          Encapsulates zooming the view
 
Field Summary
protected  AEViewer aeViewer
           
protected  float anglex
           
protected  float angley
           
protected  int BORDER3D
          border in screen pixels when in 3d space-time rendering mode
protected  int colorScale
           
protected  javax.media.opengl.GLCanvas drawable
           
protected  float[][][] fr
          fr is the rendered event data that we draw.
protected  RenderingFrame frameData
           
protected  javax.media.opengl.glu.GLU glu
           
protected  com.sun.opengl.util.GLUT glut
           
protected  java.awt.Insets insets
          Insets of the drawn chip canvas in the window
protected  float j2dScale
           
protected  java.util.logging.Logger log
           
static int MIN_DIMENSION
          defines the minimum canvas size in pixels; used when chip size has not been set to non zero value
protected  boolean openGLEnabled
           
protected  int pheight
           
protected  int[] pixels
           
protected  java.util.prefs.Preferences prefs
           
protected  int pwidth
          width and height of pixel array in canvas in screen pixels.
protected static float SCALE_DEFAULT
          Default scaling from chip pixel to screen pixels
protected static java.awt.Color selectedPixelColor
           
protected  javax.media.opengl.glu.GLUquadric selectedQuad
           
 java.awt.image.BufferStrategy strategy
           
protected  int xt
          the translation of the actual chip drawing area in the canvas, in screen pixels
protected  int yt
          the translation of the actual chip drawing area in the canvas, in screen pixels
protected  boolean zoomMode
           
 
Constructor Summary
ChipCanvas(Chip2D chip)
          Creates a new instance of ChipCanvas
 
Method Summary
 void addDisplayMethod(DisplayMethod m)
          adds a display method to this canvas
 void addGLEventListener(javax.media.opengl.GLEventListener listener)
           
protected  void annotate(javax.media.opengl.GLAutoDrawable drawable)
          First, calls annotate(GLAutoDrawable) for all FrameAnnotators that have been added explicitly to the current DisplayMethod.
protected  void annotate(java.awt.Graphics2D g2)
          Iterates through the FilterChain associated with the AEChip to call all the enabled filter annotations
 void checkGLError(javax.media.opengl.GL g, javax.media.opengl.glu.GLU glu, java.lang.String msg)
          Utility method to check for GL errors.
 void cycleDisplayMethod()
          cycle to the next display method
 void display(javax.media.opengl.GLAutoDrawable drawable)
          opengl calls this when it wants to redraw, and we call it when we actively render.
 void displayChanged(javax.media.opengl.GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged)
           
 float getAnglex()
           
 float getAngley()
           
 int getBorderSpacePixels()
          Returns minimum space around pixel array in screen pixels
 java.awt.Canvas getCanvas()
          The actual drawing surface is a Canvas and this method returns a reference to it.
 Chip2D getChip()
          gets the chip we are rendering for.
 DisplayMethod getCurrentDisplayMethod()
          returns the current display method
 javax.swing.JMenu getDisplayMethodMenu()
           
 java.util.ArrayList<DisplayMethod> getDisplayMethods()
           
 float[][][] getFr()
          Returns the rendered histogram data in case this is what is being rendered
 com.sun.opengl.util.GLUT getGlut()
           
 java.awt.image.BufferedImage getImageOpenGL()
           
 java.awt.Point getMousePixel()
          Finds the current AEChip pixel mouse position.
 float getOrigin3dx()
           
 float getOrigin3dy()
           
protected  java.awt.Color getPixelColor(float red, float green, float blue)
          A utility method that returns an AWT Color from float rgb values
 java.awt.Point getPixelFromMouseEvent(java.awt.event.MouseEvent evt)
          Takes a MouseEvent and returns the AEChip pixel.
 java.awt.Point getPixelFromPoint(java.awt.Point mp)
          Finds the chip pixel from a ChipCanvas point.
protected  int getPixelRGB(float red, float green, float blue)
           
 Chip2DRenderer getRenderer()
           
 float getScale()
          Pixel drawing j2dScale.
 ChipCanvas.Zoom getZoom()
           
 void grabNextImage()
          call this method so that next open gl rendering by display(GLAutoDrawable) writes imageOpenGL
 void init(javax.media.opengl.GLAutoDrawable drawable)
           
protected  void initComponents()
           
 boolean is3DEnabled()
           
 boolean isFillsHorizontally()
          Chip fills drawable horizontally.
 boolean isFillsVertically()
          Chip fills drawable vertically.
 boolean isOpenGLEnabled()
           
 boolean isZoomMode()
           
protected  void paint()
          use to paint with Java2D using BufferStrategy
 void paint(java.awt.Graphics g)
          used for active and passive rendering by Java2D.
 void paintFrame()
          Used for active rendering.
 void removeGLEventListener(javax.media.opengl.GLEventListener listener)
           
 void repaint()
          calls repaint on the drawable
 void repaint(long tm)
          calls repaint on the drawable
 void reshape(javax.media.opengl.GLAutoDrawable drawable, int x, int y, int width, int height)
          Called on reshape of canvas.
protected  java.lang.String scalePrefsKey()
           
protected  void set3dOrigin(int x, int y)
           
 void setAnglex(float anglex)
           
 void setAngley(float angley)
           
 void setBorderSpacePixels(int borderSpacePixels)
          Sets the border around the drawn pixel canvas.
 void setChip(Chip2D chip)
           
protected  void setDefaultProjection(javax.media.opengl.GL g, javax.media.opengl.GLAutoDrawable d)
          Sets the projection matrix so that we get an orthographic projection that is the size of the canvas with z volume -ZCLIP to ZCLIP padded with extra space around the sides.
 void setDisplayMethod(DisplayMethod m)
          sets the display method
protected  void setDisplayMethod(int index)
          sets the current display method to a particular item
 void setDisplayMethod(java.lang.String description)
          sets the display method using the menu name
 void setDisplayMethods(java.util.ArrayList<DisplayMethod> displayMethods)
           
 void setOpenGLEnabled(boolean openGLEnabled)
           
 void setOrigin3dx(float origin3dx)
           
 void setOrigin3dy(float origin3dy)
           
 void setRenderer(Chip2DRenderer renderer)
           
 void setScale(float s)
          This method sets the pixel drawing j2dScale so that e.g.
 void setZoom(ChipCanvas.Zoom zoom)
           
protected  void showSpike(javax.media.opengl.GL gl)
          Shows selected pixel spike count by drawn circle
protected  void showSpike(javax.media.opengl.GL gl, int x, int y, int size)
          draws a circle at pixel x,y of size+.5 radius.
 void unzoom()
           
 void update(java.util.Observable o, java.lang.Object arg)
           
 void zoomIn()
           
 void zoomOut()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

prefs

protected java.util.prefs.Preferences prefs

SCALE_DEFAULT

protected static final float SCALE_DEFAULT
Default scaling from chip pixel to screen pixels

See Also:
Constant Field Values

aeViewer

protected AEViewer aeViewer

anglex

protected float anglex

angley

protected float angley

colorScale

protected final int colorScale
See Also:
Constant Field Values

drawable

protected javax.media.opengl.GLCanvas drawable

fr

protected float[][][] fr
fr is the rendered event data that we draw. X is the first dimenion, Y is the second dimension, RGB 3 vector is the last dimension


frameData

protected RenderingFrame frameData

glu

protected javax.media.opengl.glu.GLU glu

glut

protected com.sun.opengl.util.GLUT glut

log

protected java.util.logging.Logger log

openGLEnabled

protected boolean openGLEnabled

pheight

protected int pheight

pixels

protected int[] pixels

MIN_DIMENSION

public static final int MIN_DIMENSION
defines the minimum canvas size in pixels; used when chip size has not been set to non zero value

See Also:
Constant Field Values

pwidth

protected int pwidth
width and height of pixel array in canvas in screen pixels. these are different than the actual canvas size


j2dScale

protected float j2dScale

selectedPixelColor

protected static final java.awt.Color selectedPixelColor

selectedQuad

protected javax.media.opengl.glu.GLUquadric selectedQuad

strategy

public java.awt.image.BufferStrategy strategy

xt

protected int xt
the translation of the actual chip drawing area in the canvas, in screen pixels


yt

protected int yt
the translation of the actual chip drawing area in the canvas, in screen pixels


zoomMode

protected boolean zoomMode

BORDER3D

protected final int BORDER3D
border in screen pixels when in 3d space-time rendering mode

See Also:
Constant Field Values

insets

protected java.awt.Insets insets
Insets of the drawn chip canvas in the window

Constructor Detail

ChipCanvas

public ChipCanvas(Chip2D chip)
Creates a new instance of ChipCanvas

Method Detail

grabNextImage

public void grabNextImage()
call this method so that next open gl rendering by display(GLAutoDrawable) writes imageOpenGL


getDisplayMethodMenu

public javax.swing.JMenu getDisplayMethodMenu()

addDisplayMethod

public void addDisplayMethod(DisplayMethod m)
adds a display method to this canvas

Parameters:
m - the method

getCurrentDisplayMethod

public DisplayMethod getCurrentDisplayMethod()
returns the current display method

Returns:
the current display method

cycleDisplayMethod

public void cycleDisplayMethod()
cycle to the next display method


setDisplayMethod

public void setDisplayMethod(DisplayMethod m)
sets the display method

Parameters:
m - the method to use

setDisplayMethod

public void setDisplayMethod(java.lang.String description)
sets the display method using the menu name

Parameters:
description - the name

setDisplayMethod

protected void setDisplayMethod(int index)
sets the current display method to a particular item

Parameters:
index - the index of the method in the list of methods

display

public void display(javax.media.opengl.GLAutoDrawable drawable)
opengl calls this when it wants to redraw, and we call it when we actively render.

Specified by:
display in interface javax.media.opengl.GLEventListener
Parameters:
drawable - the surface from which we can get the context with getGL
See Also:
which sets up GL context for display methods

displayChanged

public void displayChanged(javax.media.opengl.GLAutoDrawable drawable,
                           boolean modeChanged,
                           boolean deviceChanged)
Specified by:
displayChanged in interface javax.media.opengl.GLEventListener

getAnglex

public float getAnglex()

getAngley

public float getAngley()

getCanvas

public java.awt.Canvas getCanvas()
The actual drawing surface is a Canvas and this method returns a reference to it.

Returns:
the actual drawing Canvas.

getFr

public float[][][] getFr()
Returns the rendered histogram data in case this is what is being rendered


getScale

public float getScale()
Pixel drawing j2dScale. 1 pixel is rendered to getScale screen pixels.

Returns:
j2dScale in screen pixels/chip pixel.

getPixelColor

protected final java.awt.Color getPixelColor(float red,
                                             float green,
                                             float blue)
A utility method that returns an AWT Color from float rgb values


getPixelFromPoint

public java.awt.Point getPixelFromPoint(java.awt.Point mp)
Finds the chip pixel from a ChipCanvas point. From this forum link.

Parameters:
mp - a Point in ChipCanvas pixels.
Returns:
the AEChip pixel, clipped to the bounds of the AEChip.

getMousePixel

public java.awt.Point getMousePixel()
Finds the current AEChip pixel mouse position.

Returns:
the AEChip pixel, clipped to the bounds of the AEChip

getPixelFromMouseEvent

public java.awt.Point getPixelFromMouseEvent(java.awt.event.MouseEvent evt)
Takes a MouseEvent and returns the AEChip pixel.

Returns:
pixel x,y location (integer point) from MouseEvent. Accounts for scaling and borders of chip display area

getPixelRGB

protected final int getPixelRGB(float red,
                                float green,
                                float blue)

init

public void init(javax.media.opengl.GLAutoDrawable drawable)
Specified by:
init in interface javax.media.opengl.GLEventListener

initComponents

protected void initComponents()

is3DEnabled

public boolean is3DEnabled()

isOpenGLEnabled

public boolean isOpenGLEnabled()

isZoomMode

public boolean isZoomMode()

paint

protected void paint()
use to paint with Java2D using BufferStrategy


paint

public void paint(java.awt.Graphics g)
used for active and passive rendering by Java2D.

Parameters:
g - null to use BufferStrategy graphics (created on demand), non-null to paint to some other rendering context, e.g. an Image that can be written to a file

paintFrame

public void paintFrame()
Used for active rendering. You call this when you want to actively render the frame. Internally, this calls the display() method of the drawable, which by callback to display(GLAutoDrawable). If openGL is disabled, then it calls paint() directly.


removeGLEventListener

public void removeGLEventListener(javax.media.opengl.GLEventListener listener)

repaint

public void repaint()
calls repaint on the drawable


repaint

public void repaint(long tm)
calls repaint on the drawable


reshape

public void reshape(javax.media.opengl.GLAutoDrawable drawable,
                    int x,
                    int y,
                    int width,
                    int height)
Called on reshape of canvas. Determines which way the chip fits into the display area optimally and calls for a new orthographic projection to achieve this filling. Finally sets the viewport to the entire drawable area.

Specified by:
reshape in interface javax.media.opengl.GLEventListener

scalePrefsKey

protected java.lang.String scalePrefsKey()

set3dOrigin

protected void set3dOrigin(int x,
                           int y)

setAnglex

public void setAnglex(float anglex)

setAngley

public void setAngley(float angley)

setOpenGLEnabled

public void setOpenGLEnabled(boolean openGLEnabled)

setDefaultProjection

protected void setDefaultProjection(javax.media.opengl.GL g,
                                    javax.media.opengl.GLAutoDrawable d)
Sets the projection matrix so that we get an orthographic projection that is the size of the canvas with z volume -ZCLIP to ZCLIP padded with extra space around the sides.

Parameters:
g - the GL context
d - the GLAutoDrawable canvas

setScale

public void setScale(float s)
This method sets the pixel drawing j2dScale so that e.g. s=2 means a chip pixel occupies 2 screen pixels. Only used for java2d rendering now.

Parameters:
s - size of chip pixel in screen pixels.

showSpike

protected void showSpike(javax.media.opengl.GL gl)
Shows selected pixel spike count by drawn circle


showSpike

protected void showSpike(javax.media.opengl.GL gl,
                         int x,
                         int y,
                         int size)
draws a circle at pixel x,y of size+.5 radius. size is used to indicate number of spikes in this 'frame'


zoomIn

public void zoomIn()

zoomOut

public void zoomOut()

unzoom

public void unzoom()

update

public void update(java.util.Observable o,
                   java.lang.Object arg)
Specified by:
update in interface java.util.Observer

getRenderer

public Chip2DRenderer getRenderer()

setRenderer

public void setRenderer(Chip2DRenderer renderer)

getDisplayMethods

public java.util.ArrayList<DisplayMethod> getDisplayMethods()

setDisplayMethods

public void setDisplayMethods(java.util.ArrayList<DisplayMethod> displayMethods)

getBorderSpacePixels

public int getBorderSpacePixels()
Returns minimum space around pixel array in screen pixels

Returns:
screen pixel size border

setBorderSpacePixels

public void setBorderSpacePixels(int borderSpacePixels)
Sets the border around the drawn pixel canvas.

Parameters:
borderSpacePixels - in screen pixels.

getZoom

public ChipCanvas.Zoom getZoom()

setZoom

public void setZoom(ChipCanvas.Zoom zoom)

isFillsHorizontally

public boolean isFillsHorizontally()
Chip fills drawable horizontally.

Returns:
the fillsHorizontally

isFillsVertically

public boolean isFillsVertically()
Chip fills drawable vertically.

Returns:
the fillsVertically

addGLEventListener

public void addGLEventListener(javax.media.opengl.GLEventListener listener)

annotate

protected void annotate(javax.media.opengl.GLAutoDrawable drawable)
First, calls annotate(GLAutoDrawable) for all FrameAnnotators that have been added explicitly to the current DisplayMethod. Then it calls annotate on all FilterChain filters with that implement FrameAnnotator and that are enabled for the Chip2D.

Parameters:
drawable - the context

annotate

protected void annotate(java.awt.Graphics2D g2)
Iterates through the FilterChain associated with the AEChip to call all the enabled filter annotations

Parameters:
g2 - the graphics context passed to the EventFilter annotators

checkGLError

public void checkGLError(javax.media.opengl.GL g,
                         javax.media.opengl.glu.GLU glu,
                         java.lang.String msg)
Utility method to check for GL errors. Prints stacked up errors up to a limit.

Parameters:
g - the GL context
glu - the GLU used to obtain the error strings
msg - an error message to log to e.g., show the context

getOrigin3dx

public float getOrigin3dx()

setOrigin3dx

public void setOrigin3dx(float origin3dx)

getOrigin3dy

public float getOrigin3dy()

setOrigin3dy

public void setOrigin3dy(float origin3dy)

getImageOpenGL

public java.awt.image.BufferedImage getImageOpenGL()

getGlut

public com.sun.opengl.util.GLUT getGlut()

getChip

public Chip2D getChip()
gets the chip we are rendering for. Subclasses or display methods can use this to access the chip object.

Returns:
the chip

setChip

public void setChip(Chip2D chip)

jAER project on SourceForge