Exemple #1
0
void exercicio1(){
	GraphViewer *gv = new GraphViewer(600, 600, true);
	gv->createWindow(600, 600);
	gv->defineVertexColor("blue");
	gv->defineEdgeColor("black");
	gv->addNode(0);
	gv->addNode(1);
	gv->addEdge(0, 0, 1, EdgeType::UNDIRECTED);

	Sleep(100); // use sleep(1) in linux ; Sleep(100) on Windows

	gv->removeEdge(0);
	gv->removeNode(1);
	gv->addNode(2);
	gv->rearrange();

	Sleep(100);

	gv->addEdge(1, 0, 2, EdgeType::UNDIRECTED);
	gv->setVertexLabel(0, "Isto e um no");
	gv->setEdgeLabel(1, "Isto e uma aresta");
	gv->setVertexColor(2, "green");
	gv->setEdgeColor(1, "yellow");
	gv->rearrange();

}
Exemple #2
0
void exercicio1()
{
	GraphViewer *gv = new GraphViewer(600, 600, true);

	gv->setBackground("background.jpg");

	gv->createWindow(600, 600);

	gv->defineEdgeDashed(true);
	gv->defineVertexColor("blue");
	gv->defineEdgeColor("black");

	gv->addNode(0);
	gv->addNode(1);
	gv->addEdge(0, 0, 1, EdgeType::UNDIRECTED);

	Sleep(2000); // use sleep(1) in linux ; Sleep(2000) on Windows

	gv->removeEdge(0);
	gv->removeNode(1);
	gv->addNode(2);

	gv->rearrange();

	Sleep(2000);

	gv->addEdge(1, 0, 2, EdgeType::UNDIRECTED);
	gv->defineEdgeCurved(false);

	gv->setVertexLabel(0, "Isto e um no");
	gv->setEdgeLabel(1, "Isto e uma aresta");

	gv->setVertexColor(2, "green");
	gv->setEdgeColor(1, "yellow");

	gv->setVertexSize(2, 40);
	gv->setVertexIcon(0, "icon.gif");

	gv->setEdgeDashed(1, false);

	gv->rearrange();

}
Exemple #3
0
/**
 *  \brief Prints the given graph
 *  \param grafo Graph to be printed
 */
void showGraph(Graph<Localizacao> &grafo)
{
 	GraphViewer *gv = new GraphViewer(800, 800, true);

 	gv->createWindow(800, 800);


 	gv->defineVertexColor("blue");
 	gv->defineEdgeColor("black");


	unsigned int id1, id2;
 	string s;
 	stringstream ss;


 	for (unsigned int i = 0; i < grafo.getVertexSet().size(); i++) {
 		id1 = grafo.getVertexSet()[i]->getInfo().getId();
 		s = grafo.getVertexSet()[i]->getInfo().getRua();
 		ss << 1;
 		gv->addNode(id1);
 		gv->setVertexLabel(id1, s + " " + ss.str());

 		if(grafo.getVertexSet()[i]->getInfo().getNome() == "Garagem")
 			gv->setVertexColor(id1,"red");
 		else if(grafo.getVertexSet()[i]->getInfo().getNome() == "Escola")
 			gv->setVertexColor(id1,"green");


 		ss.str("");
 	}
 	gv->rearrange();

 	for (unsigned int vert = 0; vert < grafo.getVertexSet().size(); vert++) {
 		for (unsigned int edge = 0; edge < grafo.getVertexSet()[vert]->getAdj().size(); edge++) {
 			id1 = grafo.getVertexSet()[vert]->getInfo().getId();
 			id2 = grafo.getVertexSet()[vert]->getAdj()[edge].getDest()->getInfo().getId();


 			if (grafo.getVertexSet()[vert]->path != NULL && grafo.getVertexSet()[vert]->path->getInfo().getId() == id2) {
 				gv->setEdgeColor(id1*1000 + id2, "green");
 				gv->setEdgeThickness(id1*1000 + id2, 5);
			}


 			gv->addEdge(id1 * 1000 + id2, id1, id2, EdgeType::DIRECTED);

 			gv->setEdgeWeight(id1 * 1000 + id2, grafo.getVertexSet()[vert]->getAdj()[edge].getWeight());
 			ss.str("");
 		}
 	}

 	gv->rearrange();

 #ifdef __linux__
 	sleep(1);
 #else
 	Sleep(100); // use sleep(1) in linux ; Sleep(100) on Windows
 #endif

}