00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <stdio.h>
00023 #include <stdlib.h>
00024 #include <string.h>
00025 #include <flgrCoreIO.h>
00026 #include <flgrCoreData.h>
00027 #include <flgrCoreVector.h>
00028 #include <flgrCoreSlideWindow.h>
00029 #include <flgrCoreNhbManage.h>
00030 #include <flgrCoreCopy.h>
00031 #include <flgrCoreDispatch.h>
00032 #include <flgrCoreDataIO.h>
00033 #include <flgrArith.h>
00034 #include "flgrMorphoBase.h"
00035 #include "flgrMorphoDistance.h"
00036 #include "flgrMorphoDistanceFast.h"
00037
00046
00047
00049 #define flgr_get_dist(dtype) \
00050 int i,k; \
00051 int spp = extr->spp; \
00052 dtype *presult = (dtype *) result->array; \
00053 dtype *center = (dtype*) extr->center_data_val->array; \
00054 dtype *list_data_val; \
00055 int *size = extr->size; \
00056 dtype mini; \
00057 dtype val; \
00058 \
00059 for(k=0 ; k<spp ; k++) { \
00060 list_data_val = (dtype *) extr->list_data_val[k]; \
00061 \
00062 mini = flgr_get_array_##dtype(center,k); \
00063 flgr_set_array_##dtype(presult,k,mini); \
00064 if(mini==0) continue; \
00065 \
00066 for(i=0 ; i<size[k] ; i++) { \
00067 val = list_data_val[i]; \
00068 mini = (mini>val) ? val+1: mini; \
00069 } \
00070 \
00071 flgr_set_array_##dtype(presult,k,mini); \
00072 } \
00073 \
00074 return
00075
00076
00077
00078 void flgr_get_distance_fgUINT8(FLGR_Vector *result, FLGR_NhbBox2D *extr) {
00079 flgr_get_dist(fgUINT8);
00080 }
00081 void flgr_get_distance_fgUINT16(FLGR_Vector *result, FLGR_NhbBox2D *extr) {
00082 flgr_get_dist(fgUINT16);
00083 }
00084 void flgr_get_distance_fgUINT32(FLGR_Vector *result, FLGR_NhbBox2D *extr) {
00085 flgr_get_dist(fgUINT32);
00086 }
00087 void flgr_get_distance_fgINT8(FLGR_Vector *result, FLGR_NhbBox2D *extr) {
00088 flgr_get_dist(fgINT8);
00089 }
00090 void flgr_get_distance_fgINT16(FLGR_Vector *result, FLGR_NhbBox2D *extr) {
00091 flgr_get_dist(fgINT16);
00092 }
00093 void flgr_get_distance_fgINT32(FLGR_Vector *result, FLGR_NhbBox2D *extr) {
00094 flgr_get_dist(fgINT32);
00095 }
00096 void flgr_get_distance_fgFLOAT32(FLGR_Vector *result, FLGR_NhbBox2D *extr) {
00097 flgr_get_dist(fgFLOAT32);
00098 }
00099 void flgr_get_distance_fgFLOAT64(FLGR_Vector *result, FLGR_NhbBox2D *extr) {
00100 flgr_get_dist(fgFLOAT64);
00101 }
00102
00103
00105
00107 #define flgr_dist(dtype,dtypename) \
00108 FLGR_Data2D *nhb; \
00109 FLGR_Type type = imgsrc->type; \
00110 FLGR_Type spp = imgsrc->spp; \
00111 \
00112 \
00113 \
00114 nhb = flgr2d_create_neighborhood_from_connexity(spp,type, connexity); \
00115 \
00116 flgr2d_copy(imgdest,imgsrc); \
00117 \
00118 switch(connexity) { \
00119 case FLGR_4_CONNEX: \
00120 flgr2d_distance_raster_4_connexity_##dtype(imgdest); \
00121 break; \
00122 case FLGR_6_CONNEX: \
00123 flgr2d_distance_raster_6_connexity_##dtype(imgdest); \
00124 break; \
00125 case FLGR_8_CONNEX: \
00126 flgr2d_distance_raster_8_connexity_##dtype(imgdest); \
00127 break; \
00128 default: \
00129 flgr2d_raster_slide_window_##dtype(imgdest,imgdest,nhb, \
00130 FLGR_NHB_NO_SYM, \
00131 flgr_get_distance_##dtype); \
00132 } \
00133 \
00134 switch(connexity) { \
00135 case FLGR_4_CONNEX: \
00136 flgr2d_distance_antiraster_4_connexity_##dtype(imgdest); \
00137 break; \
00138 case FLGR_6_CONNEX: \
00139 flgr2d_distance_antiraster_6_connexity_##dtype(imgdest); \
00140 break; \
00141 case FLGR_8_CONNEX: \
00142 flgr2d_distance_antiraster_8_connexity_##dtype(imgdest); \
00143 break; \
00144 default: \
00145 flgr2d_anti_raster_slide_window_##dtype(imgdest,imgdest,nhb, \
00146 FLGR_NHB_NO_SYM, \
00147 flgr_get_distance_##dtype); \
00148 } \
00149 \
00150 flgr2d_destroy(nhb); \
00151 \
00152 return FLGR_RET_OK
00153
00154 FLGR_Ret flgr2d_distance_fgBIT(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Connexity connexity) {
00155 flgr_no_define_type_function(FLGR_BIT);
00156 return FLGR_RET_NOT_IMPLEMENTED;
00157 }
00158 FLGR_Ret flgr2d_distance_fgUINT8(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Connexity connexity) {
00159 flgr_dist(fgUINT8,FLGR_UINT8);
00160 }
00161 FLGR_Ret flgr2d_distance_fgUINT16(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Connexity connexity) {
00162 flgr_dist(fgUINT16,FLGR_UINT16);
00163 }
00164 FLGR_Ret flgr2d_distance_fgUINT32(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Connexity connexity) {
00165 flgr_dist(fgUINT32,FLGR_UINT32);
00166 }
00167 FLGR_Ret flgr2d_distance_fgINT8(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Connexity connexity) {
00168 flgr_no_define_type_function(FLGR_INT8);
00169 return FLGR_RET_NOT_IMPLEMENTED;
00170 }
00171 FLGR_Ret flgr2d_distance_fgINT16(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Connexity connexity) {
00172 flgr_dist(fgINT16,FLGR_INT16);
00173 }
00174 FLGR_Ret flgr2d_distance_fgINT32(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Connexity connexity) {
00175 flgr_dist(fgINT32,FLGR_INT32);
00176 }
00177 FLGR_Ret flgr2d_distance_fgFLOAT32(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Connexity connexity) {
00178 flgr_dist(fgFLOAT32,FLGR_FLOAT32);
00179 }
00180 FLGR_Ret flgr2d_distance_fgFLOAT64(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Connexity connexity) {
00181 flgr_dist(fgFLOAT64,FLGR_FLOAT64);
00182 }
00183
00184
00186
00192
00193 FLGR_Ret flgr2d_distance(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Connexity connexity) {
00194 FLGR_Ret ret;
00195
00196
00197
00198 if((imgdest==NULL) || (imgsrc==NULL)){
00199 POST_ERROR("Null objects!\n");
00200 return FLGR_RET_NULL_OBJECT;
00201 }
00202
00203 if((connexity != FLGR_4_CONNEX) && (connexity != FLGR_6_CONNEX) && (connexity != FLGR_8_CONNEX)) {
00204 POST_ERROR("unknown connexity\n");
00205 return FLGR_RET_CONNEXITY_UNKNOWN;
00206 }
00207
00208 if((ret=flgr2d_is_data_same_attributes(imgdest,imgsrc,__FUNCTION__))!=FLGR_RET_OK) return ret;
00209
00210 FLGR_DISPATCH_FUNCTION(FLGR_RET_TYPE_UNKNOWN,imgdest->type,flgr2d_distance,imgdest,imgsrc,connexity);
00211
00212 }
00213
00214