Zhen Jiang West Chester University

Slides:



Advertisements
Similar presentations
Polygon Scan Conversion – 11b
Advertisements

SI23 Introduction to Computer Graphics
Computer Graphics Inf4/MSc 1 Computer Graphics Lecture 7 Scanline algorithm and polygon clipping Taku Komura.
CS 376 Introduction to Computer Graphics 02 / 02 / 2007 Instructor: Michael Eckmann.
Objectives Define Clipping Various clipping methods. Line clipping methods.
Line clipping: Line clipping algorithm is method of eliminate lines of outside area of the object,so outside of object viewing is Removed. Typically, any.
CMPE 466 COMPUTER GRAPHICS
CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
Computer Graphics Scan Conversion Polygon Faculty of Physical and Basic Education Computer Science Dep Lecturer: Azhee W. MD.
College of Computer and Information Science, Northeastern UniversityApril 17, CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 9.
Introduction to Computer Graphics Chapter 6 – 2D Viewing Pt 2 1.
Different types of Polygons Simple Convex Simple Concave Non-simple : self-intersecting With holes ConvexConcaveSelf-intersecting.
1 CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai.
CS 454 Computer graphics Polygon Filling
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.
TOPIC 4 PART III FILL AREA PRIMITIVES POLYGON FILL AREAS CGMB214: Introduction to Computer Graphics.
CGMB 314 Intro to Computer Graphics Fill Area Primitives.
Dr. Scott Schaefer Scan Conversion of Lines. 2/78 Displays – Cathode Ray Tube.
Windowing and clipping
Drawing Basic Graphics Primitives Lecture 4 Wed, Sep 3, 2003.
3/4/04© University of Wisconsin, CS559 Spring 2004 Last Time Clipping Lines –Cohen-Sutherland: The use of outcodes and early reject/accept tests –Liang-Barsky:
Clipping: Clipping is a process of dividing an object into visible and invisible positions and displaying the visible portion and discarding the invisible.
10/15/02 (c) 2002 University of Wisconsin, CS559 Last Time Clipping.
College of Computer and Information Science, Northeastern UniversityMay 27, CS 4300 Computer Graphics Prof. Harriet Fell Fall 2012 Lecture 9 – September.
1 CS 430/536 Computer Graphics I Polygon Clipping and Filling Week 3, Lecture 5 David Breen, William Regli and Maxim Peysakhov Geometric and Intelligent.
Introduction to Computer Graphics CS 445 / 645 Lecture 9 Chapter 4: Rasterization L. McMillan MIT notes (Fall ’98)
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2013 Tamara Munzner Rasterization.
1 Computer Graphics Clipping Fall FCC Line Clipping What happens when one or both endpoints of a line segment are not inside the specified drawing.
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
Computer Graphics Filling. Filling Polygons So we can figure out how to draw lines and circles How do we go about drawing polygons? We use an incremental.
Graphics Graphics & Graphical Programming Lecture 23 - Viewing & Clipping.
Rasterization Overview Raster Display Device. Scan Conversion / Rasterization: converting vector graphics into raster graphics (determining pixels in.
Computer Graphics CC416 Week 14 Filling Algorithms.
Computer Graphics Lecture 08 Taqdees A. Siddiqi Computer Graphics Filled Area Primitives I Lecture 08 Taqdees A. Siddiqi
Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition Chapter 14.
Rasterization, or “What is glBegin(GL_LINES) really doing?” Course web page: February 23, 2012  Lecture 4.
Computer Graphics Filling.
Introduction to Polygons
Computer Graphics CC416 Week 13 Clipping.
CS G140 Graduate Computer Graphics
Computer Graphics Shading in OpenGL
(c) 2002 University of Wisconsin, CS559
Basic Raster Graphics Algorithms for Drawing 2D Primitives
Computer Graphics Filled Area Primitives II Lecture 09 Taqdees A
University of New Mexico
Implementation III.
Fill Area Algorithms Jan
Graphics Pipeline Clipping
Introduction to Computer Graphics with WebGL
Prof. Harriet Fell Spring 2007 Lecture 9 – January 29, 2007
© University of Wisconsin, CS559 Fall 2004
3D Rendering Pipeline Hidden Surface Removal 3D Primitives
WINDOWING AND CLIPPING
Agenda Polygon Terminology Types of polygons Inside Test
CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai
CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai
Agenda Polygon Terminology Types of polygons Inside Test
WINDOWING AND CLIPPING
Introduction to OpenGL
Prof. Harriet Fell Fall 2011 Lecture 9 – September 26, 2011
Computer Graphics Implementation III
(c) 2002 University of Wisconsin, CS559
© University of Wisconsin, CS559 Fall 2004
Chapter 3 Graphics Output Primitives
Rasterizing Polygons Lecture 29 Wed, Dec 7, 2005.
Basic Raster Graphics Algorithms for Drawing 2D Primitives
Where We Stand At this point we know how to: Next thing:
Implementation III Ed Angel Professor Emeritus of Computer Science
Polygons.
Presentation transcript:

Zhen Jiang West Chester University Computer Graphics Zhen Jiang West Chester University

Topics Introduction Display and OpenGL Point (pixel), line, polygon Curves 2D and 3D Clipping Projection and shadow Animation

Introduction Computer Graphics Sample programs 1 2 3 4 5 6 7 8 9 10 and their execution file Objective Evaluation Resource

Display and OpenGL CRT (cathode-ray tube)

Display and OpenGL

Display and OpenGL

Display and OpenGL 3 2 1 1 2 3

Display and OpenGL 3 2 RGB 1 1 2 3

Display and OpenGL 1280x1024 75 refreshes / second (from top to bottom in left right order) Memory elements called pixels

Display and OpenGL OO programming Introduced but not required in this class Application Programmer’s Interfaces (API) Is shielded from the details of both the hardware and software implementation of the graphics library. !! Match the conceptual model that we will introduce in this class

Point , line, polygon Point Line Polygon Introduction (0,0) -> (dx,dy) (0,cy)->(dx,cy+dy) (cx,cy)->(dx+cx,dy+cy) Brensenham’s algorithm Complete Brensenham’s algorithm Polygon Vertices and edges Simple polygon What’s inside? fill

Point , line, polygon (point) 1023 … 2 1 1 2 3 … 1279

Point , line, polygon (point) 1 1023/1023 1 1279/1279

Point , line, polygon (point) 640 639*1023 /1023 768 767*1279/1279

Point , line, polygon (line)

Point , line, polygon (line) Introduction Integer vertices From start point to end point y = m x + c, where 0<m<1

Point , line, polygon (line) Upper_y d2 d1 Lower_y

Point , line, polygon (line) (0,0) -> (dx,dy) //int dx, dy int x, Upper_y, Lower_y; float y, d1, d2; for ( x = 0 ; x <= dx ; x++) { y= Upper_y= Lower_y= d1= d2= glBegin(GL_POINTS); if(d1<d2) glVertex2i(x, Lower_y); else glVertex2i(x, Upper_y); glEnd(); } dy y x float (dy*x) / float(dx); int(y)+1; int(y); y-Lower_y; Upper_y-y; (0,0) dx For example, when x=0; y=0; Upper_y=1; Lower_y=0; d1=0; d2=1; d1<d2 glVertex2i(0,0);

Point , line, polygon (line) //int dx, dy int x, Upper_y, Lower_y; float y, d1, d2; for ( x = 0 ; x <= dx ; x++) { y=float (dy*x) / float(dx); Upper_y=int(y)+1; Lower_y=int(y); d1=y-Lower_y; d2=Upper_y-y; glBegin(GL_POINTS); if(d1<d2) glVertex2i(x, Lower_y); else glVertex2i(x, Upper_y); glEnd(); } Check (0,0) – (7,2)

Point , line, polygon (line) (0,cy)->(dx,cy+dy) //int dx, dy int x, Upper_y, Lower_y; float y, d1, d2; for ( x = 0 ; x <= dx ; x++) { y=float (dy*x) / float(dx); Upper_y=int(y)+1+cy; Lower_y=int(y)+cy; d1=y+cy-Lower_y; d2=Upper_y-(y+cy); glBegin(GL_POINTS); if(d1<d2) glVertex2i(x, Lower_y); else glVertex2i(x, Upper_y); glEnd(); } dy y x (0,cy) dx

Point , line, polygon (line) //int dx, dy, cy int x, Upper_y, Lower_y; float y, d1, d2; for ( x = 0 ; x <= dx ; x++) { y=float (dy*x) / float(dx); Upper_y=int(y)+1+cy; Lower_y=int(y)+cy; d1=y+cy-Lower_y; d2=Upper_y-(y+cy); glBegin(GL_POINTS); if(d1<d2) glVertex2i(x, Lower_y); else glVertex2i(x, Upper_y); glEnd(); } Check (0,-2) – (7,1)

Point , line, polygon (line) (cx,cy)->(dx+cx,dy+cy) //int dx, dy, cx, cy int x, Upper_y, Lower_y; float y, d1, d2; for ( x = cx ; x <= dx+cx ; x++) { y=float (dy*(x-cx)) / float(dx); Upper_y=int(y)+1+cy; Lower_y=int(y)+cy; d1=y+cy-Lower_y; d2=Upper_y-(y+cy); glBegin(GL_POINTS); if(d1<d2) glVertex2i(x, Lower_y); else glVertex2i(x, Upper_y); glEnd(); } dy y x (cx,cy) dx

Point , line, polygon (line) //int dx, dy, cx, cy int x, Upper_y, Lower_y; float y, d1, d2; for ( x = cx ; x <= cx+dx ; x++) { y=float (dy*(x-cx)) / float(dx); Upper_y=int(y)+1+cy; Lower_y=int(y)+cy; d1=y+cy-Lower_y; d2=Upper_y-(y+cy); glBegin(GL_POINTS); if(d1<d2) glVertex2i(x, Lower_y); else glVertex2i(x, Upper_y); glEnd(); } Check (3,-1) – (10,1)

Point , line, polygon (line) Brensenham’s Algorithm Given (x,y), must choose from either (x+1, y+1) or (x+1, y) (x+1,y+1) (x,y) d2 y+1 y d1 x x+1 (x+1,y)

Point , line, polygon (line) Brensenham’s Algorithm (m=dy/dx) d1-d2 = 2m(x+1)-2y+2c-1 For integer calculations, use p = 2dy x-2dx y+2dy+2c dx-dx d1<d2 =>p negative =>y d1>d2 =>p positive=>y+1

Point , line, polygon (line) //int dx, dy, cx, cy int x, p,y; y=cy; for ( x = cx ; x <= cx+dx ; x++) { p=2*dy*x -2*dx*y+2*dy+2*c*dx-dx; if(p>=0) y++; glBegin(GL_POINTS); glVertex2i(x, y); glEnd(); } Check (3,-1) – (10,1)

Point , line, polygon (line) Complete Algorithm for (x1, y1) to (x2, y2)? M<1 M>1 M=0 M=

Point , line, polygon glBegin(GL_POINTS); If (x1==x2) { if(y2>y1) {cy=y1; dy=y2-y1;} else {cy=y2; dy=y1-y2;} for (i=0;i<=dy;i++) glVertex2i(x1, cy+i); } Else if (y1==y2){ // ? Leave for your exercises Else { dx=x2-x1, dy=y2-y1; m=dy/dx; if(m>-1 && m < 0){ if(y2>y1) {cy=y1; cx=x1;} else {cy=y2;cx=x2;dx=-dx; dy=-dy;} c=y2-x2(y1-y2)/(x1-x2); y=cy; for ( x = cx ; x >= cx+dx ; x--) { p=2*dy*x -2*dx*y-2*dy+2*c*dx-dx; if(p>=0) y++; glVertex2i(x, y); if(m>0 && m < 1){ for ( x = cx ; x <= cx+dx ; x++) { p=2*dy*x -2*dx*y+2*dy+2*c*dx-dx; if(m>1){ if(x2>x1) {cx=x1; cy=y1;} else {cx=x2;cy=y2;dx=-dx; dy=-dy;} c=y2-x2(y1-y2)/(x1-x2); x=cx; for ( y = cy ; y >= cy+dy ; y++) { p=2*dx*y -2*dy*x+2*dx-2*c*dx-dy; if(p>=0) x++; glVertex2i(x, y); } if(m<-1){ for ( y = cy ; y <= cy+dy ; y--) { p=2*dx*y -2*dy*x-2*dx-2*c*dx-dy; glEnd(); Point , line, polygon

Point , line, polygon (polygon) Vertices and edges Simple polygon No zero-winding? No exterior? Parity? What’s inside? Given a pixel, which polygon does it lie in? Given a pixel, on edge? Given a pixel, on vertex?

2 intersections ->inside or not? 1 intersection ->inside or not?

Even number of intersections ->inside or not? Odd number of intersections ->inside or not?

Draw a line start from that pixel (point), even number of intersections -> outside; odd number of intersections -> inside. 0 intersection ? (need another line?)

Overall Algorithm: Line y=py, start from the point (px,py); Has segment (x1,y1) (x2,y2) an intersection with line y=py? For each edge in a polygon, see if it has an intersection with y=py. For each polygon, see if it has odd number of intersections with y=py. For all polygons in the area, see how many polygons contain this point (px,py).

// detect how many polygons in p[number_of_polygons] contain the pixel point. For (i=0;i<number_of_polygons;i++){ p[ i ]=get_polygon (i); count=0; for(j=0;j<p[i].size_of_edge;j++){ start=get_xy(p[ i ][ j ]); // (x1,y1) end=get_xy(p[ i ][ (j+1) % p[ i ].size_of_edge) // (x2,y2) count+=how_many_intersections (start, end, point); } if(count%2) // it’s inside; else it’s outside;

Has segment (x1,y1) (x2,y2) an intersection with line y=py? if(x1==x2) { if ((y1-py)*(y2-py)<0) it has one intersection at (x1,py). } if (y1==y2) { if (py==y1) it has two intersections (x1,py) and (x2,py); one for joining the edge and the other for leaving from this edge. X=(py-y1)(x2-x1)/(y2-y1)+x1 if ((x2-x)*(x1-x)<0) it has an intersection at (x,py). or or or

Question?

Has segment (x1,y1) (x2,y2) an intersection with line y=py? if(x1==x2) { if ((y1-py)*(y2-py)<=0 && y2!=py) => 1 it has one intersection at (x1,py). } if (y1==y2) { if (py==y1) => 1 (even) or 0 (odd) it has two intersections (x1,py) and (x2,py). (x2,py) will be counted on the edge leaving from y=py. (x1,py) (where the edges join y=py) is counted to make even when joining edge and leaving edge are on the same side of y=py; otherwise, 0 for odd intersection. X=(py-y1)(x2-x1)/(y2-y1)+x1 if ((x2-x)*(x1-x)<=0 && x2!=x) =>1 it has an intersection at (x,py). (x2,y2) (x1,y1) (x1,y1) (x2,y2) (x2,y2) (x1,y1)

Point , line, polygon (polygon) Fill (interior) Sweep fill Flood fill Boundary fill Pattern fill (openGL)

Point , line, polygon (polygon) Sweep fill (interior) Xmin, xmax Fill the bottom horizontal span of pixels; move up and keep filling Keep edge information for any change on xmin and xmax AEL (active edge list) (x, 1/m, ymax)

Overall Algorithm: This algorithm maintains one line based on AEL structure Get all the structures at the bottom line (filling procedure on this bottom line will be skipped). Get the structure for the next line (add 1/m easily to x for each old AEL structure, add new one if any, delete the expired one). If no AEL unit, stop! Find filling segments with xmin and xmax (sorting) Filling all segments on the current line, the endpoints of each segment are excluded (no painting) Go to step 2.

3 2 1 1 3 6 3

1 3 6 3 * 1 1 3 6 3 * 2 1 3 6 3 3 1 3 6 3 3 End!

4 3 2 4 4 1 1 2 6 4

1 2 6 4 * 1 1 2 6 4 2 1 2 6 4 4 4 * 2 4 4 6 4 * 3 4 4 6 4 4 4 4 6 4 4 End!

6 5 4 3 3 -1 6 5 1 6 2 1 1 3 8 -1 3

1 3 8 -1 3 * 1 1 1 3 7 -1 3 * 2 2 1 3 6 -1 3 3 3 1 3 5 -1 3 3 -1 6 5 1 6 * 3 3 -1 6 5 1 6 * 4 2 -1 6 6 1 6 * 5 1 -1 6 7 1 6 6 -1 6 8 1 6 6 End!

Why? 5 4 3 3 4 6 7 2 1 7 1 4

7 1 4 1 7 1 1 4 * 2 7 2 1 4 * 3 7 3 1 4 3 4 6 7 * 4 7 6 7 * 5 7 6 7 * 6 7 6 7 7 End!

Quiz preparation How about a sweep fill for the interior and the edges?

Point , line, polygon (polygon) Flood fill 4 connected fill 8 connected fill Spans fill ? 1 2

Point , line, polygon (polygon) Boundary fill All neighbors Pattern fill (openGL)