1 Module U08181: Computer Graphics graphics primitives part 1: scan conversion and filling.

Slides:



Advertisements
Similar presentations
Graphics Primitives: line
Advertisements

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.
Basic Raster Graphics Algorithms for Drawing 2D Primitives
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.
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.
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
Lecture 17 Fun with Graphics Dr. Dimitrios S. Nikolopoulos CSL/UIUC.
The lines of this object appear continuous However, they are made of pixels 2April 13, 2015.
Computer Graphics Tz-Huan Huang National Taiwan University (Slides are based on Prof. Chen’s)
Lecture 16 Fun with graphics
Raster conversion algorithms for line and circle
Output Primitives Computer Graphics.
CS5500 Computer Graphics © Chun-Fa Chang, Spring 2007 CS5500 Computer Graphics May 3, 2007.
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)
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..
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.
Rasterizing primitives: know where to draw the line Dr Nicolas Holzschuch University of Cape Town Modified.
1/1/20001 Topic >>>> Scan Conversion CSE Computer Graphics.
Dr. S.M. Malaek Assistant: M. Younesi
1 CPE 333 : Computer Graphics มหาวิทยาลัยเทคโนโลยีพระจอม เกล้าธนบุรี Dr. Natasha Dejdumrong.
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.
Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 121 Today’s class Drawing lines Bresenham’s algorithm Compositing Polygon filling.
1Computer Graphics Implementation III Lecture 17 John Shearer Culture Lab – space 2
Graphics Output Primitives
CGMB214: Introduction to Computer Graphics
2D Output Primitives Points Lines Circles Ellipses Other curves Filling areas Text Patterns Polymarkers.
Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization.
Digital Media Dr. Jim Rowan ITEC So far… We have compared bitmapped graphics and vector graphics We have discussed bitmapped images, some file formats.
Computer Graphics Rendering 2D Geometry CO2409 Computer Graphics Week 2.
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.
EEL Introduction to Computer Graphics
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2013 Tamara Munzner Rasterization.
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
GEOMETRY AND LINE GENERATION Geometry and Line Generation Chapter 2.
CS 551 / 645: Introductory Computer Graphics
MIT EECS 6.837, Durand and Cutler The Graphics Pipeline: Line Clipping & Line Rasterization.
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 : 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.
1 U08181 Computer Graphics Clipping Transformations –Transformations and matrices –Homogeneous matrices –Transformations in SVG.
Rasterization, or “What is glBegin(GL_LINES) really doing?” Course web page: February 23, 2012  Lecture 4.
Primitive graphic objects
Scan Conversion or Rasterization
Computer Graphics Filling.
Polygons.
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1
Scan Conversion or Rasterization
Computer Graphics Filled Area Primitives II Lecture 09 Taqdees A
Introduction to Computer Graphics
OUTPUT PRIMITIVES / DISPLAY TECHNIQUES
Presentation transcript:

1 Module U08181: Computer Graphics graphics primitives part 1: scan conversion and filling

2 Raster graphics vector graphics systems draw lines -- will be discussed later A raster (bitmapped) graphics display is a ‘grid’ of picture elements -- pixels, dots

3 Raster display: an array of pixels 0 0 screenHeight screenWidth

4 Cartesian coordinates René Descartes y x Note: x is always from left to right some systems use y top to bottom

5 Scan conversion cartesian coordinates: real, continuous raster positions: integer, discrete scan conversion: ‘rasterisation’, ‘discretisation’

6 Raster access PROCEDURE SetPixel (x, y: INTEGER; colour: INTEGER); (* pre: (x, y) is on screen post: pixel at (x, y) now in colour colour *) FUNCTION GetPixel (x, y: INTEGER): INTEGER; (* pre: (x, y) is on screen post: GetPixel (x, y) is colour of pixel at (x, y) *)

7 How to set pixels to: draw lines draw curves: circles... display characters filled shapes

8 Simple lines PROCEDURE HorizontalLine (x, y, n: INTEGER); (* pre: all of line will lie on screen post: line of n units drawn from point (x, y) *) VAR i: INTEGER; BEGIN FOR i := 0 TO n - 1 DO SetPixel(x+ i, y, black) END END HorizontalLine;

9 Other lines: arbitrary slope - naive approach PROCEDURE Line (x1, y1, x2, y2: INTEGER); VAR x, dx, dy: INTEGER; y: REAL; BEGIN dx := x2 - x1; dy := y2 - y1; FOR x := x1 TO x2 DO y := (dy / dx) * (x - x1) + y1; SetPixel(x, ROUND(y), black) END END Line;

10 Problems with naive approach: uses real (float) arithmetic including division -- slow uses ROUND -- slow

11 Better method: Bresenham’s algorithm Jack Bresenham

12 Bresenham’s algorithm: e measures the error between true position of point and nearest pixel

13 Bresenham’s algorithm: e measures the error between true position of point and nearest pixel simple version first: note precondition PROCEDURE Line (x1, y1, x2, y2: INTEGER); (* pre: dx > 0 & dy > 0 & dy/dx < 1 post: line drawn from (x1, y1) to (x2, y2) *) VAR dx, dy, e, x, y: INTEGER; BEGIN dx := x2 - x1; dy := y2 - y1; y := 0; e := dx - 2*dy;

14 continued FOR x := 0 TO dx DO SetPixel(x1+ x, y1 + y, black); IF e < 0 THEN y := y + 1; e := e + 2*(dx - dy) ELSE e := e - 2*dy END END Line;

15 Advantages of Bresenham’s algorithm uses only integer arithmetic - quick multiplications only by 2 - quick, program as left shifts or leave to a (good) compiler to do this. symmetry allows easy extension to slopes where dx > dy

16 Circle: algorithm by B. Weibel Note symmetry - we only need to draw one octant, then reflect, q is error measure PROCEDURE Circle (x1, y1, r: INTEGER); VAR x, y, q: INTEGER; BEGIN x := 0; y := r; q := 4*r; WHILE x < y DO (* set current pixel in each octant *)

17 circle: algorithm by B. Weibel SetPixel(x1 + x, y1 + y, black); SetPixel(x1 + x, y1 - y, black); SetPixel(x1 - x, y1 + y, black); SetPixel(x1 - x, y1 - y, black); SetPixel(x1 + y, y1 + x, black); SetPixel(x1 + y, y1 - x, black); SetPixel(x1 -y, y1 + x, black); SetPixel(x1 - y, y1 - x, black); (x1, y1) x y

18 circle continued x := x + 1; q := q - (8*x - 4); IF q < 1 THEN y := y - 1; q := q + 8*y END END; IF x = y THEN SetPixel(x1 + x, y1 + y, black); SetPixel(x1 + x, y1 - y, black); SetPixel(x1 - x, y1 + y, black); SetPixel(x1 - x, y1 - y, black); END END Circle;

19 Other curves More general curves can be obtained by: B-spline Bézier curves: developed for the UNISURF system by P. Bézier and used at Régie Renault for design of car bodies

20 Displaying characters: mask raster origin 0 xminxmax ymax ymin

21 Italics and bold Italics and bold can be created by algorithmic approach Typographically unsophisticated

22 WriteChar PROCEDURE WriteChar (chMask: MaskRaster; x, y: INTEGER); VAR i, j: INTEGER; BEGIN FOR j := chMask.xmin TO chMask.xmax - 1 DO FOR i := chMask.ymin TO chMask.ymax - 1 DO IF GetPixel(chMask, i, j) <> 0 THEN SetPixel(x + i, j + y, black) END END WriteChar;

23 Solid areas: Rectangle - easy PROCEDURE FilledRectangle (x, y, w, h: INTEGER); VAR i, j: INTEGER; BEGIN FOR j := y TO y + h - 1 DO FOR i := x TO x + w - 1 DO SetPixel(i, j, black) END END FilledRectangle;

24 ‘Paintpot’ fill: Pick a point (x, y) within the shape, replace all pixels adjacent of old colour by new colour PROCEDURE Fill (x, y, oldCol, newCol: INTEGER); VAR i, j: INTEGER; BEGIN IF GetPixel(x, y) = oldCol THEN SetPixel(x, y, newCol); FOR i := -1 TO 1 DO FOR j := -1 TO 1 DO Fill(x + i, j + y, oldCol, newCol) END END Fill;

25 Polygon filling y x crossed odd number of boundaries  inside shape

26 Polygon filling generate all the points (x, y) on periphery sort points first by y, then by x each pair of points(x a, y), (x b, y) is a region inside the polygon; for each such pair fill pixels from (x a, y) to (x b, y) inclusive can use dynamic data structure for this.

27 References The original paper: Bresenham, J. E.: ‘Algorithm for Computer Control of a Digital Plotter,’ IBM Sys. J. 4(1):25-30, 1965 Bresenham’s home page: Lines/bresnham.htm

28 References continued An applet that demonstrates Bresenham’s algorithm (fun): l Explanation and derivation: nes/bresenh.html Explanation and derivation: 5/ bresline/bresen.html

29 References continued Circle algorithm: by B. Weibel, in ‘System Programming in Modula-2: Mouse and Bitmap Display’ (second edition) J. Gutknecht, Institut für Informatik, ETH Zürich, Sept 1983, p44 Bézier P. :’Mathematical and Practical Possibilities of UNISURF’, in R.E. Barnhill and R.F. Riesenfeld (eds) Computer Aided Geometric Design, Academic, New York, 1974

30 Next lecture: clipping, transformations Exercises –see separate exercise sheet