Graphviz 14.1.2~dev.20260118.1035
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
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 <string.h>
24#include <common/color.h>
25#include <common/colorprocs.h>
26#include <util/alloc.h>
27
28static int get_temp_coords(topview *t, int level, int v, float *coord_x,
29 float *coord_y);
30
31static int color_interpolation(glCompColor srcColor, glCompColor tarColor,
32 glCompColor * color, int levelcount,
33 int level)
34{
35 if (levelcount <= 0)
36 return -1;
37
38 color->R = (level * tarColor.R - level * srcColor.R +
39 levelcount * srcColor.R) / levelcount;
40 color->G = (level * tarColor.G - level * srcColor.G +
41 levelcount * srcColor.G) / levelcount;
42 color->B = (level * tarColor.B - level * srcColor.B +
43 levelcount * srcColor.B) / levelcount;
44 return 0;
45}
46
47static v_data *makeGraph(Agraph_t* gg, int *nedges)
48{
49 int ne = agnedges(gg);
50 int nv = agnnodes(gg);
51 v_data *graph = gv_calloc(nv, sizeof(v_data));
52 int *edges = gv_calloc(2 * ne + nv, sizeof(int)); /* reserve space for self loops */
53 float *ewgts = gv_calloc(2 * ne + nv, sizeof(float));
54 Agraph_t *g = NULL;
55 ne = 0;
56 int i = 0;
57 for (Agnode_t *np = agfstnode(gg); np; np = agnxtnode(gg, np)) {
58 graph[i].edges = edges++; /* reserve space for the self loop */
59 graph[i].ewgts = ewgts++;
60 int i_nedges = 1; // one for the self
61
62 if (!g)
63 g = agraphof(np);
64 for (Agedge_t *ep = agfstedge(g, np); ep; ep = agnxtedge(g, ep, np)) {
65 Agnode_t *tp = agtail(ep);
66 Agnode_t *hp = aghead(ep);
67 assert(hp != tp);
68 /* FIX: handle multiedges */
69 Agnode_t *const vp = tp == np ? hp : tp;
70 ne++;
71 i_nedges++;
72 *edges++ = ND_TVref(vp);
73 *ewgts++ = 1;
74
75 }
76
77 graph[i].nedges = i_nedges;
78 graph[i].edges[0] = i;
79 graph[i].ewgts[0] = 1 - i_nedges;
80 i++;
81 }
82 ne /= 2; /* each edge counted twice */
83 *nedges = ne;
84 return graph;
85}
86
88{
89 int level, v;
90 Hierarchy *hp = t->fisheyeParams.h;
91 for (level = 0; level < hp->nlevels; level++) {
92 for (v = 0; v < hp->nvtxs[level]; v++) {
93 ex_vtx_data *gg = hp->geom_graphs[level];
96 gg[v].old_active_level = gg[v].active_level;
97 }
98 }
99
100}
101
102/* To use:
103 * double* x_coords; // initial x coordinates
104 * double* y_coords; // initial y coordinates
105 * focus_t* fs;
106 * int ne;
107 * v_data* graph = makeGraph (topview*, &ne);
108 * hierarchy = makeHier(topview->NodeCount, ne, graph, x_coords, y_coords);
109 * freeGraph (graph);
110 * fs = initFocus (topview->Nodecount); // create focus set
111 */
113{
114 double *x_coords = gv_calloc(t->Nodecount, sizeof(double)); // initial x coordinates
115 double *y_coords = gv_calloc(t->Nodecount, sizeof(double)); // initial y coordinates
116 focus_t *fs;
117 int ne;
118 int i;
119 int closest_fine_node;
120 int cur_level = 0;
121 Hierarchy *hp;
122 gvcolor_t cl;
123 Agnode_t *np;
124
125 v_data *graph = makeGraph(g, &ne);
126
127 i=0;
128 for (np = agfstnode(g); np; np = agnxtnode(g, np))
129 {
130 x_coords[i]=ND_A(np).x;
131 y_coords[i]=ND_A(np).y;
132 i++;
133 }
134 hp = t->fisheyeParams.h =
135 makeHier(agnnodes(g), ne, graph, x_coords, y_coords,
138 free(x_coords);
139 free(y_coords);
140
141 fs = t->fisheyeParams.fs = initFocus(agnnodes(g)); // create focus set
142
143 closest_fine_node = 0; /* first node */
144 fs->num_foci = 1;
145 fs->foci_nodes[0] = closest_fine_node;
146 fs->x_foci[0] = hp->geom_graphs[cur_level][closest_fine_node].x_coord;
147 fs->y_foci[0] = hp->geom_graphs[cur_level][closest_fine_node].y_coord;
148
150 round(view->bdxRight - view->bdxLeft);
152 round(view->bdyTop - view->bdyBottom);
153
154 //topological fisheye
155
157 ("topologicalfisheyefinestcolor", view,
158 view->g[view->activeGraph]), &cl, RGBA_DOUBLE);
163 ("topologicalfisheyecoarsestcolor", view,
164 view->g[view->activeGraph]), &cl, RGBA_DOUBLE);
168
169 sscanf(agget
171 "topologicalfisheyedistortionfactor"), "%lf",
173 sscanf(agget
174 (view->g[view->activeGraph], "topologicalfisheyefinenodes"),
176 sscanf(agget
178 "topologicalfisheyecoarseningfactor"), "%lf",
180 int dist2_limit = 0;
181 sscanf(agget
182 (view->g[view->activeGraph], "topologicalfisheyedist2limit"),
183 "%d", &dist2_limit);
184 view->Topview->fisheyeParams.dist2_limit = dist2_limit != 0;
185 sscanf(agget(view->g[view->activeGraph], "topologicalfisheyeanimate"),
187
191}
192
193static void drawtopfishnodes(topview * t)
194{
196 int level, v;
197 Hierarchy *hp = t->fisheyeParams.h;
198 static int max_visible_level = 0;
199 const glCompColor srcColor = view->Topview->fisheyeParams.srcColor;
200 const glCompColor tarColor = view->Topview->fisheyeParams.tarColor;
201
202 //drawing nodes
203 glPointSize(7);
204 glBegin(GL_POINTS);
205 for (level = 0; level < hp->nlevels; level++) {
206 for (v = 0; v < hp->nvtxs[level]; v++) {
207 float x0, y0;
208 if (get_temp_coords(t, level, v, &x0, &y0)) {
209
210 if (!(-x0 / view->zoom > view->clipX1 && -x0 / view->zoom < view->clipX2 &&
211 -y0 / view->zoom > view->clipY1 && -y0 / view->zoom < view->clipY2))
212 continue;
213
214 if (max_visible_level < level)
215 max_visible_level = level;
216 if (color_interpolation(srcColor, tarColor, &color, max_visible_level, level)
217 != 0) {
218 continue;
219 }
220 glColor4d(color.R, color.G, color.B, view->defaultnodealpha);
221
222 glVertex3f(x0, y0, 0.0f);
223 }
224 }
225 }
226 glEnd();
227
228}
229
230static void drawtopfishedges(topview * t)
231{
233
234 int level, v, i, n;
235 Hierarchy *hp = t->fisheyeParams.h;
236 static int max_visible_level = 0;
237 const glCompColor srcColor = view->Topview->fisheyeParams.srcColor;
238 const glCompColor tarColor = view->Topview->fisheyeParams.tarColor;
239
240 //and edges
241 glBegin(GL_LINES);
242 for (level = 0; level < hp->nlevels; level++) {
243 for (v = 0; v < hp->nvtxs[level]; v++) {
244 v_data *g = hp->graphs[level];
245 float x0, y0;
246 if (get_temp_coords(t, level, v, &x0, &y0)) {
247 for (i = 1; i < g[v].nedges; i++) {
248 float x, y;
249 n = g[v].edges[i];
250
251
252 if (max_visible_level < level)
253 max_visible_level = level;
254 if (color_interpolation(srcColor, tarColor, &color, max_visible_level,
255 level) != 0) {
256 continue;
257 }
258 glColor4d(color.R, color.G, color.B, view->defaultnodealpha);
259
260 if (get_temp_coords(t, level, n, &x, &y)) {
261 glVertex3f(x0, y0, 0.0f);
262 glVertex3f(x, y, 0.0f);
263 } else
264 {
265 int levell, nodee;
266 find_active_ancestor_info(hp, level, n, &levell,
267 &nodee);
268 if (get_temp_coords(t, levell, nodee, &x, &y)) {
269
270 if (!(-x0 / view->zoom > view->clipX1
271 && -x0 / view->zoom < view->clipX2
272 && -y0 / view->zoom > view->clipY1
273 && -y0 / view->zoom < view->clipY2)
274 && !(-x / view->zoom > view->clipX1
275 && -x / view->zoom < view->clipX2
276 && -y / view->zoom > view->clipY1
277 && -y / view->zoom < view->clipY2))
278
279 continue;
280
281 glVertex3f(x0, y0, 0.0f);
282 glVertex3f(x, y, 0.0f);
283 }
284 }
285 }
286 }
287 }
288 }
289 glEnd();
290
291}
292
293static void get_active_frame(void) {
294 gdouble seconds = g_timer_elapsed(view->timer, NULL);
295 const int fr = (int)(seconds * 1000.0);
296 if (fr < view->total_frames) {
297 view->active_frame = fr;
298 return;
299 }
300 g_timer_stop(view->timer);
302}
303
310
311static void get_interpolated_coords(float x0, float y0, float x1, float y1,
312 int fr, int total_fr, float *x, float *y) {
313 *x = x0 + (x1 - x0) / (float)total_fr * (float)(fr + 1);
314 *y = y0 + (y1 - y0) / (float)total_fr * (float)(fr + 1);
315}
316
317static int get_temp_coords(topview *t, int level, int v, float *coord_x,
318 float *coord_y) {
319 Hierarchy *hp = t->fisheyeParams.h;
320 ex_vtx_data *gg = hp->geom_graphs[level];
321
322 if (!t->fisheyeParams.animate) {
323 if (gg[v].active_level != level)
324 return 0;
325
326 *coord_x = gg[v].physical_x_coord;
327 *coord_y = gg[v].physical_y_coord;
328 } else {
329
330
331 int OAL, AL;
332
333 float x0 = 0;
334 float y0 = 0;
335 float x1 = 0;
336 float y1 = 0;
337 AL = gg[v].active_level;
338 OAL = gg[v].old_active_level;
339
340 if (OAL < level || AL < level) //no draw
341 return 0;
342 if (OAL >= level || AL >= level) //draw the node
343 {
344 if (OAL == level && AL == level) //draw as is from old coords to new)
345 {
346 x0 = gg[v].old_physical_x_coord;
347 y0 = gg[v].old_physical_y_coord;
348 x1 = gg[v].physical_x_coord;
349 y1 = gg[v].physical_y_coord;
350 }
351 if (OAL > level && AL == level) //draw as from ancs to new)
352 {
353 find_old_physical_coords(t->fisheyeParams.h, level, v, &x0, &y0);
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_physical_coords(t->fisheyeParams.h, level, v, &x1, &y1);
360 x0 = gg[v].old_physical_x_coord;
361 y0 = gg[v].old_physical_y_coord;
362 }
364 view->total_frames, coord_x, coord_y);
365 if (x0 == 0 || x1 == 0)
366 return 0;
367
368 }
369 }
370 return 1;
371}
372
373void changetopfishfocus(topview * t, float *x, float *y, int num_foci)
374{
375
376 gvcolor_t cl;
377 focus_t *fs = t->fisheyeParams.fs;
378 int i;
379 int closest_fine_node;
380 int cur_level = 0;
381
382 Hierarchy *hp = t->fisheyeParams.h;
384 fs->num_foci = num_foci;
385 for (i = 0; i < num_foci; i++) {
386 find_closest_active_node(hp, x[i], y[i], &closest_fine_node);
387 fs->foci_nodes[i] = closest_fine_node;
388 fs->x_foci[i] =
389 hp->geom_graphs[cur_level][closest_fine_node].x_coord;
390 fs->y_foci[i] =
391 hp->geom_graphs[cur_level][closest_fine_node].y_coord;
392 }
393
394
396 (int) (view->bdxRight - view->bdxLeft);
398 (int) (view->bdyTop - view->bdyBottom);
399
401 ("topologicalfisheyefinestcolor", view,
402 view->g[view->activeGraph]), &cl, RGBA_DOUBLE);
407 ("topologicalfisheyecoarsestcolor", view,
408 view->g[view->activeGraph]), &cl, RGBA_DOUBLE);
412
413 sscanf(agget
415 "topologicalfisheyedistortionfactor"), "%lf",
417 sscanf(agget
418 (view->g[view->activeGraph], "topologicalfisheyefinenodes"),
420 sscanf(agget
422 "topologicalfisheyecoarseningfactor"), "%lf",
424 int dist2_limit = 0;
425 sscanf(agget
426 (view->g[view->activeGraph], "topologicalfisheyedist2limit"),
427 "%d", &dist2_limit);
428 view->Topview->fisheyeParams.dist2_limit = dist2_limit != 0;
429 sscanf(agget(view->g[view->activeGraph], "topologicalfisheyeanimate"),
431
433
435
437
438 if (t->fisheyeParams.animate) {
439 view->active_frame = 0;
440 g_timer_start(view->timer);
441 }
442
443}
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:48
void freeGraph(v_data *graph)
Definition delaunay.c:659
void free(void *)
node NULL
Definition grammar.y:181
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:450
#define agtail(e)
Definition cgraph.h:977
Agedge_t * agnxtedge(Agraph_t *g, Agedge_t *e, Agnode_t *n)
Definition edge.c:98
#define aghead(e)
Definition cgraph.h:978
Agedge_t * agfstedge(Agraph_t *g, Agnode_t *n)
Definition edge.c:89
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:102
void positionAllItems(Hierarchy *hp, focus_t *fs, reposition_t *parms)
Definition hier.c:21
focus_t * initFocus(int ncnt)
Definition hier.c:132
void set_active_levels(Hierarchy *hierarchy, int *foci_nodes, int num_foci, levelparms_t *parms)
Definition hierarchy.c:755
void find_old_physical_coords(Hierarchy *hierarchy, int level, int node, float *x, float *y)
Definition hierarchy.c:1085
double find_closest_active_node(Hierarchy *hierarchy, double x, double y, int *closest_fine_node)
Definition hierarchy.c:920
void find_active_ancestor_info(Hierarchy *hierarchy, int level, int node, int *levell, int *nodee)
Definition hierarchy.c:1067
void find_physical_coords(Hierarchy *hierarchy, int level, int node, float *x, float *y)
Definition hierarchy.c:1054
static int nedges
total no. of edges used in routing
Definition routespl.c:32
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
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
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:32
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
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
double height
viewport height
Definition hier.h:26
double width
viewport width
Definition hier.h:25
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:23
int * edges
Definition sparsegraph.h:24
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:80