WINDOWING AND CLIPPING

Slides:



Advertisements
Similar presentations
CGPage: 1 We can define a window as a rectangular region of the world coordinate space, and the viewport as a rectangular region of the device coordinate.
Advertisements

Computer Graphics 4: Viewing In 2D
Rezanje črt in poligonov. World window & viewport window viewport screen window world window.
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.
Course Website: Computer Graphics 4: Viewing In 2D.
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.
CHAPTER 7 2D VIEWING CGMB214: Introduction to Computer Graphics.
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
Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.
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.
2-Dimension Viewing 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.
Windows, Viewports, and Clipping
Introduction to Computer Graphics Chapter 6 – 2D Viewing Pt 1 1.
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
CS COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,
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.
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.
Transformations contd.
CS 551 / 645: Introductory Computer Graphics
Computer Graphics Shading in OpenGL
Clipping Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006
Two-Dimensional Viewing
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
2D Viewing & Clipping 한신대 류승택
Concepts, algorithms for clipping
3D Clipping.
Implementation I Ed Angel
Graphics Pipeline Clipping
3D Rendering Pipeline Hidden Surface Removal 3D Primitives
o عَلَّمَهُ الْبَيَانَ
Computer Graphics : Viewing In 2D
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
Joshua Barczak CMSC 435 UMBC
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.
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:

WINDOWING AND CLIPPING

Points to cover Clipping Line clipping Polygon clipping Normalized transformation Viewing transformation

Clipping Clipping refers to the removal of part of a scene. Any procedure which identifies that portion of a picture which is either inside or outside a region is referred to as a clipping algorithm or clipping. The region against which an object is to be clipped is called clipping window. Usually it is rectangular in shape. Window : it is the selected area of the picture. Following are the graphics primitives that we are going to study under clipping: point clipping line clipping polygon clipping

Point Clipping Display P = (x, y) if xwmin <= x < = xwmax ywmin < = y <= ywmax

Line Clipping Before clipping After clipping

Line Clipping

COHEN SUTHERLAND LINE CLIPPING ALGORITHM

Cohen-Sutherland: World Division 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 Legend

Cohen-Sutherland Algorithm (Xmax,ymax) (Xmin,ymin) Region outcodes

Cohen-Sutherland: Labelling Every end-point of the line is labelled with the appropriate region code Three cases : Case1: Lines inside the window : not clipped Case2: lines outside the window : Take AND operation of the outcodes of the end points of the line. If answer of AND operation is non zero means line is outside the window and hence discard those lines. Case3 : lines partially inside the window :Lines for which the AND operation of the end coordinates is ZERO . These are identified as partially visible lines.

Case3: Other Lines These lines are processed as follows: Find the intersection of those lines with the edges of window. We can use the region codes to determine which window boundaries should be considered for intersection.eg: region code 1000 then line intersects with TOP boundary. Find intersection with that boundary only. Check other end of the line to get other intersection. Draw line between calculated intersection. Intersections are calculated as y coordinate of the intersection point with a vertical boundary can be calculated as y = y1 + m(x – x1), x = xmin or xmax and m = ( y2 – y1) / ( x2 – x1) x coordinate of the intersection point with a horizontal boundary can be calculated as x = x1 + (y – y1) / m , y = ymin or ymax and m = ( y2 – y1) / ( x2 – x1)

Algorithm Read two endpoints of the line say P1 (x1,y1) and p2(x2,y2) Read two corners of the window (left –top ) and (right-bottom) say (Wx1,Wy1) and (Wx2, Wy2) Assign the region codes to the end co-or of P1. Set Bit 1 – if (x<xwmin) Set Bit 2 – if (x >xwmax) Set Bit 3 – if (y<ywmin) Set Bit 4 – if (y<ywmax) Apply visibility check on the line.

Algorithm Conti… 5. If line is partially visible then- If region codes for the both end points are non-zero , find intersection points p1’ and p2’ with boundary edges by checking the region codes. If region code for any one end point is non-zero then find intersection point p1’ or p2’ with the boundary edge. 6. Divide the line segments considering the intersection points. 7. Draw the line segment 8. Stop.

Polygon Clipping Issues – Edges of polygon need to be tested against clipping rectangle May need to add new edges Edges discarded or divided Multiple polygons can result from a single polygon

Sutherland-Hodgman Polygon Clipping Algorithm

Sutherland-Hodgman Polygon 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. Original Area Clip Left Clip Right Clip Top Clip Bottom

Sutherland-Hodgeman Clipping Input/output for algorithm: Input: list of polygon vertices in order. Output: list of clipped polygon vertices consisting of old vertices (maybe) and new vertices (maybe) Sutherland-Hodgman does four tests on every edge of the polygon: Inside – Inside ( I-I) Inside –Outside (I-O) Outside –Outside (O-O) Outside-Inside(O-I) Output co-ordinate list is created by doing these tests on every edge of poly.

Sutherland-Hodgeman Clipping Edge from S to P takes one of four cases: inside outside s p Save p inside outside s p Save I inside outside s p Save nothing inside outside s p Save I and P I

Sutherland-Hodgeman Clipping Four cases: S inside plane and P inside plane Save p in the output-List S inside plane and P outside plane Find intersection point i Save i in the output-List S outside plane and P outside plane Save nothing S outside plane and P inside plane Save i in the output-List, followed by P

Algorithhm Read polygon vertices Read window coordinates For every edge of window do Check every edge of the polygon to do 4 tests Save the resultant vertices and the intersections in the output list. The resultant set of vertices is then sent for checking against next boundary. Draw polygon using output-list. Stop.

Generalized clipping We have used four clipping routines; one for each boundary. But these routines are identical. They differ only in their tests for determining whether a point is inside or outside the boundary. Can we make it general ?? It is possible to write one single routine and pass information about boundary as parameter. This change allows to clip along any line(not just horizontal or vertical boundaries).

Such general routine can be then used to clip along an arbitrary convex polygon. Fig :A window with 6 clipping boundaries

normalized coordinates Different display devices have different screen sizes and resolutions, which is measured in pixels. Picture on a screen with high resolution appears small in size, where as same pic on screen with less resolution appears big in size. To avoid this we make our program device independent. So picture coordinates have to be represented in some units other than pixels. Device independent units are called as Normalized device coordinates. In this screen measures 1 unit wide and 1 unit length.

Transformation to normalized coordinates Interpreter is used to convert normalized co-ordinates into device co- ordinates. A simple linear formula is used for this. x = xn * Xw y = yn * Yw Where : x= actual device x co-or y= actual device y co-or xn = Normalized x co-or yn = Normalized y co-or Xw =Width of actual screen in Pixels Yw = Height of actual screen in Pixels

Viewing Transformation An image is defined in a world coordinate system, WCS i.e. Using Cartesian coordinate system. World Coordinate system: application-specific Example: drawing dimensions may be in meters, km, feet, etc. When picture is represented on display device,it is measured in physical device coordinate system(PDCS) corresponding to the display device. Viewing Transformation: Mapping of coordinates is acheived with the use of coordinate transformation i.e. Maps picture coordinates in the WCS to display coordinates in PDCS.

WCS is infinite in extent and device display area is finite. A world coordinate area selected for display is called a window. ( defines what to display) An area on a device to which a window is mapped is called viewport. ( defines where to display.) Clipping Window Viewport

Window to viewport coordinate transformation Would like to: Specify drawing in world coordinates Display in screen coordinates Need some sort of mapping Called Window-to-viewport mapping Basic W-to-V mapping steps: Define a world window Define a viewport Compute a mapping from window to viewport

Window to viewport coordinate transformation Fig shows mapping of object from window to viewport. A point at (xw , yw ) in window is mapped into position (xv , yv ) in the associative viewport.

Window to viewport coordinate transformation To maintain relative replacement in viewport as in window we require, Solving these equations for viewport position xv = xvmin + ( xw – xwmin ) sx yv = yvmin + ( yw – ywmin ) sy Where Scaling factors:

Window to viewport coordinate transformation Mapping of window to viewport require following transformations Scaling using fixed point position of (xwmin , ywmin ) that scales the window area to the size of viewport area. Translation : translating scaled window area to the position of viewport area. Workstation Transformation: Transformation of object description from normalized coordinates to device coordinates. It is accomplished by selecting a window area in normalized space and viewport area in coordinates of display device.

Window to viewport coordinate transformation

Window to viewport coordinate transformation  

3d viewing transformation