2-Dimension Viewing and Clipping

Slides:



Advertisements
Similar presentations
Rezanje črt in poligonov. World window & viewport window viewport screen window world window.
Advertisements

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.
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.
CS 551 / 645: Introductory Computer Graphics Clipping Lines and Polygons.
CS 445 / 645 Introduction to Computer Graphics Lecture 9 Clipping Clipping.
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 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,
2 D viewing Prepared by Elizabeth Isaac DCS, RSET.
Introduction to Computer Graphics Chapter 6 – 2D Viewing Pt 2 1.
March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Clipping Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Clipping Week 8, Wed Mar.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Interpolation Clipping.
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 Computer Graphics Chapter 4 2D Viewing Algorithms.
1 King ABDUL AZIZ University Faculty Of Computing and Information Technology CS 454 Computer graphics Two Dimensional Viewing Dr. Eng. Farag Elnagahy
Texturing, Clipping Week 9, Mon 27 Oct 2003
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 551 / 645: Introductory Computer Graphics
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.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
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.
CSE Real Time Rendering Week 9. Post Geometry Shaders Courtesy: E. Angel and D. Shreiner – Interactive Computer Graphics 6E © Addison-Wesley 2012.
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,
EEL Introduction to Computer Graphics
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.
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
2D Viewing.
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
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.
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
Clipping Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Concepts, algorithms for clipping
Implementation I Ed Angel
Graphics Pipeline 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
Clipping Polygons Dr. Scott Schaefer.
Clipping Clipping Sutherland-Hodgman Clipping
Clipping University of British Columbia CPSC 314 Computer Graphics
Implementation I Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

2-Dimension Viewing and Clipping Chapter 6 Except Text and Curve clipping Some of the material in these slides may have been adapted from University of Virginia, MIT, and Åbo Akademi University

Viewing Pipeline World Co-ordinates Window: Viewport (x,y) values of all points in a single reference frame Window: It is the area of the world that was selected to be viewed Viewport It is the area on the display device on which the window is mapped View Transformation It is the process of mapping part of a scene in the world co-ordinate to an area on the display device Windows and viewports are usually rectangular In general, they can be anything (circular, oval, hexagona)

Viewing Pipeline Construct scene in world coordinate using primitives and modeling Viewing coordinates usually defined within unit square Separates transformations from device specifics Convert world coordinate To viewing coordinates Map viewing coordinates to Normalized Viewing coordinates Map Normalized View port To device coordinates

Clipping Window and Viewport

Normalized Viewport

Screen Viewport

Why Viewing Pipeline Need to use any primitives, techniques, and models to construct scenes Need to construct scenes in standard coordinates Need to view from any angle and zoom Need to be able to display on any display device

Clipping We’ve been assuming that all primitives lie entirely within the viewport In general, this assumption does not hold

Clipping What is clipping? Analytically calculating the portions of primitives within the viewport Primitives can be anything: point, line, polygon, circle, curves,…., etc.

Why Clip? Computer graphics benefits from being able to reduce the amount of work needed to draw objects. Objects will be inside the specified region but not visible and therefore skipped Bad idea to rasterize outside of framebuffer bounds Also, don’t waste time scan converting pixels outside window

Point Clipping Trivial xmin £ x £ xmax ymin£ y £ ymax Required when scene is constructed from points (e.g. Explosion, sea foam,…, etc.) Not common (we usually do lines, polygons, curves,..,etc)

Line Clipping Typical cases First, lets attempt to do a simple pre-processing Quickly determine complete acceptance or complete rejection

Trivial Accepts Big optimization: trivial accept/rejects How can we quickly determine whether a line segment is entirely inside the viewport? A: test both endpoints. xmin xmax H ymax C A E F F G D B ymin

Trivial Accepts If both endpoints are within the view port Completely accept xmin xmax H ymax C A E F F G D B ymin

Trivial Rejects How can we know a line is entirely outside viewport? R: if both endpoints on wrong side of same edge, can trivially reject line xmin xmax H ymax C A E F F G D B ymin

Simple Line Clipping All other lines have end points (x1,y1) (x2,y2) such that one or both endpoints are outside the clipping boundaries Need to determine intersection points with boundaries Represent the line in parametric form x = x1 + t*(x2 - x1) y = y1 + t*(y2 - y1) t Î [0,1] Compute intersection points with the four boundaries xmin, xmax, ymin ,ymax (how can we do that quickly?) How can we quickly determine whether a line segment intersects a clipping boundary?

Simple Line Clipping If only one endpoint is inside Display the segment from the boundary Intersection to the inside endpoint If both endpoints are outside Display the segment between the two intersections Disadvantages Computationally intensive More efficient approaches exist

Cohen-Sutherland Line Clipping Divide viewplane into regions defined by viewport edges Assign each region a 4-bit outcode: xmin xmax 1001 1000 1010 ymax 0001 0000 0010 ymin 0101 0100 0110

Cohen-Sutherland Line Clipping We generate this 4-bit classification using #define LEFT_EDGE 0x1 // 0001 #define RIGHT_EDGE 0x2 // 0010 #define BOTTOM_EDGE 0x4 // 0100 #define TOP_EDGE 0x8 // 1000 For each point (x,y) we calculate unsigned char code = 0x0 if ( x < xmin ) code = code | LEFT_EDGE if ( x > xmax ) code = code | RIGHT_EDGE if ( y < ymin ) code = code | BOTTOM_EDGE if ( y > ymax ) code = code | TOP_EDGE At the end, we have assigned a code for every endpoint

Cohen-Sutherland Line Clipping Trivial accept Accept if both endpoints are inside How can we do that efficiently? Trivial reject Reject if both endpoints are on the wrong side of an edge How can we determine which wrong side?

Cohen-Sutherland Line Clipping Trivial accept Accept if both endpoints are inside How can we do that efficiently? Trivial reject Reject of both endpoints are on the wrong side of an edge How can we do that efficiently How can we determine which wrong side? Use bitwise AND between the codes of the endpoints

Cohen-Sutherland Line Clipping Example xmax xmin 1001 1000 H 1010 ymax C A E F F 0001 0000 0010 G D B ymin 0101 0100 0110

Cohen-Sutherland Line Clipping Algorithm Given a line segment with endpoint p1(x1,y1) and p2(x2,y2) Compute the 4-bit codes for each endpoint. If both codes are 0000,(bitwise OR of the codes yields 0000 ) line lies completely inside the window: pass the endpoints to the draw routine. If both codes have a 1 in the same bit position (bitwise AND of the codes is not 0000), the line lies outside the window. It can be trivially rejected.

Cohen-Sutherland Line Clipping Algorithm Lines that cannot be trivially accepted or rejected have one or both endpoints outside Examine one of the endpoints, say P1=(x1,y1). Read P1's 4-bit code in order: Left-to-Right, Bottom-to-Top. When a set bit (1) is found, compute the intersection I of the corresponding window edge with the line from P1 to P2. Replace P1 with I and repeat the algorithm. Discard portion on wrong side of edge and assign outcode to new vertex Apply trivial accept/reject tests; Repeat if necessary until the entire line is finished Proceed to the next line

Cohen-Sutherland Line Clipping Example Pick J  Clip JI  Pick G  Clip GH Pick E  Clip ED  Pick A  Clip AB  Pick B  Clip BC E J xmax xmin 1001 1000 1010 ymax D I H 0001 0000 0010 G C ymin 0101 0100 0110 B A

Cohen-Sutherland Line Clipping We have accepted/discarded lines inside/outside the window We have chosen the subsection of the line which is inside the window Algorithm can be modified for 3D Still not efficient enough Need to compute up to 4 intersections per line Fundamentally more efficient algorithms: Liang-Barsky uses parametric lines Nicholl-Lee-Nicholl

Polygon Clipping Convex and Concave Splitting Concave Polygon Sutherland-Hodgman Clipping

Convex and Concave Definition: A closed shape (not necessarily a polygon) is said to be convex if the straight line between two internal points lies completely inside the shape`

Splitting Concave Polygon Detecting concavity: Calculate cross products of consecutive polygon edges If there is at least one change of sign in z-component, then the polygon is concave How to detect concavity on a continuous curve?

Splitting Concave Polygon Some polygon clipping algorithm assume convex polygon Concave polygons can be decomposed into convex polygons. There are Several solutions! Vector Method Rational Method Both method work non-intersecting polygons only

Splitting Concave Polygon Vector Method Walk around the polygon in counter-clockwise direction Cross product every consecutive edges When the sign of (En x En+1) changes, split along En Calculate new edge and the new polygon

Splitting Concave Polygon Rational Method Walk the polygon counter-clockwise For each two consecutive edges E1, E2 consisting of V1, V2, V3 Translate V1 to origin Rotate clockwise such that V1,V2 is on the x-axis If line is below X-axis (I.e. y3 < 0) Polygon is concave Split along x-axis

Clipping Polygons Clipping polygons is more complex than clipping the individual lines Input: polygon Output: polygon, or nothing Simply applying line clipping would not work !! We do not want broken lines. We want a polygon

Why Is Polygon Clipping Hard? Many possible outcomes: triangletriangle trianglequad triangle5-gon triangle6-gon triangle7-gon

Why Is Polygon Clipping Hard? A really tough case:

Why Is Polygon Clipping Hard? A really tough case: concave polygonmultiple polygons

Why Is Polygon Clipping Hard? Not easy to trivially reject Even if most of lines can be trivially rejected, we may still need to display a polygon

Sutherland-Hodgman Clipping Basic Idea Initial Input: Polygon = {ordered list of vertices} Process only against one clipping boundary at a time! Clip each line in the polygon against each clip boundary in turn: left, right, bottom, top. Basic steps Input: Polygon = {ordered list of vertices} After finishing each boundary, the output vertex list is generated The output vertex list is the new polygon input to the next boundary Final output list of vertices is the clipped polygon

Sutherland-Hodgman Clipping Rules to generate the Vertex list Apply the following rules for every pair of vertices If the first vertex is outside and the second is inside, then move the first vertex to the clipping boundary and accept both vertices. Calculate intersection point with the boundary Replace the first vertex with the intersection point Put the new first vertex and the second vertex in the output list If both vertices are inside, put the second vertex in the output list. If the first vertex is inside and the second is outside, then move the second to the clipping boundary and accept the second. Replace the second vertex with the intersection point Put the new second vertex in the output list If both vertices are outside, reject both. How to determine wither a point is inside or outside a given boundary?

Sutherland-Hodgman Clipping How to determine Inside and Outside Lets say a line endpoint has the co-rdinates (x,y) Inside Xmin means x > Xmin Inside Xmax means x < Xmax Inside Ymin means y > Ymin Inside Ymax means y < Ymax

Sutherland-Hodgman Clipping Illustration outin Save V’1, V2 inin Save V2 inout Save V’1 outout Save non

Sutherland-Hodgman Clipping Example V3 V2 V1

Sutherland-Hodgman Clipping Example V2V3V2’, V3 V3V1V1 V1V2V1’ Final List: V2’,V3,V1,V1’ V3 V’2 V2 V’1 V1

Sutherland-Hodgman Clipping Example V2’V3V3 V3V1V3’ V1V1’ V1’V2’V2’’V2’ Final List: V3,V3’,V2’’,V2’ V3 V’2 V’’2 V’3 V’1 V1

Sutherland-Hodgman Clipping Example V2’V3V3 V3V1V3’ V1V1’ V1’V2’V2’’V2’ Final List: V3,V3’,V2’’,V2’ V3 V’2 V’’2 V’3 V’1 V1

Sutherland-Hodgman Clipping Another Example

Sutherland-Hodgman Clipping Another Example

Sutherland-Hodgman Clipping Another Example

Sutherland-Hodgman Clipping

Sutherland-Hodgman Clipping

Sutherland-Hodgman Clipping

Sutherland-Hodgman Clipping

Sutherland-Hodgman Clipping

Sutherland-Hodgman Clipping

Sutherland-Hodgman Clipping

Sutherland-Hodgman Clipping Convex polygons correctly processed Concave polygons may produce extraneous lines We only have one list Last point is always joined to first We need two vertex lists because the polygon is divided into two polygons 6 6 5 5 4 4 3 3 1 2 1 2