Graphviz 16.1.3~dev.20261128.0221
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 v2.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11#include "config.h"
12
13#include "topfisheyeview.h"
14#include <math.h>
15#include "viewport.h"
16#include "viewportcamera.h"
17#include "draw.h"
18#include "smyrna_utils.h"
19
20#include <assert.h>
21#include "hier.h"
22#include "topfisheyeview.h"
23#include <stddef.h>
24#include <string.h>
25#include <cgraph/cgraph.h>
26#include <common/color.h>
27#include <common/colorprocs.h>
28#include <util/alloc.h>
29#include <util/list.h>
30
31static int get_temp_coords(topview *t, int level, int v, float *coord_x,
32 float *coord_y);
33
34static int color_interpolation(glCompColor srcColor, glCompColor tarColor,
35 glCompColor * color, int levelcount,
36 int level)
37{
38 if (levelcount <= 0)
39 return -1;
40
41 color->R = (level * tarColor.R - level * srcColor.R +
42 levelcount * srcColor.R) / levelcount;
43 color->G = (level * tarColor.G - level * srcColor.G +
44 levelcount * srcColor.G) / levelcount;
45 color->B = (level * tarColor.B - level * srcColor.B +
46 levelcount * srcColor.B) / levelcount;
47 return 0;
48}
49
50static v_data *makeGraph(Agraph_t* gg, int *nedges)
51{
52 int ne = agnedges(gg);
53 const size_t nv = agnnodes_z(gg);
54 v_data *graph = gv_calloc(nv, sizeof(v_data));
55 int *edges = gv_calloc(2 * ne + nv, sizeof(int)); /* reserve space for self loops */
56 float *ewgts = gv_calloc(2 * ne + nv, sizeof(float));
57 Agraph_t *g = NULL;
58 ne = 0;
59 int i = 0;
60 for (Agnode_t *np = agfstnode(gg); np; np = agnxtnode(gg, np)) {
61 graph[i].edges = edges++; /* reserve space for the self loop */
62 graph[i].ewgts = ewgts++;
63 int i_nedges = 1; // one for the self
64
65 if (!g)
66 g = agraphof(np);
67 for (Agedge_t *ep = agfstedge(g, np); ep; ep = agnxtedge(g, ep, np)) {
68 Agnode_t *tp = agtail(ep);
69 Agnode_t *hp = aghead(ep);
70 assert(hp != tp);
71 /* FIX: handle multiedges */
72 Agnode_t *const vp = tp == np ? hp : tp;
73 ne++;
74 i_nedges++;
75 *edges++ = ND_TVref(vp);
76 *ewgts++ = 1;
77
78 }
79
80 graph[i].nedges = i_nedges;
81 graph[i].edges[0] = i;
82 graph[i].ewgts[0] = 1 - i_nedges;
83 i++;
84 }
85 ne /= 2; /* each edge counted twice */
86 *nedges = ne;
87 return graph;
88}
89
91{
92 int level, v;
93 Hierarchy *hp = t->fisheyeParams.h;
94 for (level = 0; level < hp->nlevels; level++) {
95 for (v = 0; v < LIST_GET(&hp->nvtxs, (size_t)level); v++) {
96 ex_vtx_data *gg = LIST_GET(&hp->geom_graphs, (size_t)level);
99 gg[v].old_active_level = gg[v].active_level;
100 }
101 }
102
103}
104
105/* To use:
106 * double* x_coords; // initial x coordinates
107 * double* y_coords; // initial y coordinates
108 * focus_t* fs;
109 * int ne;
110 * v_data* graph = makeGraph (topview*, &ne);
111 * hierarchy = makeHier(topview->NodeCount, ne, graph, x_coords, y_coords);
112 * freeGraph (graph);
113 * fs = initFocus (topview->Nodecount); // create focus set
114 */
116{
117 double *x_coords = gv_calloc(t->Nodecount, sizeof(double)); // initial x coordinates
118 double *y_coords = gv_calloc(t->Nodecount, sizeof(double)); // initial y coordinates
119 focus_t *fs;
120 int ne;
121 int i;
122 int closest_fine_node;
123 int cur_level = 0;
124 Hierarchy *hp;
125 gvcolor_t cl;
126 Agnode_t *np;
127
128 v_data *graph = makeGraph(g, &ne);
129
130 i=0;
131 for (np = agfstnode(g); np; np = agnxtnode(g, np))
132 {
133 x_coords[i]=ND_A(np).x;
134 y_coords[i]=ND_A(np).y;
135 i++;
136 }
137 hp = t->fisheyeParams.h =
138 makeHier(agnnodes(g), ne, graph, x_coords, y_coords,
141 free(x_coords);
142 free(y_coords);
143
144 fs = t->fisheyeParams.fs = initFocus(agnnodes_z(g)); // create focus set
145
146 closest_fine_node = 0; /* first node */
147 fs->num_foci = 1;
148 fs->foci_nodes[0] = closest_fine_node;
149 fs->x_foci[0] = LIST_GET(&hp->geom_graphs, (size_t)cur_level)[closest_fine_node].x_coord;
150 fs->y_foci[0] = LIST_GET(&hp->geom_graphs, (size_t)cur_level)[closest_fine_node].y_coord;
151
153 round(view->bdxRight - view->bdxLeft);
155 round(view->bdyTop - view->bdyBottom);
156
157 //topological fisheye
158
160 ("topologicalfisheyefinestcolor", view,
161 view->g[view->activeGraph]), &cl, RGBA_DOUBLE);
166 ("topologicalfisheyecoarsestcolor", view,
167 view->g[view->activeGraph]), &cl, RGBA_DOUBLE);
171
172 sscanf(agget
174 "topologicalfisheyedistortionfactor"), "%lf",
176 sscanf(agget
177 (view->g[view->activeGraph], "topologicalfisheyefinenodes"),
179 sscanf(agget
181 "topologicalfisheyecoarseningfactor"), "%lf",
183 int dist2_limit = 0;
184 sscanf(agget
185 (view->g[view->activeGraph], "topologicalfisheyedist2limit"),
186 "%d", &dist2_limit);
187 view->Topview->fisheyeParams.dist2_limit = dist2_limit != 0;
188 sscanf(agget(view->g[view->activeGraph], "topologicalfisheyeanimate"),
190
194}
195
196static void drawtopfishnodes(topview * t)
197{
199 int level, v;
200 Hierarchy *hp = t->fisheyeParams.h;
201 static int max_visible_level = 0;
202 const glCompColor srcColor = view->Topview->fisheyeParams.srcColor;
203 const glCompColor tarColor = view->Topview->fisheyeParams.tarColor;
204
205 //drawing nodes
206 glPointSize(7);
207 glBegin(GL_POINTS);
208 for (level = 0; level < hp->nlevels; level++) {
209 for (v = 0; v < LIST_GET(&hp->nvtxs, (size_t)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 glColor4d(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 < LIST_GET(&hp->nvtxs, (size_t)level); v++) {
247 v_data *g = LIST_GET(&hp->graphs, (size_t)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 glColor4d(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 view->active_frame = fr;
301 return;
302 }
303 g_timer_stop(view->timer);
305}
306
313
314static void get_interpolated_coords(float x0, float y0, float x1, float y1,
315 int fr, int total_fr, float *x, float *y) {
316 *x = x0 + (x1 - x0) / (float)total_fr * (float)(fr + 1);
317 *y = y0 + (y1 - y0) / (float)total_fr * (float)(fr + 1);
318}
319
320static int get_temp_coords(topview *t, int level, int v, float *coord_x,
321 float *coord_y) {
322 Hierarchy *hp = t->fisheyeParams.h;
323 ex_vtx_data *gg = LIST_GET(&hp->geom_graphs, (size_t)level);
324
325 if (!t->fisheyeParams.animate) {
326 if (gg[v].active_level != level)
327 return 0;
328
329 *coord_x = gg[v].physical_x_coord;
330 *coord_y = gg[v].physical_y_coord;
331 } else {
332
333
334 int OAL, AL;
335
336 float x0 = 0;
337 float y0 = 0;
338 float x1 = 0;
339 float y1 = 0;
340 AL = gg[v].active_level;
341 OAL = gg[v].old_active_level;
342
343 if (OAL < level || AL < level) //no draw
344 return 0;
345 if (OAL >= level || AL >= level) //draw the node
346 {
347 if (OAL == level && AL == level) //draw as is from old coords to new)
348 {
349 x0 = gg[v].old_physical_x_coord;
350 y0 = gg[v].old_physical_y_coord;
351 x1 = gg[v].physical_x_coord;
352 y1 = gg[v].physical_y_coord;
353 }
354 if (OAL > level && AL == level) //draw as from ancs to new)
355 {
356 find_old_physical_coords(t->fisheyeParams.h, level, v, &x0, &y0);
357 x1 = gg[v].physical_x_coord;
358 y1 = gg[v].physical_y_coord;
359 }
360 if (OAL == level && AL > level) //draw as from ancs to new)
361 {
362 find_physical_coords(t->fisheyeParams.h, level, v, &x1, &y1);
363 x0 = gg[v].old_physical_x_coord;
364 y0 = gg[v].old_physical_y_coord;
365 }
367 view->total_frames, coord_x, coord_y);
368 if (x0 == 0 || x1 == 0)
369 return 0;
370
371 }
372 }
373 return 1;
374}
375
376void changetopfishfocus(topview * t, float *x, float *y, int num_foci)
377{
378
379 gvcolor_t cl;
380 focus_t *fs = t->fisheyeParams.fs;
381 int i;
382 int closest_fine_node;
383 int cur_level = 0;
384
385 Hierarchy *hp = t->fisheyeParams.h;
387 fs->num_foci = num_foci;
388 for (i = 0; i < num_foci; i++) {
389 find_closest_active_node(hp, x[i], y[i], &closest_fine_node);
390 fs->foci_nodes[i] = closest_fine_node;
391 fs->x_foci[i] =
392 LIST_GET(&hp->geom_graphs, (size_t)cur_level)[closest_fine_node].x_coord;
393 fs->y_foci[i] =
394 LIST_GET(&hp->geom_graphs, (size_t)cur_level)[closest_fine_node].y_coord;
395 }
396
397
399 (int) (view->bdxRight - view->bdxLeft);
401 (int) (view->bdyTop - view->bdyBottom);
402
404 ("topologicalfisheyefinestcolor", view,
405 view->g[view->activeGraph]), &cl, RGBA_DOUBLE);
410 ("topologicalfisheyecoarsestcolor", view,
411 view->g[view->activeGraph]), &cl, RGBA_DOUBLE);
415
416 sscanf(agget
418 "topologicalfisheyedistortionfactor"), "%lf",
420 sscanf(agget
421 (view->g[view->activeGraph], "topologicalfisheyefinenodes"),
423 sscanf(agget
425 "topologicalfisheyecoarseningfactor"), "%lf",
427 int dist2_limit = 0;
428 sscanf(agget
429 (view->g[view->activeGraph], "topologicalfisheyedist2limit"),
430 "%d", &dist2_limit);
431 view->Topview->fisheyeParams.dist2_limit = dist2_limit != 0;
432 sscanf(agget(view->g[view->activeGraph], "topologicalfisheyeanimate"),
434
436
438
440
441 if (t->fisheyeParams.animate) {
442 view->active_frame = 0;
443 g_timer_start(view->timer);
444 }
445
446}
Memory allocation wrappers that exit on failure.
static void * gv_calloc(size_t nmemb, size_t size)
Definition alloc.h:26
abstract graph C library, Cgraph API
@ RGBA_DOUBLE
Definition color.h:30
void colorxlate(char *str, agxbuf *buf)
Definition colxlate.c:48
void freeGraph(v_data *graph)
Definition delaunay.c:645
void free(void *)
node NULL
Definition grammar.y:181
int agnedges(Agraph_t *g)
Definition graph.c:169
int agnnodes(Agraph_t *g)
Definition graph.c:163
size_t agnnodes_z(const Agraph_t *g)
Definition graph.c:161
char * agget(void *obj, char *name)
Definition attr.c:447
#define agtail(e)
Definition cgraph.h:982
Agedge_t * agnxtedge(Agraph_t *g, Agedge_t *e, Agnode_t *n)
Definition edge.c:93
#define aghead(e)
Definition cgraph.h:983
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:50
Agnode_t * agfstnode(Agraph_t *g)
Definition node.c:43
Agraph_t * agraphof(void *obj)
Definition obj.c:187
Agraph_t * graph(char *name)
Definition gv.cpp:34
static void color(Agraph_t *g)
Definition gvcolor.c:118
Hierarchy * makeHier(int nn, int ne, v_data *graph, double *x_coords, double *y_coords, bool dist2_limit)
Definition hier.c:60
void positionAllItems(Hierarchy *hp, focus_t *fs, reposition_t *parms)
Definition hier.c:22
focus_t * initFocus(size_t ncnt)
Definition hier.c:90
void set_active_levels(Hierarchy *hierarchy, int *foci_nodes, int num_foci, levelparms_t *parms)
Definition hierarchy.c:739
void find_closest_active_node(Hierarchy *hierarchy, double x, double y, int *closest_fine_node)
Definition hierarchy.c:900
void find_old_physical_coords(Hierarchy *hierarchy, int level, int node, float *x, float *y)
Definition hierarchy.c:1063
void find_active_ancestor_info(Hierarchy *hierarchy, int level, int node, int *levell, int *nodee)
Definition hierarchy.c:1045
void find_physical_coords(Hierarchy *hierarchy, int level, int node, float *x, float *y)
Definition hierarchy.c:1032
type-generic dynamically expanding list
#define LIST_GET(list, index)
Definition list.h:197
static int nedges
total no. of edges used in routing
Definition routespl.c:33
ViewInfo * view
Definition viewport.c:40
#define ND_TVref(n)
Definition smyrnadefs.h:158
#define ND_A(n)
Definition smyrnadefs.h:156
graph or subgraph
Definition cgraph.h:424
int nlevels
Definition hierarchy.h:40
int active_frame
Definition smyrnadefs.h:312
topview * Topview
Definition smyrnadefs.h:305
Agraph_t ** g
Definition smyrnadefs.h:288
double bdxRight
Definition smyrnadefs.h:283
int total_frames
Definition smyrnadefs.h:313
float clipX2
Definition smyrnadefs.h:253
double bdyBottom
Definition smyrnadefs.h:283
double zoom
Definition smyrnadefs.h:250
double bdyTop
Definition smyrnadefs.h:282
GTimer * timer
Definition smyrnadefs.h:307
double defaultnodealpha
Definition smyrnadefs.h:268
int activeGraph
Definition smyrnadefs.h:292
double bdxLeft
Definition smyrnadefs.h:282
float clipY1
Definition smyrnadefs.h:253
float clipX1
Definition smyrnadefs.h:253
float clipY2
Definition smyrnadefs.h:253
double RGBA[4]
Definition color.h:38
union color_s::@40 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
int active_level
Definition hierarchy.h:22
Definition hier.h:17
int * foci_nodes
Definition hier.h:19
int num_foci
Definition hier.h:18
double * y_foci
Definition hier.h:21
double * x_foci
Definition hier.h:20
int num_fine_nodes
Definition hierarchy.h:55
double coarsening_rate
Definition hierarchy.h:56
double distortion
Definition hier.h:28
double height
viewport height
Definition hier.h:27
double width
viewport width
Definition hier.h:26
int animate
Definition smyrnadefs.h:221
struct topview::@22 fisheyeParams
Hierarchy * h
Definition smyrnadefs.h:220
glCompColor srcColor
Definition smyrnadefs.h:222
reposition_t repos
Definition smyrnadefs.h:215
focus_t * fs
Definition smyrnadefs.h:224
bool dist2_limit
Definition smyrnadefs.h:219
size_t Nodecount
Definition smyrnadefs.h:212
levelparms_t level
Definition smyrnadefs.h:216
glCompColor tarColor
Definition smyrnadefs.h:223
int nedges
Definition sparsegraph.h:24
int * edges
Definition sparsegraph.h:25
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:74