From 800968a91dd3aa87e085607c1b3333a0351152d5 Mon Sep 17 00:00:00 2001 From: erg Date: Thu, 10 Feb 2005 23:10:33 +0000 Subject: [PATCH] Add support for 3D output. If dim > 2, neato will look for z values on input and use them as initial z coordinates, assuming a node has a pos attribute. If dim >= 3 and z is declared, neato will output the computed z values. --- lib/neatogen/neatoinit.c | 37 +++++++++++++++++++++++++++++++++++-- lib/neatogen/neatoprocs.h | 1 + lib/neatogen/stuff.c | 9 +++++++-- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/lib/neatogen/neatoinit.c b/lib/neatogen/neatoinit.c index c2ac84db0..1fba9d3b6 100644 --- a/lib/neatogen/neatoinit.c +++ b/lib/neatogen/neatoinit.c @@ -67,6 +67,7 @@ int user_pos(attrsym_t * posptr, attrsym_t * pinptr, node_t * np, int nG) { double *pvec; char *p, c; + double z; if (posptr == NULL) return FALSE; @@ -81,8 +82,19 @@ int user_pos(attrsym_t * posptr, attrsym_t * pinptr, node_t * np, int nG) for (i = 0; i < Ndim; i++) pvec[i] = pvec[i] / PSinputscale; } - if (Ndim > 2) - jitter3d(np, nG); + if (Ndim > 2) { + if (N_z && (p = agxget(np, N_z->index)) && + (sscanf(p,"%lf",&z) == 1)) { + if (PSinputscale > 0.0) { + pvec[2] = z / PSinputscale; + } + else + pvec[2] = z; + jitter_d(np, nG, 3); + } + else + jitter3d(np, nG); + } if ((c == '!') || (pinptr && mapbool(agxget(np, pinptr->index)))) ND_pinned(np) = P_PIN; @@ -1004,6 +1016,24 @@ void neatoLayout(Agraph_t * g, int layoutMode, int layoutModel) kkNeato(g, nG, layoutModel); } +/* addZ; + * If dimension == 3 and z attribute is declared, + * attach z value to nodes if not defined. + */ +static void +addZ (Agraph_t* g) +{ + node_t* n; + char buf[BUFSIZ]; + + if ((Ndim >= 3) && N_z) { + for (n = agfstnode(g); n; n = agnxtnode(g, n)) { + sprintf(buf, "%d", POINTS(ND_pos(n)[2])); + agxset(n, N_z->index, buf); + } + } +} + /* neato_layout: */ void neato_layout(Agraph_t * g) @@ -1011,6 +1041,7 @@ void neato_layout(Agraph_t * g) neato_init_graph(g); if (Nop) { + addZ (g); if (init_nop(g)) { agerr(AGPREV, "as required by the -n flag\n"); exit(1); @@ -1062,6 +1093,7 @@ void neato_layout(Agraph_t * g) free(bp); } compute_bb(g); + addZ (g); spline_edges(g); /* cleanup and remove component subgraphs */ @@ -1073,6 +1105,7 @@ void neato_layout(Agraph_t * g) } else { neatoLayout(g, layoutMode, model); adjustNodes(g); + addZ (g); spline_edges(g); } } diff --git a/lib/neatogen/neatoprocs.h b/lib/neatogen/neatoprocs.h index 71eae17a8..0d949af01 100644 --- a/lib/neatogen/neatoprocs.h +++ b/lib/neatogen/neatoprocs.h @@ -40,6 +40,7 @@ extern "C" { extern void initial_positions(graph_t *, int); extern int init_port(Agnode_t *, Agedge_t *, char *, boolean); extern void jitter3d(Agnode_t *, int); + extern void jitter_d(Agnode_t *, int, int); extern Ppoly_t *makeObstacle(node_t * n, double SEP); extern void makeSelfArcs(path * P, edge_t * e, int stepx); extern void makeSpline(edge_t *, Ppoly_t **, int, boolean); diff --git a/lib/neatogen/stuff.c b/lib/neatogen/stuff.c index 0409a6dfc..77d0391a5 100644 --- a/lib/neatogen/stuff.c +++ b/lib/neatogen/stuff.c @@ -299,13 +299,18 @@ void free_scan_graph(graph_t * g) } } -void jitter3d(node_t * np, int nG) +void jitter_d(node_t * np, int nG, int n) { int k; - for (k = 2; k < Ndim; k++) + for (k = n; k < Ndim; k++) ND_pos(np)[k] = nG * drand48(); } +void jitter3d(node_t * np, int nG) +{ + jitter_d(np, nG, 2); +} + void randompos(node_t * np, int nG) { ND_pos(np)[0] = nG * drand48(); -- 2.40.0