Main Page   Class Hierarchy   Alphabetical List   Compound List   Compound Members  

prapi::graphics::Graphics< T > Class Template Reference

#include <Graphics.h>

Inheritance diagram for prapi::graphics::Graphics< T >:

Object prapi::graphics::MemoryGraphics< T > List of all members.

Detailed Description

template<class T>
class prapi::graphics::Graphics< T >

Drawing methods.

This is a superclass for classes that are able to draw on various devices. A graphics device must contain a rectangular area of pixels. The upper left corner of the area is used as an origin by default, with the positive y axis running down and the positive x axis to the right. By default, the Graphics class takes care of high-level drawing primitives, and delegates only the setting of pixels to the actual graphics device. It is however possible the override the drawing functions. This way it is possible to create, for example, PostScript graphics etc.

The template parameter T defines the type of a pixel in the graphics context. In a memory buffer, pixels may be represented as chars or ints. For color graphics, the type may be Color.


Public Methods

void setDrawMode (DrawMode mode)
 Set the drawing mode.

DrawMode getDrawMode () const
 Get the current drawing mode.

void setColor (T color)
 Set the current drawing "color" to a value.

getColor () const
 Get the current drawing color.

void setOpacity (double opacity)
 Set the opacity of the drawing operations.

double getOpacity ()
 Get the current opacity.

void translate (int x, int y)
 Shift the origin of this graphics context to the given coordinates.

Point< int > getOrigin () const
 Get the current origin of the coordinate system.

void setClip (const Shape *shape)
 Set the clipping region.

void drawPixel (int x, int y)
 Set a pixel in a graphics context with no interpolation (anti-aliasing).

virtual void drawPixel (double x, double y)
 Draw a pixel in a graphics context.

template<class modifier> void modifyPixel (double x, double y)
 Modify a pixel.

template<class modifier> void modifyPixel (int x, int y)
 Modify a pixel in an image without interpolation (anti-aliasing).

virtual void drawCircle (double centerX, double centerY, double radius)
 Draw an anti-alised circle.

virtual void drawArc (double centerX, double centerY, double radius, double startAngle, double endAngle)
 Draw an anti-alised arc.

virtual void drawLine (double startX, double startY, double endX, double endY)
 Draw an interpolated (anti-aliased) line.

virtual void drawLine (int startX, int startY, int endX, int endY)
 Draw a non-interpolated line.

virtual void drawRect (int x, int y, int width, int height)
 Draw a rectangle with non-interpolated borders.

virtual void drawRect (double x, double y, double width, double height)
 Draw a rectangle with interpolated (anti-alised) borders.

virtual ~Graphics ()

Protected Methods

 Graphics (int width=0, int height=0)
 Create a new graphics context.

virtual T getPixel (int x, int y) const=0
 Get a pixel in a graphics context.

virtual T & pixel (int x, int y)=0
 Get a pixel in a graphics context.

virtual void setPixel (int x, int y, T value)=0
 Set a pixel in a graphics context.


Protected Attributes

Dimension< int > _dimBounds
 The dimensions of the graphics context.

int _iOriginX
 The coordinates of the current origin.

int _iOriginY
 The coordinates of the current origin.

const Shape_pClipShape
 The current clipping region.

_color
 The current drawing color.

double _dOpacity
 The current opacity.

DrawMode _drawMode
 The current drawing mode.


Constructor & Destructor Documentation

template<class T>
prapi::graphics::Graphics< T >::Graphics int    width = 0,
int    height = 0
[inline, protected]
 

Create a new graphics context.

Subclasses should provide the bounds of their device/buffer at initialization.

Parameters:
width  the width of the graphics buffer
height  the height of the graphics buffer


Member Function Documentation

template<class T>
void prapi::graphics::Graphics< T >::drawArc double    centerX,
double    centerY,
double    radius,
double    startAngle,
double    endAngle
[virtual]
 

Draw an anti-alised arc.

Angles are represented as radians in counter-clockwise direction. Zero angle is at the direction of the horizontal x-axis.

Parameters:
centerX  the x coordinate of the center of the circle
centerY  the y coordinate of the center of the circle
radius  the radius of the circle

template<class T>
void prapi::graphics::Graphics< T >::drawCircle double    centerX,
double    centerY,
double    radius
[virtual]
 

Draw an anti-alised circle.

Parameters:
centerX  the x coordinate of the center of the circle
centerY  the y coordinate of the center of the circle
radius  the radius of the circle

template<class T>
void prapi::graphics::Graphics< T >::drawLine int    startX,
int    startY,
int    endX,
int    endY
[virtual]
 

Draw a non-interpolated line.

Parameters:
startX  the x coordinate of the starting position
startY  the y coordinate of the starting position
endX  the x coordinate of the end position
endY  the y coordinate of the end position

template<class T>
void prapi::graphics::Graphics< T >::drawLine double    startX,
double    startY,
double    endX,
double    endY
[virtual]
 

Draw an interpolated (anti-aliased) line.

Parameters:
startX  the x coordinate of the starting position
startY  the y coordinate of the starting position
endX  the x coordinate of the end position
endY  the y coordinate of the end position

template<class T>
void prapi::graphics::Graphics< T >::drawPixel double    x,
double    y
[virtual]
 

Draw a pixel in a graphics context.

This method uses bilinear interpolation to draw anti-aliased pixels. Up to four neighboring pixels closest to the given floating-point image coordinates may be affected.

Parameters:
x  the x coordinate
y  the y coordinate

template<class T>
void prapi::graphics::Graphics< T >::drawPixel int    x,
int    y
[inline]
 

Set a pixel in a graphics context with no interpolation (anti-aliasing).

It is not possible to override this method. Instead, subclasses should override the protected get/setPixel() methods.

Parameters:
x  the x coordinate
y  the y coordinate

template<class T>
virtual void prapi::graphics::Graphics< T >::drawRect double    x,
double    y,
double    width,
double    height
[inline, virtual]
 

Draw a rectangle with interpolated (anti-alised) borders.

Parameters:
x  the x coordinate of the upper left corner
y  the y coordinate of the upper left corner
width  the width of the rectangle
height  the height of the rectangle

template<class T>
virtual void prapi::graphics::Graphics< T >::drawRect int    x,
int    y,
int    width,
int    height
[inline, virtual]
 

Draw a rectangle with non-interpolated borders.

Parameters:
x  the x coordinate of the upper left corner
y  the y coordinate of the upper left corner
width  the width of the rectangle
height  the height of the rectangle

template<class T>
virtual T prapi::graphics::Graphics< T >::getPixel int    x,
int    y
const [protected, pure virtual]
 

Get a pixel in a graphics context.

Subclasses must implement this method to get the contents of the graphics device/buffer. Boundary checking has been done before calling this method. Thus, assuming _dimBounds has been set correctly, subclasses never need to check whether the given coordinates are within the allowed range.

Implemented in prapi::graphics::MemoryGraphics< T >.

template<class T>
template<class modifier>
void prapi::graphics::Graphics< T >::modifyPixel int    x,
int    y
[inline]
 

Modify a pixel in an image without interpolation (anti-aliasing).

See also:
modifyPixel(double,double) , drawPixel(int,int)

template<class T>
template<class modifier>
void prapi::graphics::Graphics< T >::modifyPixel double    x,
double    y
[inline]
 

Modify a pixel.

This method works in a similar way as drawPixel(), but instead of overwriting a pixel it modifies the old value. The current opacity is used to control the "strength" of the modification. 0 means no change, and 1 means the old value will be modified with exactly the given value. The current drawing mode does not affect pixel modifications. Therefore, this method allows one to alter the pixel data in many customized ways. The modifier template parameter can be any class with the T operator() (T,T) defined. An example:

 class MyModifier
 {
 public:
   int operator() (int a, int b) { return b-a; }
 };
 ...
 //Subtract the value of the pixel at (2.3, 3.5) from three (with anti-aliasing)
 graphics.setColor(3);
 graphics.modifyPixel<MyModifier>(2.3, 3.5);

 //Subtract the value of the pixel at (3, 4) from two (without anti-aliasing)
 graphics.setColor(4);
 graphics.setOpacity(0.5);
 graphics.modifyPixel<MyModifier>(3,4);
 

template<class T>
virtual T& prapi::graphics::Graphics< T >::pixel int    x,
int    y
[protected, pure virtual]
 

Get a pixel in a graphics context.

Subclasses must implement this method to get the contents of the graphics device/buffer. Boundary checking has been done before calling this method. Thus, assuming _dimBounds has been set correctly, subclasses never need to check whether the given coordinates are within the allowed range.

Implemented in prapi::graphics::MemoryGraphics< T >.

template<class T>
void prapi::graphics::Graphics< T >::setClip const Shape   shape [inline]
 

Set the clipping region.

The clipping region determines the drawable area in a graphics context. All graphics primitives that fall outside of the clipping region, as determined by the Shape::contains(x,y) method, are not drawn. The clipping region is always interpreted relative to the current origin of the coordinate system. That is, moving the origin also moves the clipping region.

template<class T>
void prapi::graphics::Graphics< T >::setColor   color [inline]
 

Set the current drawing "color" to a value.

All subsequent drawing operations will use this color. For gray-scale graphics, for example integer valued memory buffers, the "color" is actually a scalar.

template<class T>
void prapi::graphics::Graphics< T >::setDrawMode DrawMode    mode [inline]
 

Set the drawing mode.

All subsequent drawing operations will be performed in the indicated mode.

template<class T>
void prapi::graphics::Graphics< T >::setOpacity double    opacity [inline]
 

Set the opacity of the drawing operations.

Opacity determines how much newly drawn pixels affect those under it. If opacity is set to one, the old pixel value is totally overwritten. If opacity is set to zero, drawing operations have no visible effect. The default value is one.

template<class T>
virtual void prapi::graphics::Graphics< T >::setPixel int    x,
int    y,
  value
[protected, pure virtual]
 

Set a pixel in a graphics context.

Subclasses must implement this method to alter the graphics device/buffer. Boundary checking has been done before calling this method. Thus, assuming _dimBounds has been set correctly, subclasses never need to check whether the given coordinates are within the allowed range.

Implemented in prapi::graphics::MemoryGraphics< T >.

template<class T>
void prapi::graphics::Graphics< T >::translate int    x,
int    y
[inline]
 

Shift the origin of this graphics context to the given coordinates.

The coordinates of all subsequent drawing operations will be interpreted relative to this position. The origin can lie outside of the boundaried of the graphics context. An example:

 //To move the origin to (30,20):
 graphics.translate(30,20);
 //To move the origin back:
 graphics.translate(-30,-20);
 

In addition to the origin, this method also moves the current clipping region.


Member Data Documentation

template<class T>
T prapi::graphics::Graphics< T >::_color [protected]
 

The current drawing color.

Set initially to zero.

template<class T>
Dimension<int> prapi::graphics::Graphics< T >::_dimBounds [protected]
 

The dimensions of the graphics context.

Subclasses must fill this class with the dimensions of the graphics device/buffer.

template<class T>
double prapi::graphics::Graphics< T >::_dOpacity [protected]
 

The current opacity.

Initially set to one.

template<class T>
DrawMode prapi::graphics::Graphics< T >::_drawMode [protected]
 

The current drawing mode.

Set initially to DRAWMODE_NORMAL.


The documentation for this class was generated from the following file:
Documentation generated on 11.09.2003 with Doxygen.
The documentation is copyrighted material.
Copyright © Topi Mäenpää 2003. All rights reserved.