GridLayouter.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. #ifndef GRIDLAYOUTER_H
  2. #define GRIDLAYOUTER_H
  3. #include <Common/BoostGraphWrapper.h>
  4. #include <Common/LayoutEnum.h>
  5. #include <LayoutManager/GraphLayoutErrorCodes.h>
  6. #include <QMap>
  7. #include <GraphLayoutLibrary_global.h>
  8. #include <GridBasedLayout/GridBasedLayout.h>
  9. #include <GridBasedLayout/GraphPreProcessor.h>
  10. #include <ForceBasedLayout/Reingold.h>
  11. /**
  12. * @brief The GridLayouter class
  13. *
  14. * A class to handle grid based layout algorithm to be applied on a clustred graph.
  15. */
  16. class GRAPHLAYOUTLIBRARYSHARED_EXPORT GridLayouter
  17. {
  18. private:
  19. /**
  20. * @brief The enumVertexType enum to denote the type of vertex in list of edges to be added to NewGraph.
  21. */
  22. enum enumVertexType {ORIGINAL_VERTEX, NEW_VERTEX};
  23. /**
  24. * @brief The EdgeType enum to denote the type of edge in CurrentClusteredGraph with respect to current cluster.
  25. */
  26. enum EdgeType {COMMING_IN, GOING_OUT, NOT_INCIDENT, LIES_IN};
  27. /**
  28. * @brief The Node_Type_Pair struct to store a node in an edge that will replace edge in CurrentClusteredGraph.
  29. */
  30. struct Node_Type_Pair
  31. {
  32. VertexDescriptor vNode; /**< a vertex */
  33. enumVertexType vertexType; /**< type of the vertex */
  34. };
  35. /**
  36. * @brief edgeType type to define edge that will replace edge in CurrentClusteredGraph.
  37. */
  38. typedef std::vector<Node_Type_Pair> edgeType;
  39. public:
  40. /** @name Creators
  41. *
  42. * The methods under this section are responsible for constructing
  43. * an instance of type GridLayouter.
  44. */
  45. //@{
  46. /**
  47. Constructs new object of type GridLayouter.
  48. @pre none
  49. @param none
  50. @return none
  51. @throw none
  52. */
  53. GridLayouter();
  54. //@}
  55. /** @name Queries
  56. * The methods under this section are responsible for accessing
  57. * an instance of type GridLayouter.
  58. */
  59. //@{
  60. /**
  61. This method reads a clustered graph, applies grid based layout on the clustered graph.
  62. It works on the clusters recursively in bootom-up way. Innermost clusters will be layouted first
  63. and the the obtained layout is put in the parent cluster and so on.
  64. The layout is also reflected in RootClusteredGraph.
  65. * @brief gridLayouterForClusteredGraphProcess
  66. * applies Grid Based Layout to passed graph taking its clusters into consideration.
  67. *
  68. * @param gCurrentClusteredGraph
  69. * graph to be layed out.
  70. *
  71. * @param gRootClusteredGraph
  72. * root graph of the CurrentClusteredGraph.
  73. *
  74. * @return none
  75. *
  76. * @throw LayoutException
  77. */
  78. void gridLayouterForClusteredGraph(SubGraph & gCurrentClusteredGraph,
  79. SubGraph & gRootClusteredGraph);
  80. /**
  81. This method reads a non-clustered graph, applies grid based layout on the graph.
  82. It simply ignores the clusters in the graph if any are present and treats the graph as non-clustered.
  83. * @brief gridLayouterForNonClusteredGraphProcess
  84. * applies Grid Based Layout to passed graph without taking its clusters into consideration.
  85. *
  86. * @param gCurrentNonClusteredGraph
  87. * graph to be layed out.
  88. *
  89. * @return none
  90. *
  91. * @throw LayoutException
  92. */
  93. void gridLayouterForNonClusteredGraph(SubGraph & gCurrentNonClusteredGraph);
  94. //@}
  95. private:
  96. /**
  97. This method adds vertices to the NewGraph. Vertices are added for all vertices and clusteres
  98. at current level of CurrentClustered graph. NewGraph will not contain any cluster.
  99. It also saves Maps from vertices of NewGraph to their corresponding vertices or clusters
  100. in CurrentClusteredGraph.
  101. * @brief addVerticesToNewGraphProcess
  102. * adds vertices to NewGraph corresponding to vertices and clusters of CurrentClusteredGraph.
  103. *
  104. * @param gCurrentNonClusteredGraph
  105. * input graph from which the vertices are to be added to NewGraph.
  106. *
  107. * @param gNewGraph
  108. * graph to which the vertices are to be added.
  109. *
  110. * @param gRootClusteredGraph
  111. * root graph of the CurrentClusteredGraph.
  112. *
  113. * @param isCluster
  114. * map from vertex of NewGraph to a flag that specifies whether that vertex corresponds to
  115. * a vertex or a cluster in CurrentClusteredGraph.
  116. *
  117. * @param originalVertexForNewVertex
  118. * map from vertex of NewGraph to its corresponding vertex in CurrentClusteredGraph.
  119. *
  120. * @param childrenList
  121. * map from vertex of NewGraph to its corresponding cluster in CurrentClusteredGraph.
  122. *
  123. * @return none
  124. *
  125. * @throw LayoutException
  126. */
  127. void addVerticesToNewGraph(SubGraph & gCurrentClusteredGraph, SubGraph & gNewGraph,
  128. SubGraph & gRootClusteredGraph,
  129. QMap <int, bool> & isCluster,
  130. QMap <int, VertexIterator> & originalVertexForNewVertex,
  131. QMap <int, ChildrenIterator> & childrenList);
  132. /**
  133. This method finds the edges from CurrentClusteredGraph that should not be added to NewGraph
  134. and the edges that will replace these edges if any. It saves the list of edges that are to be removed
  135. while transfering to NewGraph and corresponding edges to be added to NewGraph if any.
  136. * @brief findEdgesToBeAddedRemovedProcess
  137. * finds edges to be removed from CurrentClusteredGraph and to be added to NewGraph.
  138. *
  139. * @param gCurrentNonClusteredGraph
  140. * input graph from which the vertices are to be added to NewGraph.
  141. *
  142. * @param gNewGraph
  143. * graph to which the vertices are to be added.
  144. *
  145. * @param oEdgesToRemove
  146. * vector that will store edges that should be replaced by new edges in NewGraph.
  147. *
  148. * @param oEdgesToAdd
  149. * vector that will store edges that should replace edges from CurrentClusteredGraph.
  150. *
  151. * @param oInnerEdgesToRemove
  152. * vector that will store edges that should not be added in NewGraph.
  153. *
  154. * @param childrenList
  155. * map from vertex of NewGraph to its corresponding cluster in CurrentClusteredGraph.
  156. *
  157. * @return none
  158. *
  159. * @throw LayoutException
  160. */
  161. void findEdgesToBeAddedRemoved(SubGraph & gCurrentClusteredGraph, SubGraph & gNewGraph,
  162. std::vector<GraphPreProcessor::VertexOrderType> & oEdgesToRemove,
  163. std::vector<GridLayouter::edgeType> & oEdgesToAdd,
  164. std::vector<GraphPreProcessor::VertexOrderType> & oInnerEdgesToRemove,
  165. QMap <int, ChildrenIterator> & childrenList);
  166. /**
  167. This method reads the edges from CurrentClusteredGraph that should not be added to NewGraph
  168. and the edges that will replace these edges if any. It removes or replaces these removed edges by new edges.
  169. * @brief addEdgesToNewGraphProcess
  170. * adds edges to NewGraph corresponding to edges in CurrentClusteredGraph.
  171. *
  172. * @param gCurrentNonClusteredGraph
  173. * input graph from which the vertices are to be added to NewGraph.
  174. *
  175. * @param gNewGraph
  176. * graph to which the vertices are to be added.
  177. *
  178. * @param oEdgesToRemove
  179. * vector that stores edges that should be replaced by new edges in NewGraph.
  180. *
  181. * @param oEdgesToAdd
  182. * vector that stores edges that should replace edges from CurrentClusteredGraph.
  183. *
  184. * @param oInnerEdgesToRemove
  185. * vector that stores edges that should not be added in NewGraph.
  186. *
  187. * @param originalVertexForNewVertex
  188. * map from vertex of NewGraph to its corresponding vertex in CurrentClusteredGraph.
  189. *
  190. * @return none
  191. *
  192. * @throw LayoutException
  193. */
  194. void addEdgesToNewGraph(SubGraph & gCurrentClusteredGraph, SubGraph & gNewGraph,
  195. std::vector<GraphPreProcessor::VertexOrderType> & oEdgesToRemove,
  196. std::vector<GridLayouter::edgeType> & oEdgesToAdd,
  197. std::vector<GraphPreProcessor::VertexOrderType> & oInnerEdgesToRemove,
  198. QMap <int, VertexIterator> & originalVertexForNewVertex);
  199. /**
  200. This method reads clustered CurrentClusteredGraph and its corresponding non-clustered NewGraph
  201. and transfers the layout of NewGraph to CurrentClusteredGraph. It puts the clusters at locations of
  202. theis corresponding vertices in NewGraph so that the layout is maintained.
  203. * @brief copyBackCoordinatesProcess
  204. * copies the layout of NewGraph to CurrentClusteredGraph.
  205. *
  206. * @param gCurrentNonClusteredGraph
  207. * input graph from which the vertices are to be added to NewGraph.
  208. *
  209. * @param gNewGraph
  210. * graph to which the vertices are to be added.
  211. *
  212. * @param gRootClusteredGraph
  213. * root graph of the CurrentClusteredGraph.
  214. *
  215. * @param isCluster
  216. * map from vertex of NewGraph to a flag that specifies whether that vertex corresponds to
  217. * a vertex or a cluster in CurrentClusteredGraph.
  218. *
  219. * @param originalVertexForNewVertex
  220. * map from vertex of NewGraph to its corresponding vertex in CurrentClusteredGraph.
  221. *
  222. * @param childrenList
  223. * map from vertex of NewGraph to its corresponding cluster in CurrentClusteredGraph.
  224. *
  225. * @return none
  226. *
  227. * @throw LayoutException
  228. */
  229. void copyBackCoordinates(SubGraph &gCurrentClusteredGraph, SubGraph &gNewGraph,
  230. SubGraph &gRootClusteredGraph,
  231. QMap<int, bool> &isCluster,
  232. QMap<int, VertexIterator> &originalVertexForNewVertex,
  233. QMap<int, ChildrenIterator> &childrenList);
  234. };
  235. #endif // GRIDLAYOUTER_H