| 1 | /** \file |
| 2 | * \brief Tests for layout algorithms for cluster graphs. |
| 3 | * |
| 4 | * \author Tilo Wiedera |
| 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 | #include <ogdf/module/LayoutModule.h> |
| 33 | #include <ogdf/cluster/ClusterPlanarizationLayout.h> |
| 34 | #include <ogdf/cluster/ClusterOrthoLayout.h> |
| 35 | |
| 36 | #include "layout_helpers.h" |
| 37 | |
| 38 | //! Looks like a regular LayoutModule but creates a ClusterGraph that is handed to |
| 39 | //! a ClusterPlanarizationLayout instead. |
| 40 | class CPLMock : public LayoutModule { |
| 41 | ClusterPlanarizationLayout clusterPlanarizationLayout; |
| 42 | |
| 43 | public: |
| 44 | virtual void call(GraphAttributes &attr) override { |
| 45 | GraphCopy G(attr.constGraph()); |
| 46 | ClusterGraph C(G); |
| 47 | ClusterGraphAttributes cAttr(C); |
| 48 | |
| 49 | // add clique cluster |
| 50 | SList<node> nodes; |
| 51 | node nodeInClique = G.newNode(); |
| 52 | nodes.pushBack(nodeInClique); |
| 53 | |
| 54 | for(int i = 0; i < 10; i++) { |
| 55 | node w = G.newNode(); |
| 56 | for(node v : nodes) { |
| 57 | G.newEdge(v, w); |
| 58 | } |
| 59 | nodes.pushBack(w); |
| 60 | } |
| 61 | C.createCluster(nodes, C.firstCluster()); |
| 62 | |
| 63 | // add path cluster |
| 64 | nodes.clear(); |
| 65 | nodes.pushBack(G.newNode()); |
| 66 | for(int i = 0; i < 10; i++) { |
| 67 | node w = G.newNode(); |
| 68 | G.newEdge(nodes.back(), w); |
| 69 | nodes.pushBack(w); |
| 70 | } |
| 71 | |
| 72 | // connect it all |
| 73 | G.newEdge(nodeInClique, nodes.front()); |
| 74 | G.newEdge(nodeInClique, nodes.back()); |
| 75 | G.newEdge(nodeInClique, G.firstNode()); |
| 76 | |
| 77 | clusterPlanarizationLayout.call(G, cAttr, C); |
| 78 | |
| 79 | for (node v : G.nodes) { |
| 80 | if(!G.isDummy(v)) { |
| 81 | attr.x(G.original(v)) = cAttr.x(v); |
| 82 | attr.y(G.original(v)) = cAttr.y(v); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | for (edge e : G.edges) { |
| 87 | if(!G.isDummy(e)) { |
| 88 | attr.bends(G.original(e)) = cAttr.bends(e); |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | }; |
| 93 | |
| 94 | go_bandit([] { |
| 95 | describeLayout<CPLMock>("ClusterPlanarizationLayout" , 0, {GraphProperty::connected, GraphProperty::sparse, GraphProperty::simple}, true, GraphSizes(16, 32, 16)); |
| 96 | }); |
| 97 | |