SlideShare uma empresa Scribd logo
1 de 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.

Mais conteúdo relacionado

Mais procurados

Intro to scan conversion
Intro to scan conversionIntro to scan conversion
Intro to scan conversionMohd Arif
 
Raster scan system
Raster scan systemRaster scan system
Raster scan systemMohd Arif
 
Polygon clipping
Polygon clippingPolygon clipping
Polygon clippingMohd Arif
 
Seed filling algorithm
Seed filling algorithmSeed filling algorithm
Seed filling algorithmMani Kanth
 
Overview of the graphics system
Overview of the graphics systemOverview of the graphics system
Overview of the graphics systemKamal Acharya
 
Visible surface detection in computer graphic
Visible surface detection in computer graphicVisible surface detection in computer graphic
Visible surface detection in computer graphicanku2266
 
Random scan displays and raster scan displays
Random scan displays and raster scan displaysRandom scan displays and raster scan displays
Random scan displays and raster scan displaysSomya Bagai
 
The sutherland hodgeman polygon clipping algorithm
The sutherland hodgeman polygon clipping algorithmThe sutherland hodgeman polygon clipping algorithm
The sutherland hodgeman polygon clipping algorithmMani Kanth
 
Graphics software and standards
Graphics software and standardsGraphics software and standards
Graphics software and standardsMani Kanth
 
Monitors & workstation,Donald ch-2
Monitors & workstation,Donald ch-2Monitors & workstation,Donald ch-2
Monitors & workstation,Donald ch-2Iftikhar Ahmad
 
Raster scan systems with video controller and display processor
Raster scan systems with video controller and display processorRaster scan systems with video controller and display processor
Raster scan systems with video controller and display processorhemanth kumar
 
Line drawing algo.
Line drawing algo.Line drawing algo.
Line drawing algo.Mohd Arif
 
Clipping in Computer Graphics
Clipping in Computer GraphicsClipping in Computer Graphics
Clipping in Computer GraphicsLaxman Puri
 
Composite transformations
Composite transformationsComposite transformations
Composite transformationsMohd Arif
 

Mais procurados (20)

Intro to scan conversion
Intro to scan conversionIntro to scan conversion
Intro to scan conversion
 
Clipping
ClippingClipping
Clipping
 
Raster scan system
Raster scan systemRaster scan system
Raster scan system
 
Frame buffer
Frame bufferFrame buffer
Frame buffer
 
Polygon clipping
Polygon clippingPolygon clipping
Polygon clipping
 
Seed filling algorithm
Seed filling algorithmSeed filling algorithm
Seed filling algorithm
 
Overview of the graphics system
Overview of the graphics systemOverview of the graphics system
Overview of the graphics system
 
lecture2 computer graphics graphics hardware(Computer graphics tutorials)
 lecture2  computer graphics graphics hardware(Computer graphics tutorials) lecture2  computer graphics graphics hardware(Computer graphics tutorials)
lecture2 computer graphics graphics hardware(Computer graphics tutorials)
 
Visible surface detection in computer graphic
Visible surface detection in computer graphicVisible surface detection in computer graphic
Visible surface detection in computer graphic
 
Depth Buffer Method
Depth Buffer MethodDepth Buffer Method
Depth Buffer Method
 
Random scan displays and raster scan displays
Random scan displays and raster scan displaysRandom scan displays and raster scan displays
Random scan displays and raster scan displays
 
The sutherland hodgeman polygon clipping algorithm
The sutherland hodgeman polygon clipping algorithmThe sutherland hodgeman polygon clipping algorithm
The sutherland hodgeman polygon clipping algorithm
 
Graphics software and standards
Graphics software and standardsGraphics software and standards
Graphics software and standards
 
Monitors & workstation,Donald ch-2
Monitors & workstation,Donald ch-2Monitors & workstation,Donald ch-2
Monitors & workstation,Donald ch-2
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Raster scan systems with video controller and display processor
Raster scan systems with video controller and display processorRaster scan systems with video controller and display processor
Raster scan systems with video controller and display processor
 
Line drawing algo.
Line drawing algo.Line drawing algo.
Line drawing algo.
 
Clipping in Computer Graphics
Clipping in Computer GraphicsClipping in Computer Graphics
Clipping in Computer Graphics
 
Spline representations
Spline representationsSpline representations
Spline representations
 
Composite transformations
Composite transformationsComposite transformations
Composite transformations
 

Destaque (9)

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
 

Semelhante a Fill area algorithms

Polygon filling algorithm
Polygon filling algorithmPolygon filling algorithm
Polygon filling algorithmAparna Joshi
 
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
 
Polygon filling
Polygon fillingPolygon filling
Polygon fillingAnkit Garg
 
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
 

Semelhante a Fill area algorithms (20)

Polygon filling algorithm
Polygon filling algorithmPolygon filling algorithm
Polygon filling algorithm
 
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
 
Polygon filling
Polygon fillingPolygon filling
Polygon filling
 
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
 

Mais de 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
 

Mais de 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
 

Último

Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
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
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
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
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 

Último (20)

Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
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
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
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
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 

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.