[Gridflow-cvs] [svn] commit: r5606 - in /trunk/src: classes1.cxx classes3.cxx formats.cxx

svn-gridflow at artengine.ca svn-gridflow at artengine.ca
Wed May 5 22:00:30 EDT 2010


Author: matju
Date: Wed May  5 22:00:29 2010
New Revision: 5606

Log:
Dim,GridInlet&

Modified:
    trunk/src/classes1.cxx
    trunk/src/classes3.cxx
    trunk/src/formats.cxx

Modified: trunk/src/classes1.cxx
==============================================================================
--- trunk/src/classes1.cxx (original)
+++ trunk/src/classes1.cxx Wed May  5 22:00:29 2010
@@ -64,10 +64,10 @@
 
 Numop *op_add, *op_sub, *op_mul, *op_div, *op_mod, *op_shl, *op_and, *op_put;
 
-static void   expect_dim_dim_list    (const Dim &d) {if (d->n!=1) RAISE("dimension list should be Dim[n], not %s",d->to_s());}
-//static void expect_min_one_dim     (const Dim &d) {if (d->n<1 ) RAISE("minimum 1 dimension");}
-static void   expect_max_one_dim     (const Dim &d) {if (d->n>1 ) RAISE("expecting Dim[] or Dim[n], got %s",d->to_s());}
-//static void expect_exactly_one_dim (const Dim &d) {if (d->n!=1) RAISE("expecting Dim[n], got %s",d->to_s());}
+static void   expect_dim_dim_list    (const Dim &d) {if (d.n!=1) RAISE("dimension list should be Dim[n], not %s",d.to_s());}
+//static void expect_min_one_dim     (const Dim &d) {if (d.n<1 ) RAISE("minimum 1 dimension");}
+static void   expect_max_one_dim     (const Dim &d) {if (d.n>1 ) RAISE("expecting Dim[] or Dim[n], got %s",d.to_s());}
+//static void expect_exactly_one_dim (const Dim &d) {if (d.n!=1) RAISE("expecting Dim[n], got %s",d.to_s());}
 
 //****************************************************************
 \class GridCast : FObject {
@@ -129,7 +129,7 @@
 GRID_INLET(0) {} GRID_FLOW {process(n,data);} GRID_END
 GRID_INPUT(1,dim_grid) {
 	Dim d = dim_grid->to_dim();
-	if (!d->prod()) RAISE("target grid size must not be zero");
+	if (!d.prod()) RAISE("target grid size must not be zero");
 	dim = d;
 	per_message=false;
 } GRID_END
@@ -729,17 +729,17 @@
 	SAME_TYPE(in,r);
 	SAME_TYPE(in,seed);
 	Dim &a=in.dim, &b=r->dim;
-	if (a->n<1) RAISE("a: minimum 1 dimension");
-	if (b->n<1) RAISE("b: minimum 1 dimension");
+	if (a.n<1) RAISE("a: minimum 1 dimension");
+	if (b.n<1) RAISE("b: minimum 1 dimension");
 	if (seed->dim.n != 0) RAISE("seed must be a scalar");
-	int n = a->n+b->n-2;
-	SAME_DIM(1,a,a->n-1,b,0);
+	int n = a.n+b.n-2;
+	SAME_DIM(1,a,a.n-1,b,0);
 	int32 v[n];
-	COPY(v,a->v,a->n-1);
-	COPY(v+a->n-1,b->v+1,b->n-1);
+	COPY(v,a.v,a.n-1);
+	COPY(v+a.n-1,b.v+1,b.n-1);
 	out=new GridOutlet(this,0,Dim(n,v),in.nt);
-	in.set_chunk(a->n-1);
-	long sjk=r->dim.prod(), sj=in.dim.prod(a->n-1), sk=sjk/sj;
+	in.set_chunk(a.n-1);
+	long sjk=r->dim.prod(), sj=in.dim.prod(a.n-1), sk=sjk/sj;
 	long chunk = max(1L,GridOutlet::MAX_PACKET_SIZE/sjk);
 	T *rdata = (T *)*r;
 	r2=new Grid(Dim(chunk*sjk),r->nt);
@@ -830,10 +830,10 @@
 GRID_INLET(0) {
 	SAME_TYPE(in,r);
 	Dim &a = in.dim, &b = r->dim;
-	int n = a->n+b->n;
+	int n = a.n+b.n;
 	int32 v[n];
-	COPY(v,a->v,a->n);
-	COPY(v+a->n,b->v,b->n);
+	COPY(v,a.v,a.n);
+	COPY(v+a.n,b.v,b.n);
 	out=new GridOutlet(this,0,Dim(n,v),in.nt);
 } GRID_FLOW {
 	long b_prod = r->dim.prod();
@@ -915,7 +915,7 @@
 	Dim d;
 	if (from->dim.n==0) {d = Dim(*nn);}
 	else {nn[n]=n;       d = Dim(n+1,nn);}
-	int total = d->prod();
+	int total = d.prod();
 	out=new GridOutlet(this,0,d,from->nt);
 	if (total==0) return;
 	int k=0;
@@ -1016,7 +1016,7 @@
 
 GRID_INPUT(1,dim_grid) {
 	Dim d = dim_grid->to_dim();
-//	if (!d->prod()) RAISE("target grid size must not be zero"); else post("d->prod=%d",d->prod());
+//	if (!d.prod()) RAISE("target grid size must not be zero"); else post("d.prod=%d",d.prod());
 	dim = d;
 } GRID_END
 

Modified: trunk/src/classes3.cxx
==============================================================================
--- trunk/src/classes3.cxx (original)
+++ trunk/src/classes3.cxx Wed May  5 22:00:29 2010
@@ -21,7 +21,7 @@
 	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
 #include "gridflow.hxx.fcs"
-static void expect_max_one_dim (const Dim &d) {if (d->n>1) RAISE("expecting Dim[] or Dim[n], got %s",d->to_s());}
+static void expect_max_one_dim (const Dim &d) {if (d.n>1) RAISE("expecting Dim[] or Dim[n], got %s",d.to_s());}
 // BAD HACK: GCC complains: unimplemented (--debug mode only) (i don't remember which GCC this was)
 #ifdef HAVE_DEBUG
 #define SCOPY(a,b,n) COPY(a,b,n)
@@ -107,20 +107,20 @@
 	NOTEMPTY(r);
 	SAME_TYPE(in,r);
 	Dim &d = in.dim;
-	if (d->n != r->dim.n) RAISE("wrong number of dimensions");
+	if (d.n != r->dim.n) RAISE("wrong number of dimensions");
 	int w = which_dim;
-	if (w<0) w+=d->n;
-	if (w<0 || w>=d->n) RAISE("can't join on dim number %d on %d-dimensional grids", which_dim,d->n);
-	int32 v[d->n];
-	for (int i=0; i<d->n; i++) {
-		v[i] = d->get(i);
+	if (w<0) w+=d.n;
+	if (w<0 || w>=d.n) RAISE("can't join on dim number %d on %d-dimensional grids", which_dim,d.n);
+	int32 v[d.n];
+	for (int i=0; i<d.n; i++) {
+		v[i] = d[i];
 		if (i==w) {
 			v[i]+=r->dim[i];
 		} else {
 			if (v[i]!=r->dim[i]) RAISE("dimensions mismatch: dim #%i, left is %d, right is %d",i,v[i],r->dim[i]);
 		}
 	}
-	out=new GridOutlet(this,0,Dim(d->n,v),in.nt);
+	out=new GridOutlet(this,0,Dim(d.n,v),in.nt);
 	in.set_chunk(w);
 } GRID_FLOW {
 	int w = which_dim;
@@ -519,9 +519,9 @@
 GRID_INLET(0) {
 	int n = in.dim.n;
 	if (n!=3) RAISE("only 3 dims supported for now");
-	if (diml->n != n) RAISE("diml mismatch");
-	if (dimr->n != n) RAISE("dimr mismatch");
-	if (diml->v[2] || dimr->v[2]) RAISE("can't augment channels (todo)");
+	if (diml.n != n) RAISE("diml mismatch");
+	if (dimr.n != n) RAISE("dimr mismatch");
+	if (diml[2] || dimr[2]) RAISE("can't augment channels (todo)");
 	int32 v[n];
 	for (int i=0; i<n; i++) v[i]=in.dim[i]+diml[i]+dimr[i];
 	in.set_chunk(0);
@@ -533,13 +533,13 @@
 	int sxc = sx*sc; int zxc = zx*zc;
 	int32 duh[zxc];
 	for (int x=0; x<zxc; x++) duh[x]=0;
-	for (int y=0; y<diml->v[0]; y++) out->send(zxc,duh);
+	for (int y=0; y<diml[0]; y++) out->send(zxc,duh);
 	for (int y=0; y<sy; y++) {
 		out->send(diml[1]*sc,duh);
 		out->send(sxc,data+y*sxc);
 		out->send(dimr[1]*sc,duh);
 	}	
-	for (int i=0; i<dimr->v[0]; i++) out->send(zxc,duh);
+	for (int i=0; i<dimr[0]; i++) out->send(zxc,duh);
 } GRID_END
 
 GRID_INPUT(1,diml_grid) {diml = diml_grid->to_dim();} GRID_END
@@ -547,16 +547,15 @@
 
 \end class {install("#border",3,1);}
 
-static void expect_picture (const Dim &d) {if (d->n!=3) RAISE("(height,width,chans) dimensions please");}
-static void expect_rgb_picture  (const Dim &d) {expect_picture(d); if (d->get(2)!=3) RAISE("(red,green,blue) channels please");}
-static void expect_rgba_picture (const Dim &d) {expect_picture(d); if (d->get(2)!=4) RAISE("(red,green,blue,alpha) channels please");}
+static void expect_picture (const Dim &d) {if (d.n!=3) RAISE("(height,width,chans) dimensions please");}
+static void expect_rgb_picture  (const Dim &d) {expect_picture(d); if (d[2]!=3) RAISE("(red,green,blue) channels please");}
+static void expect_rgba_picture (const Dim &d) {expect_picture(d); if (d[2]!=4) RAISE("(red,green,blue,alpha) channels please");}
 
 //****************************************************************
 //{ Dim[A,B,*Cs]<T>,Dim[D,E]<T> -> Dim[A,B,*Cs]<T> }
 
 static void expect_convolution_matrix (const Dim &d) {
-	if (d->n != 2) RAISE("only exactly two dimensions allowed for now (got %d)",
-		d->n);
+	if (d.n!=2) RAISE("only exactly two dimensions allowed for now (got %d)",d.n);
 }
 
 // entry in a compiled convolution kernel
@@ -605,8 +604,8 @@
 
 template <class T> void GridConvolve::make_plan (T bogus) {
 	Dim &db = b->dim;
-	long dby = db->get(0);
-	long dbx = db->get(1);
+	long dby = db[0];
+	long dbx = db[1];
 	if (plan) delete[] plan;
 	plan = new PlanEntry[dbx*dby];
 	long i=0;
@@ -636,19 +635,19 @@
 	SAME_TYPE(in,seed);
 	Dim &da=in.dim, &db=b->dim;
 	if (!seed) RAISE("seed missing");
-	if (db->n != 2) RAISE("right grid must have two dimensions");
-	if (da->n < 2) RAISE("left grid has less than two dimensions");
+	if (db.n != 2) RAISE("right grid must have two dimensions");
+	if (da.n < 2) RAISE("left grid has less than two dimensions");
 	if (seed->dim.n != 0) RAISE("seed must be scalar");
-	if (da->get(0) < db->get(0)) RAISE("grid too small (y): %d < %d", da->get(0), db->get(0));
-	if (da->get(1) < db->get(1)) RAISE("grid too small (x): %d < %d", da->get(1), db->get(1));
-	margy = (db->get(0)-1)/2;
-	margx = (db->get(1)-1)/2;
+	if (da[0] < db[0]) RAISE("grid too small (y): %d < %d", da[0], db[0]);
+	if (da[1] < db[1]) RAISE("grid too small (x): %d < %d", da[1], db[1]);
+	margy = (db[0]-1)/2;
+	margx = (db[1]-1)/2;
 	//if (a) post("for %p, a->dim=%s da=%s",this,a->dim.to_s(),da->to_s());
 	if (!a || !a->dim.equal(da)) a=new Grid(da,in.nt); // with this condition it's 2% faster on Linux but takes more RAM.
 	//a=new Grid(da,in.nt); // with this condition it's 2% faster but takes more RAM.
-	int v[da->n]; COPY(v,da->v,da->n);
-	if (!wrap) {v[0]-=db->v[0]-1; v[1]-=db->v[1]-1;}
-	out=new GridOutlet(this,0,Dim(da->n,v),in.nt);
+	int v[da.n]; COPY(v,da.v,da.n);
+	if (!wrap) {v[0]-=db[0]-1; v[1]-=db[1]-1;}
+	out=new GridOutlet(this,0,Dim(da.n,v),in.nt);
 } GRID_FLOW {
 	COPY((T *)*a+dex, data, n);
 } GRID_FINISH {
@@ -717,7 +716,7 @@
 GRID_INLET(0) {
 	Dim &a = in.dim;
 	expect_picture(a);
-	out=new GridOutlet(this,0,Dim(a->get(0)*scaley,a->get(1)*scalex,a->get(2)),in.nt);
+	out=new GridOutlet(this,0,Dim(a[0]*scaley,a[1]*scalex,a[2]),in.nt);
 	in.set_chunk(1);
 } GRID_FLOW {
 	int rowsize = in.dim.prod(1);
@@ -771,8 +770,8 @@
 
 GRID_INLET(0) {
 	Dim &a = in.dim;
-	if (a->n!=3) RAISE("(height,width,chans) please");
-	out=new GridOutlet(this,0,Dim(a->get(0)/scaley,a->get(1)/scalex,a->get(2)),in.nt);
+	if (a.n!=3) RAISE("(height,width,chans) please");
+	out=new GridOutlet(this,0,Dim(a[0]/scaley,a[1]/scalex,a[2]),in.nt);
 	in.set_chunk(1);
 	// i don't remember why two rows instead of just one.
 	temp=new Grid(Dim(2,in.dim[1]/scalex,in.dim[2]),in.nt);
@@ -844,8 +843,8 @@
 	SAME_TYPE(in,r);
 	Dim &a = in.dim;
 	expect_rgba_picture(a);
-	if (a->get(1)!=r->dim[1]) RAISE("same width please");
-	if (a->get(0)!=r->dim[0]) RAISE("same height please");
+	if (a[1]!=r->dim[1]) RAISE("same width please");
+	if (a[0]!=r->dim[0]) RAISE("same height please");
 	in.set_chunk(2);
 	out=new GridOutlet(this,0,r->dim);
 } GRID_FLOW {
@@ -870,7 +869,7 @@
 // pad1,pad2 only are there for 32-byte alignment
 struct Line {int32 y1,x1,y2,x2,x,m,ox,pad2;};
 
-static void expect_polygon (const Dim &d) {if (d->n!=2 || d->get(1)!=2) RAISE("expecting Dim[n,2] polygon");}
+static void expect_polygon (const Dim &d) {if (d.n!=2 || d[1]!=2) RAISE("expecting Dim[n,2] polygon");}
 
 enum DrawMode {DRAW_FILL,DRAW_LINE,DRAW_POINT};
 enum OmitMode {OMIT_NONE,OMIT_LAST,OMIT_ODD};
@@ -1029,8 +1028,8 @@
 
 //****************************************************************
 static void expect_position(const Dim &d) {
-	if (d->n!=1) RAISE("position should have 1 dimension, not %d", d->n);
-	if (d->v[0]!=2) RAISE("position dim 0 should have 2 elements, not %d", d->v[0]);
+	if (d.n!=1) RAISE("position should have 1 dimension, not %d", d.n);
+	if (d[0]!=2) RAISE("position dim 0 should have 2 elements, not %d", d[0]);
 }
 
 \class DrawImage : FObject {
@@ -1290,7 +1289,7 @@
 \end class {install("#rotatificator",2,1);}
 
 static void expect_min_one_dim (const Dim &d) {
-	if (d->n<1) RAISE("expecting at least one dimension, got %s",d->to_s());}
+	if (d.n<1) RAISE("expecting at least one dimension, got %s",d.to_s());}
 
 #define OP(x) op_dict[string(#x)]
 \class GridClusterAvg : FObject {
@@ -1325,7 +1324,7 @@
 	COPY(v,r->dim.v,r->dim.n-1);
 	v[r->dim.n-1]=1;
 	Dim t = Dim(r->dim.n,v);
-	if (!t->equal(in.dim)) RAISE("left %s must be equal to right %s except last dimension should be 1",in.dim.to_s(),r->dim.to_s());
+	if (!t.equal(in.dim)) RAISE("left %s must be equal to right %s except last dimension should be 1",in.dim.to_s(),r->dim.to_s());
 	in.set_chunk(0);
 	int32 w[2] = {numClusters,r->dim[r->dim.n-1]};
 	sums   = new Grid(Dim(2,w),r->nt,  true);

Modified: trunk/src/formats.cxx
==============================================================================
--- trunk/src/formats.cxx (original)
+++ trunk/src/formats.cxx Wed May  5 22:00:29 2010
@@ -215,7 +215,7 @@
 		dim = Dim(head.dimn,dimv);
 	}
 	GridOutlet out(this,0,dim,nt);
-	long nn = dim->prod();
+	long nn = dim.prod();
 	
 #define FOO(T) {T data[nn]; size_t nnn = fread(data,1,nn*sizeof(T),f); \
 	if (nnn<nn*sizeof(T)) pd_error(bself,"can't read grid data (body): %s", feof(f) ? "end of file" : strerror(ferror(f))); \
@@ -236,11 +236,11 @@
 		default: RAISE("can't write that type of number to a file");
 		}
 		head.reserved = 0;
-		head.dimn = in->dim->n;
-		size_t sz = 4*in->dim->n;
+		head.dimn = in->dim.n;
+		size_t sz = 4*in->dim.n;
 #define FRAISE(funk,f) RAISE("can't "#funk": %s",ferror(f));
-		if (fwrite(&head,1,8,f      )< 8) FRAISE(fwrite,f);
-		if (fwrite(in->dim->v,1,sz,f)<sz) FRAISE(fwrite,f);
+		if (fwrite(&head,1,8,f     )< 8) FRAISE(fwrite,f);
+		if (fwrite(in->dim.v,1,sz,f)<sz) FRAISE(fwrite,f);
 	}
 } GRID_FLOW {
 #define FOO(T) {T data2[n]; for(int i=0; i<n; i++) data2[i]=(T)data[i]; \
@@ -319,7 +319,7 @@
 	uint8 row[sx*3];
 	switch (b) {
 		case '2': case '3': {
-			size_t n = out.dim->prod();
+			size_t n = out.dim.prod();
 			int32 x;
 			for (size_t i=0; i<n; i++) if (fscanf(f,"%d",&x)<1) RERR; else out.send(1,&x);
 		} break;
@@ -329,15 +329,15 @@
 	}
 }
 GRID_INLET(0) {
-	if (in->dim->n!=3) RAISE("need 3 dimensions");
-	int sc = in->dim->v[2];
+	if (in.dim.n!=3) RAISE("need 3 dimensions");
+	int sc = in.dim[2];
 	if (sc!=1 && sc!=3) RAISE("need 1 or 3 channels");
 	fprintf(f, sc==3 ? "P6\n" : "P5\n");
-	fprintf(f,"%d %d 255\n",in->dim->v[1],in->dim->v[0]);
-	in->set_chunk(1);
+	fprintf(f,"%d %d 255\n",in.dim[1],in.dim[0]);
+	in.set_chunk(1);
 } GRID_FLOW {
-	int sx = in->dim->v[1];
-	int sc = in->dim->v[2];
+	int sx = in.dim[1];
+	int sc = in.dim[2];
 	size_t sxc = sx*sc;
 	uint8 row[sxc];
 	while (n) {



More information about the Gridflow-cvs mailing list