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

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

Two-Dimensional Viewing. Chapter 6

Computer Graphics: Two Dimensional Viewing

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

Unit 3 Transformations and Clipping

Part IV. 2D Clipping

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

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI

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

Chapter 8: Implementation- Clipping and Rasterization

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

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

Viewing Transformation. Clipping. 2-D Viewing Transformation

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

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

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

3D Rendering Pipeline (for direct illumination)

Clipping Lines. Dr. Scott Schaefer

Computer Graphics. Chapter 4 Attributes of Graphics Primitives. Somsak Walairacht, Computer Engineering, KMITL 1

Chapter 3. Sukhwinder Singh

Graphics (Output) Primitives. Chapters 3 & 4

Computer Graphics. Attributes of Graphics Primitives. Somsak Walairacht, Computer Engineering, KMITL 1

Computer Science 474 Spring 2010 Viewing Transformation

CS184 : Foundations of Computer Graphics Professor David Forsyth Final Examination

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

From Vertices To Fragments-1

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

Computer Graphics Viewing Objective

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

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

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

SE Mock Online Test 1-CG

CS 325 Computer Graphics

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

Two Dimensional Viewing

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

Lab Manual. Computer Graphics. T.E. Computer. (Sem VI)

Clipping and Scan Conversion

Roll No. : Invigilator's Signature :.. GRAPHICS AND MULTIMEDIA. Time Allotted : 3 Hours Full Marks : 70

Part 3: 2D Transformation

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

Overview. Pipeline implementation I. Overview. Required Tasks. Preliminaries Clipping. Hidden Surface removal

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

Practical Linear Algebra: A Geometry Toolbox

Computer Graphics. - Clipping - Philipp Slusallek & Stefan Lemme

4.5 VISIBLE SURFACE DETECTION METHODES

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

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

CS337 INTRODUCTION TO COMPUTER GRAPHICS. Describing Shapes. Constructing Objects in Computer Graphics. Bin Sheng Representing Shape 9/20/16 1/15

Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Einführung in Visual Computing

Review for Mastery Using Graphs and Tables to Solve Linear Systems

9.1 Parametric Curves

CS123 INTRODUCTION TO COMPUTER GRAPHICS. Describing Shapes. Constructing Objects in Computer Graphics 1/15

Topics. From vertices to fragments

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

Realtime 3D Computer Graphics Virtual Reality

Course Number: Course Title: Geometry

Systems of Equations and Inequalities. Copyright Cengage Learning. All rights reserved.

Glossary of dictionary terms in the AP geometry units

SAZ4C COMPUTER GRAPHICS. Unit : 1-5. SAZ4C Computer Graphics

Each point P in the xy-plane corresponds to an ordered pair (x, y) of real numbers called the coordinates of P.

Computational Geometry. Geometry Cross Product Convex Hull Problem Sweep Line Algorithm

CS 325 Computer Graphics

UNIT -8 IMPLEMENTATION

Computer Graphics. - Rasterization - Philipp Slusallek

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

EXAMINATIONS 2017 TRIMESTER 2

Time: 3 hours Max. Marks: 80. Note: Answer FIVE full questions, choosing one full question from each module.

Computer Graphics II

CSCI 4620/8626. Coordinate Reference Frames

COMP3421. Vector geometry, Clipping

OpenGL Graphics System. 2D Graphics Primitives. Drawing 2D Graphics Primitives. 2D Graphics Primitives. Mathematical 2D Primitives.

Perspective Mappings. Contents

CoE4TN4 Image Processing

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

Aptitude Test Question

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

Graphics and Interaction Rendering pipeline & object modelling

MATH 1020 WORKSHEET 10.1 Parametric Equations

CSE528 Computer Graphics: Theory, Algorithms, and Applications

The Graphics Pipeline. Interactive Computer Graphics. The Graphics Pipeline. The Graphics Pipeline. The Graphics Pipeline: Clipping

(a) rotating 45 0 about the origin and then translating in the direction of vector I by 4 units and (b) translating and then rotation.

More on Coordinate Systems. Coordinate Systems (3) Coordinate Systems (2) Coordinate Systems (5) Coordinate Systems (4) 9/15/2011

Number/Computation. addend Any number being added. digit Any one of the ten symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9

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

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

Lesson 1. Unit 2 Practice Problems. Problem 2. Problem 1. Solution 1, 4, 5. Solution. Problem 3

EECS490: Digital Image Processing. Lecture #23

Section 12.1 Translations and Rotations

MET71 COMPUTER AIDED DESIGN

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

SHAPE AND STRUCTURE. Shape and Structure. An explanation of Mathematical terminology

CSAP Achievement Levels Mathematics Grade 7 March, 2006

Chapter 5. Projections and Rendering

UNIT 2 2D TRANSFORMATIONS

Clipping Polygons. A routine for clipping polygons has a variety of graphics applications.

Today. CS-184: Computer Graphics. Lecture #10: Clipping and Hidden Surfaces. Clipping. Hidden Surface Removal

A Procedure to Clip Line Segment

Transcription:

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

Outline The Two-Dimensional Viewing Pipeline The Clipping Window Normalization and Viewport Transformations Clipping Algorithms Two-Dimensional Point Clipping Two-Dimensional Line Clipping Polygon Fill-Area Clipping Curve Clipping Text Clipping 2

Introduction Allows a user to specify which part of a defined picture is to be displayed and to be placed on the display device The selected areas are then mapped onto specified areas of the device coordinates Two-dimensional viewing transformations involve Translation, rotation, and scaling operations As well as procedures for deleting those parts of the picture that are outside the limits of a selected scene area - Clipping 3

The Two-Dimensional Viewing Pipeline 2-D scene that is selected for display is called a clipping window World window or Viewing window Objects inside the clipping window are mapped to the viewport The clipping window selects what we want to see The viewport indicates where it is to be viewed on the output device 4

The Two-Dimensional Viewing Pipeline Viewing coordinate reference frame for specifying the clipping window Clipping window is defined in world coordinates To make the viewing process independent of any output t device, graphics systems convert object descriptions to normalized coordinates and apply the clipping routines Range from 0 to 1, or from 1 to 1 Finally, contents of the viewport are transferred to positions o s within the display window 5

The Clipping Window We could design our own clipping window with any shape, size, and orientation A clipping window with nonlinear boundaries requires more processing than clipping against a rectangle The simplest window edges to clip against are straight lines that are parallel to the coordinate axes 6

Viewing-Coordinate Clipping Window Set up a viewing-coordinate system within the world-coordinate frame specifying a rectangular clipping window Object positions in world coordinates are then converted to viewing coordinates where T is the translation matrix translates P 0 to origin, and R is the rotation matrix 7

World-Coordinate Clipping Window Translate the triangle to the world origin Define a clipping window around the triangle 8

Normalization and Viewport Transformations Some systems, viewport coordinates in the range from 0 to 1 (within a unit square) After clipping, the unit square containing the viewport is mapped to the output display device In other systems, the normalization and clipping routines are applied before the viewport transformation Viewport boundaries are specified in screen coordinates relative to the display window position 9

Mapping the Clipping Window into a Normalized Viewport Position (x w, y w ) in the clipping window is mapped into position (x v, y v ) in the associated viewport 10

Mapping the Clipping Window into a Normalized Viewport (2) 11

Mapping the Clipping Window into a Normalized Viewport (3) Transformation from world coordinates to viewport coordinates with the sequence Scale the clipping window to the size of the viewport using a fixed-point position of (xw min, yw min ) Translate (xw min, yw min ) to (xv min, yv min ) 12

Mapping the Clipping Window into a Normalized Square Another approach Normalized coordinates in the range from 1 to 1 By substituting 1 for xv min and yv min and substituting +1 for xv max and yv max 13

Mapping the Normalized Square into a specified viewport By substituting 1 for xw min and yw min and substituting +1 for xw max and yw max Objects may be distorted unless the aspect ratio of the viewport is also adjusted 14

Clipping Algorithms Point Clipping Line Clipping (straight-line segments) Fill-Area Clipping (polygons) Curve Clipping Text Clipping 15

Two-Dimensional Point Clipping A point P = (x, y) is displayed if the following inequalities are satisfied xw min x xw max yw min y yw max It is useful in various situations, particularly when pictures are modeled with particle systems, i.e., clouds, smoke, or explosions 16

Two-Dimensional Line Clipping The expensive part of a line-clipping procedure is in calculating l the intersection positions of a line First perform tests to determine whether is completely inside or completely outside If unable to identify, then perform intersection calculations 17

2-D Line Clipping (2) Both endpoints are inside clipping boundaries, save the line (P 1 P 2 ) Both endpoints are outside, discard the line (P 3 P 4 ) If both these tests fail, the line segment intersects at least one clipping boundary 18

2-D Line Clipping (3) By assigning the coordinate value for that edge to either x or y and solving for parameter u For example Substituting the left boundary, xw min, and solve for u If u is outside the range from 0 to 1, the line segment does not intersect the left boundary Not very efficient, i.e., processing time, not easily adapted to 3-D 19

Cohen-Sutherland Line Clipping Fast line clipping, Processing time is reduced Initially, every line endpoint is assigned a four-digit binary value, called a region code Each bit position is used to indicate whether the point is inside or outside one of the clipping-window boundaries 20

Cohen-Sutherland Line Clipping (2) Rightmost position (bit 1) references the left clipping-window boundary Leftmost position (bit 4) references the top window boundary 1 (or true) in any bit position indicates endpoint is outside 0 (or false) indicates endpoint is inside A region code is sometime referred to as an out-code 21

CS Line Clipping (3) Determine the values for a region-code using bit-processing operations Calculate differences between endpoint coordinates and clipping boundaries Use the resultant t sign bit of each difference calculation to set the corresponding value in the region-code bit 1 : x xw min, bit 2 : xw max x bit 3 : y yw min, bit 4 : yw max y 22

CS Line Clipping (4) 0000 for both endpoints, save these line segments 1 in the same bit position for each endpoint is completely outside Ex., 1001 for one endpoint and 0101 for the other endpoint 23

CS Line Clipping (5) Inside-Outside Tests The or operation between two endpoint region codes, false (0000), the line is inside The and operation between the two endpoint region codes, true (not 0000), the line is completely outside Lines that cannot be identified, are next checked for intersection with the window border lines 24

CS Line Clipping (6) To determine whether a line crosses a selected clipping boundary Window edges are processed in the order: left, right, bottom, top If one of these bit values is 1 and the other is 0, the line segment crosses that boundary 25

Intersection with Clipping Border Lines A line with (x0, y0) and (xend, yend) With a vertical clipping border line y = y0 + m(x x0) where x is either xw min or xw max with a horizontal border x = x0 + (y y0) / m where y is either yw min or yw max 26

Liang-Barsky Line Clipping Parametric line equations are combined with the point-clipping conditions x = x 0 + u x, y = y 0 + u y, 0 u 1 xw min x 0 + u x xw max yw min y 0 + u y yw max u p k q k, k = 1, 2, 3, 4 (left, right, bottom, and top) p 1 = x, q 1 = x 0 xw min p 2 = x, q 2 =xw max x 0 p 3 = y, q 3 = y 0 yw min p 4 = y, q 4 = yw max y 0 27

LB Line Clipping (2) Any line that is parallel to one of the clipping-window edges has p k = 0 If q k < 0, then the line is completely outside If q k 0, the line is inside the parallel clipping border 28

LB Line Clipping (3) When p k < 0, the infinite extension of the line proceeds from the outside to the inside for this particular clipping window If pk > 0, the line proceeds from the inside to the outside The value of u corresponds to the intersection with the window edge k 29

LB Line Clipping (4) For each line, u 1 and u 2 define part of the line that lies within the clip rectangle u 1 is determined by looking at the rectangle edges for which the line proceeds from the outside to the inside (p<0) Calculate r k = q k /p k u1 is taken as the largest of r u2 for which the line proceeds from inside to outside (p>0) u2 is taken as the minimum of r If u1 > u2, the line is completely outside Otherwise, the endpoints of the clipped line are calculated from the two values of parameter u 30

Nicholl-Lee-Nicholl Line Clipping Compared to CS and LB algorithms, the Nicholl-Lee-Nicholl algorithm performs fewer comparisons and divisions But NLN algorithm can be applied only to two-dimensional i 31

NLN Line Clipping (2) Determine the position of point P 0 for 9 possible regions Consider only 3 regions If P 0 lies in any one of the other, uses symmetric transformation to one of 3 * P 0 32

NLN Line Clipping (3) Assuming that P 0 and P end are not both inside, then determine P end relative to P 0 If P 0 is inside the clipping window, new regions are semi-infinite infinite line segments pass through the clipping-window corners Depending on region contains P end, compute the line-intersection position with the boundary 33

NLN Line Clipping (4) If P 0 is in the region to the left, set up 0 the four regions labeled L, LT, LR, and LB 34

NLN Line Clipping (5) When P 0 is closer to the left clipping boundary uses Fig. a When P 0 is closer to the top clipping boundary uses Fig. b 35

NLN Line Clipping (6) To determine the region for P end Compare the slope of the line segment to the slopes of the boundaries For example, P 0 is left of the clipping window, then P end is in TL or Clip the line if 36

NLN Line Clipping (7) From parametric equations x = x 0 + (x end x 0 )u y = y 0 + (y end y 0 )u Intersection position with the left boundary x = x L, and u = (x L x 0 )/(x end x 0 ), y = y 0 + [(y end y 0 )/(x end x 0 )]*(x L x 0 ) Intersection position on the top boundary y = y T, and u = (y T y 0 )/(y end y 0 ), x = x 0 + [(x end x 0 )/(y end y 0 )]*(y T y 0 ) 37

Line Clipping Using Nonrectangular Polygon Clip Windows Can apply parametric clipping procedures if first split the concave polygon into a set of convex polygons add one or more additional edges to the concave clipping area so that it is modified to a convex- polygon shape 38

Line Clipping Using Nonlinear Clipping-Window Boundaries Circles or other curved-boundary Require more processing because the calculations involve nonlinear equations Clipped against the bounding rectangle (coordinate extents) of the curved clipping region Ex., in case of a circle, calculate the distance of the line endpoints from the circle center If the distance 2 for both endpoints of a line is less than or equal to the radius 2, save the entire line 39

Polygon Fill-Area Clipping Typically support only fill areas that are polygons, and convex Cannot directly apply a line clipping because the result would not be a closed polyline 40

Polygon Fill-Area Clipping (2) Clip a polygon fill area by determining the new shape for the polygon as each clipping-window edge is processed Or, checking its coordinate extents 41

Polygon Fill-Area Clipping (3) Create a new vertex list at each clipping boundary, and then pass this new vertex list to the next boundary clipper 42

Sutherland-Hodgman Polygon Clipping Send the pair of endpoints for each successive polygon line segment through the series of clippers (left, right, bottom, and top) Operating in parallel, l as a clipper completes the processing of one pair of vertices, the next pair of endpoints is processed 43

SH Polygon Clipping (2) There are four possible cases 1. The first edge endpoint is outside and the second endpoint is inside 2. Both endpoints are inside 3. The first endpoint is inside and the second endpoint is outside 4. Both endpoints are outside 44

SH Polygon Clipping (3) Passing of vertices from one clipping stage to the next, the output from each clipper can be formulated 1. If the first input vertex is outside and the second vertex is inside, the intersection point with the border and the second vertex are sent to the next clipper 2. If both input vertices are inside, only the second vertex is sent to the next clipper 3. If the first vertex is inside and the second vertex is outside, the intersection point is sent to the next clipper 4. If both input vertices are outside, no vertices are sent 45

SH Polygon Clipping (4) 46

Weiler-Atherton Polygon Clipping Clip a fill area that is either a convex polygon or a concave polygon By tracing around the perimeter of the fill polygon searching for the borders that enclose a clipped fill region Follow a path (either counterclockwise or clockwise) around the fill area that detours along a clippingwindow boundary whenever a polygon edge crosses to the outside of that boundary In most cases, the vertex list is specified in a counterclockwise order 47

WA Polygon Clipping (2) For a counterclockwise traversal of the polygon fill- area vertices 1. Process the edges of the polygon fill area until an insideoutside pair of vertices is encountered 2. Follow the boundaries from the exit-intersection point to another intersection point with the polygon If this is a previously processed point, proceed to the next step If this is a new intersection point, continue processing polygon edges until a previously processed vertex is encountered 3. Form the vertex list for this section of the clipped fill area 4. Return to the exit-intersection point and continue processing the polygon edges 48

WA Polygon Clipping (3) 49

Polygon Clipping Using Nonrectangular Polygon Clip Windows First compare the positions of the bounding rectangles for the fill area and the clipping polygon If not, use inside-outside tests to process the parametric edge equations Solve pairs of simultaneous parametric line equations to determine the window intersection positions 50

Polygon Clipping Using Nonrectangular Polygon Clip Windows (2) Using the edge-traversal approach of the Weiler-Atherton algorithm Apply inside-outside tests to determine whether a fill-area vertex is inside or outside a particular clipping window boundary 51

Polygon Clipping Using Nonlinear Clipping-Window Boundaries A clipping window with curved boundaries Approximate the boundaries with straight-line sections and use one of the algorithms for clipping against a general polygon-shaped p clipping window Compare the coordinate extents of the fill area to the clipping window Perform some other region tests based on symmetric considerations Calculate the window intersection positions with the fill area 52

Curve Clipping If the objects are approximated with straight-line boundary sections, we use apolygon-clipping method Otherwise, the clipping procedures involve nonlinear equations 53

Curve Clipping (2) Test the coordinate extents of an object against the clipping boundaries Check for object symmetries between quadrants and octants An intersection calculation involves substituting a clipping-boundary position (xw min, xw max, yw min, or yw max ) in the nonlinear equation for the object boundary and solving for the other coordinate value 54

Text Clipping Clipping method depends on how characters are generated The simplest method is to use the all-or-none string-clipping strategy An alternative is to use the all-or-none character-clipping strategy A third approach to text clipping is to clip the components of individual characters 55

Text Clipping (2) 56

Text Clipping (3) If an individual character overlaps a clipping window, clip off only the parts of the character that are outside Outline character fonts use a polygon-clipping algorithm Bit maps are clipped by comparing the relative position of the individual pixels in the character grid patterns to the borders of the clipping region 57

End of Chapter 6 58