CGMB214: Introduction to Computer Graphics

Slides:



Advertisements
Similar presentations
Line Drawing Algorithms
Advertisements

Graphics Primitives Part II: Bresenhams line and circle.
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.
1 King ABDUL AZIZ University Faculty Of Computing and Information Technology CS 454 Computer graphics Drawing Elementary Figures Dr. Eng. Farag Elnagahy.
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.
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.
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
The lines of this object appear continuous However, they are made of pixels 2April 13, 2015.
OUTPUT PRIMITIVES Screen vs. World coordinate systems ● Objects positions are specified in a Cartesian coordinate system called World Coordinate.
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
In the name of God Computer Graphics Bastanfard.
Raster conversion algorithms for line and circle
Output Primitives Computer Graphics.
Course Website: Computer Graphics 5: Line Drawing Algorithms.
Line Drawing by Algorithm. Line Drawing Algorithms Line drawn as pixels Graphics system –Projects the endpoints to their pixel locations in the frame.
CAP4730: Computational Structures in Computer Graphics Chapter 3 Hearn & Baker Portions obtained from Leonard McMillan’s COMP136 Notes:
CS 450: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
Circle Drawing algo..
1/1/20001 Topic >>>> Scan Conversion CSE Computer Graphics.
Scan Conversion. Also known as rasterization In our programs objects are represented symbolically –3D coordinates representing an object’s position –Attributes.
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.
Objectives Differentiate between raster scan display and random scan display.
Introduction Computer Graphics & Its application Types of computer graphics Graphic display : random Scan & Raster Scan display Frame buffer and video.
Graphics Output Primitives
 A line segment in a scene is defined by the coordinate positions of the line end-points x y (2, 2) (7, 5)
Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization.
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
GEOMETRY AND LINE GENERATION Geometry and Line Generation Chapter 2.
In the name of God Computer Graphics. Today Introduction Sampling Graphic Output Primitives 1.Line 2.Circle 3.Curve 4.polygon.
Lecture 13: Raster Graphics and Scan Conversion
Bresenham’s Line Algorithm
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.
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.
Rasterization CENG 477 Introduction to Computer Graphics Slides from Steve Marschner, CS4620, 2008 Cornell University.
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 Lecture 05 Line Drawing Techniques Taqdees A. Siddiqi
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
Line Drawing Algorithms
Lecture 9 Line Drawing Algorithms (Bresenham’s Line Algorithm)
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1
Lecture 8 Shear and Line Drawing Algorithms
Chapter Three Part I Output Primitives CS 380.
Computer Graphics 5: Line Drawing Algorithms
Computer Graphics 5: Line Drawing Algorithms
Computer Graphics 5: Line Drawing Algorithms
Chapter 3 Graphics Output Primitives
Presentation transcript:

CGMB214: Introduction to Computer Graphics Topic 4 Graphics Output Primitives (I)

Objectives To be able to define the term output primitives To be able to define and create points and lines To understand line-drawing algorithms and line function

Output Primitives “where scene been represented by basic geometric structure which map into rectangular grid of pixel” In short: Basic objects that create computer drawn pictures (points, lines, circles etc) Pixel: little rectangles with same size and shape at each screen points Image: is a rectangular grid or array of pixels.

The simplest form of output primitives are: Points Straight Lines These primitives are defines in the graphics library (high level) Learn the device-level algorithm for displaying 2D output primitives

Coordinate Reference Frames Screen coordinate Pixel position in the frame buffer Absolute coordinate The actual position within the coordinate in use Relative coordinate Coordinate position as an offset from the last position that was referenced (current position)

Points Accomplished by converting a single coordinate position by an application program into appropriate operations for output device in use (i.e. monitor) Electron beam is turned on to illuminate the screen phosphor depending on the display technology (Random-scan/Raster-scan)

OpenGL Point Function Default colour for primitives is white and the default point size is equal to the size of 1 pixel. Use glVertex*(); to state the coordinate value of a single position, where (*) determine the spatial dimension and data type of the coordinate value. glVertex must be placed in between glBegin (**); and glEnd();, where (**) refers to the kind of output primitive to be displayed

The type of output primitive to be displayed OpenGL Point Function glBegin(GL_POINTS); glVertex2i(40,50); glEnd(); The type of output primitive to be displayed The coordinate of the output primitive created Two dimensional, Integer data type

Lines Most common 2D primitive - done 100s or 1000s of times each frame Even 3D wire-frames are eventually 2D lines! Optimized algorithms contain numerous tricks/techniques that help in designing more advanced algorithms

Lines Converting a line segment Consider a line segment with endpoint (0,4) and (21,21) . Which pixel do we select?

Lines Naïve line conversion The naïve method select every pixel that the mathematical line segment intercept.

Lines Requirements: Must compute integer coordinates of pixels which lie on or near a line or circle. Pixel level algorithms are invoked hundreds or thousands of times when an image is created or modified – must be fast! Lines must create visually satisfactory images. Lines should appear straight Lines should terminate accurately Lines should have constant density Line algorithm should always be defined.

Line Drawing Algorithm Lines Line Drawing Algorithm Line Equation DDA (Digital Differential Algorithm) Bresenham’s Line Algorithm

Line Equation To create a line, an equation is used y = mx + c where: m is slope c is y intercept For example, given 2 points P1 (5,2) and P2 (10,12)

Line Equation In raster scan system, it will check for every pixel → need to calculate for all y for x = 5 until x = 10 y Plot P1 and P2 Calculate m and c Plot points from P1 to P2, based on x = 5 until x = 10 12 x = 6, y = 4 x = 7, y = 6 x = 8, y = 8 x = 9, y = 10 As you can see, the points are not connected, therefore the nearest pixel to the point is taken -8 x 5 10

Digital Deferential Algorithm A scan conversion line algorithm based on calculating either △x or△y, where △x = x2 – x1 and △y = y2 - y1 m = △y/ △x For line with positive slope greater than1 For line with positive slope smaller than1

Digital Deferential Algorithm For example, draw the line between P1(5,2) and P2(10,5) using DDA △x = 5, △y= 3, m = 3/5 m is positive and smaller than 1, therefore use k starts at 0 y0 = 2 y0 will take the value of y for P1

Digital Deferential Algorithm Since we are moving on y axis, we are going to move 5 steps in x axis (△x = 5) y1 is the point of y at x1 The value of y1 is then rounded to the nearest pixel position.

Digital Deferential Algorithm Move x, 1 step towards P2, plot y based on the rounded value of y1 Repeat the process until you reach P2 Plot P1 and P2 3 y 3 7 6 4 5 4 3 4 2 5 6 7 8 9 10 11 x

Digital Deferential Algorithm Advantages: Faster than using y = mx +c Eliminates multiplication (mx) by using screen characteristics, i.e. incrementing pixel Disadvantages: Floating point arithmetic is slower than integer arithmetic Rounding down take time Long lines can drift from the true line due to floating point round-off errors

Bresenham’s Line Algorithm Input the two line endpoints and store the left endpoint in (x0,y0) Load (x0,y0) into the frame buffer; that is, plot the first point. Calculate constants x, y, 2y, and 2y - 2x, and obtain the starting value for the decision parameter as P0 = 2y - x At each Xk along the line, starting at k = 0, perform the following test: If Pk < 0, the next point to plot is (xk + 1, yk) and Pk+1 = Pk + 2y Otherwise, the next point to plot is (xk + 1, yk + 1) and Pk+1 = Pk + 2y - 2x Repeat step 4, x times.

Bresenham’s Line Algorithm Given P1(5,2) and P2(10,5). Draw a line from P1 to P2 using Bresenham’s algorithm: △x = 5, △y= 3 P0 = 2△y-△x = 2(3) – 5 = 1 If Pk > 0, the next point to plot is (Xk + 1, Yk + 1) Therefore, plot (6,3)

Bresenham’s Line Algorithm △x=5, △y=3 P0=2△y-△x=2(3)-5=1 P0+1=P0+2△y-2△x=1+2(3)-2(5) =-3 P1+1=P1+2△y=-3+2(3) = 3 P2+1=P2+6-10=-1 P3+1=P3+6=5 P0 > 1, therefore (Xk + 1, Yk + 1) And use Pk+1 = Pk + 2y - 2y Plot (6,3) Plot (7,3) P0 < 1, therefore (xk + 1, yk) Plot (8,4) Plot (9,4) And use Pk+1 = Pk + 2y Stop when the value of Pk is the same as the value of y for P2

Bresenham’s Line Algorithm △x=5, △y=3 P0=2△y-△x=2(3)-5=1 P0+1=P0+2△y-2△x=1+2(3)-2(5) =-3 P1+1=P1+2△y=-3+2(3) = 3 P2+1=P2+6-10=-1 P3+1=P3+6=5 y 7 Plot (6,3) 6 5 4 Plot (7,3) 3 2 Plot (8,4) 5 6 7 8 9 10 11 x Plot (9,4)

Bresenham’s Line Algorithm Advantages Accurate and efficient – incremental integer calculations Can be adapted to draw circles and curves. Generalization: Increment (x or y) depending on slope (m) starting endpoints (left or right) special case (y=0 or x =0)

Optimisation Speed can be increased even more by detecting cycles in the decision variable. These cycles correspond to a repeated pattern of pixel choices. The pattern is saved and if a cycle is detected it is repeated without recalculating. 11 12 13 14 15 16 17 9 10 13 14 15 16 6 7 8