Chapter 5
Scan Converting Circles
5.1 Brute Force
Second octan, going rightward
x := 0
REPEAT
y := sqrt( R*R - x*x )
CirclPixels( x , round(y) )
x := x+1
UNTIL x>y
DEFICIENCIES
- ‘*’, ‘sqrt’, ‘round’
- arithmetics with reals
5.2 Midpoint Circle Algorithm
90o
45o
- (x,y) = an intersection point of the circle with vertical mesh line
- (x,Y ) = pixel corresponding to (x,y)
- L = distance of midpoint (x + 1,Y - 1
2) from center of circle
- L < R
- L < R iff L * L < R * R
iff
= L * L - R * R < 0
‘Y := Y - 1’ when
changes sign
(x+1,Y - 1
2 )-
(x,Y - 1
2 ):
(x + 1)2+(Y - 0.5)2-R2
-
x2 +(Y - 0.5)2-R2
2x + 1
(x+1,Y - 3
2 )-
(x+1,Y - 1
2 ):
(x + 1)2+(Y - 1 - 0.5)2-R2
-
(x + 1)2+(Y - 0.5)2-R2
2(1 - Y )
x:=0 Y:=R
Delta = (R-0.5) * (R-0.5) - R*R
PaintPixels(x,Y)
REPEAT
Delta := Delta +
(
(x+1,Y - 1
2 )-
(x,Y - 1
2 ))
IF Delta>0 THEN
Delta := Delta +
(
(x+1,Y - 3
2 )-
(x+1,Y - 1
2 ))
Y := Y-1
END
x := x+1
PaintPixels(x,Y)
UNTIL x>Y
x:=0
Y:=R
Delta := (R-0.5) * (R-0.5) - R*R
PaintPixels(x,Y)
REPEAT
Delta := Delta + 2 * x + 1
IF Delta>0 THEN
Delta := Delta + 2 * (1 - Y)
Y := Y-1
END
x := x+1
PaintPixels(x,Y)
UNTIL x>Y
_________________________________________________________________________________________
x:=0
Y:=R
Delta := 0.5*0.5 - R
PaintPixels(x,Y)
Delta := Delta + 2 * x + 1
REPEAT
IF Delta <= 0 THEN
Delta := Delta + 2 * x + 1
ELSE
Delta := Delta + 2 * (x - Y) + 3
Y := Y-1
END
x := x+1
PaintPixels(x,Y)
UNTIL x>Y
x:=0
Y:=R
Delta := 1.25 - R
PaintPixels(x,Y)
REPEAT
IF Delta <= 0 THEN
Delta := Delta + 2 * x + 1
ELSE
Delta := Delta + 2 * (x - Y) + 3
Y := Y-1
END
x := x+1
PaintPixels(x,Y)
UNTIL x>Y
_________________________________________________________________________________________
x:=0
Y:=R
Delta := 1 - R
PaintPixels(x,Y)
REPEAT
IF Delta <= -0.25 THEN
Delta := Delta + 2 * x + 1
ELSE
Delta := Delta + 2 * (x - Y) + 3
Y := Y-1
END
x := x+1
PaintPixels(x,Y)
UNTIL x>Y
Delta deals only with integer values
x:=0
Y:=R
Delta := 1 - R
PaintPixels(x,Y)
REPEAT
IF Delta < 0 THEN
Delta := Delta + 2 * x + 1
ELSE
Delta := Delta + 2 * (x - Y) + 3
Y := Y-1
END
x := x+1
PaintPixels(x,Y)
UNTIL x>Y
x:=0
Y:=R
Delta := 1 - R
PaintPixels(x,Y)
REPEAT
IF Delta <= 0 THEN
Delta := Delta + 2 * x + 1
ELSE
Delta := Delta + 2 * x + 1
+ 2 * (1-Y)
Y := Y-1
END
x := x+1
PaintPixels(x,Y)
UNTIL x>Y
x:=0
Y:=R
Delta := 1 - R
d1 := 1
d2 := 3 - 2 * R
PaintPixels(x,Y)
REPEAT
IF Delta <= 0 THEN
Delta := Delta + d1
d1 := d1 + 2
d2 := d2 + 2
ELSE
Delta := Delta + d2
d1 := d1 + 2
d2 := d2 + 4
Y := Y-1
END
x := x+1
PaintPixels(x,Y)
UNTIL x>Y
WHY ‘d2 + 4’ and not ‘d2 + 6’
5.3 Eight-Way Symmetry
PROCEDURE CirclePixels(x,y);
BEGIN
PaintPixel(x,y)
PaintPixel(y,x)
PaintPixel(y,-x)
PaintPixel(x,-y)
PaintPixel(-x,-y)
PaintPixel(-y,-x)
PaintPixel(-y,x)
PaintPixel(-x,y)
END
5.4 Scanline Fill (Polygons)
For each scanline Y
- Find intersection points with polygon’s edges
- Sort intersection points by x
- Fill spans: (x0 , Y )
(x1,Y ),
(x2,Y )
(x3,Y ), ...
INTERSECTION POINTS
- Intersection point (x,y) is ignored for an edge (xmax,ymax)
(xmin,ymin), if it satisfies y = ymax, i.e,
- All intersection points in horizontal line
- Highest endpoint in nonhorizontal line
- Each intersection point at scanline Y is
- Either a maximal vertex (xmax,ymax) of an edge
- Or a neighbor of a higher intersection point on the same edge. If the higher intersection point has coordinates (x,Y+1)
then the current intersection point has coordinates (x+
x,Y), where
x = xmax-xmin
ymax-ymin
- An edge having intersection point at the current scanline Y is called an active edge
Y := maximum ymax in ET
AET := empty
REPEAT
AET := AET + 'marked' edges
in ET[Y]
AET := AET - 'marked' edges
in AET with N<=1
Y := Y - 1
AET := 'marked' edges of AET
adjusted one scan line down
sort AET along x
coordinates
fill spans
UNTIL AET is empty
COHERENCE -- Local similarity (used to speed up algorithms)
Within the scanline fill algorithm
- Span coherence -- Properties of pixels change slowly along spans
- Scanline coherence -- Properties of spans change slowly between scanlines
- Edge coherence -- Intersection points of scanlines move slowly across edges
Edge Representation
- (xmax , ymax )--Highest
coordinate
- N--Number
ymax - ymin + 1
of x-intersects
x--Horizontal distance
xmax-xmin
ymax-ymin
between x-intersects
EDGE TABLE (ET): sorted by y
AET[Y] + ET[Y]
AET[Y-1]
AET -- ACTIVE EDGE TABLE
- Possible Polygons.
- Other shapes with easily computable intersection points (e.g., circles)
- Sorting is needed even if no new points are added to AET, because edges can intersect.
- Sorting is fast because the lists are short and almost ordered (e.g., insertion sort)
- Fractions can be avoided with representations ‘(integer part, numerator, denominator)’, e.g., (1,2,5) for 7
5.
- Sliver problem: regions with small bottle necks
5.5 Seed Fill (Flood Fill)
choose pixel within the region
paint the pixel
push the pixel onto a stack
REPEAT
pop a pixel X from stack
find the nonpainted pixels
adjacent to X
paint the adjacent pixels
push adjacents pixels onto the stack
UNTIL stack is empty
- simple algorithm
- Does not require mathematical description for the region (e.g., free hand drawing)
- Heavy on memory and time (4 inquiries; 1 push/pop)
5.6 Scanline Seed Fill
CASES TO CONSIDER
- 4-connected -- Pixels up, down, right, and left are considered to be adjacent to current pixel.
- 8-connected --
- Interior defined -- largest connected region of pixels of same color
- Boundary defined -- largest connected region of pixels that differ from the boundary color