Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 111 Today’s class Clipping Parametric and point-normal form of lines Intersecting.

Slides:



Advertisements
Similar presentations
Computer Graphics - Rasterization -
Advertisements

Rezanje črt in poligonov. World window & viewport window viewport screen window world window.
I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam September 30, D Clipping 1/14 Clipping (pages , )
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
10/10/02 (c) 2002 University of Wisconsin, CS 559 Last Time Finished viewing: Now you know how to: –Define a region of space that you wish to view – the.
CHAPTER 12 Height Maps, Hidden Surface Removal, Clipping and Level of Detail Algorithms © 2008 Cengage Learning EMEA.
CS 551 / 645: Introductory Computer Graphics Clipping Lines and Polygons.
3/2/04© University of Wisconsin, CS559 Spring 2004 Last Time General Perspective –Methods for specifying the view volume As a set of clip planes As a field.
Course Website: Computer Graphics 4: Viewing In 2D.
1 Clipping. 2 Transformation Sequence X Y Z X Y Z X Y Z X Y Z Object Coords. Eye Coords. Clip Coords. Normalized Device Coords. Screen Coords. Implementation:
Two-Dimensional Viewing Jehee Lee Seoul National University.
Computer Graphics : Clipping
Computer Graphics Viewing.
Viewing & Clipping In 2D. 2 of 44 Contents Windowing Concepts Clipping –Introduction –Brute Force –Cohen-Sutherland Clipping Algorithm Area Clipping –Sutherland-Hodgman.
CMPE 466 COMPUTER GRAPHICS Chapter 8 2D Viewing Instructor: D. Arifler Material based on - Computer Graphics with OpenGL ®, Fourth Edition by Donald Hearn,
2D Viewing and Projection
Introduction to Computer Graphics Chapter 6 – 2D Viewing Pt 2 1.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Interpolation Clipping.
Chapter 6: Vertices to Fragments Part 2 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley Mohan Sridharan Based on Slides.
Vertices and Fragments I CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
1 King ABDUL AZIZ University Faculty Of Computing and Information Technology CS 454 Computer graphics Two Dimensional Viewing Dr. Eng. Farag Elnagahy
Course Website: Computer Graphics 9: Clipping In 3D.
Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Clipping.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Implementation I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Graphics Pipeline Clipping CMSC 435/634. Graphics Pipeline Object-order approach to rendering Sequence of operations – Vertex processing – Transforms.
CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.
2-Dimension Viewing and Clipping
Clipping Apart from clipping to the view volume, clipping is a basic operation in many other algorithms –Breaking space up into chunks –2D drawing and.
CS 376 Introduction to Computer Graphics 02 / 12 / 2007 Instructor: Michael Eckmann.
Two-Dimensional Viewing
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.
CS 325 Introduction to Computer Graphics 03 / 08 / 2010 Instructor: Michael Eckmann.
Objectives Introduce basic implementation strategies Clipping Scan conversion.
Clipping Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006 (Slide set originally by David Luebke)
CS 480/680 Computer Graphics Shading in OpenGL Dr. Frederick C Harris, Jr. Fall 2013.
10/15/02 (c) 2002 University of Wisconsin, CS559 Last Time Clipping.
Windows, Viewports, and Clipping
1Computer Graphics Implementation II Lecture 16 John Shearer Culture Lab – space 2
Implementation II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Implementation II.
10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.
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.
Computer Graphics I, Fall 2010 Implementation II.
1Computer Graphics Implementation 1 Lecture 15 John Shearer Culture Lab – space 2
Clipping Primitives. Clipping line Clipping rectangle: – x min to x max – y min to y max A point (x,y) lies within a clip rectangle and thus displayed.
Graphics Graphics & Graphical Programming Lecture 23 - Viewing & Clipping.
A.Aruna/Assistant Professor/SNSCE
Computer Graphics Viewing. 2 of 30 Viewing in 2D Window in world coordinates. 45  250  Viewport in Device coords 250 x 250 Pixels.
Lecture 9 From Vertices to Fragments. Objectives Introduce basic implementation strategies Clipping Rasterization hidden-surface removal.
Chapter 71 Computer Graphics - Chapter 7 From Vertices to Fragments Objectives are: How your program are processed by the system that you are using, Learning.
Computer Graphics Lecture 14 CLIPPING I Taqdees A. Siddiqi
Computer Graphic 2 D Viewing.
Computer Graphics CC416 Week 13 Clipping.
Transformations contd.
Concepts, Algorithms for line clipping
Concepts, algorithms for clipping
3D Clipping.
Graphics Pipeline Clipping
3D Rendering Pipeline Hidden Surface Removal 3D Primitives
WINDOWING AND CLIPPING
Computer Graphics : Viewing In 2D
WINDOWING AND CLIPPING
Lecture 13 Clipping & Scan Conversion
© University of Wisconsin, CS559 Fall 2004
(c) 2002 University of Wisconsin, CS559
Clipping Clipping Sutherland-Hodgman Clipping
Clipping University of British Columbia CPSC 314 Computer Graphics
COMPUTER GRAPHICS Clipping
Presentation transcript:

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 111 Today’s class Clipping Parametric and point-normal form of lines Intersecting lines and planes

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 112 Normalized device coordinates Graphics imaging is device dependent Image development is device independent To simplify the process images are frequently generated using normalized device coordinates (NDC), where x and y values are between -1.0 and 1.0 (for OpenGL; other systems may use 0.0 to 1.0)

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 113 Converting NDC to DC To display an image a transformation from NDC to device coordinates (DC) needs to take place To convert NDC to DC:  multiply by ½ the number of pixels in the dimension  add ½ the number of pixels in the dimension

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 114 Viewing transformation It is usually inconvenient to represent an image in DC or NDC Want to do it in world coordinates (WC) Setting the window and the viewport accomplishes the transformation from WC to DC, thus providing the viewing transformation

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 115 Clipping volume The combination of setting the window and the viewport defines the clipping volume It is possible some primitives lie wholly or partially outside this volume Need to insure these items are not displayed This process is known as clipping

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 116 Clipping points Clipping points is trivial A point is visible if  x min  x  x max  y min  y  y max

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 117 Clipping lines Lines lie:  wholly inside window  wholly outside window  partially inside and partially outside window Define a 4-bit outcode (b 0 b 1 b 2 b 3 ) describing relationship of line segment to window  b 0 = 1 if y > y max (point above window)  b 1 = 1 if y < y min (point below window)  b 2 = 1 if x > x max (point to right of window)  b 3 = 1 if x < x min (point to left of window)

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 118 Cohen-Sutherland Outcode Algorithm code 1  outcode (p 1 ); code 2  outcode (p 2 ); loop  if code 1 = 0 and code 2 = 0 then  display line segment; exit loop;  if code 1 & code 2  0 then  reject line segment; exit loop;  if code 1 = 0 then  swap (p 1, p 2 ); swap (code 1, code 2 );  find a nonzero bit in code 1  find intersection of line with corresponding window boundary;  p 1  intersection point; code 1  outcode (p 1 );

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 119 Observations Clipping of one line segment may occur more than once Don’t want to change the slope of the line Therefore, do the work in floating point numbers Works well when explicit form of line equation is used

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1110 Vertical lines Vertical lines have an infinite slope Will this cause a problem for the Cohen- Sutherland algorithm? Pair off and determine the answer to the above question.  If no, great!  If yes, how can you overcome the problem?

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1111 Vertical lines and Cohen- Sutherland clipping top p1p1 p2p2 x xx yy For a vertical line  x=0, but you’ll never divide by it!

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1112 Parametric form of a line Describes a “travelling” motion along a line or line segment The x and y coordinates of points on the line are described by linear equations involving a parameter variable (frequently t, u, or v) Example: x = t y = 2t + 1

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1113 General form In general, the parametric form for the equation of a line is x = at + b y = ct + d

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1114 Line segments Frequently, in computer graphics we restrict t by 0  t  1 This generates a line segment

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1115 Finding the parametric form of a line segment Given two endpoints, (x 1, y 1 ) and (x 2, y 2 ) Let t = 0 be at (x 1, y 1 ) and t = 1 be at (x 2, y 2 ) Then: x = x 1 + (x 2 - x 1 )t y = y 1 + (y 2 - y 1 )t

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1116 Vector form of parametric equation Let the two endpoints of a line segment be denoted A and B The line between them is described by P(t) = A + (B - A)t 0  t  1

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1117 Slope vector The slope of a line is (y 2 -y 1 )/(x 2 -x 1 ) The slope vector is defined as the vector (x 2 -x 1, y 2 -y 1 ) Note that the slope vector’s components are the coefficients of the linear terms of the parametric equations

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1118 Perpendicular lines Slopes are negative reciprocals of each other Given a line with a slope of (y 2 -y 1 )/(x 2 -x 1 ), which implies a slope vector of (x 2 -x 1, y 2 -y 1 ), a perpendicular line will have slope -(x 2 -x 1 )/(y 2 -y 1 ) and a slope vector (-(y 2 -y 1 ), (x 2 -x 1 )) To get the equation of the perpendicular line choose the midpoint (m x, m y ) of the line to base it from Parametric form is now x(t) = m x - (y 2 - y 1 )t y(t) = m y + (x 2 - x 1 )t

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1119 Point normal form n r = D, where n is the normal to the line, r represents all points on the line, and D = n A, where A is any point on the line A c R n n (R - A) = 0

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1120 Half spaces A line divides space into two halves, an outside half space and an inside half space Given a line through point A and outward normal n, then any point Q lies  in the outside half space if (Q-A)n > 0  on the line if (Q-A)n = 0  in the inside half space if (Q-A)n < 0

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1121 Intersections of lines with lines and planes Let a ray be represented by B+ct Both lines and planes are represented in point normal form by n ∙ (R – A) = 0 or n ∙ R = D To find the intersection, substitute the ray equation into the point normal form for R: n ∙ ( B+ct) = D Solve for t, which we will designate t hit, the time at which the ray hits the line or plane: t hit = (D - n ∙ B) / (n ∙ C)

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1122 Intersecting a ray with a polygon We frequently need to answer the questions  Where does a ray hit an object?  What part of a line is inside an object? We can solve these problems by determining the intersections of a ray with a polygon

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1123 Two intersections Let the ray in question be denoted B + ct It will hit the boundary of a convex polygon at most twice, once upon entering the polygon and once upon leaving Call these times t in and t out Need to find intersection of ray with each edge and determine portion within polygon

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1124 Entering or leaving? When the ray intersects an edge, we need to decide if it is entering or leaving the polygon Let n represent the normal to an edge The following conditions hold:  If n ∙ c < 0 the ray is entering  If n ∙ c = 0 the ray is parallel  If n ∙ c > 0 the ray is leaving

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1125 Times to keep For entering times, want to keep the largest intersection time (or 0 if the ray starts inside the polygon) For leaving times, want to keep the smallest intersection time How would this be modified if we consider a line segment intersecting the polygon rather than a ray?

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1126 What’s left? The ray between t in and t out is the part inside the polygon The rest is clipped

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1127 Liang-Barksy clipping Useful when clipping against a rectangular window Uses parametric form of line equation  x(t) = x 1 + t(x 2 -x 1 ) = x 1 + t  x  y(t) = y 1 + t(y 2 -y 1 ) = y 1 + t  y  0  t  1 Clipping conditions become  x min  x 1 + t  x  x max  y min  y 1 + t  y  y max

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1128 Inequality form Each of the four inequalities is of the form tp k  q k, where  p 1 = -  x, q 1 = x 1 -x min  p 2 =  x, q 2 = x max -x 1  p 3 = -  y, q 3 = y 1 -y min  p 4 =  y, q 4 = y max -y 1

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1129 Lines parallel to window boundary For lines that are parallel to a window boundary, the corresponding p k will be 0 If the corresponding q k < 0 the line is outside the boundary and can be ignored

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1130 Other lines If p k < 0 the infinite extension of the line enters the clipping region If p k > 0 the infinite extension of the line leaves the clipping region In either case, the value of t for which the line crosses the boundary is q k / p k

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1131 Liang-Barksy algorithm Let t 1 and t 2 define the ends of the clipped line that will be visible t 1 is the entering time, t 2 the leaving time Initialize t 1 to 0 and t 2 to 1 For each of the four boundaries:  if p k = 0 then  if q k < 0 then reject line  else if p k < 0 then  compute entering time

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1132 Liang-Barksy algorithm (cont.)  if entering time > t 1 then change t 1 to entering time if t 1 > t 2 then reject line  else // p k > 0  compute leaving time  if leaving time < t 2 then change t 2 to leaving time if t 1 > t 2 then reject line If line has not been rejected then draw line between t 1 and t 2

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1133 Problems with polygons Edges of polygons are made of line segments Recognize that when we clip a polygon’s edges, some of the edges may be completely removed and others may be partially removed Thus, we may change the shape of the polygon during clipping

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1134 Clipping polygons to a rectangular window Number vertices of polygon and window in a clockwise manner Clip against one window edge at a time Input is a set of polygon vertices Output is an updated set of polygon vertices

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1135 Sutherland-Hodgman algorithm Start with edge from last polygon vertex to first one, and then repeat for each successive edge:  Assume beginning vertex has been handled  If both vertices are inside window with respect to clipping edge output second vertex

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1136 Sutherland-Hodgman algorithm (cont.)  If first vertex is inside and second vertex is outside, find intersection of polygon edge with clipping edge and output intersection  If both vertices are outside window output nothing  If first vertex is outside and second vertex is inside, find intersection of polygon edge with clipping edge and output intersection and then second vertex

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1137 Bounding box Clipping polygons can be time consuming, especially if it is many sided and lies completely outside the window Use a bounding box (extent) to eliminate these quickly

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1138 What’s visible? Once clipped, we now have a list of polygons to display We must determine which surfaces are visible and which are hidden

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1139 Object-space approaches Given a list of n polygons Take one polygon and compare it with the remaining ones to determine the part that is visible; render it The above polygon no longer needs to be considered Take one of the remaining polygons and repeat the process This is O(n 2 ) and thus should only be used for scenes with few polygons

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1140 Image-space approaches Follow ray tracing paradigm Consider a ray from viewpoint that passes through a pixel Find the closest intersection of the ray with all polygons Color pixel by the shade of the face closest to viewpoint Repeat for all pixels This is O(n) if there are n polygons However, they tend to be more jagged since they work at the pixel level

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1141 Back face removal A back face is one that is turned away from the eye of the camera The camera will not see it if the faces in front are opaque For a convex polyhedron:  every face is either wholly visible or wholly invisible  eliminating back faces is equivalent to hidden surface removal

Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 1142 Culling The process of removing something is known as culling In OpenGL, turn on culling of back faces with glEnable (GL_CULL_FACE); and then glCullFace (GL_BACK);