Graphics Reference
In-Depth Information
edgeListHead[i] = NULL;
}
// Reset the edge list entry counter
int cnt = 0;
// Loop over all triangles and their three edges
for(inti=0;i<numTris; i++) {
for(intj=2,k=0;k<2;j=k,k++) {
// Get the vertex indices
int vj = tri[i].vertexIndex[j];
int vk = tri[i].vertexIndex[k];
// Treat edges (vj, vk) and (vk, vj) as equal by
// flipping the indices so vj <= vk (if necessary)
if (vj > vk) Swap(vj, vk);
// Form a hash key from the pair (vj, vk) in range 0 <= x < MAX_EDGES
int hashKey = ComputeHashKey(vj, vk);
// Check linked list to see if edge already present
for (EdgeEntry *pEdge = edgeListHead[hashKey]; ; pEdge = Edge- > pNext) {
// Edge is not in the list of this hash bucket; create new edge entry
if (pEdge == NULL) {
// Create new edge entry for this bucket
edgeListEntry[cnt].vertexIndex[0] = vj;
edgeListEntry[cnt].vertexIndex[1] = vk;
edgeListEntry[cnt].triangleIndex[0] = i;
edgeListEntry[cnt].edgeNumber[0] = j;
// Link new entry first in list and bump edge entry counter
edgeListEntry[cnt].pNext = edgeListHead[hashKey];
edgeListHead[hashKey] = &edgeListEntry[cnt++];
break;
}
// Edge is in this bucket, fill in the second edge
if (pEdge- > vertexIndex[0] == vj && pEdge- > vertexIndex[1] == vk) {
pEdge- > triangleIndex[1] = i;
pEdge- > edgeNumber[1] = j;
break;
}
}
}
}
This code can easily be merged with the code given in Section 12.2.1 so that in
addition to having the vertex table have each vertex index all of its incident faces
 
Search WWH ::




Custom Search