Implementation:

Now that the details are covered, here is the implementation of the SLPF in C++.

Due to a request from my professor the C++ implementation of the code has been taken down and replaced with pseudo code (There is a strong concern that students will copy the code for projects). If you are interested in my C++ implementation feel free to message me for it.

Main Program (Pseudo code)



Creates edge buckets from the given edges













*/

createEdges(n, x[], y[]) {

instantiate a new edge table /*Creates edge buckets from the given edges @param n Number of vertices @param x[] array of x points @param y[] array of y points @return List of edge buckets*/createEdges(n, x[], y[]) {instantiate a new edge table loop through x[] & y[] pairs {

if the edge's slope is NOT undefined (verticle) {

create bucket with edge

add bucket to edge table

}

}

}

Given the edge table of the polygon, fill the polygons





*/

processEdgeTable (edgeTable) {

while (edge table is NOT empty) { /*Given the edge table of the polygon, fill the polygons @param edgeTable The polygon's edge table representation*/processEdgeTable (edgeTable) {while (edge table is NOT empty) { // Remove edges from the active list if y == ymax

if (active list is NOT empty) {

for (iterate through all buckets in the active list) {

if (current bucket's ymax == current scanline) {

remove bucket from active list

remove bucket from edge table

}

}

} // Add edge from edge table to active list if y == ymin

for (iterate through the bucket in the edge table) {

if (bucket's ymin == scanline) {

add bucket to active list

}

} // Sort active list by x position and slope

sortTheActiveList(); // Fill the polygon pixel

for (iterate through the active list) {

for (from vertex1.x to vertex2.x of the bucket) {

setPixelColor()

}

} // Increment X variables of buckets based on the slope

for (all buckets in the active list) {

if (bucketsdX != 0) {

bucket's sum += bucket's dX while (bucket's sum >= bucket's dY) {

increment or decrement bucket's X depending on sign of bucket's slope

edge's sum -= dY

}

}

}

}

}

// Draw a filled polygon in the Canvas C.

//

// The polygon has n distinct vertices. The coordinates of the vertices

// making up the polygon are stored in the x and y arrays. The ith

// vertex will have coordinate (x[i],y[i]).

//

//

//

//

///

drawPolygon(n, x[], y[]) {

// Create edge table

finalEdgeTable = createEdges() ///// Draw a filled polygon in the Canvas C.//// The polygon has n distinct vertices. The coordinates of the vertices// making up the polygon are stored in the x and y arrays. The ith// vertex will have coordinate (x[i],y[i]).//// @param n - number of vertices// @param x - x coordinates// @param y - y coordinates///drawPolygon(n, x[], y[]) {// Create edge tablefinalEdgeTable = createEdges() // Sort edges by minY

sort(finalEdgeTable) processEdgeTable(finalEdgeTable)

}

Header file with structs