Line and Curve Drawing Algorithms. Line Drawing x0x0 y0y0 x end y end.

Slides:



Advertisements
Similar presentations
Computer Graphics - Graphics Programming -
Advertisements

Department of nskinfo i-education
Graphics Primitives: line
OpenGL Open a Win32 Console Application in Microsoft Visual C++.
OpenGL CMSC340 3D Character Design & Animation. What is OpenGL? A low-level graphics library specification designed for use with the C and C++ provides…
Coordinate System.
OPEN GL. Install GLUT Download package di sini Dari devcpp, buka Tools->PackageManager-
Lecture 3 Graphics Pipeline and Graphics Software
Okay, you have learned … OpenGL drawing Viewport and World Window setup main() { glViewport(0,0,300,200); glMatrixMode(GL_PROJECTION); glLoadIndentity();
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.
CS 376 Introduction to Computer Graphics 02 / 02 / 2007 Instructor: Michael Eckmann.
CS 450: COMPUTER GRAPHICS REVIEW: DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
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.
Chapter 2: Graphics Programming
CHAPTER 3 2D GRAPHICS ALGORITHMS
CS 376 Introduction to Computer Graphics 01 / 29 / 2007 Instructor: Michael Eckmann.
OPENGL.
OUTPUT PRIMITIVES Screen vs. World coordinate systems ● Objects positions are specified in a Cartesian coordinate system called World Coordinate.
Computer Graphics CSCE 441
Okay, you have learned … OpenGL drawing Viewport and World Window setup main() { glViewport(0,0,300,200); glMatrixMode(GL_PROJECTION); glLoadIndentity();
Pemrograman OpenGL Dasar
#include int line_width = 1; void Display( void ) { glEnable( GL_LINE_STIPPLE ); glClearColor (0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT);
OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
Expanded by Jozef Goetz Chapter 3 Graphics Output Primitives Some slides adapted from Benjamin Lok, Ilmi Yoon and Falko Kuester.
CSC 461: Lecture 51 CSC461 Lecture 5: Simple OpenGL Program Objectives: Discuss a simple program Discuss a simple program Introduce the OpenGL program.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
Ellipses Using OpenGL.
Line Drawing by Algorithm. Line Drawing Algorithms Line drawn as pixels Graphics system –Projects the endpoints to their pixel locations in the frame.
Computer Graphics CS 385 February 7, Fundamentals of OpenGl and Glut Today we will go through the basics of a minimal OpenGl Glut project, explaining.
CS 450: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
CAP 4703 Computer Graphic Methods Prof. Roy Levow Lecture 2.
CS 325 Introduction to Computer Graphics 02 / 01 / 2010 Instructor: Michael Eckmann.
Lecture 3 OpenGL.
1 Figures are extracted from Angel's book (ISBN x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole.
Introduction to GL Geb Thomas. Example Code int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
Interactive Computer Graphics CS 418 MP1: Dancing I TA: Zhicheng Yan Sushma S Kini Mary Pietrowicz Slides Taken from: “An Interactive Introduction to OpenGL.
Graphics Output Primitives Hearn & Baker Chapter 3
CA 302 Computer Graphics and Visual Programming Lecture 2: Introduction to OpenGL Aydın Öztürk
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
GEOMETRY AND LINE GENERATION Geometry and Line Generation Chapter 2.
NoufNaief.net 1 TA: Nouf Al-Harbi.
OpenGL Basic Drawing 2003 Spring Keng Shih-Ling
CS552: Computer Graphics Lecture 6: Viewing in 2D.
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
OpenGL Basic Drawing Jian-Liang Lin A Smidgen of OpenGL Code #include main() { InitializeAWindowPlease(); glClearColor (0.0, 0.0, 0.0, 0.0); glClear.
Introduction to Graphics Programming. Graphics API.
Graphics Graphics Korea University kucg.korea.ac.kr Graphics Programming 고려대학교 컴퓨터 그래픽스 연구실.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
Computer Graphics CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
10/10/2006TCSS458A Isabelle Bichindaritz1 Line and Circle Drawing Algorithms.
INTRODUCTION TO OPENGL
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
CS 480/680 Computer Graphics Programming with Open GL Part 2: Complete Programs Dr. Frederick C Harris, Jr. Fall 2011.
Programming with OpenGL Part 2: Complete Programs
OpenGL API 2D Graphic Primitives
Programming with OpenGL Part 2: Complete Programs
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
גרפיקה ממוחשבת: מבוא ל-OpenGL
Introduction to OpenGL
Line and Curve Drawing Algorithms
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Scan Conversion (From geometry to pixels)
Programming with OpenGL Part 2: Complete Programs
Primitive Drawing Algorithm
Primitive Drawing Algorithm
Programming with OpenGL Part 2: Complete Programs
Presentation transcript:

Line and Curve Drawing Algorithms

Line Drawing x0x0 y0y0 x end y end

Line Drawing x0x0 y0y0 x end y end

Line Drawing x0x0 y0y0 x end y end

DDA Algorithm if |m|<1 x k+1 = x k + 1 y k+1 = y k + m if |m|>1 y k+1 = y k + 1 x k+1 = x k + 1/m x0x0 y0y0 x end y end x0x0 y0y0 x end y end

DDA Algorithm #include inline int round (const float a) { return int (a + 0.5); } void lineDDA (int x0, int y0, int xEnd, int yEnd) { int dx = xEnd - x0, dy = yEnd - y0, steps, k; float xIncrement, yIncrement, x = x0, y = y0; if (fabs (dx) > fabs (dy)) steps = fabs (dx);/* |m|<1 */ else steps = fabs (dy);/* |m|>=1 */ xIncrement = float (dx) / float (steps); yIncrement = float (dy) / float (steps); setPixel (round (x), round (y)); for (k = 0; k < steps; k++) { x += xIncrement; y += yIncrement; setPixel (round (x), round (y)); }

Bresenham’s Line Algorithm xkxk ykyk x k+1 y k+1 y dudu dldl xkxk x k+1 ykyk y k+1

Bresenham’s Line Algorithm #include /* Bresenham line-drawing procedure for |m|<1.0 */ void lineBres (int x0, int y0, int xEnd, int yEnd) { int dx = fabs(xEnd - x0), dy = fabs(yEnd - y0); int p = 2 * dy - dx; int twoDy = 2 * dy, twoDyMinusDx = 2 * (dy - dx); int x, y; /* Determine which endpoint to use as start position. */ if (x0 > xEnd) { x = xEnd; y = yEnd; xEnd = x0; } else { x = x0; y = y0; } setPixel (x, y); while (x < xEnd) { x++; if (p < 0) p += twoDy; else { y++; p += twoDyMinusDx; } setPixel (x, y); }

Circle Drawing Pythagorean Theorem: x 2 + y 2 = r 2 (x-x c ) 2 + (y-y c ) 2 = r 2 (x c -r) ≤ x ≤ (x c +r) y = y c ± √r 2 - (x-x c ) 2 xcxc ycyc r (x, y)

Circle Drawing change x change y

Circle Drawing using polar coordinates x = x c + r. cos θ y = y c + r. sin θ change θ with step size 1/r r (x, y) (x c, y c ) θ

Circle Drawing using polar coordinates x = x c + r. cos θ y = y c + r. sin θ change θ with step size 1/r use symmetry if θ>45 0 r (x, y) (x c, y c ) θ (x, y) (x c, y c ) 45 0 (y, x)(y, -x) (-x, y)

Midpoint Circle Algorithm f(x,y) = x 2 + y 2 - r 2 <0 if (x,y) is inside circle f(x,y)=0 if (x,y) is on the circle >0 if (x,y) is outside circle use symmetry if x>y xkxk x k+1 y k -1 ykyk y k - 1/2

Midpoint Circle Algorithm #include class scrPt { public: GLint x, y; }; void setPixel (GLint x, GLint y) { glBegin (GL_POINTS); glVertex2i (x, y); glEnd ( ); } void circleMidpoint (scrPt circCtr, GLint radius) { scrPt circPt; GLint p = 1 - radius; circPt.x = 0; circPt.y = radius; void circlePlotPoints (scrPt, scrPt); /* Plot the initial point in each circle quadrant. */ circlePlotPoints (circCtr, circPt); /* Calculate next points and plot in each octant. */ while (circPt.x < circPt.y) { circPt.x++; if (p < 0) p += 2 * circPt.x + 1; else { circPt.y--; p += 2 * (circPt.x - circPt.y) + 1; } circlePlotPoints (circCtr, circPt); } void circlePlotPoints (scrPt circCtr, scrPt circPt); { setPixel (circCtr.x + circPt.x, circCtr.y + circPt.y); setPixel (circCtr.x - circPt.x, circCtr.y + circPt.y); setPixel (circCtr.x + circPt.x, circCtr.y - circPt.y); setPixel (circCtr.x - circPt.x, circCtr.y - circPt.y); setPixel (circCtr.x + circPt.y, circCtr.y + circPt.x); setPixel (circCtr.x - circPt.y, circCtr.y + circPt.x); setPixel (circCtr.x + circPt.y, circCtr.y - circPt.x); setPixel (circCtr.x - circPt.y, circCtr.y - circPt.x); }

OpenGL #include // (or others, depending on the system in use) void init (void) { glClearColor (1.0, 1.0, 1.0, 0.0); // Set display-window color to white. glMatrixMode (GL_PROJECTION); // Set projection parameters. gluOrtho2D (0.0, 200.0, 0.0, 150.0); } void lineSegment (void) { glClear (GL_COLOR_BUFFER_BIT); // Clear display window. glColor3f (0.0, 0.0, 1.0); // Set line segment color to blue. glBegin (GL_LINES); glVertex2i (180, 15); // Specify line-segment geometry. glVertex2i (10, 145); glEnd ( ); glFlush ( ); // Process all OpenGL routines as quickly as possible. } void main (int argc, char** argv) { glutInit (&argc, argv); // Initialize GLUT. glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); // Set display mode. glutInitWindowPosition (50, 100); // Set top-left display-window position. glutInitWindowSize (400, 300); // Set display-window width and height. glutCreateWindow ("An Example OpenGL Program"); // Create display window. init ( ); // Execute initialization procedure. glutDisplayFunc (lineSegment); // Send graphics to display window. glutMainLoop ( ); // Display everything and wait. }

OpenGL Point Functions glVertex*( ); * : 2, 3, 4 i (integer) s (short) f (float) d (double) Ex: glBegin(GL_POINTS); glVertex2i(50, 100); glEnd(); Ex: int p1[ ]={50, 100}; glBegin(GL_POINTS); glVertex2iv(p1); glEnd();

OpenGL Line Functions GL_LINES GL_LINE_STRIP GL_LINE_LOOP Ex: glBegin(GL_LINES); glVertex2iv(p1); glVertex2iv(p2); glEnd();

OpenGL glBegin(GL_LINES);GL_LINESGL_LINE_STRIP glVertex2iv(p1); glVertex2iv(p2); glVertex2iv(p3); glVertex2iv(p4); glVertex2iv(p5); glEnd(); GL_LINE_LOOP p1 p2 p3 p2 p4 p3 p5 p4 p5

Antialiasing 19 No Antialiasing With Antialiasing Ideal

Antialiasing No AntialiasingWith Antialiasing

Antialiasing Supersampling Count the number of subpixels that overlap the line path. Set the intensity proportional to this count.

Antialiasing Supersampling Actual Screen Pixels 3x3 Virtual Pixels (255, 159, 159) Example (255,255,255)(255,0,0)(255,255,255) (255,0,0)(255,255,255) (255,0,0)

Antialiasing Area Sampling Line is treated as a rectangle. Calculate the overlap areas for pixels. Set intensity proportional to the overlap areas. 80%25%

Antialiasing Pixel Sampling Micropositioning Electron beam is shifted 1/2, 1/4, 3/4 of a pixel diameter.

Line Intensity differences Change the line drawing algorithm: For horizontal and vertical lines use the lowest intensity For 45 o lines use the highest intensity