CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Scan Conversion CS123 1 of 44Scan Conversion - 10/14/2014.

Slides:



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

CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.
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.
Lecture 5 Rendering lines 1.Steps of line rendering 2.Scan-conversion for line segments 3.A1 tutorial CP411 Computer Graphics Fall 2007 Wilfrid Laurier.
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.
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
Komputer Grafik 2 (AK045206) Scan Conversion 1/31 Scan Conversion.
2D Output Primitives Graphics packages provide basic operations (called primitive operations) to describe a scene in terms of geometric structures. The.
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.
CS 450: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
Circle Drawing algo..
Dr. Scott Schaefer Scan Conversion of Lines. 2/78 Displays – Cathode Ray Tube.
1/1/20001 Topic >>>> Scan Conversion CSE Computer Graphics.
IT- 601: Computer Graphics Lecture-03 Scan Conversion
Dr. S.M. Malaek Assistant: M. Younesi
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
Computing & Information Sciences Kansas State University CIS 536/636 Introduction to Computer Graphics Lecture 6 of 41 William H. Hsu Department of Computing.
1Computer Graphics Implementation III Lecture 17 John Shearer Culture Lab – space 2
Introduction to Computer Graphics with WebGL
CS 480/680 Computer Graphics Implementation III Dr. Frederick C Harris, Jr. Fall 2011.
Graphics Graphics & Graphical Programming Lecture 14 - Lines & Circles.
Introduction Computer Graphics & Its application Types of computer graphics Graphic display : random Scan & Raster Scan display Frame buffer and video.
Graphics Output Primitives
Line Drawing and Generalization. Outline  overview  line drawing  circle drawing  curve drawing.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization.
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.
Computing & Information Sciences Kansas State University CIS 536/636 Introduction to Computer Graphics Lecture 8 of 41 William H. Hsu Department of Computing.
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.
10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.
CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Visible Surface Determination (VSD) To render or not to render, that is the question… 1 of.
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.
Scan Conversion.
Lecture 13: Raster Graphics and Scan Conversion
OUTPUT PRIMITIVES A.Aruna/Faculty of Information technology/SNSCE13/19/2016.
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 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.
Computer Graphics Inf4/MSc Computer Graphics Lecture 4 Line & Circle Drawing.
10/10/2006TCSS458A Isabelle Bichindaritz1 Line and Circle Drawing Algorithms.
Computer Graphics Lecture 07 Ellipse and Other Curves Taqdees A. Siddiqi
Scan Conversion of Line Segments. What is Scan conversion? Final step of rasterization (the process of taking geometric shapes and converting them into.
Computer Graphics I, Fall 2010 Scan conversion algorithms.
Scan Conversion or Rasterization
Computer Graphics Drawing Line.
CSCE 441 Lecture 2: Scan Conversion of Lines
Basic Raster Graphics Algorithms for Drawing 2D Primitives
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1
Scan Conversion or Rasterization
University of New Mexico
Implementation III.
Computer Graphics Implementation I.
Introduction to Computer Graphics with WebGL
CSCE 441 Lecture 2: Scan Conversion of Lines
Rasterization and Antialiasing
Computer Graphics Implementation III
Rasterization and Antialiasing
Edited from The Rasterization Problem: Idealized Primitives Map to Discrete Display Space Edited from.
Chapter 3 Graphics Output Primitives
Basic Raster Graphics Algorithms for Drawing 2D Primitives
Implementation III Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Scan Conversion CS123 1 of 44Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Line Drawing  First problem statement: Draw a line on a raster screen between two points  Why is this a difficult problem?  What is “drawing” on a raster display?  What is a “line” in raster world?  Efficiency and appearance are both important Problem Statement  Given two points P and Q in XY plane, both with integer coordinates, determine which pixels on a raster screen should be on in order to best approximate a unit-width line segment starting at P and ending at Q 2 of 44 Scan Converting Lines Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam ©  Final step of rasterization (process of taking geometric shapes and converting them into an array of pixels stored in the framebuffer to be displayed) – converting from “random scan”/vector specification to a raster scan where we specify which pixels are on based on a stored array of pixels  Takes place after clipping occurs  All graphics packages do this at end of the rendering pipeline  Takes triangles (or higher-order primitives) and maps them to pixels on screen  For 3D rendering also takes into account other processes, like lighting and shading, but we’ll focus first on algorithms for line scan conversion 3 of 44 What is Scan Conversion? Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Special cases:  Horizontal Line:  Draw pixel P and increment x coordinate value by 1 to get next pixel.  Vertical Line:  Draw pixel P and increment y coordinate value by 1 to get next pixel.  Diagonal Line:  Draw pixel P and increment both x and y coordinate by 1 to get next pixel.  What should we do in the general case?  For slope <= 1, increment x coordinate by 1 and choose pixel on or closest to line. Slopes in other octants by reflection (e.g., in second octant, increment Y)  But how do we measure “closest”? 4 of 44 Scan-converting a Line: Finding the next pixel Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam ©  Why can we use vertical distance as a measure of which point (pixel center) is closer?  … because vertical distance is proportional to actual distance  Similar triangles show that true distances to line (in blue) are directly proportional to vertical distances to line (in black) for each point  Therefore, point with smaller vertical distance to line is closest to line 5 of 44 Vertical Distance Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 6 of 44 Strategy 1 – Incremental Algorithm (1/3) Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 7 of 44 Strategy 1 – Incremental Algorithm (2/3) Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 8 of 44 Strategy 1 – Incremental Algorithm (3/3) - Issues void Line(int x0, int y0, int x1, int y1) { int x, y; float dy = y1 – y0; float dx = x1 – x0; float m = dy / dx; y = y0; for (x = x0; x < x1; ++x) { WritePixel( x, Round(y) ); y = y + m; } Rounding takes time Since slope is fractional, need special case for vertical lines (dx = 0) Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 9 of 44 Strategy 2 – Midpoint Line Algorithm (1/3) Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 10 of 44 Strategy 2 – Midpoint Line Algorithm (2/3) Previous pixel E pixel NE pixel Midpoint M Q Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 11 of 44 Strategy 2- Midpoint Line Algorithm (3/3) For line shown, algorithm chooses NE as next pixel. Now, need to find a way to calculate on which side of line midpoint lies E pixel NE pixel Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 12 of 44 General Line Equation in Implicit Form Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 13 of 44 Decision Variable Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 14 of 44 Incrementing Decision Variable if E was chosen: Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 15 of 44 If NE was chosen: Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 16 of 44 Summary (1/2) Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 17 of 44 Summary (2/2) Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © void MidpointLine(int x0, int y0, int x1, int y1) { int dx = (x1 - x0), dy = (y1 - y0); int d = 2 * dy - dx; int incrE = 2 * dy; int incrNE = 2 * (dy - dx); int x = x0, y = y0; WritePixel(x, y); while (x < x1) { if (d <= 0) d = d + incrE; // East Case else { d = d + incrNE; ++y; } // Northeast Case ++x; WritePixel(x, y); } } 18 of 44 Example Code Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 19 of 44 Scan Converting Circles (17, 0) (0, 17) (17, 0) (0, 17) Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 20 of 44 Version 3 — Use Symmetry R (x 0 + a, y 0 + b) (x-x 0 ) 2 + (y-y 0 ) 2 = R 2 (x 0, y 0 ) Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 21 of 44 Using the Symmetry (x 0, y 0 ) Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 22 of 44 The Incremental Algorithm – a Pseudocode Sketch Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 23 of 44 What we need for the Incremental Algorithm Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 24 of 44 The Decision Variable Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 25 of 44 The right decision variable? Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 26 of 44 Alternate Phrasing (1/3) Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 27 of 44 Alternate Phrasing (2/3) Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 28 of 44 Alternate Phrasing (3/3) Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 29 of 44 Incremental Computation Revisited (1/2) Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 30 of 44 Incremental Computation (2/2) Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 31 of 44 Second Differences (1/2) Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 32 of 44 Second Differences (2/2) Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © MidpointEighthCircle(R) { /* 1/8th of a circle w/ radius R */ int x = 0, y = R; int deltaE = 2 * x + 3; int deltaSE = 2 * (x - y) + 5; float decision = (x + 1) * (x + 1) + (y - 0.5) * (y - 0.5) – R*R; WritePixel(x, y); while ( y > x ) { if (decision > 0) { // Move East x++; WritePixel(x, y); decision += deltaE; deltaE += 2; deltaSE += 2; // Update deltas } else { // Move SouthEast y--; x++; WritePixel(x, y); decision += deltaSE; deltaE += 2; deltaSE += 4; // Update deltas } } } 33 of 44 Midpoint Eighth Circle Algorithm Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam ©  Uses floats!  1 test, 3 or 4 additions per pixel  Initialization can be improved  Multiply everything by 4: No Floats!  Makes the components even, but sign of decision variable remains same Questions  Are we getting all pixels whose distance from the circle is less than ½?  Why is y > x the right criterion?  What if it were an ellipse? 34 of 44 Analysis Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam ©  Aligned Ellipses  Non-integer primitives  General conics  Patterned primitives 35 of 44 Other Scan Conversion Problems Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 36 of 44 Aligned Ellipses Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 37 of 44 Direction Changing Criterion (1/2) Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 38 of 44 Direction Changing Criterion (2/2) Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam ©  Now in ENE octant, not ESE octant. Used the wrong direction because the ellipse rapidly changes slope within a pixel  This problem is an artifact of aliasing, remember filter? 39 of 44 Problems with aligned ellipses Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 40 of 44  Patterned line from P to Q is not same as patterned line from Q to P.  Patterns can be cosmetic or geometric  Cosmetic: Texture applied after transformations  Geometric: Pattern subject to transformations Cosmetic patterned line Geometric patterned line Patterned Lines PQ PQ Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 41 of 44 Geometric vs. Cosmetic + Geometric (Perspectivized/Filtered) Cosmetic (Real-World Contact Paper) Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 42 of 44 Non-Integer Primitives and General Conics Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam ©  What's the difference between these two solutions? Under which circumstances is the right one "better"? 43 of 44 Generic Polygons Balsa Video - Scan Conversion - 10/14/2014

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam ©  Rapid Prototyping is becoming cheaper and more prevalent  3D printers lay down layer after layer to produce solid objects  We have an RP lab across the street in Barus and Holley  Printing food -  Bio-printing of 44 Scan Converting Arbitrary Solids Scan Conversion - 10/14/2014