GraphLibrary  0.0.1
A simple library that implements various graph algorithms.
 All Classes Namespaces Files Functions Variables Typedefs Macros
EntitySelector.hpp
Go to the documentation of this file.
1 #ifndef GL_ENTITY_SELECTOR_HPP
2 #define GL_ENTITY_SELECTOR_HPP
3 
4 #include "../gl_base.hpp"
5 #include "../structures/Color.hpp"
6 
7 #include <functional>
8 
9 namespace gl::interface
10 {
11 
20 template <class GRAPH>
21 std::function<std::pair<bool,gl::Color>(const gl::index_type src, const gl::index_type dest)> getEdgeSelectorFromGraph (const GRAPH& graph,
22 const gl::Color& trueColor = gl::Color("red"), const gl::Color& falseColor = gl::Color("black"))
23 {
24  return [graph, trueColor, falseColor](const gl::index_type src, const gl::index_type dest) -> std::pair<bool,gl::Color> {
25  if (graph.hasEdge(src,dest))
26  {
27  return {true,trueColor};
28  }
29  else
30  return {false,falseColor};
31  };
32 }
33 
42 template <class PATH>
43 std::function<std::pair<bool,gl::Color>(const gl::index_type src, const gl::index_type dest)> getEdgeSelectorFromPath (const PATH& path,
44 const gl::Color& trueColor = gl::Color("red"), const gl::Color& falseColor = gl::Color("black"))
45 {
46  return [path, trueColor, falseColor](const gl::index_type src, const gl::index_type dest) -> std::pair<bool,gl::Color> {
47 
48  if (!path.first) return {false,falseColor};
49  for (gl::index_type i = 0; i < path.second.size() - 1; i++)
50  {
51  if (path.second[i] == src && path.second[i+1] == dest)
52  return {true,trueColor};
53  }
54  return {false,falseColor};
55  };
56 }
57 
68 template <class SHORTEST_PATH_ALGORITHM>
69 std::function<std::pair<bool,gl::Color>(const gl::index_type src, const gl::index_type dest)> getEdgeSelectorFromShortestPath (SHORTEST_PATH_ALGORITHM& spa, const gl::index_type pathSource, const gl::index_type pathDest, const gl::Color& trueColor = gl::Color("red"), const gl::Color& falseColor = gl::Color("black"))
70 {
71  return [&spa, pathSource, pathDest, trueColor, falseColor](const gl::index_type src, const gl::index_type dest) -> std::pair<bool,gl::Color> {
72  auto path = spa.getPath(pathSource,pathDest);
73  auto selEdge = getEdgeSelectorFromPath(path,trueColor,falseColor);
74  return selEdge(src,dest);
75  };
76 }
77 
87 template <class SHORTEST_PATH_ALGORITHM>
88 std::function<std::pair<bool,gl::Color>(const gl::index_type src, const gl::index_type dest)> getEdgeSelectorFromShortestPathTree (SHORTEST_PATH_ALGORITHM& spa, const gl::index_type treeSource,
89 const gl::Color& trueColor = gl::Color("red"), const gl::Color& falseColor = gl::Color("black"))
90 {
91  return [&spa, treeSource, trueColor, falseColor](const gl::index_type src, const gl::index_type dest) -> std::pair<bool,gl::Color> {
92  auto spt = spa.getSPT(treeSource);
93  auto selEdge = getEdgeSelectorFromGraph(spt,trueColor,falseColor);
94  return selEdge(src,dest);
95  };
96 }
97 
106 template <class PATH>
107 std::function<std::pair<bool,gl::Color>(const gl::index_type node)> getNodeSelectorFromPath (const PATH& path,
108 const gl::Color& trueColor = gl::Color("red"), const gl::Color& falseColor = gl::Color("white"))
109 {
110  return [path, trueColor, falseColor](const gl::index_type node) -> std::pair<bool,gl::Color> {
111 
112  if (!path.first) return {false,falseColor};
113  for (gl::index_type i = 0; i < path.second.size(); i++)
114  {
115  if (path.second[i] == node)
116  return {true,trueColor};
117  }
118  return {false,falseColor};
119  };
120 }
121 
132 template <class SHORTEST_PATH_ALGORITHM>
133 std::function<std::pair<bool,gl::Color>(const gl::index_type node)> getNodeSelectorFromShortestPath (SHORTEST_PATH_ALGORITHM& spa,
134 const gl::index_type pathSource, const gl::index_type pathDest, const gl::Color& trueColor = gl::Color("red"), const gl::Color& falseColor = gl::Color("white"))
135 {
136  return [&spa, pathSource, pathDest, trueColor, falseColor](const gl::index_type node) -> std::pair<bool,gl::Color> {
137  auto path = spa.getPath(pathSource,pathDest);
138  auto selEdge = getNodeSelectorFromPath(path,trueColor,falseColor);
139  return selEdge(node);
140  };
141 }
142 
152 template <class SHORTEST_PATH_ALGORITHM>
153 std::function<std::pair<bool,gl::Color>(const gl::index_type node)> getNodeSelectorFromShortestPathTree (SHORTEST_PATH_ALGORITHM& spa, const gl::index_type treeSource,
154 const gl::Color& trueColor = gl::Color("red"), const gl::Color& falseColor = gl::Color("white"))
155 {
156  return [&spa, treeSource, trueColor, falseColor](const gl::index_type node) -> std::pair<bool,gl::Color> {
157  if (!spa.pathLength(treeSource,node).isInfinite())
158  {
159  return {true,trueColor};
160  }
161  else
162  {
163  return {false,falseColor};
164  }
165  };
166 }
167 
168 } // namespace gl::interface
169 
170 #endif // GL_ENTITY_SELECTOR_HPP
Stores an RGBA Color.
Definition: Color.hpp:21
std::function< std::pair< bool, gl::Color >const gl::index_type src, const gl::index_type dest)> getEdgeSelectorFromPath(const PATH &path, const gl::Color &trueColor=gl::Color("red"), const gl::Color &falseColor=gl::Color("black"))
Provides a Selector Object to color the edges in a given Path.
Definition: EntitySelector.hpp:43
std::size_t index_type
Definition: gl_base.hpp:18
std::function< std::pair< bool, gl::Color >const gl::index_type node)> getNodeSelectorFromShortestPathTree(SHORTEST_PATH_ALGORITHM &spa, const gl::index_type treeSource, const gl::Color &trueColor=gl::Color("red"), const gl::Color &falseColor=gl::Color("white"))
Provides a Selector Object to color the nodes in a Shortest Path Tree.
Definition: EntitySelector.hpp:153
std::function< std::pair< bool, gl::Color >const gl::index_type src, const gl::index_type dest)> getEdgeSelectorFromShortestPath(SHORTEST_PATH_ALGORITHM &spa, const gl::index_type pathSource, const gl::index_type pathDest, const gl::Color &trueColor=gl::Color("red"), const gl::Color &falseColor=gl::Color("black"))
Provides a Selector Object to color the edges in a Shortest Path.
Definition: EntitySelector.hpp:69
std::function< std::pair< bool, gl::Color >const gl::index_type node)> getNodeSelectorFromPath(const PATH &path, const gl::Color &trueColor=gl::Color("red"), const gl::Color &falseColor=gl::Color("white"))
Provides a Selector Object to color the nodes in a given Path.
Definition: EntitySelector.hpp:107
std::function< std::pair< bool, gl::Color >const gl::index_type src, const gl::index_type dest)> getEdgeSelectorFromShortestPathTree(SHORTEST_PATH_ALGORITHM &spa, const gl::index_type treeSource, const gl::Color &trueColor=gl::Color("red"), const gl::Color &falseColor=gl::Color("black"))
Provides a Selector Object to color the edges in a Shortest Path Tree.
Definition: EntitySelector.hpp:88
std::function< std::pair< bool, gl::Color >const gl::index_type src, const gl::index_type dest)> getEdgeSelectorFromGraph(const GRAPH &graph, const gl::Color &trueColor=gl::Color("red"), const gl::Color &falseColor=gl::Color("black"))
Provides a Selector Object to color the edges in a given Graph.
Definition: EntitySelector.hpp:21
std::function< std::pair< bool, gl::Color >const gl::index_type node)> getNodeSelectorFromShortestPath(SHORTEST_PATH_ALGORITHM &spa, const gl::index_type pathSource, const gl::index_type pathDest, const gl::Color &trueColor=gl::Color("red"), const gl::Color &falseColor=gl::Color("white"))
Provides a Selector Object to color the nodes in a Shortest Path.
Definition: EntitySelector.hpp:133