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 <math.h>
00023 #include "flgrCoreArithVector.h"
00024 #include "flgrCoreMalloc.h"
00025 #include "flgrCoreDataIO.h"
00026 #include "flgrCoreDispatch.h"
00027 #include "flgrCoreGeometry.h"
00028 #include "flgrCoreCopy.h"
00029 #include "flgrCoreNhbFill.h"
00030
00031
00040
00041
00043 #define FLGR_MACRO_NATIVE_DILATE(dtype, \
00044 c00,c01,c02, \
00045 c10,c11,c12, \
00046 c20,c21,c22) \
00047 FLGR_Data2D *nhbcopy; \
00048 dtype **seodd; \
00049 dtype **seeven; \
00050 dtype **se; \
00051 int i,j; \
00052 int k,l; \
00053 int m,n; \
00054 \
00055 dtype valse; \
00056 \
00057 FLGR_Vector *vecPixValue = flgr_vector_create(nhb->spp,nhb->type); \
00058 FLGR_Vector *vecPixMax = flgr_vector_create(nhb->spp,nhb->type); \
00059 FLGR_Vector *vecSeValue = flgr_vector_create(nhb->spp,nhb->type); \
00060 \
00061 \
00062 \
00063 nhbcopy = flgr2d_create_from(nhb); \
00064 flgr2d_copy(nhbcopy,nhb); \
00065 \
00066 seodd = (dtype**) flgr_malloc(sizeof(dtype*)*3); \
00067 seodd[0] = (dtype*) flgr_malloc(sizeof(dtype)*3); \
00068 seodd[1] = (dtype*) flgr_malloc(sizeof(dtype)*3); \
00069 seodd[2] = (dtype*) flgr_malloc(sizeof(dtype)*3); \
00070 \
00071 seeven = (dtype**) flgr_malloc(sizeof(dtype*)*3); \
00072 seeven[0] = (dtype*) flgr_malloc(sizeof(dtype)*3); \
00073 seeven[1] = (dtype*) flgr_malloc(sizeof(dtype)*3); \
00074 seeven[2] = (dtype*) flgr_malloc(sizeof(dtype)*3); \
00075 \
00076 flgr2d_set_data_array_##dtype(seodd,0,0,c02); \
00077 flgr2d_set_data_array_##dtype(seodd,0,1,c01); \
00078 flgr2d_set_data_array_##dtype(seodd,0,2,c00); \
00079 flgr2d_set_data_array_##dtype(seodd,1,0,c10); \
00080 flgr2d_set_data_array_##dtype(seodd,1,1,c11); \
00081 flgr2d_set_data_array_##dtype(seodd,1,2,c12); \
00082 flgr2d_set_data_array_##dtype(seodd,2,0,c22); \
00083 flgr2d_set_data_array_##dtype(seodd,2,1,c21); \
00084 flgr2d_set_data_array_##dtype(seodd,2,2,c20); \
00085 \
00086 flgr2d_set_data_array_##dtype(seeven,0,0,c00); \
00087 flgr2d_set_data_array_##dtype(seeven,0,1,c01); \
00088 flgr2d_set_data_array_##dtype(seeven,0,2,c02); \
00089 flgr2d_set_data_array_##dtype(seeven,1,0,c10); \
00090 flgr2d_set_data_array_##dtype(seeven,1,1,c11); \
00091 flgr2d_set_data_array_##dtype(seeven,1,2,c12); \
00092 flgr2d_set_data_array_##dtype(seeven,2,0,c20); \
00093 flgr2d_set_data_array_##dtype(seeven,2,1,c21); \
00094 flgr2d_set_data_array_##dtype(seeven,2,2,c22); \
00095 \
00096 for(i=0; i<nhb->size_y; i++) { \
00097 for(j=0; j<nhb->size_x; j++) { \
00098 \
00099 flgr_vector_populate_from_scalar_##dtype(vecPixMax,0); \
00100 \
00101 for(k=(i-1),m=0 ; k<=(i+1) ; k++,m++) { \
00102 if((k>=0) && (k<nhb->size_y)) { \
00103 for(l=(j-1),n=0 ; l<=(j+1) ; l++,n++) { \
00104 if((l>=0) && (l<nhb->size_x)) { \
00105 \
00106 se = (((i%2)==1) ? seodd:seeven); \
00107 \
00108 valse = flgr2d_get_data_array_##dtype(se,m,n); \
00109 flgr_vector_populate_from_scalar_##dtype(vecSeValue, \
00110 valse); \
00111 \
00112 flgr2d_get_data_vector_no_norm_##dtype(nhbcopy,k,l, \
00113 vecPixValue); \
00114 \
00115 flgr_vector_mult_##dtype(vecPixValue, \
00116 vecPixValue,vecSeValue); \
00117 \
00118 flgr_vector_sup_##dtype(vecPixMax, \
00119 vecPixMax,vecPixValue); \
00120 \
00121 } \
00122 } \
00123 } \
00124 } \
00125 \
00126 flgr2d_set_data_vector_##dtype(nhb,i,j,vecPixMax); \
00127 \
00128 } \
00129 } \
00130 \
00131 flgr_vector_destroy(vecPixValue); \
00132 flgr_vector_destroy(vecPixMax); \
00133 flgr_vector_destroy(vecSeValue); \
00134 \
00135 flgr2d_destroy(nhbcopy); \
00136 flgr_free(seodd[0]); \
00137 flgr_free(seodd[1]); \
00138 flgr_free(seodd[2]); \
00139 flgr_free(seodd); \
00140 flgr_free(seeven[0]); \
00141 flgr_free(seeven[1]); \
00142 flgr_free(seeven[2]); \
00143 flgr_free(seeven); \
00144 return
00145
00146 void flgr2d_native_dilate_4_connexity_fgBIT(FLGR_Data2D *nhb) {
00147 FLGR_MACRO_NATIVE_DILATE(fgBIT,0,1,0,1,1,1,0,1,0);
00148 }
00149 void flgr2d_native_dilate_4_connexity_fgUINT8(FLGR_Data2D *nhb) {
00150 FLGR_MACRO_NATIVE_DILATE(fgUINT8,0,1,0,1,1,1,0,1,0);
00151 }
00152 void flgr2d_native_dilate_4_connexity_fgUINT16(FLGR_Data2D *nhb) {
00153 FLGR_MACRO_NATIVE_DILATE(fgUINT16,0,1,0,1,1,1,0,1,0);
00154 }
00155 void flgr2d_native_dilate_4_connexity_fgUINT32(FLGR_Data2D *nhb) {
00156 FLGR_MACRO_NATIVE_DILATE(fgUINT32,0,1,0,1,1,1,0,1,0);
00157 }
00158 void flgr2d_native_dilate_4_connexity_fgINT8(FLGR_Data2D *nhb) {
00159 FLGR_MACRO_NATIVE_DILATE(fgINT8,0,1,0,1,1,1,0,1,0);
00160 }
00161 void flgr2d_native_dilate_4_connexity_fgINT16(FLGR_Data2D *nhb) {
00162 FLGR_MACRO_NATIVE_DILATE(fgINT16,0,1,0,1,1,1,0,1,0);
00163 }
00164 void flgr2d_native_dilate_4_connexity_fgINT32(FLGR_Data2D *nhb) {
00165 FLGR_MACRO_NATIVE_DILATE(fgINT32,0,1,0,1,1,1,0,1,0);
00166 }
00167 void flgr2d_native_dilate_4_connexity_fgFLOAT32(FLGR_Data2D *nhb) {
00168 FLGR_MACRO_NATIVE_DILATE(fgFLOAT32,0,1,0,1,1,1,0,1,0);
00169 }
00170 void flgr2d_native_dilate_4_connexity_fgFLOAT64(FLGR_Data2D *nhb) {
00171 FLGR_MACRO_NATIVE_DILATE(fgFLOAT64,0,1,0,1,1,1,0,1,0);
00172 }
00173
00175
00179
00180 FLGR_Ret flgr2d_native_dilate_4_connexity(FLGR_Data2D *nhb) {
00181
00182
00183 if(nhb==NULL) {
00184 POST_ERROR("Null objects!\n");
00185 return FLGR_RET_NULL_OBJECT;
00186 }
00187
00188 FLGR_DISPATCH_PROCEDURE(nhb->type,flgr2d_native_dilate_4_connexity,nhb);
00189 }
00190
00191
00192 void flgr2d_native_dilate_6_connexity_fgBIT(FLGR_Data2D *nhb) {
00193 FLGR_MACRO_NATIVE_DILATE(fgBIT,0,1,1,1,1,1,0,1,1);
00194 }
00195 void flgr2d_native_dilate_6_connexity_fgUINT8(FLGR_Data2D *nhb) {
00196 FLGR_MACRO_NATIVE_DILATE(fgUINT8,0,1,1,1,1,1,0,1,1);
00197 }
00198 void flgr2d_native_dilate_6_connexity_fgUINT16(FLGR_Data2D *nhb) {
00199 FLGR_MACRO_NATIVE_DILATE(fgUINT16,0,1,1,1,1,1,0,1,1);
00200 }
00201 void flgr2d_native_dilate_6_connexity_fgUINT32(FLGR_Data2D *nhb) {
00202 FLGR_MACRO_NATIVE_DILATE(fgUINT32,0,1,1,1,1,1,0,1,1);
00203 }
00204 void flgr2d_native_dilate_6_connexity_fgINT8(FLGR_Data2D *nhb) {
00205 FLGR_MACRO_NATIVE_DILATE(fgINT8,0,1,1,1,1,1,0,1,1);
00206 }
00207 void flgr2d_native_dilate_6_connexity_fgINT16(FLGR_Data2D *nhb) {
00208 FLGR_MACRO_NATIVE_DILATE(fgINT16,0,1,1,1,1,1,0,1,1);
00209 }
00210 void flgr2d_native_dilate_6_connexity_fgINT32(FLGR_Data2D *nhb) {
00211 FLGR_MACRO_NATIVE_DILATE(fgINT32,0,1,1,1,1,1,0,1,1);
00212 }
00213 void flgr2d_native_dilate_6_connexity_fgFLOAT32(FLGR_Data2D *nhb) {
00214 FLGR_MACRO_NATIVE_DILATE(fgFLOAT32,0,1,1,1,1,1,0,1,1);
00215 }
00216 void flgr2d_native_dilate_6_connexity_fgFLOAT64(FLGR_Data2D *nhb) {
00217 FLGR_MACRO_NATIVE_DILATE(fgFLOAT64,0,1,1,1,1,1,0,1,1);
00218 }
00219
00221
00225
00226 FLGR_Ret flgr2d_native_dilate_6_connexity(FLGR_Data2D *nhb) {
00227
00228
00229 if(nhb==NULL) {
00230 POST_ERROR("Null objects!\n");
00231 return FLGR_RET_NULL_OBJECT;
00232 }
00233
00234 FLGR_DISPATCH_PROCEDURE(nhb->type,flgr2d_native_dilate_6_connexity,nhb);
00235 }
00236
00237
00238 void flgr2d_native_dilate_8_connexity_fgBIT(FLGR_Data2D *nhb) {
00239 FLGR_MACRO_NATIVE_DILATE(fgBIT,1,1,1,1,1,1,1,1,1);
00240 }
00241 void flgr2d_native_dilate_8_connexity_fgUINT8(FLGR_Data2D *nhb) {
00242 FLGR_MACRO_NATIVE_DILATE(fgUINT8,1,1,1,1,1,1,1,1,1);
00243 }
00244 void flgr2d_native_dilate_8_connexity_fgUINT16(FLGR_Data2D *nhb) {
00245 FLGR_MACRO_NATIVE_DILATE(fgUINT16,1,1,1,1,1,1,1,1,1);
00246 }
00247 void flgr2d_native_dilate_8_connexity_fgUINT32(FLGR_Data2D *nhb) {
00248 FLGR_MACRO_NATIVE_DILATE(fgUINT32,1,1,1,1,1,1,1,1,1);
00249 }
00250 void flgr2d_native_dilate_8_connexity_fgINT8(FLGR_Data2D *nhb) {
00251 FLGR_MACRO_NATIVE_DILATE(fgINT8,1,1,1,1,1,1,1,1,1);
00252 }
00253 void flgr2d_native_dilate_8_connexity_fgINT16(FLGR_Data2D *nhb) {
00254 FLGR_MACRO_NATIVE_DILATE(fgINT16,1,1,1,1,1,1,1,1,1);
00255 }
00256 void flgr2d_native_dilate_8_connexity_fgINT32(FLGR_Data2D *nhb) {
00257 FLGR_MACRO_NATIVE_DILATE(fgINT32,1,1,1,1,1,1,1,1,1);
00258 }
00259 void flgr2d_native_dilate_8_connexity_fgFLOAT32(FLGR_Data2D *nhb) {
00260 FLGR_MACRO_NATIVE_DILATE(fgFLOAT32,1,1,1,1,1,1,1,1,1);
00261 }
00262 void flgr2d_native_dilate_8_connexity_fgFLOAT64(FLGR_Data2D *nhb) {
00263 FLGR_MACRO_NATIVE_DILATE(fgFLOAT64,1,1,1,1,1,1,1,1,1);
00264 }
00265
00267
00271
00272 FLGR_Ret flgr2d_native_dilate_8_connexity(FLGR_Data2D *nhb) {
00273
00274
00275 if(nhb==NULL) {
00276 POST_ERROR("Null objects!\n");
00277 return FLGR_RET_NULL_OBJECT;
00278 }
00279
00280 FLGR_DISPATCH_PROCEDURE(nhb->type,flgr2d_native_dilate_8_connexity,nhb);
00281 }
00282
00283
00284
00285
00286
00287
00289
00291 #define FLGR_MACRO_FILL_1D_SHP(dtype) \
00292 FLGR_Vector *vec1 = flgr_vector_create(nhb->spp,nhb->type); \
00293 \
00294 flgr_vector_populate_from_scalar_##dtype(vec1,1); \
00295 \
00296 if(nhb->shape == FLGR_LINE) { \
00297 flgr1d_draw_line_##dtype(nhb,nhb->length/2-width/2,width,vec1); \
00298 } \
00299 \
00300 flgr_vector_destroy(vec1); \
00301 \
00302 return
00303
00304
00305 void flgr1d_fill_neighborhood_fgBIT(FLGR_Data1D *nhb, FLGR_Shape shape, int width) {
00306 FLGR_MACRO_FILL_1D_SHP(fgBIT);
00307 }
00308 void flgr1d_fill_neighborhood_fgUINT8(FLGR_Data1D *nhb, FLGR_Shape shape, int width) {
00309 FLGR_MACRO_FILL_1D_SHP(fgUINT8);
00310 }
00311 void flgr1d_fill_neighborhood_fgUINT16(FLGR_Data1D *nhb, FLGR_Shape shape, int width) {
00312 FLGR_MACRO_FILL_1D_SHP(fgUINT16);
00313 }
00314 void flgr1d_fill_neighborhood_fgUINT32(FLGR_Data1D *nhb, FLGR_Shape shape, int width) {
00315 FLGR_MACRO_FILL_1D_SHP(fgUINT32);
00316 }
00317 void flgr1d_fill_neighborhood_fgINT8(FLGR_Data1D *nhb, FLGR_Shape shape, int width) {
00318 FLGR_MACRO_FILL_1D_SHP(fgINT8);
00319 }
00320 void flgr1d_fill_neighborhood_fgINT16(FLGR_Data1D *nhb, FLGR_Shape shape, int width) {
00321 FLGR_MACRO_FILL_1D_SHP(fgINT16);
00322 }
00323 void flgr1d_fill_neighborhood_fgINT32(FLGR_Data1D *nhb, FLGR_Shape shape, int width) {
00324 FLGR_MACRO_FILL_1D_SHP(fgINT32);
00325 }
00326 void flgr1d_fill_neighborhood_fgFLOAT32(FLGR_Data1D *nhb, FLGR_Shape shape, int width) {
00327 FLGR_MACRO_FILL_1D_SHP(fgFLOAT32);
00328 }
00329 void flgr1d_fill_neighborhood_fgFLOAT64(FLGR_Data1D *nhb, FLGR_Shape shape, int width) {
00330 FLGR_MACRO_FILL_1D_SHP(fgFLOAT64);
00331 }
00332
00334
00340
00341 FLGR_Ret flgr1d_fill_neighborhood(FLGR_Data1D *nhb, FLGR_Shape shape, int width) {
00342 if(nhb==NULL) {
00343 POST_ERROR("Null objects!\n");
00344 return FLGR_RET_NULL_OBJECT;
00345 }
00346
00347 FLGR_DISPATCH_PROCEDURE(nhb->type,flgr1d_fill_neighborhood,nhb,shape,width);
00348 }
00349
00350
00351
00352
00354
00356 #define FLGR_MACRO_FILL_2D_SHP(dtype) \
00357 FLGR_Vector *vec1 = flgr_vector_create(nhb->spp,nhb->type); \
00358 FLGR_Data2D *tmp = flgr2d_create_from(nhb); \
00359 int h=nhb->size_y; \
00360 int w=nhb->size_x; \
00361 int size=((height<width) ? height:width); \
00362 double size_square = ((double) (size/2)) / (1+sqrt(2)); \
00363 double size_square2 = floor(size_square); \
00364 int nbsqr = (int) ((size_square-size_square2) < 0.5f ? \
00365 size_square2 : (size_square2+1)); \
00366 int i; \
00367 \
00368 flgr2d_clear_all(nhb); \
00369 flgr_vector_populate_from_scalar_##dtype(vec1,1); \
00370 \
00371 if(shape == FLGR_HEX) { \
00372 flgr2d_set_data_vector_##dtype(nhb,h/2,w/2,vec1); \
00373 for(i=0;i<size/2;i++) flgr2d_native_dilate_6_connexity_##dtype(nhb);\
00374 if( ((size/2)%2)==1 ) { \
00375 flgr2d_fill_nhb_even_rows_##dtype(tmp,nhb); \
00376 flgr2d_copy(nhb,tmp); \
00377 } \
00378 \
00379 }else if(shape == FLGR_RECT) { \
00380 flgr2d_draw_filled_rectangle_##dtype(nhb,w/2-width/2, h/2-height/2, \
00381 width,height,vec1); \
00382 \
00383 }else if(shape == FLGR_DIAMOND) { \
00384 flgr2d_set_data_vector_##dtype(nhb,h/2,w/2,vec1); \
00385 for(i=0;i<size/2;i++) \
00386 flgr2d_native_dilate_4_connexity_##dtype(nhb); \
00387 \
00388 }else if(shape == FLGR_OCTAGON) { \
00389 flgr2d_set_data_vector_##dtype(nhb,h/2,w/2,vec1); \
00390 for(i=0 ; i<size/2-nbsqr ; i++) \
00391 flgr2d_native_dilate_4_connexity_##dtype(nhb); \
00392 \
00393 for(i=0 ; i<nbsqr ; i++) \
00394 flgr2d_native_dilate_8_connexity_##dtype(nhb); \
00395 \
00396 }else if(shape == FLGR_DISC) { \
00397 flgr2d_draw_disc_##dtype(nhb,w/2,h/2,size/2,vec1); \
00398 \
00399 }else if(shape == FLGR_ELLIPSE) { \
00400 flgr2d_draw_filled_ellipse_##dtype(nhb,w/2,h/2, \
00401 width/2,height/2,vec1); \
00402 \
00403 }else if(shape == FLGR_SLASH) { \
00404 flgr2d_draw_line_##dtype(nhb, w/2-width/2, height-1+h/2-height/2, \
00405 width-1+w/2-width/2, h/2-height/2, vec1); \
00406 \
00407 }else if(shape == FLGR_BSLASH) { \
00408 flgr2d_draw_line_##dtype(nhb,w/2-width/2, h/2-height/2, \
00409 width-1+w/2-width/2, height-1+h/2-height/2,vec1); \
00410 \
00411 }else if(shape == FLGR_CROSS) { \
00412 flgr2d_draw_vertical_line_##dtype(nhb,w/2,h/2-height/2,height,vec1); \
00413 flgr2d_draw_horizontal_line_##dtype(nhb,w/2-width/2,h/2,width,vec1); \
00414 \
00415 }else if(shape == FLGR_CROSSX) { \
00416 flgr2d_draw_line_##dtype(nhb,w/2-width/2, height-1+h/2-height/2, \
00417 width-1+w/2-width/2,h/2-height/2,vec1); \
00418 flgr2d_draw_line_##dtype(nhb, w/2-width/2, h/2-height/2, \
00419 width-1+w/2-width/2,height-1+h/2-height/2,vec1); \
00420 } \
00421 \
00422 flgr_vector_destroy(vec1); \
00423 flgr2d_destroy(tmp); \
00424 \
00425 return
00426
00427 void flgr2d_fill_neighborhood_fgBIT(FLGR_Data2D *nhb, FLGR_Shape shape, int width, int height) {
00428 FLGR_MACRO_FILL_2D_SHP(fgBIT);
00429 }
00430 void flgr2d_fill_neighborhood_fgUINT8(FLGR_Data2D *nhb, FLGR_Shape shape, int width, int height) {
00431 FLGR_MACRO_FILL_2D_SHP(fgUINT8);
00432 }
00433 void flgr2d_fill_neighborhood_fgUINT16(FLGR_Data2D *nhb, FLGR_Shape shape, int width, int height) {
00434 FLGR_MACRO_FILL_2D_SHP(fgUINT16);
00435 }
00436 void flgr2d_fill_neighborhood_fgUINT32(FLGR_Data2D *nhb, FLGR_Shape shape, int width, int height) {
00437 FLGR_MACRO_FILL_2D_SHP(fgUINT32);
00438 }
00439 void flgr2d_fill_neighborhood_fgINT8(FLGR_Data2D *nhb, FLGR_Shape shape, int width, int height) {
00440 FLGR_MACRO_FILL_2D_SHP(fgINT8);
00441 }
00442 void flgr2d_fill_neighborhood_fgINT16(FLGR_Data2D *nhb, FLGR_Shape shape, int width, int height) {
00443 FLGR_MACRO_FILL_2D_SHP(fgINT16);
00444 }
00445 void flgr2d_fill_neighborhood_fgINT32(FLGR_Data2D *nhb, FLGR_Shape shape, int width, int height) {
00446 FLGR_MACRO_FILL_2D_SHP(fgINT32);
00447 }
00448 void flgr2d_fill_neighborhood_fgFLOAT32(FLGR_Data2D *nhb, FLGR_Shape shape, int width, int height) {
00449 FLGR_MACRO_FILL_2D_SHP(fgFLOAT32);
00450 }
00451 void flgr2d_fill_neighborhood_fgFLOAT64(FLGR_Data2D *nhb, FLGR_Shape shape, int width, int height) {
00452 FLGR_MACRO_FILL_2D_SHP(fgFLOAT64);
00453 }
00454
00455
00457
00464
00465 FLGR_Ret flgr2d_fill_neighborhood(FLGR_Data2D *nhb, FLGR_Shape shape, int width, int height) {
00466 if(nhb==NULL) {
00467 POST_ERROR("Null objects!\n");
00468 return FLGR_RET_NULL_OBJECT;
00469 }
00470
00471 if(nhb->shape!=shape) {
00472 POST_WARNING("given shape does not correspond to FLGR_Data2D shape\n");
00473 }
00474
00475 if(width>nhb->size_x) {
00476 POST_WARNING("width too high\n");
00477 width=nhb->size_x;
00478 }
00479
00480 if(width<0) {
00481 POST_WARNING("width < 0\n");
00482 width=0;
00483 }
00484
00485 if(width%2==0) {
00486 width++;
00487 }
00488
00489 if(height>nhb->size_y) {
00490 POST_WARNING("height too high\n");
00491 height=nhb->size_y;
00492 }
00493
00494 if(height<0) {
00495 POST_WARNING("height < 0\n");
00496 height=0;
00497 }
00498
00499 if(height%2==0) {
00500 height++;
00501 }
00502
00503
00504
00505
00506 FLGR_DISPATCH_PROCEDURE(nhb->type,flgr2d_fill_neighborhood,nhb,shape,width,height);
00507
00508 }
00509
00510
00511