2006 by Jim X. Chen: 1.1. Review –Graphics commands specify straight lines or other geometric primitives that are scan-converted.

Slides:



Advertisements
Similar presentations
Graphics Primitives: line
Advertisements

Computer Graphics- SCC 342
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.
Basic Raster Graphics Algorithms for Drawing 2D Primitives
Scan Conversion A. Samal. Scan Conversion Last step in the graphics pipeline Efficiency is a central issue Common primitives – Lines – Polygons – Circles.
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.
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 Tz-Huan Huang National Taiwan University (Slides are based on Prof. Chen’s)
OUTPUT PRIMITIVES Screen vs. World coordinate systems ● Objects positions are specified in a Cartesian coordinate system called World Coordinate.
Okay, you have learned … OpenGL drawing Viewport and World Window setup main() { glViewport(0,0,300,200); glMatrixMode(GL_PROJECTION); glLoadIndentity();
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
Graphics Pipeline.
Status – Week 257 Victor Moya. Summary GPU interface. GPU interface. GPU state. GPU state. API/Driver State. API/Driver State. Driver/CPU Proxy. Driver/CPU.
In the name of God Computer Graphics Bastanfard.
H331: Computer Graphics Philip Dutré Department of Computer Science Wednesday, February 25.
Output Primitives Computer Graphics.
1 King ABDUL AZIZ University Faculty Of Computing and Information Technology CS 454 Computer graphicsIntroduction Dr. Eng. Farag Elnagahy
CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Scan Conversion CS123 1 of 44Scan Conversion - 10/14/2014.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Models and Architectures Ed Angel Professor of Computer Science, Electrical and Computer.
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.
CAP4730: Computational Structures in Computer Graphics Chapter 3 Hearn & Baker Portions obtained from Leonard McMillan’s COMP136 Notes:
Computer Graphics/and Multimedia CMM472/CIT773 What is CG ?, History of CG, Course Overview.
Basic Graphics Concepts Day One CSCI 440. Terminology object - the thing being modeled image - view of object(s) on the screen frame buffer - memory that.
Computer Graphics/and Multimedia CMM472/CIT773 What is CG ?, History of CG, Course Overview.
Dr. S.M. Malaek Assistant: M. Younesi
Raster-scan system In addition to the central processing unit a special purpose processor called the video controller or display controller is used to.
Introduction to OpenGL and GLUT GLUT. What is OpenGL? An application programming interface (API) A (low-level) Graphics rendering API Generate high-quality.
Objectives Differentiate between raster scan display and random scan display.
2002 by Jim X. Chen: 1 So far, we only concerned with the rendering of geometric data. Two other important classes of data:
Graphics Systems and OpenGL. Business of Generating Images Images are made up of pixels.
CSC 461: Lecture 3 1 CSC461 Lecture 3: Models and Architectures  Objectives –Learn the basic design of a graphics system –Introduce pipeline architecture.
1 The Rendering Pipeline. CS788 Topic of HCI 2 Outline  Introduction  The Graphics Rendering Pipeline  Three functional stages  Example  Bottleneck.
COMPUTER GRAPHICS CSCI 375. What do I need to know?  Familiarity with  Trigonometry  Analytic geometry  Linear algebra  Data structures  OOP.
CGMB214: Introduction to Computer Graphics
CS662 Computer Graphics Game Technologies Jim X. Chen, Ph.D. Computer Science Department George Mason University.
Computer Graphics Chapter 6 Andreas Savva. 2 Interactive Graphics Graphics provides one of the most natural means of communicating with a computer. Interactive.
B. RAMAMURTHY Simulating Motion and Implementing Animation.
Introduction to OpenGL  OpenGL is a graphics API  Software library  Layer between programmer and graphics hardware (and software)  OpenGL can fit in.
1 3D API OPENGL ES v1.0 Owned by Silicon Graphics (SGL) Control was then transferred to Khronos Group Introduction.
Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera Real Light Synthetic Light Source.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
Beam Penetration & Shadow Mask Method
1 CSCE 441 Lecture 2: Scan Conversion of Lines Jinxiang Chai.
GEOMETRY AND LINE GENERATION Geometry and Line Generation Chapter 2.
Computer Graphics & Multimedia
CS-321 Dr. Mark L. Hornick 1 Graphics Displays Video graphics adapter Monitor.
The Graphics Pipeline Revisited Real Time Rendering Instructor: David Luebke.
Lecture 13: Raster Graphics and Scan Conversion
Computer Graphics Lecture 17 Fasih ur Rehman. Last Class 3D Transforms Inverse Rotation.
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 CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
Chapter 7 Introduction to High-Level Language Programming.
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.
Pattern filling in scan-conversion Antialiasing
Draw a Simple Object.
Basic Raster Graphics Algorithms for Drawing 2D Primitives
Computer Graphics George Mason University Jim X. Chen, Ph.D.
Lecture 18 Fasih ur Rehman
Store the primitives in a famebuffer, or refresh
Real-time Computer Graphics Overview
Models and Architectures
The Graphics Pipeline Lecture 5 Mon, Sep 3, 2007.
Graphics Systems Lecture-2
Edited from The Rasterization Problem: Idealized Primitives Map to Discrete Display Space Edited from.
Basic Raster Graphics Algorithms for Drawing 2D Primitives
CS297 Graphics with Java and OpenGL
Presentation transcript:

by Jim X. Chen: 1.1. Review –Graphics commands specify straight lines or other geometric primitives that are scan-converted into a set of discrete intensity pixels in the framebuffer (back buffer) –Color points in the frame buffer are sent to the corresponding pixels in the display device by a video controller The purpose of this section is to understand how the drawing primitives and clipping are implemented A graphics library function may be implemented quite differently

by Jim X. Chen: 2.2. SCAN CONVERTING LINES For now, we consider only 1-pixel width lines. NE E M1 P (x p, y p ) Raster The screen pixel mesh is represented in different forms

by Jim X. Chen: void line(int x0,int y0,int xn,int yn) { // for –1  m  1 int x; float m, y; m = (float) (yn-y0)/(xn-x0); x=x0; y=y0; while (x<xn+1) { // write a pixel into the framebuffer glBegin(GL_POINTS); glVertex2i (x, (int) (y+0.5)); glEnd(); x++; y+=m;/* next pixel's position */ }.3. The Basic Incremental Algorithm slope m =  y/  X; y i = mx i + B; y i+1 = y i + m Intensify the pixel at (xi, Round(yi)). 1.2.line Example: J1_2_Line

by Jim X. Chen: 4 NE E M1 P (x p, y p ).4. THE MIDPOINT LINE ALGORITHM The shortcoming of the previous algorithm is that rounding y to an integer takes time. y = (dy/dx)x +B, that is F(x,y)=dy*x - dx*y + B*dx =0 F(x,y) = ax + by + c = 0 when (x,y) on the line, where a=dy>0, b=-dx 0. F(x,y’) > 0 when (x,y’) below the line, and F(x,y’) < 0 when (x,y’) above the line. 1.3.line 1.2.line Q

by Jim X. Chen: 5.5. If F(x p +1, y p +1/2)>0, Q above M, choose NE; else choose E. Therefore we have a decision variable: d old = F(x p +1, y p +1/2) = F(x p, y p ) + a + b/2 = a + b/2 If d old <=0, E is chosen: d new = F(x p +2, y p +1/2) = d old + a If d old >0, NE is chosen: d new = F(x p +2, y p +3/2) = d old + a+b “a” and “b” are integers. Multiply the decision equations by 2 for integer operation: d old = 2F(x p +1, y p +1/2) = 2F(x p, y p ) + 2a + b = 2a + b If d old <=0, E is chosen: d new = 2F(x p +2, y p +1/2) = d old + 2a If d old >0, NE is chosen: d new = 2F(x p +2, y p +3/2) = d old + 2a+2b Let’s call dE = 2a = 2dy, dNE = 2(a + b) = 2(dy – dx), then If d old <=0: d new = d old + dE If d old >0: d new = d old + dNE

by Jim X. Chen: 6.6. We only need to decide if (d old >0) to choose NE or E, and update d new accordingly with an integer addition. Bresenham Line Alg. Bresenham Line Alg. void line(int x0,int y0,int xn,int yn) { // Bresenham's midpoint line algorithm int dx, dy, dE, dNE, d, x, y, flag = 0;...; // taking care of all slopes x=x0; y=y0; d=2*dy-dx; dE=2*dy; dNE=2*(dy-dx); while (x<xn+1) { writepixel(x,y,flag); x++; // next pixel if (d<=0) d+=dE; else { y++; d+=dNE; }; } Example: J1_3_Line

by Jim X. Chen: 7.7. SCAN CONVERTING CIRCLES x 2 +y 2 =R 2, therefore y=(R 2 -x 2 ) 1/2. We can increase x form 0 to R/2 to draw the corresponding points at (x,y), (y,x), (y,-x), (x,-y), (-x,-y), (-y,-x), (-y,x), (-x,y). void circlePixel(float x, float y) { WritePixel(x,y);WritePixel(y,x); WritePixel(-x,y);WritePixel(-y,x); WritePixel(x,-y);WritePixel(y,-x); WritePixel(-x,-y);WritePixel(-y,-x); } Time consuming space between pixels is not uniform R

Poloar Coordinates x = x c + r cos(  ); y = y c + r sin(  ); 8 double cx = WIDTH/2, cy = HEIGHT/2, //center of the circle r = WIDTH/3, // radius of the circle delta = 1/r; // angle for one unit apart: 2PI/2PI*r public void drawCircle(double x0, double y0, double r) { double th = 0; while (th<=Math.PI/4) { th = th+delta; double x = r*Math.cos(th); double y = r*Math.sin(th); drawPoint(x+x0, y+y0); drawPoint(x+x0, -y+y0); drawPoint(-x+x0, y+y0); drawPoint(-x+x0, -y+y0); drawPoint(y+x0, x+y0); drawPoint(y+x0, -x+y0); drawPoint(-y+x0, x+y0); drawPoint(-y+x0, -x+y0); }

Example: J1_3_CircleLine We often draw line segments instead of real curves void circle(double cx, double cy, double r) { double xn, yn, theta = 0, delta = 0.1; // the delta angle for a line segment double x0 = r*Math.cos(theta)+cx; double y0 = r*Math.sin(theta)+cy; while (theta<2*Math.PI) { theta = theta + delta; xn = r*Math.cos(theta)+cx; yn = r*Math.sin(theta)+cy; bresenhamLine((int)x0, (int)y0, (int)xn, (int)yn); x0 = xn; y0 = yn; }

by Jim X. Chen: E SE M ),( pp yx P Midpoint Circle Algorithm

by Jim X. Chen: Scan-converting Other Curves Conic Sections (2nd degree) Ax 2 + By 2 + Cxy + Dx + Ey + F = 0 B 2 - 4AC 0 hyperbola Parabolic path: (parametric equation) x = x 0 + v x0 t y = y 0 + v y0 t – gt 2 /2 Hyperbolic pathes: (x/r x ) 2 - (y/r y ) 2 = 1

by Jim X. Chen: 12 HW1_3: due before next class Draw a pentagon in a circle that rotates. You cannot use glBegin(GL_LINES). You should use glBegin(GL_POINTS) instead. You should implement your own line function that can be used to draw the pentagon. You may inherit my provided samples.

by Jim X. Chen: D Spline: two adjacent curve sections have the same coordinate position at the boundary and the slopes at the boundary are equal. x = a x + b x t + c x t 2 + d x t 3 y = a y + b y t + c y t 2 + d y t 3 z = a z + b z t + c z t 2 + d z t 3 where 0 <= t <= 1 Polynomials: useful in the design of object shapes, the specification of animation paths, and the graphing of data trends in a discrete set of data points.

by Jim X. Chen: FILLING RECTANGLES for (y=ymin; y<ymax; y++) for (x=xmin; x<xmax; x++) WritePixel(x,y,value); SCAN-CONVERTING POLYGONS Find the intersections of the scan-line with all edges of the polygon. Sort the intersections by increasing the x coordinate. Fill in all pixels between pairs of intersections that lie interior to the polygon, using the odd-parity rule to determine that a point is inside a region.

by Jim X. Chen: Scan-line algorithm for filling polygons ET (edge table) -- all edges sorted by the smaller y coords; AET (active-edge table) corresponds to the current scan-line

by Jim X. Chen: Set y to the smallest y that has an entry in the ET. Initialize the AET to be empty. Repeat until the AET and ET are empty: 1.Move from ET bucket y to AET those edges whose y min = y. 2.Sort the AET on x. 3.Fill-in desired pixel values on scan-line y by using pairs of x coord. From the AET. 4.Increment y by 1. 5.Remove from the AET those entries that y=y max. 6.For each non-vertical edge remaining in the AET, update x for the new y: x = x + 1/m. Example: J1_3_Triangle

by Jim X. Chen: A convex polygon means that all the angles inside the polygon formed by the edges are smaller than 180 degrees. If a polygon is not convex, it is concave. Convex polygons can be scan-converted faster than concave polygons. OpenGL draws a convex polygon with the following commands: glBegin(GL_POLYGON); // a list of vertices glEnd(); OpenGL Implementation

by Jim X. Chen: Implement functions myTriangle(double V[3][2]), myTriangle(double X[3], double Y[3]) and myTriangle(double x1, double y1, double x2, double y2, double x3, double y3) for J1_3_Triangle.java. You cannot use OpenGL functions such as glBegin(GL_TRIANGLES) to draw the triangle directly. 2. Generate random vertices and draw triangles. Used to be an homework: J1_3_Triangle.java

by Jim X. Chen: CHARACTERS Characters are polygons. However, they are used very often Type-face, font: the overall design style for a set of characters, Courier, Helvetica, Times, etc. Can represent the character shapes by rectangular grid patterns (bitmap font) Or describe character shapes by lines and curves, as in Postscript (outline font) Bitmap fonts require more space, because each variation (size or format) must be stored Bitmap Outline

by Jim X. Chen: Outline fonts require more time to produce, because they must be scan converted Small bitmaps do not scale well. Different bitmaps (sizes and typefaces) are defined accessing fonts is platform dependent. GLUT provides a simple platform independent subset of font functions. GLX provides font functions and interfaces between OpenGL and the X window system. WGL is the equivalent of GLX on the Microsoft Windows platform. Example: J1_3_xFont

by Jim X. Chen: Example: J1_3_xFont import javax.media.opengl.*; import com.sun.opengl.util.*; public class J1_3_xFont extends J1_3_Triangle { static GLUT glut = new GLUT(); public void display(GLAutoDrawable drawable) { //generate a random line; // bitmap fonts gl.glWindowPos3f(x0, y0, 0); // start poistion glRasterpos or glWindowPos glut.glutBitmapCharacter(GLUT.BITMAP_HELVETICA_18, 'S'); glut.glutBitmapString(GLUT.BITMAP_HELVETICA_18, "tart"); // stroke fonts gl.glPushMatrix(); gl.glTranslatef(xn, yn, 0); // end of line position gl.glScalef(0.2f, 0.2f, 0.2f); // size glut.glutStrokeCharacter(GLUT.STROKE_ROMAN, 'E'); glut.glutStrokeString(GLUT.STROKE_ROMAN, "nd"); gl.glPopMatrix(); }

by Jim X. Chen: CLIPPING The Cohen-Sutherland Line-Clipping Algorithm If the line segment can be neither trivially accepted nor rejected, it is divided into two segments at a clip edge, so that one segment can be trivially rejected. Window is defined by: glOrtho(l, r, b, t, n, f); Iterate the following for l, r, b, t (left, right, bottom, top)

Implementation Example: Line Scan-conversion with Clipping // 2D clipping against a fixed window drawClippedLine (x0, y0, x1, y1) { clip(x0, y0, x1, y1, x00, y00, x11, y11); //(l, r, b, t) // (x00, y00) and (x11, y11) are the two // endpoints after clipping line(x00, y00, x11, y11); } 2006 by Jim X. Chen: 23

J1_3_windowClipping public void drawPoint(double x, double y) { // clip against the window if (x uRight[0]) { return; } if (y uRight[1]) { return; } super.drawPoint(x, y); } 2006 by Jim X. Chen: 24

Line Clipping against a 3D Plane // how about a line against a plane? GLdouble eqn[4] = {0.0, 1.0, 0.0, 0.0}; glClipPlane (GL_CLIP_PLANE0, eqn); glEnable (GL_CLIP_PLANE0); A plane equation Ax + By + Cz + D = 0 A 3D line equation x = x 0 + t(x 1 - x 0 ); y = y 0 + t(y 1 - y 0 ); z = z 0 + t(z 1 - z 0 ); The intersection of the line with the plane is at a specific t 2006 by Jim X. Chen: 25

by Jim X. Chen: The alg moves around the polygon from v 1 to v n and the back to v 1 against the edges of the clipping boundary. At each step, 0, 1, or 2 vertices are added to the output list of vertices that defines the clipped polygon edge. Four possible cases must be analyzed: starting & ending vertices inside (add ending vertice p to the output list) starting inside, ending outside (add intersection vertice i) starting outside, ending inside (add i, p) starting outside, ending outside (continue) The Sutherland Hodgman Polygon-Clipping Algorithm

Polygon Clipping against a Plane A plane equation Ax + By + Cz + D = 0 A polygon is a list of vertices A polygon is a list of line segments (pairs of vertices) essentially line clipping against a plane 2006 by Jim X. Chen: 27 Example: J1_3_windowClipping

by Jim X. Chen: 28 HW2: 2012 Fall Class 1.Draw a line that bounces in a circle. The line can be two moving points, so the length changes; (40%) 2.Draw a triangle that bounces in a circle. The triangle can be three moving points, so the length changes; (35%) 3.Draw a horizontal bar that can be moved using mouse horizontally, and keyboard vertically. It is used to reflect objects (points and endpoints of lines & triangles) so they don’t fall below the bar; (20%) 4.Using character strings to report (live) point counts or some other information you like to inform users. (5%)