[xiph-commits] r12305 - trunk/sushivision

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Thu Jan 4 15:21:34 PST 2007


Author: xiphmont
Date: 2007-01-04 15:21:30 -0800 (Thu, 04 Jan 2007)
New Revision: 12305

Added:
   trunk/sushivision/objective.h
Modified:
   trunk/sushivision/example_fractal.c
   trunk/sushivision/internal.h
   trunk/sushivision/objective.c
   trunk/sushivision/panel-1d.c
   trunk/sushivision/panel-2d.c
   trunk/sushivision/sushivision.h
Log:
Simplification to creating objectives with typed outputs; needed for
panels as they come to support dimensions other than Y.  Outputs are
now typed to X,Y,Z, or errorbar.



Modified: trunk/sushivision/example_fractal.c
===================================================================
--- trunk/sushivision/example_fractal.c	2007-01-04 21:24:40 UTC (rev 12304)
+++ trunk/sushivision/example_fractal.c	2007-01-04 23:21:30 UTC (rev 12305)
@@ -80,14 +80,18 @@
 
   sushiv_new_function(s, 0, 5, 2, fractal_objective, 0);
 
-  sushiv_new_objective_Y(s,0,"outer",
-			 5,(double []){0, .001, .01, .1, 1.0},
-			 0,0,0);
+  sushiv_new_objective(s,0,"outer",
+		       5,(double []){0, .001, .01, .1, 1.0},
+		       (int []){0},
+		       (int []){0},
+		       "Y", 0);
 
-  sushiv_new_objective_Y(s,1,"inner",
-			 5,(double []){0, .001, .01, .1, 1.0},
-			 0,1,0);
-
+  sushiv_new_objective(s,1,"inner",
+		       5,(double []){0, .001, .01, .1, 1.0},
+		       (int []){0},
+		       (int []){1},
+		       "Y", 0);
+  
   sushiv_new_panel_2d(s,0,"Mandel/Julia Fractal",
 		      (int []){0,1,-1},
 		      (int []){0,1,2,3,4,-1},

Modified: trunk/sushivision/internal.h
===================================================================
--- trunk/sushivision/internal.h	2007-01-04 21:24:40 UTC (rev 12304)
+++ trunk/sushivision/internal.h	2007-01-04 23:21:30 UTC (rev 12305)
@@ -29,6 +29,7 @@
 #include "gtksucks.h"
 #include "plot.h"
 #include "dimension.h"
+#include "objective.h"
 #include "panel-1d.h"
 #include "panel-2d.h"
 
@@ -118,6 +119,4 @@
 extern void _sushiv_panel1d_mark_recompute_linked(sushiv_panel_t *p); 
 extern void _sushiv_panel1d_update_linked_crosshairs(sushiv_panel_t *p, int xflag, int yflag); 
 
-extern int obj_y(sushiv_objective_t *o);
-
 extern sig_atomic_t _sushiv_exiting;

Modified: trunk/sushivision/objective.c
===================================================================
--- trunk/sushivision/objective.c	2007-01-04 21:24:40 UTC (rev 12304)
+++ trunk/sushivision/objective.c	2007-01-04 23:21:30 UTC (rev 12305)
@@ -25,28 +25,19 @@
 #include <errno.h>
 #include "internal.h"
 
-int obj_y(sushiv_objective_t *o){
-  switch(o->type){
-  case SUSHIV_OBJ_XY:
-  case SUSHIV_OBJ_XYZ:
-    return 1;
-  default:
-    return 0;
-  }
-}
-
-static int _sushiv_new_objective(sushiv_instance_t *s,
-				 int number,
-				 const char *name,
-				 unsigned scalevals,
-				 double *scaleval_list,
-				 int type,
-				 int outputs,
-				 int *function_map,
-				 int *output_map,
-				 unsigned flags){
+int sushiv_new_objective(sushiv_instance_t *s,
+			 int number,
+			 const char *name,
+			 unsigned scalevals,
+			 double *scaleval_list,
+			 int *function_map,
+			 int *output_map,
+			 char *output_types,
+			 unsigned flags){
   sushiv_objective_t *o;
+  sushiv_objective_internal_t *p;
   int i;
+  int outputs = strlen(output_types);
 
   if(number<0){
     fprintf(stderr,"Objective number must be >= 0\n");
@@ -67,6 +58,9 @@
     }
     s->objectives=number+1;
   }
+  
+  o = s->objective_list[number] = calloc(1, sizeof(**s->objective_list));
+  p = o->private = calloc(1,sizeof(*o->private));
 
   /* sanity check the maps */
   for(i=0;i<outputs;i++){
@@ -83,12 +77,63 @@
 	      number,function_map[i],output_map[i]);
       return -EINVAL;
     }
+    switch(output_types[i]){
+    case 'X':
+      if(p->x_func){
+	fprintf(stderr,"Objective %d: More than one X dimension specified.\n",
+		number);
+	return -EINVAL;
+      }
+      p->x_fout = output_map[i];
+      p->x_func = s->function_list[function_map[i]];
+      break;
+
+    case 'Y':
+      if(p->y_func){
+	fprintf(stderr,"Objective %d: More than one Y dimension specified.\n",
+		number);
+	return -EINVAL;
+      }
+      p->y_fout = output_map[i];
+      p->y_func = s->function_list[function_map[i]];
+      break;
+
+    case 'Z':
+      if(p->z_func){
+	fprintf(stderr,"Objective %d: More than one Z dimension specified.\n",
+		number);
+	return -EINVAL;
+      }
+      p->z_fout = output_map[i];
+      p->z_func = s->function_list[function_map[i]];
+      break;
+
+    case 'E':
+      if(p->e2_func){
+	fprintf(stderr,"Objective %d: More than two E dimensions specified.\n",
+		number);
+	return -EINVAL;
+      }
+      if(p->e1_func){
+	p->e2_fout = output_map[i];
+	p->e2_func = s->function_list[function_map[i]];
+      }else{
+	p->e1_fout = output_map[i];
+	p->e1_func = s->function_list[function_map[i]];
+      }
+      break;
+
+    default:
+      fprintf(stderr,"Objective %d: '%c' is an usupported output type.\n",
+	      number,output_types[i]);
+      return -EINVAL;
+    }
   }
 
-  o = s->objective_list[number] = calloc(1, sizeof(**s->objective_list));
   o->number = number;
   o->name = strdup(name);
-  o->type = type;
+  o->output_types = strdup(output_types);
+  o->type = SUSHIV_OBJ_BASIC;
   o->outputs = outputs;
   o->flags = flags;
   o->sushi = s;
@@ -104,71 +149,3 @@
 
   return 0;
 }
-
-int sushiv_new_objective_Y(sushiv_instance_t *s,
-			   int number,
-			   const char *name,
-			   unsigned scalevals, 
-			   double *scaleval_list,
-			   int function_number,
-			   int function_output,
-			   unsigned flags){
-  return _sushiv_new_objective(s,number,name, 
-			       scalevals,scaleval_list,
-			       SUSHIV_OBJ_Y,
-			       1,
-			       (int []){function_number},
-			       (int []){function_output},
-			       flags);
-}
-
-int sushiv_new_objective_XY(sushiv_instance_t *s,
-			    int number,
-			    const char *name,
-			    unsigned scalevals, 
-			    double *scaleval_list,
-			    int function_number[2],
-			    int function_output[2],
-			    unsigned flags){
-  return _sushiv_new_objective(s,number,name, 
-			       scalevals,scaleval_list,
-			       SUSHIV_OBJ_XY,
-			       2,
-			       function_number,
-			       function_output,
-			       flags);
-}
-
-int sushiv_new_objective_YZ(sushiv_instance_t *s,
-			    int number,
-			    const char *name,
-			    unsigned scalevals, 
-			    double *scaleval_list,
-			    int function_number[2],
-			    int function_output[2],
-			    unsigned flags){
-  return _sushiv_new_objective(s,number,name, 
-			       scalevals,scaleval_list,
-			       SUSHIV_OBJ_YZ,
-			       2,
-			       function_number,
-			       function_output,
-			       flags);
-}
-
-int sushiv_new_objective_XYZ(sushiv_instance_t *s,
-			     int number,
-			     const char *name,
-			     unsigned scalevals, 
-			     double *scaleval_list,
-			     int function_number[3],
-			     int function_output[3],
-			     unsigned flags){
-  return _sushiv_new_objective(s,number,name, 
-			       scalevals,scaleval_list,
-			       SUSHIV_OBJ_XYZ,
-			       3,
-			       function_number,
-			       function_output,
-			       flags);
-}

Added: trunk/sushivision/objective.h
===================================================================
--- trunk/sushivision/objective.h	2007-01-04 21:24:40 UTC (rev 12304)
+++ trunk/sushivision/objective.h	2007-01-04 23:21:30 UTC (rev 12305)
@@ -0,0 +1,35 @@
+/*
+ *
+ *     sushivision copyright (C) 2006-2007 Monty <monty at xiph.org>
+ *
+ *  sushivision is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *   
+ *  sushivision is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *   
+ *  You should have received a copy of the GNU General Public License
+ *  along with sushivision; see the file COPYING.  If not, write to the
+ *  Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * 
+ */
+
+struct sushiv_objective_internal {
+  sushiv_function_t *x_func;
+  sushiv_function_t *y_func;
+  sushiv_function_t *z_func;
+  sushiv_function_t *e1_func;
+  sushiv_function_t *e2_func;
+
+  int x_fout;
+  int y_fout;
+  int z_fout;
+  int e1_fout;
+  int e2_fout;
+};
+

Modified: trunk/sushivision/panel-1d.c
===================================================================
--- trunk/sushivision/panel-1d.c	2007-01-04 21:24:40 UTC (rev 12304)
+++ trunk/sushivision/panel-1d.c	2007-01-04 23:21:30 UTC (rev 12305)
@@ -561,27 +561,28 @@
      future, Z may also be relevant */
   for(i=0;i<p->objectives;i++){
     sushiv_objective_t *o = p->objective_list[i].o;
-    int funcnum = o->function_map[obj_y(o)];
-    int offset = o->output_map[obj_y(o)];
-    sushiv_function_t *f = p->sushi->function_list[funcnum];
-    int step = f->outputs;
-    double *fout = c->fout[funcnum]+offset;
-
-    /* map result from function output to objective output */
-    for(j=0;j<w;j++){
-      work[j] = *fout;
-      fout+=step;
+    int offset = o->private->y_fout;
+    sushiv_function_t *f = o->private->y_func;
+    if(f){
+      int step = f->outputs;
+      double *fout = c->fout[f->number]+offset;
+      
+      /* map result from function output to objective output */
+      for(j=0;j<w;j++){
+	work[j] = *fout;
+	fout+=step;
+      }
+      
+      gdk_threads_enter (); // misuse me as a global mutex
+      if(p1->serialno == serialno){
+	/* store result in panel */
+	memcpy(p1->data_vec[i],work,w*sizeof(*work));
+	gdk_threads_leave (); // misuse me as a global mutex 
+      }else{
+	gdk_threads_leave (); // misuse me as a global mutex 
+	break;
+      }
     }
-
-    gdk_threads_enter (); // misuse me as a global mutex
-    if(p1->serialno == serialno){
-      /* store result in panel */
-      memcpy(p1->data_vec[i],work,w*sizeof(*work));
-      gdk_threads_leave (); // misuse me as a global mutex 
-    }else{
-      gdk_threads_leave (); // misuse me as a global mutex 
-      break;
-    }
   }
 }
 

Modified: trunk/sushivision/panel-2d.c
===================================================================
--- trunk/sushivision/panel-2d.c	2007-01-04 21:24:40 UTC (rev 12304)
+++ trunk/sushivision/panel-2d.c	2007-01-04 23:21:30 UTC (rev 12305)
@@ -303,38 +303,39 @@
   /* 2d panels only care about the Y output value */
   for(i=0;i<p->objectives;i++){
     sushiv_objective_t *o = p->objective_list[i].o;
-    int funcnum = o->function_map[obj_y(o)];
-    int offset = o->output_map[obj_y(o)];
-    sushiv_function_t *f = p->sushi->function_list[funcnum];
-    int step = f->outputs;
-    double *fout = c->fout[funcnum]+offset;
-    mapping m;
-    double alpha;
-
-    /* map result */
-    /* range scales are static so no need to lock; if that ever
-       changes, locking should happen in the scales... */
-    for(j=0;j<w;j++){
-      work[j] = slider_val_to_del(p2->range_scales[i],*fout);
-      fout+=step;
-    }
-
-    gdk_threads_enter (); // misuse me as a global mutex
-    if(p2->serialno == serialno){
-      memcpy(p2->data_rect[i]+y*w,work,w*sizeof(*work));
-      memcpy(&m,p2->mappings+i,sizeof(m));
-      alpha = p2->alphadel[i];
-      gdk_threads_leave (); // misuse me as a global mutex
-    }else{
-      gdk_threads_leave (); // misuse me as a global mutex
-      break;
-    }
-
-    for(j=0;j<w;j++){	
-      double val = work[j];
-      if(!isnan(val) && val>=alpha)
-	render[j] = mapping_calc(&m,val,render[j]);
+    int offset = o->private->y_fout;
+    sushiv_function_t *f = o->private->y_func;
+    if(f){
+      int step = f->outputs;
+      double *fout = c->fout[f->number]+offset;
+      mapping m;
+      double alpha;
       
+      /* map result */
+      /* range scales are static so no need to lock; if that ever
+	 changes, locking should happen in the scales... */
+      for(j=0;j<w;j++){
+	work[j] = slider_val_to_del(p2->range_scales[i],*fout);
+	fout+=step;
+      }
+      
+      gdk_threads_enter (); // misuse me as a global mutex
+      if(p2->serialno == serialno){
+	memcpy(p2->data_rect[i]+y*w,work,w*sizeof(*work));
+	memcpy(&m,p2->mappings+i,sizeof(m));
+	alpha = p2->alphadel[i];
+	gdk_threads_leave (); // misuse me as a global mutex
+      }else{
+	gdk_threads_leave (); // misuse me as a global mutex
+	break;
+      }
+      
+      for(j=0;j<w;j++){	
+	double val = work[j];
+	if(!isnan(val) && val>=alpha)
+	  render[j] = mapping_calc(&m,val,render[j]);
+	
+      }
     }
   }
 }

Modified: trunk/sushivision/sushivision.h
===================================================================
--- trunk/sushivision/sushivision.h	2007-01-04 21:24:40 UTC (rev 12304)
+++ trunk/sushivision/sushivision.h	2007-01-04 23:21:30 UTC (rev 12305)
@@ -99,10 +99,7 @@
 };
 
 typedef struct sushiv_objective_internal sushiv_objective_internal_t;
-enum sushiv_objective_type { SUSHIV_OBJ_Y, 
-			     SUSHIV_OBJ_XY, 
-			     SUSHIV_OBJ_YZ, 
-			     SUSHIV_OBJ_XYZ };
+enum sushiv_objective_type { SUSHIV_OBJ_BASIC };
 typedef union sushiv_objective_subtype sushiv_objective_subtype_t;
 
 struct sushiv_objective { 
@@ -114,6 +111,7 @@
   int outputs;
   int *function_map;
   int *output_map;
+  char *output_types;
   unsigned flags;
 
   sushiv_instance_t *sushi;
@@ -206,42 +204,16 @@
 			       void(*callback)(double *,double *),
 			       unsigned flags);
   
-extern int sushiv_new_objective_Y(sushiv_instance_t *s,
-				  int number,
-				  const char *name,
-				  unsigned scalevals, 
-				  double *scaleval_list,
-				  int function_number,
-				  int function_output,
-				  unsigned flags);
+extern int sushiv_new_objective(sushiv_instance_t *s,
+				int number,
+				const char *name,
+				unsigned scalevals, 
+				double *scaleval_list,
+				int *function_map,
+				int *function_output_map,
+				char *output_type_map,
+				unsigned flags);
 
-extern int sushiv_new_objective_XY(sushiv_instance_t *s,
-				  int number,
-				  const char *name,
-				  unsigned scalevals, 
-				  double *scaleval_list,
-				  int function_number[2],
-				  int function_output[2],
-				  unsigned flags);
-
-extern int sushiv_new_objective_YZ(sushiv_instance_t *s,
-				   int number,
-				   const char *name,
-				   unsigned scalevals, 
-				   double *scaleval_list,
-				   int function_number[2],
-				   int function_output[2],
-				   unsigned flags);
-
-extern int sushiv_new_objective_XYZ(sushiv_instance_t *s,
-				    int number,
-				    const char *name,
-				    unsigned scalevals, 
-				    double *scaleval_list,
-				    int function_number[3],
-				    int function_output[3],
-				    unsigned flags);
-
 extern int sushiv_new_panel_2d(sushiv_instance_t *s,
 			       int number,
 			       const char *name, 



More information about the commits mailing list