Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

Graphics Class Reference

#include <Graphics.h>

List of all members.


Detailed Description

Provides basic graphics capabilities for drawing into any bitmap, particularly FilterBankGenerators.

Wherever possible, this should try to emulate the graphics API of Java 1 to minimize learning curve. For instance, the pen hangs down and to the right.

Definition at line 10 of file Graphics.h.


Public Member Functions

 Graphics (FilterBankGenerator &fbg, unsigned int layer, unsigned int channel)
 constructor, pass a FilterBankGenerator and layer/channel to draw into
 Graphics (unsigned char *base, unsigned int width, unsigned int height, unsigned int interval, unsigned int stride)
 constructor, directly specify an image buffer
void updateFBG ()
 If you want to reuse a graphics object across multiple frames from a FilterBankGenerator, call this after each new frame, but before you do any drawing.
void drawRect (int x, int y, int width, int height)
 Draws a rectange, upper left at x,y and extending right and down by width and height.
void drawRect (float x, float y, float width, float height)
 Draws a rectange, upper left at x,y and extending right and down by width and height.
void drawLine (int x1, int y1, int x2, int y2)
 Draws a line from (x1, y1) to (x2, y2).
void drawLine (float x1, float y1, float x2, float y2)
 Draws a line from (x1, y1) to (x2, y2).
void drawPoint (int x, int y)
 Draws a single point at (x1, y1).
void drawPoint (float x, float y)
 Draws a single point at (x1, y1).
void setColor (char color)
 Sets the "color" of the pen.
char getColor () const
 returns the "color" of the pen
void getPixelCoordinates (unsigned int &px, unsigned int &py, float x, float y) const
 sets the pixel-coordinate px and py parameters to the corresponding value of x and y
void getRealCoordinates (float &x, float &y, unsigned int px, unsigned int py) const
 sets the x and y parameters from the pixel-coordinates px and py

Protected Attributes

FilterBankGeneratorgen
 the filter bank generator we are drawing into, or NULL
unsigned int genLayer
 the layer within gen we are drawing into
unsigned int genChan
 the channel within gen we are drawing into
unsigned char * img
 the image we are currently drawing into (may need to be updated if gen is non-NULL, see updateFBG())
unsigned int w
 the width of img
unsigned int h
 the height of img
unsigned int xInc
 the number of bytes to skip to move horizontally one pixel in img
unsigned int yInc
 the number of bytes to skip to move vertically one pixel in img
unsigned char c
 the current pen color

Private Member Functions

 Graphics (const Graphics &)
 don't call (copy constructor)
Graphicsoperator= (const Graphics &)
 don't call (assignment operator)

Constructor & Destructor Documentation

Graphics::Graphics ( FilterBankGenerator fbg,
unsigned int  layer,
unsigned int  channel 
)

constructor, pass a FilterBankGenerator and layer/channel to draw into

Definition at line 19 of file Graphics.cc.

Graphics::Graphics ( unsigned char *  base,
unsigned int  width,
unsigned int  height,
unsigned int  interval,
unsigned int  stride 
)

constructor, directly specify an image buffer

Definition at line 25 of file Graphics.cc.

Graphics::Graphics ( const Graphics  )  [private]

don't call (copy constructor)


Member Function Documentation

void Graphics::updateFBG (  ) 

If you want to reuse a graphics object across multiple frames from a FilterBankGenerator, call this after each new frame, but before you do any drawing.

This is automatically called by the constructor, so you don't need to do it if you constructor a fresh Graphics object for each frame. But otherwise you'll need this to update img, w, h, xInc, and yInc from the current frame available in gen

Definition at line 29 of file Graphics.cc.

Referenced by Graphics().

void Graphics::drawRect ( int  x,
int  y,
int  width,
int  height 
)

Draws a rectange, upper left at x,y and extending right and down by width and height.

This expects direct-pixel coordinates, so make sure you check the width and height of the layer you are drawing into

Definition at line 39 of file Graphics.cc.

Referenced by drawRect().

void Graphics::drawRect ( float  x,
float  y,
float  width,
float  height 
)

Draws a rectange, upper left at x,y and extending right and down by width and height.

Definition at line 106 of file Graphics.cc.

void Graphics::drawLine ( int  ix1,
int  iy1,
int  ix2,
int  iy2 
)

Draws a line from (x1, y1) to (x2, y2).

This expects direct-pixel coordinates, so make sure you check the width and height of the layer you are drawing into

Todo:
I think this could be a little faster by writing two cases -- one that handles mostly-vertical lines, and one that handles mostly-horizontal ones. Then the primary loop could be over integer coordinates along that axis, and only the position along the other axis would have to be calculated as floating point

Definition at line 118 of file Graphics.cc.

Referenced by drawLine().

void Graphics::drawLine ( float  x1,
float  y1,
float  x2,
float  y2 
)

Draws a line from (x1, y1) to (x2, y2).

Definition at line 209 of file Graphics.cc.

void Graphics::drawPoint ( int  x,
int  y 
) [inline]

Draws a single point at (x1, y1).

This expects direct-pixel coordinates, so make sure you check the width and height of the layer you are drawing into

Definition at line 44 of file Graphics.h.

Referenced by drawPoint().

void Graphics::drawPoint ( float  x,
float  y 
) [inline]

Draws a single point at (x1, y1).

Definition at line 52 of file Graphics.h.

void Graphics::setColor ( char  color  )  [inline]

Sets the "color" of the pen.

Currently we don't support multi-channel drawing, so you have to draw into each channel separately to do real color based drawing, but maybe someday we'll add a color class.
In the mean time, this is just the byte that's going to be used to fill in wherever the pen traces

Definition at line 64 of file Graphics.h.

char Graphics::getColor (  )  const [inline]

returns the "color" of the pen

Currently we don't support multi-channel drawing, so you have to draw into each channel separately to do real color based drawing, but maybe someday we'll add a color class.
In the mean time, this is just the byte that's going to be used to fill in wherever the pen traces

Definition at line 71 of file Graphics.h.

void Graphics::getPixelCoordinates ( unsigned int &  px,
unsigned int &  py,
float  x,
float  y 
) const

sets the pixel-coordinate px and py parameters to the corresponding value of x and y

Parameters:
[out] px the pixel position, relative to left edge, positive right, ranges 0 through width-1
[out] py the pixel position, relative to top edge, positive down, ranges 0 through height-1
[in] x the horizontal position, relative to center of the image, left edge is -1 and right edge is 1; no boundary checking is done
[in] y the vertical pixel position, relative to center of the image, top edge is the negative aspect ratio, bottom edge is positive aspect ratio; no boundary checking is done
To keep the coordinate system square, the x is defined to range -1,1, but y's range depends on the aspect ratio of the image, height/width. Thus typically y will approx. -.75,.75

Definition at line 216 of file Graphics.cc.

Referenced by drawLine(), drawPoint(), and drawRect().

void Graphics::getRealCoordinates ( float &  x,
float &  y,
unsigned int  px,
unsigned int  py 
) const

sets the x and y parameters from the pixel-coordinates px and py

Parameters:
[out] x the horizontal position, relative to center of the image, left edge is -1 and right edge is 1; no boundary checking is done
[out] y the vertical pixel position, relative to center of the image, top edge is the negative aspect ratio, bottom edge is positive aspect ratio; no boundary checking is done
[in] px the pixel position, relative to left edge, positive right, ranges 0 through width-1
[in] py the pixel position, relative to top edge, positive down, ranges 0 through height-1
To keep the coordinate system square, the x is defined to range -1,1, but y's range depends on the aspect ratio of the image, height/width. Thus typically y will approx. -.75,.75

Definition at line 227 of file Graphics.cc.

Graphics& Graphics::operator= ( const Graphics  )  [private]

don't call (assignment operator)


Member Data Documentation

the filter bank generator we are drawing into, or NULL

Definition at line 94 of file Graphics.h.

Referenced by getPixelCoordinates(), getRealCoordinates(), and updateFBG().

unsigned int Graphics::genLayer [protected]

the layer within gen we are drawing into

Definition at line 95 of file Graphics.h.

Referenced by getPixelCoordinates(), getRealCoordinates(), and updateFBG().

unsigned int Graphics::genChan [protected]

the channel within gen we are drawing into

Definition at line 96 of file Graphics.h.

Referenced by updateFBG().

unsigned char* Graphics::img [protected]

the image we are currently drawing into (may need to be updated if gen is non-NULL, see updateFBG())

Definition at line 98 of file Graphics.h.

Referenced by drawLine(), drawPoint(), drawRect(), and updateFBG().

unsigned int Graphics::w [protected]

the width of img

Definition at line 99 of file Graphics.h.

Referenced by drawLine(), drawPoint(), drawRect(), getPixelCoordinates(), getRealCoordinates(), and updateFBG().

unsigned int Graphics::h [protected]

the height of img

Definition at line 100 of file Graphics.h.

Referenced by drawLine(), drawPoint(), drawRect(), getPixelCoordinates(), getRealCoordinates(), and updateFBG().

unsigned int Graphics::xInc [protected]

the number of bytes to skip to move horizontally one pixel in img

Definition at line 101 of file Graphics.h.

Referenced by drawLine(), drawPoint(), drawRect(), and updateFBG().

unsigned int Graphics::yInc [protected]

the number of bytes to skip to move vertically one pixel in img

Definition at line 102 of file Graphics.h.

Referenced by drawLine(), drawPoint(), drawRect(), and updateFBG().

unsigned char Graphics::c [protected]

the current pen color

Definition at line 104 of file Graphics.h.

Referenced by drawLine(), drawPoint(), drawRect(), getColor(), and setColor().


The documentation for this class was generated from the following files:

Tekkotsu v4.0
Generated Thu Nov 22 00:58:25 2007 by Doxygen 1.5.4