Computer Graphics Clipping.

Slides:



Advertisements
Similar presentations
Computer Graphics Inf4/MSc 1 Computer Graphics Lecture 7 Scanline algorithm and polygon clipping Taku Komura.
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.
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.
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
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)
Computer Graphics Viewing.
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 2007 Tamara Munzner Clipping II, Hidden Surfaces.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Interpolation Clipping.
Vertices and Fragments I CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
Texturing, Clipping Week 9, Mon 27 Oct 2003
1 CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai.
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.
UBI 516 Advanced Computer Graphics Two Dimensional Viewing ( Chapter 6 ) Aydın Öztürk Two Dimensional.
2-Dimension Viewing and Clipping
CS 551 / 645: Introductory Computer Graphics
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
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
Computer Graphics Viewing. 2 of 30 Viewing in 2D Window in world coordinates. 45  250  Viewport in Device coords 250 x 250 Pixels.
Computer Graphics Lecture 14 CLIPPING I Taqdees A. Siddiqi
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
Clipping Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
3D rezanje 3D Clipping view frustrum clipping planes clipped.
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 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
Segment Clipping Simple algorithm. For each segment compute the intersection with the four sides of the rectangle, and then determine which sub-segment.
3D rezanje 3D Clipping view frustrum clipping planes clipped.
CS U540 Computer Graphics Prof. Harriet Fell Spring 2007
Clipping Polygons Dr. Scott Schaefer.
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.
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
COMPUTER GRAPHICS Clipping
Presentation transcript:

Computer Graphics Clipping

Clipping Analytically calculating the portions of primitives within the viewport

Why Clip? Bad idea to rasterize outside of framebuffer bounds Also, don’t waste time scan converting pixels outside window

Clipping The naïve approach to clipping lines: for each line segment for each edge of viewport find intersection point pick “nearest” point if anything is left, draw it What do we mean by “nearest”? How can we optimize this? A B C D

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.

Trivial Rejects How can we know a line is outside viewport? A: if both endpoints on wrong side of same edge, can trivially reject line

Clipping Lines To Viewport Combining trivial accepts/rejects Trivially accept lines with both endpoints inside all edges of the viewport Trivially reject lines with both endpoints outside the same edge of the viewport Otherwise, reduce to trivial cases by splitting into two segments

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

Cohen-Sutherland Line Clipping Assign an outcode to each vertex of line to test Bit 1 = sign bit of (ymax – y) If both outcodes = 0, trivial accept bitwise OR bitwise AND vertex outcodes together if result  0, trivial reject

Cohen-Sutherland Line Clipping If line cannot be trivially accepted or rejected, subdivide so that one or both segments can be discarded Pick an edge that the line crosses (how?) Intersect line with edge (how?) Discard portion on wrong side of edge and assign outcode to new vertex Apply trivial accept/reject tests; repeat if necessary

Cohen-Sutherland Line Clipping If line cannot be trivially accepted or rejected, subdivide so that one or both segments can be discarded Pick an edge that the line crosses Check against edges in same order each time For example: top, bottom, right, left E D C B A

Cohen-Sutherland Line Clipping Intersect line with edge (how?) A B D E C

Cohen-Sutherland Line Clipping Discard portion on wrong side of edge and assign outcode to new vertex Apply trivial accept/reject tests and repeat if necessary D C B A

Viewport Intersection Code (x1, y1), (x2, y2) intersect with vertical edge at xright yintersect = y1 + m(xright – x1), m=(y2-y1)/(x2-x1) (x1, y1), (x2, y2) intersect with horizontal edge at ybottom xintersect = x1 + (ybottom – y1)/m, m=(y2-y1)/(x2-x1)

Cohen-Sutherland Review Use opcodes to quickly eliminate/include lines Best algorithm when trivial accepts/rejects are common Must compute viewport clipping of remaining lines Non-trivial clipping cost Redundant clipping of some lines More efficient algorithms exist

Clipping Polygons Clipping polygons is more complex than clipping the individual lines Input: polygon Output: original polygon, new polygon, or nothing When can we trivially accept/reject a polygon as opposed to the line segments that make up the polygon?

How many sides can a clipped triangle have? Why Is Clipping Hard? What happens to a triangle during clipping? Possible outcomes: triangle  quad triangle  triangle triangle  5-gon How many sides can a clipped triangle have?

How many sides? Seven…

Why Is Clipping Hard? A really tough case:

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

Sutherland-Hodgeman Clipping Basic idea: Consider each edge of the viewport individually Clip the polygon against the viewport edge’s equation

Sutherland-Hodgeman Clipping Basic idea: Consider each edge of the viewport individually Clip the polygon against the edge equation After doing all edges, the polygon is fully clipped

Sutherland-Hodgeman Clipping Basic idea: Consider each edge of the viewport individually Clip the polygon against the edge equation After doing all edges, the polygon is fully clipped

Sutherland-Hodgeman Clipping Basic idea: Consider each edge of the viewport individually Clip the polygon against the edge equation After doing all edges, the polygon is fully clipped

Sutherland-Hodgeman Clipping Basic idea: Consider each edge of the viewport individually Clip the polygon against the edge equation After doing all edges, the polygon is fully clipped

Sutherland-Hodgeman Clipping Basic idea: Consider each edge of the viewport individually Clip the polygon against the edge equation After doing all edges, the polygon is fully clipped

Sutherland-Hodgeman Clipping Basic idea: Consider each edge of the viewport individually Clip the polygon against the edge equation After doing all edges, the polygon is fully clipped

Sutherland-Hodgeman Clipping Basic idea: Consider each edge of the viewport individually Clip the polygon against the edge equation After doing all edges, the polygon is fully clipped

Sutherland-Hodgeman Clipping Basic idea: Consider each edge of the viewport individually Clip the polygon against the edge equation After doing all edges, the polygon is fully clipped

Sutherland-Hodgeman Clipping: The Algorithm Basic idea: Consider each edge of the viewport individually Clip the polygon against the edge equation After doing all edges, the polygon is fully clipped

Sutherland-Hodgeman Clipping Input/output for algorithm: Input: list of polygon vertices in order Output: list of clipped poygon vertices consisting of old vertices (maybe) and new vertices (maybe) Note: this is exactly what we expect from the clipping operation against each edge

Sutherland-Hodgeman Clipping Sutherland-Hodgman basic routine: Go around polygon one vertex at a time Current vertex has position p Previous vertex had position s, and it has been added to the output if appropriate

Sutherland-Hodgeman Clipping Edge from s to p takes one of four cases: (Orange line can be a line or a plane) inside outside s p p output inside outside s p i output inside outside s p no output inside outside s p i output p output

Sutherland-Hodgeman Clipping Four cases: s inside plane and p inside plane Add p to output Note: s has already been added s inside plane and p outside plane Find intersection point i Add i to output s outside plane and p outside plane Add nothing s outside plane and p inside plane Add i to output, followed by p