SlideShare a Scribd company logo
1 of 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.

More Related Content

What's hot

Back face detection
Back face detectionBack face detection
Back face detectionPooja Dixit
 
Polygon filling
Polygon fillingPolygon filling
Polygon fillingAnkit Garg
 
Liang barsky Line Clipping Algorithm
Liang barsky Line Clipping AlgorithmLiang barsky Line Clipping Algorithm
Liang barsky Line Clipping AlgorithmArvind Kumar
 
Raster scan system
Raster scan systemRaster scan system
Raster scan systemMohd Arif
 
Area filling algo
Area filling algoArea filling algo
Area filling algoPrince Soni
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer GraphicsKamal Acharya
 
Window to viewport transformation
Window to viewport transformationWindow to viewport transformation
Window to viewport transformationAnkit Garg
 
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
 
Computer graphics chapter 4
Computer graphics chapter 4Computer graphics chapter 4
Computer graphics chapter 4PrathimaBaliga
 
Polygon Fill
Polygon FillPolygon Fill
Polygon Fillwahab13
 
Attributes of Output Primitives
Attributes of Output PrimitivesAttributes of Output Primitives
Attributes of Output PrimitivesRenita Santhmayora
 
Visible surface detection in computer graphic
Visible surface detection in computer graphicVisible surface detection in computer graphic
Visible surface detection in computer graphicanku2266
 
Polygons - Computer Graphics - Notes
Polygons - Computer Graphics - NotesPolygons - Computer Graphics - Notes
Polygons - Computer Graphics - NotesOmprakash Chauhan
 
Segments in Graphics
Segments in GraphicsSegments in Graphics
Segments in GraphicsRajani Thite
 
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
 
Composite transformations
Composite transformationsComposite transformations
Composite transformationsMohd Arif
 

What's hot (20)

Depth Buffer Method
Depth Buffer MethodDepth Buffer Method
Depth Buffer Method
 
Back face detection
Back face detectionBack face detection
Back face detection
 
Polygon filling
Polygon fillingPolygon filling
Polygon filling
 
Liang barsky Line Clipping Algorithm
Liang barsky Line Clipping AlgorithmLiang barsky Line Clipping Algorithm
Liang barsky Line Clipping Algorithm
 
Raster scan system
Raster scan systemRaster scan system
Raster scan system
 
Polygon filling
Polygon fillingPolygon filling
Polygon filling
 
Area filling algo
Area filling algoArea filling algo
Area filling algo
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer Graphics
 
Window to viewport transformation
Window to viewport transformationWindow to viewport transformation
Window to viewport transformation
 
Attributes of output primitive(line attributes)
Attributes of output primitive(line attributes)Attributes of output primitive(line attributes)
Attributes of output primitive(line attributes)
 
Computer graphics chapter 4
Computer graphics chapter 4Computer graphics chapter 4
Computer graphics chapter 4
 
Polygon Fill
Polygon FillPolygon Fill
Polygon Fill
 
Clipping ( Cohen-Sutherland Algorithm )
Clipping ( Cohen-Sutherland Algorithm )Clipping ( Cohen-Sutherland Algorithm )
Clipping ( Cohen-Sutherland Algorithm )
 
Attributes of Output Primitives
Attributes of Output PrimitivesAttributes of Output Primitives
Attributes of Output Primitives
 
Visible surface detection in computer graphic
Visible surface detection in computer graphicVisible surface detection in computer graphic
Visible surface detection in computer graphic
 
Polygons - Computer Graphics - Notes
Polygons - Computer Graphics - NotesPolygons - Computer Graphics - Notes
Polygons - Computer Graphics - Notes
 
Segments in Graphics
Segments in GraphicsSegments in Graphics
Segments in Graphics
 
Video display devices
Video display devicesVideo display devices
Video display devices
 
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
 
Composite transformations
Composite transformationsComposite transformations
Composite transformations
 

Viewers also liked

Hamiltonian path
Hamiltonian pathHamiltonian path
Hamiltonian pathArindam Ghosh
 
backtracking algorithms of ada
backtracking algorithms of adabacktracking algorithms of ada
backtracking algorithms of adaSahil Kumar
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back trackingTech_MX
 
Computer graphics
Computer graphicsComputer graphics
Computer graphicsNanhen Verma
 
Lecture filling algorithms
Lecture  filling algorithmsLecture  filling algorithms
Lecture filling algorithmsavelraj
 

Viewers also liked (8)

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
 
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
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Lecture filling algorithms
Lecture  filling algorithmsLecture  filling algorithms
Lecture filling algorithms
 

Similar to Polygon and Area Fill 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
 
14485616.ppt
14485616.ppt14485616.ppt
14485616.pptssuser80439c
 
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
 
Seed filling algorithm
Seed filling algorithmSeed filling algorithm
Seed filling algorithmMani Kanth
 
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
 

Similar to Polygon and Area Fill 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
 
Seed filling algorithm
Seed filling algorithmSeed filling algorithm
Seed filling 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...
 

More from 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
 
DTD
DTDDTD
DTDKumar
 
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
 

More from 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
 

Recently uploaded

Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
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
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
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
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 đź’ž Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 đź’ž Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 đź’ž Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 đź’ž Full Nigh...Pooja Nehwal
 
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
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 

Recently uploaded (20)

Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
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
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
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
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 đź’ž Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 đź’ž Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 đź’ž Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 đź’ž Full Nigh...
 
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
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 

Polygon and Area Fill 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.