Clipping and Intersection

Similar documents
Illumination Models III: Ray Tracing (View Dependent Global Illumination)

Two-Dimensional Viewing. Chapter 6

CS123 INTRODUCTION TO COMPUTER GRAPHICS. Clipping. Concepts, Algorithms for line clipping. 1 of 16. Andries van Dam. Clipping - 10/12/17

From Vertices To Fragments-1

Clipping & Culling. Lecture 11 Spring Trivial Rejection Outcode Clipping Plane-at-a-time Clipping Backface Culling

Clipping Lines. Dr. Scott Schaefer

3D Rendering Pipeline (for direct illumination)

Computer Graphics. - Clipping - Philipp Slusallek & Stefan Lemme

On-Line Computer Graphics Notes CLIPPING

Part IV. 2D Clipping

Chapter 4 Concepts from Geometry

MATH 890 HOMEWORK 2 DAVID MEREDITH

Basics of Computational Geometry

Sung-Eui Yoon ( 윤성의 )

Set the Viewport. Set the Viewport Clipping. Set the Viewport. Set the Viewport. Set the Viewport. Resizing the Viewport W = H

CS184 : Foundations of Computer Graphics Professor David Forsyth Final Examination

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI

CS184 : Foundations of Computer Graphics Professor David Forsyth Final Examination (Total: 100 marks)

Clipping and Scan Conversion

Chapter 1. Linear Equations and Straight Lines. 2 of 71. Copyright 2014, 2010, 2007 Pearson Education, Inc.

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

Suggested problems - solutions

CSCI 4620/8626. Computer Graphics Clipping Algorithms (Chapter 8-5 )

Computer Graphics (CS 543) Lecture 10 (Part 1): 3D Clipping. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

3D Polygon Rendering. Many applications use rendering of 3D polygons with direct illumination

Today. CS-184: Computer Graphics. Lecture #10: Clipping and Hidden Surfaces. Clipping. Hidden Surface Removal

Review Exercise. 1. Determine vector and parametric equations of the plane that contains the

Chapter 8: Implementation- Clipping and Rasterization

Computational Geometry

The Graphics Pipeline. Interactive Computer Graphics. The Graphics Pipeline. The Graphics Pipeline. The Graphics Pipeline: Clipping

1999, Denis Zorin. Ray tracing

Overview. Pipeline implementation I. Overview. Required Tasks. Preliminaries Clipping. Hidden Surface removal

MODULE - 9. Subject: Computer Science. Module: Line Clipping. Module No: CS/CGV/9

Hidden-Surface Removal.

Geometric Queries for Ray Tracing

Examples. Clipping. The Rendering Pipeline. View Frustum. Normalization. How it is done. Types of operations. Removing what is not seen on the screen

Lecture 2 Convex Sets

LECTURE 7. Announcements

CS452/552; EE465/505. Clipping & Scan Conversion

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

MAT203 OVERVIEW OF CONTENTS AND SAMPLE PROBLEMS

Topics. From vertices to fragments

CS602 Midterm Subjective Solved with Reference By WELL WISHER (Aqua Leo)

Computer Graphics Geometry and Transform

Realtime 3D Computer Graphics Virtual Reality

1.5 Equations of Lines and Planes in 3-D

Graphics and Interaction Transformation geometry and homogeneous coordinates

COMP30019 Graphics and Interaction Transformation geometry and homogeneous coordinates

8.1 Geometric Queries for Ray Tracing

Unit 3 Transformations and Clipping

LECTURE 6. Announcements

CS770/870 Spring 2017 Ray Tracing Implementation

COMPUTATIONAL GEOMETRY

Clipping Points Consider a clip window which is rectangular in shape. P(x, y) is a point to be displayed.

Linear Programming and its Applications

COMP3421. Vector geometry, Clipping

Geometry 1-1. Non-collinear Points not on the same line. Need at least 3 points to be non-collinear since two points are always collinear

Computer Graphics. The Two-Dimensional Viewing. Somsak Walairacht, Computer Engineering, KMITL

Clipping a Mesh Against a Plane

CS 4204 Computer Graphics

MATRIX REVIEW PROBLEMS: Our matrix test will be on Friday May 23rd. Here are some problems to help you review.

Geometric Computations for Simulation

CS 325 Computer Graphics

Cs602-computer graphics MCQS MIDTERM EXAMINATION SOLVED BY ~ LIBRIANSMINE ~

Section 13.5: Equations of Lines and Planes. 1 Objectives. 2 Assignments. 3 Lecture Notes

EECS 487, Fall 2005 Exam 2

Linear Programming in Small Dimensions

Renderer Implementation: Basics and Clipping. Overview. Preliminaries. David Carr Virtual Environments, Fundamentals Spring 2005

PetShop (BYU Students, SIGGRAPH 2006)

Math 7 Glossary Terms

Some Advanced Topics in Linear Programming

Grade 9 Math Terminology

CSE328 Fundamentals of Computer Graphics

Lines and Planes in 3D

UNIT 2 2D TRANSFORMATIONS

(Refer Slide Time: 00:02:02)

CS 130 Exam I. Fall 2015

1 EquationsofLinesandPlanesin 3-D

CS675: Convex and Combinatorial Optimization Spring 2018 Consequences of the Ellipsoid Algorithm. Instructor: Shaddin Dughmi

Clipping. CSC 7443: Scientific Information Visualization

Department of Computer Sciences Graphics Fall 2003 (Lecture 2) Pixels

S U N G - E U I YO O N, K A I S T R E N D E R I N G F R E E LY A VA I L A B L E O N T H E I N T E R N E T

CS 372: Computational Geometry Lecture 10 Linear Programming in Fixed Dimension

Ray scene intersections

Review for Mastery Using Graphs and Tables to Solve Linear Systems

15. Clipping. Projection Transformation. Projection Matrix. Perspective Division

Mathematics. Linear Programming

There are two ways to name a line. What are the two ways?

1. CONVEX POLYGONS. Definition. A shape D in the plane is convex if every line drawn between two points in D is entirely inside D.

Rectangular Coordinates in Space

Perspective Mappings. Contents

Practical Linear Algebra: A Geometry Toolbox

Z- Buffer Store the depth for each pixel on the screen and compare stored value with depth of new pixel being drawn.

Graphs and Linear Functions

MIT EECS 6.837, Teller and Durand 1

UNIT 2. Translation/ Scaling/ Rotation. Unit-02/Lecture-01

Last class. A vertex (w x, w y, w z, w) - clipping is in the - windowing and viewport normalized view volume if: - scan conversion/ rasterization

Rubber bands. Chapter Rubber band representation

2.6: Solving Systems of Linear Inequalities

18.02 Final Exam. y = 0

Transcription:

Clipping and Intersection Clipping: Remove points, line segments, polygons outside a region of interest. Need to discard everything that s outside of our window. Point clipping: Remove points outside window. A point is either entirely inside the region or not. Line clipping: Remove portion of line segment outside window. Line segments can straddle the region boundary. The Liang-Barsky algorithm efficiently clips line segments against a halfspace. Halfspaces can be combined to bound a convex region. Use outcodes to organize combination of halfspaces. Can use some of the ideas in Liang-Barsky to clip points. The University of Texas at Austin 1

Polygon clipping: Remove portion of polygon outside window. Polygons can straddle the region boundary. Concave polygons can be broken into convex. Sutherland-Hodgemen algorithm also deals with all cases efficiently. Built upon efficient line segment clipping. The University of Texas at Austin 2

Parametric representation of line: P(t) = (1 t)p 0 + tp 1 or equivalently: P(t) = P 0 + t(p 1 P 0 ) P 0 and P 1 are non-coincident points. For t R, P(t) defines an infinite line. For t [0, 1], P(t) defines a line segment from P 0 to P 1. Good for generating points on a line. Not so good for testing if a given point is on a line. The University of Texas at Austin 3

Implicit representation of line: l(q) = (Q P) n P is a point on the line. n is a vector perpendicular to the line. l(q) gives us the signed distance from any point Q to the line. The sign of l(q) tells us if Q is on the left or right of the line, relative to the direction of n. If l(q) is zero, then Q is on the line. Use same form for the implicit representation of a halfspace. n P Q The University of Texas at Austin 4

Clipping a point to a halfspace: Represent a window edge implicitly... Use the implicit form of a line to classify a point Q. Must choose a convention for the normal: point to the inside. Check the sign of l(q): If l(q) > 0, the Q is inside. Otherwise clip (discard) Q; it is on, or outside. The University of Texas at Austin 5

Clipping a line segment to a halfspace: There are three cases: The line segment is entirely inside. The line segment is entirely outside. The line segment is partially inside and partially outside. n P The University of Texas at Austin 6

Do the easy stuff first: We can devise easy (and fast!) tests for the first two cases: (P 0 P) n < 0 AND (P 1 P) n < 0 = Outside (P 0 P) n > 0 AND (P 1 P) n > 0 = Inside We will also need to decide whether on the boundary is inside or outside. Trivial tests are important in computer graphics: Particularly if the trivial case is the most common one. Particularly if we can reuse the computation for the non-trivial case. The University of Texas at Austin 7

Do the hard stuff only if we have to: If line segment partially inside and partially outside, need to clip it: Represent the segment from P 0 to P 1 in parametric form: P(t) = (1 t)p 0 + tp 1 = P 0 + t(p 1 P 0 ) When t = 0, P(t) = P 0. When t = 1, P(t) = P 1. We now have the following: n 1P P P(t)=(1-t)P 0 +tp 1 P 0 The University of Texas at Austin 8

We want t such that P(t) is on l: (P(t) P) n = (P 0 + t(p 1 P 0 ) P) n Solving for t gives us = (P 0 P) n + t(p 1 P 0 ) n = 0 t = (P 0 P) n (P 0 P 1 ) n NOTE: The values we use for our simple test can be used to compute t: t = (P 0 P) n (P 0 P) n (P 1 P) n The University of Texas at Austin 9

Clipping a line segment to a window: Just clip to each of four halfspaces. Pseudo-code: given: P, n defining a window edge for each edge (A,B) = (P0,P1) weca = (A-P). n wecb = (B-P). n if ( weca < 0 AND wecb < 0 ) then reject if ( weca >= 0 AND wecb >= 0 ) then next t = weca / (weca - wecb) if (weca < 0 ) then A = A + t (B-A) else B = B + t (B-A) endif endfor NOTE: Liang-Barsky Algorithm lets us clip lines to arbitrary convex windows. The University of Texas at Austin 10

Optimizations can be made for the special case of horizontal and vertical window edges. The University of Texas at Austin 11

Q: Can we short-circuit evaluation of a clip on one edge if we know line segment is out on another? A: Yes. Use outcodes. Do all trivial tests first. Combine results using Boolean operations to determine Trivial accept on window: all edges have trivial accept. Trivial reject on window: any edge has trivial reject. Do Boolean AND, OR operations on bits in a packed integer. Do full clip only if no trivial accept/reject on window. The University of Texas at Austin 12

0 1010 1110 0110 1011 1111 0111 1 1001 1101 0101 2 3 The University of Texas at Austin 13

Line-clip Algorithm generalizes to 3D: Half-space now lies on one side of a plane. The implicit formula for a plane in 3D is the same as that for a line in 2D. The parametric formula for the line to be clipped is unchanged. The University of Texas at Austin 14

3D Clipping When do we clip in 3D? We should clip to the near plane before we project. Otherwise, we might map z to 0 and the x/z and y/z are undefined. We could clip to all 6 sides of the truncated viewing pyramid. but the plane equations are simpler if we clip after projection, because all sides of volume are parallel to coordinate plane. Clipping to a plane in 3D is identical to clipping to a line in 2D. We can also clip in homogeneous coordinates. The University of Texas at Austin 15

Polygon Clipping Polygon Clipping (Sutherland-Hodgeman): Window must be a convex polygon. Polygon to be clipped can be convex or not. Approach: Polygon to be clipped is given as v 1,..., v n Each polygon edge is a pair [v i, v i+1 ]i = 1,..., n Don t forget wraparound; [v n, v 1 ] is also an edge Process all polygon edges in succession against a window edge Polygon in polygon out v 1,..., v n w 1,..., w m Repeat on resulting polygon with next sequential window edge. The University of Texas at Austin 16

Contrast with Line Clipping Line clipping: Use outcodes to check all window edges before any clip Clip only against possible intersecting window edges Deal with window edges in any order Deal with line segment endpoints in either order Polygon clipping: Each window edge must be used Polygon edges must be handled in sequence Polygon edge endpoints have a given order Stripped-down line-segment/window-edge clip is a subtask There are four cases to consider. The University of Texas at Austin 17

Four Cases s = v i is the polygon edge starting vertex p = v i+1 is the polygon edge ending vertex i is a polygon-edge/window-edge intersection point w j is the next polygon vertex to be output Case 1: Polygon edge is entirely inside the window edge p is next vertex of resulting polygon p w j and j + 1 j The University of Texas at Austin 18

inside s outside p (output) Case 1 The University of Texas at Austin 19

Case 2: Polygon edge crosses window edge going out Intersection point i is next vertex of resulting polygon i w j and j + 1 j inside outside s i (output) p Case 2 The University of Texas at Austin 20

Case 3: Polygon edge is entirely outside the window edge No output inside outside p (no output) s Case 3 The University of Texas at Austin 21

Case 4: Polygon edge crosses window edge going in Intersection point i and p are next two vertices of resulting polygon i w j and p w j+1 and j + 2 j (output 2) p inside i outside (output 1) s Case 4 The University of Texas at Austin 22

An Example with a Non-convex Polygon The University of Texas at Austin 23

v2 i1 i2 v3 we1 w1 w2 v4 w3 v1 v5 w5 w4 we2 u1 u2 u3 u4 w1 w5 w3 we3 w2 w4 w1 w5 w3 i3 i4 w2 i5 i6 w4 u6 u5 we4 The University of Texas at Austin 24

Ray-Polyhedron Intersection (This algorithm is a variation/extension of the Liang-Barsky line segment clipping algorithm) The convex polyhedron is defined as the intersection of a collection of halfspaces in 3-space. Represent the ray parametrically as P(t) = P + t u, for scalar t > 0, point P and a unit vector (u). Let H 1, H 2,..., H k denote the halfspaces defining the polyhedron. Compute the intersection of the ray with each halfspace in turn. The final result will be the intersection of the ray with the entire polyhedron. An important property of convex bodies (of any variety) is that a line intersects a convex body in at most one line segment. Thus the resulting intersection of the ray with the polyhedron can be specified entirely by an interval of scalars [t 0, t 1 ]. The parametric representation of the intersection is defined by the line segment Initially, let this interval be [0, ]. (For a line-segment intersection with a polyhedron, the only change is that an initial value of t 1 is set as the endpoint of the segment rather than ). Suppose we have already performed the intersection with some number of the halfspaces. It might be that the intersection is already empty. This will be reflected by the fact that The University of Texas at Austin 25

t 0 > t 1. When this is so, we may terminate the algorithm at any time. Otherwise, let h = (a, b, c, d) be the coefficients of the current halfspace. We want to know the value of t (if any) at which the ray intersects the plane. Plugging in the representation of the ray into the halfspace inequality we have which after some manipulations is a(p x + t u x ) + b(p y + u y ) + c(p z + t u z ) + d 0, t(a u x + b u y + c u z ) (ap x + bp y + cp z + d) If P and u are given in homogeneous coordinates, this can be written as t(h u) (H P) This is not really a legitimate geometric expression (since dot product should only be applied between vectors). Actually the halfspace H should be thought of as a special geometric object, a sort of generalized normal vector. For example, when transformations are applied, normal vectors should be multiplied by the inverse transpose matrix to maintain orthogonality. The University of Texas at Austin 26

We consider three cases. (H u) > 0: in this case we have the constraint t (H P) (H u). Let t denote the right-hand side of this inequality. We trim the high-end of the intersection interval to [t 0, min(t 1, t )]. (H u) < 0 in this case we have t (H P) (H u). Let t denote the right hand side of the inequality. In this case, we trim the low-end of the intersection interval to [t 0, min(t 1, t )]. (H u) = 0: In this case the ray is parallel to the plane, either entirely above or below or on. We check the origin. If (H P) <= 0 then the origin lies in (or on the boundary The University of Texas at Austin 27

of) the halfspace, and so we leave the current interval unchanged. Otherwise, the origin lies outside the halfspace, and the intersection is empty. To model this we can set t 1 to any negative value, e.g., 1. After we repeat this on each face of the polyhedron, we have the following possibilities: t 1 < t 0 : In this case the ray does not intersect the polyhedron. 0 = t 0 = t 1 : In this case, the origin is within the polyhedron. If t 1 =, then the polyhedron must be ungrounded (e.g. like a cone) and there is no intersection. Otherwise, the first intersection point is the point P + t 1 u. 0 < t 0 t 1 : In this case, the origin is outside the polyhedron, and the first intersection is at P + t 0 u. The University of Texas at Austin 28

Reading Assignment and News Chapter 8 pages 374-387, of Recommended Text. Please also track the News section of the Course Web Pages for the most recent Announcements related to this course. (http://www.cs.utexas.edu/users/bajaj/graphics23/cs354/) The University of Texas at Austin 29