Binghamton University. EngiNet. Thomas J. Watson. School of Engineering and Applied Science. Computer Graphics. State University of New York.

Similar documents
Viewing Transformation. Clipping. 2-D Viewing Transformation

Computer Graphics (CS 543) Lecture 9 (Part 2): Clipping. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Clipping Lines. Dr. Scott Schaefer

2D Image Synthesis. 2D image synthesis. Raster graphics systems. Modeling transformation. Vectorization. u x u y 0. o x o y 1

3D Rendering Pipeline (for direct illumination)

General Hidden Surface Removal Algorithms. Binghamton University. EngiNet. Thomas J. Watson. School of Engineering and Applied Science CS 460/560

Chapter 8: Implementation- Clipping and Rasterization

Two-Dimensional Viewing. Chapter 6

CS123 INTRODUCTION TO COMPUTER GRAPHICS. Clipping. Concepts, Algorithms for line clipping. 1 of 16. Andries van Dam. Clipping - 10/12/17

CS602 MCQ,s for midterm paper with reference solved by Shahid

Part IV. 2D Clipping

Computer Graphics: Two Dimensional Viewing

MODULE - 9. Subject: Computer Science. Module: Line Clipping. Module No: CS/CGV/9

Computer Graphics. The Two-Dimensional Viewing. Somsak Walairacht, Computer Engineering, KMITL

Windowing And Clipping (14 Marks)

Examples. Clipping. The Rendering Pipeline. View Frustum. Normalization. How it is done. Types of operations. Removing what is not seen on the screen

Clipping & Culling. Lecture 11 Spring Trivial Rejection Outcode Clipping Plane-at-a-time Clipping Backface Culling

Clipping and Scan Conversion

Part 3: 2D Transformation

Scan Converting Text. Attributes of Output Primitives. CS 460/560 Computer Graphics. Binghamton University. EngiNet. Thomas J.

Text in OpenGL and Windows. Computer Graphics Attributes. Computer Graphics. Binghamton University. EngiNet. Thomas J. Watson

Last class. A vertex (w x, w y, w z, w) - clipping is in the - windowing and viewport normalized view volume if: - scan conversion/ rasterization

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI

Cs602-computer graphics MCQS MIDTERM EXAMINATION SOLVED BY ~ LIBRIANSMINE ~

Set the Viewport. Set the Viewport Clipping. Set the Viewport. Set the Viewport. Set the Viewport. Resizing the Viewport W = H

Clipping Algorithms; 8-5. Computer Graphics. Spring CS4815

2D Viewing. Viewing Pipeline: Window-Viewport Transf.

CSCI 4620/8626. Computer Graphics Clipping Algorithms (Chapter 8-5 )

Computer Graphics Viewing Objective

Computer Graphics Geometry and Transform

Computer Graphics: 7-Polygon Rasterization, Clipping

COMPUTATIONAL GEOMETRY

From Vertices To Fragments-1

Clipping Points Consider a clip window which is rectangular in shape. P(x, y) is a point to be displayed.

CS602- Computer Graphics Solved MCQS From Midterm Papers. MIDTERM EXAMINATION Spring 2013 CS602- Computer Graphics

Realtime 3D Computer Graphics Virtual Reality

521493S Computer Graphics Exercise 1 (Chapters 1-3)

CS184 : Foundations of Computer Graphics Professor David Forsyth Final Examination

UNIT 2. Translation/ Scaling/ Rotation. Unit-02/Lecture-01

Introduction to 3D Graphics with OpenGL. Z-Buffer Hidden Surface Removal. Binghamton University. EngiNet. Thomas J. Watson

From 3D World to 2D Screen. Hendrik Speleers

CS184 : Foundations of Computer Graphics Professor David Forsyth Final Examination (Total: 100 marks)

15. Clipping. Projection Transformation. Projection Matrix. Perspective Division

Computer Graphics Course Notes

CS475m - Computer Graphics. Lecture 1 : Rasterization Basics

Computer Graphics Geometry and Transform

Computer Graphics. Brian Wyvill. Clipping. cpsc/enel P 1 H K AB AC DE FG HI JK

Unit 3 Transformations and Clipping

Computer Graphics. - Clipping - Philipp Slusallek & Stefan Lemme

Introduction. LP 1: Line Drawing algorithm Slope-intersept equation for a straight line is

Lesson 8 - Practice Problems

CS602 Midterm Subjective Solved with Reference By WELL WISHER (Aqua Leo)

Binghamton University. EngiNet. Thomas J. Watson. School of Engineering and Applied Science. State University of New York. EngiNet WARNING CS 560

CS 450: COMPUTER GRAPHICS REVIEW: CLIPPING SPRING 2015 DR. MICHAEL J. REALE

CS452/552; EE465/505. Clipping & Scan Conversion

2D Graphics Primitives II. Additional issues in scan converting lines. 1)Endpoint order. Want algorithms to draw the same pixels for each line

Set the Viewport Clipping. Computer Graphics CSC470 1

What is Clipping? Why do we Clip? Lecture 9 Comp 236 Spring Clipping is an important optimization

Renderer Implementation: Basics and Clipping. Overview. Preliminaries. David Carr Virtual Environments, Fundamentals Spring 2005

VISIBILITY & CULLING. Don t draw what you can t see. Thomas Larsson, Afshin Ameri DVA338, Spring 2018, MDH

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

2.3. Graphing Calculators; Solving Equations and Inequalities Graphically

Chapter. Graph Solve. 9-1 Before Using Graph Solve 9-2 Analyzing a Function Graph 9-3 Graph Solve Precautions

Clipping and Intersection

CS 325 Computer Graphics

Write C++/Java program to draw line using DDA and Bresenham s algorithm. Inherit pixel class and Use function overloading.

CSE528 Computer Graphics: Theory, Algorithms, and Applications

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

EP486 Microcontroller Applications

Computer Graphics (CS 543) Lecture 10 (Part 1): 3D Clipping. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4620/8626 Computer Graphics Spring 2014 Homework Set 1 Suggested Answers

CSE328 Fundamentals of Computer Graphics

Binghamton University. EngiNet. Thomas J. Watson. School of Engineering and Applied Science. Computer Graphics. State University of New York.

Graphics Pipeline. CS535 Fall Daniel G. Aliaga Department of Computer Science Purdue University

Clipping. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

SE Mock Online Test 1-CG

Illumination and Reflection in OpenGL CS 460/560. Computer Graphics. Shadows. Photo-Realism: Ray Tracing. Binghamton University.

3D Polygon Rendering. Many applications use rendering of 3D polygons with direct illumination

Statistics & Curve Fitting Tool

Introduction to Computer Graphics 5. Clipping

Duration: 2 hours Max. Marks: 60

Principles of Computer Graphics. Lecture 3 1

CS488 2D Graphics. Luc RENAMBOT

Rasterization. CS 4620 Lecture Kavita Bala w/ prior instructor Steve Marschner. Cornell CS4620 Fall 2015 Lecture 16

2D TRANSFORMATIONS AND MATRICES

Section 1.6. Inverse Functions

Transformation Pipeline

3D Graphics Pipeline II Clipping. Instructor Stephen J. Guy

FMCET. Fatima Michael College of Engineering & Technology

CS 4731: Computer Graphics Lecture 21: Raster Graphics: Drawing Lines. Emmanuel Agu

Section 18-1: Graphical Representation of Linear Equations and Functions

This library uses only GL functions but contains code for creating common objects and simplifying viewing.

CS 591B Lecture 9: The OpenGL Rendering Pipeline

Rasterization. CS4620 Lecture 13

Binghamton University. EngiNet. State University of New York

More Hidden Surface Removal

+ b. From this we can derive the following equations:

Graphing with a Graphing Calculator

Computer Science 474 Spring 2010 Viewing Transformation

Polygon Filling. Can write frame buffer one word at time rather than one bit. 2/3/2000 CS 4/57101 Lecture 6 1

Transcription:

Binghamton University EngiNet State University of New York EngiNet Thomas J. Watson School of Engineering and Applied Science WARNING All rights reserved. No Part of this video lecture series may be reproduced in any form or by any electronic or mechanical means, including the use of information storage and retrieval systems, without written approval from the copyright owner. 2001 The Research Foundation of the State University of New York CS 460/560 Computer Graphics Professor Richard Eckert Lecture # 15 March 26, 2001 1

Lecture 14 -- Clipping Clipping Elimination of parts of scene outside a window or viewport Clipping with respect to a window (xwmin, ywmin, xwmax, ywmax given) Clip at this level ==> fewer points go through viewing transformation Clipping with respect to a viewport (xvmin, yvmin, xvmax, yvmax given) Points Lines Clipping Cohen-Sutherland Line Clipper Polygons Sutherland-Hodgeman Polygon Clipper Weiler-Atherton Polygon Clipper Other Curves Text Given: Point Clipping point (x,y) clipping rectangle (window or viewport) (xmin,ymin,xmax,ymax) Point test: if ((x<=xmax) && (x>=xmin) && (y<=ymax) && (y>=ymin) the point x,y lies inside the clip area so keep it! Line Clipping Could apply point test to all points on line Too much work Need a simple test involving line's endpoint coordinates Cohen-Sutherland Line Clipper Observation-- All lines fall into one of three categories 1. Both endpoints inside clip rectangle (Trivially accept entire line) 2. Both endpoints outside clip rectangle on the same side of one of its borders (Trivially reject entire line) 3. Neither 1 or 2 (Chop off part of line outside one of borders and repeat) 2

Region Code A tool in assigning lines to Category 1 or 2 4-bit region code number assigned to an endpoint (x,y) Any set bit means endpoint is outside of one of the 4 borders of the clip rectangle Each bit position corresponds to a different border Region Code RC = LRBT L=left (if x<xmin, L=1, else L=0) R=Right (if x>xmax, R=1, else R=0) B=Bottom (if y<ymin, B=1, else B=0) T=Top (if y>ymax, T=1, else B=0) Divides entire x-y plane 9 regions Region Codes (LRBT) 1001 0001 0101 ---------------------- 1000 0000 0100 ---------------------- 1010 0010 0110 Category 1 Lines Assume region codes for the line s endpoints are RC1 and RC2 if (RC1 RC2 == 0) both RCs are 0000 both endpoints are inside so Category 1 (trivial accept) Category 2 Lines If both endpoints are outside same border (Category 2 line) then both region codes will have same bit set in one of the four bit positions--i.e.: if (RC1 & RC2!= 0) both endpoints outside same border so Category 2 (trivial reject) Category 3 Lines Want to chop off outside part of line May have both endpoints (P1 & P2) outside different borders of clip region So it s not important which end is chopped off first But if one endpoint s in and other s out: Want to chop off outside end So Arrange things so P1 is the outside point (swap P1 & P2 if necessary) 3

How to do the Chopping Want to determine the new endpoint P1 s endpoint coordinates (x1,y1), (x2,y2) are known Slope m can be computed from them So y = m*(x-x2) + y2 (point slope form) Or x = (y-y2)/m + x2 Look at P1 s region code (RC1) Four possible cases: If RC1 == 1xxx (P1 to left of xmin) New endpoint should be on the left x1 <-- xmin y1 <-- m*(xmin-x2) + y2 Reset RC's L bit If RC1 == x1xx (P1 right of xmax) New endpoint should be on the right x1 <---xmax y1 <---m*(xmax-x2) +y2 Reset RC's R bit If RC1 == xx1x (P1 below ymin) New endpoint should be on the bottom y1 <---ymin x1 <---(ymin-y2)/m + x2 Reset RC's B bit If RC == xxx1 (P1 above ymax) New endpoint should be on the top y1 <---ymax x1 <---(ymax-y2)/m + y2 Reset RC's T bit The C-S Line Clipping Algorithm Input: Original endpoints (x1,y1,x2,y2) Clip region boundaries (xmin,ymin,xmax,ymax) Output: Accept Code (AC) AC==TRUE ==> part of line was inside AC==FALSE ==> no part of line was inside Clipped Line endpoints (x1,y1,x2,y2) (if AC==TRUE) 4

C-S Algorithm Pseudo-code: CS_LineClip(xmin,ymin,xmax,ymax,x1,y1,x2,y2,AC) done = FALSE While (!done) Calculate endpoint codes rc1, rc2 If ((rc1 rc2) == 0 ) // Category 1 done = TRUE AC = TRUE If ((rc1 & rc2)!= 0) // Category 2 done = TRUE AC = FALSE If (P1 is inside) Swap (x1,x2), (y1,y2); and rc1,rc2 If (L-bit of rc1 is set) // 1xxx x1 = xmin y1 = m*(xmin-x2) + y2 If (R-bit of rc1 is set) // x1xx x1 = xmax y1 = m*(xmax-x2) + y2 If (B-bit of rc1 is set) // xx1x y1 = ymin x1 = (ymin-y2)/m + x2 // xxx1 y1 = ymax x1 = (ymax-y2)/m + x2 Cohen-Sutherland Clipping Example Polygon Clipping Clip a polygon to a rectangular clip area Input Ordered list of polygon vertices (nin, vin[]) Clip rectangle boundary coordinates (xmin, ymin, xmax, ymax). Output: An ordered list of clipped polygon vertices (nout, vout[]). vin[] and vout[] could be arrays of POINTs Approaches to Polygon Clipping Use a line clipper on each polygon edge??? But we usually won t get back a polygon Parts of the clip rectangle will be edges of the clipped polygon Really need new list of edges (or vertices) Sutherland-Hodgeman Polygon Clipper Approach: Clip all polygon edges with respect to each clipping boundary Do four passes; on each pass: Traverse current polygon and clip with respect to one of the four boundaries Assemble output polygon edges as you go vin[] --> Clip Left --> vtemp1[] --> Clip Right --> vtemp2[] --> Clip Bottom --> vtemp3[] --> Clip Top --> vout[] 5

On any polygon traversal the clip boundary divides plane into "in" side and "out" side For any given edge (vertices i and i+1), during traversal, there are four possibilities: (Assume vertex i has already been processed) VERTEX i VERTEX i+1 ACTION in in Add Vertex i+1 to output list out out Add no vertex to output list in out Add intersection point with edge to output list out in Add intersection point with edge and vertex i+1 to output list Sample Traversal Implementation Function sh_clip() Will clip an input polygon (ni, vi[]) With respect to a given boundary (bndry) Generating an output polygon (no, vo[]) Enumerate the boundaries as: LEFT, RIGHT, BOTTOM, and TOP sh_clip(ni, vi[], no, vo[], xmin, ymin, xmax, ymax, bndry); vi[] and vo[]: could be arrays of POINTs ni, no: number of points in each array xmin, ymin, xmax, ymax: clip region boundaries Using sh_clip() to clip a polygon Make four calls to sh_clip(): sh_clip(nin, vin[], ntemp1, vtemp1[], xmin, ymin, xmax, ymax, LEFT); sh_clip(ntemp1, vtemp1[], ntemp2, vtemp2[], xmin, ymin, xmax, ymax, RIGHT); sh_clip(ntemp2, vtemp2[], ntemp3, vtemp3[], xmin, ymin, xmax, ymax, BOTTOM); sh_clip(ntemp3, vtemp3[], nout, vout[], xmin, ymin, xmax, ymax, TOP); Three Helper Functions BOOL inside(v, xmin, ymin, xmax, ymax, Bndry) Returns TRUE if vertex point V is on the "in" side of boundary Bndry intersect(v1, V2, xmin, ymin, xmax, ymax, Bndry, Vnew) Computes intersection point of edge whose endpoints are V1 and V2 with boundary Bndry Returns the resulting point in Vnew output(v, n, vout[]) Adds vertex point V to the polygon (n, v[]) n will be incremented by 1 vertex V added to end of polygon's vertex list v[] sh_clip (ni, vi[], no, vo[], bndry) no = 0 // output list begins empty First_V = vi[0] // first vertex (i) For (j=0 to ni-1) // traverse polygon Second_V = v[(j+1) % ni] // second vertex (i+1) If (inside(first_v, bndry) If (inside(second_v, bndry) // "in-in" case output(second_v, no, vo) // "in-out" case intersect(first_v, Second_V, bndry, Vtemp) output (Vtemp, no, vo) If (inside(second_v, bndry) // "out-in" case intersect(first_v, Second_V, bndry, Vtemp) output(vtemp, no, vo) output(second_v, no, vo) // no "out-out" case First_V = Second_V // prepare for next edge 6

Example of S-H Clipping 7