SpaceUtilizer.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. #include "SpaceUtilizer.h"
  2. SpaceUtilizer::SpaceUtilizer()
  3. {
  4. }
  5. void SpaceUtilizer::getCircleIntersection(SubGraph &gSubgraph, vector<int>& vectIntersetionPoints)
  6. {
  7. // XXX seems obselete
  8. // LAYOUT_ASSERT(&gSubgraph != NULL,LayoutException(__FUNCTION__
  9. // , LayoutExceptionEnum::REQUIRED_PARAMETER_NOT_SET
  10. // , "gSubgraph"
  11. // , ""));
  12. // Get Main graph circle's radius and center coordinates
  13. m_structMainCircleProperty.iCenterCoordX = m_boostGraphWrapper.getGraphCenterCoordX(gSubgraph);
  14. m_structMainCircleProperty.iCenterCoordY = m_boostGraphWrapper.getGraphCenterCoordY(gSubgraph);
  15. m_structMainCircleProperty.dRadius = m_boostGraphWrapper.getGraphRadius(gSubgraph);
  16. // Get subgraph circle's radius and center coordinates
  17. for(boost::tie(m_ItrSubgraph, m_ItrSubgraphEnd) = gSubgraph.children();
  18. m_ItrSubgraph != m_ItrSubgraphEnd;
  19. m_ItrSubgraph++)
  20. {
  21. CircleProperty structSubCircleProperty;
  22. structSubCircleProperty.iCenterCoordX = m_boostGraphWrapper.getGraphCenterCoordX(*m_ItrSubgraph);
  23. structSubCircleProperty.iCenterCoordY = m_boostGraphWrapper.getGraphCenterCoordY(*m_ItrSubgraph);
  24. structSubCircleProperty.dRadius = m_boostGraphWrapper.getGraphRadius(*m_ItrSubgraph);
  25. // Function call for getting the intersecting coodinates of main and sub graph circles
  26. getCircleIntersectionCoordinates(structSubCircleProperty, vectIntersetionPoints);
  27. }
  28. }
  29. void SpaceUtilizer::getCircleIntersectionCoordinates(CircleProperty structSubCircleProperty, vector<int>& vectIntersetionPoints)
  30. {
  31. // XXX seems obselete
  32. // LAYOUT_ASSERT(structSubCircleProperty.dRadius > 0,LayoutException(__FUNCTION__
  33. // , LayoutExceptionEnum::REQUIRED_PARAMETER_NOT_SET
  34. // , "dRadius"
  35. // , "in getting CircleIntersectionCoordinates"));
  36. // Main Circle Properties
  37. int iMainCircleCenterCoordX = m_structMainCircleProperty.iCenterCoordX;
  38. int iMainCircleCenterCoordY = m_structMainCircleProperty.iCenterCoordY;
  39. double dMainCircleRadius = m_structMainCircleProperty.dRadius;
  40. std::cout<<"Main Circle : "<<iMainCircleCenterCoordX<<" "<<iMainCircleCenterCoordY<<" "<<dMainCircleRadius<<std::endl;
  41. // Sub Circle Properties
  42. int iSubCircleCenetrCoordX = structSubCircleProperty.iCenterCoordX;
  43. int iSubCircleCenetrCoordY = structSubCircleProperty.iCenterCoordY;
  44. double dSubCircleRadius = structSubCircleProperty.dRadius;
  45. // Calculate distance between the centers of two circles
  46. boost::geometry::model::d2::point_xy<int> MainCircleCenter(iMainCircleCenterCoordX, iMainCircleCenterCoordY);
  47. boost::geometry::model::d2::point_xy<int> SubCircleCenter(iSubCircleCenetrCoordX, iSubCircleCenetrCoordY);
  48. double dCircleCenterDistance = boost::geometry::distance(MainCircleCenter, SubCircleCenter);
  49. double dTotalDistance = dMainCircleRadius + dSubCircleRadius;
  50. double dRadiusDifference = dMainCircleRadius - dSubCircleRadius;
  51. if(dRadiusDifference < 0)
  52. {
  53. dRadiusDifference = dRadiusDifference * NEGATIVE_FACTOR;
  54. }
  55. // No Solution
  56. if(dCircleCenterDistance > dTotalDistance)
  57. {
  58. std::cout<<"No solution : Distance between centers is greater than total distance"<<std::endl;
  59. }
  60. else if(dCircleCenterDistance < dRadiusDifference)
  61. {
  62. std::cout<<"Circles are contained within each other"<<std::endl;
  63. }
  64. else if(dCircleCenterDistance == 0 && dMainCircleRadius == dSubCircleRadius)
  65. {
  66. std::cout<<"Circles are same"<<std::endl;
  67. }
  68. else
  69. {
  70. // Calculate distance between one circle's center and line joining the intersection points
  71. double dFirstSegment = ( ((dMainCircleRadius * dMainCircleRadius) - (dSubCircleRadius * dSubCircleRadius))
  72. + (dCircleCenterDistance * dCircleCenterDistance) ) / (2 * dCircleCenterDistance);
  73. // Calculate distance between point of intersection and line joining two centers of circle
  74. double dSecondSegment = ( (dMainCircleRadius * dMainCircleRadius) - (dFirstSegment * dFirstSegment));
  75. dSecondSegment = sqrt(dSecondSegment);
  76. // Calculate point coordinates, where the line through the circle intersection points crosses the line between the circle centers.
  77. double dCrossPointX = (iMainCircleCenterCoordX +
  78. ( (dFirstSegment / dCircleCenterDistance) * (iSubCircleCenetrCoordX - iMainCircleCenterCoordX)));
  79. double dCrossPointY = (iMainCircleCenterCoordY +
  80. ( (dFirstSegment / dCircleCenterDistance) * (iSubCircleCenetrCoordY - iMainCircleCenterCoordY)));
  81. // Calculate the points of intersection of circles
  82. int iFirstPointX = (int)(dCrossPointX +
  83. ((dSecondSegment / dCircleCenterDistance) * (iSubCircleCenetrCoordY - iMainCircleCenterCoordY)));
  84. int iFirstPointY = (int)(dCrossPointY -
  85. ((dSecondSegment / dCircleCenterDistance) * (iSubCircleCenetrCoordX - iMainCircleCenterCoordX)));
  86. int iSecondPointX = (int)(dCrossPointX -
  87. ((dSecondSegment / dCircleCenterDistance) * (iSubCircleCenetrCoordY - iMainCircleCenterCoordY)));;
  88. int iSecondPointY = (int)(dCrossPointY +
  89. ((dSecondSegment / dCircleCenterDistance) * (iSubCircleCenetrCoordX - iMainCircleCenterCoordX)));;
  90. std::cout<<"Intersection Points"<<iFirstPointX<<" "<<iFirstPointY<<" "<<iSecondPointX<<" "<<iSecondPointY<<std::endl;
  91. vectIntersetionPoints.push_back(iFirstPointX);
  92. vectIntersetionPoints.push_back(iFirstPointY);
  93. vectIntersetionPoints.push_back(iSecondPointX);
  94. vectIntersetionPoints.push_back(iSecondPointY);
  95. }
  96. }
  97. double SpaceUtilizer::getIntersectionPointAngle(int iCoordX, int iCoordY, SubGraph &gSubgraph)
  98. {
  99. /**
  100. This function calculates the angle on the circumference of the circle.
  101. to calculate angle we require cos inverse functionality and os inverse has valid range
  102. of (0 to 180) degrees.
  103. Hence we use (360- angle) for angle values int range (180 to 360)
  104. */
  105. // XXX seems obselete
  106. // LAYOUT_ASSERT(&gSubgraph != NULL,LayoutException(__FUNCTION__
  107. // , LayoutExceptionEnum::REQUIRED_PARAMETER_NOT_SET
  108. // , "gSubgraph"
  109. // , ""));
  110. int iCenterCoordX = m_boostGraphWrapper.getGraphCenterCoordX(gSubgraph);
  111. double dRadius = m_boostGraphWrapper.getGraphRadius(gSubgraph);
  112. double dExpressionValue = ((iCoordX - iCenterCoordX) / dRadius);
  113. double dAngleDegrees;
  114. // Checking 3rd and 4th quadrant as cos inverse is valid range
  115. if((iCoordX <= 0 && iCoordY <= 0) || (iCoordX >= 0 && iCoordY <= 0))
  116. {
  117. dAngleDegrees = (qAcos(dExpressionValue)) * (PI_VALUE_DEGREE / PI);
  118. }
  119. // Checking 1st and second quadrant as cos inverse is invalid range
  120. else
  121. {
  122. dAngleDegrees = TWO_PI_VALUE_DEGREE - ((qAcos(dExpressionValue)) * (PI_VALUE_DEGREE / PI));
  123. }
  124. return dAngleDegrees;
  125. }
  126. void SpaceUtilizer::getSubgraphMinMaxVertices(SubGraph &gGraph, vector<VertexDescriptor> &vectMinMaxVertices)
  127. {
  128. // XXX obselete LAYOUT_ASSERT(&gGraph != NULL,LayoutException(__FUNCTION__
  129. // , LayoutExceptionEnum::REQUIRED_PARAMETER_NOT_SET
  130. // , "gGraph"
  131. // , ""));
  132. VertexDescriptor vMinVertex;
  133. VertexDescriptor vMaxVertex;
  134. for(boost::tie(m_ItrSubgraph, m_ItrSubgraphEnd) = gGraph.children();
  135. m_ItrSubgraph != m_ItrSubgraphEnd;
  136. m_ItrSubgraph++)
  137. {
  138. m_boostGraphWrapper.getMinMaxVertices(*m_ItrSubgraph, vMinVertex, vMaxVertex);
  139. //cout<<"Min - Max Vertices : "<<vMinVertex<<" "<<vMaxVertex<<endl;
  140. vectMinMaxVertices.push_back(vMinVertex);
  141. vectMinMaxVertices.push_back(vMaxVertex);
  142. }
  143. }
  144. void SpaceUtilizer::getSubgraphMinMaxVerticesOrder(SubGraph &gGraph, vector<int> &vectMinMaxVerticesOrder)
  145. {
  146. // XXX obselete LAYOUT_ASSERT(&gGraph != NULL,LayoutException(__FUNCTION__
  147. // , LayoutExceptionEnum::REQUIRED_PARAMETER_NOT_SET
  148. // , "gGraph"
  149. // , ""));
  150. int iMinOrder;
  151. int iMaxOrder;
  152. for(boost::tie(m_ItrSubgraph, m_ItrSubgraphEnd) = gGraph.children();
  153. m_ItrSubgraph != m_ItrSubgraphEnd;
  154. m_ItrSubgraph++)
  155. {
  156. m_boostGraphWrapper.getMinMaxVertexOrder(*m_ItrSubgraph, iMinOrder, iMaxOrder);
  157. vectMinMaxVerticesOrder.push_back(iMinOrder);
  158. vectMinMaxVerticesOrder.push_back(iMaxOrder);
  159. }
  160. }
  161. void SpaceUtilizer::claculateVerticesBetweenMinMax(SubGraph &gGraph, size_t iMinOrder, size_t iMaxOrder, MapOrderVertex& mapMinMaxOrderVertex )
  162. {
  163. // XXX obselete LAYOUT_ASSERT(&gGraph != NULL,LayoutException(__FUNCTION__
  164. // , LayoutExceptionEnum::REQUIRED_PARAMETER_NOT_SET
  165. // , "gGraph"
  166. // , ""));
  167. // Get start of vertex list Order
  168. std::size_t iStartVertexOrder = iMinOrder + 1;
  169. // Get Last of vertex list Order
  170. std::size_t iLastVertexOrder = iMaxOrder - 1;
  171. // Prepare list of vertices order
  172. PGL_MAP_VERTEX_ORDER(mapVertexOrder,gGraph);
  173. MapOrderVertex mapOrderVertex;
  174. mapOrderVertex = m_boostGraphWrapper.getMapOrderedVertices(gGraph, mapVertexOrder);
  175. cout << "Vertices order between min and max : " << endl;
  176. IteratorMapOrderVertex mapIter(mapOrderVertex);
  177. while(mapIter.hasNext())
  178. {
  179. mapIter.next();
  180. std::size_t key = mapIter.key();
  181. VertexDescriptor vVertex = mapOrderVertex[key];
  182. if(iStartVertexOrder < iLastVertexOrder)
  183. {
  184. if((key >= iStartVertexOrder) && (key <= iLastVertexOrder))
  185. {
  186. bool bIsExpandable = m_boostGraphWrapper.getVertexExpandable(vVertex,gGraph);
  187. if(bIsExpandable == true)
  188. {
  189. // Do not push vertices in the map
  190. }
  191. else
  192. {
  193. mapMinMaxOrderVertex.insert(key,vVertex);
  194. }
  195. }
  196. }
  197. else
  198. {
  199. if((key > iMinOrder) && (key < iMaxOrder))
  200. {
  201. if(vVertex == gGraph.global_to_local(vVertex))
  202. {
  203. //cout<<"Own Vertices"<<endl;
  204. bool bIsExpandable = m_boostGraphWrapper.getVertexExpandable(vVertex,gGraph);
  205. if(bIsExpandable == true)
  206. {
  207. // Do not push vertices in the map
  208. }
  209. else
  210. {
  211. mapMinMaxOrderVertex.insert(key,vVertex);
  212. }
  213. }
  214. }
  215. }
  216. }
  217. }
  218. void SpaceUtilizer::processSpaceUtilizer(SubGraph &gGraph)
  219. {
  220. // XXX obselete LAYOUT_ASSERT(&gGraph != NULL,LayoutException(__FUNCTION__
  221. // , LayoutExceptionEnum::REQUIRED_PARAMETER_NOT_SET
  222. // , "gGraph"
  223. // , ""));
  224. // Get Min - Max Vertices Order.
  225. vector<int> vecMinMaxVerticesOrder;
  226. getSubgraphMinMaxVerticesOrder(gGraph, vecMinMaxVerticesOrder);
  227. int iFirstItem = vecMinMaxVerticesOrder[0];
  228. vecMinMaxVerticesOrder.push_back(iFirstItem);
  229. // Process Min - Max for getting vertices list.
  230. vector<int>::iterator iterMinMaxList = vecMinMaxVerticesOrder.begin();
  231. iterMinMaxList++;
  232. int iFirstOrder;
  233. int iSecondOrder;
  234. // Get Intersecting coordinates of circles and calculate list of angle.
  235. vector<int> vecIntersectionPoints;
  236. getCircleIntersection(gGraph,vecIntersectionPoints);
  237. // prepare list of intersecting angles of all clusters present at first level in the subgraph
  238. vector<double> vecIntersectingAngles;
  239. for(vector<int>::iterator iterPoints = vecIntersectionPoints.begin();
  240. iterPoints != vecIntersectionPoints.end();
  241. iterPoints++)
  242. {
  243. int iCoordX = *iterPoints;
  244. iterPoints++;
  245. int iCoordY = *iterPoints;
  246. double dAngle = getIntersectionPointAngle(iCoordX, iCoordY, gGraph);
  247. vecIntersectingAngles.push_back(dAngle);
  248. }
  249. double dFistAngle = vecIntersectingAngles[0];
  250. vecIntersectingAngles.push_back(dFistAngle);
  251. vector<double>::iterator iterIntersectingAngles = vecIntersectingAngles.begin();
  252. iterIntersectingAngles++;
  253. double dStartAngle = 0.0;
  254. double dEndAngle = 0.0;
  255. while((iterMinMaxList != vecMinMaxVerticesOrder.end()) && (iterIntersectingAngles != vecIntersectingAngles.end()))
  256. {
  257. iFirstOrder = *iterMinMaxList;
  258. iterMinMaxList++;
  259. iSecondOrder = *iterMinMaxList;
  260. // Get Vertex List between Max - Min vertices.
  261. MapOrderVertex mapVerticesOrderList;
  262. claculateVerticesBetweenMinMax(gGraph, iFirstOrder, iSecondOrder,mapVerticesOrderList);
  263. dStartAngle = *iterIntersectingAngles;
  264. iterIntersectingAngles++;
  265. dEndAngle = *iterIntersectingAngles;
  266. // Get Radius for the subgraph.
  267. double dRadius = m_boostGraphWrapper.getGraphRadius(gGraph);
  268. // Apply arc layout to vertices between Max - Min of subgraphs.
  269. CircleLayouter circleLayouter;
  270. double dDirectionAngle = dStartAngle;
  271. dStartAngle = dEndAngle;
  272. dEndAngle = dDirectionAngle;
  273. circleLayouter.applyArcLayout(gGraph, dStartAngle, dEndAngle, get(vertex_position, gGraph), dRadius, mapVerticesOrderList);
  274. // Set the arc laid out point coordinates in the vertices
  275. IteratorMapOrderVertex mapIter(mapVerticesOrderList);
  276. while(mapIter.hasNext())
  277. {
  278. mapIter.next();
  279. std::size_t key = mapIter.key();
  280. VertexDescriptor vVertex = mapVerticesOrderList[key];
  281. int iVertexX = (int)get(vertex_position, gGraph)[vVertex][0];
  282. int iVertexY = (int)get(vertex_position, gGraph)[vVertex][1];
  283. int iCenterX = m_boostGraphWrapper.getGraphCenterCoordX(gGraph);
  284. int iCenterY = m_boostGraphWrapper.getGraphCenterCoordY(gGraph);
  285. iVertexX += iCenterX;
  286. iVertexY += iCenterY;
  287. QString sVertexId = m_boostGraphWrapper.getVertexId(vVertex, gGraph);
  288. //cout<<"Arc Laid out Coordinates : "<<endl;
  289. std::cout<<sVertexId.toStdString()<<" : "<<vVertex<<" : "<<iVertexX;
  290. std::cout<<iVertexY<<std::endl;
  291. m_boostGraphWrapper.setVertexCenterCoordX(vVertex, gGraph, iVertexX);
  292. m_boostGraphWrapper.setVertexCenterCoordY(vVertex, gGraph, iVertexY);
  293. }
  294. iterMinMaxList++;
  295. iterIntersectingAngles++;
  296. }
  297. }
  298. void SpaceUtilizer::prepareGraphOwnVertexList(SubGraph &gSubgraph,
  299. QMap<size_t,
  300. VertexDescriptor>& mapOwnVerticesOrderToVertex)
  301. {
  302. // XXX obselete LAYOUT_ASSERT(&gSubgraph != NULL,
  303. // LayoutMemoryException(__FUNCTION__,LayoutExceptionEnum::NULL_POINTER_EXCEPTION,GRAPH));
  304. IteratorQVectorUInt iterOwnVertex , iterOwnVertexEnd;
  305. try{
  306. for(boost::tie(iterOwnVertex , iterOwnVertexEnd) = m_boostGraphWrapper.ownVerticesIter(gSubgraph);
  307. iterOwnVertex != iterOwnVertexEnd;
  308. iterOwnVertex++)
  309. {
  310. VertexDescriptor vCurrentVertex = *iterOwnVertex;
  311. LayoutEnum::NodeType nodeType = m_boostGraphWrapper.getVertexType(vCurrentVertex,gSubgraph);
  312. if(nodeType == LayoutEnum::DummyNode)
  313. {
  314. VertexDescriptor vVertex = gSubgraph.local_to_global(vCurrentVertex);
  315. SubGraph& gDummyGraph = (*(m_mapDummyVertexToSubgraph.value(vVertex)));
  316. int iOrder;
  317. try
  318. {
  319. iOrder = calculateMedianOfSubgraph(gDummyGraph);
  320. }
  321. catch(LayoutMemoryException& eException)
  322. {
  323. qDebug()<<"Memory Exception: in Calculate median of subgraph";
  324. iOrder = m_boostGraphWrapper.getVertexOrder(vVertex,gSubgraph);
  325. }
  326. catch(boost::exception& eException)
  327. {
  328. qDebug()<<"Boost Exception: in Calculate median of subgraph";
  329. iOrder = m_boostGraphWrapper.getVertexOrder(vVertex,gSubgraph);
  330. }
  331. catch(...)
  332. {
  333. qDebug()<<"Boost Exception: in Calculate median of subgraph";
  334. iOrder = m_boostGraphWrapper.getVertexOrder(vVertex,gSubgraph);
  335. }
  336. mapOwnVerticesOrderToVertex.insert(iOrder,vCurrentVertex);
  337. }
  338. else
  339. {
  340. int iOrder = m_boostGraphWrapper.getVertexOrder(vCurrentVertex, gSubgraph);
  341. // //cout<<"Own Vertex List : "<<vCurrentVertex<<endl;
  342. mapOwnVerticesOrderToVertex.insert(iOrder,vCurrentVertex);
  343. }
  344. }
  345. }
  346. catch(boost::exception& eBoostException)
  347. {
  348. throw *boost::get_error_info<errmsg_info>(eBoostException);
  349. }
  350. catch(...)
  351. {}
  352. }
  353. void SpaceUtilizer::addSubgraphDummyVerticesAndMap(SubGraph &gSubgraph, VertexDescriptor vVertex)
  354. {
  355. // XXX vVertex is not used
  356. Q_UNUSED(vVertex);
  357. // XXX obselete Q_ASSERT_X(&gSubgraph != NULL,
  358. // "process Dummy Vertex",
  359. // "Trying to process dummy vertex without passing a graph to method");
  360. // XXX obselete LAYOUT_ASSERT(&gSubgraph != NULL,
  361. // LayoutMemoryException(__FUNCTION__, LayoutExceptionEnum::NULL_POINTER_EXCEPTION,GRAPH));
  362. try{
  363. ChildrenIterator itrSubgraph, itrSubgraphEnd;
  364. for(boost::tie(itrSubgraph, itrSubgraphEnd) = gSubgraph.children();
  365. itrSubgraph != itrSubgraphEnd;
  366. itrSubgraph++)
  367. {
  368. // add dummy vertex for child subgraph in the parent subgraph
  369. VertexDescriptor vVertex = m_boostGraphWrapper.addDummyVertexForChildGraph(gSubgraph, *itrSubgraph);
  370. // add properties of subgraph to its dummy node
  371. // get properties from the subgraph which is a child subgraph
  372. int iDummyVertexCenterX = m_boostGraphWrapper.getGraphCenterCoordX(*itrSubgraph);
  373. int iDummyVertexCenterY = m_boostGraphWrapper.getGraphCenterCoordY(*itrSubgraph);
  374. int iDummyVertexLeftX = m_boostGraphWrapper.getGraphLeftTopCoordX(*itrSubgraph);
  375. int iDummyVertexTopY = m_boostGraphWrapper.getGraphLeftTopCoordY(*itrSubgraph);
  376. int iDummyVertexHeight = m_boostGraphWrapper.getGraphHeight(*itrSubgraph);
  377. int iDummyVertexWidth = m_boostGraphWrapper.getGraphWidth(*itrSubgraph);
  378. //set properties of subgraph into its dummy vertex of parent graph
  379. m_boostGraphWrapper.setVertexCenterCoordX(vVertex, gSubgraph, iDummyVertexCenterX);
  380. m_boostGraphWrapper.setVertexCenterCoordY(vVertex, gSubgraph, iDummyVertexCenterY);
  381. m_boostGraphWrapper.setVertexLeftCoordX(vVertex, gSubgraph, iDummyVertexLeftX);
  382. m_boostGraphWrapper.setVertexLeftCoordY(vVertex, gSubgraph,iDummyVertexTopY);
  383. m_boostGraphWrapper.setVertexHeight(vVertex, gSubgraph, iDummyVertexHeight);
  384. m_boostGraphWrapper.setVertexWidth(vVertex, gSubgraph, iDummyVertexWidth);
  385. // add global vertex to the map
  386. VertexDescriptor vGlobalVertex = gSubgraph.local_to_global(vVertex);
  387. m_mapDummyVertexToSubgraph.insert(vGlobalVertex, &(*itrSubgraph));
  388. int iVertexSubgraphCount = num_vertices(*itrSubgraph);
  389. gSubgraph.root()[vGlobalVertex].iVertexCount = iVertexSubgraphCount;
  390. addSubgraphDummyVerticesAndMap(*itrSubgraph, vVertex);
  391. }
  392. }
  393. catch(boost::exception& eBoostException)
  394. {
  395. throw *boost::get_error_info<errmsg_info>(eBoostException);
  396. }
  397. }
  398. int SpaceUtilizer::getVertexCountForDummyNode(VertexDescriptor &vDummyVertex)
  399. {
  400. SubGraph& gSubgraph = (*m_mapDummyVertexToSubgraph.value(vDummyVertex));
  401. int iNumVertices = num_vertices(gSubgraph);
  402. return iNumVertices;
  403. }
  404. int SpaceUtilizer::calculateMedianOfSubgraph(SubGraph &gSubgraph)
  405. {
  406. // XXX obselete LAYOUT_ASSERT(&gSubgraph != NULL,
  407. // LayoutMemoryException(__FUNCTION__,
  408. // LayoutExceptionEnum::NULL_POINTER_EXCEPTION,
  409. // GRAPH));
  410. int iVertexOrder;
  411. size_t iOrder;
  412. try
  413. {
  414. // create a vertex order map.
  415. PGL_MAP_VERTEX_ORDER(mapVertexOrder,gSubgraph);
  416. // get map of order to vertices of the graph
  417. MapOrderVertex mapOrderVertex;
  418. mapOrderVertex = m_boostGraphWrapper.getMapOrderedVertices(gSubgraph, mapVertexOrder);
  419. // count total number of elements in the order to vertex map
  420. int iTotalMapElements = mapOrderVertex.count();
  421. // get the middle element's order from the map.
  422. //
  423. int iMedianElementOffset;
  424. iMedianElementOffset = std::floor((double)(iTotalMapElements + 1) / 2);
  425. IteratorMapOrderVertex mapIterOrderVertex(mapOrderVertex);
  426. int iCount = 1;
  427. VertexDescriptor vVertex;
  428. while(mapIterOrderVertex.hasNext())
  429. {
  430. mapIterOrderVertex.next();
  431. if(iCount <= iMedianElementOffset)
  432. {
  433. iOrder = mapIterOrderVertex.key();
  434. vVertex = mapIterOrderVertex.value();
  435. iCount++;
  436. }
  437. }
  438. iVertexOrder= m_boostGraphWrapper.getVertexOrder(vVertex, gSubgraph);
  439. }catch(boost::exception& eBoostException)
  440. {
  441. throw *boost::get_error_info<errmsg_info>(eBoostException);
  442. }
  443. catch(...)
  444. {
  445. throw;
  446. }
  447. cout<<"Median Order : "<<iOrder<<" "<<iVertexOrder<<endl;
  448. return iVertexOrder;
  449. }
  450. void SpaceUtilizer::processSecondPassCircularLayout(SubGraph &gSubgraph, int iCenterCoordX, int iCenterCoordY)
  451. {
  452. // XXX obselete LAYOUT_ASSERT(&gSubgraph != NULL,
  453. // LayoutMemoryException(__FUNCTION__, LayoutExceptionEnum::NULL_POINTER_EXCEPTION, GRAPH));
  454. // get the list of own vertices of graph
  455. MapOrderVertex mapKeyToOwnVertices;
  456. // prepare own vertex list
  457. try
  458. {
  459. prepareGraphOwnVertexList(gSubgraph, mapKeyToOwnVertices);
  460. }
  461. catch(LayoutMemoryException& eException)
  462. {
  463. throw LayoutMemoryException(__FUNCTION__,
  464. LayoutExceptionEnum::NULL_POINTER_EXCEPTION,
  465. eException.getObjectName());
  466. }
  467. catch(...)
  468. {
  469. throw;
  470. }
  471. // Calculate radius for this graph
  472. double dRadius = m_boostGraphWrapper.getGraphRadius(gSubgraph);
  473. // call second pass circular and expand dummy vertices and apply circular to it
  474. CircleLayouter circleLayouter;
  475. try
  476. {
  477. circleLayouter.applyCircleGraphLayout(gSubgraph, (get(vertex_position,gSubgraph)), dRadius,
  478. iCenterCoordX, iCenterCoordY, mapKeyToOwnVertices);
  479. }
  480. catch(LayoutMemoryException& eException)
  481. {
  482. throw LayoutMemoryException(__FUNCTION__,
  483. LayoutExceptionEnum::NULL_POINTER_EXCEPTION,
  484. eException.getObjectName());
  485. }
  486. catch(LayoutException& eException)
  487. {
  488. if(eException.getExceptionSubType() == LayoutExceptionEnum::INVALID_PARAMETER)
  489. {
  490. throw LayoutException(__FUNCTION__,
  491. LayoutExceptionEnum::INVALID_PARAMETER,
  492. eException.getEntityValue(),
  493. eException.getEntityType());
  494. }
  495. else if(eException.getExceptionSubType() == LayoutExceptionEnum::EMPTY_CONTAINER)
  496. {
  497. throw LayoutException(__FUNCTION__,
  498. LayoutExceptionEnum::EMPTY_CONTAINER,
  499. eException.getEntityValue(),
  500. eException.getEntityType());
  501. }
  502. }
  503. catch(boost::exception& eBoostException)
  504. {
  505. throw *boost::get_error_info<errmsg_info>(eBoostException);
  506. }
  507. catch(...)
  508. {
  509. }
  510. //add nesting edges
  511. IteratorQVectorUInt iterOwnVertex ,iterOwnVertexEnd;
  512. for(boost::tie(iterOwnVertex , iterOwnVertexEnd) = m_boostGraphWrapper.ownVerticesIter(gSubgraph);
  513. iterOwnVertex != iterOwnVertexEnd;
  514. iterOwnVertex++)
  515. {
  516. VertexDescriptor vCurrentVertex = *iterOwnVertex;
  517. LayoutEnum::NodeType nodeType = m_boostGraphWrapper.getVertexType(vCurrentVertex,gSubgraph);
  518. if(nodeType == LayoutEnum::DummyNode)
  519. {
  520. VertexDescriptor vVertex;
  521. try
  522. {
  523. vVertex = gSubgraph.local_to_global(vCurrentVertex);
  524. }
  525. catch(boost::exception& eBoostException)
  526. {
  527. throw *boost::get_error_info<errmsg_info>(eBoostException);
  528. }
  529. try
  530. {
  531. SubGraph& gDummyGraph = (*(m_mapDummyVertexToSubgraph.value(vVertex)));
  532. // //cout<<"Dummy Graph In 2nd Pass"<<endl;
  533. // m_boostGraphWrapper.printGraph(gDummyGraph);
  534. // calculate the cenroid of this graph and calculate its ceneter
  535. int iCentroidX = m_boostGraphWrapper.getVertexCenterCoordX(vCurrentVertex, gDummyGraph.parent());
  536. int iCentroidY = m_boostGraphWrapper.getVertexCenterCoordY(vCurrentVertex, gDummyGraph.parent());
  537. int iDistanceX = m_boostGraphWrapper.getGraphDistanceBetweenCentoidAndCenterCoordX(gDummyGraph);
  538. int iDistanceY = m_boostGraphWrapper.getGraphDistanceBetweenCentoidAndCenterCoordY(gDummyGraph);
  539. int iCenterDummyGraphVertexX = iCentroidX - iDistanceX;
  540. int iCenterDummyGraphVertexY = iCentroidY - iDistanceY;
  541. //set center of graph
  542. m_boostGraphWrapper.setGraphCenterCoordX(iCenterDummyGraphVertexX,gDummyGraph);
  543. m_boostGraphWrapper.setGraphCenterCoordY(iCenterDummyGraphVertexY,gDummyGraph);
  544. // Recursive call to second circle layout pass upto deep level
  545. processSecondPassCircularLayout(gDummyGraph, iCenterDummyGraphVertexX, iCenterDummyGraphVertexY);
  546. }
  547. catch(LayoutMemoryException& eException)
  548. {
  549. throw LayoutMemoryException(__FUNCTION__, LayoutExceptionEnum::NULL_POINTER_EXCEPTION,eException.getObjectName());
  550. }
  551. catch(boost::exception& eBoostException)
  552. {
  553. throw *boost::get_error_info<errmsg_info>(eBoostException);
  554. }
  555. catch(...)
  556. {}
  557. }
  558. }
  559. }