Esempio n. 1
0
void Kruskal( int D[][10], int v, int V[][2], int E[][2] )
{
	int min = D[0][0], v1 = 0, v2 = 0;
	while( count < v )
	{
	min = 2000; v1 = 0; v2 = 0;
	for( int i = 0; i < v; i++ ) //find minimum in the distance matrix
	{
		for( int j = i+1; j < v; j++ )
		{
			if( D[i][j] < min )
			{
				min = D[i][j];
				v1 = i; v2 = j;
			}
		}
	}
	D[v1][v2] = D[v2][v1] = MAX;
	if( ADDVERT( v1, v2, V ) == 1 )
	{
		ADDEDGE( v1+1, v2+1, E );
	}
	//else cout<<"\nEdge not added";
}
}
Esempio n. 2
0
void trpgwGeomHelper::Optimize()
{
    int dtype = (dataType == UseDouble ? trpgGeometry::DoubleData : trpgGeometry::FloatData);

    // Potentially writing to all of these
    strips.SetPrimType(trpgGeometry::TriStrips);
    fans.SetPrimType(trpgGeometry::TriFans);
    bags.SetPrimType(trpgGeometry::Triangles);
    unsigned int numMat = matTri.size();
    for (unsigned int loop =0; loop < numMat; loop++ ) {
        strips.AddMaterial(matTri[loop]);
        strips.AddTexCoords(trpgGeometry::PerVertex);
        fans.AddMaterial(matTri[loop]);
        fans.AddTexCoords(trpgGeometry::PerVertex);
        bags.AddMaterial(matTri[loop]);
        bags.AddTexCoords(trpgGeometry::PerVertex);
    }

    int numTri = vert.size()/3;

    if (numTri == 0)
        return;

    // Iterate through the triangles
    enum {Strip,Fan,Bag};
    int type,triId;
    optVert a[3],b[3],c[3];
    for (triId = 0; triId<numTri; ) {
        // Triangle A
        int vid = 3*triId;
        a[0] = optVert(numMat,vid,vert,norm,tex);
        a[1] = optVert(numMat,vid+1,vert,norm,tex);
        a[2] = optVert(numMat,vid+2,vert,norm,tex);
        // If we've got two or more triangles to go, try to form something
        if (triId + 1 <numTri) {
            // Triangle B
            b[0] = optVert(numMat,vid+3,vert,norm,tex);
            b[1] = optVert(numMat,vid+4,vert,norm,tex);
            b[2] = optVert(numMat,vid+5,vert,norm,tex);

            // Is it a triangle strip?
            if (a[1] == b[1] && a[2] == b[0])
                type = Strip;
            else {
                // Might be a Fan
                if (a[0] == b[0] && a[1] == b[2])
                    type = Fan;
                else
                    type = Bag;
            }
        } else
            type = Bag;

        switch (type) {
        case Bag:
            ADDVERT(bags,a[0]);
            ADDVERT(bags,a[1]);
            ADDVERT(bags,a[2]);
            bags.AddPrim();
            triId++;
            stats.AddBagStat(1);
            break;
        case Strip:
        {
            bool isStrip=true, flip=true;
            int primLen = 0;
            // Dump A into the strip
            ADDVERT(strips,a[0]);
            ADDVERT(strips,a[1]);
            ADDVERT(strips,a[2]);
            triId++;
            primLen = 3;
            do {
                // Already checked that B was good on last go-round
                ADDVERT(strips,b[2]);  primLen++;
                triId++;
                vid = 3*triId;

                if (triId < numTri) {
                    // B is the new primary, check it against the next
                    c[0] = optVert(numMat,vid,vert,norm,tex);
                    c[1] = optVert(numMat,vid+1,vert,norm,tex);
                    c[2] = optVert(numMat,vid+2,vert,norm,tex);
                    if (flip)
                        isStrip = (c[0] == b[0] && c[1] == b[2]);
                    else
                        isStrip = (c[0] == b[2] && c[1] == b[1]);
                    b[0] = c[0];  b[1] = c[1];  b[2] = c[2];
                } 
                flip = !flip;
            } while (triId < numTri && isStrip);

            strips.AddPrimLength(primLen);
            stats.AddStripStat(primLen);
        }
        break;
        case Fan:
        {
            bool isFan = true;
            int primLen = 0;

            // Dump A into the Fan
            ADDVERT(fans,a[0]);
            ADDVERT(fans,a[2]);
            ADDVERT(fans,a[1]);
            triId++;
            primLen = 3;
            do {
                // Already know that B is good, add that
                ADDVERT(fans,b[1]);  primLen++;
                triId++;
                vid = 3*triId;

                if (triId < numTri) {
                    // B is the new primary, check it agains the next
                    c[0] = optVert(numMat,vid,vert,norm,tex);
                    c[1] = optVert(numMat,vid+1,vert,norm,tex);
                    c[2] = optVert(numMat,vid+2,vert,norm,tex);
                    isFan = (c[0] == b[0] && c[2] == b[1]);
                    b[0] = c[0];  b[1] = c[1];  b[2] = c[2];
                }
            } while (triId < numTri && isFan);

            fans.AddPrimLength(primLen);
            stats.AddFanStat(primLen);
        }
        break;
        }
    }
}