Main Page | Data Structures | Directories | File List | Data Fields | Globals

bresenham.c File Reference

An implementation of Bresenham's line drawing algorithm. More...

#include <sadie.h>
#include <math.h>
#include "logerr.h"
#include "bresenham.h"

Go to the source code of this file.

Typedefs

typedef int64_t bcoord_t
 An integer of at least 33 bits: holds any signed OR unsigned 32 bit int.
typedef bcoord_t(* coord_accessorp_t )(bresenham_linep_t bline)
 A coordinate accessor function.
typedef void(* point_iteratorp_t )(bresenham_linep_t bline)
 A point iterator function.

Functions

bresenham_linep_t bresenham_from_s_coord (int32_t first_col, int32_t first_row, int32_t last_col, int32_t last_row)
 Wrapper to construct a Bresenham line context from signed coordinates.
bresenham_linep_t bresenham_from_coord (uint32_t first_col, uint32_t first_row, uint32_t last_col, uint32_t last_row)
 Wrapper to construct a Bresenham line context from unsigned coordinates.
int bresenham_next (bresenham_linep_t bline, uint32_t *col, uint32_t *row)
 Iterate the Bresenham line context, generating the next coordinate pair.
int bresenham_next_s (bresenham_linep_t bline, int32_t *col, int32_t *row)
 Iterate the Bresenham line context, generating the next coordinate pair.
void demolish_bresenham (bresenham_linep_t *blinehandle)
 Destroy a Bresenham line context.


Detailed Description

An implementation of Bresenham's line drawing algorithm.

Many different web resources reference a web page by Colin Flanagan, currently hosted at http://www.cs.helsinki.fi/group/goa/mallinnus/lines/bresenh.html which is a very lucid description of the derivation of the algorithm. Remember that here we're using row & column notation rather than left-handed Cartesian x,y coordinates, but in any case we define arbitrary internal coordinates, that get mapped to rows and columns as needed. The original reference is: Bresenham, J.E. (1965) "Algorithm for computer control of a digital plotter". IBM Systems Journal 4(1) 1965, p. 25--30.

Author:
University of Arizona Digital Image Analysis Lab
Date:
2004
Version:
Id
bresenham.c,v 1.1 2005/03/22 20:23:43 mmunro Exp

Definition in file bresenham.c.


Function Documentation

bresenham_linep_t bresenham_from_coord uint32_t  first_col,
uint32_t  first_row,
uint32_t  last_col,
uint32_t  last_row
 

Wrapper to construct a Bresenham line context from unsigned coordinates.

The context records the state of the algorithm that will generate pairs of discrete coordinates for a series of steps approximating the line linking the first and last points.

See also:
bresenham_from_bcoord
Parameters:
[in] first_col the column-coordinate of the first point.
[in] first_row the row-coordinate of the first point.
[in] last_col the column-coordinate of the last point.
[in] last_row the row-coordinate of the last point.
Returns:
A pointer to the state of the Bresenham context at the first point.

Definition at line 279 of file bresenham.c.

bresenham_linep_t bresenham_from_s_coord int32_t  first_col,
int32_t  first_row,
int32_t  last_col,
int32_t  last_row
 

Wrapper to construct a Bresenham line context from signed coordinates.

The context records the state of the algorithm that will generate pairs of discrete coordinates for a series of steps approximating the line linking the first and last points.

See also:
bresenham_from_bcoord
Parameters:
[in] first_col the column-coordinate of the first point.
[in] first_row the row-coordinate of the first point.
[in] last_col the column-coordinate of the last point.
[in] last_row the row-coordinate of the last point.
Returns:
A pointer to the state of the Bresenham context at the first point.

Definition at line 260 of file bresenham.c.

Referenced by Sadie_Plot_ProfileCmd().

int bresenham_next bresenham_linep_t  bline,
uint32_t *  col,
uint32_t *  row
 

Iterate the Bresenham line context, generating the next coordinate pair.

As constructed, the line context will always represent at least one point (even if the first point coincides with the last point), and so we can iterate it at least once; however once we've obtained the coordinates of the last point further iterations are incorrect (think of the context as being just off the end of the line). An iteration produces the current coordinate pair in the sequence of discrete points that approximate the straight line joining the first to the last point, and modifies the internals of the context to prepare the next point. The return value is a Boolean flag that is false iff further iterations are possible.

Parameters:
[in,out] bline points to the structure recording the state to iterate.
[out] col where to deposit the current column coordinate.
[out] row where to deposit the current row coordinate.
Returns:
True if off the end of the line, false if we can iterate again.

Definition at line 303 of file bresenham.c.

References logerr_assert, LOGERR_DEBUG, and LOGERR_FUNC.

Referenced by Sadie_Plot_ProfileCmd().

int bresenham_next_s bresenham_linep_t  bline,
int32_t *  col,
int32_t *  row
 

Iterate the Bresenham line context, generating the next coordinate pair.

Just a variation for signed coordinates.

See also:
bresenham_next
Parameters:
[in,out] bline points to the structure recording the state to iterate.
[out] col where to deposit the current column coordinate.
[out] row where to deposit the current row coordinate.
Returns:
True if off the end of the line, false if we can iterate again.

Definition at line 332 of file bresenham.c.

References logerr_assert, LOGERR_DEBUG, and LOGERR_FUNC.

void demolish_bresenham bresenham_linep_t blinehandle  ) 
 

Destroy a Bresenham line context.

A simple free() would suffice to reclaim the storage allocated by the current Bresenham line context constructors, but we don't want to guarantee this for all future versions of this code.

Parameters:
[out] blinehandle points to the pointer to be freed (and set NULL).

Definition at line 359 of file bresenham.c.

References logerr_assert, LOGERR_CRIT, and LOGERR_FUNC.

Referenced by Sadie_Plot_ProfileCmd().


Generated on Fri Jul 8 14:55:01 2005 for tclSadie by  doxygen 1.4.2