0% found this document useful (0 votes)
55 views23 pages

Computer Graphics Rasterization

The document discusses rasterization in computer graphics, explaining how continuous representations are converted into discrete formats for display on devices. It covers various rasterization techniques, including nearest neighbor, line, and circle rasterization, as well as algorithms like DDA and Bresenham's algorithm. The document also touches on higher-order curves and methods for improving rasterization accuracy through adaptive sampling.

Uploaded by

tasukabe
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)
55 views23 pages

Computer Graphics Rasterization

The document discusses rasterization in computer graphics, explaining how continuous representations are converted into discrete formats for display on devices. It covers various rasterization techniques, including nearest neighbor, line, and circle rasterization, as well as algorithms like DDA and Bresenham's algorithm. The document also touches on higher-order curves and methods for improving rasterization accuracy through adaptive sampling.

Uploaded by

tasukabe
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

Computer Graphics:

6-Rasterization

Prof. Dr. Charles A. Wüthrich,


Fakultät Medien, Medieninformatik
Bauhaus-Universität Weimar
caw AT medien.uni-weimar.de
Raster devices

• In modern devices the smallest addressable element is a point.


• Each of these dots is called a pixel, or „pel“, for picture element.
• Pixels can be represented as being the points of the plane having
integer coordinates (~Z2)
• Note that this is just a mathematical representation: in reality,
pixels are often broader than high, and have a shape which
resemble
– a 2D gaussian distribution (for CRT screens)
– Small squares (for LCD displays)
– A more or less circular dot (printers)
Rasterization

• Is the operation that


allows to pass from our
continuous
representation of the
world to the discrete
world of computers
• It allows drawing lines,
curves, polygons and
patches on a 2D
discrete output device
• How is this done?
Nearest neighbour rasterization

• One has to distinguish


among two types of
rasterization:
– Point rasterization:" P
Given a point P of R2, the
nearest point P´ of Z2 is its P´
rasterization.
– Curve rasterization:
nearest integer does not
work any more, since
curves are continuous
– Rasterization must be
based on intersection with
some grid.
– Is there a model that fits
both methods?
Nearest neighbour rasterization
• Sure there is! • Different choices of D lead to
• Let D be a compact set of R2, different schemes
ST it is included in the unit
square (basic domain)
• Let Dz be the translated
domain of D by the point of
integer coordinates z=(i,j)
• Let A be a subset of R2
• Def: The rasterization of A is Cell rasterization
the set of all points z such
that Dz∩A ≠ ∅
• Basically one copies D
around all points of integer
coordinates and then takes
as rasterization the
corresponding points
Grid intersection rasterization
Line rasterization

• Problem: Given the line


passing through the
points PI=(xI,yI),
PF=(xF,yF), draw its
rasterization
• Two basic methods for
doing this:
– Direct algorithms:
• use global knowledge
• generally slow
– Incremental algorithms:
• require only local
knowledge
• often highly optimized
Line rasterization
yF − yI y − yI
• Line through PI=(xI,yI), PF=(xF,yF):" y= x + yI − F xI
xF − xI xF − xI

• Simplest algorithm:
– compute intersections with grid lines x=i, y=j (i,jÎZ)
– Near intersection to next grid point
Rosenfeld‘s theorem
• There is a theorem that halves • Note that a similar theorem
the number of intersection can be stated for curves and
computations that have to be their derivatives
made
• Note that intersections can
• Theorem: Let r be the straight
lead to ambiguous
line y=mx+q. "
Let -1 ≤ m ≤ 1 (slope rasterization points, in case
between -45° and 45°). " they fall halfway between two
All the points of the integer points
rasterization of r can be found
by computing the intersection
with the straight lines of the
form x=i
• Intersections with y=j do not
lead to additional points
DDA algorithm
• Without loss of generality,
consider q=0
• Let us look at the table of the
intersections with the straight
lines x=i"
"
" x y
" 0 q
"
" 1 m+q
" 2 2*m+q
3 3*m+q

"
"
DDA algorithm
• Without loss of generality, • This gives the idea for a new
consider q=0 algorithm: we add at each
• Let us look at the table of the step of the algorithm 1 to the
intersections with the straight x and m to the y
lines x=i"
" • The resulting algorithm is an
" x y incremental algorithm,
" because there is no need for
0 q
" the general equation
" 1 m+q
" 2 2*m+q
3 3*m+q
"
"
At each step, yI+1=yI+m!!!!
DDA algorithm

x y
dy=yF-yI; dx=xF-xI; 0 2
m=dy/dx;
1 2,33→2
y=yI;
2 2,66→3
FOR x=xI TO xF
3 3
WritePixel(x,⎡y+0.5⎤);
4 3,33→3
y=y+m;
5 3,66→4
ENDFOR
6 4

• Example: y=1/3x+2 "


between (0,2) and (6,4)

0
Integer DDA algorithm

• One can improve the dx=xF; dy=yF; x=0; y=0;


algorithm so as to make it use rest=0;
integer quantities only DrawPixel(x,y);
FOR (i=0; i<=xF; i++)
• This by using the fact that
x=x+1;
only rational numbers are
rest=rest+dy;
involved in a normal if(rest>dx)
environment THEN y=y+1;
• One can therefore multiply the rest=rest-dx;
equations by the maximum ENDIF
denominator to get rid of the DrawPixel(x,y)
denominators ENDFOR
Bresenham‘s algorithm

• While tracing the line, at each


step we use a control variable
to check if we have to move NE
to the right or to the upper
right
d
• One can use thus a control Pi
variable to steer whether to
step upwards or sideways E

• Precompute increments and xi xi+1


the game is done
• Also, mirroring has to be
done to let the algorithm draw
all cases, eventually through
swapping main variable
Bresenham‘s algorithm
PROCEDURE Bresenham(x1,y1,x2,y2, WritePixel(x,y,value);
value: integer): /*first point in line */
var dx, dy, incr1, incr2, d, x, WHILE x<xend DO BEGIN
y, xend: INTEGER;
x:=x+1;
BEGIN IF d<0
dx:=ABS(x2-x1); THEN d:=d+incr1;
dy:=ABS(y2-y1); /* increment East */
d:=2*dy-dx; ELSE BEGIN
incr1:=2*dy; /* increment E */ /* increment NE */
incr2:=2*(dy-dx); /* increment y:=y+1;
NE */ d:=d+incr2;
IF x1>x2 END
THEN BEGIN /* start at WritePixel(x,y,value);
point with END /*while*/
smaller x */ END /*Bresenham*/
x:=x2; y:=y2; xend:=x1;
END
ELSE BEGIN
x:=x1; y:=y1; xend:=x2;
END
Circle rasterization

• Problem: Given the circle


x2+y2=r2 draw its
rasterization
• The most common
algorithm for drawing
circles was developed
by Bresenham
• Consider the second
octant, from x=0 to "
x=y=r/sqrt(2)
• Let F(x,y)=x2+y2-r2:"
F>0 outside the circle"
F<0 inside the circle
Circle rasterization

• Problem: Given the circle P(xp,yp) E


x2+y2=r2 draw its
ME
rasterization M

• The most common SE


MSE
algorithm for drawing
circles was developed
by Bresenham
• Consider the second • One can show that:
– if the midpoint between E
octant, from x=0 to " and SE is outside the circle,
x=y=r/sqrt(2) then SE is closer to the
• Let F(x,y)=x2+y2-r2:" circle
F>0 outside the circle" – Similarly, if the midpoint is
F<0 inside the circle inside the circle, then E is
closer to the circle
Circle rasterization
• We choose a decision • Thus, dnew=dold+2xp-2yp+5,
variable d, which is the value and"
of the function at the midpoint" ΔSE=2xp+ -2yp+5
dold=F(xp+1,yp-1/2)=" • Here, the two Δ increments
(xp+1)2+(yp-1/2)2-r2 vary from step to step
• If d<0, then E is chosen and • Otherwise it is similar to line
the increment is" drawing
dnew=F(xp+2,yp-1/2)="
(xp+2)2+(yp-1/2)2-r2 • All it needs now is to
compute a starting point and
• Thus, dnew=dold+2xp+3, and we are set
the increment in case of E is E
ΔE=2xp+3.
• If instead d³0, then SE is M ME
chosen, and the next SE
midpoint will be incremented MSE
by"
dnew=F(xp+2,yp-3/2)="
(xp+2)2+(yp-3/2)2-r2
Circle rasterization

PROCEDURE ELSE
MidpointCircle(radius, BEGIN /* select SE */
value: integer); d:=d+2*(x-y)+5;
var x, y: INTEGER; d:REAL x:=x+1; y:=y+1
BEGIN END
x:=0; y:= radius; d:=5/4/ WritePixel(x,y,value);
radius;
END /* While */
DrawPixel(x,y,value);
END
WHILE y>x DO
BEGIN
IF(d<0) THEN
BEGIN /* select E */
d:=d+2*x+3;
x:=x+1;
END
Circle drawing

• Also this algorithm can be integerized and perfectioned


• This by using second order differences
• Note that ellyppses can be drawn in a similar way
Higher order curves

• Suppose we want to rasterize a higher order curve: "


x=f(t) y=g(t) (t ∈[0,1])
Higher order curves
• Usually, hardware companies
would simply subdivide the
interval parameter into equal
parts (0, 1/n, 2/n …,1)
• Then evaluate the curve at these
parameter values
• Finally plot the polyline of the
points
• Prone to miss detail of the curve
Higher order curves
• A better method is to use
adaptive steps
• Consider three consecutive
samples Pi-1PiPi+1
• If the distance δ is bigger than a
certain threshold, then I simply Pi
half the step
• If it is smaller, then I try doubling
the step δ
Pi+1
Pi-1
End

+++ Ende - The end - Finis - Fin - Fine +++ Ende - The end - Finis - Fin - Fine +++

You might also like