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

Zbf Class Reference

#include <zbf.h>

Collaboration diagram for Zbf:

[legend]
List of all members.
Date:
20-Jun-2011
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 20-Jun-2011: Initial version. Stolen from Trab4 of CIV2802-2010.1 and modified. Incomplete version, to be complete as part of current assignment.


static int Init (cdCanvas *cv)
 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 cdCanvas * canvas = NULL
 CD handle of canvas for displaying zbuffer snap shot image.
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 int MAX (int a, int b)
 This function returns the maximum value between two integers.
static int MIN (int a, int b)
 This function returns the minumum value between two integers.

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 348 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 399 of file zbf.cpp.

References canvas, 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 390 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 431 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 281 of file zbf.cpp.

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

Referenced by EndPoly().

int Zbf::Init cdCanvas *  cv  )  [static]
 

This function initializes a zbuffer for displaying.

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

Parameters:
cv - target CD canvas for displaying (in)

Definition at line 372 of file zbf.cpp.

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

Referenced by Prj::DspRotateView(), and Prj::DspZbufferCanvas().

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

This function returns the maximum value between two integers.

Definition at line 133 of file zbf.h.

Referenced by MountEdges().

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

This function returns the minumum value between two integers.

Definition at line 141 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 201 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 250 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 102 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 124 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 333 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 159 of file zbf.cpp.

References canvas, 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 412 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

cdCanvas * Zbf::canvas = NULL [static, private]
 

CD handle of canvas for displaying zbuffer snap shot image.

Definition at line 61 of file zbf.cpp.

Referenced by BeginPoly(), Init(), and ScanLine().

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

Current fill color.

Definition at line 85 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 91 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 88 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 73 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 65 of file zbf.cpp.

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

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

Edge vector.

Definition at line 77 of file zbf.cpp.

Referenced by FillPoly().

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

Intersection vector.

Definition at line 81 of file zbf.cpp.

Referenced by FillPoly().

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

Size of poly array.

Definition at line 69 of file zbf.cpp.

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

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

Definition at line 94 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 20 18:09:56 2011 for Trab8 by  doxygen 1.4.2-20050421