Tulip  4.2.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
PlanarityTest.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 ///@cond DOXYGEN_HIDDEN
20 
21 
22 #ifndef TULIP_PLANARITYTESTX_H
23 #define TULIP_PLANARITYTESTX_H
24 
25 #include <list>
26 #include <tulip/tulipconf.h>
27 #include <tulip/tuliphash.h>
28 #include <tulip/Observable.h>
29 #include <tulip/Edge.h>
30 
31 namespace tlp {
32 
33 class Graph;
34 
35 /**
36  * @ingroup Checks
37  * @brief performs tests to check zhether a graph is planar.
38  * From wikipedia: "A planar graph is a graph that can be embedded in the plane, i.e., it can be drawn on the plane in such a way that its edges intersect only at their endpoints."
39  **/
40 class TLP_SCOPE PlanarityTest : private Observable {
41 public:
42  /*
43  The set of edges of the graph is modified during the execution of
44  the methods below. If you call one of them while iterating
45  on the edges of the graph, be careful to use a StableIterator
46  to avoid any possible invalidation of the iterator.
47  */
48 
49  /**
50  * @brief Checks whether the graph is planar (i.e. the graph can be drawn on the plane in such a way that no edges cross each other).
51  *
52  * @param graph The graph to check for planarity.
53  * @return bool True if the graph is planar, false otherwise.
54  * @note The graph is made biconnected to ease (?) the computation.
55  **/
56  static bool isPlanar(Graph *graph);
57 
58  /**
59  * Returns true if the current embedding of the graph is planar, false otherwise.
60  */
61  /**
62  * @brief Checks if the graph is plane (or a planar embedding).
63  * A planar graph *can* be drawn such as no edges cross each other, a plane graph *is* drawn such as no edges cross each other.
64  *
65  * @param graph The graph to check for a planar e;bedding.
66  * @return bool True if the graph is a planar embedding, false otherwise.
67  **/
68  static bool isPlanarEmbedding(const Graph *graph);
69 
70  /**
71  * @brief Makes a planar graph a planar embedding, i.e. makes a graph so that no edges cross each other if it is known to be possible.
72  * This modifies the order of the edges around the nodes.
73  *
74  * @param graph The graph to make a planar embedding of.
75  * @return bool True if the graph is planar, false otherwise.
76  **/
77  static bool planarEmbedding(Graph *graph);
78 
79  /**
80  * @brief Computes a list of edges that prevent the graph from being planar (i.e. part of the minor of K3,3 or K5).
81  *
82  * @param graph The graph on which to compute the obstruction edges.
83  * @return :list< tlp::edge, std::allocator< tlp::edge > > The obstruction edges.
84  **/
85  static std::list<edge> getObstructionsEdges(Graph *graph);
86 
87 private:
88  PlanarityTest() {}
89  //override of Observable::treatEvent to remove the cached result for a graph if it is modified.
90  void treatEvent(const Event&);
91  bool compute(Graph *graph);
92 
93  /**
94  * @brief Singleton instance of this class.
95  **/
96  static PlanarityTest * instance;
97  /**
98  * @brief Stored results for graphs. When a graph is updated, its entry is removed from the hashmap.
99  **/
100  TLP_HASH_MAP<unsigned long, bool> resultsBuffer;
101 };
102 
103 
104 }
105 #endif
106 ///@endcond