Graphviz 14.1.2~dev.20260119.0928
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#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{
35 int i;
36 node_t *np;
37 attrsym_t *possym;
38 attrsym_t *pinsym;
39 double *pvec;
40 char *p;
41 char c;
42
43 possym = agattr_text(g,AGNODE, "pos", NULL);
44 if (!possym)
45 return;
46 pinsym = agattr_text(g,AGNODE, "pin", NULL);
47 for (i = 0; (np = GD_neato_nlist(g)[i]); i++) {
48 p = agxget(np, possym);
49 if (p[0]) {
50 pvec = ND_pos(np);
51 c = '\0';
52 if (sscanf(p, "%lf,%lf%c", pvec, pvec + 1, &c) >= 2) {
53 if (PSinputscale > 0.0) {
54 int j;
55 for (j = 0; j < NDIM; j++)
56 pvec[j] = pvec[j] / PSinputscale;
57 }
58 ND_pinned(np) = P_SET;
59 if (c == '!'
60 || (pinsym && mapbool(agxget(np, pinsym))))
61 ND_pinned(np) = P_PIN;
62 } else
63 fprintf(stderr,
64 "Warning: node %s, position %s, expected two floats\n",
65 agnameof(np), p);
66 }
67 }
68}
69
70/* init_edge:
71 */
72static void init_edge(edge_t * e, attrsym_t * E_len)
73{
74 agbindrec(e, "Agedgeinfo_t", sizeof(Agedgeinfo_t), true); //node custom data
75 ED_factor(e) = late_double(e, E_weight, 1.0, 0.0);
76 ED_dist(e) = late_double(e, E_len, fdp_parms->K, 0.0);
77
79}
80
81static void init_node(node_t * n)
82{
84 ND_pos(n) = gv_calloc(GD_ndim(agraphof(n)), sizeof(double));
86}
87
89{
90 attrsym_t *E_len;
91 node_t *n;
92 edge_t *e;
93 int nn;
94 int i;
95
96 aginit(g, AGNODE, "Agnodeinfo_t", sizeof(Agnodeinfo_t), true);
98
99 /* Get node count after processClusterEdges(), as this function may
100 * add new nodes.
101 */
102 nn = agnnodes(g);
103 GD_neato_nlist(g) = gv_calloc(nn + 1, sizeof(node_t*));
104
105 for (i = 0, n = agfstnode(g); n; n = agnxtnode(g, n)) {
106 init_node (n);
107 GD_neato_nlist(g)[i] = n;
108 ND_id(n) = i++;
109 }
110
111 E_len = agattr_text(g,AGEDGE, "len", NULL);
112 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
113 for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
114 init_edge(e, E_len);
115 }
116 }
118}
119
120static void cleanup_subgs(graph_t * g)
121{
122 graph_t *subg;
123 int i;
124
125 for (i = 1; i <= GD_n_cluster(g); i++) {
126 subg = GD_clust(g)[i];
127 free_label(GD_label(subg));
128 if (GD_alg(subg)) {
129 free(PORTS(subg));
130 free(GD_alg(subg));
131 }
132 cleanup_subgs(subg);
133 }
134 free (GD_clust(g));
135}
136
138{
139 cleanup_subgs(g);
141 free(GD_alg(g));
142}
143
145{
146 node_t *n;
147 edge_t *e;
148
149 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
150 for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
152 }
154 }
156}
157
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:54
void common_init_edge(edge_t *e)
Definition utils.c:509
void gv_nodesize(node_t *n, bool flip)
Definition utils.c:1535
#define P_PIN
Definition const.h:249
#define P_SET
Definition const.h:247
void fdp_cleanup(graph_t *g)
Definition fdpinit.c:144
static void fdp_cleanup_graph(graph_t *g)
Definition fdpinit.c:137
static void cleanup_subgs(graph_t *g)
Definition fdpinit.c:120
static void init_node(node_t *n)
Definition fdpinit.c:81
static void init_edge(edge_t *e, attrsym_t *E_len)
Definition fdpinit.c:72
void fdp_init_node_edge(graph_t *g)
Definition fdpinit.c:88
static void initialPositions(graph_t *g)
Definition fdpinit.c:33
struct fdpParms_s * fdp_parms
Definition globals.c:36
Agsym_t * E_weight
Definition globals.h:82
double PSinputscale
Definition globals.h:56
void free(void *)
node NULL
Definition grammar.y:181
int agnnodes(Agraph_t *g)
Definition graph.c:157
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:336
char * agxget(void *obj, Agsym_t *sym)
Definition attr.c:460
#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:1512
void gv_cleanup_node(Agnode_t *n)
Definition utils.c:1524
graph or subgraph
Definition cgraph.h:424
string attribute descriptor symbol in Agattr_s.dict
Definition cgraph.h:640
double K
Definition fdp.h:102