Don't import ogdf namespace
[TortoiseGit.git] / ext / OGDF / src / energybased / multilevelmixer / MedianPlacer.cpp
blob1e5bae008ce25c3df1773047afee1fd1d250c56f
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 at the Positio of the merge-partner
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/MedianPlacer.h>
44 #include <algorithm>
45 #include <vector>
47 namespace ogdf {
49 void MedianPlacer::placeOneLevel(MultilevelGraph &MLG)
51 int level = MLG.getLevel();
52 while (MLG.getLevel() == level && MLG.getLastMerge() != 0)
54 placeOneNode(MLG);
59 void MedianPlacer::placeOneNode(MultilevelGraph &MLG)
61 node merged = MLG.undoLastMerge();
62 int i = 0;
63 std::vector<double> xVector;
64 std::vector<double> yVector;
65 adjEntry adj;
66 forall_adj(adj, merged) {
67 i++;
68 xVector.push_back(MLG.x(adj->twinNode()));
69 yVector.push_back(MLG.y(adj->twinNode()));
71 std::nth_element(xVector.begin(), xVector.begin()+(i/2), xVector.end());
72 std::nth_element(yVector.begin(), yVector.begin()+(i/2), yVector.end());
73 double x = xVector[i/2];
74 double y = yVector[i/2];
75 if (i % 2 == 0) {
76 std::nth_element(xVector.begin(), xVector.begin()+(i/2)-1, xVector.end());
77 std::nth_element(yVector.begin(), yVector.begin()+(i/2)-1, yVector.end());
78 x += xVector[i/2 - 1];
79 y += yVector[i/2 - 1];
80 x /= 2.0;
81 y /= 2.0;
83 MLG.x(merged, x + ((m_randomOffset)?(float)randomDouble(-1.0, 1.0):0.f));
84 MLG.y(merged, y + ((m_randomOffset)?(float)randomDouble(-1.0, 1.0):0.f));
87 } // namespace ogdf