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(); }
void printGraph(const Graph<NodeInfo> &graph, const vector<int> &path, const vector<int> &stations) { GraphViewer *gv = new GraphViewer(600, 600, false); gv->createWindow(600, 600); gv->defineVertexColor("black"); gv->defineEdgeColor("black"); vector<Vertex<NodeInfo> *> vertexSet = graph.getVertexSet(); for (size_t i = 0; i < vertexSet.size(); i++) { gv->addNode(vertexSet[i]->getInfo().id, vertexSet[i]->getInfo().x, vertexSet[i]->getInfo().y); if (vertexSet[i]->getInfo().name == "house") gv->setVertexColor(vertexSet[i]->getInfo().id, "red"); } for (size_t i = 0; i < stations.size(); i++) gv->setVertexColor(stations[i], "green"); int edgeID = 0; vector<int> edges; for (size_t i = 0; i < vertexSet.size(); i++) { vector<Edge<NodeInfo> > adj = vertexSet[i]->getAdjacentEdges(); for (size_t j = 0; j < adj.size(); j++) { int src = vertexSet[i]->getInfo().id; int dst = adj[j].getDestination()->getInfo().id; if (!edgeExists(edges, src, dst)) { gv->addEdge(edgeID, src, dst, EdgeType::UNDIRECTED); stringstream ss; ss << adj[j].getWeight(); gv->setEdgeLabel(edgeID, ss.str()); edges.push_back(src); edges.push_back(dst); edgeID++; } } } if (path.size() != 0) { for (size_t i = 0; i < path.size() - 1; i+=2) { gv->addEdge(edgeID, path[i], path[i + 1], EdgeType::UNDIRECTED); gv->setEdgeColor(edgeID, "green"); gv->setEdgeThickness(edgeID, 2); edgeID++; } } cin.clear(); cin.ignore(100, '\n'); cout << "\n\tPress enter to continue..."; cin.get(); gv->closeWindow(); delete(gv); }
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(); }