Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

Draw Class Reference

A very simple drawing environment, originally to visualize planner stuff. More...

#include <Draw.h>


Detailed Description

A very simple drawing environment, originally to visualize planner stuff.

Default origin is in the lower left corner, positive x and y to the right and up

Definition at line 12 of file Draw.h.

List of all members.

Public Types

enum  Colors {
  BLACK, DK_GRAY, GRAY, LT_GRAY,
  WHITE, RED, YELLOW, GREEN,
  CYAN, BLUE, MAGENTA
}
 

Convenient color constants.

More...
enum  PointStyles { CIRCLE, SQUARE, DIAMOND }
 

Provides different point() styles.

More...

Public Member Functions

 Draw ()
 Default constructor, must still call setFile() before any drawing commands.
 Draw (const std::string &file, double width, double height)
 Constructor, sets up output.
 ~Draw ()
 Destructor.
DrawsetFile (const std::string &file, double width, double height)
 This must be called to setup output destination before calling any drawing commands.
DrawflushPage ()
 Writes the current page and starts a new one.
DrawsetOrigin (const fmat::Column< 2 > &p)
 Moves the origin (lower left corner).
DrawsetOrigin (double x, double y)
 Moves the origin (lower left corner).
DrawcenterView (const fmat::Column< 2 > &p)
 Moves the origin in order to center the viewport on the specified point.
DrawcenterView (double x, double y)
 Moves the origin in order to center the viewport on the specified point.
DrawsetClip ()
 Clips further drawing to the current path area.
DrawclearClip ()
 Clears the clipping region.
DrawsetScale (double x, bool scaleStroke=false)
 Changes the scaling factor, to display more or less within the bounds given to setFile().
double displayToScaled (double x) const
 Converts from display units to scaled coordinates.
double scaledToDisplay (double x) const
 Converts from scaled coordinates to display units.
DrawsetRegion (const BoundingBox2D &region, bool scaleStroke=false)
 Changes scale and origin to fit the specified drawing region to the output.
DrawdrawGrid (double xRes, double yRes, double xOff=0, double yOff=0)
 Draws a grid of the specified horizontal and vertical resolution across the visible region (doesn't stroke).
DrawdrawAxes ()
 Draws the axes across the visible region (doesn't stroke).
DrawsetStrokeWidth (double x)
 Sets the stroke width using output dimension units, i.e. scale factor invariant.
DrawsetScaledStrokeWidth (double x)
 Sets the stroke width using coordinate-space units, i.e. relative to scale factor.
double getStrokeWidth () const
 Returns the stroke width in output dimension units.
double getScaledStrokeWidth () const
 Returns the stroke width in coordinate-space units.
DrawsetColorRGB (double red, double green, double blue, double alpha=1)
 Sets the color for future drawing operations.
DrawsetColorGray (double x, double alpha=1)
 Sets the color for future drawing operations.
DrawsetColor (Colors c, double alpha=1)
 Sets the color for future drawing operations.
Drawstroke ()
 Outline the current path.
Drawstroke (Colors c, double alpha=1)
 Outline the current path with specified color.
Drawstroke (double red, double green, double blue, double alpha=1)
 Outline the current path with specified color.
DrawstrokeLine (const fmat::Column< 2 > &p1, const fmat::Column< 2 > &p2)
 Stroke a single line; if drawing a polygon, better to use lineTo and stroke as a batch.
DrawstrokeLine (double x1, double y1, double x2, double y2)
 Stroke a single line; if drawing a polygon, better to use lineTo and stroke as a batch.
Drawfill ()
 Paint the current path.
Drawfill (Colors c, double alpha=1)
 Paint the current path with specified color.
Drawfill (double red, double green, double blue, double alpha=1)
 Paint the current path with specified color.
Drawpoint (const fmat::Column< 2 > &p, double size, PointStyles style=CIRCLE)
 Produces a output-dimension (i.e. unscaled) symbol at the specified point (follow up with fill() and/or stroke()).
Drawpoint (double x, double y, double size, PointStyles style=CIRCLE)
 Produces a output-dimension (i.e. unscaled) symbol at the specified point (follow up with fill() and/or stroke()).
Drawarc (const fmat::Column< 2 > &p, double r, double begin, double end)
 Produces an arc of the specified range.
Drawarc (double x, double y, double r, double begin, double end)
 Produces an arc of the specified range.
Drawcircle (const fmat::Column< 2 > &c, double r)
 Produces a closed path for a circle at the specified point.
Drawcircle (double x, double y, double r)
 Produces a closed path for a circle at the specified point.
Drawellipse (const fmat::Column< 2 > &c, double width, double height, double orientation=0)
 Produces an ellipse, note width and height, not major/minor.
Drawrect (const BoundingBox2D &r)
 Produces a closed path for an axis-aligned rectangle.
Drawrect (const fmat::Column< 2 > &p1, const fmat::Column< 2 > &p2)
 Produces a closed path for an axis-aligned rectangle between the specified points.
Drawarrow (const fmat::Column< 2 > &p1, const fmat::Column< 2 > &p2, double headWidth=2, double headLength=5)
 Draws a line between points with an arrowhead at p2, the headWidth and headLength are multiples of the stroke width.
Drawdraw (const PlannerObstacle2D &o)
 Produces a closed path for a planner obstacle.
Drawdraw (const RectangularObstacle &o)
 Produces a closed path for a planner obstacle.
Drawdraw (const CircularObstacle &o)
 Produces a closed path for a planner obstacle.
Drawdraw (const EllipticalObstacle &o)
 Produces a closed path for a planner obstacle.
Drawdraw (const ConvexPolyObstacle &o)
 Produces a closed path for a planner obstacle.
Drawdraw (const HierarchicalObstacle &o)
 Produces a closed path for a planner obstacle.
DrawmoveTo (const fmat::Column< 2 > &p)
 Set the pen location without adding a line segment to the current path.
DrawmoveTo (double x, double y)
 Set the pen location without adding a line segment to the current path.
DrawlineTo (const fmat::Column< 2 > &p)
 Add a line segment to the current path.
DrawlineTo (double x, double y)
 Add a line segment to the current path.
DrawarcTo (const fmat::Column< 2 > &p, double r, double begin, double end)
 Produces an arc of the specified range (continuing the current path).
DrawarcTo (double x, double y, double r, double begin, double end)
 Produces an arc of the specified range (continuing the current path).
DrawclosePath ()
 Add a line segment back to the last moveTo location.
DrawholdPath (bool continuePath=false)
 Clears path unless continuePath is set, additional paths will be collected together until releasePath() is called.
DrawreleasePath ()
 Clears the hold flag from holdPath(), but does not actually clear the path.
bool getHoldMode () const
 Returns current hold setting.
DrawclearPath ()
 Erase current path, but does not reset holdPath() mode.

Protected Member Functions

void teardown ()
 Flush pending output and release resources.
void resetTransform ()
 Recomputes and applies the surface transform.
void checkSurfaceStatus (const std::string &msg)
 Throws an exception if surface status is not success.
void checkStatus (const std::string &msg)
 Throws an exception if either cairo or surface status is not success.

Protected Attributes

cairo_tcr
cairo_surface_tsurface
std::string filename
fmat::Column< 2 > origin
double scale
double surfaceWidth
double surfaceHeight
bool addPath
 Indicates state of holdPath()/releasePath(), if true the path isn't cleared between draw calls.

Private Member Functions

 Draw (const Draw &o)
 Do not call.
Drawoperator= (const Draw &o)
 Do not call.

Member Enumeration Documentation

Convenient color constants.

Enumerator:
BLACK 
DK_GRAY 
GRAY 
LT_GRAY 
WHITE 
RED 
YELLOW 
GREEN 
CYAN 
BLUE 
MAGENTA 

Definition at line 70 of file Draw.h.

Provides different point() styles.

Enumerator:
CIRCLE 
SQUARE 
DIAMOND 

Definition at line 102 of file Draw.h.


Constructor & Destructor Documentation

Draw::Draw (  ) 

Default constructor, must still call setFile() before any drawing commands.

Definition at line 15 of file Draw.h.

Draw::Draw ( const std::string &  file,
double  width,
double  height 
)

Constructor, sets up output.

Definition at line 19 of file Draw.h.

Draw::~Draw (  ) 

Destructor.

Definition at line 23 of file Draw.h.

Draw::Draw ( const Draw o  )  [private]

Do not call.


Member Function Documentation

Draw & Draw::arc ( double  x,
double  y,
double  r,
double  begin,
double  end 
)

Produces an arc of the specified range.

Definition at line 78 of file Draw.cc.

Draw& Draw::arc ( const fmat::Column< 2 > &  p,
double  r,
double  begin,
double  end 
)

Produces an arc of the specified range.

Definition at line 112 of file Draw.h.

Referenced by arc(), and circle().

Draw & Draw::arcTo ( double  x,
double  y,
double  r,
double  begin,
double  end 
)

Produces an arc of the specified range (continuing the current path).

Definition at line 90 of file Draw.cc.

Draw& Draw::arcTo ( const fmat::Column< 2 > &  p,
double  r,
double  begin,
double  end 
)

Produces an arc of the specified range (continuing the current path).

Definition at line 159 of file Draw.h.

Referenced by arcTo().

Draw & Draw::arrow ( const fmat::Column< 2 > &  p1,
const fmat::Column< 2 > &  p2,
double  headWidth = 2,
double  headLength = 5 
)

Draws a line between points with an arrowhead at p2, the headWidth and headLength are multiples of the stroke width.

You can stroke to get a barbed head, or fill to get a little triangle. For a really perfect filled arrowhead, call closePath() first to avoid a little bit of mitred corners sticking out.

Definition at line 81 of file Draw.cc.

Draw & Draw::centerView ( double  x,
double  y 
)

Moves the origin in order to center the viewport on the specified point.

Definition at line 70 of file Draw.cc.

Draw& Draw::centerView ( const fmat::Column< 2 > &  p  ) 

Moves the origin in order to center the viewport on the specified point.

Definition at line 36 of file Draw.h.

Referenced by centerView(), and setRegion().

void Draw::checkStatus ( const std::string &  msg  )  [protected]

Throws an exception if either cairo or surface status is not success.

Definition at line 95 of file Draw.cc.

void Draw::checkSurfaceStatus ( const std::string &  msg  )  [protected]

Throws an exception if surface status is not success.

Definition at line 94 of file Draw.cc.

Draw& Draw::circle ( double  x,
double  y,
double  r 
)

Produces a closed path for a circle at the specified point.

Definition at line 119 of file Draw.h.

Draw& Draw::circle ( const fmat::Column< 2 > &  c,
double  r 
)

Produces a closed path for a circle at the specified point.

Definition at line 117 of file Draw.h.

Draw & Draw::clearClip (  ) 

Clears the clipping region.

Definition at line 72 of file Draw.cc.

Draw & Draw::clearPath (  ) 

Erase current path, but does not reset holdPath() mode.

Definition at line 92 of file Draw.cc.

Referenced by holdPath().

Draw & Draw::closePath (  ) 

Add a line segment back to the last moveTo location.

Definition at line 91 of file Draw.cc.

double Draw::displayToScaled ( double  x  )  const

Converts from display units to scaled coordinates.

Definition at line 49 of file Draw.h.

Draw & Draw::draw ( const HierarchicalObstacle o  ) 

Produces a closed path for a planner obstacle.

Definition at line 87 of file Draw.cc.

Draw & Draw::draw ( const ConvexPolyObstacle o  ) 

Produces a closed path for a planner obstacle.

Definition at line 86 of file Draw.cc.

Draw & Draw::draw ( const EllipticalObstacle o  ) 

Produces a closed path for a planner obstacle.

Definition at line 85 of file Draw.cc.

Draw & Draw::draw ( const CircularObstacle o  ) 

Produces a closed path for a planner obstacle.

Definition at line 84 of file Draw.cc.

Draw & Draw::draw ( const RectangularObstacle o  ) 

Produces a closed path for a planner obstacle.

Definition at line 83 of file Draw.cc.

Draw & Draw::draw ( const PlannerObstacle2D o  ) 

Produces a closed path for a planner obstacle.

Definition at line 82 of file Draw.cc.

Draw & Draw::drawAxes (  ) 

Draws the axes across the visible region (doesn't stroke).

Definition at line 63 of file Draw.cc.

Draw & Draw::drawGrid ( double  xRes,
double  yRes,
double  xOff = 0,
double  yOff = 0 
)

Draws a grid of the specified horizontal and vertical resolution across the visible region (doesn't stroke).

Definition at line 62 of file Draw.cc.

Draw & Draw::ellipse ( const fmat::Column< 2 > &  c,
double  width,
double  height,
double  orientation = 0 
)

Produces an ellipse, note width and height, not major/minor.

Definition at line 79 of file Draw.cc.

Draw& Draw::fill ( double  red,
double  green,
double  blue,
double  alpha = 1 
)

Paint the current path with specified color.

Definition at line 98 of file Draw.h.

Draw& Draw::fill ( Colors  c,
double  alpha = 1 
)

Paint the current path with specified color.

Definition at line 96 of file Draw.h.

Draw & Draw::fill (  ) 

Paint the current path.

Definition at line 76 of file Draw.cc.

Referenced by fill().

Draw & Draw::flushPage (  ) 

Writes the current page and starts a new one.

Definition at line 69 of file Draw.cc.

bool Draw::getHoldMode (  )  const

Returns current hold setting.

Definition at line 171 of file Draw.h.

double Draw::getScaledStrokeWidth (  )  const

Returns the stroke width in coordinate-space units.

Definition at line 66 of file Draw.cc.

Referenced by getStrokeWidth().

double Draw::getStrokeWidth (  )  const

Returns the stroke width in output dimension units.

Definition at line 65 of file Draw.h.

Draw& Draw::holdPath ( bool  continuePath = false  ) 

Clears path unless continuePath is set, additional paths will be collected together until releasePath() is called.

Definition at line 167 of file Draw.h.

Draw & Draw::lineTo ( double  x,
double  y 
)

Add a line segment to the current path.

Definition at line 89 of file Draw.cc.

Draw& Draw::lineTo ( const fmat::Column< 2 > &  p  ) 

Add a line segment to the current path.

Definition at line 154 of file Draw.h.

Referenced by lineTo().

Draw & Draw::moveTo ( double  x,
double  y 
)

Set the pen location without adding a line segment to the current path.

Clears previous path unless holdPath() has been called.

Definition at line 88 of file Draw.cc.

Draw& Draw::moveTo ( const fmat::Column< 2 > &  p  ) 

Set the pen location without adding a line segment to the current path.

Definition at line 148 of file Draw.h.

Referenced by moveTo().

Draw& Draw::operator= ( const Draw o  )  [private]

Do not call.

Draw & Draw::point ( double  x,
double  y,
double  size,
PointStyles  style = CIRCLE 
)

Produces a output-dimension (i.e. unscaled) symbol at the specified point (follow up with fill() and/or stroke()).

Definition at line 77 of file Draw.cc.

Draw& Draw::point ( const fmat::Column< 2 > &  p,
double  size,
PointStyles  style = CIRCLE 
)

Produces a output-dimension (i.e. unscaled) symbol at the specified point (follow up with fill() and/or stroke()).

Definition at line 107 of file Draw.h.

Referenced by point().

Draw & Draw::rect ( const fmat::Column< 2 > &  p1,
const fmat::Column< 2 > &  p2 
)

Produces a closed path for an axis-aligned rectangle between the specified points.

Definition at line 80 of file Draw.cc.

Draw& Draw::rect ( const BoundingBox2D r  ) 

Produces a closed path for an axis-aligned rectangle.

Definition at line 125 of file Draw.h.

Referenced by rect().

Draw& Draw::releasePath (  ) 

Clears the hold flag from holdPath(), but does not actually clear the path.

Definition at line 169 of file Draw.h.

void Draw::resetTransform (  )  [protected]

Recomputes and applies the surface transform.

Definition at line 93 of file Draw.cc.

Referenced by setOrigin().

double Draw::scaledToDisplay ( double  x  )  const

Converts from scaled coordinates to display units.

Definition at line 51 of file Draw.h.

Draw & Draw::setClip (  ) 

Clips further drawing to the current path area.

Definition at line 71 of file Draw.cc.

Draw & Draw::setColor ( Colors  c,
double  alpha = 1 
)

Sets the color for future drawing operations.

Definition at line 3 of file Draw.cc.

Referenced by fill(), and stroke().

Draw& Draw::setColorGray ( double  x,
double  alpha = 1 
)

Sets the color for future drawing operations.

Definition at line 77 of file Draw.h.

Draw & Draw::setColorRGB ( double  red,
double  green,
double  blue,
double  alpha = 1 
)

Sets the color for future drawing operations.

Definition at line 73 of file Draw.cc.

Referenced by fill(), setColor(), setColorGray(), and stroke().

Draw & Draw::setFile ( const std::string &  file,
double  width,
double  height 
)

This must be called to setup output destination before calling any drawing commands.

Definition at line 38 of file Draw.cc.

Referenced by Draw().

Draw& Draw::setOrigin ( double  x,
double  y 
)

Moves the origin (lower left corner).

Definition at line 34 of file Draw.h.

Draw& Draw::setOrigin ( const fmat::Column< 2 > &  p  ) 

Moves the origin (lower left corner).

Definition at line 32 of file Draw.h.

Draw & Draw::setRegion ( const BoundingBox2D region,
bool  scaleStroke = false 
)

Changes scale and origin to fit the specified drawing region to the output.

Definition at line 51 of file Draw.cc.

Draw & Draw::setScale ( double  x,
bool  scaleStroke = false 
)

Changes the scaling factor, to display more or less within the bounds given to setFile().

The apparent stroke width is unchanged unless you set scaleStroke

Definition at line 45 of file Draw.cc.

Referenced by setRegion().

Draw & Draw::setScaledStrokeWidth ( double  x  ) 

Sets the stroke width using coordinate-space units, i.e. relative to scale factor.

Definition at line 65 of file Draw.cc.

Draw & Draw::setStrokeWidth ( double  x  ) 

Sets the stroke width using output dimension units, i.e. scale factor invariant.

Definition at line 64 of file Draw.cc.

Draw& Draw::stroke ( double  red,
double  green,
double  blue,
double  alpha = 1 
)

Outline the current path with specified color.

Definition at line 86 of file Draw.h.

Draw& Draw::stroke ( Colors  c,
double  alpha = 1 
)

Outline the current path with specified color.

Definition at line 84 of file Draw.h.

Draw & Draw::stroke (  ) 

Outline the current path.

Definition at line 74 of file Draw.cc.

Referenced by stroke().

Draw & Draw::strokeLine ( double  x1,
double  y1,
double  x2,
double  y2 
)

Stroke a single line; if drawing a polygon, better to use lineTo and stroke as a batch.

Definition at line 75 of file Draw.cc.

Draw& Draw::strokeLine ( const fmat::Column< 2 > &  p1,
const fmat::Column< 2 > &  p2 
)

Stroke a single line; if drawing a polygon, better to use lineTo and stroke as a batch.

Definition at line 88 of file Draw.h.

Referenced by strokeLine().

void Draw::teardown (  )  [protected]

Flush pending output and release resources.

Definition at line 67 of file Draw.cc.

Referenced by setFile(), and ~Draw().


Member Data Documentation

bool Draw::addPath [protected]

Indicates state of holdPath()/releasePath(), if true the path isn't cleared between draw calls.

Definition at line 196 of file Draw.h.

Referenced by getHoldMode(), holdPath(), and releasePath().

cairo_t* Draw::cr [protected]
std::string Draw::filename [protected]

Definition at line 188 of file Draw.h.

fmat::Column<2> Draw::origin [protected]

Definition at line 190 of file Draw.h.

Referenced by setOrigin().

double Draw::scale [protected]

Definition at line 191 of file Draw.h.

Referenced by displayToScaled(), getStrokeWidth(), scaledToDisplay(), setScale(), and setStrokeWidth().

Definition at line 187 of file Draw.h.

double Draw::surfaceHeight [protected]

Definition at line 193 of file Draw.h.

Referenced by setFile(), and setRegion().

double Draw::surfaceWidth [protected]

Definition at line 192 of file Draw.h.

Referenced by setFile(), and setRegion().


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

Tekkotsu v5.1CVS
Generated Mon May 9 04:59:06 2016 by Doxygen 1.6.3