Al salam 3alikom w ra7mat Allah w'barakatoh
These are my notes about our next assignment in visualization.
(Polygon Filling Algorithm)
1st we'll be using the loader to load the mesh we need to color. This mesh consists of polygons. We'll be coloring these polygons.
We'll make a function with the following specifications
Input:
- The polygon to be colored
- The contours that we did last week
Output:
- An array of lines with their corresponding colors (we'll get them from the color map editor we did 2 weeks ago)
How will we color the regions of the polygon??
using the lines from the array we just got [L1 & L2]. We'll iterate on all the vertices we have in this polygon [V1, V2, V3 & V4] and check if the region we are coloring contains this vertex or not.
If it contains the vertex, then add the vertex to -say- an array of points that defines this region.
After we finish this iteration, we'll be having a set of points that defines the regions to be colored.
in this example we'll have 3 arrays:
[L1, V1] [L1, L2, V2, V4] [L2, V3]
These defines the 3 regions [R1, R2 & R3]
Now What?
can we start coloring?
No, we still need to sort these points, to be able to color the regions.
How will we sort them?
take any vertex as a reference point, then draw the main coordinates (wiz respect to this vertex) & calculate the angles between the main coordinates and the lines.
Sort the angles & start coloring.
Here we took V4 as a reference point.
The Orange lines represent the main axes.
and the angles are (1, 2 & 3)
(Texture Mapping)
This should be faster than the "polygon filling" algorithm and easier to implement.
say we have 8 colors. We'll store them as 8 pixels in the memory.
We should normalize the values, so that they range from 0 to 1.
Also the values of pixels in the polygon, should range from 0 to 1.
Now we'll iterate on the polygon's pixels and get the required pixel (color) directly from the memory.
No distribution is used. We get the color directly from the pixels we stored.
I hope you find this post useful :)
Al Salam 3alikom w ra7mat Allah w'barakatoh
concerning the sorting of points to form a polygon.
ReplyDeleteIt doesn't really work, may be there are some constraints that we're missing here.
Any way, here is another solution for this problem: http://jaqoup.wordpress.com/2009/03/20/simple-polygon-construction/
and you can simply avoid it if you made sure you have the points sorted from the beginning.