Michener’s Algorithm An efficient scheme for drawing circles (and filling circular disks) on a raster graphics display.

Slides:



Advertisements
Similar presentations
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.
Advertisements

Larry F. Hodges (modified by Amos Johnson) 1 Design of Line, Circle & Ellipse Algorithms.
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 686: Programming SuperVGA Graphics Devices Introduction: An exercise in working with graphics file formats.
1 Computer Graphics Week6 –Basic Transformations- Translation & Scaling.
Raster conversion algorithms for line and circle
Programming Super-VGA Graphics Devices Introduction to VESA graphics modes and to organization of the linear frame-buffer memory.
Output Primitives Computer Graphics.
Drawing Lines The Bresenham Algorithm for drawing lines and filling polygons.
A code-walkthrough Commentary on our ‘wfmodel.cpp’ demo-program – an initial ‘prototype’ for 3D wire-frame animations.
CS5500 Computer Graphics © Chun-Fa Chang, Spring 2007 CS5500 Computer Graphics May 3, 2007.
The CRT Controller How to modify CRTC registers to achieve a non-standard horizontal and vertical screen resolution.
A code-walkthrough Commentary on our ‘model3d.cpp’ demo-program – an initial ‘prototype’ for 3D wire-frame animations.
Wire-frame Modeling An application of Bresenham’s line-drawing algorithm.
Vertical Retrace Interval An introduction to VGA techniques for smooth graphics animation.
Graphics Bitmaps Drawing characters glyphs and multicolor patterns.
How to do ‘page-flipping’ The steps needed when revising our ‘wfmodel1.cpp’ prototype to achieve ‘smooth’ animation.
Michener’s Algorithm An efficient scheme for drawing circles (and filling circular disks) on a raster graphics display.
VGA Color Registers How we can reprogram the Digital-to-Analog Converter’s 256 color-table registers.
Course Website: Computer Graphics 5: Line Drawing Algorithms.
Vertical Retrace Interval An introduction to VGA techniques for smooth graphics animation.
SiS 315 An introductory exploration of features of the SVGA graphics processor used in our classroom’s workstations.
Drawing Lines The Bresenham Algorithm for drawing lines and filling polygons.
1 King ABDUL AZIZ University Faculty Of Computing and Information Technology CS 454 Computer graphicsIntroduction Dr. Eng. Farag Elnagahy
Ch 1 Intro to Graphics page 1CS 367 First Day Agenda Best course you have ever had (survey) Info Cards Name, , Nickname C / C++ experience, EOS experience.
Circle Drawing algo..
IE433 CAD/CAM Computer Aided Design and Computer Aided Manufacturing Part-2 CAD Systems Industrial Engineering Department King Saud University.
Basics of a Computer Graphics System Introduction to Computer Graphics CSE 470/598 Arizona State University Dianne Hansford.
Rasterizing primitives: know where to draw the line Dr Nicolas Holzschuch University of Cape Town Modified.
Scan Conversion. Also known as rasterization In our programs objects are represented symbolically –3D coordinates representing an object’s position –Attributes.
1 CS 430/536 Computer Graphics I Circle Drawing and Clipping Week 3, Lecture 6 David Breen, William Regli and Maxim Peysakhov Geometric and Intelligent.
Dr. S.M. Malaek Assistant: M. Younesi
Jehee Lee Seoul National University
WHERE TO DRAW A LINE?? Line drawing is accomplished by calculating intermediate positions along the line path between specified end points. Precise definition.
Graphics Pipeline Rasterization CMSC 435/634. Drawing Terms Primitive – Basic shape, drawn directly – Compare to building from simpler shapes Rasterization.
ECE291 Computer Engineering II Lecture 9 Josh Potts University of Illinois at Urbana- Champaign.
Triangle Scan Conversion. 2 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Rasterization Rasterization (scan conversion) –Determine which.
Objectives Differentiate between raster scan display and random scan display.
College of Computer and Information Science, Northeastern UniversityOctober 12, CS G140 Graduate Computer Graphics Prof. Harriet Fell Spring 2006.
Line Drawing and Generalization. Outline  overview  line drawing  circle drawing  curve drawing.
CGMB214: Introduction to Computer Graphics
CAP4730: Computational Structures in Computer Graphics
Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization.
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
Program 2 due 02/01  Be sure to document your program  program level doc  your name  what the program does  each function  describe the arguments.
Digression on r/w ‘/proc’ files An application of kernel module programming to Super VGA graphics device control.
Midpoint Circle Algorithm
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.
Graphics Pipeline Rasterization CMSC 435/634. Drawing Terms Primitive – Basic shape, drawn directly – Compare to building from simpler shapes Rasterization.
CS-321 Dr. Mark L. Hornick 1 Graphics Displays Video graphics adapter Monitor.
Scan Conversion.
Lecture 11 Text mode video
Computer Graphics CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
Computer Graphics Lecture 03 Graphics Systems Cont… Taqdees A. Siddiqi
Computer Graphics Inf4/MSc Computer Graphics Lecture 4 Line & Circle Drawing.
10/10/2006TCSS458A Isabelle Bichindaritz1 Line and Circle Drawing Algorithms.
Computer Graphics Lecture 06 Circle Drawing Techniques Taqdees A. Siddiqi
Rasterization, or “What is glBegin(GL_LINES) really doing?” Course web page: February 23, 2012  Lecture 4.
Primitive graphic objects
Line Drawing Algorithms
Computer Graphics Lecture 13 Graphics Systems Taqdees A
2D GPU Platform with Hardware-Accelerated Features
CS G140 Graduate Computer Graphics
Lecture 05: Mid-point Ellipse algorithm Dr. Manal Helal – Fall 2014
Chapter Three Part I Output Primitives CS 380.
Scan Conversion of Circles
Graphics Systems Lecture-2
Presentation transcript:

Michener’s Algorithm An efficient scheme for drawing circles (and filling circular disks) on a raster graphics display

Scan conversion Geometric objects possess implicit parameters Example: A circle has a ‘center’ and a ‘radius’ Its equation is: (x – xc) 2 + (y - yc) 2 = R 2 x and y are from the continuum of real numbers CRT display is a discrete 2D array of ‘pixels’ So drawing a circle requires a conversion, from something continuous into something discrete In computer graphics it’s called scan conversion Imperfections: unavoidable, but to be minimized

Graphics Animations Fast drawing is essential for animations Some guidelines for speed: –eliminate all redundant computations –prefer integer arithmetic to floating-point –prefer add and subtract to multiply or divide Famous example: ‘Michener Algorithm’ We can use it later with our ‘pong’ game

Eight-fold symmetry (x, y)(-x, y) (x, -y) (-x, -y) (y, x) (y, -x) (-y, -x) (-y, x)

Compute only one octant

Subroutine: draw_octant_points Arguments: int x, y, xcent, ycent, color; draw_pixel( xcent + x, ycent + y, color ); draw_pixel( xcent + y, ycent + x, color ); draw_pixel( xcent - x, ycent + y, color ); draw_pixel( xcent - y, ycent + x, color ); draw_pixel( xcent + x, ycent - y, color ); draw_pixel( xcent + y, ycent - x, color ); draw_pixel( xcent - x, ycent - y, color ); draw_pixel( xcent - y, ycent - x, color );

The “best” pixel to draw? Blue pixel: too far from center ( E > 0 ) Red pixel: too near the center ( E < 0 ) Error-term: E = (x 2 + y 2 ) – R 2

Decision at n-th stage y n-1 x n-1 xnxn P n-1 A n ? B n ? Algorithm: compute sum = error( A n ) + error( B n ); If ( sum < 0 ) choose A n ; otherwise choose B n.

Formula: sum of error-terms Assume circle has radius R, center (0,0) error( A n ) = (x n-1 +1) 2 + (y n-1 ) 2 – R 2 error( B n ) = (x n-1 +1) 2 + (y n-1 – 1) 2 – R 2 sum n = 2(x n-1 +1) 2 + 2(y n-1 ) 2 –2(y n-1 ) R 2 Now, how is sum n different from sum n+1 : –If A n is chosen at the n-th step? –If B n is chosen at the n-th step?

Difference Equation Observe that: sum n+1 – sum n = 4x n (y n 2 – y n-1 2 ) – 2(y n – y n-1 ) When A n is selected at n-th stage: –we will have y n = y n-1 –thus: sum n+1 = sum n + 4x n When B n is selected at n-th stage: –we will have y n = y n –thus: sum n+1 = sum n + 4(x n-1 – y n-1 ) + 10

Algorithm initialization We start with the point P 0 = (x 0,y 0 ), where x 0 = 0 and y 0 = R In this case: A 1 = (1, R) and B 1 = (1, R-1) So the initial ‘sum-of-errors’ term will be: sum 1 = error(A 1 ) + error(B 1 ) = [(1 2 + R 2 ) – R 2 ] + [(1 2 + R 2 –2R+1) – R 2 ] = 3 – 2R

Michener’s Algorithm intx = 0, y = R, sum = 3 – 2*R; while ( x <= y ) { draw_octant_points( x, y, xc, yc, color ); if ( sum < 0 ) sum += 4*x + 6; else{ sum += 4*(x - y) + 10; --y; } ++x; }

Reference Francis S. Hill, jr., “Computer Graphics,” Macmillan (1990), pp NOTE: Michener’s circle-drawing method owes its inspiration to a famous algorithm for efficient line-drawing, devised in 1965 by J. E. Bresenham (see the IBM Systems Journal, vol 4, pp ).

Circle ‘fill’ also exploits symmetry (x, y)(-x, y) (x, -y) (-x, -y) (y, x) (y, -x) (-y, -x) (-y, x)

Subroutine: draw_segments Arguments: int x, y, xc, yc, color; draw_horiz( xc – x, xc + x, yc + y, color ); draw_horiz( xc – x, xc + x, yc - y, color ); draw_horiz( xc – y, xc + y, yc + x, color ); draw_horiz( xc – y, xc + y, yc - x, color );

draw_horiz( int xlo, xhi, y, color ); Clipping to screen boundaries: If (( y ymax )) return; if ( xlo < xmin ) xlo = xmin; if ( xhi > xmax ) xhi = xmax; Drawing the horizontal segment: for (x = xlo; x <= xhi; x++) draw_pixel( x, y, color );

Demo-program Try the ‘michener.cpp’ demo It uses VESA graphics-mode 0x0103 Screen resolution is 800x600 Color depth is 8 bits-per-pixel (8bpp) SVGA’s Linear Frame Buffer is enabled by calling VESA’s Set Display Mode service with bit #14 of the mode ID-number set

In-Class Exercise #1 Modify the ‘michener.cpp’ demo: –Use the standard ‘rand()’ function –Draw lots of color-filled circles –Stop if user hits key NOTE: For this latter feature, we need to recall how to set up the terminal keyboard so it uses a ‘non-canonical’ input-mode

Animation with ‘image tearing’ We used Michner’s Algorithm in a graphics animation demo (named ‘bouncing.cpp’) But you will see undesirable ‘tearing’ of the bouncing ball’s image – because we drew a large number of pixels, and computed a large number of pixel-locations – twice for each displayed frame (erase, then redraw) Not enough drawing time during ‘retrace’!

What can we do about it? One idea is to draw a smaller-sized ball Another idea is to draw only once – i.e. include enough extra pixels around the new ball’s perimeter to hide the old one Also we could ‘pre-compute’ coordinates An important general technique is to use off-screen display memory to ‘prepare’ a new screen-image, and then do a ‘bitblit’

SuperVGA’s hardware The graphics processor has the capability to switch the CRTC’s ‘start_address’, so we see a new full-screen image displayed almost instantly (i.e., just one or two CPU instructions), instead of a copying a screen But doing this for higher-resolution SVGA display-modes requires accessing one or more of the nonstandard VGA extensions

VESA’s BIOS-Extensions Video Electronics Standards Association defines a ROM-BIOS service that can be invoked to reprogram CRT Start_Address in a standard way for compliant systems For a particular vendor’s graphics card, we can discover how to directly reprogram the CRT’s Start-Address, by ‘trapping’ the I/O instructions used in the ROM-BIOS routine

Using ‘off-screen’ video memory Visible screen Alternate screen CRT Controller’s Start-Address (default=0) VRAM The currently displayed image is defined in this region of VRAM while an alternative image is prepared for display in this region of VRAM When the ‘alternate’ memory region is ready to be displayed, the CRT Start-Address register is rewritten, instantaneously changing what the user sees on the display monitor The technique is called ‘page flipping’

VBE service 0x07 This ROM-BIOS service can be called to obtain or modify the CRT Start-Address It isn’t instantaneous – because of all the parameter-passing and changing of CPU execution-mode and transitions back and forth from user-space to kernel-space But it might be fast enough to ‘cure’ the image-tearing we saw in ‘bouncing’ demo

In-class exercise #2 Look at documentation for VESA service 7 See if you can modify the main animation loop in our ‘bouncing.cpp’ program so the image-frames are alternately drawn in two different ‘pages’ of the video memory (i.e., implement the ‘page-flipping’ idea): while one frame is being viewed by the user, the next frame is being readied out-of-sight