[xiph-commits] r12791 - trunk/sushivision

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Thu Mar 22 03:04:43 PDT 2007


Author: xiphmont
Date: 2007-03-22 03:04:41 -0700 (Thu, 22 Mar 2007)
New Revision: 12791

Added:
   trunk/sushivision/sushimacro.h
Modified:
   trunk/sushivision/Makefile
   trunk/sushivision/example_discrete.c
   trunk/sushivision/example_spirograph.c
   trunk/sushivision/plot.c
   trunk/sushivision/sushivision.h
Log:
The beginning of a macro convenience layer.



Modified: trunk/sushivision/Makefile
===================================================================
--- trunk/sushivision/Makefile	2007-03-22 06:47:29 UTC (rev 12790)
+++ trunk/sushivision/Makefile	2007-03-22 10:04:41 UTC (rev 12791)
@@ -27,7 +27,7 @@
 SRC       = main.c scale.c plot.c slider.c slice.c spinner.c panel.c panel-1d.c panel-2d.c \
 	panel-xy.c mapping.c dimension.c function.c objective.c undo.c gtksucks.c xml.c \
 	example_fractal.c example_discrete.c example_chirp.c example_spirograph.c
-INC       = sushivision.h
+INC       = sushivision.h sushimacro.h
 MAN	  =
 EXAMPLES  = sushivision_fractal sushivision_discrete sushivision_chirp
 EX_OBJ    = example_fractal.o example_discrete.o example_chirp.o example_spirograph.o

Modified: trunk/sushivision/example_discrete.c
===================================================================
--- trunk/sushivision/example_discrete.c	2007-03-22 06:47:29 UTC (rev 12790)
+++ trunk/sushivision/example_discrete.c	2007-03-22 10:04:41 UTC (rev 12791)
@@ -22,7 +22,7 @@
 #define _GNU_SOURCE
 #include <stdio.h>
 #include <math.h>
-#include "sushivision.h"
+#include "sushimacro.h"
 
 static void discrete_objective(double *d, double *ret){
 
@@ -37,43 +37,54 @@
 
 int sv_submain(int argc, char *argv[]){
 
-  sv_instance_t *s = sv_new(0,NULL);
+  svm_new("alignment test");
 
-  sv_dim_t *d0 = sv_dim_new(s,0,"A",0);
-  sv_dim_make_scale(d0, 5,(double []){-500,-10,0,10,500}, NULL, 0);
-  sv_dim_set_discrete(d0, 1, 1);
+  svm_scale_vals(-500,-10,0,10,500);
+  svm_dim(0,"A");
+  svm_dim_discrete(1,1);
+  svm_dim_value(-2,NAN,2);
 
-  sv_dim_t *d1 = sv_dim_new(s,1,"B",0);
-  sv_dim_make_scale(d1, 5,(double []){-500,-10,0,10,500}, NULL, 0);
-  sv_dim_set_discrete(d1, 1, 1);
+  svm_scale_vals(-500,-10,0,10,500);
+  svm_dim(1,"B");
+  svm_dim_discrete(1,1);
+  svm_dim_value(-2,NAN,2);
 
-  sv_dim_set_value(d0,0,-2);
-  sv_dim_set_value(d0,2,2);
-  sv_dim_set_value(d1,0,-2);
-  sv_dim_set_value(d1,2,2);
+  //sv_func_t *f = sv_func_new(s, 0, 1, discrete_objective, 0);
+#if 0
+  //sv_obj_t *o0 = sv_obj_new(s,0,"test pattern",
+  //		    (sv_func_t *[]){f},
+  //		    (int []){0},
+  //		    "Y",0);
+  //sv_obj_make_scale(o0, 2, (double []){0, 1.0}, NULL, 0);
+  
+  svm_obj_simple(0,"test pattern",f,"Y");
 
-  sv_func_t *f = sv_func_new(s, 0, 1, discrete_objective, 0);
+  //sv_panel_t *p2 = sv_panel_new_2d(s,0,"Discrete data example",
+  //			   (sv_obj_t *[]){o0,NULL},
+  //			   (sv_dim_t *[]){d0,d1,NULL},
+  //			   0);
+  
+  svm_panel_2d(0,"Discrete data example");
 
-  sv_obj_t *o0 = sv_obj_new(s,0,"test pattern",
-			    (sv_func_t *[]){f},
-			    (int []){0},
-			    "Y",0);
-  sv_obj_make_scale(o0, 2, (double []){0, 1.0}, NULL, 0);
+  //sv_panel_t *px = sv_panel_new_1d(s,1,"X Slice", s->objective_list[0]->scale,
+  //			   (sv_obj_t *[]){o0,NULL},
+  //			   NULL,0);
+  //sv_panel_link_1d(px, p2, SV_PANEL_LINK_X);
   
-  sv_panel_t *p2 = sv_panel_new_2d(s,0,"Discrete data example",
-				   (sv_obj_t *[]){o0,NULL},
-				   (sv_dim_t *[]){d0,d1,NULL},
-				   0);
-  
-  sv_panel_t *px = sv_panel_new_1d(s,1,"X Slice", s->objective_list[0]->scale,
-				   (sv_obj_t *[]){o0,NULL},
-				   NULL,0);
-  sv_panel_link_1d(px, p2, SV_PANEL_LINK_X);
-  
-  sv_panel_t *py = sv_panel_new_1d(s,2,"Y Slice", s->objective_list[0]->scale,
-				   (sv_obj_t *[]){o0,NULL},
-				   NULL,SV_PANEL_FLIP);
-  sv_panel_link_1d(py, p2, SV_PANEL_LINK_Y);
-  
+  svm_scale(0, 1.0);
+  svm_obj_list(0);
+  svm_panel_1d(1,"X Slice");
+  svm_panel_linkx(0);
+
+  //sv_panel_t *py = sv_panel_new_1d(s,2,"Y Slice", s->objective_list[0]->scale,
+  //			   (sv_obj_t *[]){o0,NULL},
+  //			   NULL,SV_PANEL_FLIP);
+  //sv_panel_link_1d(py, p2, SV_PANEL_LINK_Y);
+
+  svm_scale(0, 1.0);
+  svm_obj_list(0);
+  svm_panel_1d(2,"Y Slice");
+  svm_panel_linky(0);
+#endif  
   return 0;
 }

Modified: trunk/sushivision/example_spirograph.c
===================================================================
--- trunk/sushivision/example_spirograph.c	2007-03-22 06:47:29 UTC (rev 12790)
+++ trunk/sushivision/example_spirograph.c	2007-03-22 10:04:41 UTC (rev 12791)
@@ -97,8 +97,7 @@
 			    (int []){0,1},
 			    "XY", 0);
   
-  //sv_scale_t *axis = sv_scale_new(NULL,3,(double []){-MAX_TEETH*3,0,MAX_TEETH*3},NULL,0);
-  sv_scale_t *axis = svm_scale(NULL,3,-MAX_TEETH*3,0,MAX_TEETH*3);
+  sv_scale_t *axis = sv_scale_new(NULL,3,(double []){-MAX_TEETH*3,0,MAX_TEETH*3},NULL,0);
 
   sv_panel_new_xy(s,0,"spirograph (TM)",
 		  axis,axis,

Modified: trunk/sushivision/plot.c
===================================================================
--- trunk/sushivision/plot.c	2007-03-22 06:47:29 UTC (rev 12790)
+++ trunk/sushivision/plot.c	2007-03-22 10:04:41 UTC (rev 12791)
@@ -91,8 +91,6 @@
 
     cairo_set_line_width(c,1.);
     if(grid & _SV_PLOT_GRID_NORMAL){
-      cairo_save(c);
-      //cairo_set_operator(c,CAIRO_OPERATOR_XOR);       
       switch(grid&0xf00){
       case 256:
 	cairo_set_source_rgba(c,.9,.9,.9,.4);
@@ -122,7 +120,6 @@
       }
 
       cairo_stroke(c);
-      cairo_restore(c);
     }
 
 

Added: trunk/sushivision/sushimacro.h
===================================================================
--- trunk/sushivision/sushimacro.h	2007-03-22 06:47:29 UTC (rev 12790)
+++ trunk/sushivision/sushimacro.h	2007-03-22 10:04:41 UTC (rev 12791)
@@ -0,0 +1,144 @@
+/*
+ *
+ *     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.
+ *
+ * 
+ */
+
+#ifndef _SUSHIMACRO_
+#define _SUSHIMACRO_
+  
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "sushivision.h"
+
+static sv_instance_t *svm_instance_curr = NULL; 
+static int svm_instance_number = 0;
+
+static double *svm_scale_vals_curr = NULL;
+static int svm_scale_vsize_curr = 0;
+static char **svm_scale_labels_curr = NULL;
+static int svm_scale_lsize_curr = 0;
+      
+static sv_dim_t *svm_dim_curr = NULL;
+static unsigned svm_scale_flags_curr = 0;
+static sv_dim_t **svm_dim_list = NULL;
+static int svm_dim_listsize = 0;
+
+// helpers
+
+#define svm_scale_check(a, b, c)					\
+  ( svm_scale_vals_curr ?						\
+    (fprintf(stderr,"No scale defined for %s %d (\"%s\")\n",#a,(b),c), \
+     1 ):								\
+    (svm_scale_labels_curr  && svm_scale_vsize_curr != svm_scale_lsize_curr ? \
+     (fprintf(stderr,"Scale values and labels list size mismatch for %s %d (\"%s\")\n",#a,(b),c), \
+      1 ):								\
+     (0) ))
+
+#define svm_dim_check(f) \
+  ( !svm_dim_curr ?						\
+    (fprintf(stderr,"No dimension currently set at %s\n",#f),	\
+     1):							\
+    (0) )
+
+#define svm_dim_list_add(d) \
+  ( (svm_dim_list && svm_dim_listsize ?					\
+     (svm_dim_list = realloc(svm_dim_list, sizeof(*svm_dim_list)*(svm_dim_listsize+2))): \
+     (svm_dim_list = calloc(2, sizeof(*svm_dim_list)))),		\
+    svm_dim_list[svm_dim_listsize] = (d) ,				\
+    svm_dim_listsize++)
+
+#define svm_dim_list_clear()			\
+  ( (svm_dim_list ?				\
+     (free(svm_dim_list),			\
+      svm_dim_list = NULL) : 0),		\
+    svm_dim_listsize = 0 )
+
+// toplevel
+
+#define svm_new(name)					   \
+  ( svm_instance_curr = sv_new(svm_instance_number, name), \
+    svm_instance_number++,				   \
+    svm_instance_curr )
+
+#define svm_scale_vals(...)						\
+  svm_scale_vals_curr = (double []){__VA_ARGS__};			\
+  svm_scale_vsize_curr = (sizeof((double []){__VA_ARGS__})/sizeof(double));
+
+#define svm_scale_labels(...)						\
+  svm_scale_labels_curr = (char []){__VA_ARGS__};			\
+  svm_scale_lsize_curr = (sizeof((char *[]){__VA_ARGS__})/sizeof(char *));
+
+#define svm_scale_flags(number)			\
+  (svm_scale_flags_curr = (number))
+
+#define svm_dim(number, name)						\
+  ( svm_scale_check(dimension,number,name) ?				\
+    (svm_dim_curr = NULL ):						\
+    (svm_dim_curr = sv_dim_new(svm_instance_curr, number, name, 0),	\
+     sv_dim_make_scale(svm_dim_curr, svm_scale_vsize_curr, svm_scale_vals_curr, svm_scale_labels_curr, svm_scale_flags_curr), \
+     svm_scale_vals_curr = NULL,					\
+     svm_scale_labels_curr = NULL,					\
+     svm_scale_vsize_curr = 0,						\
+     svm_scale_lsize_curr = 0,						\
+     svm_scale_flags_curr = 0,						\
+     svm_dim_list_add(svm_dim_curr),					\
+     svm_dim_curr) )
+
+#define svm_dim_set(number) \
+  ( !svm_instance_curr ?						\
+    (fprintf(stderr,"No instance currently set while trying to retrieve dimension %d\n",(number)), \
+     svm_dim_curr = NULL ):						\
+    ( number<0 || number >= svm_instance_curr->dimensions ?		\
+      (fprintf(stderr,"Dimension %d does not exist in instance \"%s\"\n", (number), svm_instance_curr->name), \
+       svm_dim_curr = NULL) :						\
+      (svm_dim_curr = svm_instance_curr->dimension_list[(number)])) )
+
+#define svm_dim_discrete(num,den)					\
+  ( svm_dim_check(svm_dim_curr)?					\
+    1 :	sv_dim_set_discrete(svm_dim_curr,num,den))
+
+#define svm_dim_value(a,b,c)						\
+  ( svm_dim_check(svm_dim_disabled)?					\
+    (1) :								\
+    ( !isnan(a) ? sv_dim_set_value(svm_dim_curr,0,(a)) : 0,		\
+      !isnan(b) ? sv_dim_set_value(svm_dim_curr,1,(b)) : 0,		\
+      !isnan(c) ? sv_dim_set_value(svm_dim_curr,2,(c)) : 0,		\
+      (0)))
+
+#define svm_dim_list(...)						\
+  ( svm_dim_list_clear(),						\
+    svm_dim_listsize = sizeof((sv_dim_t *[]){__VA_ARGS__}) / sizeof(sv_dim_t *), \
+    svm_dim_list = calloc(svm_dim_listsize + 1, sizeof(sv_dim_t *)),	\
+    memcpy(svm_dim_list, (sv_dim_t *[]){__VA_ARGS__}, svm_dim_listsize * sizeof(sv_dim_t *)) )
+
+#define svm_obj_simple(num,name,func,map)				\
+  ( svm_func_list_clear(),						\
+    svm_func_curr = sv_func(svm_instance_curr, svm_func_curr_num, strlen(map), func, 0), \
+    svm_obj_curr = sv_obj_new(svm_obj_curr, num, name, (sv_func_t *[]){svm_func_curr}, \
+			      (int []){0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16},map,0), \
+    (svm_scale_vals_curr ?						\
+     (svm_scale_check(objective,number,name) ?				\
+      (sv_obj_make_scale(svm_obj_curr, svm_scale_vsize_curr, svm_scale_vals_curr, svm_scale_labels_curr, svm_scale_flags_curr)):\
+      (0)):0),								\
+    svm_scale_clear(),							\
+    svm_obj_curr)
+
+
+#endif

Modified: trunk/sushivision/sushivision.h
===================================================================
--- trunk/sushivision/sushivision.h	2007-03-22 06:47:29 UTC (rev 12790)
+++ trunk/sushivision/sushivision.h	2007-03-22 10:04:41 UTC (rev 12791)
@@ -85,8 +85,6 @@
 				 char **scalelabel_list,
 				 unsigned flags);
 
-#define svm_scale(legend,vals,...) sv_scale_new(legend,vals,(double []){__VA_ARGS__},NULL,0)
-
 sv_scale_t       *sv_scale_copy (sv_scale_t *s);
 
 void              sv_scale_free (sv_scale_t *s);



More information about the commits mailing list