Rasterization Foley, Ch: 3. Pixels are represented as disjoint circles centered on uniform grid Each (x,y) of the grid has a pixel Y X (1,1) (1,2) (0,0)

Slides:



Advertisements
Similar presentations
Circle Drawing Asst. Prof. Dr. Ahmet Sayar Kocaeli University
Advertisements

Contents In today’s lecture we’ll have a look at:
Polygon Scan Conversion – 11b
Computer Graphics Inf4/MSc 1 Computer Graphics Lecture 7 Scanline algorithm and polygon clipping Taku Komura.
CS 376 Introduction to Computer Graphics 02 / 02 / 2007 Instructor: Michael Eckmann.
Computer Graphics 4: Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling By:Kanwarjeet Singh.
+ CPCS 391 Computer Graphics 1 Instructor: Dr. Sahar Shabanah Lecture 3.
CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
Komputer Grafik 2 (AK045206) Scan Conversion 1/31 Scan Conversion.
Different types of Polygons Simple Convex Simple Concave Non-simple : self-intersecting With holes ConvexConcaveSelf-intersecting.
2D Output Primitives Graphics packages provide basic operations (called primitive operations) to describe a scene in terms of geometric structures. The.
Implementation Dr. Amy Zhang. Reading 2  Hill, Chapters  Hill, Chapter 10.
Graphics Programming: Polygon Filling
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 50 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 45 Computer Graphics Implementation I.
Circle Drawing algo..
Polygon Scan Conversion and Z-Buffering
Dr. Scott Schaefer Scan Conversion of Lines. 2/78 Displays – Cathode Ray Tube.
1/1/20001 Topic >>>> Scan Conversion CSE Computer Graphics.
Jehee Lee Seoul National University
1 CPE 333 : Computer Graphics มหาวิทยาลัยเทคโนโลยีพระจอม เกล้าธนบุรี Dr. Natasha Dejdumrong.
Graphics Primitives: line. Pixel Position
WHERE TO DRAW A LINE?? Line drawing is accomplished by calculating intermediate positions along the line path between specified end points. Precise definition.
Scan Conversion Line and Circle
CS 450: COMPUTER GRAPHICS REVIEW: DRAWING ELLIPSES AND OTHER CURVES SPRING 2015 DR. MICHAEL J. REALE.
Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 121 Today’s class Drawing lines Bresenham’s algorithm Compositing Polygon filling.
College of Computer and Information Science, Northeastern UniversityOctober 12, CS G140 Graduate Computer Graphics Prof. Harriet Fell Spring 2006.
10/15/02 (c) 2002 University of Wisconsin, CS559 Last Time Clipping.
Graphics Output Primitives
1 CS 430/536 Computer Graphics I Polygon Clipping and Filling Week 3, Lecture 5 David Breen, William Regli and Maxim Peysakhov Geometric and Intelligent.
 A line segment in a scene is defined by the coordinate positions of the line end-points x y (2, 2) (7, 5)
Chapter 3 Scan Conversion Lecture-02. Bresenham’s Line Algorithm Bresenham’s line algorithm – is a highly efficient incremental method for scan- converting.
MIDPOINT CIRCLE & ELLIPSE GENERARTING ALGORITHMS
Computer Graphics Drawing Line. Lines and Polylines Convex: For every pair of points in the polygon, the line between them is fully contained in the polygon.
10/15/02 (c) 2002 University of Wisconsin, CS559 Who Am I? Prof Stephen Chenney These notes will be online after the lecture – in fact they’re online already.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2013 Tamara Munzner Rasterization.
Midpoint Circle Algorithm
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
1 CSCE 441 Lecture 2: Scan Conversion of Lines Jinxiang Chai.
Computer Graphics Filling. Filling Polygons So we can figure out how to draw lines and circles How do we go about drawing polygons? We use an incremental.
Lecture 15: Raster Graphics and Scan Conversion
1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.
Scan Conversion.
Rasterization Overview Raster Display Device. Scan Conversion / Rasterization: converting vector graphics into raster graphics (determining pixels in.
Computer Graphics CC416 Week 14 Filling Algorithms.
Computer Graphics Lecture 08 Taqdees A. Siddiqi Computer Graphics Filled Area Primitives I Lecture 08 Taqdees A. Siddiqi
Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing
Computer Graphics Inf4/MSc Computer Graphics Lecture 4 Line & Circle Drawing.
Computer Graphics Lecture 07 Ellipse and Other Curves Taqdees A. Siddiqi
Rasterization, or “What is glBegin(GL_LINES) really doing?” Course web page: February 23, 2012  Lecture 4.
OUTPUT PRIMITIVES CEng 477 Computer Graphics METU, 2004.
Scan Conversion or Rasterization
Computer Graphics Filling.
CS G140 Graduate Computer Graphics
Polygons.
(c) 2002 University of Wisconsin, CS559
Scan Conversion or Rasterization
Computer Graphics Implementation I.
Lecture 05: Mid-point Ellipse algorithm Dr. Manal Helal – Fall 2014
Scan Conversion of Lines
© University of Wisconsin, CS559 Fall 2004
Scan Conversion of Circles
2D Scan-line Conversion
Agenda Polygon Terminology Types of polygons Inside Test
Rasterizing Lines 1 Lecture 32 Mon, Nov 12, 2007.
Prepared by Narendra V G CSE MIT
Agenda Polygon Terminology Types of polygons Inside Test
Scan Conversion (From geometry to pixels)
Chapter 3 Graphics Output Primitives
Where We Stand At this point we know how to: Next thing:
Presentation transcript:

Rasterization Foley, Ch: 3

Pixels are represented as disjoint circles centered on uniform grid Each (x,y) of the grid has a pixel Y X (1,1) (1,2) (0,0)

Scan Converting Lines If the line has slope, m = 1 Incremental along x and y axis is 1 Y X (0,0)

Scan Converting Lines If the line has slope < 1 Increment along x is 1, increment along y is fractional – Round the value along y axis

Scan Converting Lines If the line has slope > 1 Increment along y is 1, increment along x is fractional – Round the value along y axis Y X (0,0)

Scan Converting Lines Basic Incremental Algorithm Two end points (x o,y o ) and (x 1,y 1 ) Calculate slope m=y 1 -y 0 / x 1 -x 0 If(m<1): y i+1 = mx i+1 + B = m(x i + Δx) + B = (mx i + B) + mΔx = y i + mΔx = y i + m So next point to intensify is (x i+1, round(y i+1 ))

Scan Converting Lines Basic Incremental Algorithm Two end points (x o,y o ) and (x 1,y 1 ) Calculate slope m=y 1 -y 0 / x 1 -x 0 If(m>1) (Steeper): x i+1 = (y i+1 – B)/m = ((y i + Δy) – B)/m = (y i - B)/m + Δy/m = x i + 1/m So next point to intensify is (round(x i+1 ), y i+1 ) Y (0,0)

Scan Converting Lines Basic Incremental Algorithm Problem: 1.Handle fractional values  Rounding takes time Solution: Midpoint Line Algorithm 1.Only integer arithmetic 2.Avoid rounding 3.Assumes 0<=m<=1

Midpoint Line Algorithm Lower end point (x o,y o ) and upper point (x 1,y 1 ) Initially we are at P(x p,y p ) Choose between NE and E Midpoint M is (x p +1, y p +1/2) M lies on which side of the line? – M is on the line  any pixel NE /E – M is below the line  choose NE – M is above the line  choose E Find the equation of the line f(x,y) – f(x,y) = ax +by +c a=dy; b= -dx ; c= dxB (learn the derivation) – Let d = f(M) = f(x p+1, y p+1/2 ) – d = 0  M is on the line d > 0  M is below the line d < 0  M is above the line

Midpoint Line Algorithm Find the next value of the decision variable d? – Need to apply incremental approach Two cases: 1.If E is chosen 2.If Ne is chosen

Midpoint Line Algorithm Find the next value of the decision variable d? – Need to apply incremental approach 1.If E is chosen : New Midpoint: M 1 (x p +2, y p + 1/2) New decision variable d new = f(M 1 )=f(x p +2, y p + 1/2) = d old + dy = d old + d E (learn the derivation) M1

Midpoint Line Algorithm Find the next value of the decision variable d? – Need to apply incremental approach 1.If NE is chosen : New Midpoint: M 2 (x p +2, y p + (1+1/2)) New decision variable d new = f(M 2 )=f(x p +2, y p + 1+1/2) = d old + (dy – dx) = d old + d NE (learn the derivation) M2

Midpoint Line Algorithm Initial value of decision variable d start Start point (x o,y o ) d start = f(x o +1, y o + 1/2) = f(x o +y o ) + dy-dx/2 = dy-dx/2 (learn the derivation) Here the fraction in dx/2 can be avoided by considering f(x,y)=2(ax+by+c)

Simple addition and comparison

Midpoint Line Algorithm The algorithm works for 0<=m<=1 What about other slopes? – Think!

Polygon Scan Conversion Steps: 1.Find the intersections of the scan line with the polygon edges 2.Sort the intersection points in increasing order of x coordinate 3.For each pair of intersections, use odd parity rule to draw the pixels that are interior to the polygon – Initially parity is even, P = 0 – For each intersection, parity is changed – Draw the pixels only when the parity is odd P=1P=0P=1P=0 P=1P=0 P=1

Polygon Scan Conversion Draw only those pixels which are strictly interior to the polygon Cases to consider: 1.Intersection point is fractional 2.Intersection point is integer 3.Integer intersection point that is a shared vertex 4.Integer intersection points that define horizontal edge

Polygon Scan Conversion 1.Intersection point is fractional – If it is the left most of the span, and before intersection we were outside the polygon, then round up – If it is the right most of the span, and before intersection we were inside the polygon, then round down

Polygon Scan Conversion 2.Intersection point is integer – If it is the left most of the span, draw it – If it is the right most of the span, don’t draw it

Polygon Scan Conversion 3.Integer intersection point that is a shared vertex Draw it only if it is y min of an edge

Polygon Scan Conversion 4.Integer intersection points that define horizontal edge Scanline Y1: A is a Y min of JA. A is drawn and parity becomes odd. Through out AB, parity remains odd, the span AB is drawn. B is Ymin of CB. Parity becomes even. Drawing stops. Y1

Polygon Scan Conversion 4.Integer intersection points that define horizontal edge Scanline Y2: First Intersection point is drawn and parity becomes odd. Through out the span up to C, parity remains odd, the span is drawn. C is not Y min of CD or BC. So C is not considered. Parity remains odd. Span CD is drawn. D is Y min of DE. Parity becomes even. Drawing stops. Y2

Polygon Scan Conversion 4.Integer intersection points that define horizontal edge Scanline Y3: I is not Y min of IH or IJ. So I is not considered. Parity remains even. Span IH is not drawn. H is Y min of GH. So H is considered and Parity becomes odd. The span up to next intersection point is drawn. Y3

Polygon Scan Conversion 4.Integer intersection points that define horizontal edge Scanline Y4: G is not Y min of GF or GH. So G is not considered. Parity remains even. Span GF is not drawn. Summary: Top edges are not drawn Bottom edges are drawn Y4

Polygon Scan Conversion IJ: J up to before I is drawn JA: Completely drawn BC: Not Drawn GH: H up to before G is drawn FE: Not Drawn ED: Not Drawn Summary: Left Edges are drawn Right Edges are not drawn

Slivers In case of thin polygon area, each scan line may not have a distinct span

Midpoint Circle Algorithm Algorithm based on the second octant

Midpoint Circle Algorithm Currently we are are P(x p,y p ). Choose Between E or SE based on midpoint M(x p +1, y p - 1/2) M lies inside or outside the circle? – M is outside the circle  choose SE – M is inside the circle  choose E – M is on the circle  any pixel SE /E

Midpoint Circle Algorithm Use f(x,y) = x 2 + y 2 – R 2 d = f(M) = f (x p +1, y p - 1/2) d = 0  M is on the circle  any pixel SE/E d > 0  M is outside the circle  choose SE d < 0  M is inside the circle  choose E

Midpoint Circle Algorithm After we reach E or SE, what is the new value of d? Case 1-We are at E: New midpoint M E (x p +2, y p - 1/2) d new = f (M E ) = f(x p +2, y p - 1/2) = d old + (2x p + 3) = dold + ΔE (learn the derivation) d new > 0  M is outside the circle  Choose SE’ d new < 0  M is inside the circle  Choose E’ d new = 0  M is on the circle  Choose E’ / SE’ P(x p,y p )E SE E’ SE’ MEME M

Midpoint Circle Algorithm After we reach E or SE, what is the new value of d? Case 2-We are at SE: New midpoint M SE (x p +2, y p – /2) d new = f (M SE ) = f(x p +2, y p -1-1/2) = d old + (2x p – 2y p + 5) = dold + ΔSE (learn the derivation) d new > 0  M is outside the circle  Choose SE’ d new < 0  M is inside the circle  Choose E’ d new = 0  M is on the circle  Choose E’ / SE’ P(x p,y p )E SE E’ SE’ M M SE

Midpoint Circle Algorithm Initial Value of d: d start = f(1,R-1/2) = 5/4 – R h= d -1/4 d = h+1/4 h+1/4 = 5/4 – R h = 1- R h = -1/4  M is on the circle  any pixel SE/E h > -1/4  M is outside the circle  choose SE h < -1/4  M is inside the circle  choose E If h starts out with integer value and gets incremented by integer value (ΔE or ΔSE) then the comparisons reduce to h=0, h>0, and h<0

Improvements by second order difference ΔE = 2x p + 3 ΔSE= 2x p – 2y p + 5 E is chosen  new point of evaluation E(x p +1,y p ) SE is chosen  new point of evaluation SE(x p +1,y p -1) Point of evaluation P(x p,y p )

Improvements by second order difference ΔE = 2x p + 3 ΔSE= 2x p – 2y p + 5 Find increments ΔE and ΔSE with respect to new point of evaluation E(x p +1,y p ) Find increments ΔE and ΔSE with respect to new point of evaluation SE(x p +1,y p -1) Point of evaluation P(x p,y p )

ΔE and ΔSE with respect to new point of evaluation E(x p +1,y p ) P(x p,y p ) E(x p +1,y p ) ΔE= 2x p + 3 = ΔE old ΔSE= 2x p – 2y p + 5= ΔSE old ΔE= 2(x p + 1) + 3 = (2x p + 3) + 2 = ΔE old + 2 Increment in d when E is chosen P(x p,y p )E SE E’ SE’ E’’ SE’’

ΔE and ΔSE with respect to new point of evaluation E(x p +1,y p ) P(x p,y p ) E(x p +1,y p ) ΔE= 2x p + 3 = ΔE old ΔSE= 2x p – 2y p + 5= ΔSE old ΔE= 2(x p + 1) + 3 = (2x p + 3) + 2 = ΔE old + 2 ΔSE=2(x p +1 )– 2y p + 5 = (2x p – 2y p + 5) + 2 = ΔSE old + 2 Increment in d when E is chosen P(x p,y p )E SE E’ SE’ E’’ SE’’

Improvements by second order difference

ΔE and ΔSE with respect to new point of evaluation SE(x p +1,y p -1) P(x p,y p ) SE(x p +1,y p -1) ΔE= 2(x p + 1) + 3 = (2x p + 3) + 2 = ΔE old + 2 ΔE= 2x p + 3 = ΔE old ΔSE= 2x p – 2y p + 5= ΔSE old Increment in d when E is chosen P(x p,y p )E SE SE’ E’ E’’ SE’’

ΔE and ΔSE with respect to new point of evaluation SE(x p +1,y p -1) P(x p,y p ) SE(x p +1,y p -1) ΔSE=2(x p +1)– 2(y p -1)+5 = (2x p –2y p +5)+2+2=ΔSE old +4 ΔE= 2x p + 3 = ΔE old ΔSE= 2x p – 2y p + 5= ΔSE old Increment in d when E is chosen P(x p,y p )E SE SE’ E’ E’’ SE’’ ΔE= 2(x p + 1) + 3 = (2x p + 3) + 2 = ΔE old + 2

Improvements by second order difference

Eight Way Symmetry

First quadrant is divided into two regions based on the change of slope The line going through point P is the boundary Slope of the curve at point P is -1 Slope of the Gradient at point P is +1 Scan Conversion ellipse

Ellipse Equation: f(x,y)=b 2 x 2 +a 2 y 2 -a 2 b 2 =0 Gradient is the vector that is perpendicular to the tangent to the curve at point P. Region 1: 2b 2 x<2a 2 y  b 2 x<a 2 y Region 2: 2b 2 x>=2a 2 y  b 2 x>=a 2 y

Scan Conversion ellipse Pixel Choosing: Region 1: we are at (x p,y p ), midpoint to consider M(x p +1,y p -1/2) Choose between E and SE Region 2: we are at (x p’,y p’ ), midpoint to consider M’(x p’ +1/2,y p’ -1) Choose between S and SE 1 2 P E SE M S M’ (x p,y p ) (x p’,y p’ )

Scan Conversion ellipse Region Change Testing: Start from region 1 We are at (x p,y p ) Next midpoint to consider is M(x p +1, y p -1/2) If b 2 (x p +1)<a 2 (y p -1/2)  still at region 1 If b 2 (x p +1)>=a 2 (y p -1/2)  changed to region P

Scan Conversion ellipse Region 1: We are at (x p,y p ) Midpoint to consider M(x p +1,y p – 1/2) Choose between E or SE based on d=f(M)=(x p +1) 2 b 2 +(y p – 1/2) 2 a 2 – a 2 b 2 d > 0  M is outside the ellipse  choose SE d < 0  M is inside the ellipse  choose E d = 0  M is on the ellipse  any pixel SE/E 1 2 P E SE M (x p,y p )

Scan Conversion ellipse Region 1: d old =(x p +1) 2 b 2 +(y p – 1/2) 2 a 2 – a 2 b 2 If E is chosen: d new = f (x p +2,y p -1/2) =d old +b 2 (2x p +3) =d old + ∆E (learn the derivation) 1 2 P E M (x p,y p ) E’ SE’ M’

Scan Conversion ellipse Region 1: d old =(x p +1) 2 b 2 +(y p – 1/2) 2 a 2 – a 2 b 2 If E is chosen: d new = f (x p +2,y p -1/2) =d old +b 2 (2x p +3) =d old + ∆E (learn the derivation) If SE is chosen: d new = f (x p +2,y p -1 -1/2) =d old + b 2 (2x p +3) +a 2 (-2y p +2) =d old + ∆SE (learn the derivation) At each iteration, test for region change. Continue the process until changed to region P SE M (x p,y p ) E’ SE’ M’

Scan Conversion ellipse Region 2: We are at (x p,y p ) Midpoint to consider M(x p +1/2,y p – 1) Choose between E or SE based on d=f(M)=(x p +1/2) 2 b 2 +(y p – 1) 2 a 2 – a 2 b 2 d > 0  M is outside the ellipse  choose S d < 0  M is inside the ellipse  choose SE d = 0  M is on the ellipse  any pixel SE/S 1 2 P S SE M (x p,y p )

Scan Conversion ellipse Region 2: We are at (x p,y p ) d old =(x p +1/2) 2 b 2 +(y p – 1) 2 a 2 – a 2 b 2 If S is chosen: d new = f (x p +1/2,y p -2) =d old +a 2 (3-2y p )=d old +∆E P S’ SE’ M (x p,y p ) M’ S

Scan Conversion ellipse Region 2: We are at (x p,y p ) d old =(x p +1/2) 2 b 2 +(y p – 1) 2 a 2 – a 2 b 2 If S is chosen: d new = f (x p +1/2,y p -2) =d old +a 2 (3-2y p )=d old +∆E 2 If SE is chosen: d new =f (x p +1+1/2,y p -2) =d old +2b 2 (x p +1)+a 2 (3-2y p )=d old +∆SE P SE’ M (x p,y p ) M’ S SE

Initial decision variable: Region 1: Initial point is (0,b) d start1 =f(1,b-1/2) Region 2: For the midpoint M’ for which transition takes place, is used as d start2 If the last pixel dawn is (x p,y p ) then next midpoint M’(x p +1,y p -1/2) M’ changes the region so d start2 =f(M’) Scan Conversion ellipse 1 2 P b a

Learn applying second order difference just like circle!

Reference Foley: 3.1, 3.2.1, 3.2.2, 3.3, 3.4, 3.6 (exclude 3.6.3)