Tulip  4.4.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 #include <tulip/Graph.h>
31 
32 namespace tlp {
33 
34 /**
35  * @ingroup Checks
36  * @brief performs tests to check zhether a graph is planar.
37  * 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."
38  **/
39 class TLP_SCOPE PlanarityTest : private Observable {
40 public:
41  /*
42  The set of edges of the graph is modified during the execution of
43  the methods below. If you call one of them while iterating
44  on the edges of the graph, be careful to use a StableIterator
45  to avoid any possible invalidation of the iterator.
46  */
47 
48  /**
49  * @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).
50  *
51  * @param graph The graph to check for planarity.
52  * @return bool True if the graph is planar, false otherwise.
53  * @note The graph is made biconnected to ease (?) the computation.
54  **/
55  static bool isPlanar(Graph *graph);
56 
57  /**
58  * Returns true if the current embedding of the graph is planar, false otherwise.
59  */
60  /**
61  * @brief Checks if the graph is plane (or a planar embedding).
62  * 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.
63  *
64  * @param graph The graph to check for a planar e;bedding.
65  * @return bool True if the graph is a planar embedding, false otherwise.
66  **/
67  static bool isPlanarEmbedding(const Graph *graph);
68 
69  /**
70  * @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.
71  * This modifies the order of the edges around the nodes.
72  *
73  * @param graph The graph to make a planar embedding of.
74  * @return bool True if the graph is planar, false otherwise.
75  **/
76  static bool planarEmbedding(Graph *graph);
77 
78  /**
79  * @brief Computes a list of edges that prevent the graph from being planar (i.e. part of the minor of K3,3 or K5).
80  *
81  * @param graph The graph on which to compute the obstruction edges.
82  * @return :list< tlp::edge, std::allocator< tlp::edge > > The obstruction edges.
83  **/
84  static std::list<edge> getObstructionsEdges(Graph *graph);
85 
86 private:
87  PlanarityTest() {}
88  //override of Observable::treatEvent to remove the cached result for a graph if it is modified.
89  void treatEvent(const Event&);
90  bool compute(Graph *graph);
91 
92  /**
93  * @brief Singleton instance of this class.
94  **/
95  static PlanarityTest * instance;
96  /**
97  * @brief Stored results for graphs. When a graph is updated, its entry is removed from the hashmap.
98  **/
99  TLP_HASH_MAP<const Graph*, bool> resultsBuffer;
100 };
101 
102 
103 }
104 #endif
105 ///@endcond