CGMB 314 Intro to Computer Graphics Fill Area Primitives.

Slides:



Advertisements
Similar presentations
Polygon Scan Conversion – 11b
Advertisements

Computer Graphics Inf4/MSc 1 Computer Graphics Lecture 7 Scanline algorithm and polygon clipping Taku Komura.
CMPE 466 COMPUTER GRAPHICS
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.
Computer Graphics Scan Conversion Polygon Faculty of Physical and Basic Education Computer Science Dep Lecturer: Azhee W. MD.
Viewing & Clipping In 2D. 2 of 44 Contents Windowing Concepts Clipping –Introduction –Brute Force –Cohen-Sutherland Clipping Algorithm Area Clipping –Sutherland-Hodgman.
Introduction to Computer Graphics Chapter 6 – 2D Viewing Pt 2 1.
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.
CSCE 441: Computer Graphics Scan Conversion of Polygons
Graphics Programming: Polygon Filling
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Scan Conversion Week 6, Mon 6 Oct 2003 recap: Bresenham line algorithm scan.
1 CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai.
CS 454 Computer graphics Polygon Filling
CS 4731: Computer Graphics Lecture 22: Raster Graphics Part 3 Emmanuel Agu.
TOPIC 4 PART III FILL AREA PRIMITIVES POLYGON FILL AREAS CGMB214: Introduction to Computer Graphics.
1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.
1/24/20061 Fill-Area Algorithms and Functions. 1/24/20062 Learning Objectives OpenGL state variables Color and gray scale Color functions Point attributes.
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.
CS 551 / 645: Introductory Computer Graphics
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:
CS 445 / 645 Introduction to Computer Graphics Lecture 8 Triangle Rasterization Lecture 8 Triangle Rasterization.
College of Computer and Information Science, Northeastern UniversityOctober 12, CS G140 Graduate Computer Graphics Prof. Harriet Fell Spring 2006.
1 Filling Graphical Shapes. 2 We know how to draw outlines Can we just fill the “inside”? …but how do we know the difference between the inside and outside?
10/15/02 (c) 2002 University of Wisconsin, CS559 Last Time Clipping.
College of Computer and Information Science, Northeastern UniversityMay 27, CS 4300 Computer Graphics Prof. Harriet Fell Fall 2012 Lecture 9 – September.
2D Output Primitives Points Lines Circles Ellipses Other curves Filling areas Text Patterns Polymarkers.
Introduction to Computer Graphics CS 445 / 645 Lecture 9 Chapter 4: Rasterization L. McMillan MIT notes (Fall ’98)
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.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2013 Tamara Munzner Rasterization.
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.
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.
Lecture 15: Raster Graphics and Scan Conversion
Graphics Graphics & Graphical Programming Lecture 23 - Viewing & Clipping.
1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.
Rasterization Overview Raster Display Device. Scan Conversion / Rasterization: converting vector graphics into raster graphics (determining pixels in.
Computer Graphics CC416 Week 14 Filling Algorithms.
Computer Graphics Lecture 08 Taqdees A. Siddiqi Computer Graphics Filled Area Primitives I Lecture 08 Taqdees A. Siddiqi
Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition Chapter 14.
OUTPUT PRIMITIVES CEng 477 Computer Graphics METU, 2004.
CS552: Computer Graphics Lecture 16: Polygon Filling.
Computer Graphics Filling.
Introduction to Polygons
CS G140 Graduate Computer Graphics
Polygons.
(c) 2002 University of Wisconsin, CS559
Computer Graphics Filled Area Primitives II Lecture 09 Taqdees A
Fill Area Algorithms Jan
Polygon Filling Algorithms
Concepts, algorithms for clipping
Graphics Pipeline Clipping
© University of Wisconsin, CS559 Fall 2004
Agenda Polygon Terminology Types of polygons Inside Test
CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai
Prepared by Narendra V G CSE MIT
Agenda Polygon Terminology Types of polygons Inside Test
Prof. Harriet Fell Fall 2011 Lecture 9 – September 26, 2011
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
(c) 2002 University of Wisconsin, CS559
© University of Wisconsin, CS559 Fall 2004
Primitive Drawing Algorithm
Primitive Drawing Algorithm
Where We Stand At this point we know how to: Next thing:
Polygons.
Presentation transcript:

CGMB 314 Intro to Computer Graphics Fill Area Primitives

Filling 2D Shapes How do we fill shapes? Solid Fill Pattern Fill Texture Fill

Filling 2D Shapes (cont…) Some requirements A digital representation of the shape The shape must be closed It must have a well defines inside and outside A test for determining if a point is inside or outside of the shape A rule or procedure for determining the colors of points inside the shape

Representing Filled Shapes Digital images Inside determined by a color or range of colors Original ImagePink pixels have been filled with yellow

Representing Filled Shapes (cont…) A digital outline and a seed point indicating the interior Digital outline and seed points Filled outlines

Representing Filled Shapes (cont…) An implicit function representing a shape’s interior The inside of a circle of radius R The inside of a unit square

Representing Filled Shapes (cont…) An equation or list of edges representing a shape’s boundary and a rule for determining its interior E.g. Edge list Line from (0,0) to (1,0) Line from (1,0) to (1,1) Line from (1,1) to (0,1) Line from (0,1) to (1,1) Rule for interior points All points to the right of all of the (ordered) edges

Representing Filled Shapes (cont…) Edge list Line from (0,0) to (1,0) Line from (1,0) to (1,1) Line from (1,1) to (0,1) Line from (0,1) to (1,1) Rule for interior points All points to the right of all of the (ordered) edges Ordered edges

Representing Filled Shapes (cont…) Edge list Line from (0,0) to (1,0) Line from (1,0) to (1,1) Line from (1,1) to (0,1) Line from (0,1) to (1,1) Rule for interior points All points to the right of all of the (ordered) edges Filled shape

Fill Options How to set pixel colors for points inside the shape? Solid Fill Pattern Fill Texture Fill

Seed Fill Approach Select a seed point inside a region Move outwards from the seed point, setting neighboring pixels until the region is filled Seed pointMove outwards to neighbors Stop when the region is filled

Selecting the Seed Point Difficult to place the seed point automatically Seed fill works best in an interactive application where the user sets the seed point What is the inside of this shape? * It depends on the user’s intent

Seed Fill Basic algorithm select seed pixel initialize a fill list to contain seed pixel while (fill list not empty) { pixel  get next pixel from fill list setPixel(pixel) for (each of the pixel’s neighbors) { if (neighbor is inside region AND neighbor not set) add neighbor to fill list }

There are two types of 2D regions 4-connected region (test 4 neighbors) Two pixels are 4-connected if they are vertical or horizontal neighbors 8-connected region (test 8 neighbors) Two pixels are 8-connected if they are vertical, horizontal, or diagonal neighbors Which neighbors should be tested?

Using 4-connected and 8-connected neighbors gives different results Magnified area Original boundary Fill using 4-connected neighbors Fill using 8-connected neighbors

When is a Neighbor Inside the Region? There are two types of tests, resulting in two filling approaches Boundary fill Flood fill

Boundary Fill Fill condition The region is defined by a set of boundary pixels A neighbor of an inside pixel is also inside if it is not a boundary pixel Boundary pixel Seed pixel Original image and seed pointImage after 4-connected boundary fill

Flood Fill Fill condition The region is defined by a patch of like-colored pixels A neighbor of an inside pixel is also inside if its color is within a range of the seed pixel’s original color The range of inside colors can be specified in the application Seed pixel Original image and seed pointImage after 4-connected flood fill

Improving Performance Problems with the basic algorithm We don’t know how big the fill list should be Worst case, all the image pixels Slow Pixels may be checked many times to see if they have already been set (especially for 8-connected regions)

Improving Performance (cont…) Use coherence (logical connection) to improve performance and reduce memory requirements Neighbor coherence Neighboring pixels tend to be in the same region Span coherence Neighboring pixels along a given scan line tend to be in the same region Scan-line coherence The filling patterns of adjacent scan lines tends to be similar

Improving Performance (cont…) Span-based seed fill algorithm Seed point

Improving Performance (cont…) Span-based seed fill algorithm Start from the seed point Fill the entire horizontal span of pixels inside the region Seed point

Improving Performance (cont…) Span-based seed fill algorithm Determine spans of pixels in the rows above and below the current row that are connected to the current span Add the left-most pixel of these spans to the fill list

Improving Performance (cont…) Span-based seed fill algorithm Repeat until the fill list is empty

Improving Performance (cont…) Span-based seed fill algorithm Repeat until the fill list is empty

Improving Performance (cont…) Span-based seed fill algorithm Repeat until the fill list is empty

Improving Performance (cont…) Span-based seed fill algorithm Repeat until the fill list is empty

Filling Axis-Aligned Rectangles An axis-aligned rectangle is defined by its corner points (X min, Y min ) and (X max, Y max ) (X min, Y min ) (X max, Y max )

Filling Axis-Aligned Rectangles Filling can be done in a nested loop for (j = Ymin, j < Ymax, j++) { for (i = Xmin, i < Xmax, i++) { setPixel(i, j, fillColor) } (X min, Y min ) (X max, Y max )

Filling General Polygons Representing general polygons Defined by a list of connected line segments The line segments must form a closed shape (i.e. the boundary must connected) General polygons Can be self intersecting Can have interior holes

Filling General Polygons Specifying the interior Must be able to determine which points are inside the polygon Need a fill rule

Filling General Polygons Specifying the interior There are two commonly used fill rules Even-odd parity rule Non-zero winding rule Filled using even-odd parity ruleFilled using none-zero winding rule

Even-odd Parity Rule To determine if a point P is inside or outside Draw a line from P to infinity Count the number of times the line crosses an edge If the number of crossing is odd, the point is inside If the number of crossing is even, the point is outside

Non-zero Winding Number Rule The outline of the shape must be directed The line segments must have a consistent direction so that they formed a continuous, closed path

Non-zero Winding Number Rule To determine if a points is inside or outside Determine the winding number (i.e. the number of times the edge winds around the point in either a clockwise or counterclockwise direction) Points are outside if the winding number is zero Point are inside if the winding number is not zero

Non-zero Winding Number Rule To determine the winding number at a point P Initialize the winding number to zero and draw a line (e.g. horizontal) from P to infinity If the line crosses an edge directed bottom to up Add 1 to the winding number If the line crosses an edge directed top to bottom Subtract 1 from the winding number

Inside-Outside Tests The non-zero winding number rule and the even-odd parity rule can give different results for general polygons When polygons self intersect When polygons have interior holes Even-odd parityNon-zero winding

Inside-Outside Tests Standard polygons Standard polygons (e.g. triangles, rectangles, octagons) do not self intersect and do not contain holes The non-zero winding number rule and the even-odd parity rule give the same results for standard polygons

Shared Vertices Edges share vertices If the line drawn for the fill rule intersects a vertex, the edge crossing would be counted twice This yields incorrect and inconsistent even-odd parity checks and winding numbers Line pierces the outline - Should count as one crossing Line grazes the outline - Should count as no crossings

Dealing with Shared Vertices 1. Check the vertex type (piercing or grazing) If the vertex is between two upwards or two downwards edges, the line pierces the edge Process a single edge crossing If the vertex is between an upwards and a downwards edge, the line grazes the vertex Don’t process any edge crossings Vertex between two upwards edges - Process a single crossing Vertex between upwards and downwards edges - Process no crossings

Dealing with Shared Vertices 2. Ensure that the line does not intersect a vertex Use a different line if the first line intersects a vertex Could be costly if you have to try several lines If using horizontal scan line for the inside-outside test Preprocess edge vertices to make sure that none of them fall on a scan line Add a small floating point value to each vertex y-position

Filling Polygons via Boundary Fill Polygons are defined by their edges

Filling Polygons via Boundary Fill Polygons are defined by their edges Use a line drawing algorithm to draw edges of the polygon with a boundary color

Filling Polygons via Boundary Fill Polygons are defined by their edges Fill the inside of the polygon using a boundary fill

Filling Polygons via Boundary Fill Problems 1.Pixels are drawn on both sides of the line The polygon contains pixels outside of the outline Polygons with shared edges will have overlapping pixels 2.Efficiency Drawing outlines and then filling can be less efficient that combining the edge drawing and filling in one step

Raster-Based Filling Fill polygons in raster-scan order Fill spans of pixels inside the polygon along each horizontal scan line More efficient addressing by accessing spans of pixels Only test pixels at the span endpoints

Raster-Based Filling For each scan line Determine points where the scan line intersects the polygon

Raster-Based Filling For each scan line Set pixels between intersection points (using a fill rule) Even-odd parity rule: set pixels between pairs of intersections Non-zero winding rule: set pixels according to the winding number

Raster-Based Filling Basic algorithm (with even-odd parity rule) for (each scan line, j) { find the x-intersections between the scan line and each edge sort the x-intersections by increasing x-value for (each pair of intersection points, x1 and x2) { while (x1 < i < x2) setPixel(i, j, fillColor) }

Conventions for Setting Edge Pixels Adjacent polygons share edges When rendered, some pixels along the edges are shared Need to know what color to use for shared edge pixels

Conventions for Setting Edge Pixels If we draw all edge pixels for each polygon Shared pixels will be rendered more than once If setPixel() overwrites the current pixel, the last polygon drawn will look larger Green triangle written last

Conventions for Setting Edge Pixels If we draw all edge pixels for each polygon Shared pixels will be rendered more than once If setPixel() overwrites the current pixel, the last polygon drawn will look larger Blue triangle written last

Conventions for Setting Edge Pixels If we draw all edge pixels for each polygon Shared pixels will be rendered more than once If setPixel() blends the background color with the foreground color, shared edge pixels will have a blended color Edge color different than either triangle

Conventions for Setting Edge Pixels If we draw none of the edge pixels Only interior pixels are drawn Gaps appear between polygons and the background shows through Gaps between adjacent triangles