RelaxInterEdges.cpp 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287
  1. #include "RelaxInterEdges.h"
  2. RelaxInterEdges::RelaxInterEdges()
  3. {
  4. }
  5. void RelaxInterEdges :: interEdgesCaseOne(SubGraph& gMaingraph,
  6. VertexDescriptor& vSource,
  7. VertexDescriptor& vTarget,
  8. int* iOuterIntersect)
  9. {
  10. cout<<"\n CASE 1 : ";
  11. // calculate attractive force here ******
  12. int iUCoordX , iUCoordY , iVCoordX , iVCoordY;
  13. iUCoordX = m_bGraphWrapper.getVertexCenterCoordX(vSource,gMaingraph);
  14. iUCoordY = m_bGraphWrapper.getVertexCenterCoordY(vSource,gMaingraph);
  15. iVCoordX = m_bGraphWrapper.getVertexCenterCoordX(vTarget,gMaingraph);
  16. iVCoordY = m_bGraphWrapper.getVertexCenterCoordY(vTarget,gMaingraph);
  17. cout<<"\n Initial X and Y Cordinates "<<iUCoordX<<" "<<iUCoordY;
  18. cout<<"\n Initial X and Y Cordinates "<<iVCoordX<<" "<<iVCoordY;
  19. double dVx = iVCoordX - iOuterIntersect[0];
  20. double dVy = iVCoordY - iOuterIntersect[1];
  21. double dUx = iUCoordX - iOuterIntersect[0] ;
  22. double dUy = iUCoordY - iOuterIntersect[1] ;
  23. cout<<"\n Delta X and Y at attractive force : "<<dVy<<" "
  24. << dVx;
  25. cout<<"\n Delta X and Y at attractive force : "<<dUy<<" "
  26. << dUx;
  27. double dDist1 = fabs(sqrt((dVx*dVx+dVy* dVy)));
  28. double dDist2 = fabs(sqrt((dUx*dUx+dUy* dUy)));
  29. cout<<"\n Distance at attractive force in Inter edges : "<<dDist1<<" "<< dDist2;
  30. // avoid nan
  31. if(dDist1 == 0)
  32. {
  33. dDist1 = 0.0001;
  34. }
  35. if(dDist2 == 0)
  36. {
  37. dDist2 = 0.0001;
  38. }
  39. // desired length = 50
  40. double dForce1 = INTEREDGES_ATTRACTION_MULTIPLIER *(INTEREDGES_DEFAULT_LENGTH - dDist1)/dDist1 ; //0.3 force multiplier
  41. double dForce2 = INTEREDGES_ATTRACTION_MULTIPLIER *(INTEREDGES_DEFAULT_LENGTH - dDist2)/dDist2 ; //0.3 force multiplier
  42. cout<<"\n Force between interedges "<<dForce1<<" " <<dForce2;
  43. // maintain minimum distance
  44. if(dDist1 < MINIMUM_INTEREDGE_DISTANCE ) // 60 earlier
  45. {
  46. dDist1 = 0.0001;
  47. dForce1 = 0;
  48. }
  49. if(dDist2 < MINIMUM_INTEREDGE_DISTANCE)
  50. {
  51. dDist2 = 0.0001;
  52. dForce2 = 0;
  53. }
  54. double dx1 = dForce1 * dVx;
  55. double dy1 = dForce1 * dVy;
  56. double dx2 = dForce2 * dUx;
  57. double dy2 = dForce2 * dUy;
  58. double dXDispV = m_bGraphWrapper.getVertXDisp(vTarget,gMaingraph);
  59. double dYDispV = m_bGraphWrapper.getVertYDisp(vTarget,gMaingraph);
  60. double dXDispU = 0;
  61. double dYDispU = 0;
  62. dXDispU = m_bGraphWrapper.getVertXDisp(vSource,gMaingraph);
  63. dYDispU = m_bGraphWrapper.getVertYDisp(vSource,gMaingraph);
  64. dXDispV += dx1;
  65. dYDispV += dy1;
  66. dXDispU += dx2;
  67. dYDispU += dy2;
  68. cout<<"\n Disp between interedges "<<dx1<<" " <<dy1;
  69. cout<<"\n Disp between interedges "<<dx2<<" " <<dy2;
  70. m_bGraphWrapper.setVertXDisp(dXDispV,vTarget,gMaingraph);
  71. m_bGraphWrapper.setVertYDisp(dYDispV,vTarget,gMaingraph);
  72. m_bGraphWrapper.setVertXDisp(dXDispU,vSource,gMaingraph);
  73. m_bGraphWrapper.setVertYDisp(dYDispU,vSource,gMaingraph);
  74. cout<<"\n Final X and Y Cordinates "<<iUCoordX<<" "<<iUCoordY;
  75. cout<<"\n Final X and Y Cordinates "<<iVCoordX<<" "<<iVCoordY;
  76. }
  77. void RelaxInterEdges :: interEdgesCaseTwoSourceOuter(SubGraph& gMaingraph,
  78. VertexDescriptor& vSource,
  79. VertexDescriptor& vTarget,
  80. int* iOuterIntersect,
  81. SubGraph* gTarget)
  82. {
  83. LAYOUT_ASSERT( gTarget != NULL,
  84. LayoutException(__FUNCTION__
  85. ,LayoutExceptionEnum::INCONSISTENT_DATASTRUCTURE
  86. ,"Input and Output graphml path"
  87. ,"springRepelInterEdges"));
  88. cout<<"\n Source is Outer";
  89. int iSourceX = m_bGraphWrapper.getVertexCenterCoordX(vSource,gMaingraph);
  90. int iSourceY = m_bGraphWrapper.getVertexCenterCoordY(vSource,gMaingraph);
  91. int iTargetX = m_bGraphWrapper.getVertexCenterCoordX(vTarget,gMaingraph);
  92. int iTargetY = m_bGraphWrapper.getVertexCenterCoordY(vTarget,gMaingraph);
  93. int iInnerIntersect[2] = {0,0}; // x and y
  94. int iHeight,iLeftTopX,iLeftTopY,iWidth;
  95. // outer compartment of inner vertex
  96. iHeight = m_bGraphWrapper.getGraphHeight(*gTarget);
  97. iWidth = m_bGraphWrapper.getGraphWidth(*gTarget);
  98. iLeftTopX = m_bGraphWrapper.getGraphLeftTopCoordX(*gTarget);
  99. iLeftTopY = m_bGraphWrapper.getGraphLeftTopCoordY(*gTarget);
  100. cout<<"\n Inner cluster Compartments";
  101. cout<<"\n Top Left X " << iLeftTopX;
  102. cout<<"\n Top Left Y " << iLeftTopY;
  103. cout<<"\n Height " <<iHeight;
  104. cout<<"\n Width "<<iWidth;
  105. // Form 4 piars of P Q R S with Edge e ===> PQ , QR , RS , SP
  106. typedef boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian> Points;
  107. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pP;
  108. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pQ;
  109. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pR;
  110. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pS;
  111. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pX;
  112. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pY;
  113. typedef boost::geometry::model::segment<Points> Segment;
  114. std::vector<Points> pInnerIntersect;
  115. bool bIsNoInnerIntersection = false;
  116. pP.set<0>(iLeftTopX);
  117. pP.set<1>(iLeftTopY);
  118. pQ.set<0>(iLeftTopX);
  119. pQ.set<1>(iLeftTopY + iHeight);
  120. pR.set<0>(iLeftTopX + iWidth);
  121. pR.set<1>(iLeftTopY + iHeight);
  122. pS.set<0>(iLeftTopX+ iWidth);
  123. pS.set<1>(iLeftTopY);
  124. pX.set<0>(iSourceX);
  125. pX.set<1>(iSourceY);
  126. pY.set<0>(iTargetX);
  127. pY.set<1>(iTargetY);
  128. Segment PQ( pP,pQ );
  129. Segment QR( pQ,pR );
  130. Segment RS( pR,pS );
  131. Segment SP( pS,pP );
  132. Segment Edge (pX,pY);
  133. // get different intersection points
  134. if(boost::geometry::intersects(Edge,PQ))
  135. {
  136. boost::geometry::intersection(Edge,PQ,pInnerIntersect);
  137. cout<<" \n Inner Clip Found with Edge PQ";
  138. }
  139. else if( boost::geometry::intersects(Edge,QR))
  140. {
  141. boost::geometry::intersection(Edge,QR,pInnerIntersect);
  142. cout<<" \n Inner Clip Found with Edge QR";
  143. }
  144. else
  145. {
  146. if(boost::geometry::intersects(Edge,RS))
  147. {
  148. boost::geometry::intersection(Edge,RS,pInnerIntersect);
  149. cout<<" \n Inner Clip Found with Edge RS";
  150. }
  151. else if(boost::geometry::intersects(Edge,SP))
  152. {
  153. boost::geometry::intersection(Edge,SP,pInnerIntersect);
  154. cout<<" \n Inner Clip Found with Edge SP";
  155. }
  156. else
  157. {
  158. // no intersection , not possible but handle
  159. cout<<"\n *** No Intersection in Inner *** Check Cluster cordinates" ;
  160. bIsNoInnerIntersection = true;
  161. }
  162. }
  163. if(!bIsNoInnerIntersection)
  164. {
  165. Points pIntersection = pInnerIntersect[0];
  166. iInnerIntersect[0] = pIntersection.get<0>();
  167. iInnerIntersect[1] = pIntersection.get<1>();
  168. }
  169. cout<<"\n Inner Intersection Points "<< " "<<iInnerIntersect[0]<< " "
  170. <<iInnerIntersect[1];
  171. int iUCoordX , iUCoordY , iVCoordX , iVCoordY;
  172. iUCoordX = m_bGraphWrapper.getVertexCenterCoordX(vSource,gMaingraph);
  173. iUCoordY = m_bGraphWrapper.getVertexCenterCoordY(vSource,gMaingraph);
  174. iVCoordX = m_bGraphWrapper.getVertexCenterCoordX(vTarget,gMaingraph);
  175. iVCoordY = m_bGraphWrapper.getVertexCenterCoordY(vTarget,gMaingraph);
  176. double dVx = iVCoordX - iInnerIntersect[0];
  177. double dVy = iVCoordY - iInnerIntersect[1];
  178. double dUx = iUCoordX - iOuterIntersect[0];
  179. double dUy = iUCoordY - iOuterIntersect[1];
  180. cout<<"\n Delta X and Y at attractive force case 2 : "<<dVy<<" "
  181. << dVx;
  182. double dDist1 = fabs(sqrt((dVx*dVx+dVy* dVy)));
  183. double dDist2 = fabs(sqrt((dUx*dUx+dUy* dUy)));
  184. cout<<"\n Distance at attractive force in Inter edges case 2: "<<dDist1;
  185. if(dDist1 == 0)
  186. {
  187. dDist1 = 0.0001;
  188. }
  189. if(dDist2 == 0)
  190. {
  191. dDist2 = 0.0001;
  192. }
  193. // desired length = 100 , adjust force
  194. double dForce1 = INTEREDGES_ATTRACTION_MULTIPLIER *(INTEREDGES_DEFAULT_LENGTH - dDist1)/dDist1 ; //0.3 force multiplier
  195. double dForce2 = INTEREDGES_ATTRACTION_MULTIPLIER *(INTEREDGES_DEFAULT_LENGTH - dDist2)/dDist2 ; //0.3 force multiplier
  196. cout<<"\n Force between Case 2 interedges "<<dForce1<<" " <<dForce2;
  197. if(dDist1 < MINIMUM_INTEREDGE_DISTANCE )
  198. {
  199. dDist1 = 0.0001;
  200. dForce1 = 0;
  201. }
  202. if(dDist2 < MINIMUM_INTEREDGE_DISTANCE)
  203. {
  204. dDist2 = 0.0001;
  205. dForce2 = 0;
  206. }
  207. double dx1 = dForce1 * dVx;
  208. double dy1 = dForce1 * dVy;
  209. double dx2 = dForce2 * dUx;
  210. double dy2 = dForce2 * dUy;
  211. double dXDispV = m_bGraphWrapper.getVertXDisp(vTarget,gMaingraph);
  212. double dYDispV = m_bGraphWrapper.getVertYDisp(vTarget,gMaingraph);
  213. double dXDispU = 0;
  214. double dYDispU = 0;
  215. dXDispU = m_bGraphWrapper.getVertXDisp(vSource,gMaingraph);
  216. dYDispU = m_bGraphWrapper.getVertYDisp(vSource,gMaingraph);
  217. dXDispV += dx1;
  218. dYDispV += dy1;
  219. dXDispU += dx2;
  220. dYDispU += dy2;
  221. cout<<"\n Disp between interedges case 2 "<<dx1<<" " <<dy1;
  222. cout<<"\n Disp between interedges case 2 "<<dx2<<" " <<dy2;
  223. m_bGraphWrapper.setVertXDisp(dXDispV,vTarget,gMaingraph);
  224. m_bGraphWrapper.setVertYDisp(dYDispV,vTarget,gMaingraph);
  225. m_bGraphWrapper.setVertXDisp(dXDispU,vSource,gMaingraph);
  226. m_bGraphWrapper.setVertYDisp(dYDispU,vSource,gMaingraph);
  227. }
  228. void RelaxInterEdges :: interEdgesCaseTwoSourceInner(SubGraph& gMaingraph,
  229. VertexDescriptor& vSource,
  230. VertexDescriptor& vTarget,
  231. int* iOuterIntersect,
  232. SubGraph* gSource)
  233. {
  234. LAYOUT_ASSERT( gSource != NULL,
  235. LayoutException(__FUNCTION__
  236. ,LayoutExceptionEnum::INCONSISTENT_DATASTRUCTURE
  237. ,"Input and Output graphml path"
  238. ,"springRepelInterEdges"));
  239. // source is inner
  240. cout<<"\n Source is Inner";
  241. // inner clipping for source graph
  242. int iSourceX = m_bGraphWrapper.getVertexCenterCoordX(vSource,gMaingraph);
  243. int iSourceY = m_bGraphWrapper.getVertexCenterCoordY(vSource,gMaingraph);
  244. int iTargetX = m_bGraphWrapper.getVertexCenterCoordX(vTarget,gMaingraph);
  245. int iTargetY = m_bGraphWrapper.getVertexCenterCoordY(vTarget,gMaingraph);
  246. int iInnerIntersect[2]; // x and y
  247. int iHeight,iLeftTopX,iLeftTopY,iWidth; // outer compartment of inner vertex
  248. iHeight = m_bGraphWrapper.getGraphHeight(*gSource);
  249. iWidth = m_bGraphWrapper.getGraphWidth(*gSource);
  250. iLeftTopX = m_bGraphWrapper.getGraphLeftTopCoordX(*gSource);
  251. iLeftTopY = m_bGraphWrapper.getGraphLeftTopCoordY(*gSource);
  252. // Form 4 piars of P Q R S with Edge e ===> PQ , QR , RS , SP
  253. typedef boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian> Points;
  254. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pP;
  255. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pQ;
  256. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pR;
  257. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pS;
  258. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pX;
  259. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pY;
  260. typedef boost::geometry::model::segment<Points> Segment;
  261. std::vector<Points> pInnerIntersect;
  262. bool bIsNoInnerIntersection = false;
  263. pP.set<0>(iLeftTopX);
  264. pP.set<1>(iLeftTopY);
  265. pQ.set<0>(iLeftTopX);
  266. pQ.set<1>(iLeftTopY + iHeight);
  267. pR.set<0>(iLeftTopX + iWidth);
  268. pR.set<1>(iLeftTopY + iHeight);
  269. pS.set<0>(iLeftTopX+ iWidth);
  270. pS.set<1>(iLeftTopY);
  271. pX.set<0>(iSourceX);
  272. pX.set<1>(iSourceY);
  273. pY.set<0>(iTargetX);
  274. pY.set<1>(iTargetY);
  275. Segment PQ( pP,pQ );
  276. Segment QR( pQ,pR );
  277. Segment RS( pR,pS );
  278. Segment SP( pS,pP );
  279. Segment Edge (pX,pY);
  280. // get inner clip
  281. if(boost::geometry::intersects(Edge,PQ))
  282. {
  283. boost::geometry::intersection(Edge,PQ,pInnerIntersect);
  284. cout<<" \n Inner Clip Found with Edge PQ";
  285. }
  286. else if( boost::geometry::intersects(Edge,QR))
  287. {
  288. boost::geometry::intersection(Edge,QR,pInnerIntersect);
  289. cout<<" \n Inner Clip Found with Edge QR";
  290. }
  291. else
  292. {
  293. if(boost::geometry::intersects(Edge,RS))
  294. {
  295. boost::geometry::intersection(Edge,RS,pInnerIntersect);
  296. cout<<" \n Inner Clip Found with Edge RS";
  297. }
  298. else if(boost::geometry::intersects(Edge,SP))
  299. {
  300. boost::geometry::intersection(Edge,SP,pInnerIntersect);
  301. cout<<" \n Inner Clip Found with Edge SP";
  302. }
  303. else
  304. {
  305. // no intersection , not possible but handle
  306. cout<<"\n *** No Intersection in Inner *** Check Cluster cordinates" ;
  307. bIsNoInnerIntersection = true;
  308. }
  309. }
  310. if(!bIsNoInnerIntersection)
  311. {
  312. Points pIntersection = pInnerIntersect[0];
  313. iInnerIntersect[0] = pIntersection.get<0>();
  314. iInnerIntersect[1] = pIntersection.get<1>();
  315. } else {
  316. // XXX preset needed
  317. iInnerIntersect[0] =0;
  318. iInnerIntersect[1] =0;
  319. }
  320. int iUCoordX , iUCoordY , iVCoordX , iVCoordY;
  321. iUCoordX = m_bGraphWrapper.getVertexCenterCoordX(vSource,gMaingraph);
  322. iUCoordY = m_bGraphWrapper.getVertexCenterCoordY(vSource,gMaingraph);
  323. iVCoordX = m_bGraphWrapper.getVertexCenterCoordX(vTarget,gMaingraph);
  324. iVCoordY = m_bGraphWrapper.getVertexCenterCoordY(vTarget,gMaingraph);
  325. double dVx = iVCoordX - iOuterIntersect[0];
  326. double dVy = iVCoordY - iOuterIntersect[1];
  327. double dUx = iUCoordX - iInnerIntersect[0];
  328. double dUy = iUCoordY - iInnerIntersect[1];
  329. cout<<"\n Delta X and Y at attractive force case 2 : "<<dVy<<" "
  330. << dVx;
  331. double dDist1 = fabs(sqrt((dVx*dVx+dVy* dVy)));
  332. double dDist2 = fabs(sqrt((dUx*dUx+dUy* dUy)));
  333. cout<<"\n Distance at attractive force in Inter edges case 2: "<<dDist1;
  334. if(dDist1 == 0)
  335. {
  336. dDist1 = 0.0001;
  337. }
  338. if(dDist2 == 0)
  339. {
  340. dDist2 = 0.0001;
  341. }
  342. // desired length = 50
  343. double dForce1 = INTEREDGES_ATTRACTION_MULTIPLIER *(INTEREDGES_DEFAULT_LENGTH - dDist1)/dDist1 ; //0.3 force multiplier
  344. double dForce2 = INTEREDGES_ATTRACTION_MULTIPLIER *(INTEREDGES_DEFAULT_LENGTH - dDist2)/dDist2 ; //0.3 force multiplier
  345. cout<<"\n Force between Case 2 interedges "<<dForce1<<" " <<dForce2;
  346. if(dDist1 < MINIMUM_INTEREDGE_DISTANCE )
  347. {
  348. dDist1 = 0.0001;
  349. dForce1 = 0;
  350. }
  351. if(dDist2 < MINIMUM_INTEREDGE_DISTANCE)
  352. {
  353. dDist1 = 0.0001;
  354. dForce2 = 0;
  355. }
  356. double dx1 = dForce1 * dVx;
  357. double dy1 = dForce1 * dVy;
  358. double dx2 = dForce2 * dUx;
  359. double dy2 = dForce2 * dUy;
  360. double dXDispV = m_bGraphWrapper.getVertXDisp(vTarget,gMaingraph);
  361. double dYDispV = m_bGraphWrapper.getVertYDisp(vTarget,gMaingraph);
  362. double dXDispU = 0;
  363. double dYDispU = 0;
  364. dXDispU = m_bGraphWrapper.getVertXDisp(vSource,gMaingraph);
  365. dYDispU = m_bGraphWrapper.getVertYDisp(vSource,gMaingraph);
  366. dXDispV += dx1;
  367. dYDispV += dy1;
  368. dXDispU += dx2;
  369. dYDispU += dy2;
  370. cout<<"\n Disp between interedges case 2 "<<dx1<<" " <<dy1;
  371. cout<<"\n Disp between interedges case 2 "<<dx2<<" " <<dy2;
  372. m_bGraphWrapper.setVertXDisp(dXDispV,vTarget,gMaingraph);
  373. m_bGraphWrapper.setVertYDisp(dYDispV,vTarget,gMaingraph);
  374. m_bGraphWrapper.setVertXDisp(dXDispU,vSource,gMaingraph);
  375. m_bGraphWrapper.setVertYDisp(dYDispU,vSource,gMaingraph);
  376. }
  377. void RelaxInterEdges :: OverLapCaseSourceOuter(SubGraph& gMaingraph,
  378. VertexDescriptor& vSource,
  379. VertexDescriptor& vTarget,
  380. SubGraph* gTarget,
  381. int iSourceGraphId)
  382. {
  383. LAYOUT_ASSERT( gTarget != NULL,
  384. LayoutException(__FUNCTION__
  385. ,LayoutExceptionEnum::INCONSISTENT_DATASTRUCTURE
  386. ,"Input and Output graphml path"
  387. ,"springRepelInterEdges"));
  388. bool bIsSourceOuter = true;
  389. bool bIsNull = false;
  390. bool bParentFound = false;// source is outer
  391. SubGraph* gTempGraph = (gTarget);
  392. // XXX unused
  393. Q_UNUSED(bIsSourceOuter);
  394. while( !bParentFound )
  395. {
  396. // SubGraph& gOuterParentGraph = (*gTempGraph).parent();
  397. SubGraph* gOuterParentGraph = &((*gTempGraph).parent());
  398. if(!gOuterParentGraph)
  399. {
  400. // null graph received
  401. bIsNull = true;
  402. break;
  403. }
  404. int iParentGraphId = m_bGraphWrapper.getGraphClusterID(*gOuterParentGraph);
  405. if(iParentGraphId == iSourceGraphId)
  406. {
  407. bParentFound = true;
  408. }
  409. else
  410. {
  411. //gTempGraph = & gOuterParentGraph;
  412. gTempGraph = & (*gOuterParentGraph);
  413. }
  414. }
  415. if(!bIsNull)
  416. {
  417. int iTargetGraphHeight = m_bGraphWrapper.getGraphHeight(*gTarget);
  418. int iTargetTopXLeft = m_bGraphWrapper.getGraphLeftTopCoordX(*gTarget);
  419. int iTargetGraphWidth = m_bGraphWrapper.getGraphWidth(*gTarget);
  420. int iTargetTopYLeft = m_bGraphWrapper.getGraphLeftTopCoordY(*gTarget);
  421. int iUCoordX , iUCoordY , iVCoordX , iVCoordY;
  422. iUCoordX = m_bGraphWrapper.getVertexCenterCoordX(vSource,gMaingraph);
  423. iUCoordY = m_bGraphWrapper.getVertexCenterCoordY(vSource,gMaingraph);
  424. iVCoordX = m_bGraphWrapper.getVertexCenterCoordX(vTarget,gMaingraph);
  425. iVCoordY = m_bGraphWrapper.getVertexCenterCoordY(vTarget,gMaingraph);
  426. int iHeight,iLeftTopX,iLeftTopY,iWidth; // outer compartment of inner vertex
  427. iHeight = m_bGraphWrapper.getGraphHeight(*gTempGraph);
  428. iWidth = m_bGraphWrapper.getGraphWidth(*gTempGraph);
  429. iLeftTopX = m_bGraphWrapper.getGraphLeftTopCoordX(*gTempGraph);
  430. iLeftTopY = m_bGraphWrapper.getGraphLeftTopCoordY(*gTempGraph);
  431. int iOuterMostGraphID = m_bGraphWrapper.getGraphClusterID(*gTempGraph);
  432. cout<< "\n Outer Cordinates of Clusters Overlapping Case " ;
  433. cout<<"\n Outer Graph ID "<<iOuterMostGraphID;
  434. cout<< " Height "<<iHeight;
  435. cout<< " Width "<<iWidth;
  436. cout<< " Lefttop X "<<iLeftTopX;
  437. cout<< " Lefttop Y "<<iLeftTopY;
  438. // For inner clipping points
  439. // Form 4 piars of P Q R S with Edge e ===> PQ , QR , RS , SP and AB , BC ,CD , DA
  440. typedef boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian> Points;
  441. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pP;
  442. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pQ;
  443. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pR;
  444. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pS;
  445. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pA;
  446. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pB;
  447. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pC;
  448. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pD;
  449. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pX;
  450. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pY;
  451. typedef boost::geometry::model::segment<Points> Segment;
  452. std::vector<Points> pOverlapOuterIntersect , pOverlapInnerIntersect;
  453. bool bIsNoInnerIntersection = false , bIsNoOuterIntersection = false;
  454. pP.set<0>(iLeftTopX);
  455. pP.set<1>(iLeftTopY);
  456. pQ.set<0>(iLeftTopX);
  457. pQ.set<1>(iLeftTopY + iHeight);
  458. pR.set<0>(iLeftTopX + iWidth);
  459. pR.set<1>(iLeftTopY + iHeight);
  460. pS.set<0>(iLeftTopX+ iWidth);
  461. pS.set<1>(iLeftTopY);
  462. pA.set<0>(iTargetTopXLeft); // For inner Clips
  463. pA.set<1>(iTargetTopYLeft);
  464. pB.set<0>(iTargetTopXLeft);
  465. pB.set<1>(iTargetTopYLeft + iTargetGraphHeight);
  466. pC.set<0>(iTargetTopXLeft + iTargetGraphWidth);
  467. pC.set<1>(iTargetTopYLeft + iTargetGraphHeight);
  468. pD.set<0>(iTargetTopXLeft+ iTargetGraphWidth);
  469. pD.set<1>(iTargetTopYLeft);
  470. pX.set<0>(iUCoordX); // Source X and Y
  471. pX.set<1>(iUCoordY);
  472. pY.set<0>( iVCoordX); // Target X and Y
  473. pY.set<1>(iVCoordY);
  474. Segment PQ( pP,pQ );
  475. Segment QR( pQ,pR );
  476. Segment RS( pR,pS );
  477. Segment SP( pS,pP );
  478. Segment Edge (pX,pY);
  479. Segment AB(pA,pB);
  480. Segment BC(pB,pC);
  481. Segment CD(pC,pD);
  482. Segment DA(pD,pA);
  483. // check outer intersection
  484. if(boost::geometry::intersects(Edge,PQ))
  485. {
  486. boost::geometry::intersection(Edge,PQ,pOverlapOuterIntersect);
  487. cout<<" \n OverLapping Outer Clip Found with Edge PQ";
  488. }
  489. else if( boost::geometry::intersects(Edge,QR))
  490. {
  491. boost::geometry::intersection(Edge,QR,pOverlapOuterIntersect);
  492. cout<<" \n OverLapping Outer Clip Found with Edge QR";
  493. }
  494. else
  495. {
  496. if(boost::geometry::intersects(Edge,RS))
  497. {
  498. boost::geometry::intersection(Edge,RS,pOverlapOuterIntersect);
  499. cout<<" \n OverLapping Outer Clip Found with Edge RS";
  500. }
  501. else if(boost::geometry::intersects(Edge,SP))
  502. {
  503. boost::geometry::intersection(Edge,SP,pOverlapOuterIntersect);
  504. cout<<" \n OverLapping Outer Clip Found with Edge SP";
  505. }
  506. else
  507. {
  508. // no intersection , not possible but handle
  509. cout<<"\n *** No Intersection in Overlap *** Check Cluster cordinates" ;
  510. bIsNoOuterIntersection = true;
  511. }
  512. }
  513. // check inner intersection
  514. { // For separating two if else loops
  515. if(boost::geometry::intersects(Edge,AB))
  516. {
  517. boost::geometry::intersection(Edge,AB,pOverlapInnerIntersect);
  518. cout<<" \n OverLapping Inner Clip Found with Edge AB";
  519. }
  520. else if( boost::geometry::intersects(Edge,BC))
  521. {
  522. boost::geometry::intersection(Edge,BC,pOverlapInnerIntersect);
  523. cout<<" \n OverLapping Inner Clip Found with Edge BC";
  524. }
  525. else
  526. {
  527. if(boost::geometry::intersects(Edge,CD))
  528. {
  529. boost::geometry::intersection(Edge,CD,pOverlapInnerIntersect);
  530. cout<<" \n OverLapping Inner Clip Found with Edge CD";
  531. }
  532. else if(boost::geometry::intersects(Edge,DA))
  533. {
  534. boost::geometry::intersection(Edge,DA,pOverlapInnerIntersect);
  535. cout<<" \n OverLapping Inner Clip Found with Edge DA";
  536. }
  537. else
  538. {
  539. // no intersection , not possible but handle
  540. cout<<"\n *** No Inner Intersection in Overlap *** Check Cluster cordinates" ;
  541. bIsNoInnerIntersection = true;
  542. }
  543. }
  544. }
  545. int iOuterIntersectX,iOuterIntersectY,iInnerIntersectX,iInnerIntersectY;
  546. if(!bIsNoOuterIntersection)
  547. {
  548. Points pIntersection = pOverlapOuterIntersect[0];
  549. iOuterIntersectX = pIntersection.get<0>();
  550. iOuterIntersectY = pIntersection.get<1>();
  551. }
  552. if(!bIsNoInnerIntersection)
  553. {
  554. Points pIntersection = pOverlapInnerIntersect[0];
  555. iInnerIntersectX = pIntersection.get<0>();
  556. iInnerIntersectY = pIntersection.get<1>();
  557. }
  558. // attract source with outer and target with inner
  559. if(!bIsNoOuterIntersection && !bIsNoInnerIntersection )
  560. {
  561. // attract only if both intersections are found
  562. double dVx = iVCoordX - iInnerIntersectX;
  563. double dVy = iVCoordY - iInnerIntersectY;
  564. double dUx = iUCoordX - iOuterIntersectX;
  565. double dUy = iUCoordY - iOuterIntersectY;
  566. cout<<"\n Delta X and Y at attractive force case 2 : "<<dVy<<" "
  567. << dVx;
  568. double dDist1 = fabs(sqrt((dVx*dVx+dVy* dVy)));
  569. double dDist2 = fabs(sqrt((dUx*dUx+dUy* dUy)));
  570. cout<<"\n Distance at attractive force in Inter edges case 2: "<<dDist1;
  571. if(dDist1 == 0)
  572. {
  573. dDist1 = 0.0001;
  574. }
  575. if(dDist2 == 0)
  576. {
  577. dDist2 = 0.0001;
  578. }
  579. // desired length = 50
  580. double dForce1 = INTEREDGES_ATTRACTION_MULTIPLIER *(INTEREDGES_DEFAULT_LENGTH - dDist1)/dDist1 ; //0.3 force multiplier
  581. double dForce2 = INTEREDGES_ATTRACTION_MULTIPLIER *(INTEREDGES_DEFAULT_LENGTH - dDist2)/dDist2 ; //0.3 force multiplier
  582. cout<<"\n Force between Case 2 interedges "<<dForce1<<" " <<dForce2;
  583. if(dDist1 < MINIMUM_INTEREDGE_DISTANCE )
  584. {
  585. dDist1 = 0.0001;
  586. dForce1 = 0;
  587. }
  588. if(dDist2 < MINIMUM_INTEREDGE_DISTANCE)
  589. {
  590. dDist2 = 0.0001;
  591. dForce2 = 0;
  592. }
  593. // get displacement
  594. double dx1 = dForce1 * dVx;
  595. double dy1 = dForce1 * dVy;
  596. double dx2 = dForce2 * dUx;
  597. double dy2 = dForce2 * dUy;
  598. double dXDispV = m_bGraphWrapper.getVertXDisp(vTarget,gMaingraph);
  599. double dYDispV = m_bGraphWrapper.getVertYDisp(vTarget,gMaingraph);
  600. double dXDispU = 0;
  601. double dYDispU = 0;
  602. dXDispU = m_bGraphWrapper.getVertXDisp(vSource,gMaingraph);
  603. dYDispU = m_bGraphWrapper.getVertYDisp(vSource,gMaingraph);
  604. dXDispV += dx1;
  605. dYDispV += dy1;
  606. dXDispU += dx2;
  607. dYDispU += dy2;
  608. cout<<"\n Disp between interedges case 2 "<<dx1<<" " <<dy1;
  609. cout<<"\n Disp between interedges case 2 "<<dx2<<" " <<dy2;
  610. m_bGraphWrapper.setVertXDisp(dXDispV,vTarget,gMaingraph);
  611. m_bGraphWrapper.setVertYDisp(dYDispV,vTarget,gMaingraph);
  612. m_bGraphWrapper.setVertXDisp(dXDispU,vSource,gMaingraph);
  613. m_bGraphWrapper.setVertYDisp(dYDispU,vSource,gMaingraph);
  614. }
  615. }
  616. }
  617. void RelaxInterEdges :: OverLapCaseSourceInner(SubGraph& gMaingraph,
  618. VertexDescriptor& vSource,
  619. VertexDescriptor& vTarget,
  620. SubGraph* gSource,
  621. int iTargetGraphId)
  622. {
  623. LAYOUT_ASSERT( gSource != NULL,
  624. LayoutException(__FUNCTION__
  625. ,LayoutExceptionEnum::INCONSISTENT_DATASTRUCTURE
  626. ,"Input and Output graphml path"
  627. ,"springRepelInterEdges"));
  628. cout<<"\n Target is outer ";
  629. // Source is inner and target is outer
  630. bool bIsSourceOuter = false;
  631. bool bParentFound = false; // source is inner
  632. SubGraph* gTempGraph = (gSource);
  633. // XXX unused
  634. Q_UNUSED(bIsSourceOuter)
  635. bool bIsNull = false;
  636. while( bParentFound == false)
  637. {
  638. SubGraph* gOuterParentGraph = &((*gTempGraph).parent());
  639. if(!gOuterParentGraph)
  640. {
  641. // null graph received
  642. bIsNull = true;
  643. break;
  644. }
  645. int iParentGraphId = m_bGraphWrapper.getGraphClusterID(*gOuterParentGraph);
  646. if(iParentGraphId == iTargetGraphId)
  647. {
  648. bParentFound = true;
  649. }
  650. else
  651. {
  652. gTempGraph = & (*gOuterParentGraph); // changed goutergraph to pointer
  653. }
  654. }
  655. if(!bIsNull)
  656. {
  657. int iSourceGraphHeight = m_bGraphWrapper.getGraphHeight(*gSource);
  658. int iSourceTopXLeft = m_bGraphWrapper.getGraphLeftTopCoordX(*gSource);
  659. int iSourceGraphWidth = m_bGraphWrapper.getGraphWidth(*gSource);
  660. int iSourceTopYLeft = m_bGraphWrapper.getGraphLeftTopCoordY(*gSource);
  661. int iUCoordX = m_bGraphWrapper.getVertexCenterCoordX(vSource,gMaingraph);
  662. int iUCoordY = m_bGraphWrapper.getVertexCenterCoordY(vSource,gMaingraph);
  663. int iVCoordX = m_bGraphWrapper.getVertexCenterCoordX(vTarget,gMaingraph);
  664. int iVCoordY = m_bGraphWrapper.getVertexCenterCoordY(vTarget,gMaingraph);
  665. int iHeight,iLeftTopX,iLeftTopY,iWidth;
  666. // outer compartment of inner vertex
  667. iHeight = m_bGraphWrapper.getGraphHeight(*gTempGraph);
  668. iWidth = m_bGraphWrapper.getGraphWidth(*gTempGraph);
  669. iLeftTopX = m_bGraphWrapper.getGraphLeftTopCoordX(*gTempGraph);
  670. iLeftTopY = m_bGraphWrapper.getGraphLeftTopCoordY(*gTempGraph);
  671. int iOuterMostGraphID = m_bGraphWrapper.getGraphClusterID(*gTempGraph);
  672. cout<< "\n Outer Cordinates of Clusters Overlapping Case " ;
  673. cout<<"\n Outer Graph ID "<<iOuterMostGraphID;
  674. cout<< " Height "<<iHeight;
  675. cout<< " Width "<<iWidth;
  676. cout<< " Lefttop X "<<iLeftTopX;
  677. cout<< " Lefttop Y "<<iLeftTopY;
  678. // For inner clipping points
  679. // Form 4 piars of P Q R S with Edge e ===> PQ , QR , RS , SP and AB , BC ,CD , DA
  680. typedef boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian> Points;
  681. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pP;
  682. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pQ;
  683. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pR;
  684. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pS;
  685. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pA;
  686. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pB;
  687. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pC;
  688. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pD;
  689. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pX;
  690. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pY;
  691. typedef boost::geometry::model::segment<Points> Segment;
  692. std::vector<Points> pOverlapOuterIntersect , pOverlapInnerIntersect;
  693. bool bIsNoInnerIntersection = false , bIsNoOuterIntersection = false;
  694. pP.set<0>(iLeftTopX);
  695. pP.set<1>(iLeftTopY);
  696. pQ.set<0>(iLeftTopX);
  697. pQ.set<1>(iLeftTopY + iHeight);
  698. pR.set<0>(iLeftTopX + iWidth);
  699. pR.set<1>(iLeftTopY + iHeight);
  700. pS.set<0>(iLeftTopX+ iWidth);
  701. pS.set<1>(iLeftTopY);
  702. pA.set<0>(iSourceTopXLeft); // For inner Clips
  703. pA.set<1>(iSourceTopYLeft);
  704. pB.set<0>(iSourceTopXLeft);
  705. pB.set<1>(iSourceTopYLeft + iSourceGraphHeight);
  706. pC.set<0>(iSourceTopXLeft + iSourceGraphWidth);
  707. pC.set<1>(iSourceTopYLeft + iSourceGraphHeight);
  708. pD.set<0>(iSourceTopXLeft + iSourceGraphWidth);
  709. pD.set<1>(iSourceTopYLeft);
  710. pX.set<0>(iUCoordX); // Source X and Y
  711. pX.set<1>(iUCoordY);
  712. pY.set<0>( iVCoordX); // Target X and Y
  713. pY.set<1>(iVCoordY);
  714. Segment PQ( pP,pQ );
  715. Segment QR( pQ,pR );
  716. Segment RS( pR,pS );
  717. Segment SP( pS,pP );
  718. Segment Edge (pX,pY);
  719. Segment AB(pA,pB);
  720. Segment BC(pB,pC);
  721. Segment CD(pC,pD);
  722. Segment DA(pD,pA);
  723. // check outer intersection
  724. if(boost::geometry::intersects(Edge,PQ))
  725. {
  726. boost::geometry::intersection(Edge,PQ,pOverlapOuterIntersect);
  727. cout<<" \n OverLapping Outer Clip Found with Edge PQ";
  728. }
  729. else if( boost::geometry::intersects(Edge,QR))
  730. {
  731. boost::geometry::intersection(Edge,QR,pOverlapOuterIntersect);
  732. cout<<" \n OverLapping Outer Clip Found with Edge QR";
  733. }
  734. else
  735. {
  736. if(boost::geometry::intersects(Edge,RS))
  737. {
  738. boost::geometry::intersection(Edge,RS,pOverlapOuterIntersect);
  739. cout<<" \n OverLapping Outer Clip Found with Edge RS";
  740. }
  741. else if(boost::geometry::intersects(Edge,SP))
  742. {
  743. boost::geometry::intersection(Edge,SP,pOverlapOuterIntersect);
  744. cout<<" \n OverLapping Outer Clip Found with Edge SP";
  745. }
  746. else
  747. {
  748. // no intersection , not possible but handle
  749. cout<<"\n *** No Intersection in Overlap *** Check Cluster cordinates" ;
  750. bIsNoOuterIntersection = true;
  751. }
  752. }
  753. // check inner intersection
  754. { // For separating two if else loops
  755. if(boost::geometry::intersects(Edge,AB))
  756. {
  757. boost::geometry::intersection(Edge,AB,pOverlapInnerIntersect);
  758. cout<<" \n OverLapping Inner Clip Found with Edge AB";
  759. }
  760. else if( boost::geometry::intersects(Edge,BC))
  761. {
  762. boost::geometry::intersection(Edge,BC,pOverlapInnerIntersect);
  763. cout<<" \n OverLapping Inner Clip Found with Edge BC";
  764. }
  765. else
  766. {
  767. if(boost::geometry::intersects(Edge,CD))
  768. {
  769. boost::geometry::intersection(Edge,CD,pOverlapInnerIntersect);
  770. cout<<" \n OverLapping Inner Clip Found with Edge CD";
  771. }
  772. else if(boost::geometry::intersects(Edge,DA))
  773. {
  774. boost::geometry::intersection(Edge,DA,pOverlapInnerIntersect);
  775. cout<<" \n OverLapping Inner Clip Found with Edge DA";
  776. }
  777. else
  778. {
  779. // no intersection , not possible but handle
  780. cout<<"\n *** No Inner Intersection in Overlap *** Check Cluster cordinates" ;
  781. bIsNoInnerIntersection = true;
  782. }
  783. }
  784. }
  785. int iOuterIntersectX,iOuterIntersectY,iInnerIntersectX,iInnerIntersectY;
  786. if(!bIsNoOuterIntersection)
  787. {
  788. Points pIntersection = pOverlapOuterIntersect[0];
  789. iOuterIntersectX = pIntersection.get<0>();
  790. iOuterIntersectY = pIntersection.get<1>();
  791. }
  792. if(!bIsNoInnerIntersection)
  793. {
  794. Points pIntersection = pOverlapInnerIntersect[0];
  795. iInnerIntersectX = pIntersection.get<0>();
  796. iInnerIntersectY = pIntersection.get<1>();
  797. }
  798. // attract source with inner and target with outer
  799. if(!bIsNoOuterIntersection && !bIsNoInnerIntersection )
  800. {
  801. // attract only if both intersections are found
  802. double dVx = iVCoordX - iOuterIntersectX;
  803. double dVy = iVCoordY - iOuterIntersectY;
  804. double dUx = iUCoordX - iInnerIntersectX;
  805. double dUy = iUCoordY - iInnerIntersectY;
  806. cout<<"\n Delta X and Y at attractive force case 2 : "<<dVy<<" "
  807. << dVx;
  808. double dDist1 = fabs(sqrt((dVx*dVx+dVy* dVy)));
  809. double dDist2 = fabs(sqrt((dUx*dUx+dUy* dUy)));
  810. cout<<"\n Distance at attractive force in Inter edges case 2: "<<dDist1;
  811. if(dDist1 == 0)
  812. {
  813. dDist1 = 0.0001;
  814. }
  815. if(dDist2 == 0)
  816. {
  817. dDist2 = 0.0001;
  818. }
  819. // desired length = 50
  820. double dForce1 = INTEREDGES_ATTRACTION_MULTIPLIER *(INTEREDGES_DEFAULT_LENGTH - dDist1)/dDist1 ; //0.3 force multiplier
  821. double dForce2 = INTEREDGES_ATTRACTION_MULTIPLIER *(INTEREDGES_DEFAULT_LENGTH - dDist2)/dDist2 ; //0.3 force multiplier
  822. cout<<"\n Force between Case 2 interedges "<<dForce1<<" " <<dForce2;
  823. if(dDist1 < MINIMUM_INTEREDGE_DISTANCE )
  824. {
  825. dDist1 = 0.0001;
  826. dForce1 = 0;
  827. }
  828. if(dDist2 < MINIMUM_INTEREDGE_DISTANCE)
  829. {
  830. dDist2 = 0.0001;
  831. dForce2 = 0;
  832. }
  833. double dx1 = dForce1 * dVx;
  834. double dy1 = dForce1 * dVy;
  835. double dx2 = dForce2 * dUx;
  836. double dy2 = dForce2 * dUy;
  837. double dXDispV = m_bGraphWrapper.getVertXDisp(vTarget,gMaingraph);
  838. double dYDispV = m_bGraphWrapper.getVertYDisp(vTarget,gMaingraph);
  839. double dXDispU = 0;
  840. double dYDispU = 0;
  841. dXDispU = m_bGraphWrapper.getVertXDisp(vSource,gMaingraph);
  842. dYDispU = m_bGraphWrapper.getVertYDisp(vSource,gMaingraph);
  843. dXDispV += dx1;
  844. dYDispV += dy1;
  845. dXDispU += dx2;
  846. dYDispU += dy2;
  847. cout<<"\n Disp between interedges case 2 "<<dx1<<" " <<dy1;
  848. cout<<"\n Disp between interedges case 2 "<<dx2<<" " <<dy2;
  849. m_bGraphWrapper.setVertXDisp(dXDispV,vTarget,gMaingraph);
  850. m_bGraphWrapper.setVertYDisp(dYDispV,vTarget,gMaingraph);
  851. m_bGraphWrapper.setVertXDisp(dXDispU,vSource,gMaingraph);
  852. m_bGraphWrapper.setVertYDisp(dYDispU,vSource,gMaingraph);
  853. }
  854. }
  855. }
  856. void RelaxInterEdges :: nonOverLapCase(SubGraph& gMaingraph,
  857. VertexDescriptor& vSource,
  858. VertexDescriptor& vTarget,
  859. SubGraph* gSource, SubGraph* gTarget)
  860. {
  861. LAYOUT_ASSERT( gSource != NULL,
  862. LayoutException(__FUNCTION__
  863. ,LayoutExceptionEnum::INCONSISTENT_DATASTRUCTURE
  864. ,"Input and Output graphml path"
  865. ,"springRepelInterEdges"));
  866. LAYOUT_ASSERT( gTarget != NULL,
  867. LayoutException(__FUNCTION__
  868. ,LayoutExceptionEnum::INCONSISTENT_DATASTRUCTURE
  869. ,"Input and Output graphml path"
  870. ,"springRepelInterEdges"));
  871. int iSourceGraphHeight = m_bGraphWrapper.getGraphHeight(*gSource);
  872. int iSourceTopXLeft = m_bGraphWrapper.getGraphLeftTopCoordX(*gSource);
  873. int iSourceGraphWidth = m_bGraphWrapper.getGraphWidth(*gSource);
  874. int iSourceTopYLeft = m_bGraphWrapper.getGraphLeftTopCoordY(*gSource);
  875. int iTargetGraphHeight = m_bGraphWrapper.getGraphHeight(*gTarget);
  876. int iTargetTopXLeft = m_bGraphWrapper.getGraphLeftTopCoordX(*gTarget);
  877. int iTargetGraphWidth = m_bGraphWrapper.getGraphWidth(*gTarget);
  878. int iTargetTopYLeft = m_bGraphWrapper.getGraphLeftTopCoordY(*gTarget);
  879. int iSourceXIntersect =0 , iSourceYIntersect = 0 , iTargetYIntersect =0 ,
  880. iTargetXIntersect = 0;
  881. // Non overlapping code here
  882. // For inner clipping points of both subgraphs
  883. // Form 4 piars of P Q R S with Edge e ===> PQ , QR , RS , SP and AB , BC ,CD , DA
  884. typedef boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian> Points;
  885. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pP;
  886. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pQ;
  887. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pR;
  888. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pS;
  889. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pA;
  890. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pB;
  891. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pC;
  892. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pD;
  893. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pX;
  894. boost::geometry::model::point<int, 2, boost::geometry::cs::cartesian>pY;
  895. typedef boost::geometry::model::segment<Points> Segment;
  896. std::vector<Points> pSourceIntersect , pTargetIntersect;
  897. bool bIsNoInnerIntersection = false , bIsNoOuterIntersection = false;
  898. pP.set<0>(iSourceTopXLeft);
  899. pP.set<1>(iSourceTopYLeft); // For Source
  900. pQ.set<0>(iSourceTopXLeft);
  901. pQ.set<1>(iSourceTopYLeft+ iSourceGraphHeight);
  902. pR.set<0>(iSourceTopXLeft+ iSourceGraphWidth);
  903. pR.set<1>(iSourceTopYLeft + iSourceGraphHeight);
  904. pS.set<0>(iSourceTopXLeft+ iSourceGraphWidth);
  905. pS.set<1>(iSourceTopYLeft);
  906. pA.set<0>(iTargetTopXLeft); // For Target
  907. pA.set<1>(iTargetTopYLeft);
  908. pB.set<0>(iTargetTopXLeft);
  909. pB.set<1>(iTargetTopYLeft + iTargetGraphHeight);
  910. pC.set<0>(iTargetTopXLeft + iTargetGraphWidth);
  911. pC.set<1>(iTargetTopYLeft + iTargetGraphHeight);
  912. pD.set<0>(iTargetTopXLeft + iTargetGraphWidth);
  913. pD.set<1>(iTargetTopYLeft);
  914. int iUCoordX = m_bGraphWrapper.getVertexCenterCoordX(vSource,gMaingraph);
  915. int iUCoordY = m_bGraphWrapper.getVertexCenterCoordY(vSource,gMaingraph);
  916. int iVCoordX = m_bGraphWrapper.getVertexCenterCoordX(vTarget,gMaingraph);
  917. int iVCoordY = m_bGraphWrapper.getVertexCenterCoordY(vTarget,gMaingraph);
  918. pX.set<0>(iUCoordX); // Source X and Y
  919. pX.set<1>(iUCoordY);
  920. pY.set<0>(iVCoordX); // Target X and Y
  921. pY.set<1>(iVCoordY);
  922. Segment PQ( pP,pQ );
  923. Segment QR( pQ,pR );
  924. Segment RS( pR,pS );
  925. Segment SP( pS,pP );
  926. Segment Edge (pX,pY);
  927. Segment AB(pA,pB);
  928. Segment BC(pB,pC);
  929. Segment CD(pC,pD);
  930. Segment DA(pD,pA);
  931. {
  932. if(boost::geometry::intersects(Edge,PQ))
  933. {
  934. boost::geometry::intersection(Edge,PQ,pSourceIntersect);
  935. cout<<" \n OverLapping Outer Clip Found with Edge PQ";
  936. }
  937. else if( boost::geometry::intersects(Edge,QR))
  938. {
  939. boost::geometry::intersection(Edge,QR,pSourceIntersect);
  940. cout<<" \n OverLapping Outer Clip Found with Edge QR";
  941. }
  942. else
  943. {
  944. if(boost::geometry::intersects(Edge,RS))
  945. {
  946. // get insetersect points
  947. boost::geometry::intersection(Edge,RS,pSourceIntersect);
  948. cout<<" \n OverLapping Outer Clip Found with Edge RS";
  949. }
  950. else if(boost::geometry::intersects(Edge,SP))
  951. {
  952. boost::geometry::intersection(Edge,SP,pSourceIntersect);
  953. cout<<" \n OverLapping Outer Clip Found with Edge SP";
  954. }
  955. else
  956. {
  957. // no intersection , not possible but handle
  958. cout<<"\n *** No Intersection in Overlap *** Check Cluster cordinates" ;
  959. bIsNoOuterIntersection = true;
  960. }
  961. }
  962. }
  963. { // For separating two if else loops
  964. if(boost::geometry::intersects(Edge,AB))
  965. {
  966. boost::geometry::intersection(Edge,AB,pTargetIntersect);
  967. cout<<" \n OverLapping Inner Clip Found with Edge AB";
  968. }
  969. else if( boost::geometry::intersects(Edge,BC))
  970. {
  971. boost::geometry::intersection(Edge,BC,pTargetIntersect);
  972. cout<<" \n OverLapping Inner Clip Found with Edge BC";
  973. }
  974. else
  975. {
  976. if(boost::geometry::intersects(Edge,CD))
  977. {
  978. boost::geometry::intersection(Edge,CD,pTargetIntersect);
  979. cout<<" \n OverLapping Inner Clip Found with Edge CD";
  980. }
  981. else if(boost::geometry::intersects(Edge,DA))
  982. {
  983. boost::geometry::intersection(Edge,DA,pTargetIntersect);
  984. cout<<" \n OverLapping Inner Clip Found with Edge DA";
  985. }
  986. else
  987. {
  988. // no intersection , not possible but handle
  989. cout<<"\n *** No Inner Intersection in Overlap *** Check Cluster cordinates" ;
  990. bIsNoInnerIntersection = true;
  991. }
  992. }
  993. }
  994. // attract here
  995. if(!bIsNoOuterIntersection)
  996. {
  997. Points pIntersection = pSourceIntersect[0];
  998. iSourceXIntersect = pIntersection.get<0>();
  999. iSourceYIntersect = pIntersection.get<1>();
  1000. }
  1001. if(!bIsNoInnerIntersection)
  1002. {
  1003. Points pIntersection = pTargetIntersect[0];
  1004. iTargetXIntersect = pIntersection.get<0>();
  1005. iTargetYIntersect = pIntersection.get<1>();
  1006. }
  1007. if(!bIsNoOuterIntersection && !bIsNoInnerIntersection )
  1008. {
  1009. // attract only if both intersections are found
  1010. double dVx = iVCoordX - iTargetXIntersect;
  1011. double dVy = iVCoordY - iTargetYIntersect;
  1012. double dUx = iUCoordX - iSourceXIntersect;
  1013. double dUy = iUCoordY - iSourceYIntersect;
  1014. cout<<"\n Delta X and Y at attractive force case 2 : "<<dVy<<" "
  1015. << dVx;
  1016. double dDist1 = fabs(sqrt((dVx*dVx+dVy* dVy)));
  1017. double dDist2 = fabs(sqrt((dUx*dUx+dUy* dUy)));
  1018. cout<<"\n Distance at attractive force in Inter edges case 2: "<<dDist1;
  1019. if(dDist1 == 0)
  1020. {
  1021. dDist1 = 0.0001;
  1022. }
  1023. if(dDist2 == 0)
  1024. {
  1025. dDist2 = 0.0001;
  1026. }
  1027. // desired length = 50 // force = 0.3
  1028. double dForce1 = INTEREDGES_ATTRACTION_MULTIPLIER *(INTEREDGES_DEFAULT_LENGTH - dDist1)/dDist1 ; //0.3 force multiplier
  1029. double dForce2 = INTEREDGES_ATTRACTION_MULTIPLIER *(INTEREDGES_DEFAULT_LENGTH - dDist2)/dDist2 ; //0.3 force multiplier
  1030. cout<<"\n Force between Case 2 interedges "<<dForce1<<" " <<dForce2;
  1031. if(dDist1 < MINIMUM_INTEREDGE_DISTANCE )
  1032. {
  1033. dDist1 = 0.0001;
  1034. dForce1 = 0;
  1035. }
  1036. if(dDist2 < MINIMUM_INTEREDGE_DISTANCE)
  1037. {
  1038. dDist2 = 0.0001;
  1039. dForce2 = 0;
  1040. }
  1041. double dx1 = dForce1 * dVx;
  1042. double dy1 = dForce1 * dVy;
  1043. double dx2 = dForce2 * dUx;
  1044. double dy2 = dForce2 * dUy;
  1045. double dXDispV = m_bGraphWrapper.getVertXDisp(vTarget,gMaingraph);
  1046. double dYDispV = m_bGraphWrapper.getVertYDisp(vTarget,gMaingraph);
  1047. double dXDispU = 0;
  1048. double dYDispU = 0;
  1049. dXDispU = m_bGraphWrapper.getVertXDisp(vSource,gMaingraph);
  1050. dYDispU = m_bGraphWrapper.getVertYDisp(vSource,gMaingraph);
  1051. dXDispV += dx1;
  1052. dYDispV += dy1;
  1053. dXDispU += dx2;
  1054. dYDispU += dy2;
  1055. cout<<"\n Disp between interedges case 2 "<<dx1<<" " <<dy1;
  1056. cout<<"\n Disp between interedges case 2 "<<dx2<<" " <<dy2;
  1057. m_bGraphWrapper.setVertXDisp(dXDispV,vTarget,gMaingraph);
  1058. m_bGraphWrapper.setVertYDisp(dYDispV,vTarget,gMaingraph);
  1059. m_bGraphWrapper.setVertXDisp(dXDispU,vSource,gMaingraph);
  1060. m_bGraphWrapper.setVertYDisp(dYDispU,vSource,gMaingraph);
  1061. }
  1062. }