[xiph-commits] r12303 - trunk/sushivision

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Thu Jan 4 13:14:30 PST 2007


Author: xiphmont
Date: 2007-01-04 13:14:27 -0800 (Thu, 04 Jan 2007)
New Revision: 12303

Modified:
   trunk/sushivision/dimension.c
   trunk/sushivision/dimension.h
   trunk/sushivision/panel-1d.c
   trunk/sushivision/panel-1d.h
Log:
Discrete dimension fixes, infrastructure improvement, changes:

1) Discrete dimensions upper/lower bounds quantize to the bin closest to the scale min and max; the upper scale bound is inclusive, not one past (ie, a discrete dimension with a scale of {1.,5.,10.} and a quant of 1 is specified to span [1, 10], not (1,10)

2) discrete dimensions are iterated monotonically from zero.  In the
above example, this means the objective sees 0,1,2,3,4,5,6,7,8,9.
Zero indexed monotonic applies only to objective iteration; this will
be configurable soon...



Modified: trunk/sushivision/dimension.c
===================================================================
--- trunk/sushivision/dimension.c	2007-01-04 19:49:19 UTC (rev 12302)
+++ trunk/sushivision/dimension.c	2007-01-04 21:14:27 UTC (rev 12303)
@@ -29,48 +29,83 @@
 /* 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 ret;
-  memset(&ret,0,sizeof(ret));
 
+/* A panel that supports discrete dimensions must deal with up to
+   three different scales for the discrete axis; the first is
+   pixel-oriented to the actually displayed panel, the second covers
+   the same range but is oriented to integer bin numbers in the
+   underlying data vector (often the same as the display), and the
+   third the same as the second, but over the absolute range [0 - n)
+   such that discrete dimensions will count from 0 in iteration. */
+/* if a dimension is linked, that is not handled here; the passed in x
+   must be the linked x_v scale in which case it will be unaltered (it
+   will be filtered through the discrete transformation a second time,
+   which will not alter it) but x_i will bre generated fresh. */
+int _sushiv_dimension_scales(sushiv_dimension_t *d,
+			     double lo,
+			     double hi,
+			     int panel_w, int data_w,
+			     int spacing,
+			     char *legend,
+			     scalespace *panel, 
+			     scalespace *data, 
+			     scalespace *iter){
+
   switch(d->type){
   case SUSHIV_DIM_CONTINUOUS:
-    ret = x;
+    *panel = scalespace_linear(lo, hi, panel_w, spacing, legend);
+    *data = *iter = scalespace_linear(lo, hi, data_w, spacing, legend);
     break;
   case SUSHIV_DIM_DISCRETE:
     {
       /* return a scale that when iterated will only hit values
 	 quantized to the discrete base */
+      /* what is the absolute base? */
+      /* the ceiling in a discrete dimension is an inclusive upper bound, not one-past */
+      int floor_i =  rint(d->scale->val_list[0] * d->private->discrete_denominator / 
+			  d->private->discrete_numerator);
+      int ceil_i =  rint(d->scale->val_list[d->scale->vals-1] * d->private->discrete_denominator / 
+			 d->private->discrete_numerator) +1;
       
-      int lo_i =  floor(x.lo * d->private->discrete_denominator / 
+      int lo_i =  floor(lo * d->private->discrete_denominator / 
 			d->private->discrete_numerator);
-      int hi_i =  ceil(x.hi * d->private->discrete_denominator / 
-		       d->private->discrete_numerator);
-      
+      int hi_i =  floor(hi * d->private->discrete_denominator / 
+		       d->private->discrete_numerator)+1;
+
+      if(floor_i < ceil_i){
+	if(lo_i < floor_i)lo_i = floor_i;
+	if(hi_i > ceil_i)hi_i = ceil_i;
+      }else{
+	if(lo_i > floor_i)lo_i = floor_i;
+	if(hi_i < ceil_i)hi_i = ceil_i;
+      }
+
       double lo = lo_i * d->private->discrete_numerator / 
 	d->private->discrete_denominator;
       double hi = hi_i * d->private->discrete_numerator / 
 	d->private->discrete_denominator;
-      
-      ret = scalespace_linear(lo, hi, hi_i-lo_i+1, 1, x.legend);
+
+      data_w = hi_i-lo_i;
+
+      *panel = scalespace_linear(lo, hi, panel_w, spacing, legend);
+      *data = scalespace_linear(lo, hi, data_w, 1, legend);
+      *iter = scalespace_linear(lo_i - floor_i, hi_i - floor_i, data_w, 1, legend);
+      break;
     }
     break;
   case SUSHIV_DIM_PICKLIST:
-    fprintf(stderr,"ERROR: Cannot iterate over picklist dimensions!\n"
+    fprintf(stderr,"ERROR: Cannot iterate over picklist dimension!\n"
 	    "\tA picklist dimension may not be a panel axis.\n");
+    data_w = 0;
     break;
   default:
     fprintf(stderr,"ERROR: Unsupporrted dimension type in dimension_datascale.\n");
+    data_w = 0;
     break;
   }
-  return ret;
+  return data_w;
 }
 
-/* takes the data scale, not the panel plot scale */
-int _sushiv_dimension_data_width(sushiv_dimension_t *d, scalespace *datascale){
-  return datascale->pixels;
-}
-
 static double discrete_quantize_val(sushiv_dimension_t *d, double val){
   if(d->type == SUSHIV_DIM_DISCRETE){
     val *= d->private->discrete_denominator;

Modified: trunk/sushivision/dimension.h
===================================================================
--- trunk/sushivision/dimension.h	2007-01-04 19:49:19 UTC (rev 12302)
+++ trunk/sushivision/dimension.h	2007-01-04 21:14:27 UTC (rev 12303)
@@ -51,8 +51,15 @@
   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 int _sushiv_dimension_scales(sushiv_dimension_t *d,
+				    double lo,
+				    double hi,
+				    int panel_w, int data_w,
+				    int spacing,
+				    char *legend,
+				    scalespace *panel, 
+				    scalespace *data, 
+				    scalespace *iter);
 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,   

Modified: trunk/sushivision/panel-1d.c
===================================================================
--- trunk/sushivision/panel-1d.c	2007-01-04 19:49:19 UTC (rev 12302)
+++ trunk/sushivision/panel-1d.c	2007-01-04 21:14:27 UTC (rev 12303)
@@ -70,10 +70,10 @@
 
   if(plot){
     int xi,i,j;
-    int dw = p1->data_size;
     double h = p1->panel_h;
+    int dw = p1->data_size;
     double r = (p1->flip?p1->panel_w:p1->panel_h);
-
+    
     /* blank frame to black */
     cairo_set_source_rgb (c, 0,0,0);
     cairo_paint(c);
@@ -112,9 +112,8 @@
 	    double xpixel = xi;
 	    double ypixel = NAN;
 	    
-	    /* in linked panels, the data vector doesn't match the graph width; map */
-	    if(p1->link_x || p1->link_y)
-	      xpixel = scalespace_pixel(&p1->x,scalespace_value(&p1->vs,xpixel))+.5;
+	    /* map data vector bin to x pixel location in the plot */
+	    xpixel = scalespace_pixel(&p1->x,scalespace_value(&p1->x_v,xpixel))+.5;
 	    
 	    /* map/render result */
 	    if(!isnan(val))
@@ -306,7 +305,7 @@
     char buffer[320];
     plot_legend_clear(plot);
 
-    if(-p1->vs.decimal_exponent > depth) depth = 3-p1->vs.decimal_exponent;
+    if(-p1->x_v.decimal_exponent > depth) depth = 3-p1->x_v.decimal_exponent;
 
     // add each dimension to the legend
     for(i=0;i<p->dimensions;i++){
@@ -332,7 +331,7 @@
       
       // add each dimension to the legend
       // display decimal precision relative to display scales
-      if(3-p1->vs.decimal_exponent > depth) depth = 3-p1->vs.decimal_exponent;
+      if(3-p1->x_v.decimal_exponent > depth) depth = 3-p1->x_v.decimal_exponent;
       snprintf(buffer,320,"%s = %+.*f",
 	       d->name,
 	       depth,
@@ -347,7 +346,7 @@
     // choose the value under the crosshairs 
     {
       double val = (p1->flip?plot->sely:plot->selx);
-      int bin = scalespace_pixel(&p1->vs, val);
+      int bin = scalespace_pixel(&p1->x_v, val);
       u_int32_t color = mapping_calc(p1->mappings+i,1.,0);
 
       for(i=0;i<p->objectives;i++){
@@ -610,32 +609,22 @@
   }
 
   if(plot && GTK_WIDGET_REALIZED(GTK_WIDGET(plot))){
-    p1->x = scalespace_linear(p1->x_d->bracket[0],
-			     p1->x_d->bracket[1],
-			     (p1->flip?h:w),
-			     PLOT(p->private->graph)->scalespacing,
-			     p1->x_d->name);
+    dw = _sushiv_dimension_scales(p1->x_d, 
+				  p1->x_d->bracket[0],
+				  p1->x_d->bracket[1],
+				  (p1->flip?h:w),dw,
+				  plot->scalespacing,
+				  p1->x_d->name,
+				  &p1->x,
+				  &p1->x_v,
+				  &p1->x_i);
 
     p1->y = scalespace_linear(p1->range_bracket[0],
-			     p1->range_bracket[1],
-			     (p1->flip?w:h),
-			     PLOT(p->private->graph)->scalespacing,
-			     p1->range_scale->legend);
+			      p1->range_bracket[1],
+			      (p1->flip?w:h),
+			      plot->scalespacing,
+			      p1->range_scale->legend);
     
-
-    // handle the possibility that our data scale is from a link.
-    // 2d panels do not necessarily update their scales until
-    // recompute time, and 1d panels may be recomputed first,
-    // thus duplicate the scale computaiton here
-    p1->vs = scalespace_linear(p1->x_d->bracket[0],
-			       p1->x_d->bracket[1],
-			       dw,
-			       PLOT(p->private->graph)->scalespacing,
-			       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);
-
     if(p1->data_size != dw){
       if(p1->data_vec){
 
@@ -891,19 +880,23 @@
   double x_min, x_max;
   int x_d=-1;
   int render_scale_flag = 0;
-  scalespace sx;
   scalespace sy;
-  scalespace sv;
 
+  scalespace sx;
+  scalespace sxv;
+  scalespace sxi;
+
   // lock during setup
   gdk_threads_enter ();
   dw = p1->data_size;
   w = p1->panel_w;
   h = p1->panel_h;
 
-  sx = p1->x;
   sy = p1->y;
-  sv = p1->vs;
+
+  sx = p1->x;
+  sxv = p1->x_v;
+  sxi = p1->x_i;
   
   if(p1->last_line){
     gdk_threads_leave ();
@@ -919,8 +912,9 @@
      computing objectives */
   double dim_vals[p->sushi->dimensions];
 
-  x_min = scalespace_value(&sv,0);
-  x_max = scalespace_value(&sv,dw);
+  /* get iterator bounds, use iterator scale */
+  x_min = scalespace_value(&sxi,0);
+  x_max = scalespace_value(&sxi,dw);
   x_d = p1->x_d->number;
 
   if(p1->flip){
@@ -1109,7 +1103,7 @@
 	
 	count = inner_count;
 	if(count>p1->peak_count){
-	  double xv = scalespace_value(&p1->vs,best_j);
+	  double xv = scalespace_value(&p1->x_v,best_j);
 
 	  if(p1->flip)
 	    plot_set_crosshairs(plot,0,xv);

Modified: trunk/sushivision/panel-1d.h
===================================================================
--- trunk/sushivision/panel-1d.h	2007-01-04 19:49:19 UTC (rev 12302)
+++ trunk/sushivision/panel-1d.h	2007-01-04 21:14:27 UTC (rev 12303)
@@ -36,10 +36,12 @@
   int serialno;
   double **data_vec;
 
-  scalespace x;
-  scalespace vs;
   scalespace y;
 
+  scalespace x;   // the x scale aligned to panel's pixel context
+  scalespace x_v; // the x scale aligned to data vector's bins
+  scalespace x_i; // the 'counting' scale used to iterate for compute
+
   int scales_init;
   double oldbox[4];
   int oldbox_active;



More information about the commits mailing list