EEL Introduction to Computer Graphics

Slides:



Advertisements
Similar presentations
Computer Graphics 4: Viewing In 2D
Advertisements

Computer Graphics CLIPPING.
Objectives Define Clipping Various clipping methods. Line clipping methods.
CHAPTER 12 Height Maps, Hidden Surface Removal, Clipping and Level of Detail Algorithms © 2008 Cengage Learning EMEA.
CS 551 / 645: Introductory Computer Graphics Clipping Lines and Polygons.
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.
Two-Dimensional Viewing Jehee Lee Seoul National University.
Computer Graphics : Clipping
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,
2D Viewing and Projection
2 D viewing Prepared by Elizabeth Isaac DCS, RSET.
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 CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai.
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.
Circle Drawing algo..
1 Computer Graphics Assistant Professor Dr. Sana’a Wafa Al-Sayegh 2 nd Semester ITGD3107 University of Palestine.
2-Dimension Viewing and Clipping
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 and clipping
CS 376 Introduction to Computer Graphics 02 / 12 / 2007 Instructor: Michael Eckmann.
Two-Dimensional Viewing
Clipping: Clipping is a process of dividing an object into visible and invisible positions and displaying the visible portion and discarding the invisible.
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.
Clipping Computer Graphics Cohen Sutherland Algorithm (Line)
Windows, Viewports, and 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.
1 Computer Graphics Clipping Fall FCC Line Clipping What happens when one or both endpoints of a line segment are not inside the specified drawing.
1Computer Graphics Implementation 1 Lecture 15 John Shearer Culture Lab – space 2
2D Viewing.
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
Institute for Visualization and Perception Research 1 © Copyright 2000 Haim Levkowitz Raster graphics alg’s for drawing 2D primitives Points of view Application.
CS 376 Introduction to Computer Graphics 02 / 14 / 2007 Instructor: Michael Eckmann.
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.
Clipping.
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.
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
2D Viewing & Clipping 한신대 류승택
Concepts, algorithms for clipping
Graphics Pipeline Clipping
Chapter 7 2D Clipping.
WINDOWING AND CLIPPING
Computer Graphics : Viewing In 2D
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
WINDOWING AND CLIPPING
Lecture 13 Clipping & Scan Conversion
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Two Dimensional Viewing and Clipping.
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.
COMPUTER GRAPHICS Clipping
Presentation transcript:

EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing Presented by: Yerrapati Raviteja (U41011820)

OUTLINE 2D VIEWING PIPELINE CLIPPING TYPES OF CLIPPING Line clipping Cohen-Sutherland Clipping Liang-Barsky Clipping NLN Clipping Algorithm Point clipping Area clipping Sutherland-Hodgman Area Clipping Algorithm Curve clipping Text clipping All-or-none string clipping All-or-none character clipping Individual character clipping or component clipping Exterior clipping Polygon Clipping Weiler-Atherton Polygon Clipping

CLIPPING Clipping is a process of extracting a portion of a data base or identifying elements of a scene or picture inside or outside a specified region, called the clipping region. In the below figure, which lines and points should be kept and which ones should be clipped??

Windowing I A 2D viewing pipeline is made up of a bunch of objects specified in space of coordinates World Coordinates

Windowing II While we display a scene, only those objects within a particular clipping window are seen Window wymax wymin wxmin wxmax World Coordinates

Windowing III As it takes lots of time to draw things, we simply clip everything which is outside the window. Window wymax wymin wxmin wxmax World Coordinates

TYPES OF CLIPPINGS Based on different output primitives. Further presentation deals with these clipping types with examples: Line clipping Point clipping Area clipping Curve clipping Text clipping Exterior clipping

LINE CLIPPING Examine the end-points of each line to see if they are in the window or not Situation Solution Example Both end-points inside the window Clipping is not needed One end-point inside the window, one outside Clipping is needed Both end-points outside the window Clipping decision should be made accordingly

How line clipping works: LINE CLIPPING (cont..) How line clipping works: Before After Let us discuss about the following Line clipping algorithms in the coming slides: 1. Cohen-Sutherland Clipping 2. Liang-Barsky Clipping 3. NLN Clipping Algorithm

Cohen-Sutherland Clipping Algorithm Oldest, most popular & efficient line clipping algorithm It reduces the number of line intersections that must be calculated by performing initial tests & speeds up processing Every line endpoint in a picture is assigned a 4-digit binary code called a region code Region code identifies the location of a point relative to the boundaries of the clipping rectangle

Cohen-Sutherland: World Division World space is divided into regions based on the window boundaries Each region has a unique four bit region code Region codes indicate the position of the regions with respect to the window 1001 1000 1010 0001 0000 Window 0010 0101 0100 0110 above below right left 3 2 1 Region Code

Cohen-Sutherland: Labelling Every end-point is labelled with the appropriate region code wymax wymin wxmin wxmax Window P3 [0001] P6 [0000] P5 [0000] P7 [0001] P10 [0100] P9 [0000] P4 [1000] P8 [0010] P12 [0010] P11 [1010] P13 [0101] P14 [0110]

Cohen-Sutherland: Lines In The Window Lines completely contained within the window boundaries have region code [0000] for both end-points so are not clipped wymax wymin wxmin wxmax Window P3 [0001] P6 [0000] P5 [0000] P7 [0001] P10 [0100] P9 [0000] P4 [1000] P8 [0010] P12 [0010] P11 [1010] P13 [0101] P14 [0110]

Cohen-Sutherland: Lines Outside The Window Any lines with a common set bit in the region codes of both end-points can be clipped The AND operation (result – not 0000) can efficiently check this wymax wymin wxmin wxmax Window P3 [0001] P6 [0000] P5 [0000] P7 [0001] P10 [0100] P9 [0000] P4 [1000] P8 [0010] P12 [0010] P11 [1010] P13 [0101] P14 [0110]

Cohen-Sutherland: Other Lines Lines that cannot be identified as completely inside or outside the window may or may not cross the window interior These lines are processed as follows: Compare an end-point outside the window to a boundary (choose any order in which to consider boundaries e.g. left, right, bottom, top) and determine how much can be discarded If the remainder of the line is entirely inside or outside the window, retain it or clip it respectively

Cohen-Sutherland: Other Lines (cont…) Otherwise, compare the remainder of the line against the other window boundaries Continue until the line is either discarded or a segment inside the window is found We can use the region codes to determine which window boundaries should be considered for intersection To check if a line crosses a particular boundary we compare the appropriate bits in the region codes of its end-points If one of these is a 1 and the other is a 0 then the line crosses the boundary

Cohen-Sutherland Examples Consider the line P9 to P10 below Start at P10 From the region codes of the two end-points we know the line doesn’t cross the left or right boundary Calculate the intersection of the line with the bottom boundary to generate point P10’ The line P9 to P10’ is completely inside the window so is retained wymax wymin wxmin wxmax Window P10 [0100] P9 [0000] P10’ [0000]

Cohen-Sutherland Examples (cont…) Consider the line P3 to P4 below Start at P4 From the region codes of the two end-points we know the line crosses the left boundary so calculate the intersection point to generate P4’ The line P3 to P4’ is completely outside the window so is clipped wymax wymin wxmin wxmax Window P4’ [1001] P3 [0001] P4 [1000]

Cohen-Sutherland Examples (cont…) Consider the line P7 to P8 below Start at P7 From the two region codes of the two end-points we know the line crosses the left boundary so calculate the intersection point to generate P7’ wymax wymin wxmin wxmax Window P7’ [0000] P7 [0001] P8 [0010] P8’ [0000]

Cohen-Sutherland Examples (cont…) Consider the line P7’ to P8 Start at P8 Calculate the intersection with the right boundary to generate P8’ P7’ to P8’ is inside the window so is retained wymax wymin wxmin wxmax Window P7’ [0000] P7 [0001] P8 [0010] P8’ [0000]

Liang-Barsky Line Clipping Algorithm:- The Liang–Barsky algorithm uses the parametric equation of a line and inequalities describing the range of the clipping window to determine the intersections between the line and the clipping window. With these intersections it knows which portion of the line should be drawn. Consider first the usual parametric form of a straight line: X= x0+u(x1-x0)= x0+uΔx, Y= y0+u(y1-y0)= y0+uΔy, where 0<=u<=1.

Liang-Barsky line clipping (cont..) Faster line clipper algorithm Based on the analysis of parametric equation of a line segment of the form x=x0+u Δx y=y0+u Δy, // 0<=u<=1 Δx=x1-x0 & Δy=y1-y0 More efficient Both Cohen-Sutherland and Liang-Barsky algorithm can be extended to 3-D clipping

Liang-Barsky line clipping (cont..) Algorithm:- 1. Set umin = 0 and umax = 1. 2. Calculate the u values: 3. If u < umin or u > umax ignore it. Otherwise classify the u values as entering or exiting. 4. If umin < umax then draw a line from: ( x0 + Δx · umin, y0 + Δy · umin ) to ( x0 + Δx · umax, y0 + Δy · umax ).

Liang-Barsky line clipping (cont..) Example:- Let P1 (-1, -2), P2 (2, 4) => XL = 0, XR = 1, YB = 0, YT = 1 => dx = 2 - (-1) = 3; dy = 4 - (-2) = 6 P1 = -dx = -3; Q1 = x1 - XL = -1 - 0 = -1; So, Q1 / P1 = 1/3 P2 = dx = 3; Q2 = XR - x1 = 1 - (-1) = 2; So, Q2 / P2 = 2/3 P3 = -dy = -6; Q3 = y1 - YR = -2; So, Q3 / P3 = 1/3 P4 = dy = 6; Q4 = YT - y1 = 3; So, Q4 / P4 = 1/2 for (Pi < 0) t1="MAX" ( 1 / 3, 1 / 3, 0 )= 1 / 3 for (Pi > 0) t2 = MIN ( 2 / 3, 1 / 2, 1 ) = 1 / 2 Since t1 < t2 there is a visible section

Liang-Barsky line clipping (cont..) Example cont.. :- Now, Compute new endpoints: t1 = 1 / 3 x1' = x1 + dx . t1 = -1 + (3 * 1 / 3) = 0 y1' = y1 + dy . t1 = -2 + (6 * 1 / 3) = 0 t2 = 1 / 2 x2' = x1 + dx . t2 = -1 + (3 * 1 / 2) = 1 / 2 y2' = y1 + dy . t2 = -1 + (6 * 1 / 2) = 1 These are the new end point after performing clipping using Liang-Barsky line clipping algorithm.

NLN clipping Algorithm NLN method uses more regions testing in the xy plane to reduce intersection calculations. The extra intersection calculation eliminated in the NLN algorithm by carrying out more region testing before intersection position is calculated. It uses symmetry to categorize endpoints into one of 3 regions (in the clip window, edge & corner). Then according to end point category it checks several clip cases.

NLN clipping Algorithm (cont..) Fig: NLN clipping window. Totally, we can see 9 regions in each image. Only the three region pointed above need be considered If P1 lies in any one of the other six region, we can move it to one of the three regions using a symmetry transformation.

Clipping against Concave Clipping Windows If the clipping polygon is of concave topology, then if the line to be clipped intersects the clipping polygon then it does so at even number of points In this case, in order to find the clipped line, it is necessary to sort the points of intersection, pair the intersection points and then join each pair by a line segment. Sorting can be performed based on either x or y coordinates

POINT CLIPPING Consider a point (x,y) If wxmin ≤ x ≤ wxmax AND wymin ≤ y ≤ wymax It is not clipped! Otherwise It is clipped!

AREA CLIPPING Similarly to lines, areas must be clipped to a window boundary Consideration must be taken as to which portions of the area must be clipped Below are few examples:

AREA CLIPPING (cont..) Sutherland-Hodgman Area Clipping Algorithm: A technique for clipping areas developed by Sutherland & Hodgman Put simply the polygon is clipped by comparing it against each boundary in turn

Sutherland-Hodgman Area Clipping Algorithm (cont…) AREA CLIPPING (cont..) Sutherland-Hodgman Area Clipping Algorithm (cont…) To clip an area against an individual boundary: Consider each vertex in turn against the boundary Vertices inside the boundary are saved for clipping against the next boundary Vertices outside the boundary are clipped If we proceed from a point inside the boundary to one outside, the intersection of the line with the boundary is saved If we cross from the outside to the inside intersection point and the vertex are saved

CURVE CLIPPING Curve clipping procedures will involve non-linear equations (so requires more processing than for objects with linear boundaries In general, methods depend on how characters are represented). Clipping curves requires more work For circles we must find the two intersection points on the window boundary

CURVE CLIPPING (cont..) Preliminary test (Test for overlapping) The bounding rectangle for a circle or other curved object is used to test for overlap with a rectangular clip window. If the bounding rectangle is completely inside (save object), completely outside (discard the object) Both cases- no computation is necessary. If bounding rectangle test fails, use computation-saving approaches Circle – coordinate extents of individual quadrants & then octants are used for preliminary testing before calculating curve–window intersections Ellipse – coordinate extents of individual quadrants are used. If 2 regions overlap, solve the simultaneous line-curve equations to obtain the clipping intersection points.

TEXT CLIPPING It is used to clip character strings. In general, methods depend on how characters are represented. Based on the method used to generate the original characters, three strategies can be followed: 1) All-or-none string clipping use a bounding rectangle for the string 2) All-or-none character clipping use a bounding rectangle for the character 3) Individual character clipping or component clipping like line/curve clipping (outlined char’s) compare individual pixels (bit-mapped)

TEXT CLIPPING (cont..) All-or-none string clipping : Example: It is used to clip the strings relative to the window boundary. Just consider a bounding rectangle around the string. If all of the string is inside the window Save it! Otherwise discard it! Example:

TEXT CLIPPING (cont..) Example: All-or-none character clipping: It is used to clip the characters relative to the window boundary. If all of the character is inside the window Save it! Otherwise discard it! Example:

TEXT CLIPPING (cont..) Example: Component clipping : Clip the components of individual characters. If an individual character crosses or overlaps clip window boundary Discard that component of the character! Otherwise saveit! Example:

EXTERIOR CLIPPING Clip a picture to the exterior of a specified region The picture parts to be saved are those that are outside the region. Ex: Multiple window systems, applications that require overlapping pictures.

Polygon Clipping A polygon boundary processed with a line clipper may be displayed as a series of unconnected line segments, depending on the orientation of the polygon to the clipping window. What we really want to display is a bounded area after clipping. For polygon clipping, we require an algorithm that will generate one or more closed areas that are then scan converted for the appropriate area fill. The output of a polygon clipper should be a sequence of vertices that defines the clipped polygon boundaries.

Polygon Fill-Area Clipping

Steps involved in Polygon Clipping STEP 1: Original polygon STEP 2: After clipping RIGHT Boundary STEP 3: After clipping RIGHT & BOTTOM Boundaries STEP 4: After clipping RIGHT & BOTTOM & LEFT Boundaries STEP 5: After clipping ALL Boundaries

Weiler- Atherton Polygon Clipping In this algorithm, the vertex –processing procedures for window boundaries are modified so that concave polygons are displayed correctly. This clipping procedure was developed as a method for identifying visible surfaces, and so it can be applied with arbitrary polygon-clipping regions. The basic idea in this algorithm is that instead of always proceeding around the polygon edges as vertices are processed,we sometimes want to follow the window boundaries .Which path we follow depend on the polygon-processing direction(clockwise or counterclockwise)

Weiler-Atherton Polygon Clipping

REFERENCES http://www.cs.mun.ca/av/old/teaching/cg/notes/raster_clip2_inclass.pdf http://www.cc.gatech.edu/grads/h/Hao-wei.Hsieh/Haowei.Hsieh/mm.html http://myweb.lmu.edu/dondi/share/cg/clipping.pdf http://www.tutorialspoint.com/computer_graphics/viewing_and_clipping.htm https://www.google.com/search?q=Text+clipping&rlz=1C1CHWA_enUS622US622&es_sm=122&source=lnms&tbm=isch&sa=X&ved=0CAcQ_AUoAWoVChMI08Cvga-byAIVytceCh2d1Ql2&biw=1242&bih=545 http://www.sersc.org/journals/IJCG/vol6_no1/1.pdf