Transformations contd.

Slides:



Advertisements
Similar presentations
Computer Graphics - Rasterization -
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 , )
Computer Graphics CLIPPING.
Objectives Define Clipping Various clipping methods. Line clipping methods.
Java ThreadsGraphics Programming Graphics Programming: Windows, Viewports & Clipping.
CHAPTER 12 Height Maps, Hidden Surface Removal, Clipping and Level of Detail Algorithms © 2008 Cengage Learning EMEA.
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:
Line Clipping Algorithms. A Cases for Clipping Lines E B H C G J I clip rectangle 2Prepared by Narendra V G CSE MIT.
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.
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
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.
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.
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
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.
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
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.
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.
Chapter 71 Computer Graphics - Chapter 7 From Vertices to Fragments Objectives are: How your program are processed by the system that you are using, Learning.
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.
Introduction to Computer Graphics with WebGL
Computer Graphics CC416 Week 13 Clipping.
CS 551 / 645: Introductory Computer Graphics
Computer Graphics Shading in OpenGL
Concepts, Algorithms for line clipping
Clipping Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Computer Graphics Viewing
2D Viewing & Clipping 한신대 류승택
Concepts, algorithms for 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 Polygons 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
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
COMPUTER GRAPHICS Clipping
Presentation transcript:

Transformations contd.

Reflections y x =  x x x =  x y =  y y =  y Initial Reflection about y x =  x Initial Object x Reflection about origin x =  x y =  y Reflection about x y =  y

Matrix Representations Reflection about x Reflection about y Reflection about the Origin

Reflections Reflection about x axis: Reflection about y axis: Reflection about origin: It is rotation matrix R(θ) With θ = 180o

Reflection Reflection can be generalized to any reflection point in xy-plane. This reflection is the same as a 180o rotation in the xy plane using the reflection point as the pivot point. If we choose the reflection point as the diagonal line x=y, the reflection matrix is y y=x x

Reflection We can derive this matrix by concatenating a sequence of rotation and coordinate-axis reflection matrices. One possible sequence is: a) clockwise rotation of 45o (b) reflection about x-axis (c) counterclockwise rotation by 45o. To obtain a transformation matrix for reflection about the diagonal y = -x, we could concatenate matrices for the transformation sequence: a) clockwise rotation of 45o (b) reflection about y-axis (c) counterclockwise rotation by 45o. The resulting transformation is: Reflections about any line y=mx + c in the xy plane can be accomplished with a combination of translate-rotate-reflect transformations.

Shear A shearing affects an object in a particular direction (in 2D, it’s either in the x or in the y direction) A shear transformation in the x-direction (along x) shifts the points in the x-direction proportional to the y-coordinate. The y-coordinate of each point is unaffected.

Matrix Representations Shear along x Shear along x (homogeneous coordinate) Shear along y Shear along y (homogeneous coordinate)

Shearing A shear in the x direction would be as follows: x’ = x + h. y & y’ = y h is shear parameter The quantity h specifies what fraction of the y-coordinate should be added to the x-coordinate, and may be positive or negative -ve values for h shifts coordinate positions to the left

Shearing g =0, h=0.5 g=0.5, h=0.5 Shear by {g,h} Original points Transformed points g=0.5, h=0.5 Shear by {g,h} Original points Transformed points

We generate x-direction shears relative to other reference lines with With coordinate positions transformed as x’ = x + h(y- yref), y’ = y We generate y-direction shears relative to other reference lines (eg. x = xref) with x’ = x & y’ = h(x- xref) + y,

2D Viewing and Information Visualization

2D Viewing Pipeline From Computer Graphics by Hearn & Baker Modeling coordinates Construct World Coordinate Scene Using Model-Coordinate Transformations World coordinates Convert World Coordinates to Viewing Coordinates Viewing coordinates Transform Viewing Coordinates to Normalized Coordinates Normalized coordinates Map Normalized Coordinates to Device Coordinates Device coordinates From Computer Graphics by Hearn & Baker

Coordinate Systems Screen coordinates: the coordinate system used to address the screen (device coordinates) World coordinates: a user defined application specific coordinate system having its own units of measure, axis, origin etc. Window: the rectangular region of the world that is visible Viewport: the rectangular region of the screen space that is used to display the window.

2D rendering pipeline

CLIPPING

Point Clipping For a point (x,y) to be inside the clip rectangle:

Point Clipping For a point (x,y) to be inside the clip rectangle:

Cases for clipping lines Line Clipping Cases for clipping lines

Cases for clipping lines Line Clipping Cases for clipping lines

Cases for clipping lines Line Clipping Cases for clipping lines

Cases for clipping lines Line Clipping Cases for clipping lines

Cases for clipping lines Line Clipping Cases for clipping lines

Cases for clipping lines Line Clipping Cases for clipping lines

Cohen-Sutherland Clipping Basic Idea Encode the line endpoints Successively divide the line segments so that they are completely contained in the window or completely lies outside window Division occurs at the boundary of window Cohen-Sutherland Clipping Algorithm. To clip a line, we need to consider only its endpoints, not its infinitely many interior points. If both endpoints of a line lie inside the clip rectangle, the entire line lies inside the clip rectangle and 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, the line may or may not intersect with the clip rectangle, and we need to perform further calculations to determine whether there are any intersections. To do this, Cohen-Sutherland Clipping Algorithm first encode the line endpoints. Encoding is done by four criteria. So, four bit is need to each endpoint. Is the point Above the window? (Top) Is the point Under the window? (Bottom) Is the point on the Left side of the window? (Left) Is the point on the Right side of the window? (Right) 1 for True, 0 for False. After encoding, we may accept if the line is fully inside the window, Or discard if the line is fully outside the window. 1001 1000 1010 left 0001 0000 0010 right 0101 0100 0110 bottom top

Four Cases outcode1 = outcode2 = 0000 --> Accept all outcode1 OR outcode2 = 0000 --> Accept all outcode1 & outcode2 != 0000 --> Discard outcode1 != 0000 , outcode2 = 0000 (Vice versa) --> Shorten outcode1 & outcode2 = 0000 --> Discard or Shorten H D There can be four cases. First, see the line AB. Both endpoints can be encoded as 0000. So, it means that the line is fully inside the window, So Accept all. Second, see the line EF (0010 , 1010) Result of logical and operation is not 0000 (0010), and it means the it is fully outside the window, So Discard. Third, see the line CD(0000, 1010). This is the case of one endpoint inside the window and the other is not. In this case the line may be shorten. Forth, see the line GH and IJ (0001, 1000). We can not make a decision only with outcodes. Because it may be fully outside the window like line GH And it may have some intersections like line IJ. So in this case, the line may be discarded or shorten,. J F B G A C I E

Cohen-Sutherland Algorithm A line segment can be trivially accepted if the outcodes of both the endpoints are zero. A line segment can be trivially rejected if the logical AND of the outcodes of the endpoints is not zero. A key property of the outcode is that bits that are set in nonzero outcode correspond to edges crossed.

Cohen-Sutherland Algorithm The Cohen-Sutherland Line-Clipping Algorithm performs initial tests on a line to determine whether intersection calculations can be avoided. First, end-point pairs are checked for Trivial Acceptance. If the line cannot be trivially accepted, region checks are done for Trivial Rejection. If the line segment can be neither trivially accepted or rejected, it is divided into two segments at a clip edge, so that one segment can be trivially rejected. These three steps are performed iteratively until what remains can be trivially accepted or rejected.

Cohen-Sutherland Algorithm An Example

Cohen-Sutherland Algorithm An Example

Cohen-Sutherland Algorithm An Example

Cohen-Sutherland Algorithm An Example

For a line {(x1, y1), (x2, y2)} The y coordinate of the intersection point with the vertical boundary is y=y1+m(x-x1) Where x=xwmin or xwmax m=(y2-y1)/(x2-x1) Intersection with horizontal boundary x= x1+(y-y1)/m With y=ywmin or ywmax

Parametric Line-Clipping (1) This is fundamentally different (from Cohen-Sutherland algorithm) and generally more efficient algorithm was originally published by Cyrus and Beck. (2) Liang and Barsky later independently developed a more efficient algorithm that is especially fast in the special cases of upright 2D and 3D clipping regions.They also introduced more efficient trivial rejection tests for general clip regions.

yo

Liang-Barsky Clipping The Liang-Barsky two-dimensional line clipping algorithm uses the parametric form of a line and the clipping window to determine the clipping coordinates of lines intersecting the clipping volume. This algorithm is significantly more efficient than Cohen-Sutherland clipping.

Liang-Barsky Clipping To summarize, the Liang-Barsky clipping algorithm consists of the following steps: 1. Define all line segments in parametric form. 2. Set the minimum and maximum values for u (umin = 0 and umax = 1). 3. Calculate all the u values located between umin and umax. 4. Determine whether the arbitrary values of each parametric line lie within the clipping window. a. If the line intersects, shorten the line segment via a floating-point division. b. If the line doesn’t intersect the clipping window, discard it. 5. Display all clipped line segments.

Polygon clipping

Original Polygon Clip Left Clip Right Clip Bottom Clip Top No Points Saved (c) Save P (a) Save I (b) Save I, P (d)

Sutherland-Hodgeman Polygon Clipping

Window Window (a) (b)

Before Clipping After Clipping

Clipping Polygons Extending two-dimensional line clipping to polygons involves the clipping of polygons against a clipping rectangle or against other polygons, as is the case with hidden surface removal. Polygon clipping algorithms are derived from simple line clipping algorithms. We can thus clip a polygon against the edges of a clipping rectangle. There is, however, a problem with this approach clipping concave polygons can result in several additional polygons as shown in Figure 12-19.

Clipping Polygons

Clipping Polygons The illustrated problem is not encountered when working with convex polygons. The only solution to this problem is to consider the clipped region as a single polygon or to tessellate (divide) the polygon into a number of convex polygons

Clipping Polygons

Sutherland-Hodgman Polygon Clipping Input each edge (vertex pair) successively. Output is a new list of vertices. Each edge goes through 4 clippers. The rule for each edge for each clipper is: If first input vertex is outside, and second is inside, output the intersection and the second vertex If first both input vertices are inside, then just output second vertex If first input vertex is inside, and second is outside, output is the intersection If both vertices are outside, output is nothing

Sutherland-Hodgman Polygon Clipping: Four possible scenarios at each clipper outside inside outside inside outside inside outside inside v2 v2 v2 v2 v1’ v1’ v1 v1 v1 v1 Outside to inside: Output: v1’ and v2 Inside to inside: Output: v2 Inside to outside: Output: v1’ Outside to outside: Output: nothing

Sutherland-Hodgeman Algorithm: Combination of the 4 Passes

Sutherland-Hodgeman Algorithm:

Polygon Clipping Example

Text Clipping (1)

Text Clipping (2)

Text Clipping (3)