You are on page 1of 27

Chapter 4

Attributes of output primitives


Contents
 Attributes of
 Line
 Circle/Ellipse

 Fill

 Color tables
 Anti aliasing of primitives and area
Line attributes
 Thick
 Multiple lines (covering adjacent pixels) drawn
 This can be done by plotting pixels on the line and
additional pixels
 Dash
 n pixels on the line plotted and next n pixels not plotted
and so on
 First and last pixel should be plotted

 Dotted
 Plot alternate pixels. Cover last point
 Draw short stretches of dash
Circle/Ellipse attributes
 Thick
 Two concentric circles can be drawn and area in
between can be filled
 As you plot pixels on the circle some adjacent pixels
can be plotted too
 Dash
 n pixels on the plotted and next n pixels not plotted
 Arc
 Beginning and ending angles of the arc specified and
polar coordinates are used to plot points on the arc
Fill attributes
 Fill styles
 Hollow
 Solid

 Pattern

 Hatch

 Edge type –independent of fill attributes


Line attributes
 Thick line
 Case 1: line has abs slope <1 then x varies more than y
 If (x1, y1) is the pixel plotted then plot also (x1, y1-1)
and (x1, y1+1) – one pixel up and one down
 Case 2: line has abs slope >= 1 then y varies more
than x
 If (x1, y1) is the pixel plotted also plot (x1-1 ,Y1),
(x1+1, y1) – one pixel left and one right
 Case 3: For horizontal line for every (x1, y1) also plot
(x1, y1-1) and (x1,y1+1). Similar procedure for vertical
line
Line attributes
 Thick line example – parameters: end points and thickness
 Suppose the end points are (20,10) and (28, 15)
 Points on the line and additional points are given here (if
thickness is 3 pixels-also called width)
 Points (20,10) (21,11) (22,11) (23, 12)
(24, 13) (25, 13) (26, 14) (27, 14)
(28, 15)
 Also plot (20, 9), (20,11), (21, 10), (21, 12), (22, 10), (22,
12), 923, 11), (23, 13), 924, 12), (24, 14), (25, 12), (25, 14),
(26, 13), (26, 15), (27, 13), (27, 12), (28, 14), (28, 16)
 Note that each pixel in the additional points is unique and
does not appear in the list of points on the line
Line attributes
 Dash line – parameters: end points and length of
dash
 Suppose the end points are (12, 24) and (22, 20)
 The number of pixels is 11
 Suppose the length of dash is 4
 Points (12, 24), (13, 24), (14, 23), (15, 23) are
plotted. Points (16, 23), (17, 22), (18, 22), (19, 21)
are generated by the algorithm but not plotted
and points ((20, 21), (21, 21), (22, 20) are plotted
Line attributes
 Dotted line –parameters: end points and
size of dot
 Suppose the end points are (12, 24) and (8,
30)
 Size of dot be 2

 Plot (12, 24), (12, 25), find but not plot (11,
26), (10, 27), plot (10, 28), (9, 29), (8, 30)
Line attributes
dashline(xa, ya, xb, yb, c, d)
dx=abs(xb-xa), dy=abs(yb-ya)
d1=2*dy, d2=2*dy-2*dx, p= 2*dy-dx
If xa < xb, xinc=1 endif If xa=xb, xinc=0 endif If xa > xb, xinc=-1 endif
If ya < yb yinc=1 endif If ya=yb, yinc=0 endif If ya > yb, yinc=-1 endif
x=xa, y=ya, setpixel(x, y, c)
ctr1=1, ctr2=0
For i=1 to dx-1 in steps of 1
x=x+xinc
If p>=0 then y= y+yinc, p=p+d2
Else p=p+d1 Endif
If ctr1 0 then
setpixel(x, y, c), ctr1=ctr1+1
Else ctr2=ctr2+1 Endif
If ctr1=d+1 then ctr1=0, ctr2=1
If ctr2=d+1 then ctr2=0, ctr1=1
End for
setpixel(x,y,c)
setpixel(xb, yb, c)
End dashline
Line attributes
thickline(xa, ya, xb, yb, c, 3) //abs m <1
dx=abs(xb-xa), dy=abs(yb-ya)
d1=2*dy, d2=2*dy-2*dx, p= 2*dy-dx
If xa < xb, xinc=1 endif If xa=xb, xinc=0 endif If xa > xb, xinc=-1
endif
If ya < yb yinc=1 endif If ya=yb, yinc=0 endif If ya > yb, yinc=-1
endif
x=xa, y=ya, setpixel(x, y, c), setpixel(x,y-1,c), setpixel(x, y+1, c)
For i=1 to dx in steps of 1
x=x+xinc
If p>=0 then y= y+yinc, p=p+d2
Else p=p+d1 Endif
setpixel(x, y, c), setpixel(x,y-1,c), setpixel(x, y+1, c)
End for
End thickline
Circle attributes
 Thick circle
 1/8 of the circle is generated from (0,r). Here x
varies more than y. If (x1, y1) is a plotted by
algorithm also plot (x1, y1-1) and (x1, y1+1).
However for the symmetrical point (y1, x1) plot
additional two points (y1-1, x1) and (y1+1, x1).
Note that (y1, x1) is in the region where y
varies more than x. Do similar additional point
plots for other parts of the circle.
Circle attributes
thickcircle (h,k,c,3)
x=0, y=r, p=1-r
setpixel(x+h, y+k, c), setpixel(x+h, y+k-1,c), setpixel(x+h, y+k+1)
setpixel(x+h, -y+k, c), setpixel(x+h, -y+k-1,c), setpixel(x+h, -y+k+1)
setpixel(y+h, x+k, c), setpixel(y+h-1, x+k, c), setpixel(y+h+1, x+k, c)
setpixel(-y+h, x+k, c), setpixel(-y+h-1, x+k, c), setpixel(-y+h+1, x+k, c)
while (x<=y)
x=x+1
if p>=0 then y=y-1, p=p+2x-2y+1,
else p=p+2x+1
endif
setpixel(x+h, y+k,c ), setpixel(x+h, y+k-1,c ), setpixel(x+h, y+k+1,c)
setpixel(y+h, x+k,c), setpixel(y+h-1, x+k,c), setpixel(y+h+1, x+k,c)
setpixel(x+h, -y+k,c), setpixel(x+h, -y+k-1,c), setpixel(x+h, -y+k+1,c)
setpixel(y+h, -x+k, c), setpixel(y+h-1, -x+k, c), setpixel(y+h+1, -x+k, c)
setpixel(-x+h, -y+k,c), setpixel(-x+h, -y+k-1,c), setpixel(-x+h, -y+k+1,c)
setpixel –y+h, -x+k, c), setpixel –y+h-1, -x+k, c), setpixel –y+h+1, -x+k, c)
setpixel(-x+h, y+k,c), setpixel(-x+h, y+k-1,c), setpixel(-x+h, y+k+1,c)
setpixel (-y+h, x+k, c), setpixel (-y+h-1, x+k, c), setpixel (-y+h+1, x+k, c)
endwhile
Circle attributes
 Arc
 Is portion of a circle. Difficult to specify end
points on the arc
 Assuming that angles are measured from
positive x axis in anti clock wise direction,
user inputs the beginning and ending angle
of the arc
 Points on the arcs are generated using polar
coordinates of circle
Circle attributes
arc(h, k, r, c, a1, a2)
for phi=a1 to a2 in steps of 
x=round(r*cos(phi)), y=round(r*sin(phi))
setpixel(x+h, y+k, c)
endfor
end arc
Color table
 Frame buffers have RGB values of each pixel or codes of colors
corresponding to pixels
 The table of codes is called color lookup table or video lookup
table
 Suppose for a graphics system each color has one bit, (frame
buffer has three bits per pixel) the color lookup table for such
system is given here
 Here there is no reduction in frame buffer size even with codes

Code 0 1 2 3 4 5 6 7
RGB 000 001 010 011 100 101 110 111
Color black blue green cyan red magenta yellow white
Color table
 In the example of 7 colors, first bit controls red gun, middle
bit controls green gun and right bit controls blue gun
 Adding more bits per pixel will increase the number of color
choices
 With 6 bits per pixel 2 bits are allotted for each color
component, giving 4 intensity settings (4 shades on display
device) to each color
 Total of 64 colors are available to each pixel
 For a full color system (24 bits- one byte per color
component) a screen resolution of 1024 x 1024 requires 3
megabytes for frame buffer
 Color tables provide extended color capabilities without
large size frame buffer
Color table
Display device
Color table

0
1
196

196 2081 0000000000001000000100001

255
Color table
 Systems using this particular color table would allow user to select any of
256 colors in the table for simaltaneous display
 Whereas the full color system has 17 million colors

 17 million to 256 colors is not a serious restriction, since not more than
256 are used at a time on the display device
 There is advantage in using table like this since it reduces size of frame
buffer
 Some graphics system uses 9 bits per pixel in the frame buffer allowing
512 colors for display at a time
 For most applications 256 to 512 colors at a time is sufficient

 setColourRepresentation (ws, ci, colorptr) will create a table in PHIGS


application programs
 ws-workstation device, ci-color index (color table position number),
colorptr-is the rgb value
Gray scale monitors
 Colors in the table are values in the range of 0 to 1 for
each component
 For gray monitors these values are gray values computed
as 0.5(min(r,g,b)+max(r,g,b)
ws=1 ws=2
ci ws=1
color ci ws=2color
0 (0, 0,0) 0 (1, 1, 1)
1 (0, 0, 0.2) 1 (0.1, 0, 0.3)
. . . .
. . . .
196 (0, 0.00000008, 0.00000033)
. .
. .
Area fill attributes
 Types of fill are
 Hollow with border
 Solid

 Pattern

 First two types are already dealt with


 Fill patterns selected using

setInteriorStyleIndex(pi)
 pi specifies a table position

 The following lines will fill area with pattern 1

setInteriorStyle(pattern)
setInteriorStyle Index(1)
fillArea(n, points)
Fill attributes
 Fill style patters for individual workstations can be created
using
 setPatternRepresentation(ws, pi, nx, ny, cp)

 setPatternRepresentation(1, 1, 2, 2, cp) will use pattern 1


for work station 1
pi cp pi cp
1 4 0 2 2 1 2
0 4 1 2 1
1 1 2
Entries in cp are color codes in the code table for that work
station
Fill attributes
 It is required to specify size of fill pattern
setPatternSize(dx, dy)
 dx, dy give the coordinate width and height of
the array cp
 A reference position for the starting pattern fill
is done using the function
setPatternReferencePoint(position)
 Position fixes the lower left corner of the
pattern array cp
Antialiasing
Objects displayed will have jagged or staircase effect – sometimes
This is because the actual coordinates are floating point and these are integerized and

plotted on the device


This distortion seen is called aliasing

Methods to improve look of the object on the display are called antialiasing methods

One way is to increase sampling

Instead of calculating y at every integral x, y may be calculated for more x (atleast twice the

number of x – called Nyquist sampling theory) and round of (x, y) to integers


This is called super sampling or post filtering. You are assuming that the screen has more

coordinate addresses than actually available


We can use the multiple sample points around a pixel to determine intensity level for that

pixel
In this method not all positions on the line will have same intensity

Super sampling straight lines for gray scale display- find sub pixels along the lie path.

Intensity value for the pixel correspond to the count


Area sampling- determine pixel intensity by calculating the areas of overlaps of each pixel

with the object boundary


Pixel weighting masks- super sampling algorithms can give more weight to sub pixels near

the center of the of a pixel area


Pixel phasing- staircase effect can be handled by adjusting (micro positioning the electron

beam) electron beam to more nearly approximate positions of the crystal


Questions
1. Discuss line attributes and write
algorithms
2. Discuss circle attributes and write
algorithms
3. Write about fill area primitives and anti
aliasing
Lab problems
1. Implement
Thick line and circle, dash line and circle,
fill area with simple pattern
Circle attributes
 Thick circle

You might also like