Computer Graphics : Viewing In 2D

Slides:



Advertisements
Similar presentations
Computer Graphics - Rasterization -
Advertisements

9.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 9 – Clipping.
Computer Graphics 4: Viewing In 2D
CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Clipping Concepts, Algorithms for line clipping 1 of 16 Clipping - 10/16/12.
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.
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.
Course Website: Computer Graphics 4: Viewing In 2D.
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,
2D Viewing and Projection
Introduction to Computer Graphics Chapter 6 – 2D Viewing Pt 2 1.
Vertices and Fragments I CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
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.
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.
2-Dimension Viewing and Clipping
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.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Objectives Introduce basic implementation strategies Clipping Scan conversion.
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
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
Graphics Graphics & Graphical Programming Lecture 23 - Viewing & Clipping.
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 Graphics Lecture 14 CLIPPING I Taqdees A. Siddiqi
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
Concepts, algorithms for clipping
Implementation I Ed Angel
Graphics Pipeline Clipping
Chapter 7 2D Clipping.
WINDOWING AND CLIPPING
o عَلَّمَهُ الْبَيَانَ
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.
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 : Viewing In 2D UNIT-3

Contents Windowing Concepts Clipping Area Clipping Introduction Brute Force Cohen-Sutherland Clipping Algorithm Area Clipping Sutherland-Hodgman Area Clipping Algorithm

Windowing I A scene is made up of a collection of objects specified in world coordinates World Coordinates

Windowing II When we display a scene only those objects within a particular window are displayed Window wymax wymin wxmin wxmax World Coordinates

Windowing III Because drawing things to a display takes time we clip everything outside the window Window wymax wymin wxmin wxmax World Coordinates

Clipping For the image below consider which lines and points should be kept and which ones should be clipped P4 Window P2 wymax P6 P3 P1 P7 P5 P9 P8 wymin P10 wxmin wxmax

Points Within the Window are Not Clipped Point Clipping Easy - a point (x,y) is not clipped if: wxmin ≤ x ≤ wxmax AND wymin ≤ y ≤ wymax otherwise it is clipped P4 Clipped Clipped Window P2 wymax Clipped P5 P1 P7 Points Within the Window are Not Clipped P9 P8 wymin Clipped P10 wxmin wxmax

Line Clipping Harder - 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 Don’t clip One end-point inside the window, one outside Must clip Both end-points outside the window Don’t know!

Cohen-Sutherland Algorithm Idea: eliminate as many cases as possible without computing intersections Start with four lines that determine the sides of the clipping window y = ymax x = xmin x = xmax y = ymin

The Cases Case 1: both endpoints of line segment inside all four lines Draw (accept) line segment as is Case 2: both endpoints outside all lines and on same side of a line Discard (reject) the line segment y = ymax x = xmin x = xmax y = ymin

The Cases Case 3: One endpoint inside, one outside Must do at least one intersection Case 4: Both outside May have part inside y = ymax x = xmin x = xmax

Defining Outcodes For each endpoint, define an outcode Outcodes divide space into 9 regions Computation of outcode requires at most 4 subtractions b0b1b2b3 b0 = 1 if y > ymax, 0 otherwise b1 = 1 if y < ymin, 0 otherwise b2 = 1 if x > xmax, 0 otherwise b3 = 1 if x < xmin, 0 otherwise

Using Outcodes Consider the 5 cases below AB: outcode(A) = outcode(B) = 0 Accept line segment

Using Outcodes CD: outcode (C) = 0, outcode(D)  0 Compute intersection Location of 1 in outcode(D) determines which edge to intersect with Note if there were a segment from A to a point in a region with 2 ones in outcode, we might have to do two interesections

Using Outcodes EF: outcode(E) logically ANDed with outcode(F) (bitwise)  0 Both outcodes have a 1 bit in the same place Line segment is outside of corresponding side of clipping window reject

Using Outcodes GH and IJ: same outcodes, neither zero but logical AND yields zero Shorten line segment by intersecting with one of sides of window Compute outcode of intersection (new endpoint of shortened line segment) Reexecute algorithm

Efficiency In many applications, the clipping window is small relative to the size of the entire data base Most line segments are outside one or more side of the window and can be eliminated based on their outcodes Inefficiency when code has to be reexecuted for line segments that must be shortened in more than one step

Liang – Barsky clipping In computer graphics, the Liang–Barsky algorithm (named after You-Dong Liang and Brian A. Barsky) is a 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. This algorithm is significantly more efficient than Cohen– Sutherland.

The idea of the Liang-Barsky clipping algorithm is to do as much testing as possible before computing line intersections. Consider first the usual parametric form of a straight line: A point is in the clip window, if

To compute the final line segment: A line parallel to a clipping window edge has   for that boundary. If for that  the line is completely outside and can be eliminated. When   the line proceeds outside to inside the clip window and when , the line proceeds inside to outside. For nonzero  ,  gives the intersection point.

Here

Liang-Barsky Leave Enter Leave Leave Leave Enter Enter Enter

Liang-Barsky - Algorithm Compute entering u values, which are qk/pk for each pk<0 Compute leaving u values, which are qk/pk for each pk>0 Parameter value for small u end of line is:usmall= max(0, entering u’s) parameter value for large t end of line is: ularge=min(1, leaving u’s) If usmall<ularge, there is a line segment - compute endpoints by substituting t values Improvement (and actual Liang-Barsky): compute u’s for each edge in turn (some rejects occur earlier like this.)

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

Sutherland-Hodgman Area Clipping Algorithm Sutherland turns up again. This time with Gary Hodgman with whom he worked at the first ever graphics company Evans & Sutherland A technique for clipping areas developed by Sutherland & Hodgman Put simply the polygon is clipped by comparing it against each boundary in turn Original Area Clip Left Clip Right Clip Top Clip Bottom

The Sutherland-Hodgeman Polygon-Clipping Algorithms clips a given polygon successively against the edges of the given clip- rectangle. These clip edges are denoted with e1, e2, e3, and e4, here. The closed polygon is represented by a list of its vertices (v1 to vn; Since we got 15 vertices in the example shown above, vn = v15.). Clipping is computed successively for each edge. The output list of the previous clipping run is used as the input list for the next clipping run.

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

Sutherland-Hodgman Example Each example shows the point being processed (P) and the previous point (S) Saved points define area clipped to the boundary in question S P Save Point P S P Save Point I I P S No Points Saved S P Save Points I & P I

Other Area Clipping Concerns Clipping concave areas can be a little more tricky as often superfluous lines must be removed Clipping curves requires more work For circles we must find the two intersection points on the window boundary Window Window