コード例 #1
0
	void PlanarizationGridLayout::doCall(
		const Graph &G,
		GridLayout &gridLayout,
		IPoint &bb)
	{
		m_nCrossings = 0;
		if(G.empty()) return;

		PlanRep pr(G);

		const int numCC = pr.numberOfCCs();
		// (width,height) of the layout of each connected component
		Array<IPoint> boundingBox(numCC);

		for(int cc = 0; cc < numCC; ++cc)
		{
			//--------------------------------------
			// 1. crossing minimization
			//--------------------------------------
			int cr;
			m_crossMin.get().call(pr, cc, cr);
			m_nCrossings += cr;
			OGDF_ASSERT(isPlanar(pr));

			GridLayout gridLayoutPG(pr);
			m_planarLayouter.get().callGrid(pr,gridLayoutPG);

			// copy grid layout of PG into grid layout of G
			for(int j = pr.startNode(); j < pr.stopNode(); ++j)
			{
				node vG = pr.v(j);

				gridLayout.x(vG) = gridLayoutPG.x(pr.copy(vG));
				gridLayout.y(vG) = gridLayoutPG.y(pr.copy(vG));

				adjEntry adj;
				forall_adj(adj,vG) {
					if ((adj->index() & 1) == 0) continue;
					edge eG = adj->theEdge();
					IPolyline &ipl = gridLayout.bends(eG);
					ipl.clear();

					bool firstTime = true;
					ListConstIterator<edge> itE;
					for(itE = pr.chain(eG).begin(); itE.valid(); ++itE) {
						if(!firstTime) {
							node v = (*itE)->source();
							ipl.pushBack(IPoint(gridLayoutPG.x(v),gridLayoutPG.y(v)));
						} else
							firstTime = false;
						ipl.conc(gridLayoutPG.bends(*itE));
					}
				}
			}

			boundingBox[cc] = m_planarLayouter.get().gridBoundingBox();
			boundingBox[cc].m_x += 1; // one row/column space between components
			boundingBox[cc].m_y += 1;
		}

		Array<IPoint> offset(numCC);
		m_packer.get().call(boundingBox,offset,m_pageRatio);

		bb.m_x = bb.m_y = 0;
		for(int cc = 0; cc < numCC; ++cc)
		{
			const int dx = offset[cc].m_x;
			const int dy = offset[cc].m_y;

			if(boundingBox[cc].m_x + dx > bb.m_x)
				bb.m_x = boundingBox[cc].m_x + dx;
			if(boundingBox[cc].m_y + dy > bb.m_y)
				bb.m_y = boundingBox[cc].m_y + dy;

			// iterate over all nodes in i-th cc
			for(int j = pr.startNode(cc); j < pr.stopNode(cc); ++j)
			{
				node vG = pr.v(j);

				gridLayout.x(vG) += dx;
				gridLayout.y(vG) += dy;

				adjEntry adj;
				forall_adj(adj,vG) {
					if ((adj->index() & 1) == 0) continue;
					edge eG = adj->theEdge();

					ListIterator<IPoint> it;
					for(it = gridLayout.bends(eG).begin(); it.valid(); ++it) {
						(*it).m_x += dx;
						(*it).m_y += dy;
					}
				}
			}
		}

		bb.m_x -= 1; // remove margin of topmost/rightmost box
		bb.m_y -= 1;
	}
void PlanarizationGridLayout::doCall(
	const Graph &G,
	GridLayout &gridLayout,
	IPoint &bb)
{
	m_nCrossings = 0;
	if(G.empty()) return;

	PlanRep PG(G);
	
	const int numCC = PG.numberOfCCs();
	// (width,height) of the layout of each connected component
	Array<IPoint> boundingBox(numCC);

	int i;
	for(i = 0; i < numCC; ++i)
	{
		PG.initCC(i);
		const int nOrigVerticesPG = PG.numberOfNodes();

		List<edge> deletedEdges;
		m_subgraph.get().callAndDelete(PG, deletedEdges);

		m_inserter.get().call(PG,deletedEdges);

		m_nCrossings += PG.numberOfNodes() - nOrigVerticesPG;

		GridLayout gridLayoutPG(PG);
		m_planarLayouter.get().callGrid(PG,gridLayoutPG);

		// copy grid layout of PG into grid layout of G
		ListConstIterator<node> itV;
		for(itV = PG.nodesInCC(i).begin(); itV.valid(); ++itV)
		{
			node vG = *itV;

			gridLayout.x(vG) = gridLayoutPG.x(PG.copy(vG));
			gridLayout.y(vG) = gridLayoutPG.y(PG.copy(vG));

			adjEntry adj;
			forall_adj(adj,vG) {
				if ((adj->index() & 1) == 0) continue;
				edge eG = adj->theEdge();
				IPolyline &ipl = gridLayout.bends(eG);
				ipl.clear();

				bool firstTime = true;
				ListConstIterator<edge> itE;
				for(itE = PG.chain(eG).begin(); itE.valid(); ++itE) {
					if(!firstTime) {
						node v = (*itE)->source();
						ipl.pushBack(IPoint(gridLayoutPG.x(v),gridLayoutPG.y(v)));
					} else
						firstTime = false;
					ipl.conc(gridLayoutPG.bends(*itE));
				}
			}
		}

		boundingBox[i] = m_planarLayouter.get().gridBoundingBox();
		boundingBox[i].m_x += 1; // one row/column space between components
		boundingBox[i].m_y += 1;
	}

	Array<IPoint> offset(numCC);
	m_packer.get().call(boundingBox,offset,m_pageRatio);

	bb.m_x = bb.m_y = 0;
	for(i = 0; i < numCC; ++i)
	{
		const List<node> &nodes = PG.nodesInCC(i);

		const int dx = offset[i].m_x;
		const int dy = offset[i].m_y;

		if(boundingBox[i].m_x + dx > bb.m_x)
			bb.m_x = boundingBox[i].m_x + dx;
		if(boundingBox[i].m_y + dy > bb.m_y)
			bb.m_y = boundingBox[i].m_y + dy;

		// iterate over all nodes in i-th cc
		ListConstIterator<node> it;
		for(it = nodes.begin(); it.valid(); ++it)
		{
			node vG = *it;

			gridLayout.x(vG) += dx;
			gridLayout.y(vG) += dy;

			adjEntry adj;
			forall_adj(adj,vG) {
				if ((adj->index() & 1) == 0) continue;
				edge eG = adj->theEdge();

				ListIterator<IPoint> it;
				for(it = gridLayout.bends(eG).begin(); it.valid(); ++it) {
					(*it).m_x += dx;
					(*it).m_y += dy;
				}
			}
		}
	}

	bb.m_x -= 1; // remove margin of topmost/rightmost box
	bb.m_y -= 1;
}