Notes on creating faces for loop subdivision . . .

First of all I skipped a necessary part of calculating the edge vertices. Since the edge vertices are placed on the new vertex vector in order we should be easily able to find them. However, it is not immediately clear when looking at the edge buffer, which edge (in order) we are looking at. This means that we need to creating a lookup data structure for the edges.

So here's the pseudocode

// get edge vertices
vector<vector<int> > edgebufferlookup = edgebuffer

for i = 0 to edgebuffer.size()
	for j = 0 to edgebuffer[i].size
		int v1 = i
		int v2 = edgebuffer[i][j]
		if (edgeonboundary(i,j)) 
			newv.push_back(1/2 * vertices[v1] + 1/2 * vertices[v2])
		else {
			// find v3 & v4 by checking neighboring faces
			newv.push_back(3/8 * (vertices[v1] + vertices[v2]) + 1/8 * (vertices[v3] + vertices[v4])
		}
		edgebufferlookup[i][j] = newv.size()


// put together the faces
for i = 0 to faces.size()
{
	v0 = faces.vertices[0]
	v1 = faces.vertices[1]
	v2 = faces.vertices[2]
	// get e1, this is the edge vertex between v0 and v1
	if v0 < v1
		for j = 0 to edgebuffer[v0].size
			if edgebuffer[v0][j] == v1
			{
				e1 = edgebufferlookup[v0][j] // get index into newv of this edge vertex
				break;
			}
	else
		for j = 0 to edgebuffer[v1].size
			if edgebuffer[v1][j] = v0
			{	e1 = edgebufferlookup[v1][j] // get index into newv of this edge vertex
				break;
			}
	// now get e2, the edge vertex between v1 and v2
	if v1 < v2
		for j = 0 to edgebuffer[v1].size
			if edgebuffer[v1][j] == v2
			{
				e2 = edgebufferlookup[v1][j] // get index into newv of this edge vertex
				break;
			}
	else
		for j = 0 to edgebuffer[v2].size
			if edgebuffer[v2][j] = v1
			{	e2 = edgebufferlookup[v2][j] // get index into newv of this edge vertex
				break;
			}
	// now get e3, the edge vertex between v2 and v0
	-> same as the last two, just change the indices

	// create the new faces . . . make sure vertices are added in counter-clockwise fashion
	Face f1.vertices.push_back(v0,e1,e3)
	Face f2.vertices.push_back(v1,e2,e1)
	Face f3.vertices.push_back(v2,e3,e2)
	Face f4.vertices.push_back(e1,e2,e3)
	newfaces.push_back(f1,f2,f3,f4)
}

// lastly we should set up our new links
for i=0 to newfaces.size
	for j=0 to newfaces.vertices.size
		newlinks[faces[i].vertices[j]] = i;

// now we replace our coarse mesh with the fine one
vertices = newvertices
faces = newfaces
link = newlinks

// we now need to find boundaries, edge, and normal info again
calculateboundaries()
buildedgebuffer()
calculatenormals()

updateGL()