Jehee Lee Seoul National University

Slides:



Advertisements
Similar presentations
Graphics Primitives Part II: Bresenhams line and circle.
Advertisements

COMPUTER GRAPHICS SOFTWARE.
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.
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.
30/9/2008Lecture 21 Computer Graphics Assistant Professor Dr. Sana’a Wafa Al-Sayegh 2 nd Semester ITGD3107 University of Palestine.
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.
Komputer Grafik 2 (AK045206) Scan Conversion 1/31 Scan Conversion.
In the name of God Computer Graphics Bastanfard.
Two-Dimensional Viewing Jehee Lee Seoul National University.
Output Primitives Computer Graphics.
1 CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai.
Graphics Output Primitives Pixel Addressing and Fill Area Dr. M. Al-Mulhem Feb. 1, 2008.
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..
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.
Dr. S.M. Malaek Assistant: M. Younesi
Graphics Output Primitives Sang Il Park Sejong 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
Tools for Raster Displays CVGLab Goals of the Chapter To describe pixmaps and useful operations on them. To develop tools for copying, scaling, and rotating.
10/15/02 (c) 2002 University of Wisconsin, CS559 Last Time Clipping.
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
Line Drawing and Generalization. Outline  overview  line drawing  circle drawing  curve drawing.
CGMB214: Introduction to Computer Graphics
Computer Graphics Chapter 6 Andreas Savva. 2 Interactive Graphics Graphics provides one of the most natural means of communicating with a computer. Interactive.
Affine Geometry Jehee Lee Seoul National University.
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.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2013 Tamara Munzner Rasterization.
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
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.
In the name of God Computer Graphics. Today Introduction Sampling Graphic Output Primitives 1.Line 2.Circle 3.Curve 4.polygon.
Institute for Visualization and Perception Research 1 © Copyright 2000 Haim Levkowitz Raster graphics alg’s for drawing 2D primitives Points of view Application.
Scan Conversion.
Lecture 13: Raster Graphics and Scan Conversion
OUTPUT PRIMITIVES A.Aruna/Faculty of Information technology/SNSCE13/19/2016.
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.
Scan Conversion of Line Segments. What is Scan conversion? Final step of rasterization (the process of taking geometric shapes and converting them into.
Rasterization, or “What is glBegin(GL_LINES) really doing?” Course web page: February 23, 2012  Lecture 4.
OUTPUT PRIMITIVES CEng 477 Computer Graphics METU, 2004.
Objectives Understand Bresenhams line drawing algorithm. Apply the algorithm to plot a line with the end points specified.
Primitive graphic objects
CSCE 441 Lecture 2: Scan Conversion of Lines
(c) 2002 University of Wisconsin, CS559
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1
CSCE 441 Lecture 2: Scan Conversion of Lines
© University of Wisconsin, CS559 Fall 2004
Scan Conversion of Circles
Introduction to Computer Graphics
Scan Conversion (From geometry to pixels)
Chapter 3 Graphics Output Primitives
SUBJECT : COMPUTER GRAPHICS
Presentation transcript:

Jehee Lee Seoul National University Output Primitives Jehee Lee Seoul National University

OpenGL Programming OpenGL ( gl ) is a common graphics library which provides functions for drawings and interactive input. OpenGL is accessible via C or C++ programs http://www.opengl.org OpenGL basic (core) library Functions, symbols, and types glBegin, glClear, glCopyPixels, glPolygonMode GL_2D, GL_RGB, GL_POLYGON Glbyte, Glshort, Glint, Glfloat, Gldouble

Related Libraries OpenGL Utility (GLU) OpenGL Utility Toolkit (GLUT) Setting up viewing and projection matrices Complex objects Line and polygon approximations Displaying quadrics, B-splines Prefix glu OpenGL Utility Toolkit (GLUT) Support any screen-windowing system

An Example of Open GL Initialize OpenGL and GLUT Initialize a drawing window Draw a line segment

Output and Input Pipeline Scan conversion converts primitives such as lines, circles, etc. into pixel values geometric description  a finite scene area Clipping the process of determining the portion of a primitive lying within a region called clip region

Output Pipeline Output pipeline (rendering process) Application model : descriptions of objects Application program : generates a sequence of functions to display a model Graphics package : clipping, scan conversion, shading Display H/W

Output Pipeline

Input Pipeline Input pipeline user interaction (e.g., mouse click) graphic package (by sampling or event-driven input functions) application program modify the model or the image on the screen

Hardware vs Software Pipelines Displays with frame buffers only scan conversion by a graphic package Displays with frame buffers and display controllers common in plug-in graphics card scan conversion by a graphic package and display processor

Scan conversion and Clipping Clipping before scan conversion Eg) Lines, rectangles, and polygons (scissoring) Clipping after scan converting the entire collection of primitives into a temporary canvas Eg) Text window Text can be clipped

Scan Converting Lines [Criteria] uniform, user-selected density A line from (x1,y1) to (x2,y2)  a series of pixels [Criteria] uniform, user-selected density straight lines should appear straight line end-points should be constrained line drawing algorithms should be fast

Why Study Scan Conversion Algorithms? Every high-end graphics card support this. You will never have to write these routines yourself, unless you become a graphics hardware designer. So why do we learn this stuff? Maybe you will become a graphics hardware designer But seriously, the same basic tricks underlie lots of algorithms: 3-D shaded polygons, texture mapping

Scan Converting Lines Digital Differential Analyzer(DDA) Basic incremental algorithm Each point is generated from the previous point in a simple fashion Slope of a line m = Δy/Δx y x

Digital Differential Analyzer(DDA) Idea Go to starting point Increment x and y values by constants proportional to x and y such that one of them is 1. Round to the closest raster position Drawbacks rounding to an integer takes time floating-point operations

Digital Differential Analyzer(DDA)

Midpoint Line Algorithm (Bresenham's Line Algorithm) Assume a line from (x0,y0) to (x1,y1) that 0<slope<1 and x0<x1 Suppose that we have just finished drawing a pixel P = (xp, yp) and we are interested in figuring out which pixel to draw next.

Midpoint Line Algorithm (Bresenham's Line Algorithm) If distance(NE,Q) > distance(E,Q) then select E = (xp+1, yp) else select NE = (xp+1, yp+1) NE E M P Q

Midpoint Line Algorithm (Bresenham's Line Algorithm) A line eq. in the implicit form F(x, y) = ax + by + c = 0 Using y = (Δy/Δx)x + B, where a = Δy, b = -Δx, c = B·Δx. F(x,y) = Δy·x - Δx·y + B·Δx = 0 Let's use an equivalent representation F(x,y) = 2ax + 2by + 2c = 0.

Midpoint Line Algorithm (Bresenham's Line Algorithm) Making slope assumptions, observe that b < 0, and this implies: F(x,y) < 0 for points above the line F(x,y) > 0 for points below the line To apply the midpoint criterion, we need only to compute F(M) = F(xp+1, yp+½) and to test its sign.

Midpoint Line Algorithm (Bresenham's Line Algorithm) To determine which one to pick up, we define a decision variable D = F(xp+1, yp+½) D = 2a(xp+1) + 2b(yp+½) + 2c = 2axp + 2byp + (2a + b + c) If D > 0 then M is below the line, so select NE, otherwise select E. NE E M P Q

Midpoint Line Algorithm (Bresenham's Line Algorithm) How to compute D incrementally? Suppose we know the current D value, and we want to determine the next D. If we decide on going to E next, Dnew = F(xp + 2, yp + ½) = 2a(xp + 2) + 2b(yp + ½) + c = D + 2a = D + 2Δy If we decide on going to NE next, Dnew = F(xp + 2, yp + 1 + ½) = 2a(xp + 2) + 2b(yp + 1 + ½) + c = D + 2(a + b) = D + 2(Δy - Δx).

Midpoint Line Algorithm (Bresenham's Line Algorithm) Since we start at (x0,y0), the initial value of D can be calculated by Dinit = F(x0 + 1, y0 + ½) = (2ax0 + 2by0 + c) + (2a + b) = 0 + 2a + b = 2Δy - Δx Advantages need to add integers and multiply by 2 (which can be done by shift operations) incremental algorithm

Midpoint Line Algorithm- Example Line end points: (x0,y0) = (5,8); (x1,y1) = (9,11) Δx = 4; Δy = 3 Dinit = 2Δy – Δx = 2 > 0  select NE Dnew = D + 2(Δy - Δx) = 0  Select E Dnew = D + 2Δy = 0 + 6 = 6 Select NE 13 12 11 10 9 8 7 6 4 5 6 7 8 9 10 11

Scan Converting Lines (issues) Endpoint order S01 is a set of pixels that lie on the line from P0 to P1 S10 is a set of pixels that lie on the line from P1 to P0  S01 should be the same as S10 Varying intensity of a line as a function of slope For the diagonal line, it is longer than the horizontal line but has the same number of pixels as the latter  needs antialiasing Outline primitives composed of lines Care must be taken to draw shared vertices of polylines only once

Scan Converting Lines (issues) Starting at the edge of a clip rectangle Starting point is not the intersection point of the line with clipping edge  Clipped line may have a different slope

Scan Converting Circles Eight-way symmetry We only consider 45° of a circle

Midpoint Circle Algorithm Suppose that we have just finished drawing a pixel (xp, yp) and we are interested in figuring out which pixel to draw next.

Midpoint Circle Algorithm F(x,y) = x2 + y2 - R2 = 0 on the circle > 0 outside the circle < 0 inside the circle If F(midpoint between E and SE) > 0 then select SE = (xp+1,yp-1) else select E = (xp+1, yp);

Midpoint Circle Algorithm Decision variable dold = F(xp+1, yp-½) = (xp+1)2 + (yp-½)2 - R2 If dold < 0, select E. dnew = F(xp+2, yp-½) = dold + (2xp + 3) If dold  0, select SE. dnew = F(xp+2, yp-½-1) = dold + (2xp - 2yp + 5) We have to calculate new d based on the point of evaluation P=(xp, yp), but this is not expensive computationally.

Midpoint Circle Algorithm Since we start at (0,R), the initial value of d can be calculated by dinit = F(1, R - ½) = 5/4 – R By substituting d - 1/4 by h, we can get the integer midpoint circle scan-conversion algorithm.

Scan Converting Ellipses F(x,y) = b2x2 + a2y2 -a2b2 Divide the quadrant into two regions; the boundary of two regions is the point at which the curve has a slope of -1. And then apply any midpoint algorithm.