Graphviz 13.0.0~dev.20250121.0651
Loading...
Searching...
No Matches
topfisheyeview.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 v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10#include "topfisheyeview.h"
11#include <math.h>
12#include "viewport.h"
13#include "viewportcamera.h"
14#include "draw.h"
15#include "smyrna_utils.h"
16
17#include <assert.h>
18#include "hier.h"
19#include "topfisheyeview.h"
20#include <string.h>
21#include <common/color.h>
22#include <common/colorprocs.h>
23#include <util/alloc.h>
24
25static int get_temp_coords(topview * t, int level, int v, double *coord_x,
26 double *coord_y);
27
28static void color_interpolation(glCompColor srcColor, glCompColor tarColor,
29 glCompColor * color, int levelcount,
30 int level)
31{
32 if (levelcount <= 0)
33 return;
34
35
36 color->R =
37 ((float) level * tarColor.R - (float) level * srcColor.R +
38 (float) levelcount * srcColor.R) / (float) levelcount;
39 color->G =
40 ((float) level * tarColor.G - (float) level * srcColor.G +
41 (float) levelcount * srcColor.G) / (float) levelcount;
42 color->B =
43 ((float) level * tarColor.B - (float) level * srcColor.B +
44 (float) levelcount * srcColor.B) / (float) levelcount;
45}
46
47static v_data *makeGraph(Agraph_t* gg, int *nedges)
48{
49 int i;
50 int ne = agnedges(gg);
51 int nv = agnnodes(gg);
52 v_data *graph = gv_calloc(nv, sizeof(v_data));
53 int *edges = gv_calloc(2 * ne + nv, sizeof(int)); /* reserve space for self loops */
54 float *ewgts = gv_calloc(2 * ne + nv, sizeof(float));
55 Agnode_t *np;
56 Agedge_t *ep;
57 Agraph_t *g = NULL;
58 int i_nedges;
59 ne = 0;
60 i=0;
61 for (np = agfstnode(gg); np; np = agnxtnode(gg, np))
62 {
63 graph[i].edges = edges++; /* reserve space for the self loop */
64 graph[i].ewgts = ewgts++;
65#ifdef STYLES
66 graph[i].styles = NULL;
67#endif
68 i_nedges = 1; /* one for the self */
69
70 if (!g)
71 g = agraphof(np);
72 for (ep = agfstedge(g, np); ep; ep = agnxtedge(g, ep, np))
73 {
74 Agnode_t *vp;
75 Agnode_t *tp = agtail(ep);
76 Agnode_t *hp = aghead(ep);
77 assert(hp != tp);
78 /* FIX: handle multiedges */
79 vp = tp == np ? hp : tp;
80 ne++;
81 i_nedges++;
82 *edges++ = ND_TVref(vp);
83 *ewgts++ = 1;
84
85 }
86
87 graph[i].nedges = i_nedges;
88 graph[i].edges[0] = i;
89 graph[i].ewgts[0] = 1 - i_nedges;
90 i++;
91 }
92 ne /= 2; /* each edge counted twice */
93 *nedges = ne;
94 return graph;
95}
96
98{
99 int level, v;
100 Hierarchy *hp = t->fisheyeParams.h;
101 for (level = 0; level < hp->nlevels; level++) {
102 for (v = 0; v < hp->nvtxs[level]; v++) {
103 ex_vtx_data *gg = hp->geom_graphs[level];
106 gg[v].old_active_level = gg[v].active_level;
107 }
108 }
109
110}
111
112/* To use:
113 * double* x_coords; // initial x coordinates
114 * double* y_coords; // initial y coordinates
115 * focus_t* fs;
116 * int ne;
117 * v_data* graph = makeGraph (topview*, &ne);
118 * hierarchy = makeHier(topview->NodeCount, ne, graph, x_coords, y_coords);
119 * freeGraph (graph);
120 * fs = initFocus (topview->Nodecount); // create focus set
121 */
123{
124 double *x_coords = gv_calloc(t->Nodecount, sizeof(double)); // initial x coordinates
125 double *y_coords = gv_calloc(t->Nodecount, sizeof(double)); // initial y coordinates
126 focus_t *fs;
127 int ne;
128 int i;
129 int closest_fine_node;
130 int cur_level = 0;
131 Hierarchy *hp;
132 gvcolor_t cl;
133 Agnode_t *np;
134
135 v_data *graph = makeGraph(g, &ne);
136
137 i=0;
138 for (np = agfstnode(g); np; np = agnxtnode(g, np))
139 {
140 x_coords[i]=ND_A(np).x;
141 y_coords[i]=ND_A(np).y;
142 i++;
143 }
144 hp = t->fisheyeParams.h =
145 makeHier(agnnodes(g), ne, graph, x_coords, y_coords,
146 &t->fisheyeParams.hier);
148 free(x_coords);
149 free(y_coords);
150
151 fs = t->fisheyeParams.fs = initFocus(agnnodes(g)); // create focus set
152
153 closest_fine_node = 0; /* first node */
154 fs->num_foci = 1;
155 fs->foci_nodes[0] = closest_fine_node;
156 fs->x_foci[0] = hp->geom_graphs[cur_level][closest_fine_node].x_coord;
157 fs->y_foci[0] = hp->geom_graphs[cur_level][closest_fine_node].y_coord;
158
160 (int) (view->bdxRight - view->bdxLeft);
162 (int) (view->bdyTop - view->bdyBottom);
163
164 //topological fisheye
165
167 ("topologicalfisheyefinestcolor", view,
168 view->g[view->activeGraph]), &cl, RGBA_DOUBLE);
169 view->Topview->fisheyeParams.srcColor.R = (float) cl.u.RGBA[0];
170 view->Topview->fisheyeParams.srcColor.G = (float) cl.u.RGBA[1];
171 view->Topview->fisheyeParams.srcColor.B = (float) cl.u.RGBA[2];
173 ("topologicalfisheyecoarsestcolor", view,
174 view->g[view->activeGraph]), &cl, RGBA_DOUBLE);
175 view->Topview->fisheyeParams.tarColor.R = (float) cl.u.RGBA[0];
176 view->Topview->fisheyeParams.tarColor.G = (float) cl.u.RGBA[1];
177 view->Topview->fisheyeParams.tarColor.B = (float) cl.u.RGBA[2];
178
179
180 sscanf(agget
182 "topologicalfisheyedistortionfactor"), "%lf",
184 sscanf(agget
185 (view->g[view->activeGraph], "topologicalfisheyefinenodes"),
187 sscanf(agget
189 "topologicalfisheyecoarseningfactor"), "%lf",
191 sscanf(agget
192 (view->g[view->activeGraph], "topologicalfisheyedist2limit"),
194 sscanf(agget(view->g[view->activeGraph], "topologicalfisheyeanimate"),
196
200}
201
202static void drawtopfishnodes(topview * t)
203{
204 glCompColor srcColor;
205 glCompColor tarColor;
207 int level, v;
208 Hierarchy *hp = t->fisheyeParams.h;
209 static int max_visible_level = 0;
210 srcColor.R = view->Topview->fisheyeParams.srcColor.R;
211 srcColor.G = view->Topview->fisheyeParams.srcColor.G;
212 srcColor.B = view->Topview->fisheyeParams.srcColor.B;
213 tarColor.R = view->Topview->fisheyeParams.tarColor.R;
214 tarColor.G = view->Topview->fisheyeParams.tarColor.G;
215 tarColor.B = view->Topview->fisheyeParams.tarColor.B;
216
217 //drawing nodes
218 glPointSize(7);
219 level = 0;
220 glBegin(GL_POINTS);
221 for (level = 0; level < hp->nlevels; level++) {
222 for (v = 0; v < hp->nvtxs[level]; v++) {
223 double x0, y0;
224 if (get_temp_coords(t, level, v, &x0, &y0)) {
225
226 if (!(-x0 / view->zoom > view->clipX1 && -x0 / view->zoom < view->clipX2 &&
227 -y0 / view->zoom > view->clipY1 && -y0 / view->zoom < view->clipY2))
228 continue;
229
230 if (max_visible_level < level)
231 max_visible_level = level;
232 color_interpolation(srcColor, tarColor, &color,
233 max_visible_level, level);
234 glColor4f(color.R, color.G, color.B, view->defaultnodealpha);
235
236 glVertex3f((float)x0, (float)y0, 0.0f);
237 }
238 }
239 }
240 glEnd();
241
242}
243
244static void drawtopfishedges(topview * t)
245{
246 glCompColor srcColor;
247 glCompColor tarColor;
249
250 int level, v, i, n;
251 Hierarchy *hp = t->fisheyeParams.h;
252 static int max_visible_level = 0;
253 srcColor.R = view->Topview->fisheyeParams.srcColor.R;
254 srcColor.G = view->Topview->fisheyeParams.srcColor.G;
255 srcColor.B = view->Topview->fisheyeParams.srcColor.B;
256 tarColor.R = view->Topview->fisheyeParams.tarColor.R;
257 tarColor.G = view->Topview->fisheyeParams.tarColor.G;
258 tarColor.B = view->Topview->fisheyeParams.tarColor.B;
259
260 //and edges
261 glBegin(GL_LINES);
262 for (level = 0; level < hp->nlevels; level++) {
263 for (v = 0; v < hp->nvtxs[level]; v++) {
264 v_data *g = hp->graphs[level];
265 double x0, y0;
266 if (get_temp_coords(t, level, v, &x0, &y0)) {
267 for (i = 1; i < g[v].nedges; i++) {
268 double x, y;
269 n = g[v].edges[i];
270
271
272 if (max_visible_level < level)
273 max_visible_level = level;
274 color_interpolation(srcColor, tarColor, &color,
275 max_visible_level, level);
276 glColor4f(color.R, color.G, color.B, view->defaultnodealpha);
277
278 if (get_temp_coords(t, level, n, &x, &y)) {
279 glVertex3f((float)x0, (float)y0, 0.0f);
280 glVertex3f((float)x, (float)y, 0.0f);
281 } else
282 {
283 int levell, nodee;
284 find_active_ancestor_info(hp, level, n, &levell,
285 &nodee);
286 if (get_temp_coords(t, levell, nodee, &x, &y)) {
287
288 if (!(-x0 / view->zoom > view->clipX1
289 && -x0 / view->zoom < view->clipX2
290 && -y0 / view->zoom > view->clipY1
291 && -y0 / view->zoom < view->clipY2)
292 && !(-x / view->zoom > view->clipX1
293 && -x / view->zoom < view->clipX2
294 && -y / view->zoom > view->clipY1
295 && -y / view->zoom < view->clipY2))
296
297 continue;
298
299
300 glVertex3f((float)x0, (float)y0, 0.0f);
301 glVertex3f((float)x, (float)y, 0.0f);
302 }
303 }
304 }
305 }
306 }
307 }
308 glEnd();
309
310}
311
312static int get_active_frame(void)
313{
314 int fr;
315 gdouble seconds = g_timer_elapsed(view->timer, NULL);
316 fr = (int)(seconds * 1000.0);
317 if (fr < view->total_frames) {
318
319 if (fr == view->active_frame)
320 return 0;
321 else {
322 view->active_frame = fr;
323 return 1;
324 }
325 } else {
326 g_timer_stop(view->timer);
328 return 0;
329 }
330
331}
332
339
340static void get_interpolated_coords(double x0, double y0, double x1, double y1,
341 int fr, int total_fr, double *x, double *y)
342{
343 *x = x0 + (x1 - x0) / (double) total_fr *(double) (fr + 1);
344 *y = y0 + (y1 - y0) / (double) total_fr *(double) (fr + 1);
345}
346
347static int get_temp_coords(topview * t, int level, int v, double *coord_x,
348 double *coord_y)
349{
350 Hierarchy *hp = t->fisheyeParams.h;
351 ex_vtx_data *gg = hp->geom_graphs[level];
352
353 if (!t->fisheyeParams.animate) {
354 if (gg[v].active_level != level)
355 return 0;
356
357 *coord_x = (double) gg[v].physical_x_coord;
358 *coord_y = (double) gg[v].physical_y_coord;
359 } else {
360
361
362 double x0, y0, x1, y1;
363 int OAL, AL;
364
365 x0 = 0;
366 y0 = 0;
367 x1 = 0;
368 y1 = 0;
369 AL = gg[v].active_level;
370 OAL = gg[v].old_active_level;
371
372 if (OAL < level || AL < level) //no draw
373 return 0;
374 if (OAL >= level || AL >= level) //draw the node
375 {
376 if (OAL == level && AL == level) //draw as is from old coords to new)
377 {
378 x0 = (double) gg[v].old_physical_x_coord;
379 y0 = (double) gg[v].old_physical_y_coord;
380 x1 = (double) gg[v].physical_x_coord;
381 y1 = (double) gg[v].physical_y_coord;
382 }
383 if (OAL > level && AL == level) //draw as from ancs to new)
384 {
385 find_old_physical_coords(t->fisheyeParams.h, level, v, &x0, &y0);
386 x1 = (double) gg[v].physical_x_coord;
387 y1 = (double) gg[v].physical_y_coord;
388 }
389 if (OAL == level && AL > level) //draw as from ancs to new)
390 {
391 find_physical_coords(t->fisheyeParams.h, level, v, &x1, &y1);
392 x0 = (double) gg[v].old_physical_x_coord;
393 y0 = (double) gg[v].old_physical_y_coord;
394 }
396 view->total_frames, coord_x, coord_y);
397 if (x0 == 0 || x1 == 0)
398 return 0;
399
400 }
401 }
402 return 1;
403}
404
405void changetopfishfocus(topview * t, float *x, float *y, int num_foci)
406{
407
408 gvcolor_t cl;
409 focus_t *fs = t->fisheyeParams.fs;
410 int i;
411 int closest_fine_node;
412 int cur_level = 0;
413
414 Hierarchy *hp = t->fisheyeParams.h;
416 fs->num_foci = num_foci;
417 for (i = 0; i < num_foci; i++) {
418 find_closest_active_node(hp, x[i], y[i], &closest_fine_node);
419 fs->foci_nodes[i] = closest_fine_node;
420 fs->x_foci[i] =
421 hp->geom_graphs[cur_level][closest_fine_node].x_coord;
422 fs->y_foci[i] =
423 hp->geom_graphs[cur_level][closest_fine_node].y_coord;
424 }
425
426
428 (int) (view->bdxRight - view->bdxLeft);
430 (int) (view->bdyTop - view->bdyBottom);
431
433 ("topologicalfisheyefinestcolor", view,
434 view->g[view->activeGraph]), &cl, RGBA_DOUBLE);
435 view->Topview->fisheyeParams.srcColor.R = (float) cl.u.RGBA[0];
436 view->Topview->fisheyeParams.srcColor.G = (float) cl.u.RGBA[1];
437 view->Topview->fisheyeParams.srcColor.B = (float) cl.u.RGBA[2];
439 ("topologicalfisheyecoarsestcolor", view,
440 view->g[view->activeGraph]), &cl, RGBA_DOUBLE);
441 view->Topview->fisheyeParams.tarColor.R = (float) cl.u.RGBA[0];
442 view->Topview->fisheyeParams.tarColor.G = (float) cl.u.RGBA[1];
443 view->Topview->fisheyeParams.tarColor.B = (float) cl.u.RGBA[2];
444
445
446
447 sscanf(agget
449 "topologicalfisheyedistortionfactor"), "%lf",
451 sscanf(agget
452 (view->g[view->activeGraph], "topologicalfisheyefinenodes"),
454 sscanf(agget
456 "topologicalfisheyecoarseningfactor"), "%lf",
458 sscanf(agget
459 (view->g[view->activeGraph], "topologicalfisheyedist2limit"),
461 sscanf(agget(view->g[view->activeGraph], "topologicalfisheyeanimate"),
463
465
467
469
470 if (t->fisheyeParams.animate) {
471 view->active_frame = 0;
472 g_timer_start(view->timer);
473 }
474
475}
Memory allocation wrappers that exit on failure.
static void * gv_calloc(size_t nmemb, size_t size)
Definition alloc.h:26
@ RGBA_DOUBLE
Definition color.h:27
void colorxlate(char *str, agxbuf *buf)
Definition colxlate.c:46
void freeGraph(v_data *graph)
Definition delaunay.c:823
void free(void *)
node NULL
Definition grammar.y:163
int agnedges(Agraph_t *g)
Definition graph.c:171
int agnnodes(Agraph_t *g)
Definition graph.c:165
char * agget(void *obj, char *name)
Definition attr.c:465
#define agtail(e)
Definition cgraph.h:888
Agedge_t * agnxtedge(Agraph_t *g, Agedge_t *e, Agnode_t *n)
Definition edge.c:94
#define aghead(e)
Definition cgraph.h:889
Agedge_t * agfstedge(Agraph_t *g, Agnode_t *n)
Definition edge.c:85
Agnode_t * agnxtnode(Agraph_t *g, Agnode_t *n)
Definition node.c:47
Agnode_t * agfstnode(Agraph_t *g)
Definition node.c:40
Agraph_t * agraphof(void *obj)
Definition obj.c:185
Agraph_t * graph(char *name)
Definition gv.cpp:30
static void color(Agraph_t *g)
Definition gvcolor.c:129
Hierarchy * makeHier(int nn, int ne, v_data *graph, double *x_coords, double *y_coords, hierparms_t *parms)
Definition hier.c:99
void positionAllItems(Hierarchy *hp, focus_t *fs, reposition_t *parms)
Definition hier.c:18
focus_t * initFocus(int ncnt)
Definition hier.c:130
void set_active_levels(Hierarchy *hierarchy, int *foci_nodes, int num_foci, levelparms_t *parms)
Definition hierarchy.c:753
double find_closest_active_node(Hierarchy *hierarchy, double x, double y, int *closest_fine_node)
Definition hierarchy.c:929
void find_active_ancestor_info(Hierarchy *hierarchy, int level, int node, int *levell, int *nodee)
Definition hierarchy.c:1078
void find_old_physical_coords(Hierarchy *hierarchy, int level, int node, double *x, double *y)
Definition hierarchy.c:1097
void find_physical_coords(Hierarchy *hierarchy, int level, int node, double *x, double *y)
Definition hierarchy.c:1064
static int nedges
total no. of edges used in routing
Definition routespl.c:31
ViewInfo * view
Definition viewport.c:37
#define ND_TVref(n)
Definition smyrnadefs.h:164
#define ND_A(n)
Definition smyrnadefs.h:162
graph or subgraph
Definition cgraph.h:424
v_data ** graphs
Definition hierarchy.h:40
int * nvtxs
Definition hierarchy.h:42
ex_vtx_data ** geom_graphs
Definition hierarchy.h:41
int nlevels
Definition hierarchy.h:39
float bdxLeft
Definition smyrnadefs.h:287
int active_frame
Definition smyrnadefs.h:317
topview * Topview
Definition smyrnadefs.h:310
Agraph_t ** g
Definition smyrnadefs.h:293
int total_frames
Definition smyrnadefs.h:318
float clipX2
Definition smyrnadefs.h:258
float bdyTop
Definition smyrnadefs.h:287
GTimer * timer
Definition smyrnadefs.h:312
int activeGraph
Definition smyrnadefs.h:297
float bdxRight
Definition smyrnadefs.h:288
float bdyBottom
Definition smyrnadefs.h:288
float zoom
Definition smyrnadefs.h:255
float clipY1
Definition smyrnadefs.h:258
float clipX1
Definition smyrnadefs.h:258
float clipY2
Definition smyrnadefs.h:258
float defaultnodealpha
Definition smyrnadefs.h:273
double RGBA[4]
Definition color.h:32
union color_s::@71 u
float physical_y_coord
Definition hierarchy.h:29
float old_physical_y_coord
Definition hierarchy.h:32
float old_physical_x_coord
Definition hierarchy.h:31
int old_active_level
Definition hierarchy.h:33
float physical_x_coord
Definition hierarchy.h:28
float x_coord
Definition hierarchy.h:24
int active_level
Definition hierarchy.h:20
float y_coord
Definition hierarchy.h:25
Definition hier.h:15
int * foci_nodes
Definition hier.h:17
int num_foci
Definition hier.h:16
double * y_foci
Definition hier.h:19
double * x_foci
Definition hier.h:18
int dist2_limit
Definition hierarchy.h:63
int num_fine_nodes
Definition hierarchy.h:56
double coarsening_rate
Definition hierarchy.h:57
double distortion
Definition hier.h:26
int height
Definition hier.h:25
int width
Definition hier.h:24
hierparms_t hier
Definition smyrnadefs.h:223
int animate
Definition smyrnadefs.h:225
Hierarchy * h
Definition smyrnadefs.h:224
glCompColor srcColor
Definition smyrnadefs.h:226
reposition_t repos
Definition smyrnadefs.h:221
focus_t * fs
Definition smyrnadefs.h:228
struct topview::@55 fisheyeParams
size_t Nodecount
Definition smyrnadefs.h:218
levelparms_t level
Definition smyrnadefs.h:222
glCompColor tarColor
Definition smyrnadefs.h:227
int nedges
Definition sparsegraph.h:22
int * edges
Definition sparsegraph.h:23
static void get_interpolated_coords(double x0, double y0, double x1, double y1, int fr, int total_fr, double *x, double *y)
void changetopfishfocus(topview *t, float *x, float *y, int num_foci)
static void color_interpolation(glCompColor srcColor, glCompColor tarColor, glCompColor *color, int levelcount, int level)
static void refresh_old_values(topview *t)
static void drawtopfishedges(topview *t)
static int get_temp_coords(topview *t, int level, int v, double *coord_x, double *coord_y)
static void drawtopfishnodes(topview *t)
static int get_active_frame(void)
void drawtopologicalfisheye(topview *t)
void prepare_topological_fisheye(Agraph_t *g, topview *t)
static v_data * makeGraph(Agraph_t *gg, int *nedges)
char * get_attribute_value(char *attr, ViewInfo *vi, Agraph_t *g)
Definition viewport.c:77