From 89df77fed8a1a5b3721c27ae23d319e05fb255db Mon Sep 17 00:00:00 2001 From: arif Date: Tue, 17 Nov 2009 20:39:11 +0000 Subject: [PATCH] smyrna settings performance improvements --- cmd/smyrna/gui/frmobjectui.c | 18 +++ cmd/smyrna/gui/topviewsettings.c | 5 + cmd/smyrna/gui/topviewsettings.h | 1 + cmd/smyrna/smyrnadefs.h | 28 ++--- cmd/smyrna/topview.c | 193 ++++++++++++++++++------------- cmd/smyrna/viewport.c | 6 +- share/gui/smyrna.glade | 2 + 7 files changed, 150 insertions(+), 103 deletions(-) diff --git a/cmd/smyrna/gui/frmobjectui.c b/cmd/smyrna/gui/frmobjectui.c index 1ae22e7d0..5cc1c2fdf 100644 --- a/cmd/smyrna/gui/frmobjectui.c +++ b/cmd/smyrna/gui/frmobjectui.c @@ -465,6 +465,23 @@ _BB void on_txtAttr_changed(GtkWidget * widget, gpointer user_data) } +static void set_refresh_filters(ViewInfo* v,int type,char* name) +{ + if (STRCASECMP(name,"pos")==0) + v->refresh.pos=1; + if (STRCASECMP(name,"color")==0) + v->refresh.color=1; + if ((STRCASECMP(name,"size")==0) &&(type==AGNODE)) + v->refresh.nodesize=1; + if (STRCASECMP(name,"selected")==0) + v->refresh.selection=1; + if (STRCASECMP(name,"visible")==0) + v->refresh.visibility=1; + +} + + + _BB void on_attrApplyBtn_clicked (GtkWidget * widget, gpointer user_data) { int ind; @@ -523,6 +540,7 @@ _BB void on_attrApplyBtn_clicked (GtkWidget * widget, gpointer user_data) else fprintf (stderr, "on_attrApplyBtn_clicked: unknown object kind %d\n", objKind); + set_refresh_filters(view,objKind,attr_name); } _BB void on_attrRB0_clicked (GtkWidget * widget, gpointer user_data) { diff --git a/cmd/smyrna/gui/topviewsettings.c b/cmd/smyrna/gui/topviewsettings.c index a981199a6..3f421d23f 100644 --- a/cmd/smyrna/gui/topviewsettings.c +++ b/cmd/smyrna/gui/topviewsettings.c @@ -22,6 +22,11 @@ #include "topview.h" #include "memory.h" +void color_change_request(GtkWidget * widget, gpointer user_data) +{ + view->refresh.color=1; +} + void on_settingsOKBtn_clicked(GtkWidget * widget, gpointer user_data) { on_settingsApplyBtn_clicked(widget, user_data); diff --git a/cmd/smyrna/gui/topviewsettings.h b/cmd/smyrna/gui/topviewsettings.h index 185dd3c3f..abf0154f0 100644 --- a/cmd/smyrna/gui/topviewsettings.h +++ b/cmd/smyrna/gui/topviewsettings.h @@ -28,6 +28,7 @@ extern "C" { gpointer user_data); _BB void on_settingsApplyBtn_clicked(GtkWidget * widget, gpointer user_data); + _BB void color_change_request(GtkWidget * widget, gpointer user_data); extern int load_settings_from_graph(Agraph_t * g); extern int update_graph_from_settings(Agraph_t * g); diff --git a/cmd/smyrna/smyrnadefs.h b/cmd/smyrna/smyrnadefs.h index 0bdde1c0d..be1b1451e 100644 --- a/cmd/smyrna/smyrnadefs.h +++ b/cmd/smyrna/smyrnadefs.h @@ -225,27 +225,16 @@ typedef struct } topviewdata; typedef struct xdot_set xdot_set; - -//bind this to cgraph g -/* -#define GD_data(g) ((custom_graph_data*)AGDATA(g)) -#define GD_TopView(g) (GD_data(g)->TopView) -#define GD_Engine(g) (GD_data(g)->Engine) -#define GD_GraphFileName(g) (GD_data(g)->GraphFileName) -#define GD_GraphName(g) (GD_data(g)->GraphName) -#define GD_AlwaysShow(g) (GD_data(g)->AlwaysShow) -#define GD_Locked(g) (GD_data(g)->Locked) -#define GD_Modified(g) (GD_data(g)->Modified) -#define GD_selectedGraphs(g) (GD_data(g)->selectedGraphs) -#define GD_selectedGraphsCount(g) (GD_data(g)->selectedGraphsCount) -#define GD_selectedNodesCount(g) (GD_data(g)->selectedNodesCount) -#define GD_selectedNodes(g) (GD_data(g)->selectedNodes) -#define GD_selectedEdgesCount(g) (GD_data(g)->selectedEdgesCount) -#define GD_selectedEdges(g) (GD_data(g)->selectedEdges) -*/ + typedef enum { GEpixels, GEinches, GEmm } GEunit; + typedef struct { + int color; + int pos; + int selection; + int visibility; + int nodesize; - typedef enum { GEpixels, GEinches, GEmm } GEunit; + }refresh_filter; typedef struct @@ -661,6 +650,7 @@ typedef struct keymap_t keymap; mouse_action_t* mouse_actions; /*customizable moouse interraction list*/ int mouse_action_count; + refresh_filter refresh; } ViewInfo; /*rotation steps*/ diff --git a/cmd/smyrna/topview.c b/cmd/smyrna/topview.c index 42c92458f..e79af1e1e 100755 --- a/cmd/smyrna/topview.c +++ b/cmd/smyrna/topview.c @@ -81,12 +81,12 @@ static void setpositioninfo(float *x, float *y, float *z, char *buf) /*zero all values */ char* a; - - + static char bf[512]; + strcpy(bf,buf); *x = 0; *y = 0; *z = 0; - a=strtok(buf,","); + a=strtok(bf,","); if(a) *x=atof(a); a=strtok(NULL,","); @@ -130,61 +130,6 @@ static void setglCompColor(glCompColor * c, char *colorstr) /*update position info from cgraph*/ -void settvposinfo(Agraph_t * g, topview * t) -{ - int ind; - float maxedgelen, len, minedgelen, totallen; - float xmin, xmax, ymin, ymax; - topview_node *np; - topview_edge *ep; - Agsym_t *poss = agattr(g, AGNODE, "pos", 0); - assert(poss); - - maxedgelen = 0; - xmax = ymax = -MAXFLOAT; - xmin = ymin = minedgelen = MAXFLOAT; - totallen = 0; - - - /*loop nodes */ - for (ind = 0; ind < t->Nodecount; ind++) { - np = t->Nodes + ind; - setpositioninfo(&np->x, &np->y, &np->z, agxget(np->Node, poss)); - - /*distorted coordiates, same with original ones at the beginning */ - np->distorted_x = t->Nodes[ind].x; - np->distorted_y = t->Nodes[ind].y; - np->distorted_z = t->Nodes[ind].z; - xmax = MAX(xmax, np->x); - xmin = MIN(xmin, np->x); - ymax = MAX(ymax, np->y); - ymin = MIN(ymin, np->y); - } - - /*loop edges */ - for (ind = 0; ind < t->Edgecount; ind++) { - ep = t->Edges + ind; - ep->x1 = ep->Node1->x; - ep->y1 = ep->Node1->y; - ep->z1 = ep->Node1->z; - ep->x2 = ep->Node2->x; - ep->y2 = ep->Node2->y; - ep->z2 = ep->Node2->z; - len = (float) DIST(ep->x2 - ep->x1, ep->y2 - ep->y1); - totallen = totallen + len; - if (len > maxedgelen) - maxedgelen = len; - if (len < minedgelen) - minedgelen = len; - ep->length = len; - } - - t->maxedgelen = maxedgelen; - t->minedgelen = minedgelen; - t->avgedgelength = totallen / (float) t->Edgecount; - -} - /* mapbool: */ @@ -225,66 +170,132 @@ static int visible(void *obj, Agsym_t * vattr, Agsym_t * sattr) return 1; } +static int needs_refresh(ViewInfo* v) +{ + return ((view->refresh.color) || (view->refresh.nodesize) || (view->refresh.pos) || (view->refresh.selection) || (view->refresh.visibility)); +} + + + + void settvcolorinfo(Agraph_t * g, topview * t) { + float maxedgelen, len, minedgelen, totallen; + float xmin, xmax, ymin, ymax; int ind; glCompColor color; + char *color_string; + char* tempStr; topview_node *np; topview_edge *ep; Agsym_t *sel = agattr(g, AGNODE, "selected", 0); - Agsym_t *hilite = agattr(g, AGNODE, "highlighted", 0); Agsym_t *vis = agattr(g, AGNODE, "visible", 0); Agsym_t *sty = agattr(g, AGNODE, "style", 0); Agsym_t *ecolor = agattr(g, AGEDGE, "color", 0); Agsym_t *edgeid = agattr(g, AGEDGE, "edgeid", 0); - char *color_string; - char* tempStr; + Agsym_t *poss = agattr(g, AGNODE, "pos", 0); + int setpos=1; + assert(poss); + maxedgelen = 0; + xmax = ymax = -MAXFLOAT; + xmin = ymin = minedgelen = MAXFLOAT; + totallen = 0; + if (!needs_refresh(view)) + return; /*loop nodes */ - for (ind = 0; ind < t->Nodecount; ind++) { + for (ind = 0; ind < t->Nodecount; ind++) + { np = t->Nodes + ind; - setglCompColor(&color, agget(np->Node, "color")); - np->Color = color; + if(view->refresh.color) + { + setglCompColor(&color, agget(np->Node, "color")); + np->Color = color; + } /*while in the loop why dont we set some smyrna settings from graph? selected , highlighted , visible */ - np->data.Selected = boolAttr(np->Node, sel, 0); - np->data.Visible = visible(np->Node, vis, sty); - tempStr=agget(t->Nodes[ind].Node, "size"); - if(tempStr) + if(view->refresh.selection) + np->data.Selected = boolAttr(np->Node, sel, 0); + if(view->refresh.visibility) + np->data.Visible = visible(np->Node, vis, sty); + if(view->refresh.nodesize) { - if (strlen(tempStr) > 0) /*set node size */ - t->Nodes[ind].size = atof(tempStr); + tempStr=agget(t->Nodes[ind].Node, "size"); + if(tempStr) + { + if (strlen(tempStr) > 0) /*set node size */ + t->Nodes[ind].size = atof(tempStr); + } } if (t->Nodes[ind].degree > t->maxnodedegree) t->maxnodedegree = t->Nodes[ind].degree; + if(view->refresh.pos) + { + setpositioninfo(&np->x, &np->y, &np->z, agxget(np->Node, poss)); + /*distorted coordiates, same with original ones at the beginning */ + np->distorted_x = np->x; + np->distorted_y = np->y; + np->distorted_z = np->z; + xmax = MAX(xmax, np->x); + xmin = MIN(xmin, np->x); + ymax = MAX(ymax, np->y); + ymin = MIN(ymin, np->y); + } } /*loop edges */ sel = agattr(g, AGEDGE, "selected", 0); - hilite = agattr(g, AGEDGE, "highlighted", 0); vis = agattr(g, AGEDGE, "visible", 0); sty = agattr(g, AGEDGE, "style", 0); setMultiedges(g, "edgeid"); edgeid = agattr(g, AGEDGE, "edgeid", 0); /*set multi edges */ - for (ind = 0; ind < t->Edgecount; ind++) { + for (ind = 0; ind < t->Edgecount; ind++) + { ep = t->Edges + ind; - if (ecolor && (color_string = agxget(ep->Edge, ecolor)) - && (*color_string != '\0')&& (strlen(color_string)>0)) - setglCompColor(&color, color_string); - else { /*use color theme */ - getcolorfromschema(view->colschms, ep->length, t->maxedgelen, - &color); - color.tag = 0; + if(view->refresh.color) + { + if (ecolor && (color_string = agxget(ep->Edge, ecolor)) + && (*color_string != '\0')&& (strlen(color_string)>0)) + setglCompColor(&color, color_string); + else { /*use color theme */ + getcolorfromschema(view->colschms, ep->length, t->maxedgelen,&color); + color.tag = 0;} + ep->Color = color; + } ep->data.edgeid = boolAttr(ep->Edge, edgeid, 0); - ep->Color = color; - ep->data.Selected = boolAttr(ep->Edge, sel, 0); - ep->data.Visible = visible(ep->Edge, vis, sty); + if(view->refresh.selection) + ep->data.Selected = boolAttr(ep->Edge, sel, 0); + if(view->refresh.visibility) + ep->data.Visible = visible(ep->Edge, vis, sty); + if(view->refresh.pos) + { + ep->x1 = ep->Node1->x; + ep->y1 = ep->Node1->y; + ep->z1 = ep->Node1->z; + ep->x2 = ep->Node2->x; + ep->y2 = ep->Node2->y; + ep->z2 = ep->Node2->z; + len = (float) DIST(ep->x2 - ep->x1, ep->y2 - ep->y1); + totallen = totallen + len; + if (len > maxedgelen) + maxedgelen = len; + if (len < minedgelen) + minedgelen = len; + ep->length = len; + } } + if(view->refresh.pos) + { + t->maxedgelen = maxedgelen; + t->minedgelen = minedgelen; + t->avgedgelength = totallen / (float) t->Edgecount; + } + } @@ -341,6 +352,15 @@ void init_node_size(Agraph_t * g, topview * t) } +static void reset_refresh(ViewInfo* v) +{ + v->refresh.color=0; + v->refresh.nodesize=0; + v->refresh.pos=0; + v->refresh.selection=0; + v->refresh.visibility=0; + +} void update_topview(Agraph_t * g, topview * t, int init) { char *info_file; @@ -352,11 +372,18 @@ void update_topview(Agraph_t * g, topview * t, int init) if (init) preparetopview(g, t); - settvposinfo(g, t); settvcolorinfo(g, t); set_boundaries(t); settvxdot(view->g[view->activeGraph], view->Topview); init_node_size(g, t); + reset_refresh(view); + if (init)/*one time call to calculate right colors*/ + { + view->refresh.color=1; + settvcolorinfo(g, t); + reset_refresh(view); + } + /*This is a temp code , need to be removed after Xue's demo */ #if UNUSED info_file = agget(g, "demo_file"); diff --git a/cmd/smyrna/viewport.c b/cmd/smyrna/viewport.c index e11e831bb..9651f4b08 100755 --- a/cmd/smyrna/viewport.c +++ b/cmd/smyrna/viewport.c @@ -504,7 +504,11 @@ void init_viewport(ViewInfo * view) view->arcball = NEW(ArcBall_t); view->keymap.down=0; load_mouse_actions (NULL,view); - + view->refresh.color=1; + view->refresh.pos=1; + view->refresh.selection=1; + view->refresh.visibility=1; + view->refresh.nodesize=1; /*add default camera */ //create fontset } diff --git a/share/gui/smyrna.glade b/share/gui/smyrna.glade index ab0e4b9fd..07701b4d0 100755 --- a/share/gui/smyrna.glade +++ b/share/gui/smyrna.glade @@ -2382,6 +2382,7 @@ Rain Forest False True True + 1 @@ -2446,6 +2447,7 @@ Rain Forest True * False + 1 -- 2.50.1