0% found this document useful (0 votes)
72 views31 pages

Line Drawing: CMPT 361 Introduction To Computer Graphics Torsten Möller

The document discusses the graphics rendering pipeline and techniques for rasterizing primitives like lines and circles. It covers topics like the vertex processor, rasterizer, and algorithms for scan converting lines and circles in a discrete pixel grid like Bresenham's line algorithm and the midpoint circle algorithm.

Uploaded by

Sadam Gebi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views31 pages

Line Drawing: CMPT 361 Introduction To Computer Graphics Torsten Möller

The document discusses the graphics rendering pipeline and techniques for rasterizing primitives like lines and circles. It covers topics like the vertex processor, rasterizer, and algorithms for scan converting lines and circles in a discrete pixel grid like Bresenham's line algorithm and the midpoint circle algorithm.

Uploaded by

Sadam Gebi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Line Drawing

CMPT 361
Introduction to Computer Graphics
Torsten Möller

© Machiraju/Zhang/Möller
Rendering Pipeline
Hardware

Modelling Transform Visibility

Illumination +
Shading

Texture/
Perception,
Color Realism
Interaction
© Machiraju/Zhang/Möller
Reading
• Angel – Chapter 6.8, 6.9
• Foley et al - Chapter 3

© Machiraju/Zhang/Möller
3
The graphics pipeline

• From the modeling stage to image formation


• Pipelined approach helps increase system
throughput
– Throughput: rate at which data flows through the system
– In a pipeline, data processing in subsequent blocks can
be done in parallel
– Especially effective when the same sequence of
operations are to be performed on large quantity of data
– true in graphics
© Machiraju/Zhang/Möller
4
Vertex processor
• Per-vertex operations (vertices define objects/
primitives)
• Two main functionalities:
– Coordinate transformations
– Color computation at each vertex (shading models)
• Objects/geometry first defined in their own
coordinate systems, then transformed into a
world space — modeling transformation
• Then objects are transformed from world space
into the camera coordinate system — viewing
© Machiraju/Zhang/Möller
transformation and projection transformation 5
Clipping and primitive assembly
• Model a finite field of vision
• Remove objects outside a
finite clipping volume
• Need to be done on a primitive
by primitive basis,
not on vertices
• Output is a set of primitives
whose projections can appear in the image

© Machiraju/Zhang/Möller
6
Rasterizer
• The rasterizer converts a primitive into a set of
fragments
• A fragment stores per pixel information for its
associated primitive, later used to determine whether
the fragment contributes to pixel color and to
compute the pixel color
– Raster/pixel location (in the frame buffer)
– Depth, e.g., to determine whether this fragment “survives”
– Interpolated attributes, e.g., color and texture coordinate,
from the previous stages
– Alpha value (for blending)
– Window ID, etc. © Machiraju/Zhang/Möller 7
Fragment processing
• Performs per-fragment operations
• Main function is to compute the color at a pixel,
using information stored in the fragments, e.g.,
depth, alpha, texture coordinates; can also add in
fog and other effects
• A (programmable) fragment shader is a program
that performs the processing which replaces the
OpenGL fixed functionality, e.g., simply using
interpolated attributes
• Similar to a vertex shader (per-vertex operations)
• Shader programs typically have limited instruction
© Machiraju/Zhang/Möller
set 8
Where are we at now?

Drawing or rasterization of
primitives first. Consider
lines and polygons.

© Machiraju/Zhang/Möller
Assumptions
• Transformation, clipping, projection already done
• Primitives to rasterize are actually on the screen
• Work with 2D screen coordinates with square
pixels
(N, M)

(0, 0)
© Machiraju/Zhang/Möller
10
Primitives
• Polygons
• explicit curves
– lines, quadricts
• parametric curves/surfaces
– Curves, Surfaces
• implicit description
• Misc
– particle systems/points, fractals
© Machiraju/Zhang/Möller
11
Explicit Descriptions
• Given - an explicit equation
y = f(x)
• cannot get multiple values of y
• not rotationally invariant
• no infinite slope (vertical line)
• axis dependent (y depends on x)
• specify one variable and resolve for the
other
© Machiraju/Zhang/Möller
12
Lines
• Given - an explicit line equation
y = mx+n
• Which pixels to set?
http://www.cse.unsw.edu.au/~cs3421/slides/bres/Bresenham.html

© Machiraju/Zhang/Möller
13
Scan Converting Lines
• Compute the coordinates of pixels that lies
on or near an ideal, infinitely thin line
imposed on a 2D raster grid
• Assumptions
– line will be 1 pixel thick and will approximate
an infinitely fine line
– pixels represented as disjoint circles, centred on
a grid (unless specified otherwise)
– integer coordinates of endpoints
– pixel on or off ©(2Machiraju/Zhang/Möller
states) 14
Scan Converting Lines (2)
• Desirable properties:
– constant brightness (irrespective of length or
orientation)
– 1 pixel per column (-1 <= slope <= 1), 1 pixel
per row (slope > +/- 1)
– as close to the ideal/as straight as possible
– allow control of pen, line and endpoint styles
– drawn as smoothly as possible
(anti-aliasing)
– drawn as rapidly as possible
© Machiraju/Zhang/Möller
15
Scan Converting Lines (3)
• Difficulties:
– brightness and pixel criteria conflict (for bi-
level displays)

© Machiraju/Zhang/Möller
16
Basic – Brute force
• Find slope m = rise/run or y = mx + b
• increment x by 1 (xi);
• calculate yi = mxi + b
• pixel (xi, round(yi)) turned on
• simple, but inefficient:
– floating point multiplication
– addition
– round
© Machiraju/Zhang/Möller
17
Incremental - DDA
• multiplication can yi+1 = mxi+1 + b
be eliminated:
= m(xi + 1) + b
= yi + m
• called digital differential analyzer (DDA) - after
mechanical device that solves differential
equations by numerical methods
• Drawbacks:
– floating point values (m,y)
– round operation
© Machiraju/Zhang/Möller
– special cases could be done more quickly 18
Lines - Bresenham
• Special case of Midpoint Line Algorithm
• uses only integer arithmetic & no rounding
• idea is to provide the best-fit approximation
to a true line by minimizing the error
(distance) to the true line
• slope (rest is done with reflection)

© Machiraju/Zhang/Möller
19
Lines - Bresenham (2)
• Explicit line equation:
y
y = mx + b = x+b
x
• Implicit line equation:
F (x, y) = x y y x+h
• Main idea - call on decision variable:
di = F (xi + 1, yi + 1/2)
= (xi + 1) y (yi + 1/2) x + h
© Machiraju/Zhang/Möller
20
Lines - Bresenham (3)
• if di > 0, pick O, and:
O = di+1 di
= F (xi + 2, yi + 1/2) = y
• if di < 0, pick NO, and:
NO = di+1 di
= F (xi + 2, yi + 3/2) = y x
• if di = 0, pick either one, but consistently

© Machiraju/Zhang/Möller
21
Lines - Bresenham (4)
• Additional issues:
– Endpoint order: we want P0 to P1 to look
exactly the same as P1 to P0
– Starting at edge of a clip rectangle: we must use
the midpoint test result rather than computing
intersections analytically if we are to ensure the
correct sequence of pixels

© Machiraju/Zhang/Möller
22
Lines - Bresenham (4)

© Machiraju/Zhang/Möller
23
Quadrics - Circles
• Circles, ellipsoids, etc. p
y= R2 x2
• divide in 8 quadrants
• What is special
about 8-fold
symmetry?

© Machiraju/Zhang/Möller
24
Quadrics - Circles (2)
• Midpoint Circle Algorithm
– trace out arc in 2nd octant and draw the rest by
symmetry
– choose between E and SE pixel at each stage

© Machiraju/Zhang/Möller
25
Quadrics - Circles (3)
• incremental - now have higher order
D(x) = (x + x)2 x2 = 2x x + x2
• higher order difference system
D(x + x) D(x) = 2 x2

© Machiraju/Zhang/Möller
26
Quadrics - Ellipses
• Can a midpoint algorithm be developed for
ellipses? What are the important differences
from circles?
• The result is Da Silva's algorithm (the idea
is illustrated below):

© Machiraju/Zhang/Möller
27
Lines - Anti-Aliasing
• A continuous (zero-width) line is “invisible”
in a discrete grid.
• Give line thickness - How?
• Signal Processing Approach:
– line is high-frequency
– want to avoid aliasing
– what to do first?

© Machiraju/Zhang/Möller
28
Lines - Anti-Aliasing (2)
• Bandlimit signal - how?
• Convolve with smoothing filter - which?

© Machiraju/Zhang/Möller
29
Lines - Anti-Aliasing (3)
• Box filter not all that good
• convolve it again - why?
• Then resample!

© Machiraju/Zhang/Möller
30
Lines - Anti-Aliasing (4)
• Other alternatives?
• Can we improve this algorithm?

© Machiraju/Zhang/Möller
31

You might also like