Computer Graphics Lecture 14 CLIPPING I Taqdees A. Siddiqi

Slides:



Advertisements
Similar presentations
9.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 9 – Clipping.
Advertisements

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Clipping Concepts, Algorithms for line clipping 1 of 16 Clipping - 10/16/12.
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 , )
Computer Graphics CLIPPING.
Objectives Define Clipping Various clipping methods. Line clipping methods.
Line clipping: Line clipping algorithm is method of eliminate lines of outside area of the object,so outside of object viewing is Removed. Typically, any.
Computer Graphics, KKU. Lecture 81 Clipping on a Raster Display.
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.
Clipping Lines Lecture 7 Wed, Sep 10, The Graphics Pipeline From time to time we will discuss the graphics pipeline. The graphics pipeline is the.
Computer Graphics : Clipping
Computer Graphics Viewing.
Clipping CSE 403 Computer Graphics Cohen Sutherland Algorithm (Line)
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.
1 Computer Graphics Chapter 4 2D Viewing Algorithms.
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.
Graphics Pipeline Clipping CMSC 435/634. Graphics Pipeline Object-order approach to rendering Sequence of operations – Vertex processing – Transforms.
Windowing and clipping
CS 376 Introduction to Computer Graphics 02 / 12 / 2007 Instructor: Michael Eckmann.
Clipping: Clipping is a process of dividing an object into visible and invisible positions and displaying the visible portion and discarding the invisible.
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
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
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.
Clipping. Before clipping… After clipping… Point Clipping Display P = (x, y) if xw min
Computer Graphic 2 D Viewing.
Computer Graphics Clipping.
Introduction to Computer Graphics with WebGL
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
2D Viewing & Clipping 한신대 류승택
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
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.
CS U540 Computer Graphics Prof. Harriet Fell Spring 2007
Clipping Clipping Sutherland-Hodgman Clipping
CS U540 Computer Graphics Prof. Harriet Fell Spring 2007
Computer Graphics Viewing. 2 of 30 Viewing in 2D Window in world coordinates. 45  250  Viewport in Device coords 250 x 250 Pixels.
Type to enter a caption. Computer Graphics Week 4 Lecture 2.
Implementation I Ed Angel Professor Emeritus of Computer Science
CS U540 Computer Graphics Prof. Harriet Fell Spring 2007
COMPUTER GRAPHICS Clipping
Presentation transcript:

Computer Graphics Lecture 14 CLIPPING I Taqdees A. Siddiqi cs602@vu Computer Graphics Lecture 14 CLIPPING I Taqdees A. Siddiqi cs602@vu.edu.pk

CLIPPING I Taqdees A. Siddiqi cs602@vu.edu.pk

Concept Restricting the effect of graphics primitives to a sub-region of the canvas Protecting other portions of the canvas

Primitives lying outside the clip rectangle are not drawn. All primitives are clipped to the boundaries of this clipping rectangle; Primitives lying outside the clip rectangle are not drawn.

The default clipping rectangle is the full canvas (the screen); We cannot see any graphics primitives outside the screen

Example This is a simple example of line clipping: the display window is the canvas and also the default clipping rectangle, thus all line segments inside the canvas are drawn.

Point Clipping xmin <= x <= xmax ymin <= y <= ymax

Line Clipping Clipping of lines against rectangles

Clipping Individual Points Simpler problem Xmin < X < Xmax And Ymin < Y < Ymax

Trivial Accept – save a line with both endpoints inside all clipping boundaries

Trivial Reject – discard a line with both endpoints outside the clipping boundaries

For all other lines – compute intersections of line with clipping boundaries

Parametric Representation Line x = x1 + u (x2 - x1) y = y1 + u (y2 - y1) and 0 <= u <= 1

If 0 <= u <= 1 then the line does enter the interior of the window at that boundary otherwise, the line does not enter the interior of the window at that boundary.

Solve Simultaneous Equations Need to consider only endpoints of a line: If both endpoints lie inside the clip rectangle; it can be trivially accepted.

If one endpoint lies inside and one outside, the line intersects the clip rectangle and we must compute the intersection point.

If both endpoints are outside the clip rectangle, we need to perform further calculations to determine whether there are any intersections.

The Brute Force Approach Intersect that line with each of the four clip rectangle edges. if so, the line cuts the clip rectangle and is partially inside.

For each line and clip-rectangle edge, we therefore take the two mathematically infinite lines that contain them and intersect them.

Test whether this intersection point is "interior" -- that is, whether it lies within both the clip rectangle edge and the line.

If so, there is an intersection with the clip rectangle.

Line Clipping Algorithm Cohen Sutherland Line Clipping Algorithm More efficient; Performs initial tests on a line to determine whether intersection calculations can be avoided.

End-point pairs are checked using the out-code. If not divided into two segments at a clip edge, iteratively clipped by testing trivial-acceptance or trivial-rejection.

Trivial Accept / Reject Test

Each bit in the out-code is set to either 1 (true) or 0 (false); The 4 bits in the code correspond to the following conditions:

Bit 1: outside half-plane of top edge, above top edge Y > Ymax Bit 2: outside half-plane of bottom edge, below bottom edge Y < Ymin

Bit 3: outside half-plane of right edge, to the right of right edge X > Xmax Bit 4: outside half-plane of left edge, to the left of left edge X < Xmin

Conclusion Algorithm is efficient when out-code testing can be done cheaply

Liang-Barsky Algorithm Faster line clippers based on analysis of the parametric equation of a line segment:

x = x1 + u x y = y1 + u y, where 0 <= u <= 1, x = x2 - x1 and y = y2 - y1

Following the Liang-Barsky approach, we first write the point-clipping in a parameteric way: xmin <= x1 + u x <= xmax ymin <= y1 + u y <= ymax

These four inequalities can be expressed as   u * pk <= qk, for k = 1, 2, 3, 4

Where parameters p and q are defined as:   p1 = -x, q1 = x1 - xmin p2 = -x, q2 = xmax - x1 p3 = -y, q3 = y1 - ymin p4 = -y, q4 = ymax - y1

Any line that is parallel to one of the clipping boundaries having pk = 0 If, for that value of k, we also find qk >= 0, the line is inside the parallel clipping boundary.

When pk < 0, the infinite extension of the line proceeds from outside to the inside of the infinite extension of the particular clipping boundary.

If pk > 0, the line proceeds from the inside to the outside.

For a nonzero value of pk, we can calculate the value of u that corresponds to the point where the infinitely extended line intersects the extension of boundary k as: u = qk / pk

For each line, we can calculate values for parameters u1 and u2 which define that part of the line which lies within the clip rectangle.

The value of u1 is determined by looking at the rectangle edges for which the line proceeds from the outer-side to the inner-side (p < 0). For these edges we calculate rk = qk / pk.

The value of u1 is taken as the largest of the set consisting of 0 and the various values of r.

The value of u2 is determined by examining the boundaries for which the line proceeds from inside to outside (p > 0).

Algorithm Line intersection parameters are initialized to the values: u1 = 0 and u2 = 1.

For each clipping boundary, the appropriate values for p and q are calculated and used to determine whether the line can be rejected or the intersection parameters are to be adjusted.

A value of rk is calculated for each of these boundaries and the value of u2 is the minimum of the set consisting of 1 and the calculated r values.

If u1 > u2, the line is completely outside the clip window and it can be rejected.

Otherwise, the end points of the clipped line are calculated from the two values of parameter u.

When p < 0, the parameter r is used to update u1;

If updating u1 or u2 results in u1 > u2, we reject the line.

Otherwise, we update the appropriate u parameter only if the new value results in a shortening of the line.

When p = 0 and q < 0, we can discard the line since it is parallel to and outside of this boundary.  

If the line has not been rejected after all four values of p and q have been tested, the endpoints of the clipped line are determined from values of u1 and u2.

More efficient; intersection calculations are reduced. Conclusion More efficient; intersection calculations are reduced.

Each update of parameters u1 and u2 requires only one division; and window intersections of the line are computed only once, when the final values of u1 and u2 are computed.

Cohen-Sutherland algorithm can repeatedly calculate intersections along a line path, even though the line may be completely outside the clip window, and, each intersection calculation requires both a division and a multiplication.

Computer Graphics Lecture 14