hier.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*************************************************************************
  2. * Copyright (c) 2011 AT&T Intellectual Property
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * https://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors: Details at https://graphviz.org
  9. *************************************************************************/
  10. #include "smyrnadefs.h"
  11. #include "hier.h"
  12. #include <math.h>
  13. #include <neatogen/delaunay.h>
  14. #include <stddef.h>
  15. #include <util/alloc.h>
  16. void positionAllItems(Hierarchy * hp, focus_t * fs, reposition_t * parms)
  17. {
  18. int interval = 20;
  19. size_t counter = 0; // no. of active nodes
  20. double *x_coords = gv_calloc(hp->nvtxs[0], sizeof(double));
  21. double *y_coords = gv_calloc(hp->nvtxs[0], sizeof(double));
  22. int max_level = hp->nlevels - 1; // coarsest level
  23. double width = parms->width;
  24. double height = parms->height;
  25. double distortion = parms->distortion;
  26. /* get all logical coordinates of active nodes */
  27. for (int i = 0; i < hp->nvtxs[max_level]; i++) {
  28. counter =
  29. extract_active_logical_coords(hp, i, max_level, x_coords,
  30. y_coords, counter);
  31. }
  32. /* distort logical coordinates in order to get uniform density
  33. * (equivalent to concentrating on the focus area)
  34. */
  35. if (fs->num_foci != 0) {
  36. rescale_layout_polar(x_coords, y_coords, fs->x_foci,
  37. fs->y_foci, fs->num_foci, counter,
  38. interval, width, height, distortion);
  39. }
  40. /* Update the final physical coordinates of the active nodes */
  41. for (int count = 0, i = 0; i < hp->nvtxs[max_level]; i++) {
  42. count =
  43. set_active_physical_coords(hp, i, max_level, x_coords,
  44. y_coords, count);
  45. }
  46. free(x_coords);
  47. free(y_coords);
  48. }
  49. #ifdef DEBUG
  50. static void dumpG(int nn, v_data * graph)
  51. {
  52. int i, j;
  53. for (i = 0; i < nn; i++) {
  54. fprintf(stderr, "[%d]", i);
  55. for (j = 1; j < graph->nedges; j++)
  56. fprintf(stderr, " %d", graph->edges[j]);
  57. fprintf(stderr, "\n");
  58. graph++;
  59. }
  60. }
  61. static void dumpEG(int nn, ex_vtx_data * graph)
  62. {
  63. int i, j;
  64. for (i = 0; i < nn; i++) {
  65. fprintf(stderr, "[%d](%d,%d,%d)(%f,%f)", i, graph->size,
  66. graph->active_level, graph->globalIndex, graph->x_coord,
  67. graph->y_coord);
  68. for (j = 1; j < graph->nedges; j++)
  69. fprintf(stderr, " %d", graph->edges[j]);
  70. fprintf(stderr, "\n");
  71. graph++;
  72. }
  73. }
  74. static void dumpHier(Hierarchy * hier)
  75. {
  76. int i;
  77. for (i = 0; i < hier->nlevels; i++) {
  78. fprintf(stderr, "level [%d] %d %d \n", i, hier->nvtxs[i],
  79. hier->nedges[i]);
  80. fprintf(stderr, "graph\n");
  81. dumpG(hier->nvtxs[i], hier->graphs[0]);
  82. fprintf(stderr, "geom_graph\n");
  83. dumpEG(hier->nvtxs[i], hier->geom_graphs[0]);
  84. }
  85. }
  86. #endif
  87. Hierarchy *makeHier(int nn, int ne, v_data * graph, double *x_coords,
  88. double *y_coords, hierparms_t * parms)
  89. {
  90. v_data *delaunay;
  91. ex_vtx_data *geom_graph;
  92. int ngeom_edges;
  93. Hierarchy *hp;
  94. int i;
  95. delaunay = UG_graph(x_coords, y_coords, nn);
  96. ngeom_edges =
  97. init_ex_graph(delaunay, graph, nn, x_coords, y_coords,
  98. &geom_graph);
  99. free(delaunay[0].edges);
  100. free(delaunay);
  101. hp = create_hierarchy(graph, nn, ne, geom_graph, ngeom_edges, parms);
  102. free(geom_graph[0].edges);
  103. free(geom_graph);
  104. init_active_level(hp, 0);
  105. geom_graph = hp->geom_graphs[0];
  106. for (i = 0; i < hp->nvtxs[0]; i++) {
  107. geom_graph[i].physical_x_coord = (float) x_coords[i];
  108. geom_graph[i].physical_y_coord = (float) y_coords[i];
  109. }
  110. return hp;
  111. }
  112. focus_t *initFocus(int ncnt)
  113. {
  114. focus_t *fs = gv_alloc(sizeof(focus_t));
  115. fs->num_foci = 0;
  116. fs->foci_nodes = gv_calloc(ncnt, sizeof(int));
  117. fs->x_foci = gv_calloc(ncnt, sizeof(double));
  118. fs->y_foci = gv_calloc(ncnt, sizeof(double));
  119. return fs;
  120. }