Пример #1
0
void Graph::move(vec3d amount){
	if (selectednodes.size() > 0) {
		int selectednodeindex = selectednodes.back();
		GraphNode * selected = adjlist.at(selectednodeindex);
		selected->visited(true);
		vector<GraphNode * > level0  = selected-> nodesvec();
	
		 vector < vector< GraphNode* > > visitednodes;
		 visitednodes.push_back(level0);
		 
		 traverse(visitednodes);
		 
		 //printf("size of visitednodes: %d \n", visitednodes.size());
		 //do the actual move
		
		selected -> move(amount);
		for (int v=0; v<visitednodes.size(); v++) {
			amount = amount * 0.4;
			vector<GraphNode * > lv = visitednodes.at(v);
			for (int n=0; n<lv.size(); n++) {
				GraphNode * g = lv.at(n);
				g->move(amount);
			}
		}
		 
		 //unmark all nodes
		for (int a=0; a<adjlist.size(); a++) {
			adjlist.at(a)->visited(false);
		}
		 
	}
	else printf("Graph:move no valid selected node \n");
}
Пример #2
0
void Graph::traverse(vector < vector <GraphNode* > > & bftr){
	//recursive implementation
	vector<GraphNode *> level = bftr.at(bftr.size()-1);
	vector<GraphNode *> newlevel; 
	for (int l=0; l<level.size(); l++) {
		vector<GraphNode *> nodes = level.at(l) -> nodesvec();
		
		for (int n=0; n<nodes.size(); n++) {
			GraphNode * g = nodes.at(n);
			if (! ( g->isVisited() ) ) { //unvisited sibling
				newlevel.push_back(g);
				g->visited(true);
			}
		}
		
	}
	if (newlevel.size() > 0 ) {
		//printf("next level size: %d \n", newlevel.size());
		bftr.push_back(newlevel);
		traverse(bftr);
	}
	
}