Tulip  5.3.0
Large graphs analysis and drawing
PlanarityTest.h
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
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 
20 #ifndef TULIP_PLANARITYTESTX_H
21 #define TULIP_PLANARITYTESTX_H
22 
23 #include <list>
24 #include <tulip/tulipconf.h>
25 #include <tulip/tuliphash.h>
26 #include <tulip/Observable.h>
27 #include <tulip/Edge.h>
28 #include <tulip/Graph.h>
29 
30 namespace tlp {
31 
32 /**
33  * @ingroup Checks
34  * @brief performs tests to check whether a graph is planar.
35  * From wikipedia: "A planar graph is a graph that can be embedded in the plane, i.e., it can be
36  *drawn on the plane in such a way that its edges intersect only at their endpoints."
37  **/
38 class TLP_SCOPE PlanarityTest : private Observable {
39 public:
40  /*
41  The set of edges of the graph is modified during the execution of
42  the methods below. If you call one of them while iterating
43  on the edges of the graph, be careful to use a StableIterator
44  to avoid any possible invalidation of the iterator.
45  */
46 
47  /**
48  * @brief Checks whether the graph is planar (i.e. the graph can be drawn on the plane in such a
49  *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
63  *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
72  *other if it is known to be possible.
73  * This modifies the order of the edges around the nodes.
74  *
75  * @param graph The graph to make a planar embedding of.
76  * @return bool True if the graph is planar, false otherwise.
77  **/
78  static bool planarEmbedding(Graph *graph);
79 
80  /**
81  * @brief Computes a list of edges that prevent the graph from being planar (i.e. part of the
82  *minor of K3,3 or K5).
83  *
84  * @param graph The graph on which to compute the obstruction edges.
85  * @return :list< tlp::edge, std::allocator< tlp::edge > > The obstruction edges.
86  **/
87  static std::list<edge> getObstructionsEdges(Graph *graph);
88 
89 private:
90  PlanarityTest() {}
91  // override of Observable::treatEvent to remove the cached result for a graph if it is modified.
92  void treatEvent(const Event &) override;
93  bool compute(Graph *graph);
94 
95  /**
96  * @brief Singleton instance of this class.
97  **/
98  static PlanarityTest *instance;
99  /**
100  * @brief Stored results for graphs. When a graph is updated, its entry is removed from the
101  *hashmap.
102  **/
103  TLP_HASH_MAP<const Graph *, bool> resultsBuffer;
104 };
105 } // namespace tlp
106 #endif
performs tests to check whether a graph is planar. From wikipedia: "A planar graph is a graph that ca...
Definition: PlanarityTest.h:38
Event is the base class for all events used in the Observation mechanism.
Definition: Observable.h:51
The Observable class is the base of Tulip&#39;s observation system.
Definition: Observable.h:141