1 /** \file
2  * \brief Declaration of upward planarization layout algorithm.
3  *
4  * \author Hoi-Ming Wong
5  *
6  * \par License:
7  * This file is part of the Open Graph Drawing Framework (OGDF).
8  *
9  * \par
10  * Copyright (C)<br>
11  * See README.md in the OGDF root directory for details.
12  *
13  * \par
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * Version 2 or 3 as published by the Free Software Foundation;
17  * see the file LICENSE.txt included in the packaging of this file
18  * for details.
19  *
20  * \par
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  *
26  * \par
27  * You should have received a copy of the GNU General Public
28  * License along with this program; if not, see
29  * http://www.gnu.org/copyleft/gpl.html
30  */
31 
32 #pragma once
33 
34 #include <ogdf/basic/LayoutModule.h>
35 #include <ogdf/upward/UpwardPlanRep.h>
36 #include <ogdf/upward/LayerBasedUPRLayout.h>
37 #include <ogdf/upward/SubgraphUpwardPlanarizer.h>
38 
39 namespace ogdf {
40 
41 class UpwardPlanarizationLayout : public LayoutModule
42 {
43 public:
44 	// constructor: sets options to default values
UpwardPlanarizationLayout()45 	UpwardPlanarizationLayout()
46 	{
47 		m_cr_nr = 0;
48 		// set default module
49 		m_layout.reset(new LayerBasedUPRLayout());
50 		m_UpwardPlanarizer.reset(new SubgraphUpwardPlanarizer());
51 	}
52 
53 	// calls the algorithm for attributed graph GA
54 	// returns layout information in GA
call(GraphAttributes & GA)55 	virtual void call(GraphAttributes &GA) override
56 	{
57 		if(GA.constGraph().numberOfNodes() > 2) {
58 			UpwardPlanRep UPR;
59 			UPR.createEmpty(GA.constGraph());
60 			m_UpwardPlanarizer->call(UPR);
61 			m_layout->call(UPR, GA);
62 			m_cr_nr = UPR.numberOfCrossings();
63 			m_numLevels = m_layout->numberOfLevels;
64 		}
65 	}
66 
67 	// module option for the computation of the final layout
setUPRLayout(UPRLayoutModule * pLayout)68 	void setUPRLayout(UPRLayoutModule *pLayout) {
69 		m_layout.reset(pLayout);
70 	}
71 
setUpwardPlanarizer(UpwardPlanarizerModule * pUpwardPlanarizer)72 	void setUpwardPlanarizer(UpwardPlanarizerModule *pUpwardPlanarizer) {
73 		m_UpwardPlanarizer.reset(pUpwardPlanarizer);
74 	}
75 
76 	// returns the number of crossings in the layout after the algorithm
77 	// has been applied
numberOfCrossings()78 	int numberOfCrossings() const { return m_cr_nr; }
79 
numberOfLevels()80 	int numberOfLevels() const { return m_numLevels; }
81 
82 protected:
83 	int m_cr_nr;
84 	int m_numLevels;
85 	std::unique_ptr<UpwardPlanarizerModule> m_UpwardPlanarizer;
86 	std::unique_ptr<UPRLayoutModule> m_layout;
87 };
88 
89 }
90