[xiph-commits] r12277 - trunk/sushivision

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Sun Dec 31 15:55:56 PST 2006


Author: xiphmont
Date: 2006-12-31 15:55:53 -0800 (Sun, 31 Dec 2006)
New Revision: 12277

Modified:
   trunk/sushivision/dimension.c
   trunk/sushivision/dimension.h
   trunk/sushivision/example_fractal.c
   trunk/sushivision/panel-1d.c
   trunk/sushivision/panel-2d.c
   trunk/sushivision/sushivision.h
Log:
Welcome, picklist dimensions.

Added gratuitous 'max iter' picklist to fractal example



Modified: trunk/sushivision/dimension.c
===================================================================
--- trunk/sushivision/dimension.c	2006-12-31 22:59:36 UTC (rev 12276)
+++ trunk/sushivision/dimension.c	2006-12-31 23:55:53 UTC (rev 12277)
@@ -29,7 +29,7 @@
 /* modules attempts to encapsulate and hide differences between the
    different types of dimensions with respect to widgets, iterators,
    shared dimensions */
-scalespace sushiv_dimension_datascale(sushiv_dimension_t *d, scalespace x){
+scalespace _sushiv_dimension_datascale(sushiv_dimension_t *d, scalespace x){
   scalespace ret;
   memset(&ret,0,sizeof(ret));
 
@@ -67,11 +67,11 @@
 }
 
 /* takes the data scale, not the panel plot scale */
-int sushiv_dimension_data_width(sushiv_dimension_t *d, scalespace *datascale){
+int _sushiv_dimension_data_width(sushiv_dimension_t *d, scalespace *datascale){
   return datascale->pixels;
 }
 
-static void sushiv_dimension_center_callback(void *data, int buttonstate){
+static void _sushiv_dimension_center_callback(void *data, int buttonstate){
   gdk_threads_enter();
 
   sushiv_dim_widget_t *dw = (sushiv_dim_widget_t *)data;
@@ -115,7 +115,7 @@
   gdk_threads_leave();
 }
 
-static void sushiv_dimension_bracket_callback(void *data, int buttonstate){
+static void _sushiv_dimension_bracket_callback(void *data, int buttonstate){
   gdk_threads_enter();
 
   sushiv_dim_widget_t *dw = (sushiv_dim_widget_t *)data;
@@ -163,7 +163,7 @@
   gdk_threads_leave();
 }
 
-static void sushiv_dimension_dropdown_callback(void *data){
+static void _sushiv_dimension_dropdown_callback(GtkWidget *dummy, void *data){
   gdk_threads_enter();
 
   sushiv_dim_widget_t *dw = (sushiv_dim_widget_t *)data;
@@ -207,7 +207,7 @@
 }
 
 /* undo/redo have to frob widgets; this is indirected here too */
-void sushiv_dimension_set_value(sushiv_dim_widget_t *dw, int thumb, double val){
+void _sushiv_dimension_set_value(sushiv_dim_widget_t *dw, int thumb, double val){
   sushiv_dimension_t *d = dw->dl->d;
 
   switch(d->type){
@@ -240,12 +240,44 @@
   }
 }
 
-void sushiv_dim_widget_set_thumb_active(sushiv_dim_widget_t *dw, int thumb, int active){
+/* external version with externalish API */
+void sushiv_dimension_set_value(sushiv_instance_t *s, int dim_number, int thumb, double val){
+  sushiv_dimension_t *d;
+
+  if(dim_number<0 || dim_number>=s->dimensions){
+    fprintf(stderr,"Dimension number %d out of range.\n",dim_number);
+    return;
+  }
+
+  d=s->dimension_list[dim_number];
+  if(!d){
+    fprintf(stderr,"Dimension %d does not exist.\n",dim_number);
+    return;
+  }
+
+  if(!d->private->widgets){
+    switch(thumb){
+    case 0:
+      d->bracket[0] = val;
+      break;
+    case 1:
+      d->val = val;
+      break;
+    default:
+      d->bracket[1] = val;
+      break;
+    }
+  }else
+    _sushiv_dimension_set_value(d->private->widget_list[0],thumb,val);
+  
+}
+
+void _sushiv_dim_widget_set_thumb_active(sushiv_dim_widget_t *dw, int thumb, int active){
   if(dw->scale)
     slider_set_thumb_active(dw->scale,thumb,active);
 }
 
-sushiv_dim_widget_t *sushiv_new_dimension_widget(sushiv_dimension_list_t *dl,   
+sushiv_dim_widget_t *_sushiv_new_dimension_widget(sushiv_dimension_list_t *dl,   
 						 void (*center_callback)(sushiv_dimension_list_t *),
 						 void (*bracket_callback)(sushiv_dimension_list_t *)){
   
@@ -261,12 +293,16 @@
   case SUSHIV_DIM_DISCRETE:
     /* Continuous and discrete dimensions get sliders */
     {
+      double v[3];
       GtkWidget **sl = calloc(3,sizeof(*sl));
       dw->t = GTK_TABLE(gtk_table_new(1,3,0));
-    
-      sl[0] = slice_new(sushiv_dimension_bracket_callback,dw);
-      sl[1] = slice_new(sushiv_dimension_center_callback,dw);
-      sl[2] = slice_new(sushiv_dimension_bracket_callback,dw);
+      v[0]=d->bracket[0];
+      v[1]=d->val;
+      v[2]=d->bracket[1];
+
+      sl[0] = slice_new(_sushiv_dimension_bracket_callback,dw);
+      sl[1] = slice_new(_sushiv_dimension_center_callback,dw);
+      sl[2] = slice_new(_sushiv_dimension_bracket_callback,dw);
       
       gtk_table_attach(dw->t,sl[0],0,1,0,1,
 		       GTK_EXPAND|GTK_FILL,0,0,0);
@@ -278,9 +314,9 @@
       dw->scale = slider_new((Slice **)sl,3,d->scale->label_list,d->scale->val_list,
 			     d->scale->vals,0);
 
-      slice_thumb_set((Slice *)sl[0],d->scale->val_list[0]);
-      slice_thumb_set((Slice *)sl[1],0);
-      slice_thumb_set((Slice *)sl[2],d->scale->val_list[d->scale->vals-1]);
+      slice_thumb_set((Slice *)sl[0],v[0]);
+      slice_thumb_set((Slice *)sl[1],v[1]);
+      slice_thumb_set((Slice *)sl[2],v[2]);
     }
     break;
   case SUSHIV_DIM_PICKLIST:
@@ -292,12 +328,14 @@
       dw->menu=gtk_combo_box_new_markup();
       for(j=0;j<d->scale->vals;j++)
 	gtk_combo_box_append_text (GTK_COMBO_BOX (dw->menu), d->scale->label_list[j]);
-      gtk_combo_box_set_active(GTK_COMBO_BOX(dw->menu),0);
+
       g_signal_connect (G_OBJECT (dw->menu), "changed",
-			G_CALLBACK (sushiv_dimension_dropdown_callback), dw);
+			G_CALLBACK (_sushiv_dimension_dropdown_callback), dw);
       
       gtk_table_attach(dw->t,dw->menu,0,1,0,1,
 		       GTK_EXPAND|GTK_FILL,GTK_SHRINK,5,0);
+      _sushiv_dimension_set_value(dw,1,d->val);
+      //gtk_combo_box_set_active(GTK_COMBO_BOX(dw->menu),0);
     }
     break;
   default:
@@ -357,6 +395,10 @@
   d->type = SUSHIV_DIM_CONTINUOUS;
   d->private = calloc(1, sizeof(*d->private));
 
+  d->bracket[0]=d->scale->val_list[0];
+  d->val = 0;
+  d->bracket[1]=d->scale->val_list[d->scale->vals-1];
+
   return 0;
 }
 

Modified: trunk/sushivision/dimension.h
===================================================================
--- trunk/sushivision/dimension.h	2006-12-31 22:59:36 UTC (rev 12276)
+++ trunk/sushivision/dimension.h	2006-12-31 23:55:53 UTC (rev 12277)
@@ -51,10 +51,10 @@
   sushiv_dim_widget_t **widget_list;
 };
 
-extern scalespace sushiv_dimension_datascale(sushiv_dimension_t *d, scalespace x);
-extern int sushiv_dimension_data_width(sushiv_dimension_t *d, scalespace *datascale);
-extern void sushiv_dimension_set_value(sushiv_dim_widget_t *d, int thumb, double val);
-extern void sushiv_dim_widget_set_thumb_active(sushiv_dim_widget_t *dw, int thumb, int active);
-extern sushiv_dim_widget_t * sushiv_new_dimension_widget(sushiv_dimension_list_t *dl,   
+extern scalespace _sushiv_dimension_datascale(sushiv_dimension_t *d, scalespace x);
+extern int _sushiv_dimension_data_width(sushiv_dimension_t *d, scalespace *datascale);
+extern void _sushiv_dimension_set_value(sushiv_dim_widget_t *d, int thumb, double val);
+extern void _sushiv_dim_widget_set_thumb_active(sushiv_dim_widget_t *dw, int thumb, int active);
+extern sushiv_dim_widget_t *_sushiv_new_dimension_widget(sushiv_dimension_list_t *dl,   
 							 void (*center_callback)(sushiv_dimension_list_t *),
 							 void (*bracket_callback)(sushiv_dimension_list_t *));

Modified: trunk/sushivision/example_fractal.c
===================================================================
--- trunk/sushivision/example_fractal.c	2006-12-31 22:59:36 UTC (rev 12276)
+++ trunk/sushivision/example_fractal.c	2006-12-31 23:55:53 UTC (rev 12277)
@@ -25,21 +25,21 @@
 #include "sushivision.h"
 
 sushiv_instance_t *s;
-#define MAX_ITER 1024
 
 static void fractal_objective(double *d, double *ret){
+  int max_iter = d[4];
   int i;
   double z, zi, zz;
   const double c=d[0],ci=d[1];
-
+  
   *ret=NAN;
   z = d[2]; zi = d[3];
-  for(i=0;i<MAX_ITER;i++){
+  for(i=0;i<max_iter;i++){
     zz = z*z - zi*zi + c;
     zi = 2.0*z*zi + ci;
     z  = zz;
     if (z*z + zi*zi > 4.0){
-      *ret = (double)i/MAX_ITER;
+      *ret = (double)i/max_iter;
       return;
     }
   }
@@ -62,14 +62,23 @@
   sushiv_new_dimension(s,3,"Im(z0)",
 		       5,(double []){-2.25,-1,0,1,2.25},
 		       NULL,0);
-  
+
+  sushiv_new_dimension_picklist(s,4,"Max Iterations",
+				4,
+				(double []){100,1000,10000,100000},
+				(char *[]){"one hundred",
+					     "one thousand",
+					     "ten thousand",
+					     "one hundred thousand"},
+				NULL,0);
+
   sushiv_new_objective(s,0,"fractal",
-		       4,(double []){0, .01, .1, 1.0},
+		       5,(double []){0, .001, .01, .1, 1.0},
 		       fractal_objective,0);
 
   sushiv_new_panel_2d(s,0,"Mandel/Julia Fractal",
 		      (int []){0,-1},
-		      (int []){0,1,2,3,-1},
+		      (int []){0,1,2,3,4,-1},
 		      0);
 
   sushiv_new_panel_1d_linked(s,1,"X Slice",s->objective_list[0]->scale,
@@ -79,6 +88,8 @@
   sushiv_new_panel_1d_linked(s,2,"Y Slice",s->objective_list[0]->scale,
 			     (int []){0,-1},
 			     0,SUSHIV_PANEL_LINK_Y | SUSHIV_PANEL_FLIP);
+
+  sushiv_dimension_set_value(s,4,1,10000);
   
   return 0;
 }

Modified: trunk/sushivision/panel-1d.c
===================================================================
--- trunk/sushivision/panel-1d.c	2006-12-31 22:59:36 UTC (rev 12276)
+++ trunk/sushivision/panel-1d.c	2006-12-31 23:55:53 UTC (rev 12277)
@@ -326,12 +326,12 @@
     if(p1->dim_xb[i] &&
        gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p1->dim_xb[i]))){
       // make all thumbs visible 
-      sushiv_dim_widget_set_thumb_active(p->private->dim_scales[i],0,1);
-      sushiv_dim_widget_set_thumb_active(p->private->dim_scales[i],2,1);
+      _sushiv_dim_widget_set_thumb_active(p->private->dim_scales[i],0,1);
+      _sushiv_dim_widget_set_thumb_active(p->private->dim_scales[i],2,1);
     }else{
       // make bracket thumbs invisible */
-      sushiv_dim_widget_set_thumb_active(p->private->dim_scales[i],0,0);
-      sushiv_dim_widget_set_thumb_active(p->private->dim_scales[i],2,0);
+      _sushiv_dim_widget_set_thumb_active(p->private->dim_scales[i],0,0);
+      _sushiv_dim_widget_set_thumb_active(p->private->dim_scales[i],2,0);
     }
   } 
 }
@@ -421,7 +421,7 @@
 			      p1->x_d->name);
     
     // the data iterator may need to be mapped to the dimension type
-    p1->vs = sushiv_dimension_datascale(p1->x_d, p1->vs);
+    p1->vs = _sushiv_dimension_datascale(p1->x_d, p1->vs);
 
     if(p1->data_size != dw){
       if(p1->data_vec){
@@ -632,7 +632,7 @@
       sushiv_dimension_t *d = p->dimension_list[i].d;
       sushiv_panel1d_t *p1 = p->subtype->p1;
       if(d == p1->x_d)
-	sushiv_dimension_set_value(p->private->dim_scales[i],1,x);
+	_sushiv_dimension_set_value(p->private->dim_scales[i],1,x);
 	            
       p1->oldbox_active = 0;
     }
@@ -656,9 +656,9 @@
     _sushiv_panel_undo_suspend(p);
 
     crosshair_callback(p);
-
-    sushiv_dimension_set_value(p1->x_scale,0,p1->oldbox[0]);
-    sushiv_dimension_set_value(p1->x_scale,2,p1->oldbox[1]);
+    
+    _sushiv_dimension_set_value(p1->x_scale,0,p1->oldbox[0]);
+    _sushiv_dimension_set_value(p1->x_scale,2,p1->oldbox[1]);
     p1->oldbox_active = 0;
     _sushiv_panel_undo_resume(p);
     break;
@@ -822,9 +822,9 @@
   }
 
   for(i=0;i<p->dimensions;i++){
-    sushiv_dimension_set_value(p->private->dim_scales[i],0,u->dim_vals[0][i]);
-    sushiv_dimension_set_value(p->private->dim_scales[i],1,u->dim_vals[1][i]);
-    sushiv_dimension_set_value(p->private->dim_scales[i],2,u->dim_vals[2][i]);
+    _sushiv_dimension_set_value(p->private->dim_scales[i],0,u->dim_vals[0][i]);
+    _sushiv_dimension_set_value(p->private->dim_scales[i],1,u->dim_vals[1][i]);
+    _sushiv_dimension_set_value(p->private->dim_scales[i],2,u->dim_vals[2][i]);
   }
 
   if(p1->dim_xb && u->x_d<p->dimensions && p1->dim_xb[u->x_d])
@@ -835,9 +835,9 @@
 
   if(link){
     /* doesn't matter which widget belonging to the dimension is the one that gets set */
-    sushiv_dimension_set_value(p1->x_d->private->widget_list[0],0,u->dim_vals[0][p->dimensions]);
-    sushiv_dimension_set_value(p1->x_d->private->widget_list[0],1,u->dim_vals[1][p->dimensions]);
-    sushiv_dimension_set_value(p1->x_d->private->widget_list[0],2,u->dim_vals[2][p->dimensions]);
+    _sushiv_dimension_set_value(p1->x_d->private->widget_list[0],0,u->dim_vals[0][p->dimensions]);
+    _sushiv_dimension_set_value(p1->x_d->private->widget_list[0],1,u->dim_vals[1][p->dimensions]);
+    _sushiv_dimension_set_value(p1->x_d->private->widget_list[0],2,u->dim_vals[2][p->dimensions]);
   }
 
   if(u->box_active){
@@ -1193,7 +1193,7 @@
       }
 
       p->private->dim_scales[i] = 
-	sushiv_new_dimension_widget(p->dimension_list+i,center_callback_1d,bracket_callback_1d);
+	_sushiv_new_dimension_widget(p->dimension_list+i,center_callback_1d,bracket_callback_1d);
       
       gtk_table_attach(GTK_TABLE(p1->dim_table),
 		       GTK_WIDGET(p->private->dim_scales[i]->t),

Modified: trunk/sushivision/panel-2d.c
===================================================================
--- trunk/sushivision/panel-2d.c	2006-12-31 22:59:36 UTC (rev 12276)
+++ trunk/sushivision/panel-2d.c	2006-12-31 23:55:53 UTC (rev 12277)
@@ -265,12 +265,12 @@
        (p2->dim_yb[i] &&
 	gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p2->dim_yb[i])))){
       // make all thumbs visible 
-      sushiv_dim_widget_set_thumb_active(p->private->dim_scales[i],0,1);
-      sushiv_dim_widget_set_thumb_active(p->private->dim_scales[i],2,1);
+      _sushiv_dim_widget_set_thumb_active(p->private->dim_scales[i],0,1);
+      _sushiv_dim_widget_set_thumb_active(p->private->dim_scales[i],2,1);
     }else{
       // make bracket thumbs invisible */
-      sushiv_dim_widget_set_thumb_active(p->private->dim_scales[i],0,0);
-      sushiv_dim_widget_set_thumb_active(p->private->dim_scales[i],2,0);
+      _sushiv_dim_widget_set_thumb_active(p->private->dim_scales[i],0,0);
+      _sushiv_dim_widget_set_thumb_active(p->private->dim_scales[i],2,0);
     }
   } 
 }
@@ -680,12 +680,12 @@
     sushiv_dimension_t *d = p->dimension_list[i].d;
     if(d == p2->x_d){
       if(p2->x_d->val != x)
-	sushiv_dimension_set_value(p->private->dim_scales[i],1,x);
+	_sushiv_dimension_set_value(p->private->dim_scales[i],1,x);
     }
 
     if(d == p2->y_d){
       if(p2->y_d->val != y)
-	sushiv_dimension_set_value(p->private->dim_scales[i],1,y);
+	_sushiv_dimension_set_value(p->private->dim_scales[i],1,y);
     }
     
     p2->oldbox_active = 0;
@@ -711,10 +711,10 @@
 
     _sushiv_panel2d_crosshairs_callback(p);
 
-    sushiv_dimension_set_value(p2->x_scale,0,p2->oldbox[0]);
-    sushiv_dimension_set_value(p2->x_scale,2,p2->oldbox[1]);
-    sushiv_dimension_set_value(p2->y_scale,0,p2->oldbox[2]);
-    sushiv_dimension_set_value(p2->y_scale,2,p2->oldbox[3]);
+    _sushiv_dimension_set_value(p2->x_scale,0,p2->oldbox[0]);
+    _sushiv_dimension_set_value(p2->x_scale,2,p2->oldbox[1]);
+    _sushiv_dimension_set_value(p2->y_scale,0,p2->oldbox[2]);
+    _sushiv_dimension_set_value(p2->y_scale,2,p2->oldbox[3]);
     p2->oldbox_active = 0;
     _sushiv_panel_undo_resume(p);
     break;
@@ -906,9 +906,9 @@
   }
 
   for(i=0;i<p->dimensions;i++){
-    sushiv_dimension_set_value(p->private->dim_scales[i],0,u->dim_vals[0][i]);
-    sushiv_dimension_set_value(p->private->dim_scales[i],1,u->dim_vals[1][i]);
-    sushiv_dimension_set_value(p->private->dim_scales[i],2,u->dim_vals[2][i]);
+    _sushiv_dimension_set_value(p->private->dim_scales[i],0,u->dim_vals[0][i]);
+    _sushiv_dimension_set_value(p->private->dim_scales[i],1,u->dim_vals[1][i]);
+    _sushiv_dimension_set_value(p->private->dim_scales[i],2,u->dim_vals[2][i]);
   }
 
   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(p2->dim_xb[u->x_d]),TRUE);
@@ -1248,7 +1248,7 @@
     }
 
     p->private->dim_scales[i] = 
-      sushiv_new_dimension_widget(p->dimension_list+i,center_callback_2d,bracket_callback_2d);
+      _sushiv_new_dimension_widget(p->dimension_list+i,center_callback_2d,bracket_callback_2d);
     
     gtk_table_attach(GTK_TABLE(p2->dim_table),
 		     GTK_WIDGET(p->private->dim_scales[i]->t),

Modified: trunk/sushivision/sushivision.h
===================================================================
--- trunk/sushivision/sushivision.h	2006-12-31 22:59:36 UTC (rev 12276)
+++ trunk/sushivision/sushivision.h	2006-12-31 23:55:53 UTC (rev 12277)
@@ -159,6 +159,8 @@
 					 int (*callback)(sushiv_dimension_t *),
 					 unsigned flags);
 
+extern void sushiv_dimension_set_value(sushiv_instance_t *s, int dim_number, int thumb, double val);
+
 extern int sushiv_new_objective(sushiv_instance_t *s,
 				int number,
 				const char *name,



More information about the commits mailing list