-
Notifications
You must be signed in to change notification settings - Fork 0
/
macros.h
303 lines (239 loc) · 12 KB
/
macros.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#ifndef MACROS_H_
#define MACROS_H_
/**********************************************************/
/************************ SPConfig ************************/
/**********************************************************/
#define MAX_LENGTH 1026
#define OK 0
#define ERROR -1
#define ERR 1
#define COMMENT_BLANK 2
#define DEFAULT_CANT_OPEN "The default configuration file spcbir.config couldn't be open\n"
#define CANT_OPEN "The configuration file %s couldn't be open\n"
#define MEMORY_FAIL1 "Memory Allocation Failure - createAttributes\n"
#define UNDECLARED "Configuartion file must contain all of the following declerations:\n"\
" - spImagesDirectory\n"\
" - spImagesPrefix\n"\
" - spImagesSuffix\n"\
" - spNumOfImages\n"
#define INVALID_CONFLINE "File: %s\nLine: %d\nMessage: Invalid configuration line\n"
#define CONSTRAINT "File: %s\nLine: %d\nMessage: Invalid value - constraint not met\n"
#define INVALID_COMLINE "Invalid command line : use -c <config_filename>\n"
#define PARAMETER_NOTSET "File: %s\nLine: %d\nMessage: Parameter %s is not set\n"
#define DEFAULT_CONFIG "spcbir.config"
#define PCAYML "pca.yml"
#define STD "stdout"
#define C_ARG "-c"
#define CLS_QRY "<>"
#define STR_LINE "%s\n"
#define IMGDIR "spImagesDirectory"
#define IMGPRE "spImagesPrefix"
#define IMGSUF "spImagesSuffix"
#define IMGNUM "spNumOfImages"
#define IMGCAD "spPCADimension"
#define IMGPCA "spPCAFilename"
#define IMGNOF "spNumOfFeatures"
#define IMGEXM "spExtractionMode"
#define TRUE_STR "true"
#define FALSE_STR "false"
#define IMGNOS "spNumOfSimilarImages"
#define POS_FIRST_VAL 1
#define LOG_MIN 1
#define LOG_MAX 4
#define IMGSPM "spKDTreeSplitMethod"
#define SPLIT_METHODS "RANDOM", "MAX_SPREAD", "INCREMENTAL"
#define IMGKNN "spKNN"
#define IMGMNG "spMinimalGUI"
#define IMGLGL "spLoggerLevel"
#define IMGLGF "spLoggerFilename"
#define POSSIBLE_SUFFIEXS ".jpg", ".png", ".bmp", ".gif"
#define CAD_DEFAULT 20
#define FEATS_DEFAULT 100
#define SIMILAR_DEFAULT 1
#define KNN_DEFAULT 1
#define PCA_SIZE 8
#define LOGFILE_SIZE 7
#define PATH_FRMT_STR "%s%s%d%s"
#define TWO_STR "%s%s"
/**********************************************************/
/************************ Debugging ***********************/
/**********************************************************/
#define ERR_ARGS "%s - at file: %s, line: %d, func: %s"
#define INVALID "Invalid Argument Error"
#define INVALID_WRN "Invalid Argument Warning"
#define MALLOC_ERR "Memory Allocation Failure"
#define CONFIG_ERR "SPConfig Error"
#define LOGGER_ERR "SPLogger Error"
#define SYNTAX "Syntax Error while reading feature file. SKIPPING FILE."
#define CONFIG_MSG_ERR "Got SPConfig Error, MSG no. <%d>"
#define FEATS_FILE "Cannot create feats file"
#define FEATS_PRNT "Print to feats-file error"
#define PCA_ERR "Error in getting PCA Dimensions"
#define KDT_START "Entering Recursive creation of the KD Tree"
#define NO_CNFG "No Configuration File"
#define NO_IMG_NUM "Failed getting NumOfImages from configuration struct"
#define IMG_EXTR "Extracting image number %d"
#define DBG_CREATE "Creating .feats file for image"
#define KNN_FAIL "Failed in finding nearest neighbors for features"
#define KNN_DO "Finding nearest neighbors to each feature"
#define CLOS_IMGS "Calculating the global closest images (most frequent appearances in closest per feature)"
#define errorWithLogger() fprintf(stderr,ERR_ARGS,LOGGER_ERR,__FILE__,__LINE__,__func__)
#define printError(msg) if((*log_msg = spLoggerPrintError(msg,__FILE__,__func__,__LINE__)) \
!= SP_LOGGER_SUCCESS){ \
errorWithLogger();}
#define printWarning(msg) if((*log_msg = spLoggerPrintWarning(msg,__FILE__,__func__,__LINE__)) \
!= SP_LOGGER_SUCCESS){ \
errorWithLogger();}
#define printInfo(msg) if((*log_msg = spLoggerPrintInfo(msg)) \
!= SP_LOGGER_SUCCESS){ \
errorWithLogger();}
#define printDebug(msg) if((*log_msg = spLoggerPrintDebug(msg,__FILE__,__func__,__LINE__)) \
!= SP_LOGGER_SUCCESS){ \
errorWithLogger();}
#define printFinishProgram(rc) sprintf(msg, "Program finished. Status: %s", rc ? "FAIL" : "SUCCESS"); \
printInfo(msg)
#define InvalidError() printError(INVALID)
#define MallocError() printError(MALLOC_ERR)
#define infoWithArgs(MSG,...) char err[MAX_LENGTH] = {'\0'}; \
sprintf(err,MSG,__VA_ARGS__); \
printInfo(err)
#define warningWithArgs(MSG,...) char err[MAX_LENGTH] = {'\0'}; \
sprintf(err,MSG,__VA_ARGS__); \
printWarning(err)
#define loggerWithArgs(MSG,...) char err[MAX_LENGTH] = {'\0'}; \
sprintf(err,MSG,__VA_ARGS__); \
printError(err)
#define returnIfConfigMsg(ret) if (*conf_msg != SP_CONFIG_SUCCESS) { \
loggerWithArgs(CONFIG_MSG_ERR,*conf_msg) \
return ret; \
}
#define declareLogMsg() SP_LOGGER_MSG _log_msg = SP_LOGGER_SUCCESS, *log_msg = &_log_msg
#define declareConfMsg() SP_CONFIG_MSG _conf_msg = SP_CONFIG_SUCCESS, *conf_msg = &_conf_msg
/**************************************************************/
/************************ SPConfig ***********************/
/**************************************************************/
#define ignoreSpaces(x) while(isspace(*x)){x++;}
#define errorInvalidLine() printf(INVALID_CONFLINE, filename, lineNum)
#define assignString(configAttribute,xVal) configAttribute = (char*) malloc(strlen(xVal)+1); \
if(!configAttribute){ \
return SP_CONFIG_ALLOC_FAIL; \
} \
strcpy(configAttribute,xVal)
#define checkAndAssign(property,x) if(!attr->property) \
attr->property = x;
#define getter(property) assert(msg); \
*msg = config ? SP_CONFIG_SUCCESS : SP_CONFIG_INVALID_ARGUMENT; \
return config ? config->property : -1 //maybe error
#define getterBoolean(property) assert(msg); \
*msg = config ? SP_CONFIG_SUCCESS : SP_CONFIG_INVALID_ARGUMENT; \
return config ? config->property : 0 //maybe error
/********************************************************/
/************************ KDArray ***********************/
/********************************************************/
#define EPS 0.000001
#define arrayMallocFail(array,j) if(!array[j]){ \
for(j--;j>=0;j--){ \
free(array[j]); \
}\
free(array); \
return NULL; \
}
#define frees() free(map1); free(map2); free(X);
/************************************************************/
/************************ SPExtractor ***********************/
/************************************************************/
#define MAX_FEATS_LINE 50000
#define READ_ERR "Error while reading the feats file. SKIPPING FILE"
#define CHAR_ERR "Invalid characters found on file. SKIPPING FILE"
#define SPACE_ERR "Empty lines are not permitted in the .feats file. SKIPPING FILE"
#define INDX_ERR "Image index and/or number of features written in the .feats file cannot be negative. SKIPPING FILE"
#define FEAT_ERR "%s\n feature = %d, line = %d, char = %c <%d>\nline is:\n%s"
#define FEAT_ERR2 "Invalid characters found on file. SKIPPING FILE\n\tfeature = %d, line = %d, char = %c <%d>\n\tline is:\n%s"
#define FEAT_SIZE_ERR "Current feature size != spCADimension (%d) on line %d. SKIPPING FILE no. %d"
#define FEAT_SMALL "Feature size is smaller than spCADimension. SKIPPING FILE"
#define errorReturn() spPointArrayDestroy(pntsArray, countOfFeatures); \
*numOfFeatures = 0; \
fclose(feats); \
return NULL;
#define FEATS_EXT ".feats"
#define FILE_ERR "File \"%s\" cannot be opened. SKIPPING FILE"
#define INDEX_ERR "Image index inside file (%d) doesn't match filename index - \"%s\". SKIPPING FILE"
#define FEATS_QNTTY_LESS "Features file has %d features, less than %d, the quantity defined at the 2nd line. SKIPPING FILE"
#define FEATS_QNTTY_MORE "Features file has more than %d features, the quantity defined at the 2nd line. SKIPPING FILE"
#define FEATS_SUFFIX "Error with the configuration:\nPath of .feats file cannot be retrieved"
#define NO_FEATS_IMPRT "No image features were imported"
#define SOME_FEATS "Some of the images features were not imported"
#define INTS_FEATS_FILE "%d\n%d\n"
#define FLOAT "%f"
#define FLOAT_CHAR "%f%c"
#define MAIN1 "Start Building a KD Tree"
#define MAIN2 "Importing Image features from files"
#define MAINFAIL1 "Failed Extracting Features from image files"
#define MAIN3 "Constructing KD Array out of the features"
#define MAINFAIL2 "Failed Constructing KD Array"
#define MAIN4 "Constructing KD Tree using the KD Array"
#define MAIN5 "Destroying Configuration parameters struct"
#define MAIN6 "Destroying KD-Tree"
#define MAIN7 "Destroying Logger"
#define MAIN8 "Cleaning query-oriented resources"
#define LOG_OPEN "Logger opened successfully in file: %s"
/*****************************************************/
/************************ Main ***********************/
/*****************************************************/
#define clearAll() cleanGlobalResources(config, kdtree);
#define LOGGERnMSG "SPLogger Error. Message Type: %d"
#define FINISH_PRG "Program Finished Successfully"
#define NO_FILE "Image file \"%s\" doesn't exist"
#define PLS_ENTER "Please enter an image path:\n"
#define INV_PATH "Invalid path to image. Please try again;\n"
#define BST_CND "Best candidates for - %s - are:\n"
#define EXIT "Exiting...\n"
#define WRITE_MODE "w"
#define READ_MODE "r"
#define EXTRCT_MODE "Starting Extraction Mode"
#define EXTRCT_IMG_NUM "Extracting image in index %d"
#define EXTRCT_FROM_IMG "Extracting features from image"
#define EXPORT_TO_FILE "Exporting image features into a file"
#define EXTRCT_SKIP "Skipping Extraction Mode"
#define GLOBAL_RES "Creating Global Resources"
#define USR_QRY "Start getting queries from user"
#define EXIT_SNGL "Got Exiting String: \"<>\""
#define QRY_PATH_GOT "Got query image path: %s"
#define QRY_GET "Getting features for query image"
#define QRY_FEAT_ERR "Failed in getting features for query image"
#define IMG_EXTRCT "Extracted %d features from image %s"
#define CLS_SRCH "Searching for the closest images in database for the query image"
#define SRCH_FAIL "Failed in searching for closest images"
#define RSLTS "Now showing results"
#define checkifImgExists() if(access(path, F_OK) == -1){ \
char err[MAX_LENGTH] = {'\0'}; \
sprintf(err,NO_FILE,path); \
if((*log_msg = spLoggerPrintError(err,__FILE__,__func__,__LINE__)) \
!= SP_LOGGER_SUCCESS){ \
errorWithLogger(); \
} \
clearAll() \
return ERROR; \
}
/*********************************************************/
/************************ SPLogger ***********************/
/*********************************************************/
#define SP_LOGGER_OPEN_MODE "w"
#define OC logger->outputChannel
#define OUTPUT() fprintf(OC,"- file: %s\n- function: %s\n- line: %d\n- message: %s\n",file,function,line,msg)
#define CheckWF(cond) if(cond<0){ return SP_LOGGER_WRITE_FAIL; }
#define NULLChecks() if (logger == NULL) { \
return SP_LOGGER_UNDIFINED; \
} \
if (msg == NULL) { \
return SP_LOGGER_INVAlID_ARGUMENT; }
#define DST_FAIL "Failed destroying logger. No active logger found"
#define DST_LOGGER "Destroying logger"
#define LOG_TITLE "---%s---\n"
#define ERROR_LOGGER "ERROR"
#define WARNING "WARNING"
#define INFO "INFO"
#define LOGR_MSG "- message: %s\n"
#define DEBUG "DEBUG"
#define STR "%s"
#endif /* MACROS_H_ */