COMPUTER GRAPHICS Clipping

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

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.
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 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,
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 King ABDUL AZIZ University Faculty Of Computing and Information Technology CS 454 Computer graphics Two Dimensional Viewing Dr. Eng. Farag Elnagahy
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.
1 Computer Graphics Assistant Professor Dr. Sana’a Wafa Al-Sayegh 2 nd Semester ITGD3107 University of Palestine.
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
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.
Unit – IV 2D Viewing. 2 of 30 Contents Windowing Concepts The viewing pipeline viewing coordinate reference frame, window to view-port coordinate transformation,
10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.
EEL Introduction to Computer Graphics
1Computer Graphics Implementation 1 Lecture 15 John Shearer Culture Lab – space 2
Introduction to Computer Graphics Chapter 6 – 2D Viewing Pt 3 1.
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
Lecture 9 From Vertices to Fragments. Objectives Introduce basic implementation strategies Clipping Rasterization hidden-surface removal.
Clipping.
Two-Dimensional Viewing Hearn & Baker Chapter 6
Computer Graphics Lecture 14 CLIPPING I Taqdees A. Siddiqi
Computer Graphic 2 D Viewing.
Computer Graphics Clipping.
Computer Graphics CC416 Week 13 Clipping.
Transformations contd.
CS 551 / 645: Introductory Computer Graphics
Computer Graphics Shading in OpenGL
Concepts, Algorithms for line clipping
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Computer Graphics Viewing
2D Viewing & Clipping 한신대 류승택
3D rezanje 3D Clipping view frustrum clipping planes clipped.
Concepts, algorithms for clipping
3D Clipping.
Implementation I Ed Angel
Graphics Pipeline Clipping
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
CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai
WINDOWING AND CLIPPING
Lecture 13 Clipping & Scan Conversion
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
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
(c) 2002 University of Wisconsin, CS559
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
Presentation transcript:

COMPUTER GRAPHICS Clipping Slides are taken from Robert Thomsons notes.

Graphics packages commonly allow only rectangular clipping windows aligned with the x- and y-axes Must implement own clipping and coordinate transformations for other form of clipping

(clipping) window to viewport transformation Zooming is successive mapping of different sized clipping windows to the viewport reducing clip window : zoom in on part of scene increase clip window : zoom out Panning moving a fixed-size clipping window across the scene

From world coordinates to view coordinates

Clipping Remove portion of output primitives outside clipping window Two approaches Clip during scan conversion: check each pixel against clip limits Clip analytically, then scan-convert the modified primitives

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 windowing Modelling May require more complex geometry than rectangular boxes

Two-Dimensional Clipping Point clipping – trivial Line clipping Cohen-Sutherland Liang-Barsky Nicholl-Lee-Nicholl Fill-area clipping Sutherland-Hodgeman Weiler-Atherton Text clipping

Cohen-Sutherland Clip line against each edge of clip region in turn If both endpoints outside, discard line and stop If both endpoints in, continue to next edge (or finish) If one in, one out, chop line at crossing pt and continue

Cohen-Sutherland 1 2 3 3 4 4 3 3 4 4 1 2 1 2

Cohen-Sutherland Some cases lead to early acceptance or rejection If both endpoints are inside all edges If both endpoints are outside one edge

b1 OR b2 = 0 iff both end points inside clipping window. Accept b1 AND b2  0 iff line end points are in the same half-space defined by an edge of the clipping window. Reject Else subdivide the line into two segments at the point where it crosses a clipping rectangle edge. Reject segment(s) outside the clipping edge

The Cohen-Sutherland algorithm Consider line AD (above). Point A has outcode 0000 and point D has outcode 1001. The line AD cannot be trivially accepted or rejected. D is chosen as the outside point. Its outcode shows that the line cuts the top and left edges (The bits for these edges are different in the two outcodes). Let the order in which the algorithm tests edges be top-to-bottom, left-to-right. The top edge is tested first, and line AD is split into lines DB and BA. Line BA is trivially accepted (both A and B have outcodes of 0000). Line DB is in the outside halfspace of the top edge, and gets rejected.

update line endpoint coordinates

Cohen-Sutherland Line Clipping Fixed order testing and clipping cause needless clipping (external intersections) Extra clipping here

Cohen-Sutherland Line Clipping This algorithm can be very efficient if it can accept and reject primitives trivially If clip window is large wrt scene data Most primitives are accepted trivially If clip window is much smaller than scene data Most primitives are rejected trivially Good for hardware implementation

Liang-Barsky Line Clipping Clipping: Overview of Steps Express line segments in parametric form Derive equations for testing if a point is inside the window Compute new parameter values for visible portion of line segment, if any Display visible portion of line segment The relative speed improvement over Sutherland-Cohen algorithm is as follows: 36% for 2D lines 40% for 3D lines 70% for 4D lines

Liang-Barsky Clipping Parametric clipping - view line in parametric form and reason about the parameter values More efficient, as not computing the coordinate values at irrelevant vertices Clipping conditions on parameter: Line is inside clip region for values of t such that:

Liang-Barsky (2) Infinite line intersects clip region edges when: where

Liang-Barsky (3) When pk<0, as t increases line goes from outside to inside - enter When pk>0, line goes from inside to outside - leave When pk=0, line is parallel to an edge (clipping is easy) If there is a segment of the line inside the clip region, sequence of infinite line intersections must go: enter, enter, leave, leave

Liang-Barsky (4) Leave Enter Leave Leave Leave Enter Enter Enter

Liang-Barsky - Algorithm Compute entering t values, which are qk/pk for each pk<0 Compute leaving t values, which are qk/pk for each pk>0 Parameter value for small t end of line is:tsmall= max(0, entering t’s) parameter value for large t end of line is: tlarge=min(1, leaving t’s) if tsmall<tlarge, there is a line segment - compute endpoints by substituting t values

Nicholl-Lee-Nicholl Line Clipping Creates more testing regions around the clipping window Avoids multiple line-intersection calculations Initial testing to determine if a line segment is completely inside the clipping window can be done using previous methods If trivial acceptance or rejection is not possible the NLN algorithm sets up additional regions

P0 P0 P0 For line with endpoints P0Pend, there are three different positions to consider - all others can be derived from these by symmetry considerations For each case, we generate specialized test regions for other endpoint Pend, which use simple tests (slope, >, <), and tells us which edges to clip against.

Case 1 T Find which of the four regions Pend lies in, then calculate the line intersection with the corresponding boundary L R P0 B

Case 2 LT L LR P0 L L LB Find which of the four regions Pend lies in, then calculate the line intersection with the corresponding boundary

Case 3 : 2 possibilities P0 P0 T T TR T TR L L L LR LB TB LB Find which of the five regions Pend lies in, then calculate the line intersection with the corresponding boundary

N-L-N Line clipping To determine in which region Pend lies we compare the slope of PendPo to the slopes of the boundaries of the NLN regions LT L LR P0 L L LB Number of cases explodes in 3D, making algorithm unsuitable

Polygon clipping Clipping a polygon fill area needs more than line-clipping of the polygon edges would produce and unconnected set of lines Must generate one or more closed polylines, which can be filled with the assigned colour or pattern

Sutherland-Hodgman Polygon Clipping The algorithm correctly clips convex polygons, but may display extraneous lines for concave polygons

Weiler-Atherton Polygon Clipping Another approach to polygon clipping No extra clipping outside window Works for arbitrary shapes Avoids degenerate polygons Outline of Weiler algorithm: Replace crossing points with vertices Form linked lists of edges Change links at vertices Enumerate polygon patches

Weiler-Atherton Clipping clockwise orientation of subject polygon 13 14 4 2 3 5 1 6 12 Clip Polygon (ep) 9 7 8 Subject Polygon (sp) 10 11

Gives “Right” Answer

Weiler-Atherton Clipping (clockwise orientation of polygon) Start at first (inside) vertex Traverse polygon until hitting a window boundary Output intersection point i Turn right Follow window boundary until next intersection

Weiler-Atherton Clipping Output second intersection Turn right, again, and follow subject polygon until closed Continue on subject polygon from first intersection point. Repeat processing until complete

Generalizations of W-A Can be extended to complex situations, arbitrary windows Stability issues can arise for such cases

Weiler-Atherton Polygon Clipping counter-clockwise orientation of subject polygon

For an outside-to-inside pair of vertices, follow the polygon boundary Weiler-Atherton Polygon Clipping counter-clockwise orientation of subject polygon For an outside-to-inside pair of vertices, follow the polygon boundary For an inside-to-outside pair of vertices, follow the window boundary in a counter-clockwise direction

Weiler-Atherton Polygon Clipping Polygon clipping using nonrectangular polygon clip windows

Text Clipping All-or-none text clipping All-or-non character clipping Using boundary box for the entire text All-or-non character clipping Using boundary box for each individual character Character clipping Vector font: Clip boundary polygons or curves Bitmap font: Clip individual pixels

3D Clipping Algorithms No matter what the projection details were, we now have a normalized cube, so we clip against planes parallel to Cartesian planes (either at coordinates 0 and 1, or -1 and 1) The task is to identify object sections within the cube (save parts inside and eliminate parts outside) Algorithms are extensions of the 2D algorithms

3D Region Codes The idea is the same as in 2D (we added 2 more bits for near and far planes) A point is now P=(xh,yh,zh,h) h can be a value other than 1 (in perspective projection), so, the inequalities to be satisfied are -1<=xh/h<=1 -1<= yh/h<=1 -1<= zh/h<=1

3D Region Codes And bit values can be decided by h values should be nonzero and often positive (these can be easily checked) So, our inequalities become -h <= xh <= h, -h <= yh <= h, and -h <= zh <= h And bit values can be decided by bit 1 = 1 if h + xh < 0 (left) bit 2 = 1 if h - xh < 0 (right) bit 3 = 1 if h + yh < 0 (bottom) bit 4 = 1 if h - yh < 0 (top) bit 5 = 1 if h + zh < 0 (near) bit 6 = 1 if h - zh < 0 (far)

Figure 10-50 Values for the three-dimensional, six-bit region code that identifies spatial positions relative to the boundaries of a view volume.

Figure 10-51 Three-dimensional region codes for two line segments Figure 10-51 Three-dimensional region codes for two line segments. Line P1P2 intersects the right and top clipping boundaries of the view volume, while line P3P4 is completely below the bottom clipping plane.

Figure 10-52 Three-dimensional object clipping Figure 10-52 Three-dimensional object clipping. Surface sections that are outside the view-volume clipping planes are eliminated from the object description, and new surface facets may need to be constructed.

Figure 10-53 Clipping a line segment against a plane with normal vector N.

Figure 10-54 Clipping the surfaces of a pyramid against a plane with normal vector N. The surfaces in front of the plane are saved, and the surfaces of the pyramid behind the plane are eliminated.