159.235Graphics1 159.235 Graphics & Graphical Programming Lecture 14 - Lines & Circles.

Slides:



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

Graphics Primitives: line
5.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 5 – Drawing A Line.
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.
Section 3-1 to 3-2, 3-5 Drawing Lines Some of the material in these slides may have been adapted from university of Virginia, MIT, and Åbo Akademi University.
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.
Scan Conversion Algorithms
Scan conversion of Line , circle & ellipse
Computer Graphics Lecture 3 Line & Circle Drawing.
Larry F. Hodges (modified by Amos Johnson) 1 Design of Line, Circle & Ellipse Algorithms.
30/9/2008Lecture 21 Computer Graphics Assistant Professor Dr. Sana’a Wafa Al-Sayegh 2 nd Semester ITGD3107 University of Palestine.
Lecture 2 Line & Circle Drawing
CS 551 / CS 645 Antialiasing. What is a pixel? A pixel is not… –A box –A disk –A teeny tiny little light A pixel is a point –It has no dimension –It occupies.
2D Output Primitives Graphics packages provide basic operations (called primitive operations) to describe a scene in terms of geometric structures. The.
Raster conversion algorithms for line and circle
Bresenham’s Midpoint Algorithm CS5600 Computer Graphics Rich Riesenfeld Spring 2006 Lecture Set 1.
Line Drawing by Algorithm. Line Drawing Algorithms Line drawn as pixels Graphics system –Projects the endpoints to their pixel locations in the frame.
CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Scan Conversion CS123 1 of 44Scan Conversion - 10/14/2014.
CS 450: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
Bresenham’s Algorithm. Line Drawing Reference: Edward Angel’s book: –6 th Ed. Sections 6.8 and 6.9 Assuming: –Clipped (to fall within the window) –2D.
Dr. Scott Schaefer Scan Conversion of Lines. 2/78 Displays – Cathode Ray Tube.
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
Graphics Pipeline Rasterization CMSC 435/634. Drawing Terms Primitive – Basic shape, drawn directly – Compare to building from simpler shapes Rasterization.
3/4/04© University of Wisconsin, CS559 Spring 2004 Last Time Clipping Lines –Cohen-Sutherland: The use of outcodes and early reject/accept tests –Liang-Barsky:
Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 121 Today’s class Drawing lines Bresenham’s algorithm Compositing Polygon filling.
CS 325 Introduction to Computer Graphics 02 / 01 / 2010 Instructor: Michael Eckmann.
Larry F. Hodges 1 Design of Line and Circle Algorithms.
Filtering Robert Lin April 29, Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview.
10/15/02 (c) 2002 University of Wisconsin, CS559 Last Time Clipping.
Introduction Computer Graphics & Its application Types of computer graphics Graphic display : random Scan & Raster Scan display Frame buffer and video.
1 Line Drawing Version B: Semi-Formal Methods Derivation ©Anthony Steed
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.
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.
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.
CS 551 / 645: Introductory Computer Graphics
Scan Conversion.
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.
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
Computer Graphics Lecture 06 Circle Drawing Techniques Taqdees A. Siddiqi
Computer Graphics : output primitives.. 2 of 32 T1 – pp. 103–123, 137–145, 147–150, 164–171 Points and LinesPoints Line Drawing AlgorithmsLine Mid–Point.
Rasterization, or “What is glBegin(GL_LINES) really doing?” Course web page: February 23, 2012  Lecture 4.
Computer Graphics Lecture 05 Line Drawing Techniques Taqdees A. Siddiqi
Scan Conversion or Rasterization
Computer Graphics Drawing Line.
CSCE 441 Lecture 2: Scan Conversion of Lines
(c) 2002 University of Wisconsin, CS559
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1
Scan Conversion or Rasterization
Chapter Three Part I Output Primitives CS 380.
2D Scan-line Conversion
Edited from The Rasterization Problem: Idealized Primitives Map to Discrete Display Space Edited from.
Line Drawing Algorithms
Presentation transcript:

Graphics Graphics & Graphical Programming Lecture 14 - Lines & Circles

Graphics2 Towards the Ideal Line We can only do a discrete approximation Illuminate pixels as close to the true path as possible, consider bi-level display only –Pixels are either lit or not lit

Graphics3 What is an ideal line Must appear straight and continuous –Only possible axis-aligned and 45 o lines Must interpolate both defining end points Must have uniform density and intensity –Consistent within a line and over all lines –What about antialiasing? Must be efficient, drawn quickly –Lots of them are required!!!

Graphics4 Simple Line Based on slope-intercept algorithm from algebra: y = mx + b Simple approach: increment x, solve for y Floating point arithmetic required

Graphics5 Does it Work? It seems to work okay for lines with a slope of 1 or less, but doesn’t work well for lines with slope greater than 1 – lines become more discontinuous in appearance and we must add more than 1 pixel per column to make it work. Solution? - use symmetry.

Graphics6 Modify algorithm per octant OR, increment along x-axis if dy<dx else increment along y-axis

Graphics7 DDA algorithm DDA = Digital Differential Analyser –finite differences Treat line as parametric equation in t : Start point - End point -

Graphics8 DDA Algorithm Start at t = 0 At each step, increment t by dt Choose appropriate value for dt Ensure no pixels are missed: –Implies: and Set dt to maximum of dx and dy

Graphics9 DDA algorithm line(int x1, int y1, int x2, int y2) { float x,y; int dx = x2-x1, dy = y2-y1; int n = max(abs(dx),abs(dy)); float dt = n, dxdt = dx/dt, dydt = dy/dt; x = x1; y = y1; while( n-- ) { point(round(x),round(y)); x += dxdt; y += dydt; } n - range of t.

Graphics10 DDA algorithm Still need a lot of floating point arithmetic. –2 ‘round’s and 2 adds per pixel. Is there a simpler way ? Can we use only integer arithmetic ? –Easier to implement in hardware.

Graphics11 Observation on lines. while( n-- ) { draw(x,y); move right; if( below line ) move up; }

Graphics12 Testing for the side of a line. Need a test to determine which side of a line a pixel lies. Write the line in implicit form: Easy to prove F 0 for points below.

Graphics13 Testing for the side of a line. Need to find coefficients a,b,c. Recall explicit, slope-intercept form : So:

Graphics14 Decision variable. Previous Pixel (x p,y p ) Choices for Current pixel Choices for Next pixel Evaluate F at point M Referred to as decision variable M NE E

Graphics15 Decision variable. Evaluate d for next pixel, Depends on whether E or NE Is chosen : If E chosen : But recall : So : M E NE Previous Pixel (x p,y p ) Choices for Current pixel Choices for Next pixel

Graphics16 Decision variable. If NE was chosen : So : M E NE Previous Pixel (x p,y p ) Choices for Current pixel Choices for Next pixel

Graphics17 Summary of mid-point algorithm Choose between 2 pixels at each step based upon sign of decision variable. Update decision variable based upon which pixel is chosen. Start point is simply first endpoint (x 1, y 1 ). Need to calculate initial value for d

Graphics18 Initial value of d. But (x 1, y 1 ) is a point on the line, so F(x 1, y 1 ) =0 Conventional to multiply by 2 to remove fraction  doesn’t effect sign. Start point is (x 1, y 1 )

Graphics19 Bresenham algorithm void MidpointLine(int x1,y1,x2,y2) { int dx=x2-x1; int dy=y2-y1; int d=2*dy-dx; int increE=2*dy; int incrNE=2*(dy-dx); x=x1; y=y1; WritePixel(x,y); while (x < x2) { if (d<= 0) { d+=incrE; x++ } else { d+=incrNE; x++; y++; } WritePixel(x,y); }

Graphics20 Bresenham was not the end! 2-step algorithm by Xiaolin Wu: (see Graphics Gems 1, by Brian Wyvill) Treat line drawing as an automaton, or finite state machine, ie. looking at next two pixels of a line, easy to see that only a finite set of possibilities exist. The 2-step algorithm exploits symmetry by simultaneously drawing from both ends towards the midpoint.

Graphics21 Two-step Algorithm Possible positions of next two pixels dependent on slope – current pixel in blue: Slope between 0 and ½ Slope between ½ and 1 Slope between 1 and 2 Slope greater than 2

Graphics22 Circle drawing. Can also use Bresenham to draw circles. Use 8-fold symmetry Choices for Next pixel M E SE Previous Pixel Choices for Current pixel

Graphics23 Circle drawing. Implicit form for a circle is: Functions are linear equations in terms of (x p, y p ) –Termed point of evaluation

Graphics24 Problems with Bresenham algorithm Pixels are drawn as a single line  unequal line intensity with change in angle. Pixel density = n pixels/mm Pixel density =  2.n pixels/mm Can draw lines in darker colours according to line direction. - Better solution : antialiasing !

Graphics25 Summary of line drawing so far. Explicit form of line –Inefficient, difficult to control. Parametric form of line. –Express line in terms of parameter t –DDA algorithm Implicit form of line –Only need to test for ‘side’ of line. –Bresenham algorithm. –Can also draw circles.

Graphics26 Sampling theory tells us aliasing is caused by frequencies being present above the Nyquist limit. Ideal solution : band-pass filter to remove high frequencies. Fourier transform tells us the transform of a band-pass filter is a sinc function. Convolution theory tells us we can convolve with a sinc function in the spatial domain instead. A sinc function is an impractical filter. Summary of aliasing.

Graphics27 Antialiasing Gather all the values into the pixels -Loop round the pixels. -Used for complex scenes. -Cast out rays, convolve result into pixel (Pixel Grid  Impulse) x line Two ways of antialiasing

Graphics28 Antialiasing Two ways of antialiasing Scatter values into the pixels -Loop along the line. -If line is delta function, we just sweep the pixel filter along the line (Line  Pixel) x impulse

Graphics29 Antialiasing lines. Obvious : Need a grey level display in order to remove aliasing. Convolve line with filter function for pixel –Box filter  area sample –Convolution with conical filter function. Price to be paid : trade off spatial resolution –Line appears more ‘blurred’, it’s exact position is no longer as well defined. –In practice : contrast of lines much reduced. 1 pixel

Graphics30 Antialiasing by area sampling. Convolve line with box filter function  Draw line as thin rectangle. Calculate area of square pixel covered by line Problem : Equal areas contribute equal intensity, regardless of distance from line centre Small area in the pixels centre contributes as much as a small area at the pixels edge.

Graphics31 Weighted area filtering. Convolution with a conical filter. Easy to compute, symmetrical. Lines are same distance from pixel centre, but area of pixel covered is very different in the square case

Graphics32 Weighted area filtering. Diameter is 2 pixels, so overlap occurs –Ensures all of the grid is covered Area is normalised Only need to know distance from pixel centre to line Gupta-Sproull algorithm.

Graphics33 Gupta-Sproull algorithm. M NE Calculate distance using features of mid-point algorithm D Angle =  v dy dx E

Graphics34 Gupta-Sproull algorithm. Calculate distance using features of mid-point algorithm See Foley Van-Dam Sec d is the decision variable.

Graphics35 Filter shape. Cone filter –Simply set pixel to a multiple of the distance Gaussian filter –Store precomputed values in look up table Thick lines –Store area intersection in look-up table.

Graphics36 Summary of antialiasing lines Use square unweighted average filter –Poor representation of line. Weighted average filter better Use Cone –Symmetrical, only need to know distance –Use decision variable calculated in Bresenham. –Gupta-Sproull algorithm.