Example #1
0
void depthFirstRecursive(int ** matrix, int vertex, int matrixSize, int * visited ){
    int * adj = getAdjacent(matrix,matrixSize,vertex);
    int i = 0 ;
    visited[vertex] = 1 ;
    printf("%d ",vertex);
    for ( i = 0 ; i < matrixSize ; i++ ){
        if ( adj[i]  != -1 ){
            if (visited[adj[i]] == 0 ) {
                depthFirstRecursive(matrix,i,matrixSize,visited);
            }
        }
    }
}
Example #2
0
/**
 * Removes a given vertex from the graph.
 * @param v - the vertex to remove
 */
void Graph::removeVertex(Vertex v)
{
    assertExists(v, __func__);

    // first, remove all references to the vertex in every other edge list
    // luckily, we can call getAdjacent and work backwards
    //  instead of traversing the whole hash table
    vector<Vertex> adjacent = getAdjacent(v);
    vector<Vertex>::iterator it;
    for (it = adjacent.begin(); it != adjacent.end(); ++it)
        removeEdge(*it, v);

    // now that all references are gone, we can delete the vertex
    graph.erase(v);
    vertexLabels.erase(v);
}
void VoxelUnit::reassignDepth()
{
	for(int x=0;x<mVoxelsDim.x;x++)
	{
		for(int y=0;y<mVoxelsDim.y;y++)
		{
			for(int z=0;z<mVoxelsDim.z;z++)
			{
				Vector3 index((float)x,(float)y,(float)z);

				//get adjacent voxels, there will always be six
				Voxel* adj=getAdjacent(index);

				if(mVoxels[x][y][z].depth>=0)//if this is a full voxel
				{
					bool outsidePresent=false;
					for(int i=0;i<6;i++)
					{
						if(adj[i].depth<0)//if any adjacent voxels are not full
							outsidePresent=true;
					}
					if(outsidePresent)
						mVoxels[x][y][z].depth=SURFACE; //if touching empty voxels, must be on surface
					else
						mVoxels[x][y][z].depth=CENTER; //otherwise it's in the center
				}
				else if(mVoxels[x][y][z].depth!=EMPTY)//if a not full voxel, and not one that is permanently empty
				{
					bool objectPresent=false;
					for(int i=0;i<6;i++)
					{
						if(adj[i].depth>=0)//if any adjacent voxels are full
							objectPresent=true;
					}
					if(objectPresent)
					{
						mVoxels[x][y][z].depth=BORDER;//if touching a full voxel, must be on the border
						//if(RandomRegen)
							//mVoxels[x][y][z].regenTimer=(float)(rand()%(int)RegenTime);
					}
					else
						mVoxels[x][y][z].depth=DESTROYED;//otherwise it's just destroyed
				}
			}
		}
	}
}
Example #4
0
/**
 * Gets all the edges in the graph.
 * @return a vector of all the edges in the graph
 */
vector<Edge> Graph::getEdges() const
{
    if (graph.empty())
        return vector<Edge>();

    vector<Edge> ret;
    set<pair<Vertex, Vertex>> seen;
    VertexMap::const_iterator it;

    for (it = graph.begin(); it != graph.end(); ++it) {
        Vertex u = it->first;
        vector<Vertex> adj = getAdjacent(u);
        for (size_t i = 0; i < adj.size(); ++i) {
            Vertex v = adj[i];
            if (seen.find(make_pair(u, v)) == seen.end()) {
                ret.push_back(getEdge(u, v));
                seen.insert(make_pair(u, v));
                seen.insert(make_pair(v, u));
            }
        }
    }

    return ret;
}
Example #5
0
//returns a vector of locations around a location
vector<location> getAdjacent(int x, int y)
{
  return getAdjacent(location(x,y));
}