Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

Zbf Class Reference

#include <zbf.h>

List of all members.
Date:
21-Jun-2010
Author:
Luiz F. Martha
Version:
1.0
--------------------------------------------------------------- Reference:

See class notes of courses CIV-2802 Sistemas Graficos para Engenharia, Departamento de Engenharia Civil, PUC-Rio.

--------------------------------------------------------------- Description:

This is a simple graphics package containing a z-buffer algorithm for filling polygon areas with a given color. For functions specification, see header file "zbf.h".

--------------------------------------------------------------- Revisions:

  • Version 1.0 by L.F. Martha on 21-Jun-2010: Initial version. Stolen from Trab3 of CIV2801-2005.2 and modified.


static int Init (int width, int height)
 This function initializes a zbuffer for displaying.
static void Close (void)
 This function closes a zbuffer.
static void BeginPoly (long int color)
 This function starts the display of a new polygon in this module.
static void Vertex (double x, double y, double z)
 This function receives a vertex of the current polygon being displayed in this module.
static void EndPoly (void)
 This function finishes the specification of a polygon to be displayed in this module.
static void NSCtoRaster (double xnsc, double ynsc, double znsc, int *xr, int *yr, unsigned int *zr)
 Convert from normalized screen coordinates (NSC) to raster (image) coordinates.
static void OrderIntersections (Pixel *vtx, int left, int right)
 Order intesections of a scan line with polygon edges from left to right.
static void ScanLine (Pixel *vtx_lft, Pixel *vtx_rgt, int ys)
 Paints a horizontal line on canvas (image).
static int MountEdges (Edge *edge, int *ymin, int *ymax, int npoints, NscPnt *poly)
 Calculate maximum and minimum y coordinate and mount edge vector.
static int MountInt (Pixel *vtx, Edge *edge, int *nedges, int ys)
 Mount intersection vector.
static void FillPoly (int npoints, NscPnt *poly)
 This function fills a closed polygon with the current color.
static void Release (void)
 Release memory used by z-buffer and polygon.
static int Alloc (void)
 Allocate memory used by z-buffer and polygon.
static NscPntpoly = NULL
 Current polygon being displayed.
static int sizepoly = 0
 Size of poly array.
static int npolyverts = 0
 Number of polygon vertices.
static Edgepoly_edge = NULL
 Edge vector.
static Pixelscanline_vtx = NULL
 Intersection vector.
static long int curr_color = 0x0L
 Current fill color.
static int cv_width = 100
 Current z-buffer (canvas) horizontal size.
static int cv_height = 100
 Current z-buffer (canvas) vertical size.
static unsigned int * zbuff = NULL

Static Private Member Functions

static double MAX (double a, double b)
 This function returns the maximum value between two doubles.
static double MIN (double a, double b)
 This function returns the minumum value between two doubles.

Classes

struct  Edge
 Polygon edge. More...
struct  NscPnt
 3D point in normalized screen coordinates More...
struct  Pixel
 Pixel point. More...


Member Function Documentation

int Zbf::Alloc void   )  [static, private]
 

Allocate memory used by z-buffer and polygon.

Definition at line 343 of file zbf.cpp.

References cv_height, cv_width, poly, Release(), sizepoly, and zbuff.

Referenced by Init().

void Zbf::BeginPoly long int  color  )  [static]
 

This function starts the display of a new polygon in this module.

The polygon is filled with the given color.

Parameters:
color - coded color of polygon (in)

Definition at line 392 of file zbf.cpp.

References curr_color, npolyverts, and zbuff.

Referenced by Dsp::ZbfBeginPoly().

void Zbf::Close void   )  [static]
 

This function closes a zbuffer.

It releases the memory used by the current allocated zbuffer.

Definition at line 383 of file zbf.cpp.

References cv_height, cv_width, and Release().

void Zbf::EndPoly void   )  [static]
 

This function finishes the specification of a polygon to be displayed in this module.

It displays the polygon using the z-buffer algorithm.

Definition at line 424 of file zbf.cpp.

References FillPoly(), npolyverts, poly, Zbf::NscPnt::x, Zbf::NscPnt::y, and Zbf::NscPnt::z.

Referenced by Dsp::ZbfEndPoly().

void Zbf::FillPoly int  npoints,
NscPnt poly
[static, private]
 

This function fills a closed polygon with the current color.

Each pixel of the polygon is tested against the zbuffer. A pixel is displayed only if its z value is less then the current value of that pixel in the zbuffer (which is then updated).

Definition at line 276 of file zbf.cpp.

References MountEdges(), MountInt(), OrderIntersections(), poly_edge, ScanLine(), scanline_vtx, and Zbf::Pixel::x.

Referenced by EndPoly().

int Zbf::Init int  width,
int  height
[static]
 

This function initializes a zbuffer for displaying.

It allocate memory for the zbuffer array and for local variables.

Parameters:
width,height - sizes of new zbuffer (in)

Definition at line 367 of file zbf.cpp.

References Alloc(), cv_height, cv_width, and zbuff.

Referenced by Prj::ZbufferSnapShot().

static double Zbf::MAX double  a,
double  b
[inline, static, private]
 

This function returns the maximum value between two doubles.

Definition at line 129 of file zbf.h.

Referenced by MountEdges().

static double Zbf::MIN double  a,
double  b
[inline, static, private]
 

This function returns the minumum value between two doubles.

Definition at line 137 of file zbf.h.

Referenced by MountEdges().

int Zbf::MountEdges Edge edge,
int *  ymin,
int *  ymax,
int  npoints,
NscPnt poly
[static, private]
 

Calculate maximum and minimum y coordinate and mount edge vector.

Definition at line 196 of file zbf.cpp.

References Zbf::Edge::dxs, Zbf::Edge::dzs, MAX(), MIN(), NSCtoRaster(), Zbf::Edge::xs, Zbf::Edge::y_max, Zbf::Edge::y_min, and Zbf::Edge::zs.

Referenced by FillPoly().

int Zbf::MountInt Pixel vtx,
Edge edge,
int *  nedges,
int  ys
[static, private]
 

Mount intersection vector.

Definition at line 245 of file zbf.cpp.

References Zbf::Edge::dxs, Zbf::Edge::dzs, Zbf::Pixel::x, Zbf::Edge::xs, Zbf::Edge::y_max, Zbf::Edge::y_min, Zbf::Pixel::z, and Zbf::Edge::zs.

Referenced by FillPoly().

void Zbf::NSCtoRaster double  xnsc,
double  ynsc,
double  znsc,
int *  xr,
int *  yr,
unsigned int *  zr
[static, private]
 

Convert from normalized screen coordinates (NSC) to raster (image) coordinates.

The view volume in NSC ranges from -1 to +1 in the three axes. In NSC, the front (near) clipping plane has znsc = -1 and the back (far) clipping plane has znsc = +1. In raster coordinates, the front plane has zr = UINT_MAX (maximum unsigned int value) and the back plane has zr = 0. Therefore, the conversions of the limiting planes of the view volume from NSC to raster are as follows: left: xnsc = -1.0 ---> xr = 0 right: xnsc = +1.0 ---> xr = cv_width-1 bottom: ynsc = -1.0 ---> yr = 0 top: ynsc = +1.0 ---> yr = cv_height-1 front: znsc = -1.0 ---> zr = UINT_MAX back: znsc = +1.0 ---> zr = 0

Definition at line 97 of file zbf.cpp.

References cv_height, and cv_width.

Referenced by MountEdges().

void Zbf::OrderIntersections Pixel vtx,
int  left,
int  right
[static, private]
 

Order intesections of a scan line with polygon edges from left to right.

Definition at line 119 of file zbf.cpp.

References Zbf::Pixel::x.

Referenced by FillPoly().

void Zbf::Release void   )  [static, private]
 

Release memory used by z-buffer and polygon.

Definition at line 328 of file zbf.cpp.

References npolyverts, poly, sizepoly, and zbuff.

Referenced by Alloc(), and Close().

void Zbf::ScanLine Pixel vtx_lft,
Pixel vtx_rgt,
int  ys
[static, private]
 

Paints a horizontal line on canvas (image).

Each pixel of the scan line is tested against the zbuffer. A pixel is displayed only if its z value is less then the current value of that pixel in the zbuffer (which is then updated).

Definition at line 154 of file zbf.cpp.

References curr_color, cv_width, Zbf::Pixel::x, Zbf::Pixel::z, and zbuff.

Referenced by FillPoly().

void Zbf::Vertex double  x,
double  y,
double  z
[static]
 

This function receives a vertex of the current polygon being displayed in this module.

It is assumed that the vertex is given in normalized screen coordinates (NSC). The view volume in NSC ranges from -1 to +1 in the three axes. In NSC, the front (near) clipping plane has z = -1 and the back (far) clipping plane has z = +1.

Parameters:
x,y,z - polygon vertex in normalized screen coords. (in)

Definition at line 405 of file zbf.cpp.

References npolyverts, poly, sizepoly, Zbf::NscPnt::x, Zbf::NscPnt::y, Zbf::NscPnt::z, and zbuff.

Referenced by Dsp::ZbfVertex().


Member Data Documentation

long int Zbf::curr_color = 0x0L [static, private]
 

Current fill color.

Definition at line 80 of file zbf.cpp.

Referenced by BeginPoly(), and ScanLine().

int Zbf::cv_height = 100 [static, private]
 

Current z-buffer (canvas) vertical size.

Definition at line 86 of file zbf.cpp.

Referenced by Alloc(), Close(), Init(), and NSCtoRaster().

int Zbf::cv_width = 100 [static, private]
 

Current z-buffer (canvas) horizontal size.

Definition at line 83 of file zbf.cpp.

Referenced by Alloc(), Close(), Init(), NSCtoRaster(), and ScanLine().

int Zbf::npolyverts = 0 [static, private]
 

Number of polygon vertices.

Definition at line 68 of file zbf.cpp.

Referenced by BeginPoly(), EndPoly(), Release(), and Vertex().

Zbf::NscPnt * Zbf::poly = NULL [static, private]
 

Current polygon being displayed.

Definition at line 60 of file zbf.cpp.

Referenced by Alloc(), EndPoly(), Release(), and Vertex().

Zbf::Edge * Zbf::poly_edge = NULL [static, private]
 

Edge vector.

Definition at line 72 of file zbf.cpp.

Referenced by FillPoly().

Zbf::Pixel * Zbf::scanline_vtx = NULL [static, private]
 

Intersection vector.

Definition at line 76 of file zbf.cpp.

Referenced by FillPoly().

int Zbf::sizepoly = 0 [static, private]
 

Size of poly array.

Definition at line 64 of file zbf.cpp.

Referenced by Alloc(), Release(), and Vertex().

unsigned int * Zbf::zbuff = NULL [static, private]
 

Definition at line 89 of file zbf.cpp.

Referenced by Alloc(), BeginPoly(), Init(), Release(), ScanLine(), and Vertex().


The documentation for this class was generated from the following files:
Generated on Mon Jun 21 12:45:22 2010 for Trab4 by  doxygen 1.4.2-20050421