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