attributes of graphics primitives hearn & baker chapter 4 some slides are taken from robert...
TRANSCRIPT
![Page 1: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/1.jpg)
Attributes of Graphics Primitives
Hearn & Baker Chapter 4Some slides are taken from Robert Thomsons notes.
![Page 2: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/2.jpg)
OVERVIEW
• Color• Point and line attributes• Curve attributes• Fill-area attributes• Scan-line fill• Fill-area methods• Character attributes• Antialising
![Page 3: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/3.jpg)
Attributes
• Attribute parameter is a parameter that affects the way a primitive is to be displayed.
• Some attribute parameters determine the fundamental characteristics of a primitive.– Color– Size
• For now, we consider only those attributes that control the basic display properties of primitives.– Lines can be dotted or dashed, fat or thin, and blue or
orange. – Areas might be filled with one color or with a
multicolor pattern.
![Page 4: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/4.jpg)
Color
• Basic attribute for all primitives.• RGB color components
– Either store the color code into frame buffer– Or use index values to reference the color-table
entries.
![Page 5: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/5.jpg)
Color tables
![Page 6: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/6.jpg)
Line attributes
• Line width– Plot a vertical span of pixels in each column (slope <=1)– Line width is equal to number of pixels in each column
![Page 7: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/7.jpg)
Line width
• Problem – Width of a line
depends on the slope. 450 line will be thinner by a factor of 1/sqrt(2)
![Page 8: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/8.jpg)
Line width
• Another problem: line ends– Horizontal or vertical line ends regardless of slope
• Solution– Add line caps
![Page 9: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/9.jpg)
Line Attributes
Butt cap
Round cap
Projecting square capMiter join
Round Join
Bevel join
![Page 10: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/10.jpg)
Pen and Brush Options
• Using packages, lines can be displayed with pen or brush selections.– shape, size, and
pattern. • Some possible
pen or brush shapes
![Page 11: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/11.jpg)
• The shapes can be stored in a pixel mask– I.e., a rectangular pen can be implemented with the following mask
![Page 12: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/12.jpg)
Area Filling
How can we generate a solid color/patterned polygon area?
![Page 13: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/13.jpg)
Triangle fill : color Interpolation
span
C1
C3
C2
C5
C4scan line
C1 C2 C3 specified by glColor or by vertex shadingC4 determined by interpolating between C1 and C3
C5 determined by interpolating between C2 and C3
interpolate between C4 and C5 along span
![Page 14: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/14.jpg)
Edge equations
• An edge equations is the equations of the line defining the edges– Each line defines 2 half-spaces
![Page 15: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/15.jpg)
Edge equations
• A triangle can be defined as the intersection of three positive half-spaces
A1x + B1y + C1 < 0
A2 x + B
2 y + C2 < 0
A 3x
+ B 3
y +
C 3 <
0
A1x + B1y + C1 > 0
A 3x
+ B 3
y +
C 3 >
0 A2 x + B
2 y + C2 > 0
![Page 16: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/16.jpg)
Edge Equations
+++-
--
So…simply turn on those pixels for which all edge equations evaluate to > 0:
Lots of implementation details to consider….
![Page 17: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/17.jpg)
![Page 18: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/18.jpg)
(Line Walking approach)
(When deciding if scan-line is inside the polygon)
![Page 19: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/19.jpg)
![Page 20: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/20.jpg)
Area Filling (Scan line Approach)
• For each scan line (increasing y order)
(1) Find intersections (the extrema of spans)(2) Sort intersections (increasing x order)(3) Fill in between pair of intersections
![Page 21: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/21.jpg)
Data Structure
![Page 22: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/22.jpg)
![Page 23: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/23.jpg)
![Page 24: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/24.jpg)
![Page 25: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/25.jpg)
![Page 26: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/26.jpg)
8
![Page 27: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/27.jpg)
![Page 28: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/28.jpg)
AF'
FE'
ED
AB
ABCD
CB
![Page 29: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/29.jpg)
Area Filling – for irregular areas
• Paint the interior point by point out to the boundary.
• Pixel Adjacency
8-connected
4-connected
![Page 30: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/30.jpg)
Area Filling – for irregular areas
• Boundary-Fill Algorithm– starting at a point inside the figure and painting
the interior in a specified color or intensity.
Used in interactive painting packages
Like identifying connected components
![Page 31: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/31.jpg)
![Page 32: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/32.jpg)
the fill
![Page 33: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/33.jpg)
Boundary Filling
![Page 34: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/34.jpg)
![Page 35: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/35.jpg)
Fill pattern
![Page 36: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/36.jpg)
Fill pattern
![Page 37: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/37.jpg)
Hollow display of a polygon
glPolygonMode (face, displayMode);
Face: GL_FRONT, GL_BACK, GL_FRONT_AND_BACK
displayMode : GL_LINE no fillGL_POINTS vertex points onlyGL_FILL fill (default)
glColor3f (0.0, 1.0, 0.0); \\blue fill\\generate polygon
glColor3f (1.0, 0.0, 0.0); \\red lineglPolygonMode (GL_FRONT, GL_LINE); \\generate polygon
![Page 38: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/38.jpg)
Aliasing in CG
Wh
ich
is th
e
bette
r?
![Page 39: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/39.jpg)
Aliasing in Computer Graphics
• Digital technology can only approximate analogue signals through a process known as sampling
• The distortion of information due to low-frequency sampling (undersampling)
• Choosing an appropriate sampling rate depends on data size restraints, need for accuracy, the cost per sample…
• Errors caused by aliasing are called artifacts. Common aliasing artifacts in computer graphics include jagged profiles, disappearing or improperly rendered fine detail, and disintegrating textures.
![Page 40: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/40.jpg)
The Nyquist Theorem
The sampling rate must be at least twice the frequency of the signal or aliasing occurs ( twice the frequency of the highest frequency component)
![Page 41: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/41.jpg)
Aliasing
• In order to have any hope of accurately reconstructing a function from a periodically sampled version of it, two conditions must be satisfied: – The function must be bandlimited. – The sampling frequency must be at least twice the
maximum frequency of the function.
Satisfying these conditions will eliminate aliasing.
![Page 42: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/42.jpg)
Polygon Aliasing
• Aliasing problems can be serious for polygons– Jaggedness of edges– Small polygons neglected– Need compositing so color
of one polygon does not
totally determine color of
pixel
All three polygons should contribute to color
![Page 43: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/43.jpg)
Antialiasing
• Antialiasing methods try to combat the effects of aliasing.
• Two major categories of antialiasing techniques – prefiltering
– postfiltering.
![Page 44: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/44.jpg)
Prefiltering
• Central idea is to consider the pixel as an area, not a point, and calculate the pixel colour value from a weighted sum of the colours present inside the area.– e.g. In line-drawing, think of the line as a long
rectangle, not the minimal line of pixels found by Bresenham’s method.Pixels partly covered by this rectangle would be shaded grey
![Page 45: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/45.jpg)
![Page 46: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/46.jpg)
Anti-aliasing through area averaging
How can we make the line less jagged and avoid aliasing?
Bresenham's algorithm is optimal for drawing the line if you only have 2 colors. It chooses the closest set of pixels to the line.
However, if you have more than 2 colors, you can color the pixels differently depending on the distance to the line.Suppose each pixel is square, 1 unit high and 1 unit wide.Suppose the line is 1 unit in width.
Shade each pixel according to the percentage of that pixel covered by the line.
![Page 47: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/47.jpg)
Antialiasing by Area Averaging
• Color multiple pixels for each x depending on coverage by ideal line
without antialiasing
antialiased
magnified
![Page 48: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/48.jpg)
![Page 49: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/49.jpg)
Antialiasing (postfiltering)
• Postfiltering first supersamples the signal in its unfiltered form and then filters out the high frequency from the supersamples.
• Increase the sampling rate by treating the screen as if it had a finer grid resolution than is actually available
![Page 50: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/50.jpg)
(non-adaptive) Super-Sampling
• Split single pixel into sub-pixels.• Pixel’s final color is a mixture of sub-pixels’ colors. Simple method:
Sample at the middle of each sub-pixel. Then, pixel’s color is the average of the sub-pixels’ color.
Pixels Sub-divide into sub-pixels
![Page 51: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/51.jpg)
Super-Sampling a Zero-Width Line
Apply Bresenham’s algorithm at sub-pixel level
Sub-divide each pixel into sub-pixels, for example 4x4 sub-pixels
Each pixel can have a maximum of 4 colored sub-pixels
How many sub-pixels are colored?
0 0 0 4
2 4 4 0
2 0 0 0
Assign color
Fraction of pixel’s color to be line’s color
0.0 0.0 0.0 1.0
0.5 1.0 1.0 0.0
0.5 0.0 0.0 0.0
![Page 52: Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes](https://reader035.vdocuments.net/reader035/viewer/2022062409/5697bfa81a28abf838c992d0/html5/thumbnails/52.jpg)
Super-Sampling a Line with Non-Zero Width
A line that is one-pixel wide.For every pixel: Maximum number of sub-pixels inside line = 16
A sub-pixel is considered in if its lower-left corner is inside the line
Fraction of sub-pixels are in = fraction of color of the pixel should be line color
0 0 5/16 9/16
10/16 15/16 13/16 7/16
8/16 2/16 0 0