Don't import ogdf namespace
[TortoiseGit.git] / ext / OGDF / src / energybased / multilevelmixer / SolarPlacer.cpp
blob32f1887c0a5a1e44ed328e91b37683a043acc639
1 /*
2 * $Revision: 2523 $
4 * last checkin:
5 * $Author: gutwenger $
6 * $Date: 2012-07-02 20:59:27 +0200 (Mon, 02 Jul 2012) $
7 ***************************************************************/
9 /** \file
10 * \brief Places Nodes with Solar System rules
12 * \author Gereon Bartel
14 * \par License:
15 * This file is part of the Open Graph Drawing Framework (OGDF).
17 * \par
18 * Copyright (C)<br>
19 * See README.txt in the root directory of the OGDF installation for details.
21 * \par
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License
24 * Version 2 or 3 as published by the Free Software Foundation;
25 * see the file LICENSE.txt included in the packaging of this file
26 * for details.
28 * \par
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
34 * \par
35 * You should have received a copy of the GNU General Public
36 * License along with this program; if not, write to the Free
37 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
38 * Boston, MA 02110-1301, USA.
40 * \see http://www.gnu.org/copyleft/gpl.html
41 ***************************************************************/
43 #include <ogdf/energybased/multilevelmixer/SolarPlacer.h>
45 namespace ogdf {
47 void SolarPlacer::placeOneLevel(MultilevelGraph &MLG)
49 int level = MLG.getLevel();
50 while (MLG.getLevel() == level && MLG.getLastMerge() != 0)
52 placeOneNode(MLG);
57 void SolarPlacer::placeOneNode(MultilevelGraph &MLG)
59 NodeMerge * lastNM = MLG.getLastMerge();
60 double x = 0.0;
61 double y = 0.0;
62 int i = 0;
64 node sun = MLG.getNode(lastNM->m_changedNodes.front());
65 std::vector< std::pair<int, double> > positions = lastNM->m_position;
67 node merged = MLG.undoLastMerge();
69 if (positions.size() > 0) {
70 for (std::vector< std::pair<int, double> >::iterator j = positions.begin(); j != positions.end(); j++) {
71 double factor = (*j).second;
72 node other_sun = MLG.getNode((*j).first);
73 i++;
74 x += MLG.x(sun) * factor + MLG.x(other_sun) * (1.0f-factor);
75 y += MLG.y(sun) * factor + MLG.y(other_sun) * (1.0f-factor);
77 } else {
78 i++;
79 x += MLG.x(sun);
80 y += MLG.y(sun);
83 OGDF_ASSERT(i > 0);
84 if (positions.size() == 0 || m_randomOffset) {
85 x += randomDouble(-1.0, 1.0);
86 y += randomDouble(-1.0, 1.0);
88 MLG.x(merged, (x / static_cast<double>(i)));
89 MLG.y(merged, (y / static_cast<double>(i)));
92 } // namespace ogdf