Changeset: 7becf2237c61 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7becf2237c61
Modified Files:
sql/backends/monet5/UDF/80_ssdb.sql
sql/backends/monet5/UDF/ssdb.c
sql/backends/monet5/UDF/ssdb.h
sql/backends/monet5/UDF/ssdb.mal
Branch: ssdb
Log Message:
first uncompiled version of cooking without polygon
diffs (truncated from 482 to 300 lines):
diff --git a/sql/backends/monet5/UDF/80_ssdb.sql
b/sql/backends/monet5/UDF/80_ssdb.sql
--- a/sql/backends/monet5/UDF/80_ssdb.sql
+++ b/sql/backends/monet5/UDF/80_ssdb.sql
@@ -22,9 +22,7 @@ All Rights Reserved.
-- Cooks one pixels value (tin_pixs.val) for each image in the input table
-- 'tin_pixs' according to the description in the SS-DB paper.
--- tin_img: name of the input table for image meta data, with columns
--- (imageid int, time int, cyclem int)
--- tin_pix: name of the input table for image pixel values, with columns
+-- tin: name of the input table for image pixel values, with columns
-- (imageid int, x int, y int, val int)
-- tout_obs: name of the output table for observations, with columns
-- (obsid INT, imageid INT, time INT, cyclem INT, averageDist REAL,
@@ -34,7 +32,7 @@ All Rights Reserved.
-- (obsid INT, ord INT, x INT, y INT)
-- width: width of all images, assuming they are the same
-- height: height of all images, assuming they are the same
-CREATE PROCEDURE cooking (tin_img CHAR(128), tin_pix CHAR(128), tout_obs
CHAR(128), tout_plg CHAR(128), width INT, height INT)
+CREATE PROCEDURE cooking (tin CHAR(128), tout_obs CHAR(128), tout_plg
CHAR(128), width INT, height INT)
EXTERNAL NAME ssdb.cooking;
-- Determines for each polygon in the input table 'tin' if it intersects with
diff --git a/sql/backends/monet5/UDF/ssdb.c b/sql/backends/monet5/UDF/ssdb.c
--- a/sql/backends/monet5/UDF/ssdb.c
+++ b/sql/backends/monet5/UDF/ssdb.c
@@ -57,6 +57,17 @@ _bind_bat(mvc *sql, sql_table *t, char *
return b;
}
+static str
+_append_bat(mvc *sql, sql_table *t, char cname, BAT *b)
+{
+ sql_column *c = mvc_bind_column(sql, t, cname);
+
+ if(!c)
+ return sql_message("42S02!COOKING(): no such column '%s.%s'",
t->base.name, cname);
+ store_funcs.append_col(m->session->tr, c, b, TYPE_bat);
+ return NULL;
+}
+
str
SSDBintersects(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{ /* intersects(tin:str, tout:str, xstart:int, ystart:int, xlen:int,
ylen:int):void */
@@ -70,13 +81,11 @@ SSDBintersects(Client cntxt, MalBlkPtr m
str
SSDBcooking(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
-{ /* cooking(tin_img:str, tin_pix:str, tout_obs:str, tout_plg:str):void */
+{ /* cooking(tin:str, tout_obs:str, tout_plg:str):void */
mvc *sql = NULL;
- sql_table *tin_img = NULL, *tin_pix = NULL, *tout_obs = NULL, *tout_plg
= NULL;
- /* tin_img (imageid int, time int, cyclem int) */
- BAT *tin_img_imgid = NULL, *tin_img_time NULL, *tin_img_cyclem = NULL;
- /* tin_pix (imageid int, x int, y int, val int) */
- BAT *tin_pix_imgid = NULL, *tin_pix_x NULL, *tin_pix_y = NULL,
*tin_pix_val = NULL;
+ sql_table *tin = NULL, *tout_obs = NULL, *tout_plg = NULL;
+ /* tin (imageid int, x int, y int, val int) */
+ BAT *tin_imgid = NULL, *tin_x NULL, *tin_y = NULL, *tin_val = NULL;
/* tout_obs (obsid INT, imageid INT, time INT, cyclem INT,
* averagedist REAL, pixelsum BIGINT, centerx INT,
* centery INT, boxxstart INT, boxystart INT, boxxend INT,
@@ -92,11 +101,10 @@ SSDBcooking(Client cntxt, MalBlkPtr mb,
*tout_plg_x = NULL, *tout_plg_y = NULL;
BUN i = 0, idx = 0, nr_pixs = 0, nr_obs = 0;
- int nr_imgs = 0, imgid = 0;
int *grpid = NULL, *obsid = NULL, cur_obsid = 0;
/* pointers to the actual values of the columns */
- int *tin_pix_imgid_t = NULL, *tin_pix_x_t = NULL, *tin_pix_y_t = NULL,
- *tin_pix_val_t = NULL;
+ int *tin_imgid_t = NULL, *tin_x_t = NULL, *tin_y_t = NULL,
+ *tin_val_t = NULL;
int *tout_obs_obsid_t = NULL, *tout_obs_imgid_t = NULL,
*tout_obs_time_t = NULL, *tout_obs_cyclem_t = NULL,
*tout_obs_pixsum_t = NULL,
@@ -109,63 +117,110 @@ SSDBcooking(Client cntxt, MalBlkPtr mb,
dbl *distSum = NULL;
str msg = getSQLContext(cntxt, mb, &sql, NULL);
- str tin_img_name = *(str *) getArgReference(stk, pci, pci->retc + 0);
- str tin_pix_name = *(str *) getArgReference(stk, pci, pci->retc + 1);
- str tout_obs_name = *(str *) getArgReference(stk, pci, pci->retc + 2);
- str tout_plg_name = *(str *) getArgReference(stk, pci, pci->retc + 3);
- int width = *(int *) getArgReference(stk, pci, pci->retc + 4);
- int height = *(int *) getArgReference(stk, pci, pci->retc + 5);
+ str tin_name = *(str *) getArgReference(stk, pci, pci->retc + 0);
+ str tout_obs_name = *(str *) getArgReference(stk, pci, pci->retc + 1);
+ str tout_plg_name = *(str *) getArgReference(stk, pci, pci->retc + 2);
+ int width = *(int *) getArgReference(stk, pci, pci->retc + 3);
+ int height = *(int *) getArgReference(stk, pci, pci->retc + 4);
if (msg)
return msg;
- if (pci->argc - pci->retc != 6)
- return sql_message("COOKING(): 6 parameters expected, got %d",
pci->argc - pci->retc);
- if (!tin_img_name || !tin_pix_name)
- return sql_message("COOKING(): missing name(s) of the input
table(s)");
+ if (pci->argc - pci->retc != 5)
+ return sql_message("COOKING(): 5 parameters expected, got %d",
pci->argc - pci->retc);
+ if (!tin_name)
+ return sql_message("COOKING(): missing name of the input
table");
if (!tout_obs_name || !tout_plg_name)
return sql_message("COOKING(): missing name(s) of the output
table(s)");
- if(!(tin_img = _bind_table(sql, "tmp", tin_img_name)))
- return sql_message("42S02!COOKING(): no such table '%s'",
tin_img_name);
- if(!(tin_pix = _bind_table(sql, "tmp", tin_pix_name)))
- return sql_message("42S02!COOKING(): no such table '%s'",
tin_pix_name);
+ if(!(tin = _bind_table(sql, "tmp", tin_name)))
+ return sql_message("42S02!COOKING(): no such table '%s'",
tin_name);
if(!(tout_obs = _bind_table(sql, NULL, tout_obs_name)))
return sql_message("42S02!COOKING(): no such table '%s'",
tout_obs_name);
if(!(tout_plg = _bind_table(sql, NULL, tout_plg_name)))
return sql_message("42S02!COOKING(): no such table '%s'",
tout_plg_name);
- /* get the BATs of all columns of the input table 'tin_img' */
+ /* get the BATs of all columns of the input table 'tin' */
/* RD_INS means we want the insert BATs, since all input tables are
* declared as TEMP */
- if(!(tin_img_imgid = _bind_bat(sql, tin_img, "imageid", TYPE_int,
RD_INS))) {
+ if(!(tin_imgid = _bind_bat(sql, tin, "imageid", TYPE_int, RD_INS))) {
msg = sql_message("42S02!COOKING(): no such column '%s.%s'",
tin_name, "imageid");
goto CLEANUP_RETURN;
}
- if(!(tin_img_time = _bind_bat(sql, tin_img, "time", TYPE_int, RD_INS)))
{
- msg = sql_message("42S02!COOKING(): no such column '%s.%s'",
tin_name, "time");
- goto CLEANUP_RETURN;
- }
- if(!(tin_img_cyclem = _bind_bat(sql, tin_img, "cyclem", TYPE_int,
RD_INS))) {
- msg = sql_message("42S02!COOKING(): no such column '%s.%s'",
tin_name, "cyclem");
- goto CLEANUP_RETURN;
- }
- /* get the BATs of all columns of the input table 'tin_pix' */
- if(!(tin_pix_imgid = _bind_bat(sql, tin_pix, "imageid", TYPE_int,
RD_INS))) {
- msg = sql_message("42S02!COOKING(): no such column '%s.%s'",
tin_name, "imageid");
- goto CLEANUP_RETURN;
- }
- if(!(tin_pix_x = _bind_bat(sql, tin_pix, "x", TYPE_int, RD_INS))) {
+ if(!(tin_x = _bind_bat(sql, tin, "x", TYPE_int, RD_INS))) {
msg = sql_message("42S02!COOKING(): no such column '%s.%s'",
tin_name, "x");
goto CLEANUP_RETURN;
}
- if(!(tin_pix_y = _bind_bat(sql, tin_pix, "y", TYPE_int, RD_INS))) {
+ if(!(tin_y = _bind_bat(sql, tin, "y", TYPE_int, RD_INS))) {
msg = sql_message("42S02!COOKING(): no such column '%s.%s'",
tin_name, "y");
goto CLEANUP_RETURN;
}
- if(!(tin_pix_val = _bind_bat(sql, tin_pix, "val", TYPE_int, RD_INS))) {
+ if(!(tin_val = _bind_bat(sql, tin, "val", TYPE_int, RD_INS))) {
msg = sql_message("42S02!COOKING(): no such column '%s.%s'",
tin_name, "val");
goto CLEANUP_RETURN;
}
+
+ tin_imgid_t = (int*)Tloc(tin_imgid, BUNfirst(tin_imgid));
+ tin_x_t = (int*)Tloc(tin_x, BUNfirst(tin_x));
+ tin_y_t = (int*)Tloc(tin_y, BUNfirst(tin_y));
+ tin_val_t = (int*)Tloc(tin_val, BUNfirst(tin_val));
+
+ nr_pixs = BATcount(tin_imgid);
+ if(!(grpid = GDKmalloc(nr_pixs * sizeof(int)))) {
+ msg = sql_message("COOKING(): GDKmalloc 'grpid' failed");
+ goto CLEANUP_RETURN;
+ }
+ if(!(obsid = GDKmalloc(nr_pixs * sizeof(int)))) {
+ msg = sql_message("COOKING(): GDKmalloc 'obsid' failed");
+ goto CLEANUP_RETURN;
+ }
+
+ /* First pass over all input pixels, to group the pixels into
+ * observations and assign them a unique obsid */
+ for (idx = 0; idx < nr_pixs; idx++) {
+ int x_prev, y_prev, x, y, min;
+
+ x = tin_x_t[idx];
+ y = tin_y_t[idx];
+ /* Compute a temporary group ID for each pixel, which is its
position
+ * in the image */
+ min = grpid[idx] = tin_y_t[idx] * width + tin_x_t[idx];
+
+ /* search back for the smallest 'grpid' value of my neighbours
*/
+ /* FIXME: this can be inefficient, need something to reduce the
number
+ * of iterations! */
+ for(i = idx-1, x_prev = tin_x_t[i], y_prev = tin_y_t[i];
+ /* current or previous row */
+ i >= 0 && (y_prev == y || y_prev == y-1);
+ i--, x_prev = tin_x_t[i], y_prev = tin_y_t[i]) {
+ if((x-1 <= x_prev && x_prev <= x+1) && grpid[i] < min)
+ min = grpid[i];
+ }
+ if(min < grpid[idx]) {
+ grpid[idx] = min;
+ }
+
+ /* If the group ID of this pixel is larger than the previous
pixel, or
+ * a new image has been started, we have a new observation */
+ if(idx > 0 && (grpid[idx] > grpid[idx-1] ||
+ tin_imgid_t[idx] > tin_imgid_t[idx-1]))
+ nr_obs++;
+ obsid[idx] = nr_obs;
+ }
+ nr_obs++; /* now we know the exact number of observations we have */
+
+ /* Create BATs for all columns of the output table 'tout_obs' */
+ tout_obs_obsid = BATnew(TYPE_void, TYPE_int, nr_obs);
+ tout_obs_imgid = BATnew(TYPE_void, TYPE_int, nr_obs);
+ tout_obs_time = BATnew(TYPE_void, TYPE_int, nr_obs);
+ tout_obs_cyclem = BATnew(TYPE_void, TYPE_int, nr_obs);
+ tout_obs_avgdist = BATnew(TYPE_void, TYPE_dbl, nr_obs);
+ tout_obs_pixsum = BATnew(TYPE_void, TYPE_lng, nr_obs);
+ tout_obs_centerx = BATnew(TYPE_void, TYPE_int, nr_obs);
+ tout_obs_centery = BATnew(TYPE_void, TYPE_int, nr_obs);
+ tout_obs_boxxstart = BATnew(TYPE_void, TYPE_int, nr_obs);
+ tout_obs_boxystart = BATnew(TYPE_void, TYPE_int, nr_obs);
+ tout_obs_boxxend = BATnew(TYPE_void, TYPE_int, nr_obs);
+ tout_obs_boxyend = BATnew(TYPE_void, TYPE_int, nr_obs);
/* get the BATs of all columns of the output table 'tout_plg' */
/*
if(!(tout_plg_obsid = _bind_bat(sql, tout_plg, "obsid", TYPE_int,
RD_INS))) {
@@ -185,76 +240,6 @@ SSDBcooking(Client cntxt, MalBlkPtr mb,
goto CLEANUP_RETURN;
}
*/
-
- tin_pix_imgid_t = (int*)Tloc(tin_pix_imgid, BUNfirst(tin_pix_imgid));
- tin_pix_x_t = (int*)Tloc(tin_pix_x, BUNfirst(tin_pix_x));
- tin_pix_y_t = (int*)Tloc(tin_pix_y, BUNfirst(tin_pix_y));
- tin_pix_val_t = (int*)Tloc(tin_pix_val, BUNfirst(tin_pix_val));
-
- nr_pixs = BATcount(tin_pix_imgid);
- if(!(grpid = GDKmalloc(nr_pixs * sizeof(int)))) {
- msg = sql_message("COOKING(): GDKmalloc 'grpid' failed");
- goto CLEANUP_RETURN;
- }
- if(!(obsid = GDKmalloc(nr_pixs * sizeof(int)))) {
- msg = sql_message("COOKING(): GDKmalloc 'obsid' failed");
- goto CLEANUP_RETURN;
- }
-
- /* First pass over all input pixels, to: */
- for (idx = 0, imgid = tin_pix_imgid_t[0], nr_imgs = 1;
- idx < nr_pixs; idx++) {
- /* 1. Compute a temporary group ID for each pixel, which is its
- * position in the image */
- grpid[idx] = tin_pix_y_t[idx] * width + tin_pix_x_t[idx];
-
- assert(tin_pix_imgid_t[idx] >= imgid);
- if(tin_pix_imgid_t[idx] != imgid){
- imgid = tin_pix_imgid_t[idx];
- /* 2. compute the actual number of images */
- nr_imgs++;
- }
- }
-
- /* Second pass over all input pixels, to group the pixels into
- * observations and assign them a unique obsid */
- for (idx = 0; idx < nr_pixs; idx++) {
- int x_prev, y_prev, x = tin_pix_x_t[idx], y = tin_pix_y_t[idx],
- min = grpid[idx];
- /* search back for the smallest 'grpid' value of my neighbours
*/
- for(i = idx-1, x_prev = tin_pix_x_t[i], y_prev = tin_pix_y_t[i];
- /* current or previous row */
- i >= 0 && (y_prev == y || y_prev == y-1);
- i--, x_prev = tin_pix_x_t[i], y_prev =
tin_pix_y_t[i]) {
- if((x-1 <= x_prev && x_prev <= x+1) && grpid[i] < min)
- min = grpid[i];
- }
- if(min < grpid[idx]) {
- grpid[idx] = min;
- }
-
- /* If the group ID of this pixel is larger than the previous
pixel, or
- * a new image has been started, we have a new observation */
- if(idx > 0 && (grpid[idx] > grpid[idx-1] ||
- tin_pix_imgid_t[idx] >
tin_pix_imgid_t[idx-1]))
- nr_obs++;
- obsid[idx] = nr_obs;
- }
- nr_obs++; /* now we know the exact number of observations we have */
-
- /* Create BATs for all columns of the output table 'tout_obs' */
- tout_obs_obsid = BATnew(TYPE_void, TYPE_int, nr_obs);
- tout_obs_imgid = BATnew(TYPE_void, TYPE_int, nr_obs);
- tout_obs_time = BATnew(TYPE_void, TYPE_int, nr_obs);
- tout_obs_cyclem = BATnew(TYPE_void, TYPE_int, nr_obs);
- tout_obs_avgdist = BATnew(TYPE_void, TYPE_dbl, nr_obs);
- tout_obs_pixsum = BATnew(TYPE_void, TYPE_lng, nr_obs);
- tout_obs_centerx = BATnew(TYPE_void, TYPE_int, nr_obs);
- tout_obs_centery = BATnew(TYPE_void, TYPE_int, nr_obs);
- tout_obs_boxxstart = BATnew(TYPE_void, TYPE_int, nr_obs);
- tout_obs_boxystart = BATnew(TYPE_void, TYPE_int, nr_obs);
- tout_obs_boxxend = BATnew(TYPE_void, TYPE_int, nr_obs);
- tout_obs_boxyend = BATnew(TYPE_void, TYPE_int, nr_obs);
/* pointers directly to the BATs' tails */
tout_obs_obsid_t = (int*)Tloc(tout_obs_obsid, BUNfirst(tout_obs_obsid));
tout_obs_imgid_t = (int*)Tloc(tout_obs_imgid, BUNfirst(tout_obs_imgid));
@@ -289,26 +274,26 @@ SSDBcooking(Client cntxt, MalBlkPtr mb,
cur_obsid = obsid[idx];
/* initialise a new obs */
tout_obs_obsid_t[cur_obsid] = cur_obsid; /* can
we optimise away this column? */
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list