| 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 |
|
| 11 |
#include "config.h" |
| 12 |
|
| 13 |
#include "smyrnadefs.h" |
| 14 |
#include "hier.h" |
| 15 |
#include <math.h> |
| 16 |
#include <neatogen/delaunay.h> |
| 17 |
#include <stdbool.h> |
| 18 |
#include <stddef.h> |
| 19 |
#include <util/alloc.h> |
| 20 |
|
| 21 |
void positionAllItems(Hierarchy * hp, focus_t * fs, reposition_t * parms) |
| 22 |
{ |
| 23 |
int interval = 20; |
| 24 |
size_t counter = 0; // no. of active nodes |
| 25 |
double *x_coords = gv_calloc(hp->nvtxs[0], sizeof(double)); |
| 26 |
double *y_coords = gv_calloc(hp->nvtxs[0], sizeof(double)); |
| 27 |
int max_level = hp->nlevels - 1; // coarsest level |
| 28 |
double width = parms->width; |
| 29 |
double height = parms->height; |
| 30 |
double distortion = parms->distortion; |
| 31 |
|
| 32 |
/* get all logical coordinates of active nodes */ |
| 33 |
for (int i = 0; i < hp->nvtxs[max_level]; i++) { |
| 34 |
counter = |
| 35 |
extract_active_logical_coords(hp, i, max_level, x_coords, |
| 36 |
y_coords, counter); |
| 37 |
} |
| 38 |
|
| 39 |
/* distort logical coordinates in order to get uniform density |
| 40 |
* (equivalent to concentrating on the focus area) |
| 41 |
*/ |
| 42 |
if (fs->num_foci != 0) { |
| 43 |
rescale_layout_polar(x_coords, y_coords, fs->x_foci, |
| 44 |
fs->y_foci, fs->num_foci, counter, |
| 45 |
interval, width, height, distortion); |
| 46 |
} |
| 47 |
|
| 48 |
/* Update the final physical coordinates of the active nodes */ |
| 49 |
for (int count = 0, i = 0; i < hp->nvtxs[max_level]; i++) { |
| 50 |
count = |
| 51 |
set_active_physical_coords(hp, i, max_level, x_coords, |
| 52 |
y_coords, count); |
| 53 |
} |
| 54 |
|
| 55 |
free(x_coords); |
| 56 |
free(y_coords); |
| 57 |
} |
| 58 |
|
| 59 |
#ifdef DEBUG |
| 60 |
static void dumpG(int nn, v_data * graph) |
| 61 |
{ |
| 62 |
int i, j; |
| 63 |
for (i = 0; i < nn; i++) { |
| 64 |
fprintf(stderr, "[%d]", i); |
| 65 |
for (j = 1; j < graph->nedges; j++) |
| 66 |
fprintf(stderr, " %d", graph->edges[j]); |
| 67 |
fprintf(stderr, "\n"); |
| 68 |
graph++; |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
static void dumpEG(int nn, ex_vtx_data * graph) |
| 73 |
{ |
| 74 |
int i, j; |
| 75 |
for (i = 0; i < nn; i++) { |
| 76 |
fprintf(stderr, "[%d](%d,%d,%d)(%f,%f)", i, graph->size, |
| 77 |
graph->active_level, graph->globalIndex, graph->x_coord, |
| 78 |
graph->y_coord); |
| 79 |
for (j = 1; j < graph->nedges; j++) |
| 80 |
fprintf(stderr, " %d", graph->edges[j]); |
| 81 |
fprintf(stderr, "\n"); |
| 82 |
graph++; |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
static void dumpHier(Hierarchy * hier) |
| 87 |
{ |
| 88 |
int i; |
| 89 |
|
| 90 |
for (i = 0; i < hier->nlevels; i++) { |
| 91 |
fprintf(stderr, "level [%d] %d %d \n", i, hier->nvtxs[i], |
| 92 |
hier->nedges[i]); |
| 93 |
fprintf(stderr, "graph\n"); |
| 94 |
dumpG(hier->nvtxs[i], hier->graphs[0]); |
| 95 |
fprintf(stderr, "geom_graph\n"); |
| 96 |
dumpEG(hier->nvtxs[i], hier->geom_graphs[0]); |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
#endif |
| 101 |
|
| 102 |
Hierarchy *makeHier(int nn, int ne, v_data *graph, double *x_coords, |
| 103 |
double *y_coords, bool dist2_limit) { |
| 104 |
v_data *delaunay; |
| 105 |
ex_vtx_data *geom_graph; |
| 106 |
int ngeom_edges; |
| 107 |
Hierarchy *hp; |
| 108 |
int i; |
| 109 |
|
| 110 |
delaunay = UG_graph(x_coords, y_coords, nn); |
| 111 |
|
| 112 |
ngeom_edges = |
| 113 |
init_ex_graph(delaunay, graph, nn, x_coords, y_coords, |
| 114 |
&geom_graph); |
| 115 |
free(delaunay[0].edges); |
| 116 |
free(delaunay); |
| 117 |
|
| 118 |
hp = create_hierarchy(graph, nn, ne, geom_graph, ngeom_edges, dist2_limit); |
| 119 |
free(geom_graph[0].edges); |
| 120 |
free(geom_graph); |
| 121 |
|
| 122 |
init_active_level(hp, 0); |
| 123 |
geom_graph = hp->geom_graphs[0]; |
| 124 |
for (i = 0; i < hp->nvtxs[0]; i++) { |
| 125 |
geom_graph[i].physical_x_coord = (float) x_coords[i]; |
| 126 |
geom_graph[i].physical_y_coord = (float) y_coords[i]; |
| 127 |
} |
| 128 |
|
| 129 |
return hp; |
| 130 |
} |
| 131 |
|
| 132 |
focus_t *initFocus(int ncnt) |
| 133 |
{ |
| 134 |
focus_t *fs = gv_alloc(sizeof(focus_t)); |
| 135 |
fs->num_foci = 0; |
| 136 |
fs->foci_nodes = gv_calloc(ncnt, sizeof(int)); |
| 137 |
fs->x_foci = gv_calloc(ncnt, sizeof(double)); |
| 138 |
fs->y_foci = gv_calloc(ncnt, sizeof(double)); |
| 139 |
return fs; |
| 140 |
} |