예제 #1
0
void gkBlenderMeshConverter::assignBoneAssignments(gkSubMesh* me, AssignmentListMap& dest)
{
	UTsize totface = me->getIndexBuffer().size();
	gkTriangle* ibuf = me->getIndexBuffer().ptr();

	for (UTsize f = 0; f < totface; ++f)
	{
		const gkTriangle& i = ibuf[f];

		findWeight((int)i.i0, me, dest);
		findWeight((int)i.i1, me, dest);
		findWeight((int)i.i2, me, dest);
	}
}
예제 #2
0
int findWeight(int i){
	if(i == 0) return 0;
	if(i == 1) return 1;
	//if i is a power of 2:
	//reasoning taken from SO question:
	//http://stackoverflow.com/questions/600293/how-to-check-if-a-number-is-a-power-of-2	
	if ((i & (i - 1)) == 0) return 1;
	
	//for a number that's greater than 1 and not a power of 2:
	
	//cp = closest power of 2 below i:
	int cp = 2;
	//while the next power of 2 is less than
	while(cp*2 < i) cp = cp*2;
	//...
	return 1 + findWeight(i-cp);
}
/* Returns the number of nodes inside a tree */
int findWeight( tree t )
{
    return ( emptyTree( t ) ? 0
             : 1 + findWeight( left( t ) ) + findWeight( right( t ) ) );
}
예제 #4
0
// The main function that constructs Minimum Spanning Tree (MST)
// using Prim's algorithm
void PrimMST(Graph* graph)
{
    int MSTWeight = 0;
    int V = graph->V;// Get the number of vertices in graph
    int E = graph->E;// Get the number of edges in graph
    int parent[V];   // Array to store constructed MST
    int key[V];      // Key values used to pick minimum weight edge in cut
 
    // minHeap represents set E
    MinHeap* minHeap = createMinHeap(V);
 
    // Initialize min heap with all vertices. Key value of
    // all vertices (except 0th vertex) is initially infinite

    // print edges of MST
    printf("===============================================\n");
    printf("Following are the edges in the constructed MST\n");

    for (int v = 1; v < V; ++v)
    {
        parent[v] = -1;
        key[v] = INT_MAX;
        minHeap->array[v] = newMinHeapNode(v, key[v]);
        minHeap->pos[v] = v;
    }
 
    // Make key value of 0th vertex as 0 so that it
    // is extracted first
    key[0] = 0;
    minHeap->array[0] = newMinHeapNode(0, key[0]);
    minHeap->pos[0]   = 0;
 
    // Initially size of min heap is equal to V
    minHeap->size = V;
 
    // In the followin loop, min heap contains all nodes
    // not yet added to MST.
    while (!isEmpty(minHeap))
    {
        // Extract the vertex with minimum key value
        MinHeapNode* minHeapNode = extractMin(minHeap);
        int u = minHeapNode->v; // Store the extracted vertex number
        // Traverse through all adjacent vertices of u (the extracted
        // vertex) and update their key values
	int i;
	int* adjList = findAdjList(graph,u);
        int size = findAdjListCount(graph, u, NULL, 0);
	//printf("%d->%d\n",adjList[0],adjList[1]);
        //printf("%d\n",size);
	for (i=1;i<size;i++) 
        {
	    int v = adjList[i];
	    // printf("%d\n",v);   
            // If v is not yet included in MST and weight of u-v is
            // less than key value of v, then update key value and
            // parent of v
            if (isInMinHeap(minHeap, v) && findWeight(graph,u,v) < key[v])
            {
                key[v] = findWeight(graph,u,v);
                parent[v] = u;
                decreaseKey(minHeap, v, key[v]);
	    }
	 }
	 MSTWeight += minHeapNode->key;
    }
    int n;
    for (n=1;n<V;n++) {
       printf("Edge: %d -- %d (Weight: %d)\n",parent[n],n,key[n]);
    }
    printf("Total Weight: %d\n", MSTWeight);
    printf("===============================================\n");
}