Graphviz 15.1.0~dev.20260613.0511
Loading...
Searching...
No Matches
fdpinit.c
Go to the documentation of this file.
1
6/*************************************************************************
7 * Copyright (c) 2011 AT&T Intellectual Property
8 * All rights reserved. This program and the accompanying materials
9 * are made available under the terms of the Eclipse Public License v2.0
10 * which accompanies this distribution, and is available at
11 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
12 *
13 * Contributors: Details at https://graphviz.org
14 *************************************************************************/
15
16#include "config.h"
17
18/* fdpinit.c:
19 * Written by Emden R. Gansner
20 *
21 * Mostly boilerplate initialization and cleanup code.
22 */
23
24/* uses PRIVATE interface */
25#define FDP_PRIVATE 1
26
27#include <fdpgen/tlayout.h>
28#include <neatogen/neatoprocs.h>
29#include <stdbool.h>
30#include <util/agxbuf.h>
31#include <util/alloc.h>
32
33static void initialPositions(graph_t *g) {
34 int i;
35 node_t *np;
36 attrsym_t *possym;
37 attrsym_t *pinsym;
38 double *pvec;
39 char *p;
40 char c;
41
42 possym = agattr_text(g, AGNODE, "pos", NULL);
43 if (!possym)
44 return;
45 pinsym = agattr_text(g, AGNODE, "pin", NULL);
46 for (i = 0; (np = GD_neato_nlist(g)[i]); i++) {
47 p = agxget(np, possym);
48 if (p[0]) {
49 pvec = ND_pos(np);
50 c = '\0';
51 if (sscanf(p, "%lf,%lf%c", pvec, pvec + 1, &c) >= 2) {
52 if (PSinputscale > 0.0) {
53 for (int j = 0; j < NDIM; j++)
54 pvec[j] = pvec[j] / PSinputscale;
55 }
56 ND_pinned(np) = P_SET;
57 if (c == '!' || (pinsym && mapbool(agxget(np, pinsym))))
58 ND_pinned(np) = P_PIN;
59 } else
60 fprintf(stderr, "Warning: node %s, position %s, expected two floats\n",
61 agnameof(np), p);
62 }
63 }
64}
65
66/* init_edge:
67 */
68static void init_edge(edge_t *e, attrsym_t *E_len) {
69 agbindrec(e, "Agedgeinfo_t", sizeof(Agedgeinfo_t), true); // node custom data
70 ED_factor(e) = late_double(e, E_weight, 1.0, 0.0);
71 ED_dist(e) = late_double(e, E_len, fdp_parms->K, 0.0);
72
74}
75
76static void init_node(node_t *n) {
78 ND_pos(n) = gv_calloc(GD_ndim(agraphof(n)), sizeof(double));
80}
81
83 attrsym_t *E_len;
84 node_t *n;
85 edge_t *e;
86 int nn;
87 int i;
88
89 aginit(g, AGNODE, "Agnodeinfo_t", sizeof(Agnodeinfo_t), true);
91
92 /* Get node count after processClusterEdges(), as this function may
93 * add new nodes.
94 */
95 nn = agnnodes(g);
96 GD_neato_nlist(g) = gv_calloc(nn + 1, sizeof(node_t *));
97
98 for (i = 0, n = agfstnode(g); n; n = agnxtnode(g, n)) {
99 init_node(n);
100 GD_neato_nlist(g)[i] = n;
101 ND_id(n) = i++;
102 }
103
104 E_len = agattr_text(g, AGEDGE, "len", NULL);
105 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
106 for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
107 init_edge(e, E_len);
108 }
109 }
111}
112
113static void cleanup_subgs(graph_t *g) {
114 graph_t *subg;
115 int i;
116
117 for (i = 1; i <= GD_n_cluster(g); i++) {
118 subg = GD_clust(g)[i];
119 free_label(GD_label(subg));
120 if (GD_alg(subg)) {
121 free(PORTS(subg));
122 free(GD_alg(subg));
123 }
124 cleanup_subgs(subg);
125 }
126 free(GD_clust(g));
127}
128
129static void fdp_cleanup_graph(graph_t *g) {
130 cleanup_subgs(g);
132 free(GD_alg(g));
133}
134
136 node_t *n;
137 edge_t *e;
138
139 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
140 for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
142 }
144 }
146}
147
Dynamically expanding string buffers.
Memory allocation wrappers that exit on failure.
static void * gv_calloc(size_t nmemb, size_t size)
Definition alloc.h:26
void processClusterEdges(graph_t *g)
Definition utils.c:930
bool mapbool(const char *p)
Definition utils.c:341
void common_init_node(node_t *n)
Definition utils.c:427
double late_double(void *obj, attrsym_t *attr, double defaultValue, double minimum)
Definition utils.c:55
void common_init_edge(edge_t *e)
Definition utils.c:509
void gv_nodesize(node_t *n, bool flip)
Definition utils.c:1536
#define P_PIN
Definition const.h:249
#define P_SET
Definition const.h:247
void fdp_cleanup(graph_t *g)
Definition fdpinit.c:135
static void fdp_cleanup_graph(graph_t *g)
Definition fdpinit.c:129
static void cleanup_subgs(graph_t *g)
Definition fdpinit.c:113
static void init_node(node_t *n)
Definition fdpinit.c:76
static void init_edge(edge_t *e, attrsym_t *E_len)
Definition fdpinit.c:68
void fdp_init_node_edge(graph_t *g)
Definition fdpinit.c:82
static void initialPositions(graph_t *g)
Definition fdpinit.c:33
struct fdpParms_s * fdp_parms
Definition globals.c:38
Agsym_t * E_weight
Definition globals.h:83
double PSinputscale
Definition globals.h:58
void free(void *)
node NULL
Definition grammar.y:181
int agnnodes(Agraph_t *g)
Definition graph.c:159
Agsym_t * agattr_text(Agraph_t *g, int kind, char *name, const char *value)
creates or looks up text attributes of a graph
Definition attr.c:333
char * agxget(void *obj, Agsym_t *sym)
Definition attr.c:457
#define ED_dist(e)
Definition types.h:602
Agedge_t * agfstout(Agraph_t *g, Agnode_t *n)
Definition edge.c:28
#define ED_factor(e)
Definition types.h:585
Agedge_t * agnxtout(Agraph_t *g, Agedge_t *e)
Definition edge.c:43
#define GD_clust(g)
Definition types.h:360
#define GD_alg(g)
Definition types.h:358
#define GD_n_cluster(g)
Definition types.h:389
#define GD_ndim(g)
Definition types.h:390
#define GD_label(g)
Definition types.h:374
#define GD_flip(g)
Definition types.h:378
#define GD_neato_nlist(g)
Definition types.h:392
Agnode_t * agnxtnode(Agraph_t *g, Agnode_t *n)
Definition node.c:50
Agnode_t * agfstnode(Agraph_t *g)
Definition node.c:43
#define ND_pinned(n)
Definition types.h:519
#define ND_pos(n)
Definition types.h:520
Agraph_t * agraphof(void *obj)
Definition obj.c:187
char * agnameof(void *)
returns a string descriptor for the object.
Definition id.c:145
@ AGEDGE
Definition cgraph.h:207
@ AGNODE
Definition cgraph.h:207
void aginit(Agraph_t *g, int kind, const char *rec_name, int rec_size, int move_to_front)
attach new records to objects of specified kind
Definition rec.c:172
void * agbindrec(void *obj, const char *name, unsigned int recsize, int move_to_front)
attaches a new record of the given size to the object
Definition rec.c:91
void free_label(textlabel_t *p)
Definition labels.c:204
#define ND_id(n)
Definition mm2gv.c:41
void gv_cleanup_edge(Agedge_t *e)
Definition utils.c:1513
void gv_cleanup_node(Agnode_t *n)
Definition utils.c:1525
graph or subgraph
Definition cgraph.h:424
string attribute descriptor symbol in Agattr_s.dict
Definition cgraph.h:640
double K
spring constant; ideal distance
Definition fdp.h:102