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 CIS 736 Computer Graphics Lecture 4 of 42 Review of Basics 3 of 5: Clipping and 3-D Viewing.

Slides:



Advertisements
Similar presentations
CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Clipping Concepts, Algorithms for line clipping 1 of 16 Clipping - 10/16/12.
Advertisements

Computer Graphics Inf4/MSc 1 Computer Graphics Lecture 7 Scanline algorithm and polygon clipping Taku Komura.
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 , )
Objectives Define Clipping Various clipping methods. Line clipping methods.
Computer Graphics Lecture 8 Arbitrary Viewing II: More Projection, Clipping and Mathematics of 3D Viewing.
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.
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.
Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)
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.
Clipping CSE 403 Computer Graphics Cohen Sutherland Algorithm (Line)
Introduction to Computer Graphics Chapter 6 – 2D Viewing Pt 2 1.
Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 111 Today’s class Clipping Parametric and point-normal form of lines Intersecting.
Vertices and Fragments I CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
1 CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai.
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.
University College Dublin1 Clipping u Clipping is the removal of all objects or part of objects in a modelled scene that are outside the real-world window.
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.
2/26/04© University of Wisconsin, CS559 Spring 2004 Last Time General Orthographic Viewing –Specifying cameras in world coordinates –Building world  view.
CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.
Computing & Information Sciences Kansas State University CG Basics 4 of 8: ViewingCIS 636/736: (Introduction to) Computer Graphics CIS 636 Introduction.
Windowing and clipping
C O M P U T E R G R A P H I C S Jian Chen January 15, D Viewing II 1/23 3D Viewing II By Andries van Dam.
CS 376 Introduction to Computer Graphics 02 / 12 / 2007 Instructor: Michael Eckmann.
Part II (The Synthetic Camera)
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
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.
CSE Real Time Rendering Week 9. Post Geometry Shaders Courtesy: E. Angel and D. Shreiner – Interactive Computer Graphics 6E © Addison-Wesley 2012.
Clipping Computer Graphics Cohen Sutherland Algorithm (Line)
Windows, Viewports, and Clipping
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 3D Viewing I CIS 736 Computer Graphics Review of Basics 2 of 5: 3D Viewing.
Computer Graphics Zhen Jiang West Chester University.
Basic Perspective Projection Watt Section 5.2, some typos Define a focal distance, d, and shift the origin to be at that distance (note d is negative)
10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 50 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 50 Computer Graphics Implementation II.
Computer Graphics Lecture 20 Fasih ur Rehman. Last Class Clipping – What is clipping – Why we do clipping – How clipping is done.
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.
CIS 736 Computer Graphics Lecture 6 of 42 Viewing 4: Clipping and Culling Monday, 04 February 2008 Reading: Sections 2.4, 4.1, 4.5 Eberly 2e Adapted with.
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 CIS 736 Computer Graphics Lecture 5 of 42 Review of Basics 4 of 5: 3-D Viewing III and Intro.
Computer Graphics Implementation II.
Computer Graphics Lecture 14 CLIPPING I Taqdees A. Siddiqi
Introduction to Computer Graphics with WebGL
Transformations contd.
Computer Graphics Shading in OpenGL
Concepts, Algorithms for line clipping
CSCE 441 Computer Graphics 3-D Viewing
Concepts, algorithms for clipping
3D Clipping.
Implementation I Ed Angel
Graphics Pipeline Clipping
WINDOWING AND CLIPPING
Computer Graphics : Viewing In 2D
Clipping Computer Graphics Cohen Sutherland Algorithm (Line)
CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai
WINDOWING AND CLIPPING
Lecture 13 Clipping & Scan Conversion
Clipping Clipping Sutherland-Hodgman Clipping
Implementation I Ed Angel Professor Emeritus of Computer Science
COMPUTER GRAPHICS Clipping
Presentation transcript:

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 CIS 736 Computer Graphics Lecture 4 of 42 Review of Basics 3 of 5: Clipping and 3-D Viewing II Monday, 23 January 2006 (pages , ) Adapted with Permission W. H. Hsu Andries van Dam 2D Clipping 1/14

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 25, D Clipping 2/14 Clipping endpoints x min < x < x max and y min < y < y max point inside Endpoint analysis for lines: –if both endpoints in, can do “trivial acceptance” –if one endpoint is inside, one outside, must clip –if both endpoints out, don’t know Brute force clip: solve simultaneous equations using y = mx + b for line and four clip edges –slope-intercept formula handles infinite lines only –doesn’t handle vertical lines Line Clipping

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 25, D Clipping 3/14 Parametric form for line segment X = x 0 + t(x 1 – x 0 ) 0 < t < 1 Y = y 0 + t(y 1 – y 0 ) P(t) = P 0 + t(P 1 – P 0 ) “true,” i.e., interior intersection, if s edge and t line in [0,1] Parametric Line Formulation For Clipping

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 25, D Clipping 4/14 Divide plane into 9 regions 4 bit outcode records results of four bounds tests: First bit: outside halfplane of top edge, above top edge Second bit: outside halfplane of bottom edge, below bottom edge Third bit: outside halfplane of right edge, to right of right edge Fourth bit: outside halfplane of left edge, to left of left edge Lines with OC 0 = 0 and OC 1 = 0 can be trivially accepted Lines lying entirely in a half plane on outside of an edge can be trivially rejected: OC 0 & OC 1  0 (i.e., they share an “outside” bit) Outcodes for Cohen-Sutherland Line Clipping Clip Rectangle

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 25, D Clipping 5/14 If we can neither trivial reject nor accept, divide and conquer: subdivide line into two segments, then can T/A or T/R one or both segments: –use a clip edge to cut the line –use outcodes to choose edge that is crossed: if outcodes differ in the edge’s bit, endpoints must straddle that edge –pick an order for checking edges: top – bottom – right – left –compute the intersection point; the clip edge fixes either x or y, can be substituted into the line equation –iterate for the newly shortened line –“extra” clips may happen, e.g., E-I at H Cohen-Sutherland Algorithm Clip rectangle D C B A E F G H I

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 25, D Clipping 6/14 ComputeOutCode(x0, y0, outcode0) ComputeOutCode(x1, y1, outcode1) repeat check for trivial reject or trivial accept pick the point that is outside the clip rectangle if TOP then x = x0 + (x1 – x0) * (ymax – y0)/(y1 – y0); y = ymax; else if BOTTOM then x = x0 + (x1 – x0) * (ymin – y0)/(y1 – y0); y = ymin; else if RIGHT then y = y0 + (y1 – y0) * (xmax – x0)/(x1 – x0); x = xmax; else if LEFT then y = y0 + (y1 – y0) * (xmin – x0)/(x1 – x0); x = xmin; end {calculate the line segment} if (outcode = outcode0) then x0 = x; y0 = y; ComputeOutCode(x0, y0, outcode0) else x1 = x; y1 = y; ComputeOutCode(x1, y1, outcode1) end {Subdivide} until done Pseudocode for the Cohen- Sutherland Algorithm y = y0 + slope*(x - x0) and x = x0 + (1/slope)*(y - y0)

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 25, D Clipping 7/14 a)Don’t round and then scan: calculate decision variable based on pixel chosen on left edge b)Horizontal edge problem: clipping and rounding produces pixel A; to get pixel B, round up x of the intersection of the line with y = y min - ½ and pick pixel above: Scan Conversion after Clipping BA x = x min y = y min y = y min – 1 y = y min – 1/2

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 25, D Clipping 8/14 Use parametric line formulation P(t) = P 0 + (P 1 – P 0 )t Find the four ts for the four clip edges, then decide which form true intersections and calculate (x, y) for those only (< 2) For any point P E i on edge E i Cyrus-Beck/Liang-Barsky Parametric Line Clipping-1

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 25, D Clipping 9/14 Now we can solve for the value of t at the Intersection of P 0 P 1 with the edge E i : N i [P(t) – P E i ] = 0 First, substitute for P(t): N i [P 0 + (P 1 – P 0 )t – P E i ] = 0 Next, group terms and distribute the dot product: N i [P 0 – P E i ] + N i [P 1 – P 0 ]t = 0 Let D be the vector from P 0 to P 1 = (P 1 – P 0 ), and solve for t: Note that this gives a valid value of t only if the denominator of the expression is nonzero. For this to be true, it must be the case that N i  0 (that is, the normal should not be 0; this could occur only as a mistake) D  0 (that is, P 1  P 0 ) N i D  0 (edge E i and line D are not parallel; if they are, no intersection). The algorithm checks these conditions. C-B/L-B Param. Line Clipping-2

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 25, D Clipping 10/14 Eliminate ts outside [0,1] on the line Which remaining ts produce interior intersections? Can’t just take the innermost t values! Move from P 0 to P 1 ; for a given edge, just before crossing: if N i D 0 Potentially Leaving (PL) Pick inner PE, PL pair: t E for P PE with max t, t L for P PL with min t, and t E > 0, t L < 1. If t L < t E, no intersection C-B/L-B Param. Line Clipping-3

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 25, D Clipping 11/14 Pseudocode for Cyrus-Beck/ Liang-Barsky Line Clipping Algorithm precalculate N i and select P E i for each edge; for each line segment to be clipped if P 1 = P 0 then line is degenerate so clip as a point; else begin t E = 0; t L = 1; for each candidate intersection with a clip edge if Ni D  0 then {Ignore edges parallel to line} begin calculate t; {of line and clip edge intersection} use sign of N i D to categorize as PE or PL; if PE then t E = max(t E,t); if PL then t L = min(t L,t); end if t E > t L then return nil else return P(t E ) and P(t L ) as true clip intersections end

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 25, D Clipping 12/14 D = P 1 – P 0 = (x 1 – x 0, y 1 – y 0 ) Leave P E i as an arbitrary point on the clip edge; it’s a free variable and drops out Calculations for Parametric Line Clipping for Upright Clip Rectangle (1/2) Clip Edge i Normal N i PEiPEi P 0 -P E i left: x = x min (-1,0)(x min, y)(x 0 - x min,y 0 -y) right: x = x max (1,0)(x max,y)(x 0 - x max,y 0 -y) bottom: y = y min (0,-1)(x, y min )(x 0 -x,y 0 - y min ) top: y = y max (0,1)(x, y max )(x 0 -x,y 0 - y max ) Calculations for Parametric Line Clipping Algorithm

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 25, D Clipping 13/14 Examine t: –Numerator is just the directed distance to an edge; sign corresponds to OC –Denominator is just the horizontal or vertical projection of the line, dx or dy; sign determines PE or PL for a given edge –Ratio is constant of proportionality: “how far over” from P 0 to P 1 intersection is relative to dx or dy Calculations for Parametric Line Clipping for Upright Clip Rectangle (2/2)

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 25, D Clipping 14/14 Sutherland-Hodgman Polygon Clipping

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 16, D Viewing II 9/21 Analogous to the size of film used in a camera Determines proportion of width to height of image displayed on screen Square viewing window has aspect ratio of 1:1 Movie theater “letterbox” format has aspect ratio of 2:1 NTSC television has an aspect ratio of 4:3, and HDTV is 16:9 Aspect Ratio Kodak HDTV 16:9 NTSC 4:3

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 16, D Viewing II 10/21 Determines amount of perspective distortion in picture, from none (parallel projection) to a lot (wide-angle lens) In a frustum, two viewing angles: width and height angles. We specify Height angle, and get the Width angle from (Aspect ratio * Height angle) Choosing View angle analogous to photographer choosing a specific type of lens (e.g., a wide-angle or telephoto lens) View Angle (1/2)

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 16, D Viewing II 11/21 Lenses made for distance shots often have a nearly parallel viewing angle and cause little perspective distortion, though they foreshorten depth Wide-angle lenses cause a lot of perspective distortion View Angle (2/2) Resulting pictures

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 16, D Viewing II 12/21 Volume of space between Front and Back clipping planes defines what camera can see Position of planes defined by distance along Look vector Objects appearing outside of view volume don’t get drawn Objects intersecting view volume get clipped Front and Back Clipping Planes (1/3) Front clipping plane Back clipping plane

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 16, D Viewing II 13/21 Reasons for Front (near) clipping plane: Don’t want to draw things too close to the camera –would block view of rest of scene –objects would be prone to distortion Don’t want to draw things behind camera –wouldn’t expect to see things behind the camera –in the case of the perspective camera, if we decided to draw things behind the camera, they would appear upside-down and inside-out because of perspective transformation Reasons for Back (far) clipping plane: Don’t want to draw objects too far away from camera –distant objects may appear too small to be visually significant, but still take long time to render –by discarding them we lose a small amount of detail but reclaim a lot of rendering time –alternately, the scene may be filled with many significant objects; for visual clarity, we may wish to declutter the scene by rendering those nearest the camera and discarding the rest Front and Back Clipping Planes (2/3)

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 16, D Viewing II 14/21 Front and Back Clipping Planes (3/3) Have you ever played a video game and all of the sudden some object pops up in the background (e.g. a tree in a racing game)? That’s the object coming inside the far clip plane. The old hack to keep you from noticing the pop-up is to add fog in the distance. A classic example of this is from Turok: Dinosaur Hunter Now all you notice is fog and how little you can actually see. This practically defeats the purpose of an outdoor environment! And you can still see pop-up from time to time. Thanks to fast hardware and level of detail algorithms, we can push the far plane back now and fog is much less prevalent Putting the near clip plane as far away as possible helps Z precision. Sometimes in a game you can position the camera in the right spot so that the front of an object gets clipped letting you see inside of it.

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 16, D Viewing II 15/21 Some camera models take a Focal length Focal Length is a measure of ideal focusing range; approximates behavior of real camera lens Objects at distance of Focal length from camera are rendered in focus; objects closer or farther away than Focal length get blurred Focal length used in conjunction with clipping planes Only objects within view volume are rendered, whether blurred or not. Objects outside of view volume still get discarded Focal Length

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 16, D Viewing II 16/21 It can create the following view volumes: –perspective: positive view angle –parallel: zero view angle Model cannot create oblique view volume Non-oblique vs. oblique view volumes: For example, view cameras with bellows are used to take pictures of (tall) buildings. The film plane is parallel to the façade, while the camera points up. This is an oblique view volume, with the façade undistorted What This Camera Model Can And Cannot Do Non-oblique view volume: Oblique view volume: Look vector is perpendicular to film plane Look vector is at an angle to the film plane

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 16, D Viewing II 17/21 From Position, Look vector, Up vector, Aspect ratio, Height angle, Clipping planes, and (optionally) Focal length together specify a truncated view volume Truncated view volume is a specification of bounded space that camera can “see” 2D view of 3D scene can be computed from truncated view volume and projected onto film plane Truncated view volumes come in two flavors: parallel and perspective View Volume Specification

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 16, D Viewing II 18/21 Limiting view volume useful for eliminating extraneous objects Orthographic parallel projection has width and height view angles of zero Truncated View Volume for Orthographic Parallel Projection Height Width Look vector Near distance Position Far distance Up vector

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 16, D Viewing II 19/21 Removes objects too far from Position, which otherwise would merge into “blobs” Removes objects too close to Position (would be excessively distorted) Truncated View Volume (Frustum) for Perspective Projection Position Near distance Far distance Height angle Width angle = Look vector Up vector Height angle Aspect ratio

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 16, D Viewing II 20/21 Real cameras have a roll of film that captures pictures Synthetic camera “film” is a rectangle on an infinite film plane that contains image of scene Why haven’t we talked about the “film” in our synthetic camera, other than mentioning its aspect ratio? How is the film plane positioned relative to the other parts of the camera? Does it lie between the near and far clipping planes? Behind them? Turns out that fine positioning of Film plane doesn’t matter. Here’s why: –for a parallel view volume, as long as the film plane lies in front of the scene, parallel projection onto film plane will look the same no matter how far away film plane is from scene –same is true for perspective view volumes, because the last step of computing the perspective projection is a transformation that stretches the perspective volume into a parallel volume To be explained in detail in the next lecture In general, it is convenient to think of the film plane as lying at the eye point (Position) Where’s My Film?

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 16, D Viewing II 21/21 Carlbom, Ingrid and Paciorek, Joseph, “Planar Geometric Projections and Viewing Transformations,” Computing Surveys, Vol. 10, No. 4 December 1978 Kemp, Martin, The Science of Art, Yale University Press, 1992 Mitchell, William J., The Reconfigured Eye, MIT Press, 1992 Foley, van Dam, et. al., Computer Graphics: Principles and Practice, Addison-Wesley, 1995 Wernecke, Josie, The Inventor Mentor, Addison-Wesley, 1994 Sources