SlideShare una empresa de Scribd logo
1 de 82
SUBMITTED TO : SUBMITTED BY :
MISS. NAMITA JAIN KRATI KATYAL
MCA 4TH SEM
Polygon Filling
Topic Covered
 Polygon
 Types
 Inside – Outside Test
 Polygon Filling
 Techniques
 Algorithms
 Example
What is a Polygon….?
 A closed figure represented by a collection of more than 2 line
segments connected end to end.
 The line segments are known as “Edge” of the Polygon and make up
the Polygon boundary.
 Endpoints of the edges are known as “Vertex” of the Polygon.
Types Of Polygon
 Simple Convex
 Simple Concave
 Non-simple : self-intersecting
Convex Concave Self-intersecting
Convex
< 180°
Concave
> 180°
CONVEX CONCAVE
All points on the line segment
connecting two points of the Polygon
are also inside the Polygon.
All points on the line segment connecting
two points of the Polygon are not inside
the Polygon.
All interior angles lesser than 180°. At least one interior angle is greater than
180°.
All of its lines curve outside At least one line curve is inside.
One thing you may note about a convex
shape is that, no matter where you draw
a line that passes through the shape, it
will always pass through only two of the
lines or polygons making up the shape
If you try the same thing with a concave
shape it can pass through more than
two of the lines
 CONVEX POLYGON:
 CONCAVE POLYGON:
Inside – Outside Test
 Even – Odd Test
 Winding Number Method
out
out
in
in
Even – Odd Test
 Also known as “Crossing Number Method”
 Construct a line segment which crosses the given Polygon and then count
the number of time a line crosses the Polygon Boundary.
 If the crossing number is odd then the line is inside the Polygon, else
outside.
Special case : when point of intersection is the vertex .
out
in
Even – Odd Test: Special Case Handling
 Two cases:
 Case A: edges are monotonically increasing or decreasing
 Case B: edges reverse direction at endpoint
 In Case A, we should consider this as only ONE edge intersection.
 In Case B, we should consider this as TWO edge intersections.
Case A
Counts one
Counts two
Case B
Winding Number Method
 Instead of just counting the number of intersections, each edge crossed is
given a direction number.
 Value of the direction number is :
 1, (Ystart < Yend)
 -1, (Ystart > Yend)
 Point is inside the Polygon if the sum of direction numbers is non-zero, else
outside.
Example
1
-1
1
1+(-1)+1=1 , non-zero ,point inside
Polygon Filling
 Filling a Polygon is the process of coloring every pixel that comes inside
the Polygon region.
 Techniques:
 Boundary Fill Method
 Flood Fill Method
 Scan – Line Fill Method
Boundary Fill Method
 Also known as “Seed-Fill Method”
 Draw Polygon boundaries
 Fill up the seed point
 A Seed-Point i.e. an arbitrary interior point is taken as the initial or the
starting point.
 Test neighboring pixels to determine whether they correspond to
the boundary pixel
 If not, paint them with the fill-color and test their neighboring pixels
(store neighbors in stack)
 Continue until all pixels have been tested
 A considerable stack is used to store pixel information.
 Basically, it is of two types :
1. 4-Connected Seed Fill
2. 8-Connected Seed Fill
4-Connected and 8-Connected Seed
(X, Y+1)
(X+1,
Y+1)
(X-1,
Y+1)
(X, Y) (X+1, Y)(X-1, Y)
(X, Y-1)
(X+1, Y-
1)
(X-1, Y-1)
(X, Y+1)
(X, Y) (X+1, Y)(X-1, Y)
(X, Y-1)
 The 4-connected pixel technique failed to fill the area as marked in the
following figure which won’t happen with the 8-connected technique.
4 – Connected Example
Start Position
1
2 3
1 4
2
1
2
5 1
1
8 – Connected Example
Start Position
4 1 5
2 3
6
4 1
2 3
7 8
4 1
2 3
11 9 12
7 10
4 1
2 3
11 9
7 10
4 1
2 3
9
7 10
4 1
2 3
9
7
4 1
2 3
7
4 1
2 3
4 1
2 3
1
2 3
1
2
1
Algorithm: 4 Connected
 boundaryFill(int x, int y, int fill, int boundary)
current = getPixel(x,y)
if(current < > boundary AND current < > fill) then
setPixel(x,y,fill)
boundaryFill(x+1,y,fill,boundary)
boundaryFill(x-1,y,fill,boundary)
boundaryFill(x,y+1,fill,boundary)
boundaryFill(x,y-1,fill,boundary)
end if
end
Flood Fill Method
 Modified form of Boundary Fill Method.
 Basic concept is just like Boundary Filling.
 Fill polygon starting with a “seed” point known to be inside the polygon &
set the neighboring pixels until we encounter the boundary pixels.
 Polygon is filled just like pouring water in an empty bucket.
 Common example is the bucket-fill tool of MS-Paint.
 Like Boundary Fill Method, it is also used in games.
Algorithm:
void floodFill(int x, int y, int fillColor, int interiorColor) {
int color;
getPixel(x,y,color)
if (color==interiorColor) {
setPixel(x,y,fillColor);
floodFill(x+1,y,fillColor,interiorColor);
floodFill(x-1,y,fillColor,interiorColor);
floodFill(x,y+1,fillColor,interiorColor);
floodFill(x,y-1,fillColor,interiorColor);
}
}
Flood Fill Method: Working
Filling Irregular Boundaries
 Boundary fill: expand and fill region until you reach
boundary color
 Flood fill: expand and fill region while you find interior color
Boundary
Fill
Interior Fill
 In brief:
• Flood Fill and Boundary Fill are algorithms used for colouring a given figure
with a chosen colour
• Flood Fill is one in which all connected pixels of a selected colour get
replaced by a fill colour.
• Boundary Fill is very similar with the difference being the program stopping
when a given colour boundary is found.
Scan - Line Fill Method
 Used in Raster Scan Devices.
 The scan-line algorithm works as follows:
i. Find intersections of the scan-line with all edges
ii. Sort intersections in increasing x
iii. Fill all the pixels between pairs of intersections
 Special Cases to handle:
i. Exclude horizontal edges
ii. For vertices lying on scan-line
 Count twice
Scan - Line Example
9
7
6
5
4
3
2
1
0
8
976543210 8 10
10
Scan - Line Base Approach
2
4
6
8
10 Scan Line
0
2 4 6 8 10 12 14 16
Scan - Line Draw Polygon
9
7
6
5
4
3
2
1
0
8
976543210 8 10
10
Scan - Line Filling Process
9
7
6
5
4
3
2
1
0
8
976543210 8 10
10
Scan - Line Filling Process
9
7
6
5
4
3
2
1
0
8
976543210 8 10
10
Filling Process
9
7
6
5
4
3
2
1
0
8
976543210 8 10
10
Scan - Line Filling Process
9
7
6
5
4
3
2
1
0
8
976543210 8 10
10
Scan - Line Filling Process
9
7
6
5
4
3
2
1
0
8
976543210 8 10
10
Scan - Line Filling Process
9
7
6
5
4
3
2
1
0
8
976543210 8 10
10
Scan - Line Filling Process
9
7
6
5
4
3
2
1
0
8
976543210 8 10
10
Scan - Line Filling Process
9
7
6
5
4
3
2
1
0
8
976543210 8 10
10
Example
 Initially, each vertices of the polygon is given in the form of (x,y) and is in an
ordered array as such:
 Unfilled, the polygon would look like this to the human eye:
Steps
 1.In order to fill a polygon, we do not want to have to determine the type of
polygon that we are filling.
 2. The basic concept of the scan-line algorithm is to draw points from edges
of odd parity to even parity on each scan-line.
 3.scan-line: A scan-line is a line of constant y value.
Algorithm
 1.Initializing All of the Edges: all_edges table:
 The first thing that needs to be done is determine how the polygon's
vertices are related. The all_edges table will hold this information.
1. The minimum y value of the two vertices.
2. The maximum y value of the two vertices.
3. The x value associated with the minimum y value.
4. The slope of the edge.
 The formula for the slope is as follows:
 m = (y0 - y1) / (x0 - x1).
2. Global Edge Table: GET
 The global edge table will be used to keep track of the edges that are still
needed to complete the polygon.
 Edges with the same minimum y values are sorted on minimum x values as
follows:
1. Place the first edge with a slope that is not equal to zero in the global
edge table.
2. If the slope of the edge is zero, do not add that edge to the global edge
table.
 3.Initializing Parity
Parity is initially set to even. Yet now no edges has crossed.
 4.Initializing the Scan-Line
• we can safely choose lowest y value in the global edge table as our initial
scan-line.
• In our example it is 10.
5. Initializing the Active Edge Table
 The active edge table will be used to keep track of the edges that are
intersected by the current scan-line. This should also contain ordered
edges.
 This is initially set up as follows:
1. The global edge table is ordered on minimum y and x values, search
through the global edge table and, for each edge found having a minimum
y value equal to the current scan-line.
2. Append the edge information in the AET for the
a. Maximum y value
b. X value
c. 1/m
3.Do this until an edge is found with a minimum y value greater than the scan
line value.
 The active edge table will now contain ordered edges of those edges that
are being filled as such:
Filling the Polygon
 Filling the polygon involves deciding whether or not to draw pixels, adding
to and removing edges from the active edge table, and updating x values for
the next scan-line.
 Starting with the initial scan-line, until the active edge table is empty, do the
following:
a. Draw all pixels from the x value of odd to the x value of even parity edge
pairs.
b. Increase the scan-line by 1.
c. Remove any edges from the active edge table for which the maximum y
value is equal to the scan_line.
a. Update the x value for each edge in the active edge table using the
formula x1 = x0 + 1/m. (This is based on the line formula and the fact
that the next scan-line equals the old scan-line plus one.)
b. Remove any edges from the global edge table for which the minimum
y value is equal to the scan-line and place them in the active edge
table.
c. Reorder the edges in the active edge table according to increasing x
value. This is done in case edges have crossed.
Scan Line 10
 The polygon is now filled as follows:
Scan Line 11
i. Increase the scan-line by 1.
ii. Update x1 = x0 + 1/m
 The polygon is now filled as follows:
 The polygon is now filled as follows:
Scan Line 15
 The polygon is now filled as follows:
Scan Line 16
i. Next scan Line value is 16.
ii. This is equal to maximum value of y in AET. So we will remove these edges
whose maximum y value is 16 from AET.
 We then need to update the x values for all remaining edges.
 Now we can add the last edge from the global edge table to the active edge
table since its minimum y value is equal to the next scan-line. The active
edge table now look as follows (the global edge table is now empty):
 Now that we have filled the polygon, let's see what it looks like to the naked eye:
Scan - Line Alogorithm
1. Set y to the smallest y coordinate that has an entry in the ET; i.e, y for the
first nonempty bucket.
2. Initialize the AET to be empty.
3. Repeat until the AET and ET are empty:
 3.1 Move from ET bucket y to the AET those edges whose y_min = y
(entering edges).
 3.2 Remove from the AET those entries for which y = y_max (edges
not involved in the next scanline), the sort the AET on x (made easier
because ET is presorted).
 3.3 Fill in desired pixel values on scanline y by using pairs of x
coordinates from AET.
 3.4 Increment y by 1 (to the coordinate of the next scanline).
 3.5 For each nonvertical edge remaining in the AET, update x for the new
y.
References
 Book Reference
 Computer Graphics –Neetu Agarwal
 Graphics Programming in C – Roger Stevens
 Web Reference
 www.wikipedia.org
 www.tutorialspoint.com
Polygon filling

Más contenido relacionado

La actualidad más candente

The sutherland hodgeman polygon clipping algorithm
The sutherland hodgeman polygon clipping algorithmThe sutherland hodgeman polygon clipping algorithm
The sutherland hodgeman polygon clipping algorithmMani Kanth
 
Computer graphics basic transformation
Computer graphics basic transformationComputer graphics basic transformation
Computer graphics basic transformationSelvakumar Gna
 
Seed filling algorithm
Seed filling algorithmSeed filling algorithm
Seed filling algorithmMani Kanth
 
Back face detection
Back face detectionBack face detection
Back face detectionPooja Dixit
 
Segments in Graphics
Segments in GraphicsSegments in Graphics
Segments in GraphicsRajani Thite
 
Scan line method
Scan line methodScan line method
Scan line methodPooja Dixit
 
Raster scan system
Raster scan systemRaster scan system
Raster scan systemMohd Arif
 
Polygon clipping with sutherland hodgeman algorithm and scan line fill algorithm
Polygon clipping with sutherland hodgeman algorithm and scan line fill algorithmPolygon clipping with sutherland hodgeman algorithm and scan line fill algorithm
Polygon clipping with sutherland hodgeman algorithm and scan line fill algorithmMani Kanth
 
Hidden surface removal algorithm
Hidden surface removal algorithmHidden surface removal algorithm
Hidden surface removal algorithmKKARUNKARTHIK
 
Visible surface detection in computer graphic
Visible surface detection in computer graphicVisible surface detection in computer graphic
Visible surface detection in computer graphicanku2266
 
Character generation
Character generationCharacter generation
Character generationAnkit Garg
 
Cohen sutherland line clipping
Cohen sutherland line clippingCohen sutherland line clipping
Cohen sutherland line clippingMani Kanth
 
Video display devices
Video display devicesVideo display devices
Video display devicesMohd Arif
 
4-CONNECTED AND 8-CONNECTED NEIGHBOR SELECTION By Sintiak Haque
4-CONNECTED AND 8-CONNECTED NEIGHBOR SELECTION  By Sintiak Haque4-CONNECTED AND 8-CONNECTED NEIGHBOR SELECTION  By Sintiak Haque
4-CONNECTED AND 8-CONNECTED NEIGHBOR SELECTION By Sintiak HaqueSintiak haque
 
2D transformation (Computer Graphics)
2D transformation (Computer Graphics)2D transformation (Computer Graphics)
2D transformation (Computer Graphics)Timbal Mayank
 
Bresenham's line drawing algorithm
Bresenham's line drawing algorithmBresenham's line drawing algorithm
Bresenham's line drawing algorithmnehrurevathy
 
Window to viewport transformation&amp;matrix representation of homogeneous co...
Window to viewport transformation&amp;matrix representation of homogeneous co...Window to viewport transformation&amp;matrix representation of homogeneous co...
Window to viewport transformation&amp;matrix representation of homogeneous co...Mani Kanth
 
COMPUTER GRAPHICS-"Projection"
COMPUTER GRAPHICS-"Projection"COMPUTER GRAPHICS-"Projection"
COMPUTER GRAPHICS-"Projection"Ankit Surti
 
Computer graphics chapter 4
Computer graphics chapter 4Computer graphics chapter 4
Computer graphics chapter 4PrathimaBaliga
 

La actualidad más candente (20)

The sutherland hodgeman polygon clipping algorithm
The sutherland hodgeman polygon clipping algorithmThe sutherland hodgeman polygon clipping algorithm
The sutherland hodgeman polygon clipping algorithm
 
Computer graphics basic transformation
Computer graphics basic transformationComputer graphics basic transformation
Computer graphics basic transformation
 
Seed filling algorithm
Seed filling algorithmSeed filling algorithm
Seed filling algorithm
 
Back face detection
Back face detectionBack face detection
Back face detection
 
Segments in Graphics
Segments in GraphicsSegments in Graphics
Segments in Graphics
 
Scan line method
Scan line methodScan line method
Scan line method
 
Raster scan system
Raster scan systemRaster scan system
Raster scan system
 
Polygon clipping with sutherland hodgeman algorithm and scan line fill algorithm
Polygon clipping with sutherland hodgeman algorithm and scan line fill algorithmPolygon clipping with sutherland hodgeman algorithm and scan line fill algorithm
Polygon clipping with sutherland hodgeman algorithm and scan line fill algorithm
 
Hidden surface removal algorithm
Hidden surface removal algorithmHidden surface removal algorithm
Hidden surface removal algorithm
 
Visible surface detection in computer graphic
Visible surface detection in computer graphicVisible surface detection in computer graphic
Visible surface detection in computer graphic
 
Character generation
Character generationCharacter generation
Character generation
 
Boundary fill algm
Boundary fill algmBoundary fill algm
Boundary fill algm
 
Cohen sutherland line clipping
Cohen sutherland line clippingCohen sutherland line clipping
Cohen sutherland line clipping
 
Video display devices
Video display devicesVideo display devices
Video display devices
 
4-CONNECTED AND 8-CONNECTED NEIGHBOR SELECTION By Sintiak Haque
4-CONNECTED AND 8-CONNECTED NEIGHBOR SELECTION  By Sintiak Haque4-CONNECTED AND 8-CONNECTED NEIGHBOR SELECTION  By Sintiak Haque
4-CONNECTED AND 8-CONNECTED NEIGHBOR SELECTION By Sintiak Haque
 
2D transformation (Computer Graphics)
2D transformation (Computer Graphics)2D transformation (Computer Graphics)
2D transformation (Computer Graphics)
 
Bresenham's line drawing algorithm
Bresenham's line drawing algorithmBresenham's line drawing algorithm
Bresenham's line drawing algorithm
 
Window to viewport transformation&amp;matrix representation of homogeneous co...
Window to viewport transformation&amp;matrix representation of homogeneous co...Window to viewport transformation&amp;matrix representation of homogeneous co...
Window to viewport transformation&amp;matrix representation of homogeneous co...
 
COMPUTER GRAPHICS-"Projection"
COMPUTER GRAPHICS-"Projection"COMPUTER GRAPHICS-"Projection"
COMPUTER GRAPHICS-"Projection"
 
Computer graphics chapter 4
Computer graphics chapter 4Computer graphics chapter 4
Computer graphics chapter 4
 

Destacado (6)

Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
 
Risc & cisk
Risc & ciskRisc & cisk
Risc & cisk
 
Modular programming
Modular programmingModular programming
Modular programming
 
And or graph problem reduction using predicate logic
And or graph problem reduction using predicate logicAnd or graph problem reduction using predicate logic
And or graph problem reduction using predicate logic
 
Protection
ProtectionProtection
Protection
 
Knapsack problem using fixed tuple
Knapsack problem using fixed tupleKnapsack problem using fixed tuple
Knapsack problem using fixed tuple
 

Similar a Polygon filling

Similar a Polygon filling (20)

UNIT2.pptx
UNIT2.pptxUNIT2.pptx
UNIT2.pptx
 
Polygon Fill
Polygon FillPolygon Fill
Polygon Fill
 
Lecture filling algorithms
Lecture  filling algorithmsLecture  filling algorithms
Lecture filling algorithms
 
Clipping computer graphics
Clipping  computer graphicsClipping  computer graphics
Clipping computer graphics
 
Clipping
ClippingClipping
Clipping
 
99995327.ppt
99995327.ppt99995327.ppt
99995327.ppt
 
lecture8 clipping
lecture8 clippinglecture8 clipping
lecture8 clipping
 
Unit2- line clipping.pptx
Unit2- line clipping.pptxUnit2- line clipping.pptx
Unit2- line clipping.pptx
 
ohu.pptx
ohu.pptxohu.pptx
ohu.pptx
 
Unit-2 PPT.ppt
Unit-2 PPT.pptUnit-2 PPT.ppt
Unit-2 PPT.ppt
 
Liang- Barsky Algorithm, Polygon clipping & pipeline clipping of polygons
Liang- Barsky Algorithm, Polygon clipping & pipeline clipping of polygonsLiang- Barsky Algorithm, Polygon clipping & pipeline clipping of polygons
Liang- Barsky Algorithm, Polygon clipping & pipeline clipping of polygons
 
Clipping
ClippingClipping
Clipping
 
Unit 4 notes
Unit 4 notesUnit 4 notes
Unit 4 notes
 
yutd65.pptx
yutd65.pptxyutd65.pptx
yutd65.pptx
 
Clipping
ClippingClipping
Clipping
 
Lecture 2d point,curve,text,line clipping
Lecture   2d point,curve,text,line clippingLecture   2d point,curve,text,line clipping
Lecture 2d point,curve,text,line clipping
 
Open GL T0074 56 sm3
Open GL T0074 56 sm3Open GL T0074 56 sm3
Open GL T0074 56 sm3
 
Clipping & Rasterization
Clipping & RasterizationClipping & Rasterization
Clipping & Rasterization
 
7-Clipping-16 (1).pdf
7-Clipping-16 (1).pdf7-Clipping-16 (1).pdf
7-Clipping-16 (1).pdf
 
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
 

Último

(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 

Último (20)

(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 

Polygon filling

  • 1. SUBMITTED TO : SUBMITTED BY : MISS. NAMITA JAIN KRATI KATYAL MCA 4TH SEM Polygon Filling
  • 2. Topic Covered  Polygon  Types  Inside – Outside Test  Polygon Filling  Techniques  Algorithms  Example
  • 3. What is a Polygon….?  A closed figure represented by a collection of more than 2 line segments connected end to end.  The line segments are known as “Edge” of the Polygon and make up the Polygon boundary.  Endpoints of the edges are known as “Vertex” of the Polygon.
  • 4. Types Of Polygon  Simple Convex  Simple Concave  Non-simple : self-intersecting Convex Concave Self-intersecting
  • 5. Convex < 180° Concave > 180° CONVEX CONCAVE All points on the line segment connecting two points of the Polygon are also inside the Polygon. All points on the line segment connecting two points of the Polygon are not inside the Polygon. All interior angles lesser than 180°. At least one interior angle is greater than 180°. All of its lines curve outside At least one line curve is inside. One thing you may note about a convex shape is that, no matter where you draw a line that passes through the shape, it will always pass through only two of the lines or polygons making up the shape If you try the same thing with a concave shape it can pass through more than two of the lines
  • 6.  CONVEX POLYGON:  CONCAVE POLYGON:
  • 7. Inside – Outside Test  Even – Odd Test  Winding Number Method out out in in
  • 8. Even – Odd Test  Also known as “Crossing Number Method”  Construct a line segment which crosses the given Polygon and then count the number of time a line crosses the Polygon Boundary.  If the crossing number is odd then the line is inside the Polygon, else outside. Special case : when point of intersection is the vertex . out in
  • 9. Even – Odd Test: Special Case Handling  Two cases:  Case A: edges are monotonically increasing or decreasing  Case B: edges reverse direction at endpoint  In Case A, we should consider this as only ONE edge intersection.  In Case B, we should consider this as TWO edge intersections.
  • 11. Winding Number Method  Instead of just counting the number of intersections, each edge crossed is given a direction number.  Value of the direction number is :  1, (Ystart < Yend)  -1, (Ystart > Yend)  Point is inside the Polygon if the sum of direction numbers is non-zero, else outside.
  • 13. Polygon Filling  Filling a Polygon is the process of coloring every pixel that comes inside the Polygon region.  Techniques:  Boundary Fill Method  Flood Fill Method  Scan – Line Fill Method
  • 14. Boundary Fill Method  Also known as “Seed-Fill Method”  Draw Polygon boundaries  Fill up the seed point  A Seed-Point i.e. an arbitrary interior point is taken as the initial or the starting point.  Test neighboring pixels to determine whether they correspond to the boundary pixel  If not, paint them with the fill-color and test their neighboring pixels (store neighbors in stack)  Continue until all pixels have been tested
  • 15.  A considerable stack is used to store pixel information.  Basically, it is of two types : 1. 4-Connected Seed Fill 2. 8-Connected Seed Fill
  • 16. 4-Connected and 8-Connected Seed (X, Y+1) (X+1, Y+1) (X-1, Y+1) (X, Y) (X+1, Y)(X-1, Y) (X, Y-1) (X+1, Y- 1) (X-1, Y-1) (X, Y+1) (X, Y) (X+1, Y)(X-1, Y) (X, Y-1)
  • 17.  The 4-connected pixel technique failed to fill the area as marked in the following figure which won’t happen with the 8-connected technique.
  • 18. 4 – Connected Example Start Position
  • 19. 1 2 3
  • 20. 1 4 2
  • 21. 1 2
  • 22. 5 1
  • 23. 1
  • 24.
  • 25. 8 – Connected Example Start Position
  • 26. 4 1 5 2 3
  • 29. 11 9 12 7 10 4 1 2 3
  • 30. 11 9 7 10 4 1 2 3
  • 35. 1 2 3
  • 36. 1 2
  • 37. 1
  • 38.
  • 39. Algorithm: 4 Connected  boundaryFill(int x, int y, int fill, int boundary) current = getPixel(x,y) if(current < > boundary AND current < > fill) then setPixel(x,y,fill) boundaryFill(x+1,y,fill,boundary) boundaryFill(x-1,y,fill,boundary) boundaryFill(x,y+1,fill,boundary) boundaryFill(x,y-1,fill,boundary) end if end
  • 40. Flood Fill Method  Modified form of Boundary Fill Method.  Basic concept is just like Boundary Filling.  Fill polygon starting with a “seed” point known to be inside the polygon & set the neighboring pixels until we encounter the boundary pixels.  Polygon is filled just like pouring water in an empty bucket.  Common example is the bucket-fill tool of MS-Paint.  Like Boundary Fill Method, it is also used in games.
  • 41. Algorithm: void floodFill(int x, int y, int fillColor, int interiorColor) { int color; getPixel(x,y,color) if (color==interiorColor) { setPixel(x,y,fillColor); floodFill(x+1,y,fillColor,interiorColor); floodFill(x-1,y,fillColor,interiorColor); floodFill(x,y+1,fillColor,interiorColor); floodFill(x,y-1,fillColor,interiorColor); } }
  • 43. Filling Irregular Boundaries  Boundary fill: expand and fill region until you reach boundary color  Flood fill: expand and fill region while you find interior color Boundary Fill Interior Fill
  • 44.  In brief: • Flood Fill and Boundary Fill are algorithms used for colouring a given figure with a chosen colour • Flood Fill is one in which all connected pixels of a selected colour get replaced by a fill colour. • Boundary Fill is very similar with the difference being the program stopping when a given colour boundary is found.
  • 45. Scan - Line Fill Method  Used in Raster Scan Devices.  The scan-line algorithm works as follows: i. Find intersections of the scan-line with all edges ii. Sort intersections in increasing x iii. Fill all the pixels between pairs of intersections  Special Cases to handle: i. Exclude horizontal edges ii. For vertices lying on scan-line  Count twice
  • 46. Scan - Line Example 9 7 6 5 4 3 2 1 0 8 976543210 8 10 10
  • 47. Scan - Line Base Approach 2 4 6 8 10 Scan Line 0 2 4 6 8 10 12 14 16
  • 48. Scan - Line Draw Polygon 9 7 6 5 4 3 2 1 0 8 976543210 8 10 10
  • 49. Scan - Line Filling Process 9 7 6 5 4 3 2 1 0 8 976543210 8 10 10
  • 50. Scan - Line Filling Process 9 7 6 5 4 3 2 1 0 8 976543210 8 10 10
  • 52. Scan - Line Filling Process 9 7 6 5 4 3 2 1 0 8 976543210 8 10 10
  • 53. Scan - Line Filling Process 9 7 6 5 4 3 2 1 0 8 976543210 8 10 10
  • 54. Scan - Line Filling Process 9 7 6 5 4 3 2 1 0 8 976543210 8 10 10
  • 55. Scan - Line Filling Process 9 7 6 5 4 3 2 1 0 8 976543210 8 10 10
  • 56. Scan - Line Filling Process 9 7 6 5 4 3 2 1 0 8 976543210 8 10 10
  • 57. Example  Initially, each vertices of the polygon is given in the form of (x,y) and is in an ordered array as such:  Unfilled, the polygon would look like this to the human eye:
  • 58. Steps  1.In order to fill a polygon, we do not want to have to determine the type of polygon that we are filling.  2. The basic concept of the scan-line algorithm is to draw points from edges of odd parity to even parity on each scan-line.  3.scan-line: A scan-line is a line of constant y value.
  • 59. Algorithm  1.Initializing All of the Edges: all_edges table:  The first thing that needs to be done is determine how the polygon's vertices are related. The all_edges table will hold this information. 1. The minimum y value of the two vertices. 2. The maximum y value of the two vertices. 3. The x value associated with the minimum y value. 4. The slope of the edge.  The formula for the slope is as follows:  m = (y0 - y1) / (x0 - x1).
  • 60. 2. Global Edge Table: GET  The global edge table will be used to keep track of the edges that are still needed to complete the polygon.  Edges with the same minimum y values are sorted on minimum x values as follows: 1. Place the first edge with a slope that is not equal to zero in the global edge table. 2. If the slope of the edge is zero, do not add that edge to the global edge table.
  • 61.
  • 62.  3.Initializing Parity Parity is initially set to even. Yet now no edges has crossed.  4.Initializing the Scan-Line • we can safely choose lowest y value in the global edge table as our initial scan-line. • In our example it is 10.
  • 63. 5. Initializing the Active Edge Table  The active edge table will be used to keep track of the edges that are intersected by the current scan-line. This should also contain ordered edges.  This is initially set up as follows: 1. The global edge table is ordered on minimum y and x values, search through the global edge table and, for each edge found having a minimum y value equal to the current scan-line. 2. Append the edge information in the AET for the a. Maximum y value b. X value c. 1/m
  • 64. 3.Do this until an edge is found with a minimum y value greater than the scan line value.  The active edge table will now contain ordered edges of those edges that are being filled as such:
  • 65. Filling the Polygon  Filling the polygon involves deciding whether or not to draw pixels, adding to and removing edges from the active edge table, and updating x values for the next scan-line.  Starting with the initial scan-line, until the active edge table is empty, do the following: a. Draw all pixels from the x value of odd to the x value of even parity edge pairs. b. Increase the scan-line by 1. c. Remove any edges from the active edge table for which the maximum y value is equal to the scan_line.
  • 66. a. Update the x value for each edge in the active edge table using the formula x1 = x0 + 1/m. (This is based on the line formula and the fact that the next scan-line equals the old scan-line plus one.) b. Remove any edges from the global edge table for which the minimum y value is equal to the scan-line and place them in the active edge table. c. Reorder the edges in the active edge table according to increasing x value. This is done in case edges have crossed.
  • 68.  The polygon is now filled as follows:
  • 69. Scan Line 11 i. Increase the scan-line by 1. ii. Update x1 = x0 + 1/m
  • 70.  The polygon is now filled as follows:
  • 71.  The polygon is now filled as follows:
  • 73.  The polygon is now filled as follows:
  • 74. Scan Line 16 i. Next scan Line value is 16. ii. This is equal to maximum value of y in AET. So we will remove these edges whose maximum y value is 16 from AET.
  • 75.  We then need to update the x values for all remaining edges.
  • 76.  Now we can add the last edge from the global edge table to the active edge table since its minimum y value is equal to the next scan-line. The active edge table now look as follows (the global edge table is now empty):
  • 77.
  • 78.
  • 79.  Now that we have filled the polygon, let's see what it looks like to the naked eye:
  • 80. Scan - Line Alogorithm 1. Set y to the smallest y coordinate that has an entry in the ET; i.e, y for the first nonempty bucket. 2. Initialize the AET to be empty. 3. Repeat until the AET and ET are empty:  3.1 Move from ET bucket y to the AET those edges whose y_min = y (entering edges).  3.2 Remove from the AET those entries for which y = y_max (edges not involved in the next scanline), the sort the AET on x (made easier because ET is presorted).  3.3 Fill in desired pixel values on scanline y by using pairs of x coordinates from AET.  3.4 Increment y by 1 (to the coordinate of the next scanline).  3.5 For each nonvertical edge remaining in the AET, update x for the new y.
  • 81. References  Book Reference  Computer Graphics –Neetu Agarwal  Graphics Programming in C – Roger Stevens  Web Reference  www.wikipedia.org  www.tutorialspoint.com