Clipping Jian Huang, CS594 This set of slides reference slides devised at Ohio State and MIT.

Slides:



Advertisements
Similar presentations
Computer Graphics - Rasterization -
Advertisements

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Clipping Concepts, Algorithms for line clipping 1 of 16 Clipping - 10/16/12.
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.
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
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.
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:
Computer Graphics Viewing.
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.
Course Website: Computer Graphics 9: Clipping In 3D.
2-Dimension Viewing and Clipping
CS 450: Computer Graphics REVIEW: OVERVIEW OF POLYGONS
02/26/02 (c) 2002 University of Wisconsin, CS 559 Last Time Canonical view pipeline Orthographic projection –There was an error in the matrix for taking.
CS 325 Introduction to Computer Graphics 03 / 08 / 2010 Instructor: Michael Eckmann.
MIT EECS 6.837, Durand and Cutler Graphics Pipeline: Projective Transformations.
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.
Windows, Viewports, and Clipping
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)
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke
Rendering Pipeline Fall, D Polygon Rendering Many applications use rendering of 3D polygons with direct illumination.
1Computer Graphics Implementation 1 Lecture 15 John Shearer Culture Lab – space 2
Graphics Graphics & Graphical Programming Lecture 23 - Viewing & Clipping.
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.
CENG 538 Advanced Graphics and UIs
Visible Surface Detection
Computer Graphics Lecture 14 CLIPPING I Taqdees A. Siddiqi
Computer Graphic 2 D Viewing.
Computer Graphics Clipping.
Rendering Pipeline Fall, 2015.
Computer Graphics CC416 Week 13 Clipping.
Transformations contd.
CS 551 / 645: Introductory Computer Graphics
Computer Graphics Shading in OpenGL
Concepts, Algorithms for line clipping
Clipping Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
CSCE 441 Computer Graphics 3-D Viewing
3D rezanje 3D Clipping view frustrum clipping planes clipped.
CENG 477 Introduction to Computer Graphics
Concepts, algorithms for clipping
3D Clipping.
Implementation I Ed Angel
Graphics Pipeline Clipping
Computer Graphics 9: Clipping In 3D
3D Rendering Pipeline Hidden Surface Removal 3D Primitives
WINDOWING AND CLIPPING
OpenGL 2D Viewing Pipeline
Computer Graphics : Viewing In 2D
Clipping Computer Graphics Cohen Sutherland Algorithm (Line)
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
WINDOWING AND CLIPPING
Lecture 13 Clipping & Scan Conversion
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Joshua Barczak CMSC 435 UMBC
Two Dimensional Viewing and Clipping.
Segment Clipping Simple algorithm. For each segment compute the intersection with the four sides of the rectangle, and then determine which sub-segment.
© University of Wisconsin, CS559 Fall 2004
3D rezanje 3D Clipping view frustrum clipping planes clipped.
Clipping Clipping Sutherland-Hodgman Clipping
Computer Graphics Viewing. 2 of 30 Viewing in 2D Window in world coordinates. 45  250  Viewport in Device coords 250 x 250 Pixels.
Clipping University of British Columbia CPSC 314 Computer Graphics
Implementation I Ed Angel Professor Emeritus of Computer Science
COMPUTER GRAPHICS Clipping
Presentation transcript:

Clipping Jian Huang, CS594 This set of slides reference slides devised at Ohio State and MIT.

Viewing Pipeline Revisited Object Space World Space Eye Space Clipping Space Canonical view volume Screen Space Object space: coordinate where each component is defined World space: all components put together via affine transformation. (camera, lighting defined in this space) Eye space: camera at the origin, view direction coincides with the z axis. Hither and Yon perpendicular to the z axis Clipping space: All point is in homogeneous coordinate. Perspective division gets everything into 3D image space. 3D image space (Canonical view volume): a parallelpipied shape defined by (-1:1,-1:1,0,1). Objects distorted. Screen space: x and y mapped to screen pixel coordinates January 17, 2019

Why do clipping Clipping is a visibility preprocess. In real-world scenes clipping can remove a substantial percentage of the environment from consideration. Clipping offers an important optimization January 17, 2019

What is clipping, two views Clipping is to spatially partition geometric primitives, according to their containment within some region. Clipping can be used to: Distinguish whether geometric primitives are inside or outside of a viewing frustum or picking frustum Detecting intersections between primitives Clipping is to subdivide geometric primitives. Several other potential applications. Binning geometric primitives into spatial data structures computing analytical shadows. January 17, 2019

Point Clipping (x, y) is inside iff AND January 17, 2019

 = Line Clipping - Half Plane Tests Modify endpoints to lie in rectangle “Interior” of rectangle? Answer: intersection of 4 half-planes 3D ? (intersection of 6 half-planes) y < ymax y > ymin x > xmin x < xmax =  interior xmin xmax ymin ymax January 17, 2019

Line Clipping Is end-point inside a clip region? - half-plane test If outside, calculate intersection betwee line and the clipping rectangle and make this the new end point Both endpoints inside: trivial accept One inside: find intersection and clip Both outside: either clip or reject (tricky case) January 17, 2019

Cohen-Sutherland Algorithm (Outcode clipping) Classifies each vertex of a primitive, by generating an outcode. An outcode identifies the appropriate half space location of each vertex relative to all of the clipping planes. Outcodes are usually stored as bit vectors. January 17, 2019

Cohen-Sutherland Algorithm (Outcode clipping) if (outcode1 == '0000' and outcode2 == ‘0000’) then line segment is inside else if ((outcode1 AND outcode2) == 0000) then line segment potentially crosses clip region line is entirely outside of clip region endif January 17, 2019

The Maybe cases? If neither trivial accept nor reject: Pick an outside endpoint (with nonzero outcode) Pick an edge that is crossed (nonzero bit of outcode) Find line's intersection with that edge Replace outside endpoint with intersection point Repeat outcode test until trivial accept or reject January 17, 2019

The Maybe case January 17, 2019

The Maybe Case January 17, 2019

One Plane At a Time Clipping (a.k.a. Sutherland-Hodgeman Clipping) The Sutherland-Hodgeman triangle clipping algorithm uses a divide-and-conquer strategy. Clip a triangle against a single plane. Each of the clipping planes are applied in succession to every triangle. There is minimal storage requirements for this algorithm, and it is well suited to pipelining. It is often used in hardware implementations. January 17, 2019

Sutherland-Hodgman Polygon Clipping Algorithm Subproblem: clip a polygon (input: vertex list) against a single clip edges output the vertex list(s) for the resulting clipped polygon(s) Clip against all four planes generalizes to 3D (6 planes) generalizes to any convex clip polygon/polyhedron Used in viewing transforms January 17, 2019

Polygon Clipping At Work January 17, 2019

Sutherland-Hodgman SHclippedge(var: ilist, olist: list; ilen, olen, edge : integer) s = ilist[ilen];     olen = 0; for i = 1 to ilen do d := ilist[i]; if (inside(d, edge) then if (inside(s, edge) then           -- case 1 addlist(d, olist);     olen := olen + 1; else                                          -- case 4 n := intersect(s, d, edge); addlist(n, olist); addlist(d, olist);    olen = olen + 2; else if (inside(s, edge) then            -- case 2 n := intersect(s, d, edge); addlist(n, olist);  olen ++; s = d; end_for; January 17, 2019

Sutherland-Hodgman SHclip(var: ilist, olist: list; ilen, olen : integer) SHclippedge(ilist, tmplist1, ilen, tlen1, RIGHT); SHclippedge(tmplist1, tmplist2, tlen1, tlen2, BOTTOM); SHclippedge(tmplist2, tmplist1, tlen2, tlen1, LEFT); SHclippedge(tmplist1, olist, tlen1, olen, TOP); January 17, 2019

With Pictures January 17, 2019

Sutherland-Hodgman Advantages: Disadvantages: Elegant (few special cases) Robust (handles boundary and edge conditions well) Well suited to hardware Canonical clipping makes fixed-point implementations manageable Disadvantages: Only works for convex clipping volumes Often generates more than the minimum number of triangles needed Requires a divide per edge January 17, 2019

Interpolating Parameters January 17, 2019

3D Clipping (Planes) Red Polygon – Clip x y z image plane near far Red Polygon – Clip Transform into 4D Clipping space (canonical viewing volume) Homogenous co-ordinates January 17, 2019

Naïve 3D Euclidean Space Clipping After perspective projection, Euclidean space is not linear!! January 17, 2019

Difficulty with Euclidean Space Clipping Clipping will handle most cases. However, there is one case in general that cannot be handled this way. Parts of a primitive lie both in front of and behind the viewpoint. This complication is caused by our projection stage. It has the nasty habit of mapping objects in behind the viewpoint to positions in front of it. Solution: clip in homogeneous coordinate January 17, 2019

4DPolygonClip Use Sutherland Hodgman algorithm Use arrays for input and output lists There are six planes of course ! January 17, 2019

4D Clipping OpenGL uses -1<=x<=1, -1<=y<=1, -1<=z<=1 We use: -1<=x<=1, -1<=y<=1, -1<=z <=0 Must clip in homogeneous coordinates: w>0: -w<=x<=w, -w<=y<=w, -w<=z<=0 w<0: -w>=x>=w, -w>=y>=w, -w>=z>=0 Consider each case separately What issues arise ? January 17, 2019

4D Clipping Clip boundary: x/w = 1 i.e. (x–w=0); Point A is inside, Point B is outside. Clip edge AB x = Ax + t(Bx – Ax) y = Ay + t(By – Ay) z = Az + t(Bz – Az) w = Aw + t(Bw – Aw) Clip boundary: x/w = 1 i.e. (x–w=0); w-x = Aw – Ax + t(Bw – Aw – Bx + Ax) = 0 Solve for t. January 17, 2019

Still have issues with 4D Clipping W=-X W=X P1 and P2 map to same physical point ! Solution: Clip against both regions Negate points with negative W January 17, 2019

Still have issues with 4D Clipping Inf -Inf P2 Line straddles both regions After projection one gets two line segments How to do this? Only before the perspective division January 17, 2019

More on Perspective Transform There are a number of perspective matrices depending on the field of view desired, and the near and far plane. But same essential idea: a perspective matrix moves the depth value z into the fourth column, where it will used to divide through the x and y values when the final homogeneous coordinate is translated back into a 3D point (3D image space), z is usually referred to as ‘depth’ of the point January 17, 2019

More on perspective transforms January 17, 2019

More on Perspective Transform Perspective projections categorized by the number of axis the view plane cuts (ie 1-point, 2-point or 3-point perspective) the plane cuts the z axis, lines parallel to the z meets at infinity; lines parallel to the x or y axis will not meet at infinity. 1-point perspective. the plane cuts the x and z axis, lines parallel to the x/z axis meet at infinity; lines parallel to the y axis will not meet at infinity. 2-point perspective. if the plane cuts the x, y, and z axis then lines parallel to the x, y, or z axis will meet at infinity. This is 3-point perspective. January 17, 2019

More on Homogeneous Coordinates To 4D: (x,y,z) -> (x,y,z,1) Back to 3D: (x,y,z,w) -> (x/w, y/w, z/w) A point is on a plane if the point satisfies 0 == A*x + B*y + C*z + D Point P: (x,y,z,1). Representing a plane N = (A,B,C,D). Point P is on the plane, if P dot N == 0 January 17, 2019

Transforming Normals January 17, 2019

Transforming Normals Transform P to P’ -> P’ = M * P (M is known) and transform N to N’ -> N’ = Q * N Let Q be our transformation matrix for N. We want to make sure that after transformation, N’ is the normal of the transformed plane. That is, N’T * P’ = 0 We get: N’T * P’ = (Q * N)T * (M * P) = NT * QT * M * P = 0 January 17, 2019

Transforming Normals So, need QT *M = Identity Then, QT = M –1 Still, we want N’ = Q * N. Q = (M –1)T January 17, 2019

Viewing Pipeline Revisited Object Space World Space Eye Space Clipping Space Canonical view volume Screen Space Object space: coordinate where each component is defined World space: all components put together via affine transformation. (camera, lighting defined in this space) Eye space: camera at the origin, view direction coincides with the z axis. Hither and Yon perpendicular to the z axis Clipping space: All point is in homogeneous coordinate. Perspective division gets everything into 3D image space. 3D image space (Canonical view volume): a parallelpipied shape defined by (-1:1,-1:1,0,1). Objects distorted. Screen space: x and y mapped to screen pixel coordinates January 17, 2019

Right-Handed Or Left-Handed Usually use right-handed coordinate (convention in math) Left-handed good for screen To convert, just flip x or y or z. (any one of the three) January 17, 2019

How about the viewing pipeline? The range of z for the canonical view volume is [0,1]. x and y still remain the same. Is converting back and forth (flipping) a major issue? January 17, 2019