Changeset: 866a5f34db91 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=866a5f34db91 Modified Files: sql/backends/monet5/UDF/ssdb.c Branch: ssdb Log Message:
skeleton of the compute_polygon function diffs (147 lines): 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 @@ -88,10 +88,91 @@ _obs_pix_expand(obs_pixels *op_ptr) } static str -compute_polygon(obs_pixels *obs_pix) +compute_polygon(mvc *sql, BUN nr_pixs, BUN nr_obs, obs_pixels *obs_pix, sql_table *tout_plg) { + str msg = MAL_SUCCEED; + + /* tout_plg (obsid INT, ord INT, x INT, y INT) */ + BAT *tout_plg_obsid = NULL, *tout_plg_ord = NULL, + *tout_plg_x = NULL, *tout_plg_y = NULL; + int *tout_plg_obsid_t = NULL, *tout_plg_ord_t = NULL, + *tout_plg_x_t = NULL, *tout_plg_y_t = NULL; + + /* keep the total #points in the toug_plg_* BATs */ + BUN i, nr_points = 0; + (void) obs_pix; - return NULL; + + /* Create BATs for all columns of the output table 'tout_plg', + * nr_pixs is a size estimation. */ + tout_plg_obsid = BATnew(TYPE_void, TYPE_int, nr_pixs); + tout_plg_ord = BATnew(TYPE_void, TYPE_int, nr_pixs); + tout_plg_x = BATnew(TYPE_void, TYPE_int, nr_pixs); + tout_plg_y = BATnew(TYPE_void, TYPE_int, nr_pixs); + + /* pointers directly to the BATs' tails */ + tout_plg_obsid_t = (int*)Tloc(tout_plg_obsid, BUNfirst(tout_plg_obsid)); + tout_plg_ord_t = (int*)Tloc(tout_plg_ord, BUNfirst(tout_plg_ord)); + tout_plg_x_t = (int*)Tloc(tout_plg_x, BUNfirst(tout_plg_x)); + tout_plg_y_t = (int*)Tloc(tout_plg_y, BUNfirst(tout_plg_y)); + + for (i = 0; i < nr_obs; i++) { + /* + * TODO: compute polygon for each obs... + */ + } + + /* Set proper properties for all BATs */ + BATsetcount(tout_plg_obsid, nr_points); + BATsetcount(tout_plg_ord, nr_points); + BATsetcount(tout_plg_x, nr_points); + BATsetcount(tout_plg_y, nr_points); + + BATseqbase(tout_plg_obsid, 0); + BATseqbase(tout_plg_ord, 0); + BATseqbase(tout_plg_x, 0); + BATseqbase(tout_plg_y, 0); + + tout_plg_obsid->tsorted = 1; + tout_plg_ord->tsorted = 0; + tout_plg_x->tsorted = 0; + tout_plg_y->tsorted = 0; + + tout_plg_obsid->trevsorted = 0; + tout_plg_ord->trevsorted = 0; + tout_plg_x->trevsorted = 0; + tout_plg_y->trevsorted = 0; + + tout_plg_obsid->T->nil = 0; + tout_plg_ord->T->nil = 0; + tout_plg_x->T->nil = 0; + tout_plg_y->T->nil = 0; + + tout_plg_obsid->T->nonil = 1; + tout_plg_ord->T->nonil = 1; + tout_plg_x->T->nonil = 1; + tout_plg_y->T->nonil = 1; + + BATkey(BATmirror(tout_plg_obsid), 0); + BATkey(BATmirror(tout_plg_ord), 0); + BATkey(BATmirror(tout_plg_x), 0); + BATkey(BATmirror(tout_plg_y), 0); + + /* Finally, append the result BATs to the result table + * Ignore errors, since we are finishing */ + msg = _append_bat(sql, tout_plg, "obsid", tout_plg_obsid); + msg = _append_bat(sql, tout_plg, "ord", tout_plg_ord); + msg = _append_bat(sql, tout_plg, "x", tout_plg_x); + msg = _append_bat(sql, tout_plg, "y", tout_plg_y); + goto CLEANUP_RETURN; + +CLEANUP_RETURN: + if (tout_plg_obsid) BBPunfix(tout_plg_obsid->batCacheid); + if (tout_plg_ord) BBPunfix(tout_plg_ord->batCacheid); + if (tout_plg_x) BBPunfix(tout_plg_x->batCacheid); + if (tout_plg_y) BBPunfix(tout_plg_y->batCacheid); + + return msg; } str @@ -107,7 +188,7 @@ SSDBintersects(Client cntxt, MalBlkPtr m str SSDBcooking(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) -{ /* cooking(tin:str, tout_obs:str, tout_plg:str):void */ +{ /* cooking(tin:str, tout_obs:str, tout_plg:str, width:int, height:int):void */ mvc *sql = NULL; sql_table *tin = NULL, *tout_obs = NULL, *tout_plg = NULL; /* tin (imageid int, x int, y int, val int) */ @@ -122,9 +203,6 @@ SSDBcooking(Client cntxt, MalBlkPtr mb, *tout_obs_centerx = NULL, *tout_obs_centery = NULL, *tout_obs_boxxstart = NULL, *tout_obs_boxystart = NULL, *tout_obs_boxxend = NULL, *tout_obs_boxyend = NULL; - /* tout_plg (obsid INT, ord INT, x INT, y INT) */ - BAT *tout_plg_obsid = NULL, *tout_plg_ord = NULL, - *tout_plg_x = NULL, *tout_plg_y = NULL; BUN i = 0, idx = 0, nr_pixs = 0, nr_obs = 0; unsigned int *pix_grpid = NULL, *obsid = NULL, cur_obsid = 0, last_obsid = 0; @@ -372,7 +450,7 @@ SSDBcooking(Client cntxt, MalBlkPtr mb, tout_obs_avgdist_t[cur_obsid] = wtdDistSum[cur_obsid] / tout_obs_pixsum_t[cur_obsid]; } - if ((msg = compute_polygon(obs_pix))) + if ((msg = compute_polygon(sql, nr_pixs, nr_obs, obs_pix, tout_plg))) goto CLEANUP_RETURN; /* Set proper properties for all BATs */ @@ -467,7 +545,8 @@ SSDBcooking(Client cntxt, MalBlkPtr mb, BATkey(BATmirror(tout_obs_boxxend), 0); BATkey(BATmirror(tout_obs_boxyend), 0); - /* Finally, append the result BATs to the result table */ + /* Finally, append the result BATs to the result table + * Ignore erros, since we are finishing */ msg = _append_bat(sql, tout_obs, "obsid", tout_obs_obsid); msg = _append_bat(sql, tout_obs, "imageid", tout_obs_imgid); msg = _append_bat(sql, tout_obs, "time", tout_obs_time); @@ -500,11 +579,6 @@ CLEANUP_RETURN: if (tout_obs_boxxend) BBPunfix(tout_obs_boxxend->batCacheid); if (tout_obs_boxyend) BBPunfix(tout_obs_boxyend->batCacheid); - if (tout_plg_obsid) BBPunfix(tout_plg_obsid->batCacheid); - if (tout_plg_ord) BBPunfix(tout_plg_ord->batCacheid); - if (tout_plg_x) BBPunfix(tout_plg_x->batCacheid); - if (tout_plg_y) BBPunfix(tout_plg_y->batCacheid); - if (pix_grpid) GDKfree(pix_grpid); if (obsid) GDKfree(obsid); if (wtdSumX) GDKfree(wtdSumX); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list