canvas_utils.hpp

Various versions of the Draw() function to draw images onto a canvas.

Each version of Draw() takes a canvas widget and some form of data to be drawn on the widget, such as a circle, a bit matrix, or a geometric surface.

Functions

void Draw(Canvas canvas, const Circle &circle, const std::string &fill = "", const std::string &line = "")

Draw a Circle onto the canvas.

Parameters:
  • canvas – The Canvas to draw on.

  • circle – The circle to draw

  • fill – The color to fill the circle with

  • line – The color of the circle’s outline

template<size_t COLS, size_t ROWS>
void Draw(Canvas canvas, const BitMatrix<COLS, ROWS> &matrix, double w, double h)

Draw a BitMatrix onto a canvas using black and white squares (can specify cell width and height) Draw a Circle onto the canvas.

Parameters:
  • canvas – The Canvas to draw on.

  • matrix – The matrix to draw

  • w – The width of the matrix (number of columns)

  • h – The height of the matrix (number of rows)

template<typename ...BODY_TYPES>
void Draw(Canvas canvas, const Surface<BODY_TYPES...> &surface, const vector<std::string> &color_map)

Draw a Surface, specifying the full colormap to be used. The surface has a range of circle bodies, each with a color id.

Parameters:
  • canvas – The Canvas to draw on.

  • surface – A surface containing a set of shapes to draw.

  • color_map – Mapping of values to the colors with which they should be associated.

template<typename ...BODY_TYPES>
void Draw(Canvas canvas, const Surface<BODY_TYPES...> &surface, size_t num_colors)

Draw a Surface, just specifying the number of colors (and using a generated hue map). The surface has a range of circle bodies, each with a color id.

Parameters:
  • canvas – The Canvas to draw on.

  • surface – A surface containing a set of shapes to draw.

  • num_colors – The number of distinct colors to use in visualization.

template<typename BODY_TYPE>
void Draw(Canvas canvas, const Surface2D<BODY_TYPE> &surface, const vector<std::string> &color_map)

Draw a Surface2D, specifying the full colormap to be used. The surface has a range of circle bodies, each with a color id.

Parameters:
  • canvas – The Canvas to draw on.

  • surface – A surface containing a set of shapes to draw.

  • color_map – Mapping of values to the colors with which they should be associated.

template<typename BODY_TYPE>
void Draw(Canvas canvas, const Surface2D<BODY_TYPE> &surface, size_t num_colors)

Draw a Surface2D, just specifying the number of colors (and using a generated hue map). The surface has a range of circle bodies, each with a color id.

Parameters:
  • canvas – The Canvas to draw on.

  • surface – A surface containing a set of shapes to draw.

  • num_colors – The number of distinct colors to use in visualization.

void Draw(Canvas canvas, const vector<vector<size_t>> &grid, const vector<std::string> &color_map, std::string line_color, double cell_width, double cell_height, double offset_x, double offset_y)

Draw a grid onto a canvas.

Parameters:
  • canvas – The Canvas to draw on.

  • grid – A vector of vectors of color IDs.

  • color_map – Mapping of values to the colors with which they should be associated.

  • line_color – The background line color for the grid.

  • cell_width – How many pixels wide is each cell to draw?

  • cell_height – How many pixels tall is each cell to draw?

  • offset_x – How far should we shift the grid relative to the left side of the canvas?

  • offset_y – How far should we shift the grid relative to the top of the canvas?

void Draw(Canvas canvas, const vector<vector<size_t>> &grid, const vector<std::string> &color_map, std::string line_color, double cell_w, double cell_h)

Draw a grid onto a canvas, but without offsets provided &#8212; the grid is centered.

Parameters:
  • canvas – The Canvas to draw on.

  • grid – A vector of vectors of color IDs.

  • color_map – Mapping of values to the colors with which they should be associated.

  • line_color – The background line color for the grid.

  • cell_w – How many pixels wide is each cell to draw?

  • cell_h – How many pixels tall is each cell to draw?

void Draw(Canvas canvas, const vector<vector<size_t>> &grid, const vector<std::string> &color_map, std::string line_color = "black")

Draw a grid onto a canvas, but without cell size provided &#8212; maximize to fill the canvas!

Parameters:
  • canvas – The Canvas to draw on.

  • grid – A vector of vectors of color IDs.

  • color_map – Mapping of values to the colors with which they should be associated.

  • line_color – The background line color for the grid.

void Draw(Canvas canvas, const vector<size_t> &grid, size_t grid_cols, const vector<std::string> &color_map, std::string line_color, double cell_width, double cell_height, double offset_x, double offset_y)

Draw a vector onto a canvas as a grid.

Parameters:
  • canvas – The Canvas to draw on.

  • grid – A vector of vectors of color IDs

  • grid_cols – Number of columns in the grid

  • color_map – Mapping of values to the colors with which they should be associated.

  • line_color – The background line color for the grid

  • cell_width – How many pixels wide is each cell to draw?

  • cell_height – How many pixels tall is each cell to draw?

  • offset_x – How far should we shift the grid relative to the left side of the canvas?

  • offset_y – How far should we shift the grid relative to the top of the canvas?

void Draw(Canvas canvas, const StateGrid &state_grid, const vector<std::string> &color_map, std::string line_color = "black")

Draw a state grid onto a canvas.

Parameters:
  • canvas – The Canvas to draw on.

  • state_grid – A StateGrid object.

  • color_map – Mapping of values to the colors with which they should be associated.

  • line_color – The background line color for the grid.

void DrawGridBG(Canvas canvas, size_t rows, size_t cols, const std::string &bg_color, const std::string &line_color)

Draw a grid as the background of a canvas. Since this is a BG, clear the canvas first.

Parameters:
  • canvas – The Canvas to draw on.

  • rows – Number of rows to draw in the grid.

  • cols – Number of columns to draw in the grid.

  • bg_color – The background color for the grid.

  • line_color – The color of the liens on the grid.

template<typename CONTAINER_T, typename POINT_FUN_T, typename COLOR_FUN_T>
void DrawPoints(Canvas canvas, CONTAINER_T &&container, double radius, POINT_FUN_T &&point_fun, COLOR_FUN_T &&color_fun, const std::string &line_color = "black")