CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai

Slides:



Advertisements
Similar presentations
Clipping Covers chapter 10 of Computer Graphics and Virtual Environments (Slater, Steed and Chrysanthou) . See ©Yiorgos Chrysanthou.
Advertisements

9.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 9 – Clipping.
Computer Graphics Inf4/MSc 1 Computer Graphics Lecture 7 Scanline algorithm and polygon clipping Taku Komura.
Rezanje črt in poligonov. World window & viewport window viewport screen window world window.
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 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
Computer Graphics Lecture 8 Arbitrary Viewing II: More Projection, Clipping and Mathematics of 3D Viewing.
CS 551 / 645: Introductory Computer Graphics Clipping Lines and Polygons.
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.
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.
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 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.
CSCE 441: Computer Graphics Scan Conversion of Polygons
1 CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Clipping.
Graphics Pipeline Clipping CMSC 435/634. Graphics Pipeline Object-order approach to rendering Sequence of operations – Vertex processing – Transforms.
1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.
2-Dimension Viewing and Clipping
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.
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.
What are Computer Graphics Basically anything that is on you Monitor – This includes the text that you will see Text isn’t Advanced Graphics But…. Understanding.
1Computer Graphics Implementation 1 Lecture 15 John Shearer Culture Lab – space 2
2D Viewing.
Graphics Graphics & Graphical Programming Lecture 23 - Viewing & Clipping.
1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.
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
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Computer Graphics Viewing
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
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.
© University of Wisconsin, CS559 Fall 2004
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:

CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai

Review: Clipping Points Given a point (x, y) and clipping window (xmin, ymin), (xmax, ymax), determine if the point should be drawn (xmax,ymax) (x,y) xmin=<x<=xmax? (xmin,ymin) ymin=<y<=ymax?

Review: Clipping Lines

Review: Clipping Lines

Review Clipping Simple line clipping algorithm - compute intersection points - clip the line segment between the outside point and intersection point Cohen-Sutherland - region coding (9 regions, 4bits) - best used when trivial acceptance and rejection is possible for most lines Liang-Barsky - computation of t-intersections is cheap (only one division) - computation of (x,y) clip points is only done once - algorithm doesn’t consider trivial accepts/rejects - best when many lines must be clipped

Clipping Polygons Clipping polygons is more complex than clipping the individual lines - Input: polygon

Clipping Polygons Clipping polygons is more complex than clipping the individual lines - Input: polygon - Output: original polygon, new polygon, or nothing

Why Is Polygon Clipping Hard? What happens to a triangle during clipping? - possible outcomes: triangle->triangle triangle->quad triangle->5-gon

Why Is Polygon Clipping Hard? What happens to a triangle during clipping? - possible outcomes: triangle->triangle triangle->quad triangle->5-gon How many sides a clipped triangle might have? 9 9

How Many Sides? Seven

Why Is Clipping Hard? A really tough case Concave polygon -> Multiple polygons

Why Is Clipping Hard? A really tough case

Outline Sutherland-Hodgman Clipping - convex polygons Weiler-Atherton Algorithm - general polygons Required readings - HB 8-8

Any idea? Clipping polygon edges? 14 14

Any idea? Clipping polygon edges?

Any idea? Clipping polygon edges? 16 16

Any idea? Clipping polygon edges? 17 17

Any idea? Clipping polygon edges? Unconnected set of lines!

Any idea? Clipping polygon edges? Wrong even with connected line segments! 19 19

Sutherland-Hodgman Clipping Basic idea: similar to line clipping

Sutherland-Hodgman Clipping Basic idea: similar to line clipping - consider each edge of the view window individually - clip the polygon against the view window edge’s equation 21 21

Sutherland-Hodgman Clipping Basic idea: - consider each edge of the view window individually - clip the polygon against the view window edge’s equation

Sutherland-Hodgman Clipping Basic idea: - consider each edge of the view window individually - clip the polygon against the view window edge’s equation

Sutherland-Hodgman Clipping Basic idea: - consider each edge of the view window individually - clip the polygon against the view window edge’s equation

Sutherland-Hodgman Clipping Basic idea: - consider each edge of the view window individually - clip the polygon against the view window edge’s equation

Sutherland-Hodgman Clipping Basic idea: - consider each edge of the view window individually - clip the polygon against the view window edge’s equation

Sutherland-Hodgman Clipping Basic idea: - consider each edge of the view window individually - clip the polygon against the view window edge’s equation

Sutherland-Hodgman Clipping Basic idea: - consider each edge of the view window individually - clip the polygon against the view window edge’s equation

Sutherland-Hodgman Clipping Basic idea: - consider each edge of the view window individually - clip the polygon against the view window edge’s equation

Sutherland-Hodgman Clipping Basic idea: - consider each edge of the view window individually - clip the polygon against the view window edge’s equation - after doing all edges, the polygon is fully clipped

Sutherland-Hodgman Clipping Input/output for algorithm: - input: list of polygon vertices in order {abcdef} a f b e d c

Sutherland-Hodgman 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 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) - exactly what expect from the clipping operation against each edge!

Sutherland-Hodgman Clipping How to clip the polygon against the window edge? - Go around polygon one vertex (i.e. polygon edge) at a time - Current vertex has position E - Previous vertex had position S, and it has been added to the output if appropriate a f b e d {abcdef} c

Sutherland-Hodgman Clipping How to clip the polygon against the window edge? - Go around polygon one vertex (i.e. polygon edge) at a time - Current vertex has position E - Previous vertex had position S, and it has been added to the output if appropriate a f b e d {abcdef} c

Sutherland-Hodgman Clipping How to clip the polygon against the window edge? - Go around polygon one vertex (i.e. polygon edge) at a time - Current vertex has position E - Previous vertex had position S, and it has been added to the output if appropriate a f b e d {abcdef} c Need to determine output vertices for each polygon line! 36 36

Sutherland-Hodgman Clipping Polygon edge from S to E takes one of four cases: inside outside inside outside inside outside inside outside E S E S E S E S

Sutherland-Hodgman Clipping Polygon edge from S to E takes one of four cases: inside outside inside outside inside outside inside outside E S E S E S E S ? output ? output ? output ? output 38 38

Sutherland-Hodgman Clipping Polygon edge from S to E takes one of four cases: inside outside inside outside inside outside inside outside E S E S E S E S I output E output E output I output no output 39 39

Sutherland-Hodgman Clipping Four cases: S inside plane and E inside plane Add E to output Note: S has already been added S inside plane and E outside plane Find intersection point I Add I to output S outside plane and E outside plane Add nothing S outside plane and E inside plane Add I to output, followed by E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E Input vertices after clipping against left edge after clipping against right edge after clipping against bottom edge after clipping all the window edges

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E b

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E Possible error for non-convex polygons

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E Possible error for non-convex polygons #1: split concave polygon into two or more convex polygons (see Section 4-7) #2: use more general polygon clipper. 85 85

Sutherland-Hodgman Algorithm How to deal with more general clipping boundaries (convex clip polygons) 86 86

Sutherland-Hodgman Algorithm How to deal with more general clipping boundaries (convex clip polygons) 87 87

Sutherland-Hodgman Algorithm Work for convex input polygons Work for convex clipping boundaries Easy to pipeline for parallel processing Polygon from one boundary does not have to be completed before next boundary starts Leads to substantial performance gains 88 88

Weiler-Atherton Algorithm + Work for general input polygons (concave & convex) + Handles a clipping window with any polygon shape (concave & convex) + Can be extended to 3D - Not as efficient as Sutherland-Hodgman - Not easy to parallelize

Weiler-Atherton Algorithm Key idea: tracing around the perimeter of the fill polygon searching for the borders that enclose a clipped fill region.

Weiler-Atherton Algorithm Advantage: multiple regions can be identified and displayed as separate, unconnected polygons. 91 91

Weiler-Atherton Algorithm Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order 92 92

Weiler-Atherton Algorithm

Weiler-Atherton Algorithm Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

Weiler-Atherton Algorithm

Weiler-Atherton Algorithm Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

Weiler-Atherton Algorithm

Weiler-Atherton Algorithm

Weiler-Atherton Algorithm Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

Weiler-Atherton Algorithm

Weiler-Atherton Algorithm Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

Weiler-Atherton Algorithm Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

Weiler-Atherton Algorithm Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

Weiler-Atherton Algorithm Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

Weiler-Atherton Algorithm

Weiler-Atherton Algorithm Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

Weiler-Atherton Algorithm

Weiler-Atherton Algorithm Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

Weiler-Atherton Algorithm

Weiler-Atherton Algorithm

Weiler-Atherton Algorithm

Weiler-Atherton Algorithm

Weiler-Atherton Algorithm

Weiler-Atherton Algorithm Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

Weiler-Atherton Algorithm

Weiler-Atherton Algorithm Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

Weiler-Atherton Algorithm Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

Weiler-Atherton Algorithm Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

Weiler-Atherton Algorithm

Weiler-Atherton Algorithm Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

Weiler-Atherton Algorithm

Weiler-Atherton Algorithm Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

Weiler-Atherton Algorithm

Weiler-Atherton Algorithm

Nonlinear Clipping-window Boundaries Approximate the boundaries with straight-line sections. Use the existing polygon clipping algorithms for clipping against a general polygon-shaped clipping window.

OpenGL Geometric Primitives All geometric primitives are specified by vertices GL_LINE_STRIP GL_LINE_LOOP GL_POLYGON GL_LINES GL_POINTS GL_TRIANGLE_STRIP GL_QUAD_STRIP GL_TRIANGLES GL_QUADS GL_TRIANGLE_FAN

Summary Polygon drawing Polygon clipping You need to implement both algorithms in assignment #3.

Next Lecture 2D transformations y y x x y x

Next Lecture 2D transformations 129 129