SlideShare ist ein Scribd-Unternehmen logo
1 von 45
Fill Area Algorithms
Jan. 2008
Polygon Fill Algorithm
• Different types of Polygons
– Simple Convex
– Simple Concave
– Non-simple : self-intersecting
– With holes
Convex Concave Self-intersecting
Polygon Fill Algorithm
• A scan-line fill algorithm of a region is
performed as follows:
1. Determining the intersection positions of the
boundaries of the fill region with the screen scan
lines.
2. Then the fill colors are applied to each section of a
scan line that lies within the interior of the fill region.
• The simplest area to fill is a polygon, because
each scan-line intersection point with a polygon
boundary is obtained by solving a pair of
simultaneous linear equations, where the
equation for the scan line is simply y = constant.
Example
• Consider the following polygon:
Example
• For each scan line that crosses the polygon, the
edge intersections are sorted from left to right,
and then the pixel positions between, and
including, each intersection pair are set to the
specified fill color.
• In the previous Figure, the four pixel intersection
positions with the polygon boundaries define two
stretches of interior pixels.
Example
• The fill color is applied to the five pixels:
–from x = 10 to x = 14
and
• To the seven pixels
–from x = 18 to x = 24.
Polygon Fill Algorithm
• However, the scan-line fill algorithm for a
polygon is not quite as simple
• Whenever a scan line passes through a
vertex, it intersects two polygon edges at
that point.
• In some cases, this can result in an odd
number of boundary intersections for a
scan line.
Polygon Fill Algorithm
• Consider the next Figure.
• It shows two scan lines that cross a
polygon fill area and intersect a vertex.
• Scan line y’ intersects an even number of
edges, and the two pairs of intersection
points along this scan line correctly
identify the interior pixel spans.
• But scan line y intersects five polygon
edges.
Polygon Fill Algorithm
Polygon Fill Algorithm
• To identify the interior pixels for scan line
y, we must count the vertex intersection as
only one point.
• Thus, as we process scan lines, we need
to distinguish between these two cases.
Polygon Fill Algorithm
• We can detect the difference between the
two cases by noting the position of the
intersecting edges relative to the scan line.
• For scan line y, the two edges sharing an
intersection vertex are on opposite sides
of the scan line.
• But for scan line y’, the two intersecting
edges are both above the scan line.
Polygon Fill Algorithm
• A vertex that has adjoining edges on opposite
sides of an intersecting scan line should be
counted as just one boundary intersection point.
• We can identify these vertices by tracing around
the polygon boundary in either clockwise or
counterclockwise order and observing the
relative changes in vertex y coordinates as we
move from one edge to the next.
Polygon Fill Algorithm
• If the three endpoint y values of two consecutive
edges increase or decrease, we need to count
the shared (middle) vertex as a single
intersection point for the scan line passing
through that vertex.
• Otherwise, the shared vertex represents a local
extremum (minimum or maximum) on the
polygon boundary, and the two edge
intersections with the scan line passing through
that vertex can be added to the intersection list.
Area Fill Algorithm
• An alternative approach for filling an area is to
start at a point inside the area and “paint” the
interior, point by point, out to the boundary.
• This is a particularly useful technique for filling
areas with irregular borders, such as a design
created with a paint program.
• The algorithm makes the following assumptions
– one interior pixel is known, and
– pixels in boundary are known.
Area Fill Algorithm
• If the boundary of some region is specified
in a single color, we can fill the interior of
this region, pixel by pixel, until the
boundary color is encountered.
• This method, called the boundary-fill
algorithm, is employed in interactive
painting packages, where interior points
are easily selected.
Example
• One can sketch a figure outline, and pick
an interior point.
• The figure interior is then painted in the fill
color as shown in these Figures
Area Fill Algorithm
• Basically, a boundary-fill algorithm starts
from an interior point (x, y) and sets the
neighboring points to the desired color.
• This procedure continues until all pixels
are processed up to the designated
boundary for the area.
Area Fill Algorithm
• There are two methods for processing
neighboring pixels from a current point.
1. Four neighboring points.
– These are the pixel positions that are right,
left, above, and below the current pixel.
– Areas filled by this method are called 4-
connected.
Area Fill Algorithm
2. Eight neighboring points.
– This method is used to fill more complex
figures.
– Here the set of neighboring points to be set
includes the four diagonal pixels, in addition to
the four points in the first method.
– Fill methods using this approach are called 8-
connected.
Area Fill Algorithm
Area Fill Algorithm
• Consider the Figure in the next slide.
• An 8-connected boundary-fill algorithm
would correctly fill the interior of the area
defined in the Figure.
• But a 4-connected boundary-fill algorithm
would only fill part of that region.
Area Fill Algorithm
Area Fill Algorithm
• The following procedure illustrates a recursive
method for painting a 4-connected area with a
solid color, specified in parameter fillColor, up
to a boundary color specified with parameter
borderColor.
• We can extend this procedure to fill an 8-
connected region by including four additional
statements to test the diagonal positions (x ± 1,
y ± 1).
Area Fill Algorithm
Area Fill Algorithm
• Some times we want to fill in (or recolor)
an area that is not defined within a single
color boundary.
• Consider the following Figure.
Area Fill Algorithm
• We can paint such areas by replacing a
specified interior color instead of
searching for a particular boundary color.
• This fill procedure is called a flood-fill
algorithm.
Area Fill Algorithm
• We start from a specified interior point (x,
y) and reassign all pixel values that are
currently set to a given interior color with
the desired fill color.
• If the area we want to paint has more than
one interior color, we can first reassign
pixel values so that all interior points have
the same color.
Area Fill Algorithm
• Using either a 4-connected or 8-
connected approach, we then step
through pixel positions until all interior
points have been repainted.
• The following procedure flood fills a 4-
connected region recursively, starting from
the input position.
Area Fill Algorithm
Problems with Fill Algorithm (1)
• Recursive boundary-fill algorithms may not
fill regions correctly if some interior pixels
are already displayed in the fill color.
• This occurs because the algorithm checks
next pixels both for boundary color and for
fill color.
Problems with Fill Algorithm
• To avoid this, we can first change the
color of any interior pixels that are initially
set to the fill color before applying the
boundary-fill procedure.
• Encountering a pixel with the fill color can
cause a recursive branch to terminate,
leaving other interior pixels unfilled.
Problems with Fill Algorithm (2)
• This procedure requires considerable
stacking of neighboring points, more
efficient methods are generally employed.
• These methods fill horizontal pixel spans
across scan lines, instead of proceeding to
4-connected or 8-connected neighboring
points.
Problems with Fill Algorithm (2)
• Then we need only stack a beginning
position for each horizontal pixel span,
instead of stacking all unprocessed
neighboring positions around the current
position.
• Starting from the initial interior point with
this method, we first fill in the contiguous
span of pixels on this starting scan line.
Problems with Fill Algorithm (2)
• Then we locate and stack starting
positions for spans on the adjacent scan
lines, where spans are defined as the
contiguous horizontal string of positions
bounded by pixels displayed in the border
color.
• At each subsequent step, we retrieve the
next start position from the top of the stack
and repeat the process.
Area Fill Algorithm
The algorithm can be summarized as follows:
1. define seed point,
2. fill scan line containing seed point,
3. for scan lines above and below, define new seed
points as:
i) first point inside left boundary,
ii) subsequent points within boundary whose left neighbor is
outside,
4. d) repeat algorithm with the new set of seed points.
Example
• In this example, we first process scan lines
successively from the start line to the top
boundary.
• After all upper scan lines are processed, we fill
in the pixel spans on the remaining scan lines in
order down to the bottom boundary.
• The leftmost pixel position for each horizontal
span is located and stacked, in left to right order
across successive scan lines.
Example
• In (a) of this figure, the initial span has
been filled, and starting positions 1 and 2
for spans on the next scan lines (below
and above) are stacked.
Example
• In Fig.(b), position 2 has been unstacked
and processed to produce the filled span
shown, and the starting pixel (position 3)
for the single span on the next scan line
has been stacked.
Example
• After position 3 is processed, the filled
spans and stacked positions are as shown
in Fig. (c).
Example
• And Fig.(d) shows the filled pixels after
processing all spans in the upper right of
the specified area.
Example
• Position 5 is next processed, and spans
are filled in the upper left of the region;
then position 4 is picked up to continue the
processing for the lower scan lines.
Example
• Finish up the upper scan lines.
Example
• Start the bottom scan lines.
Example
• Finish up the bottom scan lines.
Example
• Finish up the bottom scan lines.

Weitere ähnliche Inhalte

Was ist angesagt?

Polygon filling algorithm
Polygon filling algorithmPolygon filling algorithm
Polygon filling algorithmAparna Joshi
 
Clipping computer graphics
Clipping  computer graphicsClipping  computer graphics
Clipping computer graphicsShaishavShah8
 
sutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clippingsutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clippingArvind Kumar
 
Attributes of Output Primitives
Attributes of Output PrimitivesAttributes of Output Primitives
Attributes of Output PrimitivesRenita Santhmayora
 
Cyrus beck line clipping algorithm
Cyrus beck line clipping algorithmCyrus beck line clipping algorithm
Cyrus beck line clipping algorithmPooja Dixit
 
Overview of the graphics system
Overview of the graphics systemOverview of the graphics system
Overview of the graphics systemKamal Acharya
 
Attributes of output primitive(line attributes)
Attributes of output primitive(line attributes)Attributes of output primitive(line attributes)
Attributes of output primitive(line attributes)shalinikarunakaran1
 
Anti- aliasing computer graphics
Anti- aliasing computer graphicsAnti- aliasing computer graphics
Anti- aliasing computer graphicsSafayet Hossain
 
Seed filling algorithm
Seed filling algorithmSeed filling algorithm
Seed filling algorithmMani Kanth
 
Polygon filling
Polygon fillingPolygon filling
Polygon fillingAnkit Garg
 
Visible surface detection in computer graphic
Visible surface detection in computer graphicVisible surface detection in computer graphic
Visible surface detection in computer graphicanku2266
 
Overview of Graphics System
Overview of Graphics SystemOverview of Graphics System
Overview of Graphics SystemPrathimaBaliga
 
Unit 3
Unit 3Unit 3
Unit 3ypnrao
 
Raster scan system & random scan system
Raster scan system & random scan systemRaster scan system & random scan system
Raster scan system & random scan systemshalinikarunakaran1
 
Raster Scan And Random Scan
Raster Scan And Random ScanRaster Scan And Random Scan
Raster Scan And Random ScanDevika Rangnekar
 
Computer graphics basic transformation
Computer graphics basic transformationComputer graphics basic transformation
Computer graphics basic transformationSelvakumar Gna
 

Was ist angesagt? (20)

Clipping
ClippingClipping
Clipping
 
Polygon filling algorithm
Polygon filling algorithmPolygon filling algorithm
Polygon filling algorithm
 
Clipping computer graphics
Clipping  computer graphicsClipping  computer graphics
Clipping computer graphics
 
sutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clippingsutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clipping
 
Attributes of Output Primitives
Attributes of Output PrimitivesAttributes of Output Primitives
Attributes of Output Primitives
 
Cyrus beck line clipping algorithm
Cyrus beck line clipping algorithmCyrus beck line clipping algorithm
Cyrus beck line clipping algorithm
 
Overview of the graphics system
Overview of the graphics systemOverview of the graphics system
Overview of the graphics system
 
Attributes of output primitive(line attributes)
Attributes of output primitive(line attributes)Attributes of output primitive(line attributes)
Attributes of output primitive(line attributes)
 
Anti- aliasing computer graphics
Anti- aliasing computer graphicsAnti- aliasing computer graphics
Anti- aliasing computer graphics
 
Seed filling algorithm
Seed filling algorithmSeed filling algorithm
Seed filling algorithm
 
Polygon filling
Polygon fillingPolygon filling
Polygon filling
 
Visible surface detection in computer graphic
Visible surface detection in computer graphicVisible surface detection in computer graphic
Visible surface detection in computer graphic
 
Overview of Graphics System
Overview of Graphics SystemOverview of Graphics System
Overview of Graphics System
 
Unit 3
Unit 3Unit 3
Unit 3
 
3 d display methods
3 d display methods3 d display methods
3 d display methods
 
Raster scan system & random scan system
Raster scan system & random scan systemRaster scan system & random scan system
Raster scan system & random scan system
 
Frame buffer
Frame bufferFrame buffer
Frame buffer
 
Raster Scan And Random Scan
Raster Scan And Random ScanRaster Scan And Random Scan
Raster Scan And Random Scan
 
Computer graphics basic transformation
Computer graphics basic transformationComputer graphics basic transformation
Computer graphics basic transformation
 
Illumination Models & Shading
Illumination Models & ShadingIllumination Models & Shading
Illumination Models & Shading
 

Andere mochten auch

Andere mochten auch (10)

Backtracking
BacktrackingBacktracking
Backtracking
 
Hamiltonian path
Hamiltonian pathHamiltonian path
Hamiltonian path
 
Euler and hamilton paths
Euler and hamilton pathsEuler and hamilton paths
Euler and hamilton paths
 
Polygon filling
Polygon fillingPolygon filling
Polygon filling
 
Backtracking
BacktrackingBacktracking
Backtracking
 
backtracking algorithms of ada
backtracking algorithms of adabacktracking algorithms of ada
backtracking algorithms of ada
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
 
Lecture filling algorithms
Lecture  filling algorithmsLecture  filling algorithms
Lecture filling algorithms
 
Polygon Fill
Polygon FillPolygon Fill
Polygon Fill
 
Area filling algo
Area filling algoArea filling algo
Area filling algo
 

Ähnlich wie Fill area algorithms

CS401_M2_L6_Solid Area Scan Conversion.pptx
CS401_M2_L6_Solid Area Scan Conversion.pptxCS401_M2_L6_Solid Area Scan Conversion.pptx
CS401_M2_L6_Solid Area Scan Conversion.pptxlara333479
 
ATTRIBUTES OF OUTPUT PRIMITIVES IN COMPUTER GRAPHICS
ATTRIBUTES OF OUTPUT PRIMITIVES IN COMPUTER GRAPHICSATTRIBUTES OF OUTPUT PRIMITIVES IN COMPUTER GRAPHICS
ATTRIBUTES OF OUTPUT PRIMITIVES IN COMPUTER GRAPHICSnehrurevathy
 
B. SC CSIT Computer Graphics Unit 1.3 By Tekendra Nath Yogi
B. SC CSIT Computer Graphics Unit 1.3 By Tekendra Nath YogiB. SC CSIT Computer Graphics Unit 1.3 By Tekendra Nath Yogi
B. SC CSIT Computer Graphics Unit 1.3 By Tekendra Nath YogiTekendra Nath Yogi
 
Hidden surface removal
Hidden surface removalHidden surface removal
Hidden surface removalAnkit Garg
 
Image representation
Image representationImage representation
Image representationRahul Dadwal
 
Hidden surface removal algorithm
Hidden surface removal algorithmHidden surface removal algorithm
Hidden surface removal algorithmKKARUNKARTHIK
 
2 d viewing computer graphics
2 d viewing computer graphics2 d viewing computer graphics
2 d viewing computer graphicsKALESHWAR KUMAR
 
region-filling
region-fillingregion-filling
region-fillingKumar
 
Bidirectional graph search techniques for finding shortest path in image base...
Bidirectional graph search techniques for finding shortest path in image base...Bidirectional graph search techniques for finding shortest path in image base...
Bidirectional graph search techniques for finding shortest path in image base...Navin Kumar
 

Ähnlich wie Fill area algorithms (20)

CS401_M2_L6_Solid Area Scan Conversion.pptx
CS401_M2_L6_Solid Area Scan Conversion.pptxCS401_M2_L6_Solid Area Scan Conversion.pptx
CS401_M2_L6_Solid Area Scan Conversion.pptx
 
attribute.pptx
attribute.pptxattribute.pptx
attribute.pptx
 
ATTRIBUTES OF OUTPUT PRIMITIVES IN COMPUTER GRAPHICS
ATTRIBUTES OF OUTPUT PRIMITIVES IN COMPUTER GRAPHICSATTRIBUTES OF OUTPUT PRIMITIVES IN COMPUTER GRAPHICS
ATTRIBUTES OF OUTPUT PRIMITIVES IN COMPUTER GRAPHICS
 
Unit-2 PPT.ppt
Unit-2 PPT.pptUnit-2 PPT.ppt
Unit-2 PPT.ppt
 
B. SC CSIT Computer Graphics Unit 1.3 By Tekendra Nath Yogi
B. SC CSIT Computer Graphics Unit 1.3 By Tekendra Nath YogiB. SC CSIT Computer Graphics Unit 1.3 By Tekendra Nath Yogi
B. SC CSIT Computer Graphics Unit 1.3 By Tekendra Nath Yogi
 
14485616.ppt
14485616.ppt14485616.ppt
14485616.ppt
 
cg mod2.pdf
cg mod2.pdfcg mod2.pdf
cg mod2.pdf
 
UNIT2.pptx
UNIT2.pptxUNIT2.pptx
UNIT2.pptx
 
Hidden surface removal
Hidden surface removalHidden surface removal
Hidden surface removal
 
99995327.ppt
99995327.ppt99995327.ppt
99995327.ppt
 
CSO PPT.pptx
CSO PPT.pptxCSO PPT.pptx
CSO PPT.pptx
 
ch4.pptx
ch4.pptxch4.pptx
ch4.pptx
 
Image representation
Image representationImage representation
Image representation
 
1516 contouring
1516 contouring1516 contouring
1516 contouring
 
Hidden surface removal algorithm
Hidden surface removal algorithmHidden surface removal algorithm
Hidden surface removal algorithm
 
Boundary fill algm
Boundary fill algmBoundary fill algm
Boundary fill algm
 
2 d viewing computer graphics
2 d viewing computer graphics2 d viewing computer graphics
2 d viewing computer graphics
 
region-filling
region-fillingregion-filling
region-filling
 
Bidirectional graph search techniques for finding shortest path in image base...
Bidirectional graph search techniques for finding shortest path in image base...Bidirectional graph search techniques for finding shortest path in image base...
Bidirectional graph search techniques for finding shortest path in image base...
 
Lane Detection
Lane DetectionLane Detection
Lane Detection
 

Mehr von Kumar

Graphics devices
Graphics devicesGraphics devices
Graphics devicesKumar
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivationKumar
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons dericationKumar
 
Introductionto xslt
Introductionto xsltIntroductionto xslt
Introductionto xsltKumar
 
Extracting data from xml
Extracting data from xmlExtracting data from xml
Extracting data from xmlKumar
 
Xml basics
Xml basicsXml basics
Xml basicsKumar
 
XML Schema
XML SchemaXML Schema
XML SchemaKumar
 
Publishing xml
Publishing xmlPublishing xml
Publishing xmlKumar
 
Applying xml
Applying xmlApplying xml
Applying xmlKumar
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XMLKumar
 
How to deploy a j2ee application
How to deploy a j2ee applicationHow to deploy a j2ee application
How to deploy a j2ee applicationKumar
 
JNDI, JMS, JPA, XML
JNDI, JMS, JPA, XMLJNDI, JMS, JPA, XML
JNDI, JMS, JPA, XMLKumar
 
EJB Fundmentals
EJB FundmentalsEJB Fundmentals
EJB FundmentalsKumar
 
JSP and struts programming
JSP and struts programmingJSP and struts programming
JSP and struts programmingKumar
 
java servlet and servlet programming
java servlet and servlet programmingjava servlet and servlet programming
java servlet and servlet programmingKumar
 
Introduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversIntroduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversKumar
 
Introduction to J2EE
Introduction to J2EEIntroduction to J2EE
Introduction to J2EEKumar
 
Android tutorial (2)
Android tutorial (2)Android tutorial (2)
Android tutorial (2)Kumar
 
Android structure
Android structureAndroid structure
Android structureKumar
 

Mehr von Kumar (20)

Graphics devices
Graphics devicesGraphics devices
Graphics devices
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivation
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons derication
 
Introductionto xslt
Introductionto xsltIntroductionto xslt
Introductionto xslt
 
Extracting data from xml
Extracting data from xmlExtracting data from xml
Extracting data from xml
 
Xml basics
Xml basicsXml basics
Xml basics
 
XML Schema
XML SchemaXML Schema
XML Schema
 
Publishing xml
Publishing xmlPublishing xml
Publishing xml
 
DTD
DTDDTD
DTD
 
Applying xml
Applying xmlApplying xml
Applying xml
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
How to deploy a j2ee application
How to deploy a j2ee applicationHow to deploy a j2ee application
How to deploy a j2ee application
 
JNDI, JMS, JPA, XML
JNDI, JMS, JPA, XMLJNDI, JMS, JPA, XML
JNDI, JMS, JPA, XML
 
EJB Fundmentals
EJB FundmentalsEJB Fundmentals
EJB Fundmentals
 
JSP and struts programming
JSP and struts programmingJSP and struts programming
JSP and struts programming
 
java servlet and servlet programming
java servlet and servlet programmingjava servlet and servlet programming
java servlet and servlet programming
 
Introduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversIntroduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC Drivers
 
Introduction to J2EE
Introduction to J2EEIntroduction to J2EE
Introduction to J2EE
 
Android tutorial (2)
Android tutorial (2)Android tutorial (2)
Android tutorial (2)
 
Android structure
Android structureAndroid structure
Android structure
 

Kürzlich hochgeladen

General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxNikitaBankoti2
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIShubhangi Sonawane
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 

Kürzlich hochgeladen (20)

General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 

Fill area algorithms

  • 2. Polygon Fill Algorithm • Different types of Polygons – Simple Convex – Simple Concave – Non-simple : self-intersecting – With holes Convex Concave Self-intersecting
  • 3. Polygon Fill Algorithm • A scan-line fill algorithm of a region is performed as follows: 1. Determining the intersection positions of the boundaries of the fill region with the screen scan lines. 2. Then the fill colors are applied to each section of a scan line that lies within the interior of the fill region. • The simplest area to fill is a polygon, because each scan-line intersection point with a polygon boundary is obtained by solving a pair of simultaneous linear equations, where the equation for the scan line is simply y = constant.
  • 4. Example • Consider the following polygon:
  • 5. Example • For each scan line that crosses the polygon, the edge intersections are sorted from left to right, and then the pixel positions between, and including, each intersection pair are set to the specified fill color. • In the previous Figure, the four pixel intersection positions with the polygon boundaries define two stretches of interior pixels.
  • 6. Example • The fill color is applied to the five pixels: –from x = 10 to x = 14 and • To the seven pixels –from x = 18 to x = 24.
  • 7. Polygon Fill Algorithm • However, the scan-line fill algorithm for a polygon is not quite as simple • Whenever a scan line passes through a vertex, it intersects two polygon edges at that point. • In some cases, this can result in an odd number of boundary intersections for a scan line.
  • 8. Polygon Fill Algorithm • Consider the next Figure. • It shows two scan lines that cross a polygon fill area and intersect a vertex. • Scan line y’ intersects an even number of edges, and the two pairs of intersection points along this scan line correctly identify the interior pixel spans. • But scan line y intersects five polygon edges.
  • 10. Polygon Fill Algorithm • To identify the interior pixels for scan line y, we must count the vertex intersection as only one point. • Thus, as we process scan lines, we need to distinguish between these two cases.
  • 11. Polygon Fill Algorithm • We can detect the difference between the two cases by noting the position of the intersecting edges relative to the scan line. • For scan line y, the two edges sharing an intersection vertex are on opposite sides of the scan line. • But for scan line y’, the two intersecting edges are both above the scan line.
  • 12. Polygon Fill Algorithm • A vertex that has adjoining edges on opposite sides of an intersecting scan line should be counted as just one boundary intersection point. • We can identify these vertices by tracing around the polygon boundary in either clockwise or counterclockwise order and observing the relative changes in vertex y coordinates as we move from one edge to the next.
  • 13. Polygon Fill Algorithm • If the three endpoint y values of two consecutive edges increase or decrease, we need to count the shared (middle) vertex as a single intersection point for the scan line passing through that vertex. • Otherwise, the shared vertex represents a local extremum (minimum or maximum) on the polygon boundary, and the two edge intersections with the scan line passing through that vertex can be added to the intersection list.
  • 14. Area Fill Algorithm • An alternative approach for filling an area is to start at a point inside the area and “paint” the interior, point by point, out to the boundary. • This is a particularly useful technique for filling areas with irregular borders, such as a design created with a paint program. • The algorithm makes the following assumptions – one interior pixel is known, and – pixels in boundary are known.
  • 15. Area Fill Algorithm • If the boundary of some region is specified in a single color, we can fill the interior of this region, pixel by pixel, until the boundary color is encountered. • This method, called the boundary-fill algorithm, is employed in interactive painting packages, where interior points are easily selected.
  • 16. Example • One can sketch a figure outline, and pick an interior point. • The figure interior is then painted in the fill color as shown in these Figures
  • 17. Area Fill Algorithm • Basically, a boundary-fill algorithm starts from an interior point (x, y) and sets the neighboring points to the desired color. • This procedure continues until all pixels are processed up to the designated boundary for the area.
  • 18. Area Fill Algorithm • There are two methods for processing neighboring pixels from a current point. 1. Four neighboring points. – These are the pixel positions that are right, left, above, and below the current pixel. – Areas filled by this method are called 4- connected.
  • 19. Area Fill Algorithm 2. Eight neighboring points. – This method is used to fill more complex figures. – Here the set of neighboring points to be set includes the four diagonal pixels, in addition to the four points in the first method. – Fill methods using this approach are called 8- connected.
  • 21. Area Fill Algorithm • Consider the Figure in the next slide. • An 8-connected boundary-fill algorithm would correctly fill the interior of the area defined in the Figure. • But a 4-connected boundary-fill algorithm would only fill part of that region.
  • 23. Area Fill Algorithm • The following procedure illustrates a recursive method for painting a 4-connected area with a solid color, specified in parameter fillColor, up to a boundary color specified with parameter borderColor. • We can extend this procedure to fill an 8- connected region by including four additional statements to test the diagonal positions (x ± 1, y ± 1).
  • 25. Area Fill Algorithm • Some times we want to fill in (or recolor) an area that is not defined within a single color boundary. • Consider the following Figure.
  • 26. Area Fill Algorithm • We can paint such areas by replacing a specified interior color instead of searching for a particular boundary color. • This fill procedure is called a flood-fill algorithm.
  • 27. Area Fill Algorithm • We start from a specified interior point (x, y) and reassign all pixel values that are currently set to a given interior color with the desired fill color. • If the area we want to paint has more than one interior color, we can first reassign pixel values so that all interior points have the same color.
  • 28. Area Fill Algorithm • Using either a 4-connected or 8- connected approach, we then step through pixel positions until all interior points have been repainted. • The following procedure flood fills a 4- connected region recursively, starting from the input position.
  • 30. Problems with Fill Algorithm (1) • Recursive boundary-fill algorithms may not fill regions correctly if some interior pixels are already displayed in the fill color. • This occurs because the algorithm checks next pixels both for boundary color and for fill color.
  • 31. Problems with Fill Algorithm • To avoid this, we can first change the color of any interior pixels that are initially set to the fill color before applying the boundary-fill procedure. • Encountering a pixel with the fill color can cause a recursive branch to terminate, leaving other interior pixels unfilled.
  • 32. Problems with Fill Algorithm (2) • This procedure requires considerable stacking of neighboring points, more efficient methods are generally employed. • These methods fill horizontal pixel spans across scan lines, instead of proceeding to 4-connected or 8-connected neighboring points.
  • 33. Problems with Fill Algorithm (2) • Then we need only stack a beginning position for each horizontal pixel span, instead of stacking all unprocessed neighboring positions around the current position. • Starting from the initial interior point with this method, we first fill in the contiguous span of pixels on this starting scan line.
  • 34. Problems with Fill Algorithm (2) • Then we locate and stack starting positions for spans on the adjacent scan lines, where spans are defined as the contiguous horizontal string of positions bounded by pixels displayed in the border color. • At each subsequent step, we retrieve the next start position from the top of the stack and repeat the process.
  • 35. Area Fill Algorithm The algorithm can be summarized as follows: 1. define seed point, 2. fill scan line containing seed point, 3. for scan lines above and below, define new seed points as: i) first point inside left boundary, ii) subsequent points within boundary whose left neighbor is outside, 4. d) repeat algorithm with the new set of seed points.
  • 36. Example • In this example, we first process scan lines successively from the start line to the top boundary. • After all upper scan lines are processed, we fill in the pixel spans on the remaining scan lines in order down to the bottom boundary. • The leftmost pixel position for each horizontal span is located and stacked, in left to right order across successive scan lines.
  • 37. Example • In (a) of this figure, the initial span has been filled, and starting positions 1 and 2 for spans on the next scan lines (below and above) are stacked.
  • 38. Example • In Fig.(b), position 2 has been unstacked and processed to produce the filled span shown, and the starting pixel (position 3) for the single span on the next scan line has been stacked.
  • 39. Example • After position 3 is processed, the filled spans and stacked positions are as shown in Fig. (c).
  • 40. Example • And Fig.(d) shows the filled pixels after processing all spans in the upper right of the specified area.
  • 41. Example • Position 5 is next processed, and spans are filled in the upper left of the region; then position 4 is picked up to continue the processing for the lower scan lines.
  • 42. Example • Finish up the upper scan lines.
  • 43. Example • Start the bottom scan lines.
  • 44. Example • Finish up the bottom scan lines.
  • 45. Example • Finish up the bottom scan lines.