Changeset: cbf381a32955 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=cbf381a32955
Modified Files:
        sql/backends/monet5/UDF/80_ssdb.sql
        sql/backends/monet5/UDF/ssdb.c
        sql/backends/monet5/UDF/ssdb.mal
Branch: ssdb
Log Message:

Density function.


diffs (184 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
@@ -59,6 +59,6 @@ EXTERNAL NAME ssdb.regrid;
 -- tout: name of the output table, with columns (x int, y int, cnt int), i.e.,
 --   the center{x,y} of the tiles and the density
 CREATE PROCEDURE density (
-       tin CHAR(128), tout CHAR(128), tilesize INT, threshold INT)
+       tin CHAR(128), tout CHAR(128), x2 INT, u2 INT, y2 INT, v2 INT, tilesize 
INT, threshold INT)
 EXTERNAL NAME ssdb.density;
 
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
@@ -1142,10 +1142,155 @@ CLEANUP_RETURN:
 str
 SSDBdensity(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 { /* density(tin:str, tout:str, tilesize:int, threshold:int):void */
-       (void) cntxt;
+       /*(void) cntxt;
        (void) mb;
        (void) stk;
-       (void) pci;
+       (void) pci;*/
+
+       mvc *sql = NULL;
+       sql_table *tin = NULL, *tout = NULL;
+       str msg = getSQLContext(cntxt, mb, &sql, NULL);
+       str tin_name = *(str *) getArgReference(stk, pci, pci->retc + 0);
+       str tout_name = *(str *) getArgReference(stk, pci, pci->retc + 1);
+       int x2 = *(int *) getArgReference(stk, pci, pci->retc + 2);     
+       int u2 = *(int *) getArgReference(stk, pci, pci->retc + 3);
+       int y2 = *(int *) getArgReference(stk, pci, pci->retc + 4);
+       int v2 = *(int *) getArgReference(stk, pci, pci->retc + 5);
+       int tilesize = *(int *) getArgReference(stk, pci, pci->retc + 6);
+       int threshold = *(int *) getArgReference(stk, pci, pci->retc + 7);
+
+       BAT *tin_x = NULL, *tin_y = NULL;
+       BAT *tout_x = NULL, *tout_y = NULL, *tout_cnt = NULL;
+
+       BUN idx = 0, nr_points = 0;
+       int *tin_x_t = NULL, *tin_y_t = NULL;
+       int *tout_x_t = NULL, *tout_y_t = NULL, *tout_cnt_t = NULL;
+       int l=0,k=0,elements=0;
+
+       int tile_weights[(v2-(tilesize-1))][(u2-(tilesize-1))];
+       for(l=0;l<(v2-(tilesize-1));l++)
+               for(k=0;k<(u2-(tilesize-1));k++)
+                       tile_weights[l][k]=0;
+
+
+       if (msg)
+               return msg;
+       if (pci->argc - pci->retc != 8)
+               return sql_message("DENSITY(): 8 parameters expected, got %d", 
pci->argc - pci->retc);
+       if (!tin_name)
+               return sql_message("DENSITY(): missing name of the input 
table");
+       if (!tout_name)
+               return sql_message("DENSITY(): missing name of the output 
table");
+
+       if(!(tin = _bind_table(sql, "tmp", tin_name)))
+               return sql_message("42S02!DENSITY(): no such table '%s'", 
tin_name);
+       if(!(tout = _bind_table(sql, NULL, tout_name)))
+               return sql_message("42S02!DENSITY(): no such table '%s'", 
tout_name);
+
+       /* 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_x = _bind_bat(sql, tin, "x", TYPE_int, RD_INS))) {
+               msg = sql_message("42S22!DENSITY(): no such column '%s.%s'", 
tin_name, "x");
+               goto CLEANUP_RETURN;
+       }
+       if(!(tin_y = _bind_bat(sql, tin, "y", TYPE_int, RD_INS))) {
+               msg = sql_message("42S22!DENSITY(): no such column '%s.%s'", 
tin_name, "y");
+               goto CLEANUP_RETURN;
+       }
+
+       tin_x_t = (int*)Tloc(tin_x, BUNfirst(tin_x));
+       tin_y_t = (int*)Tloc(tin_y, BUNfirst(tin_y));
+
+       nr_points = BATcount(tin_x);
+       for(idx=0; idx<nr_points; idx++)
+       {
+               for(l=tin_y_t[idx]-y2-3;l<=(tin_y_t[idx]-y2);l++)
+               {
+                       if(l>=0 && l<=(v2-tilesize))
+                       {
+                               
for(k=tin_x_t[idx]-x2-3;k<=(tin_x_t[idx]-x2);k++)
+                               {
+                                       if(k>=0 && k<=(u2-tilesize))
+                                       {
+                                               tile_weights[l][k]++;
+                                       }
+                               }
+                       }
+               }
+               
+       }
+
+       /* Create BATs for all columns of the output table 'tout_obs' */
+       tout_x = BATnew(TYPE_void, TYPE_int, u2*v2);
+       tout_y = BATnew(TYPE_void, TYPE_int, u2*v2);
+       tout_cnt = BATnew(TYPE_void, TYPE_int, u2*v2);
+       /* pointers directly to the BATs' tails */
+       tout_x_t = (int*)Tloc(tout_x, BUNfirst(tout_x));
+       tout_y_t = (int*)Tloc(tout_y, BUNfirst(tout_y));
+       tout_cnt_t = (int*)Tloc(tout_cnt, BUNfirst(tout_cnt));
+
+       for(l=0;l<(v2-(tilesize-1));l++)
+       {
+               for(k=0;k<(u2-(tilesize-1));k++)
+               {
+                       if (tile_weights[l][k] > threshold)
+                       {
+                               tout_x_t[elements]=k+x2;
+                               tout_y_t[elements]=l+y2;
+                               tout_cnt_t[elements]=tile_weights[l][k];
+                               elements++;
+                       }
+               }
+       }
+
+       /* Set proper properties for output BATs */
+
+       BATsetcount(tout_x, elements);
+       BATsetcount(tout_y, elements);
+       BATsetcount(tout_cnt, elements);
+
+       BATseqbase(tout_x, 0);
+       BATseqbase(tout_y, 0);
+       BATseqbase(tout_cnt, 0);
+
+       tout_x->tsorted = 0;
+       tout_y->tsorted = 0;
+       tout_cnt->tsorted = 0;
+
+       tout_x->trevsorted = 0;
+       tout_y->trevsorted = 0;
+       tout_cnt->trevsorted = 0;
+
+       tout_x->T->nil = 0;
+       tout_y->T->nil = 0;
+       tout_cnt->T->nil = 0;
+
+       tout_x->T->nonil = 1;
+       tout_y->T->nonil = 1;
+       tout_cnt->T->nonil = 1;
+
+       BATkey(BATmirror(tout_x), 1);
+       BATkey(BATmirror(tout_y), 1);
+       BATkey(BATmirror(tout_cnt), 1);
+
+
+       /* Finally, append the result BATs to the result table */
+       msg = _append_bat(sql, tout, "x", tout_x);
+       msg = _append_bat(sql, tout, "y", tout_y);
+       msg = _append_bat(sql, tout, "cnt", tout_cnt);
+
+CLEANUP_RETURN:
+       if(tin_x) BBPunfix(tin_x->batCacheid);
+       if(tin_y) BBPunfix(tin_y->batCacheid);
+
+       if(tout_x) BBPunfix(tout_x->batCacheid);
+       if(tout_y) BBPunfix(tout_y->batCacheid);
+       if(tout_cnt) BBPunfix(tout_cnt->batCacheid);
+
+       return msg ? msg : MAL_SUCCEED;
+
+
 
        return MAL_SUCCEED;
 }
diff --git a/sql/backends/monet5/UDF/ssdb.mal b/sql/backends/monet5/UDF/ssdb.mal
--- a/sql/backends/monet5/UDF/ssdb.mal
+++ b/sql/backends/monet5/UDF/ssdb.mal
@@ -30,7 +30,7 @@ pattern regrid(tin:str, tout:str):void
 address SSDBregrid
 comment "Regrids all images in the table 'tin' and store results in the table 
'tout'";
 
-pattern density(tin:str, tout:str, tilesize:int, threshold:int):void
+pattern density(tin:str, tout:str, x2:int, u2:int, y2:int, v2:int, 
tilesize:int, threshold:int):void
 address SSDBdensity
 comment "Find tiles which density is larger than 'threshold' and store the 
center{x,y} and density of the tiles in the table 'tout'";
 
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to