// assumes, that the Graphs of MultilevelGraph and GA are the same, not copies! void MultilevelGraph::exportAttributesSimple(GraphAttributes &GA) const { OGDF_ASSERT(&(GA.constGraph()) == m_G); prepareGraphAttributes(GA); for(node v : m_G->nodes) { GA.x(v) = m_GA->x(v); GA.y(v) = m_GA->y(v); //TODO: Check what this w,h computation does double w = GA.width(v); double h = GA.height(v); if(w > 0 || h > 0) { double factor = m_radius[v] / sqrt(w*w + h*h) * 2.0f; w *= factor; h *= factor; } else { w = h = m_radius[v] * sqrt(2.0f); } GA.width(v) = w; GA.height(v) = h; GA.weight(v) = m_reverseNodeMergeWeight[v->index()]; } for(edge e : m_G->edges) { GA.doubleWeight(e) = m_weight[e]; } }
MultilevelGraph::MultilevelGraph(GraphAttributes &GA, Graph &G) :m_createdGraph(false) { m_G = &G; m_nodeAssociations.init(*m_G, 0); m_edgeAssociations.init(*m_G, 0); m_x.init(*m_G); m_y.init(*m_G); m_radius.init(*m_G); m_weight.init(*m_G); prepareGraphAttributes(GA); importAttributes(GA); initReverseIndizes(); }
void MultilevelGraph::exportAttributes(GraphAttributes &GA) const { OGDF_ASSERT(GA.constGraph().numberOfNodes() == m_G->numberOfNodes()); OGDF_ASSERT(GA.constGraph().numberOfEdges() == m_G->numberOfEdges()); prepareGraphAttributes(GA); std::vector<node> tempNodeAssociations; const Graph &cG = GA.constGraph(); tempNodeAssociations.resize(cG.maxNodeIndex()+1, nullptr); for(node v : cG.nodes) { tempNodeAssociations[v->index()] = v; } for(node v : m_G->nodes) { GA.x(tempNodeAssociations[m_nodeAssociations[v]]) = m_GA->x(v); GA.y(tempNodeAssociations[m_nodeAssociations[v]]) = m_GA->y(v); double w = GA.width(tempNodeAssociations[m_nodeAssociations[v]]); double h = GA.height(tempNodeAssociations[m_nodeAssociations[v]]); if(w > 0 || h > 0) { double factor = m_radius[v] / sqrt(w*w + h*h) * 2.0f; w *= factor; h *= factor; } else { w = h = m_radius[v] * sqrt(2.0f); } GA.width(tempNodeAssociations[m_nodeAssociations[v]]) = w; GA.height(tempNodeAssociations[m_nodeAssociations[v]]) = h; GA.weight(tempNodeAssociations[m_nodeAssociations[v]]) = m_reverseNodeMergeWeight[v->index()]; } std::vector<edge> tempEdgeAssociations; tempEdgeAssociations.resize(cG.maxEdgeIndex()+1, nullptr); for(edge e :cG.edges) { tempEdgeAssociations[e->index()] = e; } for(edge e : m_G->edges) { GA.doubleWeight(tempEdgeAssociations[m_edgeAssociations[e]]) = m_weight[e]; } }
MultilevelGraph::MultilevelGraph(const String &filename) :m_createdGraph(true) { m_G = new Graph(); if(m_G == 0) { OGDF_THROW(InsufficientMemoryException); } m_nodeAssociations.init(*m_G); m_edgeAssociations.init(*m_G); m_radius.init(*m_G); m_weight.init(*m_G); initInternal(); //GraphAttributes tempGA(*m_G); m_GA->readGML(*m_G, filename); prepareGraphAttributes(*m_GA); importAttributesSimple(*m_GA); initReverseIndizes(); }
MultilevelGraph::MultilevelGraph(GraphAttributes &GA) :m_createdGraph(false) { m_G = new Graph(); if(m_G == 0) { OGDF_THROW(InsufficientMemoryException); } else { m_createdGraph = true; } m_nodeAssociations.init(*m_G); m_edgeAssociations.init(*m_G); m_x.init(*m_G); m_y.init(*m_G); m_radius.init(*m_G); m_weight.init(*m_G); copyFromGraph(GA.constGraph(), m_nodeAssociations, m_edgeAssociations); prepareGraphAttributes(GA); importAttributes(GA); initReverseIndizes(); }
MultilevelGraph::MultilevelGraph(const char *filename) : m_createdGraph(true) { m_G = new Graph(); if(m_G == nullptr) { OGDF_THROW(InsufficientMemoryException); } m_nodeAssociations.init(*m_G); m_edgeAssociations.init(*m_G); m_radius.init(*m_G); m_weight.init(*m_G); initInternal(); #if 0 GraphAttributes tempGA(*m_G); #endif GraphIO::read(*m_GA, *m_G, filename, GraphIO::readGML); prepareGraphAttributes(*m_GA); importAttributesSimple(*m_GA); initReverseIndizes(); }
MultilevelGraph::MultilevelGraph(GraphAttributes &GA) :m_createdGraph(true) { m_G = new Graph(); if(m_G == 0) { OGDF_THROW(InsufficientMemoryException); } //replaces layout info stuff below initInternal(); m_nodeAssociations.init(*m_G); m_edgeAssociations.init(*m_G); m_radius.init(*m_G); m_weight.init(*m_G); copyFromGraph(GA.constGraph(), m_nodeAssociations, m_edgeAssociations); prepareGraphAttributes(GA); importAttributes(GA); initReverseIndizes(); }
MultilevelGraph::MultilevelGraph(istream &is) :m_createdGraph(false) { m_G = new Graph(); if(m_G == 0) { OGDF_THROW(InsufficientMemoryException); } else { m_createdGraph = true; } m_nodeAssociations.init(*m_G); m_edgeAssociations.init(*m_G); m_x.init(*m_G); m_y.init(*m_G); m_radius.init(*m_G); m_weight.init(*m_G); GraphAttributes tempGA(*m_G); tempGA.readGML(*m_G, is); prepareGraphAttributes(tempGA); importAttributesSimple(tempGA); initReverseIndizes(); }