CS 248 Assignment 2 Polygon Scan Conversion CS248 Presented by Zak Middleton Stanford University October 18, 2002.

Slides:



Advertisements
Similar presentations
Polygon Scan Conversion – 11b
Advertisements

The essentials managers need to know about Excel
CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
CP411 polygon Lecture 6 1. Scan conversion algorithm for circle 2. Draw polygons 3. Antialiasing.
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
College of Computer and Information Science, Northeastern UniversityApril 17, CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 9.
Viewing & Clipping In 2D. 2 of 44 Contents Windowing Concepts Clipping –Introduction –Brute Force –Cohen-Sutherland Clipping Algorithm Area Clipping –Sutherland-Hodgman.
Different types of Polygons Simple Convex Simple Concave Non-simple : self-intersecting With holes ConvexConcaveSelf-intersecting.
CPCS 391 Computer Graphics 1 Lecture 5: Polygon Filling
Implementation Dr. Amy Zhang. Reading 2  Hill, Chapters  Hill, Chapter 10.
Vertices and Fragments I CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
CS 248 Assignment 2 Polygon Scan Converter CS248 Presented by Abe Davis Stanford University October 17, 2008.
CS 248 Assignment 2 Polygon Scan Conversion CS248 Presented by Josh Wiseman Stanford University October 19, 2005.
CS 4731: Computer Graphics Lecture 22: Raster Graphics Part 3 Emmanuel Agu.
PowerPoint: Tables Computer Information Technology Section 5-11 Some text and examples used with permission from: Note: We are.
SE 313 – Computer Graphics Lecture 11: Projection Painting and Merging Textures Lecturer: Gazihan Alankuş 1.
1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.
Computer Graphics Inf4/MSc Computer Graphics Lecture 9 Antialiasing, Texture Mapping.
Managing Business Data Lecture 8. Summary of Previous Lecture File Systems  Purpose and Limitations Database systems  Definition, advantages over file.
Power Point EDU 271 Microsoft PowerPoint is a powerful tool to create professional looking presentations and slide shows. PowerPoint allows you to construct.
CGMB 314 Intro to Computer Graphics Fill Area Primitives.
Polygon Scan Conversion and Z-Buffering
Basics of Rendering Pipeline Based Rendering –Objects in the scene are rendered in a sequence of steps that form the Rendering Pipeline. Ray-Tracing –A.
Introduction Tracking the corners Camera model and collision detection Keyframes Path Correction Controlling the entire path of a virtual camera In computer.
PowerPoint. Basic Vocabulary Slide - Presentation - Slide layout – ► ► ► ► a single page in PowerPoint all the slides for a speech all the slides for.
CS 376 Introduction to Computer Graphics 02 / 12 / 2007 Instructor: Michael Eckmann.
3/4/04© University of Wisconsin, CS559 Spring 2004 Last Time Clipping Lines –Cohen-Sutherland: The use of outcodes and early reject/accept tests –Liang-Barsky:
Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 121 Today’s class Drawing lines Bresenham’s algorithm Compositing Polygon filling.
Creating your own form from scratch.. To create a custom form, you can modify an existing form or design and create a form from scratch. In either case,
Graphics A graphics program allows you to combine pictures and text in many different ways. Features – General Level Draw graphics Enter Text Common Tools.
COMP 261 Lecture 16 3D Rendering. input: set of polygons viewing direction direction of light source(s) size of window. output: an image Actions rotate.
10/26/04© University of Wisconsin, CS559 Fall 2004 Last Time Drawing lines Polygon fill rules Midterm Oct 28.
MA/CS 3751 Fall 2002 Lecture 24. MA/CS 3752 ginput ginput is a Matlab function which takes one argument input: number of points to select in the image.
Scan Conversion. Last step in the graphics pipeline Efficiency is a central issue Common primitives – Lines (done last class) – Polygons (fill polygons,
Chapter 4 Working with Frames. Align and distribute objects on a page Stack and layer objects Work with graphics frames Work with text frames Chapter.
CS 325 Introduction to Computer Graphics 03 / 22 / 2010 Instructor: Michael Eckmann.
Design Studies 20 ‘Show Off’ Project How to make a computer monitor In Google Sketchup By: Liam Jack.
CS 325 Introduction to Computer Graphics 03 / 29 / 2010 Instructor: Michael Eckmann.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential.
Lecture 6 Rasterisation, Antialiasing, Texture Mapping,
Key Applications Module Lesson 14 — Working with Tables Computer Literacy BASICS.
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.
Digital Media Lecture 5: Vector Graphics Georgia Gwinnett College School of Science and Technology Dr. Jim Rowan.
Lecture 15: Raster Graphics and Scan Conversion
1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.
XP Tutorial 3 Creating Animations. XP New Perspectives on Macromedia Flash MX Elements of Animation Layers are used to organize the content of.
COMPUTER GRAPHICS CS 482 – FALL 2015 NOVEMBER 10, 2015 VISIBILITY CULLING HIDDEN SURFACES ANTIALIASING HALFTONING.
Computer Graphics Lecture 08 Taqdees A. Siddiqi Computer Graphics Filled Area Primitives I Lecture 08 Taqdees A. Siddiqi
Processing Images and Video for An Impressionist Effect Automatic production of “painterly” animations from video clips. Extending existing algorithms.
Computer Graphics CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
Agenda Collect Color Meaning Artist PowerPoint Introduction to Adobe Illustrator ◦ Guided Notes ◦ Step-by-Step Illustrator Activity Alphabet Letters Project-
CS552: Computer Graphics Lecture 16: Polygon Filling.
What is a Function Expression?
Monday, Oct. 3rd! Copy your Agenda for the week. There is no school Thursday and Friday for State-wide Inservices. Materials: Journal, glue,
Microsoft Access 2007 – Level 2
Computer Graphics Filling.
Flash Interface, Commands and Functions
Introduction to Polygons
CS G140 Graduate Computer Graphics
Implementation I Ed Angel
Prof. Harriet Fell Spring 2007 Lecture 9 – January 29, 2007
3 1 2 Significant Figures with calculations (Advanced)
Lecture 13 Clipping & Scan Conversion
Prof. Harriet Fell Fall 2011 Lecture 9 – September 26, 2011
Introduction to PowerPoint
Using Animation and Multimedia
Implementation I Ed Angel Professor Emeritus of Computer Science
Type to enter a caption. Computer Graphics Week 6 Lecture 1.
Presentation transcript:

CS 248 Assignment 2 Polygon Scan Conversion CS248 Presented by Zak Middleton Stanford University October 18, 2002

2 Announcements… Project 1 grades should be mailed to you by Sunday, Oct. 20 (also the deadline to drop courses from study list) Project 1 grades should be mailed to you by Sunday, Oct. 20 (also the deadline to drop courses from study list)

3 Getting Started Read the project handout carefully! Read the project handout carefully! Get the assignment from /usr/class/cs248/assignments/assignment2/ Get the assignment from /usr/class/cs248/assignments/assignment2/ “README.files” goes over details on building the project, what different source files do, and where to find examples. “README.animgui” explains what to do once the program is running. How to create polygons, load/save object files, and create animations (we’ll go over most of this today too). “README.samples” in assignment2/bin goes over the settings used to create the sample images in assignment2/bin/examples ( also in /usr/class/cs248/data/assignment2).

4 Development The interface is built using a library called GLUI, which runs on Linux and Windows. The interface is built using a library called GLUI, which runs on Linux and Windows. You won’t need to change the interface unless you add features (extra credit). You can develop and test this program on Windows, just make sure it works on the Linux machines in Sweet Hall! You can develop and test this program on Windows, just make sure it works on the Linux machines in Sweet Hall! Don’t worry about matching the sample images exactly, just use them to get an idea of correct behavior. Don’t worry about matching the sample images exactly, just use them to get an idea of correct behavior.

5 The Interface A few key points: (Shift + Left click) : add vertices. (Shift + Left click) : add vertices. (Left click) : completes the polygon you’re editing, or allows you to select and drag vertices. (Left click) : completes the polygon you’re editing, or allows you to select and drag vertices. (Right click) : drag the whole polygon (Right click) : drag the whole polygon The program we give you already handles all the editing functionality, you just need to work on the rendering. The program we give you already handles all the editing functionality, you just need to work on the rendering. (demo: editing) (The interface is described in detail in README.animgui) When you’re ready to see the scene, hit the “Render” button.

6 Scan Conversion (Rasterization) The Algorithm (page 98 in Computer Graphics FvDFH second ed.) Create an Edge Table for the polygon being rendered, sorted on y. Create an Edge Table for the polygon being rendered, sorted on y. Don’t include horizontal edges, they are handled by the edges they connect to (see page 95 in text). (FvDFH, pages 92, 98) Note: xmin is the x at the minimum y for the edge, not necessarily the minimum x of the edge. Hence xmin = 7 for edge AB.

7 Scan Conversion (cont.) Once you have your Edge Table (ET) for the polygon, you’re ready to step through y coordinates and render scan lines: 1. Set y to the first non-empty bucket in the ET. This is bucket 1 in the example. 2. Initialize the Active Edge Table (AET) to be empty. The AET keeps track of which edges cross the current y scan line. 3. Repeat the following until the AET and ET are empty: 3.1 Add to the AET the ET entries for the current y. (edges AB, BC in example) 3.2 Remove from the AET entries where y = ymax. (none at first in example) Then sort the AET on x. (order: {AB, BC}) 3.3 Fill in pixel values on the y scan line using the x coordinates from the AET. Be wary of parity– use the even/odd test to determine whether to fill (see next slide). 3.4 Increment y by 1 (to the next scan line). 3.5 For every non-vertical edge in the AET update x for the new y (calculate the next intersection of the edge with the scan line). Note: the algorithm in the book (presented here and in course lecture notes) attempts to fix the problems that occur when polygons share an edge, by not rasterizing the top-most row of pixels along an edge.

8 Active Edge Table Example Example of an AET containing edges {FA, EF, DE, CD} on scan line 8: 3.1: (y = 8) Get edges from ET bucket y (none in this case, y = 8 has no entry) 3.1: (y = 8) Get edges from ET bucket y (none in this case, y = 8 has no entry) 3.2: Remove from the AET any entries where ymax = y (none here) 3.2: Remove from the AET any entries where ymax = y (none here) 3.3: Draw scan line. To handle multiple edges, group in pairs: {FA,EF}, {DE,CD} 3.3: Draw scan line. To handle multiple edges, group in pairs: {FA,EF}, {DE,CD} 3.4: y = y+1 (y = 8+1 = 9) 3.4: y = y+1 (y = 8+1 = 9) 3.5: Update x for non-vertical edges, as in simple line drawing. 3.5: Update x for non-vertical edges, as in simple line drawing. (FvDFH pages 92, 99)

9 Active Edge Table Example (cont.) 3.1: (y = 9) Get edges from ET bucket y (none in this case, y = 9 has no entry in ET) 3.1: (y = 9) Get edges from ET bucket y (none in this case, y = 9 has no entry in ET) “Scan line 9” shown in fig 3.28 below 3.2: Remove from the AET any entries with ymax = y (remove FA, EF) 3.2: Remove from the AET any entries with ymax = y (remove FA, EF) 3.3: Draw scan line between {DE, CD} 3.3: Draw scan line between {DE, CD} 3.4: y = y+1 = : y = y+1 = : Update x in {DE, CD} 3.5: Update x in {DE, CD} 3.1: (y = 10) (Scan line 10 shown in fig 3.28 below) 3.1: (y = 10) (Scan line 10 shown in fig 3.28 below) And so on… And so on… (FvDFH pages 92, 99)

10 Test Images Some cases you should test: Self-intersecting polygons, to test parity. Edges that cross.Horizontal and Vertical edges. (vertices added for illustration) (demo: rendering)

11 Antialiasing Scan conversion with super-sampling. How can we achieve this? Two possibilities: 1. Scan convert once to a super-sampled grid, then average down. Cost: 1 scan conversion s 2 x p 2 storage, where there are (s x s) samples per pixel, (p x p) image s 2 x p 2 pixel writes 2. Perform many normal scan conversions at super-sampled locations, and additively combine them. You will implement this method using an accumulation buffer (coming up). Cost: s 2 scan conversions 2p 2 storage s 2 x p 2 pixel writes (demo: overheads, program)

12 Motion Blur Synthesize the illusion that objects in our scene are moving quickly by blurring the image along the path of motion. Synthesize the illusion that objects in our scene are moving quickly by blurring the image along the path of motion. (demo: creating keyframes) (demo: motion blur.fli) Accomplished by interpolating between keyframes, meaning you define certain positions at certain times, and for times in between you calculate the position and direction of motion. Multiple images at different sample times are blurred (using the accumulation buffer), creating the illusion of motion.

13 Accumulation Buffer Algorithm Allows us to successively render multiple “scenes” and have them additively blend as we go. Each image ends up with an equal weighting of 1/n, where n is the number of samples taken. Allows us to successively render multiple “scenes” and have them additively blend as we go. Each image ends up with an equal weighting of 1/n, where n is the number of samples taken. (Appendix A in project 2 handout) Let "canvas" and "temp" be 24-bit pixel arrays. Let "polygon color" be a 24-bit color unique to each polygon. 1 clear canvas to black; 2 n = 0 (number of samples taken so far) 3 for (i=1; i<=s; i++) (for s subpixel positions) 4 for (j=1; j<=t; j++) (for t fractional frame times) 5 clear temp to black 6 n = n for each polygon 8 translate vertices for this subpixel position and fractional frame time 9 for each pixel in polygon (using your scan converter) 10 temp color <-- polygon color 11 for each pixel in canvas 12 canvas color <-- ((n-1)/n)*canvas color + (1/n)*temp color 13 display canvas on screen (by exiting from your rasterizer)

14 Accumulation Buffer (cont.) Example 1:

15 Accumulation Buffer (cont.) Example 2 (with overlap):

16 Accumulation Buffer (cont.) Question: Why should we render all polygons at once per frame (lines 7-10), why not antialias the objects separately and then blend their images together? Answer: Polygons on a perfect mesh over a colored background will show some of the background color. Rendering the polygons together prevents any unwanted blending. Answer: Polygons on a perfect mesh over a colored background will show some of the background color. Rendering the polygons together prevents any unwanted blending.

17 Extra Credit (Extra Credit is fun!!!) 1. Extend the interface to allow interactive scaling and rotations of polygons around a chosen point. Using matrices is one way… 2. Extend the interface to allow insertion and deletion of vertices in an already-defined polygon. Not hard mathematically, but think of usability as well. 3. Allow the number of vertices in a polygon to be different at any keyframe. Example: square to house.

18 Extra Credit (cont.) 4. Extend the interface to allow the input of polygons with “curved” boundaries. Curve is approximated by lots of closely spaced vertices that are still linearly connected. Not too tough, add vertices along mouse path while mouse button is down. 5. Combine #3 and #4 to allow different curved boundaries for each keyframe. Calculate approximate locations for vertices when the number changes. For example, going from a curve with 10 vertices to one with 4, calculate points along the 4-vertex curve at 1/10 intervals. Or come up with a better scheme. 6. Replace linear interpolation with splined interpolation to create smoother transitions between keyframes. Refer to section in text for more info. Consider cubic B-splines (section ).

19 Extra Credit (cont.) 7. Define a “skeleton” of connected line segments, and replace (x,y) coordinates of vertices with (u,v) offsets from skeleton. Interpolate the skeleton, then use the offsets to calculate vertex positions. (draw sketch) 8. Implement polygon clipping or scissoring. Scissoring means not sending pixel values to the canvas when they would be out of bounds. Full clipping means trimming the edge of the polygon so it fits within the screen, which can greatly reduce the time spent performing rasterization. scissoring clipping

20 Extra Credit (cont.) 9. Implement unweighted area sampling (section and earlier slide) as a user selectable alternative to accumulation buffer antialiasing (you must still implement accumulation buffer). For even more fun, implement weighted area sampling (section ). For even more fun, implement weighted area sampling (section ). 10. Create a cool animation and show it at the demo!

21 Development Tips Your canvas has (0,0) at the top left, with (canvasWidth-1, canvasHeight-1) at bottom right. Examples in book have (0,0) at bottom left. Doesn’t change too much, just be aware. Your canvas has (0,0) at the top left, with (canvasWidth-1, canvasHeight-1) at bottom right. Examples in book have (0,0) at bottom left. Doesn’t change too much, just be aware. If you are comfortable using them, you might find the C++ standard templates useful (especially sorted lists) for handling lists in your edge table. If you are comfortable using them, you might find the C++ standard templates useful (especially sorted lists) for handling lists in your edge table. Alternatively, you might want to write your own class or functions to handle this. Alternatively, you might want to write your own class or functions to handle this.

22 Questions?