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