Computer Graphics3
Computer Graphics3
3/5/17
Koushik Dutta
Department of Computer Science
Asutosh College, Kolkata
koushik.it.22@gmail.com
1
DISPLAY HARDWARE
3/5/17
Liquid Crystal Display (LCD)
Plasma panels
Thin-film electroluminescent display
Light-emitting diodes (LED)
Hard-Copy Devices
Ink-jet printer
Laser printer
Film recorder
Electrostatic printer
Pen plotter 2
CATHODE RAY TUBE (CRT)
The primary output device in a graphical system is the
video monitor. The main element of a video monitor is the
3/5/17
Cathode Ray Tube (CRT), shown in the following
illustration.
The operation of CRT is very simple:
3. When the beam hits the screen, the phosphor emits a small
spot of light at each position contacted by the electron beam.
3
4. It redraws the picture by directing the electron beam back
over the same screen points quickly.
CATHODE RAY TUBE (CRT)
3/5/17
4
LIQUID CRYSTAL DISPLAY (LCD)
3/5/17
5
LIGHT-EMITTING DIODE (LED)
3/5/17
6
RASTER GRAPHICS
3/5/17
7
FRAME BUFFER
3/5/17
8
FRAME BUFFER REFRESH
Refresh Rate
3/5/17
Usually 30~75 Hz
9
COLOR FRAME BUFFER
3/5/17
255 150 75 0
255 255
150 150
75 75
0 0
255 255
150 150
75 750 0
255 150 75 0
255 255
150 150
75 750 0
255 150 75 0
255 255
150 150
75 750 0
255 150 75 0
255 255
150 150
75 750 0 Blue channel
Green channel
255 150 75 0
Red channel
10
COLOR CRT
3/5/17
11
RASTER SCAN DISPLAY
CRT provide the raster-scan display, based on television
technology.
The electron beam is swept across the screen, one row at a time
3/5/17
from top to bottom. As the electron beam moves across each row,
the beam intensity is turned on and off to create a pattern of
illuminated spots.
3/5/17
Random scan monitors draw a picture one line at a time and
for this reason are also referred to as vector displays.
3/5/17
commands in an area of memory referred to as the refresh
display file. Sometimes the refresh display file is called the
display list, display program, or simply the refresh buffer.
15
3/5/17
16
OUTPUT PRIMITIVES
Points
3/5/17
Lines
DDA Algorithm
Bresenhams Algorithm
Polygons
Scan-Line Polygon Fill
Inside-Outside Tests
Boundary-Fill Algorithm
Antialiasing
17
POINTS
3/5/17
Set the bit value(color code) corresponding to a specified
screen position within the frame buffer
y
setPixel (x, y)
x
18
Q:From
Whata is
geometry
a pixel? point of view,
A square or aapoint?
pixel is a point. Q: Where is (2,1)?
WHAT IS A PIXEL
3
3/5/17
2
19
0 1 2 3 4 5
But when we think about images, a pixel is a rectangle.
Q: Where is (2,1)? A. The center of a pixel
3/5/17
2
0
20
0 1 2 3 4
LINES
3/5/17
DDA, Bresenhams line algorithms
Jaggies
= Aliasing
21
DRAW A LINE FROM 0,0 TO 4,2
How do we choose between 1,0 and 1,1? What would be a good heuristic?
3/5/17
(4,2)
2
(0,0)
0 22
0 1 2 3 4
LETS DRAW A TRIANGLE
(0,2) (4,2)
3/5/17
2
(2,0)
0 23
0 1 2 3 4
THE IDEAL LINE
(17,8)
What do we want?
3/5/17
Continuous
appearance
Uniform thickness
and brightness
Pixels near the ideal
line are on
Speed (2,2)
3/5/17
where m represent the slope of the line, b as y intercept. Given in
the two line segment (x1, y1) and (x2, y2) and m, b is calculated
y 2 y1
m
x2 x1
b y1 mx1
y m.x
25
SLOPE-INTERCEPT METHOD
y
m
x
3/5/17
m 1 thenx can be set proportional to small horizontal
deflection voltage and the corresponding vertical deflection is
then set proportional to y
m 1 y
then can be set proportional to small
vertical deflection voltage and the corresponding horizontal
deflection is then set proportional to x
3/5/17
nearest pixel to the line at each sampled.
(0,9)
(17,8)
(2,2)
27
(0,0) (18,0)
DDA ALGORITHM
3/5/17
0 < Slope <= 1
Unit x interval = 1
y2
y1
x1 x2
yk 1 yk m
28
DDA ALGORITHM
3/5/17
0 < Slope <= 1
Unit x interval = 1
Slope > 1 y2
Unit y interval = 1
y1
x1 x2
1
xk 1 xk
m 29
DDA ALGORITHM
3/5/17
0 < Slope <= 1
Unit x interval = 1
Slope > 1 y1
Unit y interval = 1
y2
-1 <= Slope < 0
Unit x interval = -1
x1 x2
yk 1 yk m
30
DDA ALGORITHM
3/5/17
Slope >= 1
Unit x interval = 1
3/5/17
int dx = x1 x0, dy = y1 y0, steps, k;
float xrncrement, yIncrement, x = x0, y = y0;
3/5/17
skills for implementation.
2. It is a faster method for calculating pixel positions than the
direct use of equation y = mx + b. It eliminates the
multiplication in the equation by making use of raster
characteristics, so that appropriate increments are applied in
the x or v direction to find the pixel positions along the line
path.
Cons:
3/5/17
in unit intervals and at each step choose between two different
y coordinates.
3/5/17
y at sampling position xk
y m xk 1 b
Difference
d1 y yk m xk 1 b yk yk+1 d2
d 2 yk 1 y yk 1 m xk 1 b d1
d1 d2 < 0 (xk+1, yk)
yk
d1 d2 > 0 (xk+1, yk+1) xk xk+1
Decision
d1 d 2
pk xparameter
2y xk 2x yk 2y x 2b 1 35
2y xk 2x yk c
BRESENHAMS ALGORITHM(CONT.)
3/5/17
Decision parameter
pk 1 pk 2y xk 1 2x yk 1 c 2y xk 2x yk c
2y xk 1 xk 2x yk 1 yk
xk 1 xk 1 pk 1 pk 2y 2x yk 1 yk
Where, yk+1 yk is either 0 or 1 depending on the sign of pk.
Decision parameter of a starting pixel (x0, y0)
p0 2y x0 2x y0 2y x 2b 1
2y x0 2x mx0 b 2y x 2b 1
2y x0 2y x0 2bx 2y 2bx x 36
p0 2y x
BRESENHAMS ALGORITHM(CONT.)
3/5/17
Step 1: Input the two line endpoints and store the left end point in (x0,
y0 )
Step 2: Load (x0, y0) into the frame buffer; that is, plot the first point
Step 3: Calculate constants x, y, 2y, and 2y 2x, and obtain the
starting value for the decision parameter as
p0 2y x
Step 4: At each xk along the line, start at k =0, perform the following
test:
If pk < 0, the next point to plot is (xk+1, yk) and
pk 1 pk 2y
Otherwise, the next point to plot is (xk+1, yk+1) and
pk 1 pk 2y 2x
37
Repeat the step 4 in x times
FRAME BUFFER ADDRESS
CALCULATION
3/5/17
the frame-buffer array is addressed in row-major order and
that pixel positions vary from (0. 0) at the lower left screen
corner to (xmax, ymax) at the top right corner (Fig. ). For a
bilevel system (1 bit per pixel), the frame-buffer bit address
for pixel position (x, y) is calculated as
38
addr ( x, y ) addr (0,0) y ( xmax 1) x
FRAME BUFFER ADDRESS
CALCULATION
Moving across a scan line, we can calculate the frame-buffer
address for the pixel at (x + 1, y) as the following offset from
3/5/17
the address for position (x, y):
addr ( x 1, y ) addr ( x, y ) 1
39
CIRCLE GENERATING ALGORITHM
Drawing a circle on the screen is a little complex than drawing
a line. There are two popular algorithms for generating a circle:
3/5/17
Bresenhams Algorithm and Midpoint Circle Algorithm.
These algorithms are based on the idea of determining the
subsequent points required to draw the circle.
3/5/17
y yc r 2 ( xc x) 2
3/5/17
x xc r cos y yc r sin
3/5/17
approximate the circular path.
3/5/17
inside or outside the circle boundary.
3/5/17
between pixels near the circle path x2+y2-r2=0
at each sampling step. yk
Here, 0<Slope<-1 yk -1 midpoint
After the pixel (xk, yk) is displayed,
next which pixel is decided to plot in
column xk+1? xk xk+1 xk+2
(xk+1, yk) or (xk+1, yk-1)
2
MIDPOINT CIRCLE
ALGORITHM(CONTD..)
Successive decision parameters are obtained using
incremental calculations. We obtain a recursive expression
for the next decision parameter by evaluating the circle
3/5/17
function at sampling xk 1 1 xk 2
1
Pk 1 f circle ( xk 1 1, yk 1 )
2
1
[( xk 1) 1]2 ( yk 1 ) 2 r 2
2
Or
pk 1 pk 2( xk 1) ( yk21 yk2 ) ( yk 1 yk ) 1
46
MIDPOINT CIRCLE
ALGORITHM(CONTD..)
3/5/17
also be done incrementally
2x 2x 2 2 yk 1 2 yk 2
k 1 k
3/5/17
( x0 , y0 ) (0, r )
2. Calculate the initial value of the decision parameter as
5
p0 r
4
3. At each xk position, starting at k=0, perform the following test: If
pk<0, the next point along the circle centered on (0,0) is (xk+1, yk)
and pk 1 pk 2 xk 1 1
otherwise, the next point along the circle is (xk+1, yk-1) and
pk 1 pk 2 xk 1 1 2 yk 1
3/5/17
Scan-line fill
algorithm
Inside-Outside tests
Boundary fill
algorithm
11
1 2 3 4 5 6 7 8 9 10 5 6 7 8 9
4 3 1 2
49
SCAN-LINE POLYGON FILL
3/5/17
y : intersection edges are opposite sides
y : intersection edges are same side
y 1 2
2
y 1 1
50
INSIDE-OUTSIDE TESTS
Area-filling algorithms and other graphics processes often need
to identify interior regions of objects
3/5/17
Self-Intersections
Odd-Even rule
exterior
Nonzerowinding
number rule
interior
51
BOUNDARY-FILL ALGORITHM
Proceed to Neighboring Pixels
3/5/17
4-Connected
8-Connected
52
ANTIALIASING
Aliasing
3/5/17
Undersampling: Low-frequency sampling
original
sample
reconstruct
f s 2 f max
Nyquist sampling frequency: xcycle
Nyquist sampling interval:
x s
2 53
ANTIALIASING (CONT.)
Supersampling (Postfiltering)
3/5/17
Pixel-weighting masks
Area Sampling (Prefiltering)
Pixel Phasing
Shift the display location of pixel areas
Micropositioning the electron beam in relation to
object geometry
54
SUPERSAMPLING
Subpixels
3/5/17
Increase resolution
22
(10, 20): Maximum Intensity
21
(11, 21): Next Highest Intensity
(11, 20): Lowest Intensity
20
10 11 12
55
SUPERSAMPLING
Subpixels
3/5/17
Increase resolution
22
(10, 20): Maximum Intensity
21
(11, 21): Next Highest Intensity
(11, 20): Lowest Intensity
20
10 11 12
56
PIXEL-WEIGHTING MASKS
3/5/17
Center of a Pixel Area
1 2 1
2 4 2
1 2 1
57
AREA SAMPLING
3/5/17
Area of Overlap of Pixel
2 adjacent vertical (or horizontal) screen grid lines
trapezoid
22
20
58
10 11 12
3/5/17
59