CS 376 Introduction to Computer Graphics 02 / 07 / 2007 Instructor: Michael Eckmann.

Slides:



Advertisements
Similar presentations
Computer Graphics- SCC 342
Advertisements

CS 376 Introduction to Computer Graphics 02 / 02 / 2007 Instructor: Michael Eckmann.
CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
Transformations We want to be able to make changes to the image larger/smaller rotate move This can be efficiently achieved through mathematical operations.
Informationsteknologi Wednesday, November 7, 2007Computer Graphics - Class 51 Today’s class Geometric objects and transformations.
CS 376 Introduction to Computer Graphics 02 / 05 / 2007 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 04 / 09 / 2007 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 02 / 24 / 2010 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 02 / 09 / 2007 Instructor: Michael Eckmann.
Scan Conversion II Revision 1.4 2/13/07 Copyright 2006, Dr. Zachary Wartell, UNCC, All Rights Reserved.
CS 376b Introduction to Computer Vision 02 / 27 / 2008 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 02 / 26 / 2007 Instructor: Michael Eckmann.
Graphics Output Primitives Pixel Addressing and Fill Area Dr. M. Al-Mulhem Feb. 1, 2008.
CS 376b Introduction to Computer Vision 04 / 15 / 2008 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 04 / 06 / 2007 Instructor: Michael Eckmann.
CS 450: Computer Graphics 2D TRANSFORMATIONS
By: Suhas Navada and Antony Jacob
CS 376b Introduction to Computer Vision 02 / 26 / 2008 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.
CS 450: Computer Graphics REVIEW: OVERVIEW OF POLYGONS
CGMB 314 Intro to Computer Graphics Fill Area Primitives.
Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations.
Transformation of Graphics
CS 376 Introduction to Computer Graphics 04 / 23 / 2007 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 02 / 12 / 2007 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 03 / 08 / 2010 Instructor: Michael Eckmann.
Part 6: Graphics Output Primitives (4) 1.  Another useful construct,besides points, straight line segments, and curves for describing components of a.
CS 325 Introduction to Computer Graphics 02 / 01 / 2010 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 02 / 17 / 2010 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 04 / 26 / 2010 Instructor: Michael Eckmann.
Geometric Transformations
CS 376 Introduction to Computer Graphics 02 / 16 / 2007 Instructor: Michael Eckmann.
Acute angle An angle with a measure less than 90 degrees.
CS 376 Introduction to Computer Graphics 04 / 20 / 2007 Instructor: Michael Eckmann.
Computer Graphics 2D Transformations. 2 of 74 Contents In today’s lecture we’ll cover the following: –Why transformations –Transformations Translation.
2D Output Primitives Points Lines Circles Ellipses Other curves Filling areas Text Patterns Polymarkers.
Geometric Objects and Transformation
CS 376 Introduction to Computer Graphics 02 / 23 / 2007 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 03 / 22 / 2010 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 02 / 22 / 2010 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 02 / 26 / 2010 Instructor: Michael Eckmann.
CS 376b Introduction to Computer Vision 04 / 28 / 2008 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 03 / 29 / 2010 Instructor: Michael Eckmann.
10/15/02 (c) 2002 University of Wisconsin, CS559 Who Am I? Prof Stephen Chenney These notes will be online after the lecture – in fact they’re online already.
E9 Students are expected to make generalizations about the properties of translations and reflections and apply these properties. E10 Students are expected.
10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.
Computer Graphics 3D Transformations. Translation.
Geometric Transformations
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
CS 376 Introduction to Computer Graphics 04 / 25 / 2007 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 04 / 12 / 2010 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
CS COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,
Computer Graphics Filling. Filling Polygons So we can figure out how to draw lines and circles How do we go about drawing polygons? We use an incremental.
2D Output Primitives Points Lines Circles Ellipses Other curves Filling areas Text Patterns Polymarkers.
Copyright © Ed2Net Learning Inc.1. 2 Warm Up x y y = 3x - 11) x y y = x - 62)
Unit 10 Transformations. Lesson 10.1 Dilations Lesson 10.1 Objectives Define transformation (G3.1.1) Differentiate between types of transformations (G3.1.2)
CS 376 Introduction to Computer Graphics 02 / 21 / 2007 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 04 / 07 / 2010 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 02 / 14 / 2007 Instructor: Michael Eckmann.
CS 551 / 645: Introductory Computer Graphics Viewing Transforms.
CS 325 Introduction to Computer Graphics 02 / 19 / 2010 Instructor: Michael Eckmann.
In the last several lessons, you have described translations using coordinates. You have also developed strategies for determining where an object started.
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
Computer Graphic 2 D Transformation.
Computer Graphics Filling.
Introduction to Polygons
Line and Character Attributes 2-D Transformation
Presentation transcript:

CS 376 Introduction to Computer Graphics 02 / 07 / 2007 Instructor: Michael Eckmann

Michael Eckmann - Skidmore College - CS Spring 2007 Today’s Topics Questions? Polygons Determining if a point is in the interior of a polygon Polygon filling algorithm tiling halftoning dithering antialiasing polygons

Michael Eckmann - Skidmore College - CS Spring 2007 Polygon fill areas To do a scanline fill of a polygon (see figure 4-20). –Determine the intersections (crossings) of the horizontal line (y=c) with the edges (y=mx + b) of the polygon. –Sort the crossings (x coordinates) from low to high (left to right). –There will be an even number of crossings, so draw horizontal lines between the first two crossings, then the next 2 and so on. –If the scanline goes through a vertex Add the crossing to the list twice if it's a local max or min. Add the crossing only once otherwise. Horizontal edges of a polygon can be ignored (not turned on.) Example on board.

Michael Eckmann - Skidmore College - CS Spring 2007 Polygon fill areas To count if the scanline goes through a vertex If the two edges are on the same side of the scanline, then add it twice. If the two edges are on different sides of the scanline, then add it once. To check for this, we can compare the y coordinates of the 3 vertices in question (draw on board) in either clockwise or counterclockwise fashion –If all 3 are monotonically increasing ( y 1 >y 2 => f(y 1 ) >= f(y 2 ))or all 3 are monotonically decreasing then the two edges are on different sides.

Michael Eckmann - Skidmore College - CS Spring 2007 Polygon fill areas Edge coherence properties can be used to speed up the calculation of the crossings of the scanline and edges. The crossing x-coordinate of one scanline with an edge differs from the crossing of the x-coordinate of the next scanline only by 1/m as seen below. Assuming we're processing the fill from bottom to top and the y's increase as we go up, –Assume scan line y k crosses an edge at (x k, y k ) and scan line y k+1 crosses at (x k+1, y k+1 ) –m = (y k+1 – y k ) / (x k+1 – x k ) –(y k+1 – y k ) = 1, so, m = 1 / (x k+1 – x k ) and solve for x k+1 –So, scan line y k+1 crosses that edge at (x k + 1/m, y k )

Michael Eckmann - Skidmore College - CS Spring 2007 Polygon fill areas Efficient polygon filling –1) proceed around edges in a clockwise or counterclockwise fashion –2) store each edge in an edge table –3) sort the edges based on the minimum y in the edge –4) process the scanlines in a bottom to top order –5) when the current scanline reaches the lower endpoint (with the min y) of the edge, that edge becomes active –6) active edges are sorted by their x coordinates (left to right) –During any given scanline non-active edges can be marked as either finished, or not yet active. Horizontal edges are ignored. Example on board.

Michael Eckmann - Skidmore College - CS Spring 2007 Polygon fill areas Masks –Besides being filled with a solid color, polygons are sometimes filled with patterns. The process of filling an area with a pattern is called tiling. –Fill patterns can be stored as rectangular arrays. The arrays are called masks and they are applied to the fill area and are usually smaller than the area to be filled. –The mask needs a starting position within the area to be filled. Starting at this position the mask is replicated both vertically and horizontally. –If the mask is an m  n array, and starting position is (0,0) a pixel at (x, y) will be drawn with the color in mask((x mod n), (y mod m)). –Example on board.

Michael Eckmann - Skidmore College - CS Spring 2007 Polygon fill areas Section 10.9 Halftoning and dithering –When there are very few intensity levels available (e.g. 2, black & white) to be displayed, halftoning is a technique that can provide more intensities by trading off addressability. –Newspapers show grey level photos by displaying black circles. The black circles vary in size according to how dark that part of the photo should be. –In graphics systems this halftoning technique is approximated with halftone patterns. Halftone patterns are typically n  n squares of pixels where the number of pixels turned on in that pattern correspond to the intensity desired.

Michael Eckmann - Skidmore College - CS Spring 2007 Polygon fill areas How is halftoning a tradeoff between intensities and addressability (resolution) ?

Michael Eckmann - Skidmore College - CS Spring 2007 Polygon fill areas Guidelines to creating halftoning patterns –With halftoning, one thing to be careful about is that the patterns can become apparent. That is undesirable. The intent is to have the viewer see the increase in intensities without noticing unintentional patterns. –Avoid only horizontal or vertical or diagonal pixels on in the patterns to reduce the possibility of “streaks”. –Further it is good to approximate the way that newspapers do it --- that is, concentrate on turning on pixels in the center of the pattern at each successive intensity. –To minimize unintentional patterns to be displayed, we can evolve each successive grid pattern by copying it and turning on an additional pixel. See next slide figure

Michael Eckmann - Skidmore College - CS Spring 2007 Polygon fill areas

Michael Eckmann - Skidmore College - CS Spring 2007 Polygon fill areas Dithering –Dithering refers to techniques for approximating halftones but without reducing addressability (resolution). –An n  n dither matrix D n is used to detemine if a pixel should be on or off. –The matrix is filled with the numbers from 0 to n 2 – 1 –on page 589 (equation 10-49) there's a mistake, it should be the dither matrix D

Michael Eckmann - Skidmore College - CS Spring 2007 Polygon fill areas Example of dither matrix D –For some pixel (x, y) an intensity level I(x,y) between 0 and n 2 is desired. Compute i = x mod n and j = y mod n to find which element (i,j) of the matrix D n to compare to the desired intensity. –If I(x,y) > D n (i,j) then the pixel is turned on, otherwise it is not. –This has the effect of different intensities, without reducing resolution. But what gets lost?

Michael Eckmann - Skidmore College - CS Spring 2007 Antialiasing Polygons Edges of polygons are lines. Lines (and therefore edges) have aliasing problems when made discrete. Antialiasing edges of polygons can be done using similar techniques as were used with lines. One way described below is the way I described antialiasing Bresenham lines. During scanline fill of a polygon, if the edge falls between two pixels on the scanline, then the intensities of the pixels depend on how close to the centers of the two pixels the line falls. The pixel at (x j, y k ): could be set to have x j+1 – x and x j+1 The pixel at (x j+1, y k ) would then be set to have x – x j Pixels that fall fully within the interior of a polygon are set to full intensity.

Michael Eckmann - Skidmore College - CS Spring 2007 Geometric Transformations (2D) Reading: (2D geometric transformations) Translations Rotations Scaling Homogeneous Coordinates Shearing Reflections

Michael Eckmann - Skidmore College - CS Spring 2007 Matrices An m by n matrix is a two dimensional array of values with m rows and n columns. Points are typically represented by column matrices (meaning they have multiple rows, but only 1 column) Matrix multiplication (3x3 times a 3x3 yields a 3x3 matrix) ( a b c ) ( j k l ) ( aj+bm+cp ak+bn+cq al+bo+cr ) ( d e f ) ( m n o ) = ( dj+em+fp dk+en+fq dl+eo+fr ) ( g h i ) ( p q r ) ( gj+hm+ip gk+hn+iq gl+ho+ir ) Matrix multiplication (2x2 times a 2x1 yields a 2x1 column matrix) ( a b ) ( x ) = ( ax+by ) ( c d ) ( y ) ( cx+dy ) A 2x2 matrix times a 2x1 matrix (a point) yields another point. Matrix multiplication is associative. ABC = (AB)C = A(BC).

Michael Eckmann - Skidmore College - CS Spring 2007 Translations (2D) Recall the idea that for the circle algorithm that we did computations assuming the circle's center was the origin. Then when we plotted the points we offset the calculated point by the actual center by just adding the respective coordinates. What we did there was perform a translation. Translation is a transformation on an object that simply moves it to a different position somewhere else within the same coordinate system. To translate an object we translate each of its vertices (points). To translate a 2d point (x 1, y 1 ) by t x in the x direction and t y in the y direction, we simply calculate the new coordinates to be: (x 2, y 2 ) = (x 1 + t x, y 1 + t y )

Michael Eckmann - Skidmore College - CS Spring 2007 Scaling (2D) Scaling is a transformation on an object that changes its size. Just as the translation could have been different amounts in x and y, you can scale x and y by different factors. Scaling is a transformation on an object that changes its size within the same coordinate system. To scale an object we scale each of its vertices (points). To scale a 2d point (x 1, y 1 ) by s x in the x direction and s y in the y direction, we simply calculate the new coordinates to be: (x 2, y 2 ) = (s x x 1, s y y 1 ) Example on the board of scaling a line segment from say 2,3 to 2,7

Michael Eckmann - Skidmore College - CS Spring 2007 Rotation (2D) Rotation is a transformation on an object that changes its position in a specific way (by rotating the object some angle about an axis). Rotations in the x-y plane are about an axis parallel to z. The point of intersection of the rotation axis with the x-y plane is the pivot point. We need to specify the angle and pivot point about which the object is to be rotated. To rotate an object we rotate each of its vertices (points). Positive angles are in the counterclockwise direction.

Michael Eckmann - Skidmore College - CS Spring 2007 Rotation (2D) To rotate a 2d point (x 1, y 1 ) an arbitrary angle of B, about the origin as a pivot point do the following. From the diagram on the board (also see figure 5-4 in the text) we have: sin(A + B) = y 2 / r => y 2 = r sin(A + B) cos(A + B) = x 2 / r x 2 = r cos(A + B) sin(A) = y 1 / r y 1 = r sin(A) cos(A) = x 1 / r x 1 = r cos(A) Known equalities exist for sin(A+B) and cos(A+B) sin(A + B) = sin(A) cos(B) + cos(A) sin(B) cos(A + B) = cos(A) cos(B) – sin(A) sin(B)

Michael Eckmann - Skidmore College - CS Spring 2007 Rotation (2D) Solve for x 2 and y 2. x 2 = r cos(A + B) = r cos(A) cos(B) – r sin(A) sin(B) = x 1 cos(B) – y 1 sin(B) y 2 = r sin(A + B) = r sin(A) cos(B) + r cos(A) sin(B) = y 1 cos(B) + x 1 sin(B) So, (x 2, y 2 ) = (x 1 cos(B) – y 1 sin(B), y 1 cos(B) + x 1 sin(B) ) This will rotate a point (x 1, y 1 ) an angle of B about the pivot point of the origin.

Michael Eckmann - Skidmore College - CS Spring 2007 Transformation Matrices (2D) TRANSLATION: (x 2, y 2 ) = (x 1 + t x, y 1 + t y ) ( x 2 ) = ( x 1 ) + ( t x ) ( y 2 ) ( y 1 ) ( t y ) SCALING: (x 2, y 2 ) = (s x x 1, s y y 1 ) ( x 2 ) = ( s x 0 ) ( x 1 ) ( y 2 ) ( 0 s y ) ( y 1 ) ROTATION: (x 2, y 2 ) = (x 1 cos(B) – y 1 sin(B), y 1 cos(B) + x 1 sin(B) ) ( x 2 ) = ( cos(B) – sin(B) ) ( x 1 ) ( y 2 ) ( sin(B) cos(B) ) ( y 1 )

Michael Eckmann - Skidmore College - CS Spring 2007 Homogeneous Coordinates Translations, Scales and Rotations can be done as described in the previous slides. What was not described was rotation about an arbitrary pivot point. In addition to the matrix multiplication involved, a vector (column matrix) add would need to be added in. So, both translations and rotations have an add of a column matrix. In addition, rotations and scales have matrix multiplications as well. To be able to represent all transformations only with matrix multiplications (without additions of column matrices), we use homogeneous coordinates.

Michael Eckmann - Skidmore College - CS Spring 2007 Homogeneous Coordinates To represent a 2d point in homogeneous coordinates instead of just an x and a y to represent a 2d point, we use an x, a y and an additional value, the homogeneous parameter. (x,y) => (cx, cy, c) where c is the homogeneous parameter. There are an infinite number of equivalent homogeneous representations for each coordinate point (x,y). When c = 1, we have (x,y) => (x, y, 1) Using homogeneous coordinates allows us to represent 2d transformations as matrix multiplications exclusively.

Michael Eckmann - Skidmore College - CS Spring 2007 Homogeneous Coordinates Transformations on homogeneous coordinates TRANSLATION: (x 2, y 2 ) = (x 1 + t x, y 1 + t y ) ( x 2 ) = ( 1 0 t x ) ( x 1 ) ( y 2 ) ( 0 1 t y ) ( y 1 ) ( 1 ) ( ) ( 1 ) SCALING: (x 2, y 2 ) = (s x x 1, s y y 1 ) ( x 2 ) = ( s x 0 0 ) ( x 1 ) ( y 2 ) ( 0 s y 0 ) ( y 1 ) ( 1 ) ( ) ( 1 )

Michael Eckmann - Skidmore College - CS Spring 2007 Homogeneous Coordinates Transformations on homogeneous coordinates ROTATION: (x 2, y 2 ) = (x 1 cos(B) – y 1 sin(B), y 1 cos(B) + x 1 sin(B) ) ( x 2 ) = (cos(B) – sin(B) 0 ) ( x 1 ) ( y 2 ) (sin(B) cos(B) 0 ) ( y 1 ) ( 1 ) ( ) ( 1 ) These three transform matrices are sometimes written as –T(t x,t y ) –S(s x,s y ) –R(B)

Michael Eckmann - Skidmore College - CS Spring 2007 Scaling a line segment Let's look at this example on the board. Example: Scale a line segment from (3,2) to (5,2) by 2 in the x-direction. ( x 0 ) ( ) ( 3 ) ( 6 ) ( y 0 ) = ( ) ( 2 ) = ( 2 ) ( 1 ) ( ) ( 1 ) ( 1 ) And the other endpoint: ( x end ) ( ) ( 5 ) ( 10 ) ( y end ) = ( ) ( 2 ) = ( 2 ) ( 1 ) ( ) ( 1 ) ( 1 ) Problem: The line segment (3,2) to (5,2) when scaled by 2 in x-direction gives a line segment from (6,2) to (10, 2). Yes it's original length in the x-direction was 2 and now it is 4, but the line also was translated. Let's see it on the board.

Michael Eckmann - Skidmore College - CS Spring 2007 Fixed point scaling Specify a point that will remain fixed after the scaling. This is the fixed-point. Let's scale the same line segment but this time fix the left endpoint (3,2). To do this, we need to: –a) first translate (3, 2) to the origin –b) scale by 2 in x-direction (like before) –c) then translate the origin back to (3, 2) This will yield a matrix multiplication M c M b M a = M fps which we will then multiply M fps P, where P is a homogeneous point, to get the transformed point. Notice the order: matrix M a is closest to the point, then M b then M c

Michael Eckmann - Skidmore College - CS Spring 2007 Fixed point scaling a) the matrix to translate (3, 2) to the origin is this: (1 0 -3) (0 1 -2) (0 0 1) b) the matrix to scale by 2 in x direction is this: (2 0 0) (0 1 0) (0 0 1) c) the matrix to translate the origin back to (3, 2) is this: (1 0 3) (0 1 2) (0 0 1)

Michael Eckmann - Skidmore College - CS Spring 2007 Fixed point scaling a) first translate (3, 2) to the origin b) scale by 2 in x-direction (like before) c) then translate the origin back to (3, 2) (1 0 3) (2 0 0) (1 0 -3) ( 2 0 3) ( ) ( ) (0 1 2) (0 1 0) (0 1 -2) = ( 0 1 2) ( ) = (0 1 0 ) (0 0 1) (0 0 1) (0 0 1) ( 0 0 1) ( ) (0 0 1 ) Multiply this matrix by each of the vertices (endpoints of the line segment): ( ) ( 3 ) ( 3 ) (0 1 0 ) ( 2 ) = ( 2 ) (0 0 1 ) ( 1 ) ( 1 ) ( ) ( 5 ) ( 7 ) (0 1 0 ) ( 2 ) = ( 2 ) (0 0 1 ) ( 1 ) ( 1 ) Notice: initial endpoint (the fixed-point) stayed the same after transformation and the new width in x-direction is 4 (which is 2 the scale factor * 2 the original length).

Michael Eckmann - Skidmore College - CS Spring 2007 Fixed point scaling Let's scale the same line segment but this time fix the midpoint (4,2). To do this, we need to: –a) first translate (4, 2) to the origin –b) scale by 2 in x-direction (like before) –c) then translate the origin back to (4, 2)

Michael Eckmann - Skidmore College - CS Spring 2007 Fixed point scaling a) first translate (4, 2) to the origin b) scale by 2 in x-direction (like before) c) then translate the origin back to (4, 2) (1 0 4) (2 0 0) (1 0 -4) ( 2 0 4) ( ) ( ) (0 1 2) (0 1 0) (0 1 -2) = ( 0 1 2) ( ) = (0 1 0 ) (0 0 1) (0 0 1) (0 0 1) ( 0 0 1) ( ) (0 0 1 ) Multiply this matrix by each of the vertices (endpoints of the line segment): ( ) ( 3 ) ( 2 ) (0 1 0 ) ( 2 ) = ( 2 ) (0 0 1 ) ( 1 ) ( 1 ) ( ) ( 5 ) ( 6 ) (0 1 0 ) ( 2 ) = ( 2 ) (0 0 1 ) ( 1 ) ( 1 ) Notice: the line segment stretched equally left and right from the middle. The new width in x-direction is 4 (which is 2 the scale factor * 2 the original length).