Line Drawing and Generalization. Outline  overview  line drawing  circle drawing  curve drawing.

Slides:



Advertisements
Similar presentations
Graphics Primitives: line
Advertisements

CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.
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.
Scan conversion of Line , circle & ellipse
Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing.
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.
Raster conversion algorithms for line and circle
Bresenham’s Midpoint Algorithm CS5600 Computer Graphics Rich Riesenfeld Spring 2006 Lecture Set 1.
University of Missouri at Columbia 2D Scan-line Conversion University of Missouri at Columbia.
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.
Circle Drawing algo..
Geometric Objects Computer Graphics Lab. Sun-Jeong Kim.
Rasterizing primitives: know where to draw the line Dr Nicolas Holzschuch University of Cape Town Modified.
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 325 Introduction to Computer Graphics 02 / 01 / 2010 Instructor: Michael Eckmann.
Larry F. Hodges 1 Design of Line and Circle Algorithms.
1Computer Graphics Implementation III Lecture 17 John Shearer Culture Lab – space 2
Graphics Graphics & Graphical Programming Lecture 14 - Lines & Circles.
Output Primitives Jehee Lee Seoul National University.
Introduction Computer Graphics & Its application Types of computer graphics Graphic display : random Scan & Raster Scan display Frame buffer and video.
Graphics Output Primitives
CGMB214: Introduction to Computer Graphics
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.
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.
Scan Conversion.
Lecture 13: Raster Graphics and 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.
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.
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 : output primitives.. 2 of 32 T1 – pp. 103–123, 137–145, 147–150, 164–171 Points and LinesPoints Line Drawing AlgorithmsLine Mid–Point.
Computer Graphics I, Fall 2010 Scan conversion algorithms.
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.
Primitive graphic objects
Computer Graphics Drawing Line.
CSCE 441 Lecture 2: Scan Conversion of Lines
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1
University of New Mexico
Implementation III.
Computer Graphics Implementation I.
Prof. Harriet Fell Spring 2007 Lecture 5 – January 17, 2006
Chapter Three Part I Output Primitives CS 380.
Introduction to Computer Graphics with WebGL
CSCE 441 Lecture 2: Scan Conversion of Lines
2D Scan-line Conversion
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
Primitive Drawing Algorithm
Primitive Drawing Algorithm
Implementation III Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

Line Drawing and Generalization

Outline  overview  line drawing  circle drawing  curve drawing

1. Overview application data structures/models application programs graphics systems display devices graphics primitives OpenGL pixel information

Geometric Primitives Building blocks for a 3D object Application programs must describe their service requests to a graphics system using geometric primitives !!! points, lines, polygons Why not providing data structures directly to the graphics system?

 display lists  evaluators  per-vertex operations & primitive assembly  pixel operations  rasterization  texture assembly  per-fragment operations per-vertex operations & primitive assembly rasterizationframe buffer texture assembly display lists evaluators pixel operations per-fragment operations geometric data pixel data OpenGL Rendering Pipeline

Continuity 8-connectivity (king – continuity) 4-connectivity (rook – continuity)

f f : L 1 => L 2  quality degradation!! Line drawing is at the heart of many graphics programs.  Smooth, even, and continuous as much as possible !!! Simple and fast !!! 2. Line Drawing ( x 1, y 1 ) ( x 2, y 2 )

Bresenham’s Line Drawing Algorithm via Pragram Transformation  additions / subtractions only  integer arithmetic  not programmers’ point of view but system developers’ point of view

var yt : real;  x,  y, xi, yi : integer; for xi := 0 to  x do begin yt := [  y/  x]*xi; yi := trunc(yt+[1/2]); display(xi,yi); end; var yt : real;  x,  y, xi, yi : integer; yt := 0; for xi := 0 to  x do begin yi := trunc(yt + [1/2]); display(xi,yi); yt := yt+[  y/  x] end; Eliminate multiplication !!! xx yy y = mx, m = [  y/  x] * **  x ≥  y ∴ m ≤ 1  x,  y: positive integers (0,0) (∆x, ∆y)

var ys : real;  x,  y, xi, yi : integer; ys := 1/2; for xi := 0 to dx do begin yi := trunc(ys); display(xi,yi); ys := ys+[  y/  x] end; var ysf : real;  x,  y, xi, ysi : integer; ysi := 0; ysf := 1/2; for xi := 0 to  x do begin display(xi,ysi); if ysf+[  y/  x] < 1 then begin ysf := ysf + [  y/  x]; end else begin ysi := ysi + 1; ysf := ysf + [  y/  x-1]; end; integer partfractional part *** **** Motivation(Cont’)

var  x,  y, xi, ysi, r : integer; ysi := 0; for xi := 0 to  x do begin display(xi,ysi); if then begin end else begin ysi := ysi + 1; end;

Motivation(Cont’) var  x,  y, xi, ysi, r : integer; ysi := 0; r := 2*  y -  x; for xi := 0 to  x do begin display(xi,ysi); if r < 0 then begin r := r + [2*  y]; end else begin ysi := ysi + 1; r := r + [2*  y -2*  x ]; end; Bresenham’s Algorithm !!! No multiplication/ division. No floating point operations.

Line-Drawing Algorithms Assumptions

DDA(Digital Differential Analyzer) Algorithm basic idea Take unit steps with one coordinate and calculate values for the other coordinate i.e. or discontinuity !! Why?

DDA(Cont’) procedure dda (x1, y1, x2, y2 : integer); var  x,  y, k : integer; x, y : real begin  x := x2 - x1;  y := y2 - y1; x := x1; y := y1; display(x,y); for k := 1 to  x do begin x := x + 1; y := y + [  y/  x]; display(round(x),round(y)); end { for k } end; { dda } expensive !! no *’s Assumption : 0  m <1, x1<x2

Bresenham’s Line Algorithm  basic idea − Find the closest integer coordinates to the actual line path using only integer arithmetic − Candidates for the next pixel position Specified Line Path Specified Line Path

Bresenham’s Line algorithm(Cont’)

=1

Bresenham’s Line algorithm(Cont’) procedure bres_line (x1, y1, x2, y2 : integer); var  x,  y, x,y,p,incrE,incrNE : integer; begin  x := x2 – x1;  y := y2 – y1; p := 2*  y -  x; incrE := 2*  y; incrNE := 2*(  y -  x); x := x1; y := y1; display(x,y); while x < x2 do begin if p<0 then begin p := p + incrE; x := x + 1; end; { then begin } else begin p := p + incrNE; y := y + 1; x := x + 1; end; { else begin } display (x, y); end { while x < x2 } end; { bres_line} Homework #2 Extend this algorithm for general cases.

Midpoint Line Algorithm Van Aken, “An Efficient Ellipse - Drawing Algorithm” IEEE CG & A, 4(9), 24-35, Current pixel Choices for next pixel

Midpoint Line Algorithm (Cont’)

Midpoint Line Alg. (Cont’)

Midpoint Line Algorithm(Cont’) procedure mid_point (x1, y1, x2, y2,value : integer); var  x,  y,incrE,incrNE,p,x,y : integer; begin  x := x2 – x1;  y := y2 – y1; p := 2*  y -  x; incrE := 2*  y; incrNE := 2*(  y-  x); x := x1; y := y1; display(x,y); while x  x2 do begin if p < 0 then begin p := p + incrE; x := x + 1; end; { then begin } else begin p := p + incrNE; y := y + 1; x := x + 1; end; { else begin } display(x,y); end; { while x  x2 } end; { mid_point }

Geometric Interpretation any slope Bresenhams’s algorithm

x y Geometric Interpretation(Cont’)

Aliasing Effects staircases (or jaggies) intensity variation  line drawing

animation texturing popping-up

Anti-aliasing Lines  Removing the staircase appearance of a line  Why staircases? raster effect !!!  need some compensation in line-drawing algorithms for this raster effect? How to anti-alias? well, … increasing resolution. However,...

Increasing resolution memory cost memory bandwidth scan conversion time display device cost

 super sampling (postfiltering)  area sampling (prefiltering)  stochastic sampling Cook, ACM Trans. CG, 5(1), , Anti-aliasing Line (Cont’) Anti-aliasing Techniques

Area Sampling (Prefiltering)

box filtercone filter Filters unweighted area sampling weighted area sampling

Table look-up for f ( D, t ) The table is invariant of the slope of line! Why? The search key for the table is D! Why? D

Intensity Functions f ( D, t ) (assumption : t=1)

How to compute D (assumption : t=1)

How to compute D, incrementally

IF (Cont’) Similarly, M D 1 - v 1 + v v

IF (Cont’)  x := x2 - x1;  y := y2 - y1; p := 2 *  y -  x;{Initial value p 1 as before} incrE := 2 *  y;{Increment used for move to E} incrNE := 2 * (  y -  x);{Increment used for move to NE} two_v_  x := 0;{Numerator; v = 0 for start pixel} invDenom := 1 / (2 * Sqrt(  x *  x +  y *  y));{Precomputed inverse denominator} two_  x_invDenom := 2 *  x * invDenom; {Precomputed constant} x := x1; y := y1; IntensifyPixel (x, y, 0);{Start pixel} IntensifyPixel(x, y + 1, two_  x_invDenom);{Neighbor} IntensifyPixel(x, y - 1, two_  x_invDenom);{Neighbor} while x < x2 do begin if p < 0 then begin {Choose E} two_v_  x := p +  x; p := p + incrE; x := x + 1 end else begin {Choose NE} two_v_  x := p -  x; p := p + incrNE; x := x + 1; y := y + 1; end ; {Now set chosen pixel and its neighbors} IntensifyPixel (x, y, two_v_  x * invDenom); IntensifyPixel (x, y + 1, two_  x_invDenom - two_v_  x * invDenom); IntensifyPixel (x, y - 1, two_  x_invDenom + two_v_  x * invDenom) end {while}

3. Circle Drawing

using symmetry (0,r) r symmetry

Midpoint Circle Algorithm Current pixel Choices for next pixel

(0, R) MCA (Cont’)

procedure MidpointCircle (radius,value : integer); var x,y : integer; P: real; begin x := 0; { initialization } y := radius; P := 5/4 - radius; CirclePoints(x,y,value); while y > x do begin if P < 0 then { select E } P : = P + 2*x + 3; x := x + 1; end else begin { select SE } P := P + 2*(x - y) + 5; x := x + 1; y := y - 1; end CirclePoints(x,y,value) end { while } end; { MidpointCircle } * ** d = P - 1/4 P = d + 1/4 * d = 1 - radius ** d < -1/4  d < 0 why? *** d := d + 2*x + 3 **** d := d + 2(x-y) + 5 *** **** (0, R) MCA (Cont’) y=x

procedure MidpointCircle (radius,value : integer); { Assumes center of circle is at origin. Integer arithmetic only } var x,y,d : integer; begin x := 0; { initialization } y := radius; d := 1 - radius; CirclePoints(x,y,value); while y > x do begin if d < 0 then { select E } d := d + 2*x + 3; x := x + 1; end else begin { select SE } d := d+2*(x - y) + 5; x := x + 1; y := y - 1; end CirclePoints(x,y,value) end { while } end; { MidpointCircle } Can you go further? MCA (Cont’)

procedure MidpointCircle (radius,value : integer); { This procedure uses second-order partial differences to compute increments in the decision variable. Assumes center of circle is origin. } var x,y,d,deltaE,deltaSE : integer; begin x := 0; { initialization } y := radius; d := 1 - radius; deltaE := 3; deltaSE := -2*radius + 5; CirclePoints(x,y,value); while y > x do begin if d < 0 then { select E } d := d + deltaE; deltaE := deltaE + 2; deltaSE := deltaSE + 2; x := x + 1; end else begin { select SE } d := d + deltaSE; deltaE := deltaE + 2; deltaSE := deltaSE + 4; x := x + 1; y := y - 1 end CirclePoints(x,y,value) end { while } end; { MidpointCircle }

Drawing Ellipse Homework #3 Modify the midpoint circle drawing algorithm to draw ellipses.

4. Curve Drawing   parametric equation  discrete data set − curve fitting − piecewise linear