Title: ?? ?? H/W? S/W? ??? ???? ??? ???. ?? ??? ?????.
1? 7 ? ??
2??
- ??? ????? ????? ??? ??????
- ??? ??? ??? ??????
- ???? ??? ??????
- ??? ?? ?? ??? ?? ???? ??? ?????
- ???? ???? ????? ??????
- ?? ?? H/W? S/W? ??? ???? ??? ???. ?? ??? ?????.
- ??? ??
- ?? ??, ?? ???? ?? ??? ??? ???? ??? ??
37.1 4?? ?? ??
??? ?????? ???? ??
?? 7.1 ?? ??
47.1.1 ???
- ???? ?? ???? ???? ??? ???? ???? ??
- ???
- ???? ??? ??
- ???? ???? ?? ??. ?) ??
- ???? ??? ?? ??????? ???? ??? ??? ???? ??? ??.
57.1.2 ???? ??
- ???? ???
- ?? ??? ??? ??? ???? ??
- ???? ?? ?? ?? ??
- ???, ??, ????, ???, ??
- ???? ?? ??
- ?? ?? ??
- ?? ??? ???
67.1.2 ???? ??
- ??(Clipping)
- ??? ?? ?? ?? ??? ?? ??? ???? ? ?? ??? ???.
- ?? ??(Hidden Surface Removal)
- ??? ?? ?? ??? ?????? ?? ??? ??? ??? ? ??.
- ??? ?? (Visible-surface determination)
- ???
- ?? ??? ??? ???
- 6.3.3 ?? (p231).
77.1.3 ????
- ????(rasterization) ?? ????(scan conversion)
- 2?? 3?? ??? ???? 3?? ??? ??? ? ? 2??? 2?? ???
????. ????? ??? ???? ??? ???? ?? - ??? ???? ???? ????? ??? ?.
- Frame Buffer ? ??? ???? ???. OpenGL? ???? ???
???? ????? ?? ??? ??? ? ??. (10?? ??)
87.1.4 ??(Display)
- Frame Buffer? ?? ???? ???? CRT? ???? ?? (?????
????) - ?? ?? (Aliasing)
- Anti-aliasing ???? ??
- ??? ? ??
97.1.5 ?? ?? ??
- ????(image-oriented)? ?? ??(object-oriented)
- ?? ??
- For (each object) render(object)
- ??? ??? ??
- ?? 7.2
- ?? ?? ???? ? ??? ????? ???? ??? ??
- ?? ??? ??, ?? ??? ??? ?? ?????? ?? ?? ????? ??.
- ?? ?? ??? ?? ??? ??? ?? ?? ?(chip)? ???? ???,
10?? 7.2 ?? ?? ??
117.1.5 ?? ?? ??
- ????(image-oriented)
- For (each pixel) assign_a_color(pixel)
- ? ??? ???, ?? ???? ?? ??? ? ??? ?? ??? ? ? ?? ??
???? ?? ????? ????. - ???(Coherence)? ???? ???? ??.
127.2 ??? ??
- ??? ??? ??? ??? ???? ??? ???.
- ???
- ??(??) ???
- ?(???) ???
- ?? ???
- ??? ?? ???
- ???(??) ??
- ?? 7.3
??-????, ????
13?? 7.3 ?? ???
??
?????
??
?
??
14??? ??
- (1) ??? ??
- ?? ??? ??
- ???? ???
- ???? ?????
- ?? ??? ?? ?? ???? ??
- ?? ??? 2? ???? ??? ?? ???
- (2) ?? ??? ?? ???
- ??? ?? ?? ???? ?? ??? ??
15??(Viewport)??
- (3) ?? ???? ?? (Viewing Transformation)
- ?? 7.4
- Larry ? ??
16?? 7.4 ?? ??
17???? ?
18Windows, Viewports, and Clipping
19Windows and Viewports
Window
Interface Window
Viewport
Information outside the viewport is clipped away
20Terminology
- World Coordinate System (Object Space) -
Representation of an object measured in some
physical units. - Window - The rectangle defining the part of the
world we wish to display. - Screen Coordinate System (Image Space) - The
space within the image is displayed - Interface Window - The visual representation of
the screen coordinate system for window
displays (coordinate system moves with interface
window). - Viewport - The rectangle on the raster graphics
screen (or interface window for window
displays) defining where the image will appear.
(Default is usually entire screen or interface
window.) - Viewing Transformation - The process of going
from a window in world coordinates to a viewport
in screen coordinates.
21Viewing Transformation
Choose Window in World Coordinates
Clip to size of Window
Translate to origin
Scale to size of Viewport
Translate to proper position on screen (Interface
Window)
22Notes on Viewing Transformation
- Panning - Moving the window about the world
- Zooming - Reducing the window size
- As the window increases in size, the image in the
viewport decreases in size and vice versa - Beware of aspect ratio.
23Viewing Transformation Example
(10, 30)
(50, 30)
(0, 1)
(0.5, 1)
Viewport wanted
(0, 0.5)
(0.5, 0.5)
(10, 5)
(50, 5)
X scale 0.5/40 1/80
(0,0)
(1, 0)
1 0 0 0 1 0.5 0 0 1
1/80 0 0 0 1/50 0 0
0 1
1 0 -10 0 1 -5 0 0 1
1) Translate window to origin
2) Scale to correct size
3) Translate to proper coordinates
247.3 ?? ??(Clipping)
- ???(clipper) ?? ?? ?? ?? ? ??? ??? ?????? ????.
- ??(accepted), ??(rejected, culled)
- ??? ??? ?? ? ? ?? ? ??? ???? ??? ? ??.
- ???? ?? ??? ? ??.
- 3?? ?? ??? ?? ??
- 2?? ???? ?? ??
257.3.1 Cohen-Sutherland ??
- ??? ?? ?, ?? ??? ???? ????. ???? ?? ??? ???? ????
???. ?? ??? ??? - 3???? ?? ?? ??
- 2???? ??
- Larry ?? ??
26?? 7.5 ??? ??
27?? 7.6 ??? ??? ?? ??
28?? 7.7 Cohen-Sutherland ?????? ????? ??
29- o1outcode(x1,y1), o2outcode(x2,y2)
- Case 1 o1o20,
- trivially accept, ?? AB
- Case 2 o1?0, o20
- ?? CD, ??? ?? ? ?? ?? ?? ??
- Case 3 o1o2 ? 0
- Trivially reject
- ?? EF
- Case 4 o1o2 0
- ? ?? ?? ??
- ?? GH, ?? IJ ??, ??? ??? ???.
30Clipping
(xl, yt)
(xr, yt)
A point is visible if xl lt X lt xr and yb lt Y lt yt
(xl, yb)
(xr, yb)
- A line is visible if both of its end points are
in the window. - Brute Force Method - Solve simultaneous equations
for intersections of lines with window edges.
31Cohen-Sutherland Algorithm
- Region Checks Trivially reject or accept lines
and points. - Fast for large windows (everything is inside) and
for small windows (everything is outside). - Each vertex is assigned a four-bit outcode.
- Bit 1 lt-- sign bit of (yt-Y) -- point is
above window - Bit 2 lt-- sign bit of (Y-yb) -- point is
below window - Bit 3 lt-- sign bit of (xr-X) -- point is
to right of window - Bit 4 lt-- sign bit of (X-xl) -- point is
to left of window
32Cohen-Sutherland Clipping (cont.)
1001
1000
1010
Bit 1 Above Bit 2 Below Bit 3 Right Bit 4
Left
0001
0000
0010
0101
0100
0110
- A line can be trivially accepted if both
endpoints have an outcode of 0000. - A line can be trivially rejected if any
corresponding bits in the two outcodes are both
equal to 1. (This means that both endpoints are
to the right, to the left, above, or below the
window.)
33Clipping Lines Not Accepted or Rejected
- In the case where a line can be neither trivially
accepted nor rejected, the algorithm uses a
divide and conquer method.
D
Example
C
B
A
H
E
F
G
Line AD 1) Test outcodes of A and D --gt
cant accept or reject. 2)
Calculate intersection point B, which is
conceptually on the
window side of the dividing line. Form new line
segment AB and discard
the rest of the line because it is
above the window.
3) Test outcodes of A and B. Reject.
347.3.2 Liang_Barsky ??
35?? 7.8 ?? ??? ??? ?? ???? ??? ??
367.4 ??? ??
- 10??? ??? Antialiasing? ??(Compositing)? ???? ??
???? ??? ???? ??? ?? - Sutherland-Hodgeman ???? ??
37?? 7.9 ??? ?? ?? ??
??? ?? ???? ?? ??? ???? ??? ? ??? ???? ???
??????? ??? ??? ???
38?? 7.10 ??? ???? ??
?? ???(Concave)? ?? ??? ??? ??? ?? ??? ? ??.
39?? 7.11 ??? ??? ??
40?? 7.12 ??? ???? ??
?? ???(convex)? ??? ???? ??? ??? ??? ??? ?? ????
???. ?? ???? ?? ?? ?? ????? ??(tessellate) ? ?
??.
41?? 7.13 Blackbox??? ???
?? ??
42?? 7.14 ??? ?? ??
??? ?? ??
????
43?? 7.15 ??? ???? ???
44?? 7.16 ??? ???
??? ?? ??? ?
45? ?? ?? ??? ??
?? ????? ??
Out-gtin I, N
In-gtin N
In-gtout I
Out-gtout Nothing
Intersection I, Previous endpoint P, Next
Point N
46?? 7.17 ??? ?? ??? ?
47Polygon Clipping
- Polygons can be clipped against each edge of the
window one edge at a time. Window/edge
intersections, if any, are easy to find since the
X or Y coordinates are already known. - Vertices which are kept after clipping against
one window edge are saved for clipping against
the remaining edges. Note that the number of
vertices usually changes and will often increase.
48Polygon Clipping Algorithm
P4
P4
I2
I2
P3
I1
I1
P1
P2
P1
- The window boundary determines a visible and
invisible region. - The edge from vertex i to vertex i1 can be one
of four types - Exit visible region - save the intersection (I2)
- Wholly outside visible region - save nothing
- Enter visible region - save intersection and
endpoint(I1,P1) - Wholly inside visible region - save endpoint(P4)
49Polygon clipping issues
- The final output, if any, is always considered a
single polygon. - The spurious edge may not be a problem since it
always occurs on a window boundary, but it can be
eliminated if necessary.
50Pipelined Polygon Clipping
Clip Top
Clip Right
Clip Bottom
Clip Left
- Because clipping against one edge is independent
of all others, it is possible to arrange the
clipping stages in a pipeline. the input polygon
is clipped against one edge and any points that
are kept are passed on as input to the next stage
of the pipeline. - This way four polygons can be at different stages
of the clipping process simultaneously. This is
often implemented in hardware.
517.5 ?? ?? ??? ??
527.5.1 ?? ???
- ?? ???(bounding box) ?? ??(extent)
- ?? ???? ???? ???? ???? ??? ?? ?? ????.
- ?? ???? ???? ??? ???? ?? ? ??.
53?? 7.18 ???, ?? ???, ?? ???
54?? 7.19 ?? ????? ??
?? ???? y ???? ???? ??? ?? ??? ?? ??? ???? ??? ??
??
?? ???? ?? ?? ???? ?? ??? ???? ??? ?? ??? ????.
557.5.2 ??, ??, ???
?? 7.20 ?? ??
567.5.2 ??, ??, ???
- 2? ??? ?? ??? ???? ??? ????? ?? ??? ? ???
- ??? ?? ??? ???? ??? ??? ??? ?? ????, ???? ???
? ? ?? ??? ?? - ??? ???? ????, ??? ?? ????? ??? ?? ?? ?? ??? ??
? ??.
577.5.2 ??, ??, ???
- ???? ?? ? ?? ?? ??? ??
- ?? ??, ???? ??
- ?? ??? ??
- ???? ?? ?? ????? ??? ?? ???
- ??? frame buffer?? ??.
- ???? ??? ??
- OpenGL API? ?? ? ?? ??? ???.
587.5.3 ??? ???? ??
- ??? ????, ?? ??? ??? ??? ??? ???? ??.
- ??? ?? ?? raster ??? ??? ????.
- ??? ??? ??? ???? ?? ???? ??? ???? ?? ?? ??.
597.6 ?????? ??
- ?? ??? ?? ?? ??(bound volume)? ??? ???.
- 2?? ?? ????( Cohen-Sutherland, Liang-Barsky,
Sutherland-Hodgeman)? 3???? ?? ??? ? ??.
60?? 7.21 ????? ?? ??? ??
61?? 7.22 ????? Cohen-Sutherland ??
2???? 4 ?? ??? 3???? 6 ??? ????.
62?? 7.23 ??-????
2?? ??? ??? ??? ??. ??? ?? 3?? ?? ??? ??? ??
??. ??? ??? ?? ??
63??? ??? 6?? ??? 1?? ????? ????. ??? ?? ?? ??? ??
?? ? ?? ????? ?? ? ??.
64?? 7.24 ?? ??? ?? ??
65?? 7.25 ?? ??? ?? ??
66?? 7.26 ??? ?? ?? ??? ??
- ??? ?? ?, ?? ?? ??? ???? ??? ?? ??? ?? ??? ??
???? ???? ??? ?? ?? ??? ????. - ???, ??? ?? ??? ?, ????? ??? ???? ??(??? ??) ??
????? ??? ?? ??? ????. - ?? ??? ???? ?? ??? ? ? ??.
677.7 ?? ??
- ???? ?? ???? ???? ??? ??? ??? ?? ??? ??, ?? ??
???? ??? ???? ???? ??(?,??,???)? ?? ??. - ??? ???? ???? ??? ??? ???? ?? ?? ?? ??? ???? ??
??? ?? ?? ?? ???? ??? ? ??.
687.7.1 ?? ??? ???? ??
- Object space ? image space
- K?? ????? ??? ??? ????? ??? ??? ??
- ???? ? ?? ??? ?, ? ??? A? B? ????. (?? 7.27 ??)
- A? B? ?????? ??? ??? A? ????.
- B? A? ??? B? ????.
- A? B ?? ??? ??? A? B ?? ????.
- A? B? ????? ??? ? ???? ??? ??? ??? ???? ??.
- ?? ????
- ????? ?? ?? ???? ?? ??? ? ???.
69?? 7.27 ? ???
(a) B? A? ????? ??? (b) A? B? ????? ??? (c) A? B
?? ???. A? B ?? ????. (d) B? A? ??? ???.
70- ??? ??(ray)?? ??? ???.
- ??? ?? ??? ??? ??? ???.
- ?? 7.28 ??
- k? ???? ??? ???? ????? ??? ???? ????? ????,
- ???? ??? ?? ???? ?? ??? ???? ???. ????? ???? ???
???? ????. - ??? ???, ?? ??? nmk ? ???.
- ??? ?? ???? ?.
- ?? ???? ?? ??? ??? ???.
71?? 7.28 ???? ?? ??
727.7.2 ?? ??
- Back face culling
- ?? ?? ????? ???? ?? ?? ?? ????? ?????? ?? ??? ??
? ??. (? 50 ??)
73????(Backface culling)
74?? 7.29 ?? ??
V ? ???? ?? N ? ?? T? ??? ??? ???
??? ? ???? ??? ???. ??? ??
???? ??? ???.
75?? (front face ? ?? )
??? ?? ???? ?? ??? ? ??? ?? ??? ??.
??? ??
?? ???
???
C? ???? ??, ???? ???.
767.7.3 z-?? ????(1)
- ?? ????? ???? ?? ?? ????
- H/W ?? S/W? ???? ??, ????? ??? ???? ??
- ????? ???? ?????, ??? ?? ???? ??? ????? ?? ????.
- 7.9??? ???? ???? ??? ????? ??? ? ??.
- ??? ??(Frame Buffer)? ?? ??? ??(depth)? ????
buffer(z-buffer)? ????.
777.7.3 z-?? ????(2)
- ??? ??? ???? ??? ?? ??? ???? ?? ????.
- ? ?? ???? ???? ???? ??. ??? ?? ?? ??? ?????? ? ??
?? ???. - ??7.30 ??
- B? ???? ??? ??? ?? Z2? ??? A? ?? Z1 ?? ?? ??? ???
????. ??? A? ???? ??? ??? ???? ???.
78?? 7.30 z-?? ????
797.7.3 z-?? ????(3)
- ?? ??? ?? ??? ?????.
- ??? ??? ????? ??? ??.
- ??? ??? ??? ???? ??.
- ??? ????? ???? ???? ???? ?? ??? ??? ?????? ???
??? ? ??. ? ??? dl ?? ???? z-buffer ?? ????. - ? ??? z-buffer ??? ??, ? ?? ??? ?? ???
- ? ??? z-buffer ??? ???, z-buffer ? ?? ?? ????,
??? ??? ???? ??? ?? ??? ??? ???? ????. - Foley ?? ?? ??
80- Z-??.
- ???? z-buffer? ?? z?? ?? ??? ??
- ??? ???? ???? ?? ??? ??
81Depth Coherence(?? ???)
- 7.9?? ??? ????? ?????? ???? ???? ??????? ????.
- z1 ?? ?? ???? ????? ??, (x?x,y)??? z ?? z2 ?
z1? ?? 1?? ???? ?? ? ??. ?? -A/C ?? ??? ?????
??.
82?? 7.31 ??? z-?? ????
837.7.4 ?? ??? ?? ????
- Depth Sort Algorithm, Painters Algorithm
- ???? ?? ??
- ?? ?? ????
- ?? ???? ??? ??(?????? ?? ?) z ??? ?? ????.
- ??? ???? z ?? ??? ?? ? ???? ???? ???? ?? ?????
???? ????. - ?? z ??? ?????? (?, ??? ???) ? ???? ????.
- ?? ????? ? ???? ??? z?? ?? ??? ??? ? ?? ???? ??
?? ????? ??? ???? .
84?? 7.32 ?? ????
?? ??? ??? ??? ??? ????. ??? ?? ?? ?? ???? ??
???, ????? ??? ?? ?? ???? ?? ?? ???? ???? ???
???? ???. ?? ??? (back-to-front rendering)
85?? 7.33 ??? ??? z ??
86?? 7.34 x? y ???? ??? ?? ??
- ??? ?? x ??
- ??? ?? y ??
87?? 7.35 ?? ??? ?? ???
88- ??? P? ?? ???? ?? ??? ?? ??? ????. P? z-????? ???
z-?? ??? ?? ?? ??? Q? ????, P? Q? ?? ? ?? ???, Q?
??? ?? P? ?? ? ??? ???? ??. - 5?? ??? ??? ???? ?, ? ? ????? ???? P? Q? ?? ? ???
???? ?? ??. - ????? x-????? ??? ????
- ????? y-????? ??? ????
- Q ??? ??? P? ??? ?????
- P? ??? ??? Q? ??? ?????
- (x,y) ????? ????? ??? ?? ??? ????
- ? Foley ? ??
89- 5?? ??? ?? ???? ??? P? Q? ???? ???? ??? Q? P???
?? ??? ? ???? ????. ?? 1,2, 5? ?? ??? ??? ?? - 3 P ??? ??? Q? ??? ?????
- 4 Q? ??? ??? P? ??? ?????
- ?? 7.36? ?? 3.37? ???? ?? ??????? ?????. ??? ???
???.
90?? 7.36 ??? ??
91?? 7.37 ???? ???
927.7.5 ??? ????
- ????? ????? ???? ????? ?? ??? ??? ??? ?? ???? ??
?? ???? - ??? ????? ?? ?? ????? ??? ??
- ?? 7.38? ??
93?? 7.38 ??? ????(1)
??? i ??? A? ? a ?? ??. ? ?? ????? ??? ?? ???
????. ? b ?? ?? ???? ????? ??? ???. ??? B? ? c??
??. ? ?? ?????? ?? ??? ???. ? d?? ???? ??? ??
94?? 7.38 ??? ????(2)
??? j ??? A? ? a ?? ??. ? ?? ????? ??? ?? ???
????. ??? B? ? c ?? ???? ??? ????? ????? ? d? ??
??? ??? ????? ??.
957.8 ?? ??
- ???? ???? ??? ????? ??? ???? ??? ??
- ??
- ??? ???? ???.
- ? ?? ??? ??? ??? ? ??? ?? ???? ??.
- ?? ???? 2???? ?????, ?? ????? ???.
96Write_pixel(int ix, int iy, int value) value
index mode?? index, RGB mode??? 32 bit ?
(???) ix, iy ???
97?? 7.39 ??? ?????? ??
98DDA(Digital Differential Analyzer) ????
?? 7.40 DDA ????? ?? ??? ??
99DDA(Digital Differential Analyzer) ????
m? 1?? ? ??? ???? ??
m? ?? ?????? ???? ????.
for (ixx1, ixltx2, ix) ym write_pixel(x,
round(y), line_color)
100?? 7.41 ???? ? ??? ?? ??? ?? ??? ???
101?? 7.42 ??? DDA ????? ?? ??? ??
1027.9 Bresenham ????
- DDA? ??? ????? ??? ??? ??? ????. ??? ???? ??? ???
??? ??? ????
103?? 7.43 Bresenham ????? ?? ??
104?? 7.44 Bresenham ????? ?? ??
???? da-b dgt0 ???? ?? dgt0 ??? ??
105if
otherwise
What is ?
?? ?? ??? ??? ?? ??? ???? ????.
106?? 7.45 a ? b ? ??
107Design of Line and Circle Algorithms
108Basic Line and Circle Algorithms
- 1. Must compute integer coordinates of pixels
which lie on or near a line or circle. - 2. Pixel level algorithms are invoked hundreds
or thousands of times when an image is created or
modified. - 3. Lines must create visually satisfactory
images. - Lines should appear straight
- Lines should terminate accurately
- Lines should have constant density
- Line density should be independent of line length
and angle. - 4. Line algorithm should always be defined.
109Simple DDA Line AlgorithmBased on the
parametric equation of a line
- Procedure DDA(X1,Y1,X2,Y2 Integer)
- Var Length, I Integer
- X,Y,Xinc,Yinc Real
-
- Begin
- Length ABS(X2 - X1)
- If ABS(Y2 - Y1) gt Length Then
- Length ABS(Y2-Y1)
- Xinc (X2 - X1)/Length
- Yinc (Y2 - Y1)/Length
- X X1
- Y Y1
-
- DDA creates good lines but it is too time
consuming due to the round function and long
operations on real values.
For I 0 To Length Do Begin Plot(Round(X),
Round(Y)) X X Xinc Y Y Yinc End
For End DDA
110DDA Example
- Compute which pixels should be turned on to
represent the line from (6,9) to (11,12). - Length Max of (ABS(11-6), ABS(12-9)) 5
- Xinc 1
- Yinc 0.6
- Values computed are
- (6,9), (7,9.6),
- (8,10.2), (9,10.8),
- (10,11.4), (11,12)
111Fast Lines Using The Midpoint Method
- Assumptions Assume we wish to draw a line
between points (0,0) and (a,b) with slope m
between 0 and 1 (i.e. line lies in first octant). - The general formula for a line is y mx B
where m is the slope of the line and B is the
y-intercept. From our assumptions m b/a and B
0. - y (b/a)x 0 --gt f(x,y) bx - ay 0 is an
equation for the line.
112Fast Lines (cont.)
- For lines in the first octant, the next
- pixel is to the right or to the right
- and up.
- Assume
- Distance between pixels centers 1
- Having turned on pixel P at (xi, yi), the next
pixel is T at (xi1, yi1) or S at (xi1, yi).
Choose the pixel closer to the line f(x, y) bx
- ay 0. - The midpoint between pixels S and T is (xi 1,yi
1/2). Let e be the difference between the
midpoint and where the line actually crosses
between S and T. If e is positive the line
crosses above the midpoint and is closer to T.
If e is negative, the line crosses below the
midpoint and is closer to S. To pick the correct
point we only need to know the sign of e.
113Fast Lines - The Decision Variable
- f(xi1,yi 1/2 e) b(xi1) - a(yi 1/2 e)
b(xi 1) - a(yi 1/2) -ae f(xi 1, yi
1/2) - ae 0 - Let di f(xi 1, yi 1/2) ae di is known
as the decision variable. - Since a ? 0, di has the same sign as e.
- Algorithm
- If di ? 0 Then
- Choose T (xi 1, yi 1) as next point
- di1 f(xi1 1, yi1 1/2) f(xi 11,yi
11/2) - b(xi 11) - a(yi 11/2) f(xi 1, yi
1/2) b - a - di b - a
- Else
- Choose S (xi 1, yi) as next point
- di1 f(xi1 1, yi1 1/2) f(xi 11,yi
1/2) - b(xi 11) - a(yi 1/2) f(xi 1, yi
1/2) b - di b
114Fast Line Algorithm
The initial value for the decision variable, d0,
may be calculated directly from the formula at
point (0,0). d0 f(0 1, 0 1/2) b(1) -
a(1/2) b - a/2 Therefore, the algorithm for a
line from (0,0) to (a,b) in the first octant
is x 0 y 0 d b - a/2 For i 0
to a do Begin Plot(x,y) If d gt 0 Then
Begin x x 1 y y 1 d d b
- a End
- Else Begin
- x x 1
- d d b
- End
- End
Note that the only non-integer value is a/2. If
we then multiply by 2 to get d' 2d, we can do
all integer arithmetic using only the operations
, -, and left shift. The algorithm still works
since we only care about the sign, not the value
of d.
115Bresenhams Line Algorithm
- We can also generalize the algorithm to work for
lines beginning at points other than (0,0) by
giving x and y the proper initial values. This
results in Bresenham's Line Algorithm. - Begin Bresenham for lines with slope between 0
and 1 - a ABS(xend - xstart)
- b ABS(yend - ystart)
- d 2b - a
- Incr1 2(b-a)
- Incr2 2b
- If xstart gt xend Then Begin
- x xend
- y yend
- End
- Else Begin
- x xstart
- y ystart
- End
For I 0 to a Do Begin Plot(x,y) x x
1 If d ? 0 Then Begin y y 1 d d
incr1 End Else d d incr2 End For
Loop End Bresenham
116Optimizations
- Speed can be increased even more by detecting
cycles in the decision variable. These cycles
correspond to a repeated pattern of pixel
choices. - The pattern is saved and if a cycle is detected
it is repeated without recalculating. - di 2 -6 6 -2 10
2 -6 6 -2 10
117Fast Circles
- Consider only the first octant of a circle of
radius r centered on the origin. We begin by
plotting point (r,0) and end when x lt y. - The decision at each step is whether to choose
the pixel directly above the current pixel or the
pixel which is above and to the left (8-way
stepping). - Assume Pi (xi, yi) is the current pixel.
- Ti (xi, yi 1) is the pixel directly above
- Si (xi -1, yi 1) is the pixel above and to
the left.
118Circle Drawing Algorithm
- We only need to calculate the values on the
border of the circle in the first octant. The
other values may be determined by symmetry.
Assume a circle of radius r with center at (0,0). - Procedure Circle_Points(x,y Integer)
- Begin
- Plot(x,y)
- Plot(y,x)
- Plot(y,-x)
- Plot(x,-y)
- Plot(-x,-y)
- Plot(-y,-x)
- Plot(-y,x)
- Plot(-x,y)
- End
1197.10 ???? ?? ??
- ??? ??? ???? ?? ??
- ??? ?? ???? ??, ?? ???? ???????, ??? ???? ?? ??
??? ????.
1207.10.1 z-buffer? ??? ????
- ???? ?? ?? ????? ????. ?? ?? ???? ?????, ?? ??,
?? ??, ??? ?? ????? ??. - Z-buffer ????? ? ?? ??? ??? ?? ? ??.
- ?? ???? ???? ??? ?? ????? ?? y? ??? ????. (??
7.47, ????) - ??? ???? ??? ???? ??? ????? ????, ?? ???? ??? ???
???? ??? ????.(?? ??) - ???? ?? ?? ??? ????, ??? ????. ???, ??? ?? ???
?? ???? ???? ??? ??? ??? ???? ????(???)
121?? 7.46 ???? ? ?? ??
??? ?? ???
?? ???
122?? 7.47 ???
?? ???
????? ???
1237.10.2 ???? ??
- ??? ??? ???? ???. ?? ??? ??? ???, ??? ??(???)???
????. - ??? ??? ?? ??? ??? ??? ?? ??? ??? ?? ??? ????
????. - Filling
- ?? ???(flood fill)
- ??? ??? (scan line fill)
- ??-?? ??? (even-odd fill)
1247.10.3 ?? ???
- Bresenham ????? ????, ???? ??? ?????? ???? ????
???? ?? ???? ????. (?? 7.48) - ??? ???? ???(?? ???)? ??, ? ??? ????? ????. ???
?? ?? ????(??? ??????) ????? ???.
125flood_fill (int x, int y) if (read_pixel(x,y)
WHITE) write_pixel(x,y,BLACK) flood_fil
l(x-1,y) flood_fill(x1,y) flood_fill(x,y-1)
flood_fill(x,y1)
126?? 7.48 ?? ?? ??? ???
???
???
1277.10.4 ??? ????
- ???? ??? ???? ??? ??-?? ??? ?????, ??? ??? ???
??? ?? ??? ??? ??(span)? ????. - ???? ???? ???? ??? ???? ????. ??? ??? ????? ????.
(Edge Coherence) - ?? 7.50? ?? 7.51? ??
- Y-x ???? ??? ??? ????? ????? ??? ? ? ??. ??
7.52 ??
128?? 7.49 ??? ??? ???
129?? 7.50 ?? ???? ?? ??? ???
130?? 7.51 ??? ??? ??
131?? 7.52 y-x ????? ?? ????
132?? 7.53 ???
??-?? ??? ??? ?????, ?? ??? ??? ??? ????? ??. ?,
???? ??? ??? ?, (a)? ??? 0??? 2??? ????, (b)?
???? 1??? ????? ??.
1337.11 ??????
- 7.54 ???? Raster ??
- ?? ?? ?? ??? ???? ????? ?? ??
134- ??? ??? ??? ??? ??
- ??? ??? ??? ??? ??
- ?? ?? ?? ???? ??? ??? ???? ???.??? ?? ??? ???
??? ?? ???????.
- Raster? ? ??? ??? ?? ??? ??? ???? ???? ???? ???
???.
135Anti-aliasing
- ?? ??(area averaging)
- ??? ???? ?? ??? ???? ? ??? ?? ????.( Bresenhams
algorithm? ? x?? ??? ???? ? ?? ?? ???? ?? ??? ) - ??? ? ? ???? ??
- ? ??? 1? 2? ??? ?? ??? ?
- ?? ??
- ?? ????? ???? ?? ??? ??? ???? ?? ????? ? ??? ??
?? ??.
136- ?? 7.55 Aliasing ??? Anti-aliasing? ??
- ????? ?? (b) ??????? ??
- (c) ??? ????? ?? (d) ??? ????????
137?? 7.56 ? ??? ???? ???
? ???? ?? ?? ?? ???, ??? ??? ?? ????? ?? ??? ????
??? ?? ???. ? ???? ?? ??? ?? ??? ??? ?? ??? ? ???
? ? ??? ??? ?? ? ??. (10?? ?? ??? ??)
138?? 5.57 ?? ?? ???? (time-domain aliasing)
- ?? ??? ???? ?? ??? ??
- ? ???? ?????? ??? ? ???? ????? ??? ?? ??.
1397.12 ????? ?? ??
- ?? ?????? frame buffer? ??? ??? display?? ? ????
???. - ??? ???? (flickering)
- Frame buffer? ???? ??? display? ??? frame buffer?
?? ??? ??? ???? (2 ?? ???) - ?? 60?? 75 Hz ?? ???
- Double Buffering
1407.12.1 ???
??? ??
RGB ?? ??? ???? ? ? ??
?? 7.58 ??-??-?? ? (a) RGB ??? (b) HLS ???
141? ?? ??
- OpenGL? 3?? (0.8, 0.6, 0.0)?
- CRT? ?? ?? ????? ??????
- ?? ?? ?? ??. ?? ??? CRT ?? ??? ?? ? ??? ??? ???.
- ? ????? ? ??? ????.
- M? 33 ???? ??? ?? ???.
- ??? ???? ?? ?? ???.
142- CMYK ??
- ?? ??
- ??? ??? ?? ??? ?? ??
- HLS ??
- ?? (Hue) ?? ???? ??
- ?? (Lightness) ?? ??? ?? ????.
- ?? (Saturation) ??? ????. ????
- RGB ??? ?? ??? ??? ?????? ??? ? (?? ??? ??????
???) - - ??? ????? ???? ??? ??
1437.12.2 ?? ??
(??)
?? 7.59 ??? ?? (brightness)
144- ??(brightness)? ??? ?? (intensity)
- ??? ??? ?? ???? ???.
- ? ??? ?? ??? ???? ??? ????? ????? ?.
- I ? CRT? ??, V? ???? ??,
- ? ??? CRT ? ??
- frame buffer? ?? ?? ??? ??? ?? ?? ???? ?? ???
??? ? ??. ??? ??? ???? ??? ?? ????? ??.
1457.12.3 ????? ????
( Dithering and Halftoning)
- ???? (Halftoning)
- ?? ???(black and white)?? ??? ??? ?? ? ??? ????
?? ??? ??? ?. - ?? ???? ???? ???? ???? ??? ???.
- ??? ???? ?? ?? ???? ???. ?? ?? ?? ?? ??? ???? ?
??. - OpenGL?? ???.
- glEnable(GL_DITHER)
146?? 7.60 ??? ???(digital halftone) ??
- ??? ??? ??, ??? ??? ??, ?? ??? ??? ???? ???? ??
- 0?? 16?? ?? ??? ???? 17?? ??? ??? ???. ?????? ¼?
?? ??? 2???? 17??? ?????? ???. - ??? ?? ?? ????(dither) ??? ??? ?? ?? ????? ??.