Clipping Lines Lecture 7 Wed, Sep 10, 2003. The Graphics Pipeline From time to time we will discuss the graphics pipeline. The graphics pipeline is the.

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 Inf4/MSc 1 Computer Graphics Lecture 7 Scanline algorithm and polygon clipping Taku Komura.
Okay, you have learned … OpenGL drawing Viewport and World Window setup main() { glViewport(0,0,300,200); glMatrixMode(GL_PROJECTION); glLoadIndentity();
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.
Okay, you have learned … OpenGL drawing Viewport and World Window setup main() { glViewport(0,0,300,200); glMatrixMode(GL_PROJECTION); glLoadIndentity();
CHAPTER 12 Height Maps, Hidden Surface Removal, Clipping and Level of Detail Algorithms © 2008 Cengage Learning EMEA.
Chi-Cheng Lin, Winona State University CS430 Computer Graphics Cohen-Sutherland Line Clipping Algorithm.
Computer Graphics, KKU. Lecture 81 Clipping on a Raster Display.
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)
Two-Dimensional Viewing Jehee Lee Seoul National University.
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)
CGPage: 1 東吳資訊科學 江清水 The process of clipping decides which part, if any, of a primitive lies inside the window. The algorithms used for line clipping can.
Introduction to Computer Graphics Chapter 6 – 2D Viewing Pt 2 1.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Interpolation Clipping.
1 Computer Graphics Chapter 4 2D Viewing Algorithms.
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.
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.
CS 480/680 Computer Graphics Shading in OpenGL Dr. Frederick C Harris, Jr. Fall 2013.
Clipping CSCI 440 textbook section Starter Question How do we clip these lines? X=-5 Y=-5 Y=5 X=5 [0,0] [3,3] [7,-3] [0,-3] formula from wikipedia.
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
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.
Clipping Polygons Dr Nicolas Holzschuch University of Cape Town Modified by Longin Jan Latecki
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
Transformations contd.
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
2D Viewing & Clipping 한신대 류승택
Concepts, algorithms for clipping
Implementation I Ed Angel
Graphics Pipeline Clipping
WINDOWING AND CLIPPING
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
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.
CS U540 Computer Graphics Prof. Harriet Fell Spring 2007
Clipping Clipping Sutherland-Hodgman Clipping
CS U540 Computer Graphics Prof. Harriet Fell Spring 2007
Clipping University of British Columbia CPSC 314 Computer Graphics
Implementation I Ed Angel Professor Emeritus of Computer Science
CS U540 Computer Graphics Prof. Harriet Fell Spring 2007
Presentation transcript:

Clipping Lines Lecture 7 Wed, Sep 10, 2003

The Graphics Pipeline From time to time we will discuss the graphics pipeline. The graphics pipeline is the sequence of operations that are performed on primitives to render them on the screen as collections of colored pixels. We have discussed the framebuffer. Now we will discuss 2-dimensional clipping of lines.

Clipping Any object that is not entirely within the viewport must be clipped. That is, the part that is outside the viewport must be eliminated before the object is drawn. The graphics pipeline, does this “automatically.” Why is it necessary to clip?

Clipping Lines If a line is partially in the viewport, then we need to recalculate its endpoints. In general, there are four possible cases. The line is entirely within the viewport. The line is entirely outside the viewport. One endpoint is in and the other is out. Both endpoints are out, but the middle part is in.

Clipping Lines Before clipping F A B C D E G H

Clipping Lines After clipping F A B E G H F' G' H' C D

The Cohen-Sutherland Clipping Algorithm Let the x-coordinates of the window boundaries be xmin and xmax and let the y-coordinates be ymin and ymax. xmin xmax ymin ymax

The Cohen-Sutherland Clipping Algorithm For each endpoint p of a line segment we will define a codeword c 3 c 2 c 1 c 0 consisting of 4 true/false values. c 3 = true, if p is left of the window. c 2 = true, if p is above the window. c 1 = true, if p is right of the window. c 0 = true, if p is below the window. How many different values are possible for a codeword?

The Cohen-Sutherland Clipping Algorithm How many different combinations of values are possible for the codewords of the two endpoints of a segment? How do we compute a codeword?

The Cohen-Sutherland Clipping Algorithm Consider the vertical edge x = xmin. (You can do the other edges.) Compare the x-coordinate of p to xmin. If it is less, then “set” bit 3 of the codeword. if (p.x < xmin) c = 1 << 3;

The Cohen-Sutherland Clipping Algorithm After the codewords for both endpoints are computed, we divide the possibilities into three cases: Trivial accept – both codewords are FFFF. Trivial reject – both codewords have T in the same position. Indeterminate so far – Investigate further.

The Cohen-Sutherland Clipping Algorithm What is the quickest way to separate the cases? Use bitwise “and” and “or.” If ((codeword1 | codeword2) == 0) then we trivially accept. Why? If ((codeword1 & codeword2) != 0) then we trivially reject. Why?

The Cohen-Sutherland Clipping Algorithm What about the third case? We clip against each edge of the window, in sequence, as necessary. After clipping against an edge, we may test again for trivial acceptance or trivial rejection before moving on to the next edge.

The Cohen-Sutherland Clipping Algorithm

clip

The Cohen-Sutherland Clipping Algorithm clip

The Cohen-Sutherland Clipping Algorithm clip

The Cohen-Sutherland Clipping Algorithm clip

The Cohen-Sutherland Clipping Algorithm

This raises some questions? What is the worst case? What is the best case? How do we decide whether to clip against a particular edge? If we do clip, how to we determine the new endpoint?

The Cohen-Sutherland Clipping Algorithm Consider again the vertical edge x = xmin. (You can do the other edges.) Compute codeword1 ^ codeword2. This shows where they disagree. Why? “And” this with (1 << 3). If result = 1, then clip. Else do not clip.

The Cohen-Sutherland Clipping Algorithm If we clip, then the new point will be on the line x = xmin. So its x-coordinate will be xmin. We must calculate its y-coordinate.

The Cohen-Sutherland Clipping Algorithm p q r x = xmin

The Cohen-Sutherland Clipping Algorithm p r x = xmin q

The Cohen-Sutherland Clipping Algorithm p r xmin – p.xq.x – p.x q.y – p.y r.y – p.y x = xmin q

The Cohen-Sutherland Clipping Algorithm Then (r.y – p.y)/(xmin – p.x) = (q.y – p.y)/(q.x – p.x) So r.y = p.y + (xmin – p.x)(q.y – p.y)/(q.x – p.x)

The Cohen-Sutherland Clipping Algorithm This used to be done in software. Now it is done in hardware, in the graphics pipeline. Should it be done before or after the line is rasterized? We will discuss clipping polygons and clipping in 3D later.

Example: Clip a Line LineClipper.cpp