Graphviz 16.1.3~dev.20261128.0221
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 v2.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.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#include <util/list.h>
21
23{
24 int interval = 20;
25 size_t counter = 0; // no. of active nodes
26 double *x_coords = gv_calloc(LIST_GET(&hp->nvtxs, 0), sizeof(double));
27 double *y_coords = gv_calloc(LIST_GET(&hp->nvtxs, 0), sizeof(double));
28 int max_level = hp->nlevels - 1; // coarsest level
29 double width = parms->width;
30 double height = parms->height;
31 double distortion = parms->distortion;
32
33 /* get all logical coordinates of active nodes */
34 for (int i = 0; i < LIST_GET(&hp->nvtxs, (size_t)max_level); i++) {
35 counter =
36 extract_active_logical_coords(hp, i, max_level, x_coords,
37 y_coords, counter);
38 }
39
40 /* distort logical coordinates in order to get uniform density
41 * (equivalent to concentrating on the focus area)
42 */
43 if (fs->num_foci != 0) {
44 rescale_layout_polar(x_coords, y_coords, fs->x_foci,
45 fs->y_foci, fs->num_foci, counter,
46 interval, width, height, distortion);
47 }
48
49 /* Update the final physical coordinates of the active nodes */
50 for (int count = 0, i = 0; i < LIST_GET(&hp->nvtxs, (size_t)max_level); i++) {
51 count =
52 set_active_physical_coords(hp, i, max_level, x_coords,
53 y_coords, count);
54 }
55
56 free(x_coords);
57 free(y_coords);
58}
59
60Hierarchy *makeHier(int nn, int ne, v_data *graph, double *x_coords,
61 double *y_coords, bool dist2_limit) {
62 v_data *delaunay;
63 ex_vtx_data *geom_graph;
64 int ngeom_edges;
65 Hierarchy *hp;
66 int i;
67
68 delaunay = UG_graph(x_coords, y_coords, nn);
69
70 ngeom_edges =
71 init_ex_graph(delaunay, graph, nn, x_coords, y_coords,
72 &geom_graph);
73 free(delaunay[0].edges);
74 free(delaunay);
75
76 hp = create_hierarchy(graph, nn, ne, geom_graph, ngeom_edges, dist2_limit);
77 free(geom_graph[0].edges);
78 free(geom_graph);
79
81 geom_graph = LIST_GET(&hp->geom_graphs, 0);
82 for (i = 0; i < LIST_GET(&hp->nvtxs, 0); i++) {
83 geom_graph[i].physical_x_coord = (float) x_coords[i];
84 geom_graph[i].physical_y_coord = (float) y_coords[i];
85 }
86
87 return hp;
88}
89
90focus_t *initFocus(size_t ncnt) {
91 focus_t *fs = gv_alloc(sizeof(focus_t));
92 fs->num_foci = 0;
93 fs->foci_nodes = gv_calloc(ncnt, sizeof(int));
94 fs->x_foci = gv_calloc(ncnt, sizeof(double));
95 fs->y_foci = gv_calloc(ncnt, sizeof(double));
96 return fs;
97}
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:578
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:60
void positionAllItems(Hierarchy *hp, focus_t *fs, reposition_t *parms)
Definition hier.c:22
focus_t * initFocus(size_t ncnt)
Definition hier.c:90
void init_active_level(Hierarchy *hierarchy)
Definition hierarchy.c:1075
size_t extract_active_logical_coords(Hierarchy *hierarchy, int node, int level, double *x_coords, double *y_coords, size_t counter)
Definition hierarchy.c:968
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:1002
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:915
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)
type-generic dynamically expanding list
#define LIST_GET(list, index)
Definition list.h:197
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:17
int * foci_nodes
Definition hier.h:19
int num_foci
Definition hier.h:18
double * y_foci
Definition hier.h:21
double * x_foci
Definition hier.h:20
static parms_t parms
Definition tlayout.c:77