SpaceUtilizer.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. #ifndef SPACEUTILIZER_H
  2. #define SPACEUTILIZER_H
  3. #include <GraphLayoutLibrary_global.h>
  4. #include <Common/BoostGraphWrapper.h>
  5. #include <boost/geometry.hpp>
  6. #include <boost/geometry/geometries/linestring.hpp>
  7. #include <boost/geometry/geometries/point_xy.hpp>
  8. #include <qmath.h>
  9. #include <CircularLayout/CircleLayouter.h>
  10. #include <Common/ConstantType.h>
  11. // Constant to define the negative factor
  12. #define NEGATIVE_FACTOR -1;
  13. #define PI_VALUE_DEGREE 180.0
  14. #define TWO_PI_VALUE_DEGREE 360.0
  15. #define PGL_MAP_VERTEX_TOPOLOGICAL_ORDER(mapVertexTopologicalOrder,graph) \
  16. property_map<SubGraph , std::size_t VertexProperties::*>::type \
  17. mapVertexTopologicalOrder(get(&VertexProperties::iTopologicalOrder , graph));
  18. /**
  19. * A structure to store the properties of the Circle; used in circular layout.
  20. */
  21. typedef struct CircleProperty
  22. {
  23. int iCenterCoordX; /*!< x coordinate of the center */
  24. int iCenterCoordY; /*!< y coordinate of the center */
  25. double dRadius; /*!< Radius */
  26. }CircleProperty;
  27. /**
  28. * @brief The SpaceUtilizer class
  29. *
  30. * The class provides set of functionalities around circular layout of a graph.
  31. */
  32. class GRAPHLAYOUTLIBRARYSHARED_EXPORT SpaceUtilizer
  33. {
  34. private:
  35. /**
  36. * Refers to an empty object of BoostGraphWrapper
  37. */
  38. BoostGraphWrapper m_boostGraphWrapper;
  39. /**
  40. * Stores the properties of the outermost circle
  41. */
  42. CircleProperty m_structMainCircleProperty;
  43. /**
  44. * Iterator for child items of the subgraph.
  45. */
  46. ChildrenIterator m_ItrSubgraph;
  47. /**
  48. * Iterator for child items of the subgraph. This iterator initially points to the end.
  49. */
  50. ChildrenIterator m_ItrSubgraphEnd;
  51. typedef QMap<VertexDescriptor, SubGraph *> mapDummyVertexToSubgraph;
  52. /**
  53. * Map of vertext descriptor and its associated subgraph for all dummy vertices added to the graph.
  54. */
  55. mapDummyVertexToSubgraph m_mapDummyVertexToSubgraph;
  56. public:
  57. /** @name Creators
  58. * The methods under this section are responsible for constructing or
  59. * destructing an instance of type SpaceUtilizer.
  60. */
  61. //@{
  62. /**
  63. constructs the object of type SpaceUtilizer.
  64. */
  65. SpaceUtilizer();
  66. //@}
  67. /** @name Queries
  68. * The methods under this section are responsible for accessing
  69. * an instance of type SpaceUtilizer.
  70. */
  71. //@{
  72. /**
  73. This function provides data required for calculating intersection of circles .
  74. @pre
  75. -# gSubgraph != NULL
  76. @param gSubgraph
  77. referece to graph
  78. @param vectIntersetionPoints
  79. out parameter containing the list of intersection points
  80. @return none
  81. @throw none
  82. */
  83. void getCircleIntersection(SubGraph& gSubgraph, vector<int>& vectIntersetionPoints);
  84. /**
  85. This function calculates intersection coordinates of circles.
  86. @pre
  87. -# structSubCircleProperty != NULL
  88. @param structSubCircleProperty
  89. object of structure containing circle properties
  90. @param vectIntersetionPoints
  91. reference to list of integer values
  92. @return none
  93. @throw none
  94. */
  95. void getCircleIntersectionCoordinates(CircleProperty structSubCircleProperty, vector<int>& vectIntersetionPoints);
  96. /**
  97. This function calculates angle of intersection point of circles using x coordinate value.
  98. @pre
  99. -# gSubgraph != NULL
  100. @param iCoordX
  101. x coordinate integer value
  102. @param iCoordY
  103. y coordinate integer value
  104. @param gSubgraph
  105. reference to graph
  106. @return angle value in degrees
  107. @throw none
  108. */
  109. double getIntersectionPointAngle(int iCoordX,int iCoordY, SubGraph& gSubgraph);
  110. /**
  111. This function provides the min and max vertices for next level subgraphs in the graph.
  112. @pre
  113. -# gGraph != NULL
  114. @param gGraph
  115. referece to graph
  116. @param vectMinMaxVertices
  117. reference to list of vertex descriptors
  118. @return none
  119. @throw none
  120. */
  121. void getSubgraphMinMaxVertices(SubGraph& gGraph, vector<VertexDescriptor>& vectMinMaxVertices);
  122. /**
  123. This fuction provides the min ans max vertices order for next level subgraphs in the graph.
  124. @param gGraph
  125. reference to graph
  126. @param vectMinMaxVerticesOrder
  127. out parameter containing the indices of the minimum order vertex and maximum order vertex.
  128. @return none
  129. @throw none
  130. */
  131. void getSubgraphMinMaxVerticesOrder(SubGraph& gGraph, vector<int>& vectMinMaxVerticesOrder);
  132. /**
  133. This function provides the min and max vertices for next level subgraphs in the graph.
  134. @pre
  135. -# gGraph != NULL
  136. @param gGraph
  137. referece to graph
  138. @param iMinOrder
  139. index of vertex with minimum order
  140. @param iMaxOrder
  141. index of vertex with maximum order
  142. @param mapMinMaxOrderVertex
  143. reference to list of vertex descriptors occurring between minimum and maximum order vertices.
  144. @return none
  145. @throw none
  146. */
  147. void claculateVerticesBetweenMinMax(SubGraph& gGraph,size_t iMinOrder, size_t iMaxOrder, MapOrderVertex& mapMinMaxOrderVertex);
  148. /**
  149. Returns map of vertices ordered by their 'topological order' property value.
  150. @pre
  151. -# gGraph != NULL
  152. @param gGraph
  153. referece to graph
  154. @return MapOrderVertex
  155. @throw none
  156. */
  157. template <typename MapVertexOrder>
  158. MapOrderVertex getMapTopologicalOrderedVertex(SubGraph& gSubgraph,MapVertexOrder& mapVertexOrder)
  159. {
  160. MapOrderVertex mapOrderVertex;
  161. BGL_FORALL_VERTICES(vVertex, gSubgraph , SubGraph)
  162. {
  163. std::size_t iTopologicalOrder;
  164. iTopologicalOrder = gSubgraph[vVertex].iTopologicalOrder;
  165. //cout<<"Topological Order---------: "<<iTopologicalOrder <<" - "<<vVertex<<endl;
  166. //add elements (order,vertex)
  167. mapOrderVertex.insert(iTopologicalOrder , vVertex);
  168. }
  169. return mapOrderVertex;
  170. }
  171. /**
  172. This function prepares list of own vertices of the graph
  173. @pre
  174. -# gSubgraph != NULL
  175. @param gSubgraph
  176. reference to graph
  177. @return none
  178. @throw none
  179. */
  180. void prepareGraphOwnVertexList(SubGraph& gSubgraph,QMap<size_t,VertexDescriptor>& mapOwnVerticesOrderToVertex);
  181. /**
  182. This function returns the number of vertices associated with the provided dummy node.
  183. @pre
  184. -# vDummyVertex should be dummy node
  185. @param vDummyVertex
  186. reference to dummy vertex
  187. @return count of vertices
  188. @throw none
  189. */
  190. int getVertexCountForDummyNode(VertexDescriptor& vDummyVertex);
  191. /**
  192. This function calculates the median ordered vertex order considering whlole graph.
  193. @pre
  194. -# gSubgraph != NULL
  195. @param gSubgraph
  196. reference to graph
  197. @return median order of vertex.
  198. @throw none
  199. */
  200. int calculateMedianOfSubgraph(SubGraph& gSubgraph);
  201. //@}
  202. /** @name Modifiers
  203. * The methods under this section are responsible for modifying
  204. * an instance of SpaceUtilizer.
  205. */
  206. //@{
  207. /**
  208. This function processes the grapth and tries to make it compact to make it utilize the space maximully.
  209. @pre
  210. -# gGraph != NULL
  211. @param gGraph
  212. referece to graph
  213. @return none
  214. @throw none
  215. */
  216. void processSpaceUtilizer(SubGraph& gGraph);
  217. /**
  218. This function adds dummy vertices into parent graph and creates entry into
  219. child subgraph as dummy vertex for that child subgraph
  220. prepares map of vertex to child subgraph.
  221. @pre
  222. -# gSubgraph != NULL
  223. @param gSubgraph
  224. reference to graph
  225. @param vVertex
  226. VertexDescriptor of the dummy vertex to be added to gSubgraph.
  227. @return none
  228. @throw none
  229. */
  230. void addSubgraphDummyVerticesAndMap(SubGraph& gSubgraph, VertexDescriptor vVertex);
  231. /**
  232. This function processes graph for second pass of circular layout.
  233. @pre
  234. -# gSubgraph != NULL
  235. @param gSubgraph
  236. reference to graph
  237. @return none
  238. @throw none
  239. */
  240. /**
  241. * @brief processSecondPassCircularLayout
  242. * This function processes graph for second pass of circular layout.
  243. * @pre
  244. -# gSubgraph != NULL
  245. * @param gSubgraph
  246. * reference to graph
  247. * @param iCenterCoordX
  248. * X coordinate of the center point
  249. * @param iCenterCoordY
  250. * Y coordinate of the center point
  251. */
  252. void processSecondPassCircularLayout(SubGraph& gSubgraph, int iCenterCoordX, int iCenterCoordY);
  253. //@}
  254. };
  255. #endif // SPACEUTILIZER_H