Komputer Grafik 2 (AK045206) Scan Conversion 1/31 Scan Conversion.

Slides:



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

Graphics Primitives: line
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.
CS 450: COMPUTER GRAPHICS REVIEW: DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
+ CPCS 391 Computer Graphics 1 Instructor: Dr. Sahar Shabanah Lecture 3.
Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing.
30/9/2008Lecture 21 Computer Graphics Assistant Professor Dr. Sana’a Wafa Al-Sayegh 2 nd Semester ITGD3107 University of Palestine.
2D Output Primitives Graphics packages provide basic operations (called primitive operations) to describe a scene in terms of geometric structures. The.
Bresenham’s Midpoint Algorithm CS5600 Computer Graphics Rich Riesenfeld Spring 2006 Lecture Set 1.
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.
CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Scan Conversion CS123 1 of 44Scan Conversion - 10/14/2014.
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)
CS 450: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
Circle Drawing algo..
Segment Measure and Coordinate Graphing
1 Preliminaries Precalculus Review I Precalculus Review II
Rasterizing primitives: know where to draw the line Dr Nicolas Holzschuch University of Cape Town Modified.
Dr. Scott Schaefer Scan Conversion of Lines. 2/78 Displays – Cathode Ray Tube.
1/1/20001 Topic >>>> Scan Conversion CSE Computer Graphics.
1 CS 430/536 Computer Graphics I Circle Drawing and Clipping Week 3, Lecture 6 David Breen, William Regli and Maxim Peysakhov Geometric and Intelligent.
Dr. S.M. Malaek Assistant: M. Younesi
Jehee Lee Seoul National University
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.
1. Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Graphing Linear Equations and Inequalities CHAPTER 4.1The Rectangular.
Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 121 Today’s class Drawing lines Bresenham’s algorithm Compositing Polygon filling.
Equations of Lines Chapter 8 Sections
Larry F. Hodges 1 Design of Line and Circle Algorithms.
College of Computer and Information Science, Northeastern UniversityOctober 12, CS G140 Graduate Computer Graphics Prof. Harriet Fell Spring 2006.
Graphics Output Primitives
Line Drawing and Generalization. Outline  overview  line drawing  circle drawing  curve drawing.
CGMB214: Introduction to Computer Graphics
 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.
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.
GEOMETRY AND LINE GENERATION Geometry and Line Generation Chapter 2.
Week 4 Functions and Graphs. Objectives At the end of this session, you will be able to: Define and compute slope of a line. Write the point-slope equation.
Scan Conversion.
Lecture 2: 19/4/1435 Graphical algorithms Lecturer/ Kawther Abas CS- 375 Graphics and Human Computer Interaction.
Rasterization Overview Raster Display Device. Scan Conversion / Rasterization: converting vector graphics into raster graphics (determining pixels in.
Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing
Computer Graphics CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
Write Bresenham’s algorithm for generation of line also indicate which raster locations would be chosen by Bresenham’s algorithm when scan converting.
10/10/2006TCSS458A Isabelle Bichindaritz1 Line and Circle Drawing Algorithms.
Computer Graphics Lecture 07 Ellipse and Other Curves Taqdees A. Siddiqi
Computer Graphics Lecture 06 Circle Drawing Techniques Taqdees A. Siddiqi
Rasterization, or “What is glBegin(GL_LINES) really doing?” Course web page: February 23, 2012  Lecture 4.
Line Drawing Algorithms 1. A line in Computer graphics is a portion of straight line that extends indefinitely in opposite direction. 2. It is defined.
Objectives Understand Bresenhams line drawing algorithm. Apply the algorithm to plot a line with the end points specified.
Primitive graphic objects
Scan Conversion or Rasterization
Computer Graphics Drawing Line.
CSCE 441 Lecture 2: Scan Conversion of Lines
CENG 477 Introduction to Computer Graphics
CS G140 Graduate Computer Graphics
Scan Conversion or Rasterization
Computer Graphics Implementation I.
Scan Conversion of Lines
CSCE 441 Lecture 2: Scan Conversion of Lines
Scan Conversion of Circles
Rasterizing Lines 1 Lecture 32 Mon, Nov 12, 2007.
Chapter 3 Graphics Output Primitives
Presentation transcript:

Komputer Grafik 2 (AK045206) Scan Conversion 1/31 Scan Conversion

Komputer Grafik 2 (AK045206) Scan Conversion 2/31 Outline Scan Converting Lines –Incremental Algorithm –Midpoint Algorithm Scan Converting Circle –Use Symetri –Incremental Algorithm –Midpoint Eight Circle Algorithm Other Scan Conversion Problem –Pattern Primitive –Alligned Ellipses

Komputer Grafik 2 (AK045206) Scan Conversion 3/31 Scan Converting Lines Line Drawing Draw a line on a raster screen between two points What’s wrong with the statement of the problem? –it doesn’t say anything about which points are allowed as endpoints –it doesn’t give a clear meaning to “draw” –it doesn’t say what constitutes a “line” in the raster world –it doesn’t say how to measure the success of a proposed algorithm Problem Statement Given two points P and Q in the plane, both with integer coordinates, determine which pixels on a raster screen should be on in order to make a picture of a unit-width line segment starting at P and ending at Q

Komputer Grafik 2 (AK045206) Scan Conversion 4/31 Finding the next pixel: Special case: Horizontal Line: Draw pixel P and increment the x coordinate value by one to get the next pixel. Vertical Line: Draw pixel P and increment the y coordinate value by one to get the next pixel. Diagonal Line: Draw pixel P and increment both the x and the y coordinate by one to get the next pixel. What should we do in the general case? –Increment the x coordinate by 1 and choose the point closest to the line. –But how do we measure “closest”?

Komputer Grafik 2 (AK045206) Scan Conversion 5/31 Vertical Distance Why can we use the vertical distance as a measure of which point is closer? –because the vertical distance is proportional to the actual distance –how do we show this? –with congruent triangles By similar triangles we can see that the true distances to the line (in blue) are directly proportional to the vertical distances to the line (in black) for each point Therefore, the point with the smaller vertical distance to the line is the closest to the line (x 1, y 1 ) (x 2, y 2 )

Komputer Grafik 2 (AK045206) Scan Conversion 6/31 Strategy 1 – Incremental Algorithm (1/2) The Basic Algorithm Find the equation of the line that connects the two points P and Q Starting with the leftmost point P, increment xi by 1 to calculate yi = mxi + B where m = slope, B = y intercept Intensify the pixel at (xi, Round(yi)) where Round (yi) = Floor (0.5 + yi) The Incremental Algorithm: Each iteration requires a floating-point multiplication –therefore, modify the algorithm. yi+1 = mxi+1 + B = m(xi +  x) + B = yi + m  x If  x = 1, then yi+1 = yi + m At each step, we make incremental calculations based on the preceding step to find the next y value

Komputer Grafik 2 (AK045206) Scan Conversion 7/31 Strategy 1 – Incremental Algorithm (2/2)

Komputer Grafik 2 (AK045206) Scan Conversion 8/31 Rounding integers takes time Variables y and m must be a real or fractional binary because the slope is a fraction –special case needed for vertical lines Problem with the Incremental Algorithm

Komputer Grafik 2 (AK045206) Scan Conversion 9/31 Strategy 2 – Midpoint Line Algorithm (1/3) Assume that the line’s slope is shallow and positive (0 < slope < 1); other slopes can be handled by suitable reflections about the principle axes Call the lower left endpoint (x0, y0) and the upper right endpoint (x1, y1) Assume that we have just selected the pixel P at (xp, yp) Next, we must choose between the pixel to the right (E pixel), or the one right and one up (NE pixel) Let Q be the intersection point of the line being scan-converted with the grid line x = xp +1

Komputer Grafik 2 (AK045206) Scan Conversion 10/31 Strategy 2 – Midpoint Line Algorithm (2/3) Previous pixel Choices for current pixel Choices for next pixel E pixel NE pixel Midpoint M Q

Komputer Grafik 2 (AK045206) Scan Conversion 11/31 Strategy 2 – Midpoint Line Algorithm (3/3) The line passes between E and NE The point that is closer to the intersection point Q must be chosen Observe on which side of the line the midpoint M lies: –E is closer to the line if the midpoint M lies above the line, i.e., the line crosses the bottom half –NE is closer to the line if the midpoint M lies below the line, i.e., the line crosses the top half The error, the vertical distance between the chosen pixel and the actual line, is always <= ½ The algorithm chooses NE as the next pixel for the line shown Now, find a way to calculate on which side of the line the midpoint lies

Komputer Grafik 2 (AK045206) Scan Conversion 12/31 The Line Line equation as a function f(x): f(x) = m*x + B = dy/dx*x + B Line equation as an implicit function: F(x, y) = a*x + b*y + c = 0 for coefficients a, b, c, where a, b ≠ 0 from above, y*dx = dy*x + B*dx so a = dy, b = -dx, c = B*dx, a > 0 for y0 < y1 Properties (proof by case analysis): F(xm, ym) = 0 when any point M is on the line F(xm, ym) < 0 when any point M is above the line F(xm, ym) > 0 when any point M is below the line Our decision will be based on the value of the function at the midpoint M at (xp + 1, yp + ½)

Komputer Grafik 2 (AK045206) Scan Conversion 13/31 Decision Variable Decision Variable d: We only need the sign of F(xp + 1, yp + ½) to see where the line lies, and then pick the nearest pixel d = F(xp + 1, yp + ½) - if d > 0 choose pixel NE - if d < 0 choose pixel E - if d = 0 choose either one consistently How to update d: - On the basis of picking E or NE, figure out the location of M for that pixel, and the corresponding value of d for the next grid line

Komputer Grafik 2 (AK045206) Scan Conversion 14/31 If E was chosen: M is incremented by one step in the x direction dnew = F(xp + 2, yp + ½) = a(xp + 2) + b(yp + ½) + c dold = a(xp + 1) + b(yp + ½) + c Subtract dold from dnew to get the incremental difference  E dnew = dold + a  E = a = dy Derive the value of the decision variable at the next step incrementally without computing F(M) directly dnew = dold +  E = dold + dy  E can be thought of as the correction or update factor to take dold to dnew It is referred to as the forward difference

Komputer Grafik 2 (AK045206) Scan Conversion 15/31 M is incremented by one step each in both the x and y directions dnew = F(xp + 2, yp + 3/2) = a(xp + 2) + b(yp + 3/2) + c Subtract dold from dnew to get the incremental difference dnew = dold + a + b  NE = a + b = dy – dx Thus, incrementally, dnew = dold +  NE = dold + dy – dx If NE was chosen:

Komputer Grafik 2 (AK045206) Scan Conversion 16/31 Scan Converting Circles Version 1: really bad For x = – R to R y = sqrt(R R – x x); Pixel (round(x), round(y)); Pixel (round(x), round(-y)); Version 2: slightly less bad For x = 0 to 360 Pixel (round (R cos(x)), round(R sin(x))); HW: explain why these are bad. (17, 0) (0, 17)

Komputer Grafik 2 (AK045206) Scan Conversion 17/31 Version 3 — Use Symmetry Symmetry: If (x0 + a, y0 + b) is on the circle, so are (x0 ± a, y0 ± b) and (x0 ± b, y0 ± a); hence there’s an 8-way symmetry. But in a practical setting of considering pixel values, it depends on the fact that x0 and y0 are integers. R

Komputer Grafik 2 (AK045206) Scan Conversion 18/31 Using the Symmetry We will scan top right 1/8 of circle of radius R It starts at (x0, y0 + R) Let’s use another incremental algorithm with a decision variable evaluated at midpoint

Komputer Grafik 2 (AK045206) Scan Conversion 19/31 What we need for Incremental Need a decision variable, i.e., something that is negative if we should move E, positive if we should move SE (or vice versa). Follow line strategy: Use the implicit equation of circle F(x,y) = x2 + y2 – R2 = 0 F(x,y) is zero on the circle, negative inside it, positive outside If we are at pixel (x, y), examine (x + 1, y) and (x + 1, y – 1) Again compute F at the midpoint = F(midpoint)

Komputer Grafik 2 (AK045206) Scan Conversion 20/31 Decision Variable P = (x p, y p ) MMEME MS E SE Evaluate F(x,y) = x2 + y2 – R2 at the point What we are asking is this: “Is positive or negative?” If it is negative there, this midpoint is inside the circle, so the vertical distance to the circle is less at (x + 1, y) than at (x + 1, y–1). If it is positive, the opposite is true.

Komputer Grafik 2 (AK045206) Scan Conversion 21/31 Incremental Computation, Again (1/2) How should we compute the value of at successive points? Answer: Note that is just and that is just

Komputer Grafik 2 (AK045206) Scan Conversion 22/31 So if we move E, update by adding 2x + 3 And if we move SE, update by adding 2x + 3 – 2y + 2. Note that the forward differences of a 1st degree polynomial were constants and those of a 2nd degree polynomial are 1st degree polynomials; this “first order forward difference,” like a partial derivative, is one degree lower. Let’s make use of this property. Incremental Computation, Again (2/2)

Komputer Grafik 2 (AK045206) Scan Conversion 23/31 Midpoint Eighth Circle Algorithm MEC (R) /* 1/8th of a circle w/ radius R */ { int x = 0, y = R; int delta_E, delta_SE; float decision; delta_E = 2*x + 3; delta_SE = 2(x-y) + 5; decision = (x+1)*(x+1) + (y + 0.5)*(y + 0.5) –R*R; Pixel(x, y); while( y > x ) { if (decision > 0) {/* Move east */ decision += delta_E; delta_E += 2; delta_SE += 2; } else {/* Move SE */ y--; decision += delta_SE; delta_E += 2; delta_SE += 4; } x++; Pixel(x, y); }

Komputer Grafik 2 (AK045206) Scan Conversion 24/31 Other Scan Conversion Problems Patterned primitives Aligned Ellipses

Komputer Grafik 2 (AK045206) Scan Conversion 25/31 Patterned Lines Patterned line from P to Q is not same as patterned line from Q to P. Patterns can be geometric or cosmetic –cosmetic can be from a background or a pattern sequence Cosmetic patterned line Geometric patterned line PQ PQ

Komputer Grafik 2 (AK045206) Scan Conversion 26/31 Geometric Pattern vs.Cosmetic Pattern Geometric Pattern Cosmetic Pattern

Komputer Grafik 2 (AK045206) Scan Conversion 27/31 Aligned Ellipses Equation is i.e, Computation of and is similar Only 4-fold symmetry When do we stop stepping horizontally and switch to vertical?

Komputer Grafik 2 (AK045206) Scan Conversion 28/31 Direction Changing Criterion (1/2) When the absolute value of the slope of the ellipse is more than 1, viz: How do you check this? At a point (x,y) for which F(x,y) = 0, a vector perpendicular to the level set is F(x,y) which is This vector points more right than up when

Komputer Grafik 2 (AK045206) Scan Conversion 29/31 In our case, and so we check for i.e. This, too, can be computed incrementally Direction Changing Criterion (2/2)

Komputer Grafik 2 (AK045206) Scan Conversion 30/31 Now in ENE octant, not ESE octant This problem is due to aliasing – much more on this later Problems with Aligned Ellipses

Komputer Grafik 2 (AK045206) Scan Conversion 31/31 Referensi F.S.Hill, Jr., COMPUTER GRAPHICS – Using Open GL, Second Edition, Prentice Hall, 2001 Andries van Dam, Introduction to Computer Graphics, Slide- Presentation, Brown University, 2003, (folder : brownUni)