00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <string.h>
00022 #include "flgrCoreMalloc.h"
00023 #include "flgrCoreNhbManage.h"
00024 #include "flgrCoreDispatch.h"
00025 #include "flgrCoreDataIO.h"
00026
00037
00038
00040
00046
00047 FLGR_MorphoOptim flgr1d_get_optimization_available(FLGR_Data1D *datdest, FLGR_Data1D *datsrc, FLGR_Data1D *nhb) {
00048
00049 POST_DEBUG("Optimization flag detected : FLGR_MORPHO_OPTIM_NONE\n");
00050 return FLGR_MORPHO_OPTIM_NONE;
00051 }
00052
00053
00055
00062
00063 FLGR_NhbBox1D *flgr1d_create_neighbor_box(FLGR_Data1D *data) {
00064 FLGR_NhbBox1D *tmp;
00065 int typeSize, sizeMax,k;
00066
00067
00068
00069 if(data==NULL) {
00070 POST_ERROR("Null objects!\n");
00071 return NULL;
00072 }
00073
00074 typeSize = flgr_get_sizeof(data->type);
00075 sizeMax = data->length;
00076
00077 if(typeSize < 1) return NULL;
00078 if(data->spp < 1) return NULL;
00079
00080 tmp = flgr_malloc(sizeof(FLGR_NhbBox1D));
00081
00082 tmp->type = data->type;
00083 tmp->spp = data->spp;
00084
00085 tmp->center_data_val = flgr_vector_create(data->spp, data->type);
00086 tmp->center_nhb_val = flgr_vector_create(data->spp, data->type);
00087 tmp->center_coord_x = 0;
00088 tmp->nhb_size_x = data->length;
00089
00090 tmp->list_coord_x = (int **) flgr_malloc(sizeof(int*) * data->spp);
00091
00092 tmp->list_data_val = flgr_malloc(sizeof(void*) * data->spp);
00093 tmp->list_nhb_val = flgr_malloc(sizeof(void*) * data->spp);
00094
00095 tmp->size = (int *) flgr_malloc(sizeof(int) * data->spp);
00096
00097 for(k=0 ; k<data->spp ; k++) {
00098 tmp->list_coord_x[k] = flgr_malloc(sizeof(int) * sizeMax);
00099 tmp->list_data_val[k] = flgr_malloc(flgr_get_sizeof(tmp->type) * sizeMax);
00100 tmp->list_nhb_val[k] = flgr_malloc(flgr_get_sizeof(tmp->type) * sizeMax);
00101 tmp->size[k]=0;
00102 }
00103
00104 return tmp;
00105
00106 }
00107
00108
00109
00111
00115
00116 void flgr1d_destroy_neighbor_box(FLGR_NhbBox1D *extr) {
00117 int k;
00118
00119
00120 if(extr==NULL) {
00121 POST_ERROR("Null objects!\n");
00122 return;
00123 }
00124
00125 flgr_vector_destroy(extr->center_data_val);
00126 flgr_vector_destroy(extr->center_nhb_val);
00127
00128 flgr_free(extr->size);
00129
00130 for(k=0 ; k<extr->spp ; k++) {
00131 flgr_free(extr->list_coord_x[k]);
00132 flgr_free(extr->list_data_val[k]);
00133 flgr_free(extr->list_nhb_val[k]);
00134 }
00135
00136 flgr_free(extr->list_coord_x);
00137 flgr_free(extr->list_data_val);
00138 flgr_free(extr->list_nhb_val);
00139
00140 flgr_free(extr);
00141 }
00142
00143
00144
00146
00148 #define FLGR_MACRO_GET_NHB_1D_IN_DATA(dtype) \
00149 int j,k; \
00150 int l,m; \
00151 int nbpos; \
00152 int startpos,stoppos; \
00153 int nhbsize_xdiv2; \
00154 int spp = dat->spp; \
00155 dtype *pnhb = (dtype *) nhb->array; \
00156 dtype *pdat = (dtype *) dat->array; \
00157 dtype *list_data; \
00158 dtype *list_nhb; \
00159 int *list_coord_x; \
00160 int *size = extr->size; \
00161 dtype nhb_val,data_val; \
00162 \
00163 \
00164 \
00165 nhbsize_xdiv2=(nhb->length)>>1; \
00166 \
00167 extr->center_coord_x=pos; \
00168 \
00169 nbpos=dat->length; \
00170 \
00171 startpos=pos - nhbsize_xdiv2; \
00172 if(startpos<0) startpos=0; \
00173 \
00174 stoppos=pos + nhbsize_xdiv2; \
00175 if(stoppos>=nbpos) stoppos=nbpos-1; \
00176 \
00177 \
00178 flgr_get_data_array_vector_##dtype((dtype*) (extr->center_data_val->array), \
00179 (dtype*) (dat->array), \
00180 spp, pos); \
00181 \
00182 flgr_get_data_array_vector_##dtype((dtype*) (extr->center_nhb_val->array), \
00183 (dtype*) (nhb->array), \
00184 spp, nhbsize_xdiv2); \
00185 \
00186 \
00187 for(k=0 ; k<spp ; k++) { \
00188 l=startpos-pos+ nhbsize_xdiv2; \
00189 list_data = (dtype*) extr->list_data_val[k]; \
00190 list_nhb = (dtype*) extr->list_nhb_val[k]; \
00191 list_coord_x = (int*) extr->list_coord_x[k]; \
00192 m=0; \
00193 for(j=startpos ; j<=stoppos ; j++,l++) { \
00194 nhb_val = flgr1d_get_data_array_##dtype(pnhb, l*spp+k); \
00195 if(nhb_val!=0) { \
00196 data_val = flgr1d_get_data_array_##dtype(pdat, j*spp+k); \
00197 list_coord_x[m] = l; \
00198 list_data[m] = data_val; \
00199 list_nhb[m] = nhb_val; \
00200 m++; \
00201 } \
00202 } \
00203 size[k]=m; \
00204 } \
00205 \
00206 return
00207
00208
00209
00210
00211 void flgr1d_get_neighborhood_fgBIT(FLGR_NhbBox1D *extr,
00212 FLGR_Data1D *dat, FLGR_Data1D *nhb, int pos) {
00213 FLGR_MACRO_GET_NHB_1D_IN_DATA(fgBIT);
00214 }
00215
00216 void flgr1d_get_neighborhood_fgUINT8(FLGR_NhbBox1D *extr,
00217 FLGR_Data1D *dat, FLGR_Data1D *nhb, int pos) {
00218 FLGR_MACRO_GET_NHB_1D_IN_DATA(fgUINT8);
00219 }
00220
00221 void flgr1d_get_neighborhood_fgUINT16(FLGR_NhbBox1D *extr,
00222 FLGR_Data1D *dat, FLGR_Data1D *nhb, int pos) {
00223 FLGR_MACRO_GET_NHB_1D_IN_DATA(fgUINT16);
00224 }
00225
00226 void flgr1d_get_neighborhood_fgUINT32(FLGR_NhbBox1D *extr,
00227 FLGR_Data1D *dat, FLGR_Data1D *nhb, int pos) {
00228 FLGR_MACRO_GET_NHB_1D_IN_DATA(fgUINT32);
00229 }
00230
00231 void flgr1d_get_neighborhood_fgINT8(FLGR_NhbBox1D *extr,
00232 FLGR_Data1D *dat, FLGR_Data1D *nhb, int pos) {
00233 FLGR_MACRO_GET_NHB_1D_IN_DATA(fgINT8);
00234 }
00235
00236 void flgr1d_get_neighborhood_fgINT16(FLGR_NhbBox1D *extr,
00237 FLGR_Data1D *dat, FLGR_Data1D *nhb, int pos) {
00238 FLGR_MACRO_GET_NHB_1D_IN_DATA(fgINT16);
00239 }
00240
00241 void flgr1d_get_neighborhood_fgINT32(FLGR_NhbBox1D *extr,
00242 FLGR_Data1D *dat, FLGR_Data1D *nhb, int pos) {
00243 FLGR_MACRO_GET_NHB_1D_IN_DATA(fgINT32);
00244 }
00245
00246 void flgr1d_get_neighborhood_fgFLOAT32(FLGR_NhbBox1D *extr,
00247 FLGR_Data1D *dat, FLGR_Data1D *nhb, int pos) {
00248 FLGR_MACRO_GET_NHB_1D_IN_DATA(fgFLOAT32);
00249 }
00250
00251 void flgr1d_get_neighborhood_fgFLOAT64(FLGR_NhbBox1D *extr,
00252 FLGR_Data1D *dat, FLGR_Data1D *nhb, int pos) {
00253 FLGR_MACRO_GET_NHB_1D_IN_DATA(fgFLOAT64);
00254 }
00255
00256
00258
00267
00268 FLGR_Ret flgr1d_get_neighborhood(FLGR_NhbBox1D *extr,
00269 FLGR_Data1D *dat, FLGR_Data1D *nhb, int pos) {
00270
00271
00272
00273 if(dat==NULL) {
00274 POST_ERROR("Null objects!\n");
00275 return FLGR_RET_NULL_OBJECT;
00276 }
00277
00278 if(nhb==NULL) {
00279 POST_ERROR("Null objects!\n");
00280 return FLGR_RET_NULL_OBJECT;
00281 }
00282
00283 if(extr==NULL) {
00284 POST_ERROR("Null objects!\n");
00285 return FLGR_RET_NULL_OBJECT;
00286 }
00287
00288 if(dat->type != nhb->type) {
00289 POST_ERROR("Image structure and Neighborhood structure have differents types!\n");
00290 return FLGR_RET_TYPE_DIFFERENT;
00291 }
00292
00293 if(extr->type != nhb->type) {
00294 POST_ERROR("Neighbor Box and Neighborhood structure have differents types!\n");
00295 return FLGR_RET_TYPE_DIFFERENT;
00296 }
00297
00298 if(extr->nhb_size_x!=nhb->length) {
00299 POST_ERROR("Neighbor Box and Neighborhood structure have differents size_x (%d and %d)!\n",
00300 extr->nhb_size_x,nhb->length);
00301 return FLGR_RET_SIZE_ERROR;
00302 }
00303
00304 FLGR_DISPATCH_PROCEDURE(nhb->type,flgr1d_get_neighborhood,extr,dat,nhb,pos);
00305
00306 return FLGR_RET_OK;
00307 }
00308
00309
00310
00311
00312
00313
00315
00317 #define FLGR_MACRO_GET_NHB_1D_IN_DATA_UNFOLD(dtype) \
00318 int j,k,jj; \
00319 int l,m; \
00320 int nbpos; \
00321 int startpos,stoppos; \
00322 int nhbsize_xdiv2; \
00323 int spp = dat->spp; \
00324 dtype *pnhb = (dtype *) nhb->array; \
00325 dtype *pdat = (dtype *) dat->array; \
00326 dtype *list_data; \
00327 dtype *list_nhb; \
00328 int *list_coord_x; \
00329 int *size = extr->size; \
00330 dtype nhb_val,data_val; \
00331 \
00332 \
00333 \
00334 nhbsize_xdiv2=(nhb->length)>>1; \
00335 \
00336 extr->center_coord_x=pos; \
00337 \
00338 nbpos=dat->length; \
00339 \
00340 startpos=pos - nhbsize_xdiv2; \
00341 \
00342 stoppos=pos + nhbsize_xdiv2; \
00343 \
00344 flgr_get_data_array_vector_##dtype((dtype*) (extr->center_data_val->array), \
00345 (dtype*) (dat->array), \
00346 spp, pos); \
00347 \
00348 flgr_get_data_array_vector_##dtype((dtype*) (extr->center_nhb_val->array), \
00349 (dtype*) (nhb->array), \
00350 spp, nhbsize_xdiv2); \
00351 \
00352 \
00353 for(k=0 ; k<spp ; k++) { \
00354 list_data = (dtype*) extr->list_data_val[k]; \
00355 list_nhb = (dtype*) extr->list_nhb_val[k]; \
00356 list_coord_x = (int*) extr->list_coord_x[k]; \
00357 m=0; \
00358 for(j=startpos,l=0 ; j<=stoppos ; j++,l++) { \
00359 nhb_val = flgr1d_get_data_array_##dtype(pnhb, l*spp+k); \
00360 jj=flgr_normalize_coordinate(j,dat->length); \
00361 data_val = flgr1d_get_data_array_##dtype(pdat, jj*spp+k); \
00362 list_coord_x[m] = l; \
00363 list_data[m] = data_val; \
00364 list_nhb[m] = nhb_val; \
00365 m++; \
00366 } \
00367 size[k]=m; \
00368 } \
00369 \
00370 return
00371
00372
00373
00374
00375 void flgr1d_get_neighborhood_unfolded_fgBIT(FLGR_NhbBox1D *extr,
00376 FLGR_Data1D *dat, FLGR_Data1D *nhb, int pos) {
00377 FLGR_MACRO_GET_NHB_1D_IN_DATA_UNFOLD(fgBIT);
00378 }
00379
00380 void flgr1d_get_neighborhood_unfolded_fgUINT8(FLGR_NhbBox1D *extr,
00381 FLGR_Data1D *dat, FLGR_Data1D *nhb, int pos) {
00382 FLGR_MACRO_GET_NHB_1D_IN_DATA_UNFOLD(fgUINT8);
00383 }
00384
00385 void flgr1d_get_neighborhood_unfolded_fgUINT16(FLGR_NhbBox1D *extr,
00386 FLGR_Data1D *dat, FLGR_Data1D *nhb, int pos) {
00387 FLGR_MACRO_GET_NHB_1D_IN_DATA_UNFOLD(fgUINT16);
00388 }
00389
00390 void flgr1d_get_neighborhood_unfolded_fgUINT32(FLGR_NhbBox1D *extr,
00391 FLGR_Data1D *dat, FLGR_Data1D *nhb, int pos) {
00392 FLGR_MACRO_GET_NHB_1D_IN_DATA_UNFOLD(fgUINT32);
00393 }
00394
00395 void flgr1d_get_neighborhood_unfolded_fgINT8(FLGR_NhbBox1D *extr,
00396 FLGR_Data1D *dat, FLGR_Data1D *nhb, int pos) {
00397 FLGR_MACRO_GET_NHB_1D_IN_DATA_UNFOLD(fgINT8);
00398 }
00399
00400 void flgr1d_get_neighborhood_unfolded_fgINT16(FLGR_NhbBox1D *extr,
00401 FLGR_Data1D *dat, FLGR_Data1D *nhb, int pos) {
00402 FLGR_MACRO_GET_NHB_1D_IN_DATA_UNFOLD(fgINT16);
00403 }
00404
00405 void flgr1d_get_neighborhood_unfolded_fgINT32(FLGR_NhbBox1D *extr,
00406 FLGR_Data1D *dat, FLGR_Data1D *nhb, int pos) {
00407 FLGR_MACRO_GET_NHB_1D_IN_DATA_UNFOLD(fgINT32);
00408 }
00409
00410 void flgr1d_get_neighborhood_unfolded_fgFLOAT32(FLGR_NhbBox1D *extr,
00411 FLGR_Data1D *dat, FLGR_Data1D *nhb, int pos) {
00412 FLGR_MACRO_GET_NHB_1D_IN_DATA_UNFOLD(fgFLOAT32);
00413 }
00414
00415 void flgr1d_get_neighborhood_unfolded_fgFLOAT64(FLGR_NhbBox1D *extr,
00416 FLGR_Data1D *dat, FLGR_Data1D *nhb, int pos) {
00417 FLGR_MACRO_GET_NHB_1D_IN_DATA_UNFOLD(fgFLOAT64);
00418 }
00419
00420
00422
00431
00432 FLGR_Ret flgr1d_get_neighborhood_unfolded(FLGR_NhbBox1D *extr,
00433 FLGR_Data1D *dat, FLGR_Data1D *nhb, int pos) {
00434
00435
00436
00437 if(dat==NULL) {
00438 POST_ERROR("Null objects!\n");
00439 return FLGR_RET_NULL_OBJECT;
00440 }
00441
00442 if(nhb==NULL) {
00443 POST_ERROR("Null objects!\n");
00444 return FLGR_RET_NULL_OBJECT;
00445 }
00446
00447 if(extr==NULL) {
00448 POST_ERROR("Null objects!\n");
00449 return FLGR_RET_NULL_OBJECT;
00450 }
00451
00452 if(dat->type != nhb->type) {
00453 POST_ERROR("Image structure and Neighborhood structure have differents types!\n");
00454 return FLGR_RET_TYPE_DIFFERENT;
00455 }
00456
00457 if(extr->type != nhb->type) {
00458 POST_ERROR("Neighbor Box and Neighborhood structure have differents types!\n");
00459 return FLGR_RET_TYPE_DIFFERENT;
00460 }
00461
00462 if(extr->nhb_size_x!=nhb->length) {
00463 POST_ERROR("Neighbor Box and Neighborhood structure have differents size_x (%d and %d)!\n",
00464 extr->nhb_size_x,nhb->length);
00465 return FLGR_RET_SIZE_ERROR;
00466 }
00467
00468 FLGR_DISPATCH_PROCEDURE(nhb->type,flgr1d_get_neighborhood_unfolded,extr,dat,nhb,pos);
00469
00470 return FLGR_RET_OK;
00471 }
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00484
00490
00491 FLGR_MorphoOptim flgr2d_get_optimization_available(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, FLGR_Data2D *nhb) {
00492
00493
00494 if(datdest==datsrc) {
00495 POST_DEBUG("Optimization flag detected : FLGR_MORPHO_OPTIM_NONE\n");
00496 return FLGR_MORPHO_OPTIM_NONE;
00497 }
00498
00499
00500
00501 if( (flgr2d_data_is_connexity(nhb,FLGR_8_CONNEX)) && (flgr2d_data_is_shape(nhb,FLGR_RECT)) && (datsrc->type != FLGR_BIT)) {
00502 if((nhb->size_x==nhb->size_y) && (nhb->size_x<13)) {
00503 POST_DEBUG("Optimization flag detected : FLGR_MORPHO_OPTIM_SQUARE\n");
00504 return FLGR_MORPHO_OPTIM_SQUARE;
00505 }else if(datsrc->spp==1) {
00506 POST_DEBUG("Optimization flag detected : FLGR_MORPHO_OPTIM_RECTANGLE\n");
00507 return FLGR_MORPHO_OPTIM_RECTANGLE;
00508 }
00509 }else if((flgr2d_data_is_connexity(nhb,FLGR_8_CONNEX)) && (flgr2d_data_is_shape(nhb,FLGR_RECT)) && (datsrc->type == FLGR_BIT)){
00510 POST_DEBUG("Optimization flag detected : FLGR_MORPHO_OPTIM_SQUARE\n");
00511 return FLGR_MORPHO_OPTIM_SQUARE;
00512 }
00513
00514 if((flgr2d_data_is_connexity(nhb,FLGR_8_CONNEX)) && (flgr2d_data_is_shape(nhb,FLGR_OCTAGON)) ) {
00515 if(nhb->size_x==nhb->size_y) {
00516 POST_DEBUG("Optimization flag detected : FLGR_MORPHO_OPTIM_OCTAGON\n");
00517 return FLGR_MORPHO_OPTIM_OCTAGON;
00518 }
00519 }
00520
00521 if((flgr2d_data_is_connexity(nhb,FLGR_6_CONNEX)) && (flgr2d_data_is_shape(nhb,FLGR_HEX)) ) {
00522 if(nhb->size_x==nhb->size_y) {
00523 POST_DEBUG("Optimization flag detected : FLGR_MORPHO_OPTIM_HEXAGON\n");
00524 return FLGR_MORPHO_OPTIM_HEXAGON;
00525 }
00526 }
00527
00528 if((flgr2d_data_is_connexity(nhb,FLGR_4_CONNEX)) && (flgr2d_data_is_shape(nhb,FLGR_CROSS)) ) {
00529 if((nhb->size_x==nhb->size_y) && (nhb->size_x==3)) {
00530 POST_DEBUG("Optimization flag detected : FLGR_MORPHO_OPTIM_CROSS\n");
00531 return FLGR_MORPHO_OPTIM_CROSS;
00532 }
00533 }
00534
00535 if((flgr2d_data_is_connexity(nhb,FLGR_8_CONNEX)) && (flgr2d_data_is_shape(nhb,FLGR_DIAMOND)) ) {
00536 if(nhb->size_x==nhb->size_y) {
00537 POST_DEBUG("Optimization flag detected : FLGR_MORPHO_OPTIM_DIAMOND\n");
00538 return FLGR_MORPHO_OPTIM_DIAMOND;
00539 }
00540 }
00541
00542 return FLGR_MORPHO_OPTIM_NONE;
00543
00544 }
00545
00546
00547
00548
00549
00551
00558
00559 FLGR_NhbBox2D *flgr2d_create_neighbor_box(FLGR_Data2D *data) {
00560 FLGR_NhbBox2D *tmp;
00561 int sizeMax;
00562 int typeSize,k;
00563
00564
00565
00566 if(data==NULL) {
00567 POST_ERROR("Null objects!\n");
00568 return NULL;
00569 }
00570
00571 typeSize = flgr_get_sizeof(data->type);
00572 sizeMax = data->size_x*data->size_y;
00573
00574 if(typeSize < 1) return NULL;
00575 if(data->spp < 1) return NULL;
00576
00577
00578
00579 tmp = flgr_malloc(sizeof(FLGR_NhbBox2D));
00580
00581 tmp->type = data->type;
00582 tmp->spp = data->spp;
00583
00584 tmp->center_data_val = flgr_vector_create(data->spp, data->type);
00585 tmp->center_nhb_val = flgr_vector_create(data->spp, data->type);
00586 tmp->center_coord_y = 0;
00587 tmp->center_coord_x = 0;
00588 tmp->nhb_size_y = data->size_y;
00589 tmp->nhb_size_x = data->size_x;
00590
00591 tmp->list_coord_x = (int **) flgr_malloc(sizeof(int*) * data->spp);
00592 tmp->list_coord_y = (int **) flgr_malloc(sizeof(int*) * data->spp);
00593 tmp->list_data_val = (void **) flgr_malloc(sizeof(void*) *data->spp);
00594 tmp->list_nhb_val = (void **) flgr_malloc(sizeof(void*) *data->spp);
00595
00596 tmp->size = (int *) flgr_malloc(sizeof(int) * data->spp);
00597
00598 for(k=0 ; k<data->spp ; k++) {
00599 tmp->list_coord_y[k] = flgr_malloc(sizeof(int) * sizeMax);
00600 tmp->list_coord_x[k] = flgr_malloc(sizeof(int) * sizeMax);
00601 tmp->list_data_val[k] = flgr_malloc(flgr_get_sizeof(tmp->type) * sizeMax);
00602 tmp->list_nhb_val[k] = flgr_malloc(flgr_get_sizeof(tmp->type) * sizeMax);
00603 tmp->size[k]=0;
00604 }
00605
00606
00607 return tmp;
00608
00609 }
00610
00611
00613
00617
00618 void flgr2d_destroy_neighbor_box(FLGR_NhbBox2D *extr) {
00619 int k;
00620
00621
00622 if(extr==NULL) {
00623 POST_ERROR("Null objects!\n");
00624 return;
00625 }
00626
00627 for(k=0 ; k<extr->spp ; k++) {
00628 flgr_free(extr->list_data_val[k]);
00629 flgr_free(extr->list_nhb_val[k]);
00630 flgr_free(extr->list_coord_x[k]);
00631 flgr_free(extr->list_coord_y[k]);
00632 }
00633
00634
00635 flgr_vector_destroy(extr->center_data_val);
00636 flgr_vector_destroy(extr->center_nhb_val);
00637
00638 flgr_free(extr->list_coord_x);
00639 flgr_free(extr->list_coord_y);
00640 flgr_free(extr->list_data_val);
00641 flgr_free(extr->list_nhb_val);
00642 flgr_free(extr->size);
00643
00644 flgr_free(extr);
00645 }
00646
00647
00649
00651 #define FLGR_MACRO_GET_NHB_2D_IN_DATA(dtype) \
00652 int i,j,m; \
00653 int k,l,n; \
00654 int nbrow,nbcol; \
00655 int startrow,stoprow; \
00656 int startcol,stopcol; \
00657 int nhbsize_xdiv2; \
00658 int nhbsize_ydiv2; \
00659 int spp = dat->spp; \
00660 dtype **pnhb = (dtype **) nhb->array; \
00661 dtype **pdat = (dtype **) dat->array; \
00662 dtype *list_data; \
00663 dtype *list_nhb; \
00664 int *list_coord_x; \
00665 int *list_coord_y; \
00666 int *size = extr->size; \
00667 dtype nhb_val,data_val; \
00668 \
00669 \
00670 \
00671 nhbsize_xdiv2=(nhb->size_x)>>1; \
00672 nhbsize_ydiv2=(nhb->size_y)>>1; \
00673 nbrow=dat->size_y; nbcol=dat->size_x; \
00674 \
00675 extr->center_coord_y=row; \
00676 extr->center_coord_x=col; \
00677 \
00678 startrow=row - nhbsize_ydiv2; \
00679 startrow = (startrow<0) ? 0 : startrow; \
00680 \
00681 stoprow=row + nhbsize_ydiv2; \
00682 stoprow = (stoprow>=nbrow) ? nbrow-1 : stoprow; \
00683 \
00684 startcol=col - nhbsize_xdiv2; \
00685 startcol = (startcol<0) ? 0 : startcol; \
00686 \
00687 stopcol=col + nhbsize_xdiv2; \
00688 stopcol = (stopcol>=nbcol) ? nbcol-1 : stopcol; \
00689 \
00690 \
00691 flgr_get_data_array_vector_##dtype((dtype*) (extr->center_data_val->array), \
00692 (dtype*) (dat->array[row]), \
00693 spp, col); \
00694 \
00695 flgr_get_data_array_vector_##dtype((dtype*) (extr->center_nhb_val->array), \
00696 (dtype*) (nhb->array[nhbsize_ydiv2]), \
00697 spp, nhbsize_xdiv2); \
00698 \
00699 \
00700 \
00701 for(n=0 ; n<spp ; n++) { \
00702 list_data = (dtype*) extr->list_data_val[n]; \
00703 list_nhb = (dtype*) extr->list_nhb_val[n]; \
00704 list_coord_x = (int*) extr->list_coord_x[n]; \
00705 list_coord_y = (int*) extr->list_coord_y[n]; \
00706 m=0; \
00707 k=startrow-row+nhbsize_ydiv2; \
00708 for(i=startrow ; i<=stoprow ; i++,k++) { \
00709 \
00710 l=startcol-col+nhbsize_xdiv2; \
00711 \
00712 for(j=startcol ; j<=stopcol ; j++,l++) { \
00713 \
00714 nhb_val = flgr2d_get_data_array_##dtype(pnhb, k, l*spp+n); \
00715 if(nhb_val!=0) { \
00716 data_val = flgr2d_get_data_array_##dtype(pdat,i, j*spp+n); \
00717 list_coord_x[m] = l; \
00718 list_coord_y[m] = k; \
00719 list_data[m] = data_val; \
00720 list_nhb[m] = nhb_val; \
00721 m++; \
00722 } \
00723 \
00724 } \
00725 } \
00726 size[n]=m; \
00727 } \
00728 \
00729 return
00730
00731
00732
00733
00734 void flgr2d_get_neighborhood_fgBIT(FLGR_NhbBox2D *extr,
00735 FLGR_Data2D *dat, FLGR_Data2D *nhb, int row, int col) {
00736 FLGR_MACRO_GET_NHB_2D_IN_DATA(fgBIT);
00737 }
00738
00739 void flgr2d_get_neighborhood_fgUINT8(FLGR_NhbBox2D *extr,
00740 FLGR_Data2D *dat, FLGR_Data2D *nhb, int row, int col) {
00741 FLGR_MACRO_GET_NHB_2D_IN_DATA(fgUINT8);
00742 }
00743
00744 void flgr2d_get_neighborhood_fgUINT16(FLGR_NhbBox2D *extr,
00745 FLGR_Data2D *dat, FLGR_Data2D *nhb, int row, int col) {
00746 FLGR_MACRO_GET_NHB_2D_IN_DATA(fgUINT16);
00747 }
00748
00749 void flgr2d_get_neighborhood_fgUINT32(FLGR_NhbBox2D *extr,
00750 FLGR_Data2D *dat, FLGR_Data2D *nhb, int row, int col) {
00751 FLGR_MACRO_GET_NHB_2D_IN_DATA(fgUINT32);
00752 }
00753
00754 void flgr2d_get_neighborhood_fgINT8(FLGR_NhbBox2D *extr,
00755 FLGR_Data2D *dat, FLGR_Data2D *nhb, int row, int col) {
00756 FLGR_MACRO_GET_NHB_2D_IN_DATA(fgINT8);
00757 }
00758
00759 void flgr2d_get_neighborhood_fgINT16(FLGR_NhbBox2D *extr,
00760 FLGR_Data2D *dat, FLGR_Data2D *nhb, int row, int col) {
00761 FLGR_MACRO_GET_NHB_2D_IN_DATA(fgINT16);
00762 }
00763
00764 void flgr2d_get_neighborhood_fgINT32(FLGR_NhbBox2D *extr,
00765 FLGR_Data2D *dat, FLGR_Data2D *nhb, int row, int col) {
00766 FLGR_MACRO_GET_NHB_2D_IN_DATA(fgINT32);
00767 }
00768
00769 void flgr2d_get_neighborhood_fgFLOAT32(FLGR_NhbBox2D *extr,
00770 FLGR_Data2D *dat, FLGR_Data2D *nhb, int row, int col) {
00771 FLGR_MACRO_GET_NHB_2D_IN_DATA(fgFLOAT32);
00772 }
00773
00774 void flgr2d_get_neighborhood_fgFLOAT64(FLGR_NhbBox2D *extr,
00775 FLGR_Data2D *dat, FLGR_Data2D *nhb, int row, int col) {
00776 FLGR_MACRO_GET_NHB_2D_IN_DATA(fgFLOAT64);
00777 }
00778
00779
00781
00791
00792 FLGR_Ret flgr2d_get_neighborhood(FLGR_NhbBox2D *extr,
00793 FLGR_Data2D *dat, FLGR_Data2D *nhb, int row, int col) {
00794
00795
00796
00797 if((dat==NULL) || (nhb==NULL) || (extr==NULL)) {
00798 POST_ERROR("Null objects!\n");
00799 return FLGR_RET_NULL_OBJECT;
00800 }
00801
00802
00803 if(dat->type != nhb->type) {
00804 POST_ERROR("Image structure and Neighborhood structure have differents types!\n");
00805 return FLGR_RET_TYPE_DIFFERENT;
00806 }
00807
00808 if(extr->type != nhb->type) {
00809 POST_ERROR("Neighbor Box and Neighborhood structure have differents types!\n");
00810 return FLGR_RET_TYPE_DIFFERENT;
00811 }
00812
00813 if(extr->nhb_size_x != nhb->size_x) {
00814 POST_ERROR("Neighbor Box and Neighborhood structure have differents size_x (%d and %d)!\n",extr->nhb_size_x,nhb->size_x);
00815 return FLGR_RET_SIZE_ERROR;
00816 }
00817
00818 if(extr->nhb_size_y != nhb->size_y) {
00819 POST_ERROR("Neighbor Box and Neighborhood structure have differents size_y (%d and %d)!\n",extr->nhb_size_y,nhb->size_y);
00820 return FLGR_RET_SIZE_ERROR;
00821 }
00822
00823 FLGR_DISPATCH_PROCEDURE(nhb->type,flgr2d_get_neighborhood,extr,dat,nhb,row,col);
00824
00825 return FLGR_RET_OK;
00826 }
00827
00828
00829
00830
00831
00832
00833
00834
00836
00838 #define FLGR_MACRO_GET_NHB_2D_IN_DATA_UNFOLDED(dtype) \
00839 int i,ii,j,jj,m; \
00840 int k,l,n; \
00841 int nbrow,nbcol; \
00842 int startrow,stoprow; \
00843 int startcol,stopcol; \
00844 int nhbsize_xdiv2; \
00845 int nhbsize_ydiv2; \
00846 int spp = dat->spp; \
00847 dtype **pnhb = (dtype **) nhb->array; \
00848 dtype **pdat = (dtype **) dat->array; \
00849 dtype *list_data; \
00850 dtype *list_nhb; \
00851 int *list_coord_x; \
00852 int *list_coord_y; \
00853 int *size = extr->size; \
00854 dtype nhb_val,data_val; \
00855 \
00856 \
00857 \
00858 nhbsize_xdiv2=(nhb->size_x)>>1; \
00859 nhbsize_ydiv2=(nhb->size_y)>>1; \
00860 nbrow=dat->size_y; nbcol=dat->size_x; \
00861 \
00862 extr->center_coord_y=row; \
00863 extr->center_coord_x=col; \
00864 \
00865 startrow=row - nhbsize_ydiv2; \
00866 \
00867 stoprow=row + nhbsize_ydiv2; \
00868 \
00869 startcol=col - nhbsize_xdiv2; \
00870 \
00871 stopcol=col + nhbsize_xdiv2; \
00872 \
00873 \
00874 flgr_get_data_array_vector_##dtype((dtype*) (extr->center_data_val->array), \
00875 (dtype*) (dat->array[row]), \
00876 spp, col); \
00877 \
00878 flgr_get_data_array_vector_##dtype((dtype*) (extr->center_nhb_val->array), \
00879 (dtype*) (nhb->array[nhbsize_ydiv2]), \
00880 spp, nhbsize_xdiv2); \
00881 \
00882 \
00883 for(n=0 ; n<spp ; n++) { \
00884 list_data = (dtype*) extr->list_data_val[n]; \
00885 list_nhb = (dtype*) extr->list_nhb_val[n]; \
00886 list_coord_x = (int*) extr->list_coord_x[n]; \
00887 list_coord_y = (int*) extr->list_coord_y[n]; \
00888 m=0; \
00889 for(i=startrow,k=0 ; i<=stoprow ; i++,k++) { \
00890 ii = flgr_normalize_coordinate(i,dat->size_y); \
00891 for(j=startcol,l=0 ; j<=stopcol ; j++,l++) { \
00892 \
00893 nhb_val = flgr2d_get_data_array_##dtype(pnhb, k, l*spp+n); \
00894 jj = flgr_normalize_coordinate(j,dat->size_x); \
00895 data_val = flgr2d_get_data_array_##dtype(pdat,ii, jj*spp+n); \
00896 list_coord_x[m] = l; \
00897 list_coord_y[m] = k; \
00898 list_data[m] = data_val; \
00899 list_nhb[m] = nhb_val; \
00900 m++; \
00901 \
00902 } \
00903 } \
00904 size[n]=m; \
00905 } \
00906 \
00907 return
00908
00909
00910
00911
00912 void flgr2d_get_neighborhood_unfolded_fgBIT(FLGR_NhbBox2D *extr,
00913 FLGR_Data2D *dat, FLGR_Data2D *nhb, int row, int col) {
00914 FLGR_MACRO_GET_NHB_2D_IN_DATA_UNFOLDED(fgBIT);
00915 }
00916
00917 void flgr2d_get_neighborhood_unfolded_fgUINT8(FLGR_NhbBox2D *extr,
00918 FLGR_Data2D *dat, FLGR_Data2D *nhb, int row, int col) {
00919 FLGR_MACRO_GET_NHB_2D_IN_DATA_UNFOLDED(fgUINT8);
00920 }
00921
00922 void flgr2d_get_neighborhood_unfolded_fgUINT16(FLGR_NhbBox2D *extr,
00923 FLGR_Data2D *dat, FLGR_Data2D *nhb, int row, int col) {
00924 FLGR_MACRO_GET_NHB_2D_IN_DATA_UNFOLDED(fgUINT16);
00925 }
00926
00927 void flgr2d_get_neighborhood_unfolded_fgUINT32(FLGR_NhbBox2D *extr,
00928 FLGR_Data2D *dat, FLGR_Data2D *nhb, int row, int col) {
00929 FLGR_MACRO_GET_NHB_2D_IN_DATA_UNFOLDED(fgUINT32);
00930 }
00931
00932 void flgr2d_get_neighborhood_unfolded_fgINT8(FLGR_NhbBox2D *extr,
00933 FLGR_Data2D *dat, FLGR_Data2D *nhb, int row, int col) {
00934 FLGR_MACRO_GET_NHB_2D_IN_DATA_UNFOLDED(fgINT8);
00935 }
00936
00937 void flgr2d_get_neighborhood_unfolded_fgINT16(FLGR_NhbBox2D *extr,
00938 FLGR_Data2D *dat, FLGR_Data2D *nhb, int row, int col) {
00939 FLGR_MACRO_GET_NHB_2D_IN_DATA_UNFOLDED(fgINT16);
00940 }
00941
00942 void flgr2d_get_neighborhood_unfolded_fgINT32(FLGR_NhbBox2D *extr,
00943 FLGR_Data2D *dat, FLGR_Data2D *nhb, int row, int col) {
00944 FLGR_MACRO_GET_NHB_2D_IN_DATA_UNFOLDED(fgINT32);
00945 }
00946
00947 void flgr2d_get_neighborhood_unfolded_fgFLOAT32(FLGR_NhbBox2D *extr,
00948 FLGR_Data2D *dat, FLGR_Data2D *nhb, int row, int col) {
00949 FLGR_MACRO_GET_NHB_2D_IN_DATA_UNFOLDED(fgFLOAT32);
00950 }
00951
00952 void flgr2d_get_neighborhood_unfolded_fgFLOAT64(FLGR_NhbBox2D *extr,
00953 FLGR_Data2D *dat, FLGR_Data2D *nhb, int row, int col) {
00954 FLGR_MACRO_GET_NHB_2D_IN_DATA_UNFOLDED(fgFLOAT64);
00955 }
00956
00957
00959
00969
00970 FLGR_Ret flgr2d_get_neighborhood_unfolded(FLGR_NhbBox2D *extr,
00971 FLGR_Data2D *dat, FLGR_Data2D *nhb, int row, int col) {
00972
00973
00974
00975 if((dat==NULL) || (nhb==NULL) || (extr==NULL)) {
00976 POST_ERROR("Null objects!\n");
00977 return FLGR_RET_NULL_OBJECT;
00978 }
00979
00980
00981 if(dat->type != nhb->type) {
00982 POST_ERROR("Image structure and Neighborhood_Unfolded structure have differents types!\n");
00983 return FLGR_RET_TYPE_DIFFERENT;
00984 }
00985
00986 if(extr->type != nhb->type) {
00987 POST_ERROR("Neighbor Box and Neighborhood_Unfolded structure have differents types!\n");
00988 return FLGR_RET_TYPE_DIFFERENT;
00989 }
00990
00991 if(extr->nhb_size_x != nhb->size_x) {
00992 POST_ERROR("Neighbor Box and Neighborhood_Unfolded structure have differents size_x (%d and %d)!\n",extr->nhb_size_x,nhb->size_x);
00993 return FLGR_RET_SIZE_ERROR;
00994 }
00995
00996 if(extr->nhb_size_y != nhb->size_y) {
00997 POST_ERROR("Neighbor Box and Neighborhood_Unfolded structure have differents size_y (%d and %d)!\n",extr->nhb_size_y,nhb->size_y);
00998 return FLGR_RET_SIZE_ERROR;
00999 }
01000
01001 FLGR_DISPATCH_PROCEDURE(nhb->type,flgr2d_get_neighborhood_unfolded,extr,dat,nhb,row,col);
01002
01003 return FLGR_RET_OK;
01004 }
01005
01006
01007
01008
01009
01010
01011
01013
01014