Graphviz 14.1.2~dev.20260119.0928
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 "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
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
60static 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
72static 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
86static 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
102Hierarchy *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
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}
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:592
void free(void *)
Agraph_t * graph(char *name)
Definition gv.cpp:34
Hierarchy * makeHier(int nn, int ne, v_data *graph, double *x_coords, double *y_coords, bool dist2_limit)
Definition hier.c:102
void positionAllItems(Hierarchy *hp, focus_t *fs, reposition_t *parms)
Definition hier.c:21
focus_t * initFocus(int ncnt)
Definition hier.c:132
size_t extract_active_logical_coords(Hierarchy *hierarchy, int node, int level, double *x_coords, double *y_coords, size_t counter)
Definition hierarchy.c:990
Hierarchy * create_hierarchy(v_data *graph, int nvtxs, int nedges, ex_vtx_data *geom_graph, int ngeom_edges, bool dist2_limit)
Definition hierarchy.c:668
int set_active_physical_coords(Hierarchy *hierarchy, int node, int level, double *x_coords, double *y_coords, int counter)
Definition hierarchy.c:1024
void init_active_level(Hierarchy *hierarchy, int level)
Definition hierarchy.c:1116
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:937
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:41
int * nvtxs
Definition hierarchy.h:43
int * nedges
Definition hierarchy.h:44
ex_vtx_data ** geom_graphs
Definition hierarchy.h:42
int nlevels
Definition hierarchy.h:40
float physical_y_coord
Definition hierarchy.h:30
float physical_x_coord
Definition hierarchy.h:29
Definition hier.h:16
int * foci_nodes
Definition hier.h:18
int num_foci
Definition hier.h:17
double * y_foci
Definition hier.h:20
double * x_foci
Definition hier.h:19
static parms_t parms
Definition tlayout.c:77