Graphviz 12.0.1~dev.20240715.2254
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 v1.0
10 * which accompanies this distribution, and is available at
11 * https://www.eclipse.org/legal/epl-v10.html
12 *
13 * Contributors: Details at https://graphviz.org
14 *************************************************************************/
15
16
17/* fdpinit.c:
18 * Written by Emden R. Gansner
19 *
20 * Mostly boilerplate initialization and cleanup code.
21 */
22
23/* uses PRIVATE interface */
24#define FDP_PRIVATE 1
25
26#include <cgraph/alloc.h>
27#include <fdpgen/tlayout.h>
28#include <neatogen/neatoprocs.h>
29#include <cgraph/agxbuf.h>
30#include <stdbool.h>
31
32static void initialPositions(graph_t * g)
33{
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(g,AGNODE, "pos", NULL);
43 if (!possym)
44 return;
45 pinsym = agattr(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 int j;
54 for (j = 0; j < NDIM; j++)
55 pvec[j] = pvec[j] / PSinputscale;
56 }
57 ND_pinned(np) = P_SET;
58 if (c == '!'
59 || (pinsym && mapbool(agxget(np, pinsym))))
60 ND_pinned(np) = P_PIN;
61 } else
62 fprintf(stderr,
63 "Warning: node %s, position %s, expected two floats\n",
64 agnameof(np), p);
65 }
66 }
67}
68
69/* init_edge:
70 */
71static void init_edge(edge_t * e, attrsym_t * E_len)
72{
73 agbindrec(e, "Agedgeinfo_t", sizeof(Agedgeinfo_t), true); //node custom data
74 ED_factor(e) = late_double(e, E_weight, 1.0, 0.0);
75 ED_dist(e) = late_double(e, E_len, fdp_parms->K, 0.0);
76
78}
79
80static void init_node(node_t * n)
81{
83 ND_pos(n) = gv_calloc(GD_ndim(agraphof(n)), sizeof(double));
85}
86
88{
89 attrsym_t *E_len;
90 node_t *n;
91 edge_t *e;
92 int nn;
93 int i;
94
95 aginit(g, AGNODE, "Agnodeinfo_t", sizeof(Agnodeinfo_t), true);
97
98 /* Get node count after processClusterEdges(), as this function may
99 * add new nodes.
100 */
101 nn = agnnodes(g);
102 GD_neato_nlist(g) = gv_calloc(nn + 1, sizeof(node_t*));
103
104 for (i = 0, n = agfstnode(g); n; n = agnxtnode(g, n)) {
105 init_node (n);
106 GD_neato_nlist(g)[i] = n;
107 ND_id(n) = i++;
108 }
109
110 E_len = agattr(g,AGEDGE, "len", NULL);
111 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
112 for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
113 init_edge(e, E_len);
114 }
115 }
117}
118
119static void cleanup_subgs(graph_t * g)
120{
121 graph_t *subg;
122 int i;
123
124 for (i = 1; i <= GD_n_cluster(g); i++) {
125 subg = GD_clust(g)[i];
126 free_label(GD_label(subg));
127 if (GD_alg(subg)) {
128 free(PORTS(subg));
129 free(GD_alg(subg));
130 }
131 cleanup_subgs(subg);
132 }
133 free (GD_clust(g));
134}
135
137{
138 cleanup_subgs(g);
140 free(GD_alg(g));
141}
142
144{
145 node_t *n;
146 edge_t *e;
147
148 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
149 for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
151 }
153 }
155}
156
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:936
bool mapbool(const char *p)
Definition utils.c:336
void common_init_node(node_t *n)
Definition utils.c:422
double late_double(void *obj, attrsym_t *attr, double defaultValue, double minimum)
Definition utils.c:48
void common_init_edge(edge_t *e)
Definition utils.c:505
void gv_nodesize(node_t *n, bool flip)
Definition utils.c:1556
#define P_PIN
Definition const.h:263
#define P_SET
Definition const.h:261
void fdp_cleanup(graph_t *g)
Definition fdpinit.c:143
static void fdp_cleanup_graph(graph_t *g)
Definition fdpinit.c:136
static void cleanup_subgs(graph_t *g)
Definition fdpinit.c:119
static void init_node(node_t *n)
Definition fdpinit.c:80
static void init_edge(edge_t *e, attrsym_t *E_len)
Definition fdpinit.c:71
void fdp_init_node_edge(graph_t *g)
Definition fdpinit.c:87
static void initialPositions(graph_t *g)
Definition fdpinit.c:32
struct fdpParms_s * fdp_parms
Definition globals.c:33
Agsym_t * E_weight
Definition globals.h:91
double PSinputscale
Definition globals.h:58
void free(void *)
node NULL
Definition grammar.y:149
int agnnodes(Agraph_t *g)
Definition graph.c:158
Agsym_t * agattr(Agraph_t *g, int kind, char *name, const char *value)
creates or looks up attributes of a graph
Definition attr.c:341
char * agxget(void *obj, Agsym_t *sym)
Definition attr.c:458
#define ED_dist(e)
Definition types.h:602
Agedge_t * agfstout(Agraph_t *g, Agnode_t *n)
Definition edge.c:23
#define ED_factor(e)
Definition types.h:585
Agedge_t * agnxtout(Agraph_t *g, Agedge_t *e)
Definition edge.c:38
#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:47
Agnode_t * agfstnode(Agraph_t *g)
Definition node.c:40
#define ND_pinned(n)
Definition types.h:519
#define ND_pos(n)
Definition types.h:520
Agraph_t * agraphof(void *obj)
Definition obj.c:184
char * agnameof(void *)
returns a string descriptor for the object.
Definition id.c:158
@ 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:169
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:88
void free_label(textlabel_t *p)
Definition labels.c:199
#define ND_id(n)
Definition mm2gv.c:39
void gv_cleanup_edge(Agedge_t *e)
Definition utils.c:1533
void gv_cleanup_node(Agnode_t *n)
Definition utils.c:1545
graph or subgraph
Definition cgraph.h:425
string attribute descriptor symbol in Agattr_s.dict
Definition cgraph.h:639
double K
Definition fdp.h:102