CircleLayouter.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #include "CircleLayouter.h"
  2. CircleLayouter::CircleLayouter()
  3. {
  4. m_iDefaultHeight = 40;
  5. m_iDefaultWidth = 80;
  6. }
  7. double CircleLayouter::calculateAngleSpace(VertexDescriptor& vVertex, SubGraph &gSubgraph)
  8. {
  9. // XXX obselete LAYOUT_ASSERT(&gSubgraph != NULL, LayoutMemoryException(__FUNCTION__, LayoutExceptionEnum::NULL_POINTER_EXCEPTION, NULL_GRAPH_FOUND));
  10. double dAngleSpace = 0;
  11. double dCircumference;
  12. // calculate circumference in terms of diagonal of nodes
  13. try
  14. {
  15. dCircumference = calculateCircumference(gSubgraph);
  16. }
  17. catch(LayoutException& eException)
  18. {
  19. QString sGraphId = m_boostGraphWrapper.getGraphId(gSubgraph);
  20. qDebug()<<"Default : Circumference is calculated"<<sGraphId;
  21. int iTotalVertexCount = num_vertices(gSubgraph);
  22. // calculate the default height and default width
  23. double dDefaultDiagonalLengthSquare = (double)((m_iDefaultHeight * m_iDefaultHeight) +
  24. (m_iDefaultWidth * m_iDefaultWidth));
  25. double dDefaultDiagonalLength = (double)qSqrt(dDefaultDiagonalLengthSquare);
  26. dCircumference = (double)iTotalVertexCount * dDefaultDiagonalLength;
  27. }
  28. // XXX obselete
  29. // catch(LayoutMemoryException& eException)
  30. // {
  31. // throw LayoutMemoryException(__FUNCTION__,LayoutExceptionEnum::NULL_POINTER_EXCEPTION,eException.getObjectName());
  32. // }
  33. catch(boost::exception& eBoostException)
  34. {
  35. throw *boost::get_error_info<errmsg_info>(eBoostException);
  36. }
  37. // calculate the diagonal length of this node
  38. SizeManager sizeManager;
  39. double dNodeDiagonalLength;
  40. try
  41. {
  42. dNodeDiagonalLength = sizeManager.calculateDiagonalOfNode(vVertex, gSubgraph);
  43. }
  44. catch(boost::exception& )
  45. {
  46. QString sVertexId = m_boostGraphWrapper.getVertexId(vVertex, gSubgraph);
  47. qDebug()<<"Default diagonal length caluclated for vertex"<<sVertexId;
  48. double dDefaultDiagonalLengthSquare = (double)((m_iDefaultHeight * m_iDefaultHeight) +
  49. (m_iDefaultWidth * m_iDefaultWidth));
  50. dNodeDiagonalLength = (double)qSqrt(dDefaultDiagonalLengthSquare);
  51. }
  52. catch(...)
  53. {
  54. QString sVertexId = m_boostGraphWrapper.getVertexId(vVertex, gSubgraph);
  55. qDebug()<<"Default diagonal length caluclated for vertex"<<sVertexId;
  56. double dDefaultDiagonalLengthSquare = (double)((m_iDefaultHeight * m_iDefaultHeight) +
  57. (m_iDefaultWidth * m_iDefaultWidth));
  58. dNodeDiagonalLength = (double)qSqrt(dDefaultDiagonalLengthSquare);
  59. }
  60. /*
  61. * This is the factor which calculates the proportion of node length
  62. in terms of diagonal and total circumference calculated in terms
  63. of adding all nodes diagonal length.
  64. */
  65. double dNodeDiagonalWithRadiusShare = dNodeDiagonalLength; //+ (0.0009381 * RADIUS_SHARE);
  66. // int iTotalVertices = num_vertices(gSubgraph);
  67. // int iDummyVertices = gSubgraph.num_children();
  68. // int iVertexCount = iTotalVertices - iDummyVertices;
  69. double dCircumferenceWithShare = dCircumference; //+ (2 * (m_dPiValue) * RADIUS_SHARE);
  70. double dProportionFactor = dNodeDiagonalWithRadiusShare / dCircumferenceWithShare;
  71. // Calculate the angle space required for this node
  72. dAngleSpace = ((2 * (PI)) * dProportionFactor);
  73. return dAngleSpace;
  74. }
  75. double CircleLayouter::calculateCircumference(SubGraph &gSubgraph)
  76. {
  77. // XXX obselete LAYOUT_ASSERT(&gSubgraph != NULL, LayoutMemoryException(__FUNCTION__, LayoutExceptionEnum::NULL_POINTER_EXCEPTION, NULL_GRAPH_FOUND));
  78. int iCircumference = 0;
  79. int iNumVertices = num_vertices(gSubgraph);
  80. if(iNumVertices != 0)
  81. {
  82. SizeManager sizeManager;
  83. BGL_FORALL_VERTICES(vVertex, gSubgraph, SubGraph)
  84. {
  85. LayoutEnum::NodeType nodeType = m_boostGraphWrapper.getVertexType(vVertex,gSubgraph);
  86. if(LayoutEnum::isValidCircularVertexType(nodeType) == true)
  87. {
  88. // check whether the node is valid node within available types
  89. if(nodeType == LayoutEnum::DummyNode)
  90. {
  91. // Skip Dummy Nodes
  92. continue;
  93. }
  94. double iNodeDiagonalLength;
  95. try
  96. {
  97. iNodeDiagonalLength = sizeManager.calculateDiagonalOfNode(vVertex, gSubgraph);
  98. ////cout<<"Diagonal of Node : "<<vVertex<<" "<<iNodeDiagonalLength<<endl;
  99. iCircumference += iNodeDiagonalLength;
  100. }
  101. catch(LayoutMemoryException& eException)
  102. {
  103. throw LayoutMemoryException(__FUNCTION__,
  104. LayoutExceptionEnum::NULL_POINTER_EXCEPTION,
  105. eException.getObjectName());
  106. }
  107. catch(boost::exception& eBoostException)
  108. {
  109. throw *boost::get_error_info<errmsg_info>(eBoostException);
  110. }
  111. }
  112. else
  113. {
  114. //cout<<"Invalid Node Type for Circular Layout"<<endl;
  115. throw LayoutException(__FUNCTION__, LayoutExceptionEnum::INVALID_PARAMETER, INVALID_NODE_TYPE);
  116. }
  117. }
  118. }
  119. else
  120. {
  121. int iHeight = m_boostGraphWrapper.getGraphHeight(gSubgraph);
  122. int iWidth = m_boostGraphWrapper.getGraphWidth(gSubgraph);
  123. int iGraphDiagonalSquare = (iHeight * iHeight) + (iWidth * iWidth);
  124. iCircumference = qSqrt(iGraphDiagonalSquare);
  125. }
  126. return iCircumference;
  127. }