]> granicus.if.org Git - graphviz/commitdiff
fisheye rescaling bug is fixed
authorarif <devnull@localhost>
Tue, 10 Mar 2009 19:23:36 +0000 (19:23 +0000)
committerarif <devnull@localhost>
Tue, 10 Mar 2009 19:23:36 +0000 (19:23 +0000)
cmd/smyrna/glmotion.c
cmd/smyrna/topfisheyeview.c
lib/topfish/rescale_layout.c

index c3c94e810e8e27f3bef76b50df73ae50614c6971..ee8b08db2ce1c8d46ef690595ffa4a7f4980c0b7 100644 (file)
@@ -46,8 +46,8 @@ int glmotion_main(ViewInfo * v,GdkEventMotion * event,GtkWidget * widget)
        && ((v->mouse.mouse_mode == MM_MAGNIFIER)
            || (v->mouse.mouse_mode == MM_FISHEYE_MAGNIFIER)))
        {
-               v->mouse.mouse_X = (int)event->x;
-               v->mouse.mouse_Y = (int) event->y;
+               v->mouse.mouse_X = event->x;
+               v->mouse.mouse_Y =  event->y;
                redraw = TRUE;
     }
 
index 6c3149093fbb79d1df9535139c750f13e135058c..05e032b1db9107be748b4ddbe75c30d933ce3f0a 100644 (file)
@@ -42,6 +42,7 @@ static double dist3d(double x1, double y1, double z1, double x2, double y2,
     return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) +
                (z1 - z2) * (z1 - z2));
 }
+static void drawtopologicalfisheyestatic(topview * t);
 
 
 static double G(double x)
@@ -57,43 +58,48 @@ void fisheye_polar(double x_focus, double y_focus, topview * t)
     double distance, distorted_distance, ratio, range;
 
     range = 0;
-    for (i = 1; i < t->Nodecount; i++) {
-       if (point_within_ellips_with_coords
-           ((float) x_focus, (float) y_focus, (float) view->fmg.R,
-            (float) view->fmg.R, t->Nodes[i].x, t->Nodes[i].y)) {
-           range =
-               MAX(range,
+    for (i = 1; i < t->Nodecount; i++) 
+       {
+               if (point_within_ellips_with_coords
+                       ((float) x_focus, (float) y_focus, (float) view->fmg.R,
+                       (float) view->fmg.R, t->Nodes[i].x, t->Nodes[i].y)) 
+               {
+                               range = MAX(range,
                    dist(t->Nodes[i].x, t->Nodes[i].y, x_focus, y_focus));
-       }
+               }
     }
 
-    for (i = 1; i < t->Nodecount; i++) {
+    for (i = 1; i < t->Nodecount; i++) 
+       {
 
-       if (point_within_ellips_with_coords
-           ((float) x_focus, (float) y_focus, (float) view->fmg.R,
-            (float) view->fmg.R, t->Nodes[i].x, t->Nodes[i].y)) {
-           distance =
-               dist(t->Nodes[i].x, t->Nodes[i].y, x_focus, y_focus);
-           distorted_distance = G(distance / range) * range;
-           if (distance != 0) {
-               ratio = distorted_distance / distance;
-           } else {
-               ratio = 0;
-           }
-           t->Nodes[i].distorted_x =
-               (float) x_focus + (t->Nodes[i].x -
-                                  (float) x_focus) * (float) ratio;
-           t->Nodes[i].distorted_y =
-               (float) y_focus + (t->Nodes[i].y -
-                                  (float) y_focus) * (float) ratio;
-           t->Nodes[i].zoom_factor =
-               (float) 1 *(float) distorted_distance / (float) distance;
-       } else {
-           t->Nodes[i].distorted_x = t->Nodes[i].x;
-           t->Nodes[i].distorted_y = t->Nodes[i].y;
-           t->Nodes[i].zoom_factor = 1;
+               if (point_within_ellips_with_coords
+                       ((float) x_focus, (float) y_focus, (float) view->fmg.R,
+                       (float) view->fmg.R, t->Nodes[i].x, t->Nodes[i].y)) 
+               {
+                       distance =
+                               dist(t->Nodes[i].x, t->Nodes[i].y, x_focus, y_focus);
+                               distorted_distance = G(distance / range) * range;
+                       if (distance != 0) 
+                       {
+                               ratio = distorted_distance / distance;
+                       }
+                       else 
+                       {
+                               ratio = 0;
+                       }
+                       t->Nodes[i].distorted_x =
+                                       (float) x_focus + (t->Nodes[i].x -  (float) x_focus) * (float) ratio;
+                   t->Nodes[i].distorted_y =
+                       (float) y_focus + (t->Nodes[i].y - (float) y_focus) * (float) ratio;
+                   t->Nodes[i].zoom_factor =(float) 1 *(float) distorted_distance / (float) distance;
+               }
+               else 
+               {
+                       t->Nodes[i].distorted_x = t->Nodes[i].x;
+                       t->Nodes[i].distorted_y = t->Nodes[i].y;
+                       t->Nodes[i].zoom_factor = 1;
+               }
        }
-    }
 }
 void fisheye_spherical(double x_focus, double y_focus, double z_focus,
                       topview * t)
@@ -251,12 +257,13 @@ void prepare_topological_fisheye(topview* t)
 
     view->Topview->parms.repos.width =(int) (view->bdxRight-view->bdxLeft);
     view->Topview->parms.repos.height =(int) (view->bdyTop-view->bdyBottom);
+       view->Topview->parms.repos.rescale=Polar;
+
        sscanf(agget(view->g[0],"topologicalfisheyedistortionfactor"),"%lf",&view->Topview->parms.repos.distortion);
        sscanf(agget(view->g[0],"topologicalfisheyefinenodes"),"%d",&view->Topview->parms.level.num_fine_nodes);
        sscanf(agget(view->g[0],"topologicalfisheyecoarseningfactor"),"%lf",&view->Topview->parms.level.coarsening_rate);
        sscanf(agget(view->g[0],"topologicalfisheyedist2limit"),"%d",&view->Topview->parms.hier.dist2_limit);
        sscanf(agget(view->g[0],"topologicalfisheyeanimate"),"%d",&view->Topview->animate);
-
                
        set_active_levels(hp, fs->foci_nodes, fs->num_foci, &(t->parms.level));
        positionAllItems(hp, fs, &(t->parms.repos));
@@ -372,6 +379,7 @@ void drawtopfishnodelabels(topview* t)
                                        fontColorA(view->fontset->fonts[view->fontset->activefont],0, 0, 1, 1);
                                        fontSize(view->fontset->fonts[view->fontset->activefont],fs);
                                        fontDrawString(view->fontset->fonts[view->fontset->activefont],gg[v].physical_x_coord,gg[v].physical_y_coord, (fs*strlen(buf)*0.4),buf);
+                                       printf ("focus coords : %f , %f\n",gg[v].physical_x_coord,gg[v].physical_y_coord);
                                }
                                else if (finenodes)
                                {
@@ -454,6 +462,8 @@ void drawtopologicalfisheye(topview * t)
 {
        get_active_frame(t);
        drawtopfishnodes(t);
+//     drawtopologicalfisheyestatic(t);
+
        drawtopfishedges(t);
        if(!t->animate)
                drawtopfishnodelabels(t);
@@ -577,13 +587,12 @@ void changetopfishfocus(topview * t, float *x, float *y,
        find_closest_active_node(hp, x[i], y[i], &closest_fine_node);
        fs->foci_nodes[i] = closest_fine_node;
        fs->x_foci[i] =
-               hp->geom_graphs[cur_level][closest_fine_node].physical_x_coord;
+               hp->geom_graphs[cur_level][closest_fine_node].x_coord;
        fs->y_foci[i] =
-               hp->geom_graphs[cur_level][closest_fine_node].physical_y_coord;
+               hp->geom_graphs[cur_level][closest_fine_node].y_coord;
     }
 
 
-    set_active_levels(hp, fs->foci_nodes, fs->num_foci, &(t->parms.level));
     view->Topview->parms.repos.width =(int) (view->bdxRight-view->bdxLeft);
     view->Topview->parms.repos.height =(int) (view->bdyTop-view->bdyBottom);
 
@@ -595,6 +604,7 @@ void changetopfishfocus(topview * t, float *x, float *y,
 
 
 
+    set_active_levels(hp, fs->foci_nodes, fs->num_foci, &(t->parms.level));
 
 
        positionAllItems(hp, fs, &(t->parms.repos));
@@ -660,4 +670,62 @@ int get_active_frame(topview* t)
 }
 
 
+void drawtopologicalfisheyestatic(topview * t)
+{
+    int level, v, i, n;
+    Hierarchy* hp = t->h;
+
+       glPointSize(15);
+       glBegin(GL_POINTS);
+    for (level=0;level < hp->nlevels;level++) {
+       for (v=0;v < hp->nvtxs[level]; v++) {
+           ex_vtx_data* gg = hp->geom_graphs[level];
+           vtx_data* g = hp->graphs[level];
+           if(gg[v].active_level==level) {
+               double x0 = gg[v].physical_x_coord;
+               double y0 = gg[v].physical_y_coord;
+//             glColor3f((GLfloat)(hp->nlevels-level)/(GLfloat)hp->nlevels,(GLfloat)level/(GLfloat)hp->nlevels,0);
+               glColor4f(0,1,0,0.2);
+               glVertex3f((GLfloat)x0,(GLfloat)y0,(GLfloat)0);
+           }
+       }
+    }
+    glEnd();
+
+       
+       
+       
+/*     glBegin(GL_LINES);
+    for (level=0;level < hp->nlevels;level++) {
+       for (v=0;v < hp->nvtxs[level]; v++) {
+           ex_vtx_data* gg = hp->geom_graphs[level];
+           vtx_data* g = hp->graphs[level];
+           if(gg[v].active_level==level) {
+               double x0 = gg[v].physical_x_coord;
+               double y0 = gg[v].physical_y_coord;
+
+               for (i=1;i < g[v].nedges;i++) {
+                   double x,y;
+                       n = g[v].edges[i];
+                       glColor3f((GLfloat)(hp->nlevels-level)/(GLfloat)hp->nlevels,(GLfloat)level/(GLfloat)hp->nlevels,0);
+                       if (gg[n].active_level == level) {
+                       if (v < n) {
+                           x = gg[n].physical_x_coord;
+                           y = gg[n].physical_y_coord;
+                           glVertex3f((GLfloat)x0,(GLfloat)y0,(GLfloat)0);
+                           glVertex3f((GLfloat)x,(GLfloat)y,(GLfloat)0);
+                       }
+                       }
+                   else if (gg[n].active_level > level) {
+                       find_physical_coords(hp, level, n, &x, &y);
+                       glVertex3f((GLfloat)x0,(GLfloat)y0,(GLfloat)0);
+                       glVertex3f((GLfloat)x,(GLfloat)y,(GLfloat)0);
+                   }
+               }
+           }
+       }
+    }
+    glEnd();*/
+}
+
 
index 62e7ec72c4332ab6d071b4ccf4f91112337faa00..99751be690f28a83bf19af1dd072a33c0823c262 100644 (file)
@@ -338,14 +338,16 @@ rescale_layout_polarFocus(v_data * graph, int n,
     int *ordering;
     double ratio;
 
-    for (i = 0; i < n; i++) {
-       distances[i] = DIST(x_coords[i], y_coords[i], x_focus, y_focus);
+    for (i = 0; i < n; i++) 
+       {
+               distances[i] = DIST(x_coords[i], y_coords[i], x_focus, y_focus);
     }
     cpvec(orig_distances, 0, n - 1, distances);
 
     ordering = N_NEW(n, int);
-    for (i = 0; i < n; i++) {
-       ordering[i] = i;
+    for (i = 0; i < n; i++) 
+       {
+               ordering[i] = i;
     }
     quicksort_place(distances, ordering, 0, n - 1);
 
@@ -353,41 +355,51 @@ rescale_layout_polarFocus(v_data * graph, int n,
     smoothed_densities = smooth_vec(densities, ordering, n, interval, smoothed_densities);
 
     // rescale distances
-    if (distortion < 1.01 && distortion > 0.99) {
-       for (i = 1; i < n; i++) {
-           distances[ordering[i]] =
-               distances[ordering[i - 1]] + (orig_distances[ordering[i]] -
+    if (distortion < 1.01 && distortion > 0.99) 
+       {
+               for (i = 1; i < n; i++) 
+               {
+                       distances[ordering[i]] =        distances[ordering[i - 1]] + (orig_distances[ordering[i]] -
                                              orig_distances[ordering
                                                             [i -
                                                              1]]) / smoothed_densities[ordering[i]];
-       }
-    } else {
-       double factor;
-       // just to make milder behavior:
-       if (distortion >= 0) {
-           factor = sqrt(distortion);
-       } else {
-           factor = -sqrt(-distortion);
-       }
-       for (i = 1; i < n; i++) {
-           distances[ordering[i]] =
-               distances[ordering[i - 1]] + (orig_distances[ordering[i]] -
+               }
+    } else 
+       {
+               double factor;
+               // just to make milder behavior:
+               if (distortion >= 0) 
+               {
+                       factor = sqrt(distortion);
+               } 
+               else 
+               {
+                       factor = -sqrt(-distortion);
+               }
+               for (i = 1; i < n; i++) 
+               {
+                       distances[ordering[i]] =
+                               distances[ordering[i - 1]] + (orig_distances[ordering[i]] -
                                              orig_distances[ordering
                                                             [i -
                                                              1]]) /
-               pow(smoothed_densities[ordering[i]], factor);
-       }
+                       pow(smoothed_densities[ordering[i]], factor);
+               }
     }
 
     // compute new coordinate:
-    for (i = 0; i < n; i++) {
-       if (orig_distances[i] == 0) {
-           ratio = 0;
-       } else {
-           ratio = distances[i] / orig_distances[i];
-       }
-       x_coords[i] = x_focus + (x_coords[i] - x_focus) * ratio;
-       y_coords[i] = y_focus + (y_coords[i] - y_focus) * ratio;
+    for (i = 0; i < n; i++) 
+       {
+               if (orig_distances[i] == 0) 
+               {
+                       ratio = 0;
+               } 
+               else 
+               {
+                       ratio = distances[i] / orig_distances[i];
+               }
+               x_coords[i] = x_focus + (x_coords[i] - x_focus) * ratio;
+               y_coords[i] = y_focus + (y_coords[i] - y_focus) * ratio;
     }
 
     free(densities);
@@ -413,29 +425,34 @@ rescale_layout_polar(double *x_coords, double *y_coords,
 
     width -= 2 * margin;
     height -= 2 * margin;
+       printf ("polar focus coords : %f , %f\n",x_foci[0],y_foci[0]);
+
 
     // compute original aspect ratio
     minX = maxX = x_coords[0];
     minY = maxY = y_coords[0];
-    for (i = 1; i < n; i++) {
-       if (x_coords[i] < minX)
-           minX = x_coords[i];
-       if (y_coords[i] < minY)
-           minY = y_coords[i];
-       if (x_coords[i] > maxX)
-           maxX = x_coords[i];
-       if (y_coords[i] > maxY)
-           maxY = y_coords[i];
+    for (i = 1; i < n; i++) 
+       {
+               if (x_coords[i] < minX)
+                   minX = x_coords[i];
+               if (y_coords[i] < minY)
+                       minY = y_coords[i];
+               if (x_coords[i] > maxX)
+                       maxX = x_coords[i];
+               if (y_coords[i] > maxY)
+                       maxY = y_coords[i];
     }
     aspect_ratio = (maxX - minX) / (maxY - minY);
 
     // construct mutual neighborhood graph
     graph = UG_graph(x_coords, y_coords, n, 0);
 
-    if (num_foci == 1) {       // accelerate execution of most common case
-       rescale_layout_polarFocus(graph, n, x_coords, y_coords, x_foci[0],
+    if (num_foci == 1) 
+       {       // accelerate execution of most common case
+               rescale_layout_polarFocus(graph, n, x_coords, y_coords, x_foci[0],
                                  y_foci[0], interval, distortion);
-    } else {
+    } else
+       {
        // average-based rescale
        double *final_x_coords = N_NEW(n, double);
        double *final_y_coords = N_NEW(n, double);