Graphviz 13.0.0~dev.20250402.0402
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 i_nedges = 1; /* one for the self */
66
67 if (!g)
68 g = agraphof(np);
69 for (ep = agfstedge(g, np); ep; ep = agnxtedge(g, ep, np))
70 {
71 Agnode_t *vp;
72 Agnode_t *tp = agtail(ep);
73 Agnode_t *hp = aghead(ep);
74 assert(hp != tp);
75 /* FIX: handle multiedges */
76 vp = tp == np ? hp : tp;
77 ne++;
78 i_nedges++;
79 *edges++ = ND_TVref(vp);
80 *ewgts++ = 1;
81
82 }
83
84 graph[i].nedges = i_nedges;
85 graph[i].edges[0] = i;
86 graph[i].ewgts[0] = 1 - i_nedges;
87 i++;
88 }
89 ne /= 2; /* each edge counted twice */
90 *nedges = ne;
91 return graph;
92}
93
95{
96 int level, v;
97 Hierarchy *hp = t->fisheyeParams.h;
98 for (level = 0; level < hp->nlevels; level++) {
99 for (v = 0; v < hp->nvtxs[level]; v++) {
100 ex_vtx_data *gg = hp->geom_graphs[level];
103 gg[v].old_active_level = gg[v].active_level;
104 }
105 }
106
107}
108
109/* To use:
110 * double* x_coords; // initial x coordinates
111 * double* y_coords; // initial y coordinates
112 * focus_t* fs;
113 * int ne;
114 * v_data* graph = makeGraph (topview*, &ne);
115 * hierarchy = makeHier(topview->NodeCount, ne, graph, x_coords, y_coords);
116 * freeGraph (graph);
117 * fs = initFocus (topview->Nodecount); // create focus set
118 */
120{
121 double *x_coords = gv_calloc(t->Nodecount, sizeof(double)); // initial x coordinates
122 double *y_coords = gv_calloc(t->Nodecount, sizeof(double)); // initial y coordinates
123 focus_t *fs;
124 int ne;
125 int i;
126 int closest_fine_node;
127 int cur_level = 0;
128 Hierarchy *hp;
129 gvcolor_t cl;
130 Agnode_t *np;
131
132 v_data *graph = makeGraph(g, &ne);
133
134 i=0;
135 for (np = agfstnode(g); np; np = agnxtnode(g, np))
136 {
137 x_coords[i]=ND_A(np).x;
138 y_coords[i]=ND_A(np).y;
139 i++;
140 }
141 hp = t->fisheyeParams.h =
142 makeHier(agnnodes(g), ne, graph, x_coords, y_coords,
145 free(x_coords);
146 free(y_coords);
147
148 fs = t->fisheyeParams.fs = initFocus(agnnodes(g)); // create focus set
149
150 closest_fine_node = 0; /* first node */
151 fs->num_foci = 1;
152 fs->foci_nodes[0] = closest_fine_node;
153 fs->x_foci[0] = hp->geom_graphs[cur_level][closest_fine_node].x_coord;
154 fs->y_foci[0] = hp->geom_graphs[cur_level][closest_fine_node].y_coord;
155
157 (int) (view->bdxRight - view->bdxLeft);
159 (int) (view->bdyTop - view->bdyBottom);
160
161 //topological fisheye
162
164 ("topologicalfisheyefinestcolor", view,
165 view->g[view->activeGraph]), &cl, RGBA_DOUBLE);
166 view->Topview->fisheyeParams.srcColor.R = (float) cl.u.RGBA[0];
167 view->Topview->fisheyeParams.srcColor.G = (float) cl.u.RGBA[1];
168 view->Topview->fisheyeParams.srcColor.B = (float) cl.u.RGBA[2];
170 ("topologicalfisheyecoarsestcolor", view,
171 view->g[view->activeGraph]), &cl, RGBA_DOUBLE);
172 view->Topview->fisheyeParams.tarColor.R = (float) cl.u.RGBA[0];
173 view->Topview->fisheyeParams.tarColor.G = (float) cl.u.RGBA[1];
174 view->Topview->fisheyeParams.tarColor.B = (float) cl.u.RGBA[2];
175
176
177 sscanf(agget
179 "topologicalfisheyedistortionfactor"), "%lf",
181 sscanf(agget
182 (view->g[view->activeGraph], "topologicalfisheyefinenodes"),
184 sscanf(agget
186 "topologicalfisheyecoarseningfactor"), "%lf",
188 int dist2_limit = 0;
189 sscanf(agget
190 (view->g[view->activeGraph], "topologicalfisheyedist2limit"),
191 "%d", &dist2_limit);
192 view->Topview->fisheyeParams.dist2_limit = dist2_limit != 0;
193 sscanf(agget(view->g[view->activeGraph], "topologicalfisheyeanimate"),
195
199}
200
201static void drawtopfishnodes(topview * t)
202{
204 int level, v;
205 Hierarchy *hp = t->fisheyeParams.h;
206 static int max_visible_level = 0;
207 const glCompColor srcColor = view->Topview->fisheyeParams.srcColor;
208 const glCompColor tarColor = view->Topview->fisheyeParams.tarColor;
209
210 //drawing nodes
211 glPointSize(7);
212 level = 0;
213 glBegin(GL_POINTS);
214 for (level = 0; level < hp->nlevels; level++) {
215 for (v = 0; v < hp->nvtxs[level]; v++) {
216 double x0, y0;
217 if (get_temp_coords(t, level, v, &x0, &y0)) {
218
219 if (!(-x0 / view->zoom > view->clipX1 && -x0 / view->zoom < view->clipX2 &&
220 -y0 / view->zoom > view->clipY1 && -y0 / view->zoom < view->clipY2))
221 continue;
222
223 if (max_visible_level < level)
224 max_visible_level = level;
225 color_interpolation(srcColor, tarColor, &color,
226 max_visible_level, level);
227 glColor4f(color.R, color.G, color.B, view->defaultnodealpha);
228
229 glVertex3f((float)x0, (float)y0, 0.0f);
230 }
231 }
232 }
233 glEnd();
234
235}
236
237static void drawtopfishedges(topview * t)
238{
240
241 int level, v, i, n;
242 Hierarchy *hp = t->fisheyeParams.h;
243 static int max_visible_level = 0;
244 const glCompColor srcColor = view->Topview->fisheyeParams.srcColor;
245 const glCompColor tarColor = view->Topview->fisheyeParams.tarColor;
246
247 //and edges
248 glBegin(GL_LINES);
249 for (level = 0; level < hp->nlevels; level++) {
250 for (v = 0; v < hp->nvtxs[level]; v++) {
251 v_data *g = hp->graphs[level];
252 double x0, y0;
253 if (get_temp_coords(t, level, v, &x0, &y0)) {
254 for (i = 1; i < g[v].nedges; i++) {
255 double x, y;
256 n = g[v].edges[i];
257
258
259 if (max_visible_level < level)
260 max_visible_level = level;
261 color_interpolation(srcColor, tarColor, &color,
262 max_visible_level, level);
263 glColor4f(color.R, color.G, color.B, view->defaultnodealpha);
264
265 if (get_temp_coords(t, level, n, &x, &y)) {
266 glVertex3f((float)x0, (float)y0, 0.0f);
267 glVertex3f((float)x, (float)y, 0.0f);
268 } else
269 {
270 int levell, nodee;
271 find_active_ancestor_info(hp, level, n, &levell,
272 &nodee);
273 if (get_temp_coords(t, levell, nodee, &x, &y)) {
274
275 if (!(-x0 / view->zoom > view->clipX1
276 && -x0 / view->zoom < view->clipX2
277 && -y0 / view->zoom > view->clipY1
278 && -y0 / view->zoom < view->clipY2)
279 && !(-x / view->zoom > view->clipX1
280 && -x / view->zoom < view->clipX2
281 && -y / view->zoom > view->clipY1
282 && -y / view->zoom < view->clipY2))
283
284 continue;
285
286
287 glVertex3f((float)x0, (float)y0, 0.0f);
288 glVertex3f((float)x, (float)y, 0.0f);
289 }
290 }
291 }
292 }
293 }
294 }
295 glEnd();
296
297}
298
299static int get_active_frame(void)
300{
301 int fr;
302 gdouble seconds = g_timer_elapsed(view->timer, NULL);
303 fr = (int)(seconds * 1000.0);
304 if (fr < view->total_frames) {
305
306 if (fr == view->active_frame)
307 return 0;
308 else {
309 view->active_frame = fr;
310 return 1;
311 }
312 } else {
313 g_timer_stop(view->timer);
315 return 0;
316 }
317
318}
319
326
327static void get_interpolated_coords(double x0, double y0, double x1, double y1,
328 int fr, int total_fr, double *x, double *y)
329{
330 *x = x0 + (x1 - x0) / (double) total_fr *(double) (fr + 1);
331 *y = y0 + (y1 - y0) / (double) total_fr *(double) (fr + 1);
332}
333
334static int get_temp_coords(topview * t, int level, int v, double *coord_x,
335 double *coord_y)
336{
337 Hierarchy *hp = t->fisheyeParams.h;
338 ex_vtx_data *gg = hp->geom_graphs[level];
339
340 if (!t->fisheyeParams.animate) {
341 if (gg[v].active_level != level)
342 return 0;
343
344 *coord_x = gg[v].physical_x_coord;
345 *coord_y = gg[v].physical_y_coord;
346 } else {
347
348
349 double x0, y0, x1, y1;
350 int OAL, AL;
351
352 x0 = 0;
353 y0 = 0;
354 x1 = 0;
355 y1 = 0;
356 AL = gg[v].active_level;
357 OAL = gg[v].old_active_level;
358
359 if (OAL < level || AL < level) //no draw
360 return 0;
361 if (OAL >= level || AL >= level) //draw the node
362 {
363 if (OAL == level && AL == level) //draw as is from old coords to new)
364 {
365 x0 = gg[v].old_physical_x_coord;
366 y0 = gg[v].old_physical_y_coord;
367 x1 = gg[v].physical_x_coord;
368 y1 = gg[v].physical_y_coord;
369 }
370 if (OAL > level && AL == level) //draw as from ancs to new)
371 {
372 find_old_physical_coords(t->fisheyeParams.h, level, v, &x0, &y0);
373 x1 = gg[v].physical_x_coord;
374 y1 = gg[v].physical_y_coord;
375 }
376 if (OAL == level && AL > level) //draw as from ancs to new)
377 {
378 find_physical_coords(t->fisheyeParams.h, level, v, &x1, &y1);
379 x0 = gg[v].old_physical_x_coord;
380 y0 = gg[v].old_physical_y_coord;
381 }
383 view->total_frames, coord_x, coord_y);
384 if (x0 == 0 || x1 == 0)
385 return 0;
386
387 }
388 }
389 return 1;
390}
391
392void changetopfishfocus(topview * t, float *x, float *y, int num_foci)
393{
394
395 gvcolor_t cl;
396 focus_t *fs = t->fisheyeParams.fs;
397 int i;
398 int closest_fine_node;
399 int cur_level = 0;
400
401 Hierarchy *hp = t->fisheyeParams.h;
403 fs->num_foci = num_foci;
404 for (i = 0; i < num_foci; i++) {
405 find_closest_active_node(hp, x[i], y[i], &closest_fine_node);
406 fs->foci_nodes[i] = closest_fine_node;
407 fs->x_foci[i] =
408 hp->geom_graphs[cur_level][closest_fine_node].x_coord;
409 fs->y_foci[i] =
410 hp->geom_graphs[cur_level][closest_fine_node].y_coord;
411 }
412
413
415 (int) (view->bdxRight - view->bdxLeft);
417 (int) (view->bdyTop - view->bdyBottom);
418
420 ("topologicalfisheyefinestcolor", view,
421 view->g[view->activeGraph]), &cl, RGBA_DOUBLE);
422 view->Topview->fisheyeParams.srcColor.R = (float) cl.u.RGBA[0];
423 view->Topview->fisheyeParams.srcColor.G = (float) cl.u.RGBA[1];
424 view->Topview->fisheyeParams.srcColor.B = (float) cl.u.RGBA[2];
426 ("topologicalfisheyecoarsestcolor", view,
427 view->g[view->activeGraph]), &cl, RGBA_DOUBLE);
428 view->Topview->fisheyeParams.tarColor.R = (float) cl.u.RGBA[0];
429 view->Topview->fisheyeParams.tarColor.G = (float) cl.u.RGBA[1];
430 view->Topview->fisheyeParams.tarColor.B = (float) cl.u.RGBA[2];
431
432
433
434 sscanf(agget
436 "topologicalfisheyedistortionfactor"), "%lf",
438 sscanf(agget
439 (view->g[view->activeGraph], "topologicalfisheyefinenodes"),
441 sscanf(agget
443 "topologicalfisheyecoarseningfactor"), "%lf",
445 int dist2_limit = 0;
446 sscanf(agget
447 (view->g[view->activeGraph], "topologicalfisheyedist2limit"),
448 "%d", &dist2_limit);
449 view->Topview->fisheyeParams.dist2_limit = dist2_limit != 0;
450 sscanf(agget(view->g[view->activeGraph], "topologicalfisheyeanimate"),
452
454
456
458
459 if (t->fisheyeParams.animate) {
460 view->active_frame = 0;
461 g_timer_start(view->timer);
462 }
463
464}
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:165
int agnnodes(Agraph_t *g)
Definition graph.c:159
char * agget(void *obj, char *name)
Definition attr.c:472
#define agtail(e)
Definition cgraph.h:992
Agedge_t * agnxtedge(Agraph_t *g, Agedge_t *e, Agnode_t *n)
Definition edge.c:94
#define aghead(e)
Definition cgraph.h:993
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, bool dist2_limit)
Definition hier.c:100
void positionAllItems(Hierarchy *hp, focus_t *fs, reposition_t *parms)
Definition hier.c:19
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:165
#define ND_A(n)
Definition smyrnadefs.h:163
graph or subgraph
Definition cgraph.h:424
v_data ** graphs
Definition hierarchy.h:41
int * nvtxs
Definition hierarchy.h:43
ex_vtx_data ** geom_graphs
Definition hierarchy.h:42
int nlevels
Definition hierarchy.h:40
float bdxLeft
Definition smyrnadefs.h:289
int active_frame
Definition smyrnadefs.h:319
topview * Topview
Definition smyrnadefs.h:312
Agraph_t ** g
Definition smyrnadefs.h:295
int total_frames
Definition smyrnadefs.h:320
float clipX2
Definition smyrnadefs.h:260
float bdyTop
Definition smyrnadefs.h:289
GTimer * timer
Definition smyrnadefs.h:314
int activeGraph
Definition smyrnadefs.h:299
float bdxRight
Definition smyrnadefs.h:290
float bdyBottom
Definition smyrnadefs.h:290
float zoom
Definition smyrnadefs.h:257
float clipY1
Definition smyrnadefs.h:260
float clipX1
Definition smyrnadefs.h:260
float clipY2
Definition smyrnadefs.h:260
float defaultnodealpha
Definition smyrnadefs.h:275
double RGBA[4]
Definition color.h:32
union color_s::@72 u
float physical_y_coord
Definition hierarchy.h:30
float old_physical_y_coord
Definition hierarchy.h:33
float old_physical_x_coord
Definition hierarchy.h:32
int old_active_level
Definition hierarchy.h:34
float physical_x_coord
Definition hierarchy.h:29
float x_coord
Definition hierarchy.h:25
int active_level
Definition hierarchy.h:21
float y_coord
Definition hierarchy.h:26
Definition hier.h:16
int * foci_nodes
Definition hier.h:18
int num_foci
Definition hier.h:17
double * y_foci
Definition hier.h:20
double * x_foci
Definition hier.h:19
int num_fine_nodes
Definition hierarchy.h:57
double coarsening_rate
Definition hierarchy.h:58
double distortion
Definition hier.h:27
int height
Definition hier.h:26
int width
Definition hier.h:25
struct topview::@56 fisheyeParams
int animate
Definition smyrnadefs.h:228
Hierarchy * h
Definition smyrnadefs.h:227
glCompColor srcColor
Definition smyrnadefs.h:229
reposition_t repos
Definition smyrnadefs.h:222
focus_t * fs
Definition smyrnadefs.h:231
bool dist2_limit
Definition smyrnadefs.h:226
size_t Nodecount
Definition smyrnadefs.h:219
levelparms_t level
Definition smyrnadefs.h:223
glCompColor tarColor
Definition smyrnadefs.h:230
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