The document summarizes the code written for two problems in homework 6.
For problem 1, the code loads vertex and face data from a PLY file, buckets vertices by face, calculates normals using the face buckets, and writes the normals to a file.
For problem 2, the code takes in a disparity map and color image, generates a mesh using a "zipper" algorithm that iterates through columns finding line segments and creating triangles, projects and colors the vertices, and writes the mesh to a PLY file. Screenshots are included showing the results.
1. Zachary Job
11/27/15
CS 532
Professor Mordohai
HW6
NOTE:
There’s a good chunk of code… I took an approach of listing what the code does in what file
starting at what line.
Problem 1:
Since it sounded like drawing lines was not exactly essential, I made an informative text output.
The algorithm is very simple and I checked a point so I don’t think it could mess up beyond a loss of
precision here and there. I took to creating a bucket per vertex where faces where added if they had this
vertex. Knowing calculating the normals for each connected face was needed, this solution seemed fit.
The code…
Get the user specified file names – line 31 mgr.c
Enter the read ply function to load the data – line 40 mgr.c
o Initialize base conditions – line 185 readPLY.c
o Load the file to memory – line 119, 212 readPLY.c
o Find the header for processing – line 221, 232 readPLY.c
o Given there is no defined order for variables, set a list of offsets so – line 239 readPLY.c
o Depending on which element was specified first, find the offset into the next element
given order matters in my implementation – line 293 readPLY.c
o Enter loadVerts to load the vertices – line 313 readPLY.c
Initialize the vertex list, the vertex face buckets, and the result list – line 34
readPLY.c, loadVerts
Get the current line or vertex data – line 44 readPLY.c, loadVerts
Break it into tokens – line 49 readPLY.c, loadVerts
Read the tokens into doubles with acceptable precision – line 60 readPLY.c,
loadVerts
Use this loop to initialize the bucket data – line 66
o Enter loadFaces to load the faces – line 315 readPLY.c
Initialize the face list – line 96 readPLY.c, loadFaces
Get the current line or face data – line 103 readPLY.c, loadFace
Break it into tokens – line 108 readPLY.c, loadFaces
2. Assign the tokens as int representations of the tokens – line 116 readPLY.c,
loadFaces
Enter calculateNormals to use the bucketed data to find the normal – line 47 mgr.c
o Iterate every bucket or every vertex – line 30 calcualteNormals.c
o Initialize the normals to be safe – line 32 calculateNormals.c
o Iterate the bucket at the vertex index – line 37 calculateNormals.c
o Find the normals with a point based formula – line 40, 49 calculateNormals.c
o Produce the unit vector – line 54 calculateNormals.c
o Average BUT do not get the unit vector for printing later – line 62 calculateNormals.c
Enter writeNormals to use all gathered information to make sensible output – line 54 mgr.c
o Iterate each bucket – line 37 writeNorms.c
o Write the vertex information including the normal and unit vector correction – line 44
writeNorms.c
o Iterate the bucket to list the faces used – line 65 writeNorms.c
o Write the buffer – line 77 writeNorms.c
The results appear acceptable, and one was randomly selected and passed. I do not see any
frailty in this code. It’s a basic algorithm and for what it seems everything works. The only fault would be
if the wrong faces were bucketed which I can’t see how that would go wrong.
This can be found in SRC_1/DATA/TXT/…
Problem 2:
My major delay here was actually that I was messing around and wanted to try an algorithm to
push out from a line with a left right selector and enqueue line sides which did not have a face. It was
just a heap of code I didn’t need to finish the assignment.
I took to a “zipper” algorithm instead as it could be accomplished fast and made for easy
debugging. This works on a super simple concept given we were allowed to drop vertices (which it did
not create holes for this instance). Using the depth map… Iterate every column. Look from the top down
for a new line, or pair of points. To finish it then would look for one point in the column to the right. The
next start point for another line would then lock to the last point found for the initial line. For every two
faces there could be closure to create a new face by drawing a line. As a vertex is used it too is projected
and colored to ease writing the ply result soon after.
The code…
Take the user input and jump to initData to setup the data – line 33 mgr.c
o Initialize base cases – line 31, 37 initData.c
o Ignore my shenanigans with checking for NULLs, I was getting frustrated with a memory
leak – line 48 initData.c
o Use grayToDouble pgm loader to get the user specified disparity – line 57 initData.c
No need to elaborate, this is a wrapper for your old ppm code slightly modified
3. o Use pixelToDouble ppm loader to get the user specified colors – line 60 initData.c
No need to elaborate, this is a wrapper for your old ppm code slightly modified
o Load the needed information eg focal information with acceptable precision – line 63,
70, 77 initData.c
Calculate the mesh, color the vertices, and project them all at once by calling calculateMesh –
line 36 mgr.c
o Allocate and set a list to the number of vertices in the previous column. This is used to
find offsets into lists of elements – line 35, 38 calculateMesh.c
o Initialize the now know amount of vertices – line 49 calculateMesh.c
o Iterate each column to perform the zipper operation on it and its leftmost neighbor –
line 58 calculateMesh.c
o Get the offsets into the vertex list of the vertices per the used columns – line 61
calculateMesh.c
o Iterate downwards on these two columns stopping when there are not enough or
appropriate vertices to form a face – line 65 calculateMesh.c
o Seek two vertices from the left column snapping v1 to either the first or last left vertex
found (v2) – line 69 calculateMesh.c
o Seek one vertex from the right column – line 86 calculateMesh.c
o Allocate and set the new faces vertices – line 93, 98 calculateMesh.c
(Note: confidence and intensity are debugging artifacts)
o Project and color v1 if it is the first vertex selected in the left column – line 103
calculateMesh.c
o Repeat regardless for v2 and v3 given with a match they must contain new vertices, but
first adjust the line height given ++ skews the result by one in the for loops.. I could of
handled that differently – line 128, 152 calculateMesh.c
o If enough faces where found to create a new triangle by drawing between the right
column matched vertices, generate additional faces. Do not work on the vertices given
they had to have been manipulated already if they are part of existing faces – line 181
calculateMesh.c
Write a ply to display the newfound mesh using writePLY – line 52 mgr.c
o Generate a header via using a fixed format and inserting the vertex and face counts –
line 44 writePLY.c
o Write the header – line 54 writePLY.c
o For each vertex write out its needed information from a generated buffer – line 59
writePLY.c
o For each face write out its needed information from a generated buffer – line 74
writePLY.c
For this problem the results were visual so really any mistake was not hard to catch. It can be
seen this algorithm has plenty that could be done better. Smoothing of sorts for one thing would be a
good step. However it got the job done. There is significant stretching especially where the disparity
4. could not show. Also, please note the coloring exists, however it is hard to notice given the edges are
colored on the triangles. I didn’t think it necessary to rectify it because I have evidence of the texture.
These can be found in SRC_2/DATA/SNAPS/…
Proof of color, see the texture is apparent at this angle however faded due to stretching and the edge
coloring
Side one
5. Side two, note the stretching from the lacking or more distant points
Additional visuals from the top and bottom showcasing what could be and could not be captured by the
depth map. They also show overall stretching
Top
Bottom