-
Notifications
You must be signed in to change notification settings - Fork 0
/
SPConfig.h
263 lines (242 loc) · 8.95 KB
/
SPConfig.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
#ifndef SPCONFIG_H_
#define SPCONFIG_H_
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <ctype.h>
#include "SPKDTree.h"
#include "SPKDTreeSplitMethod.h"
/**
* A data-structure which is used for configuring the system.
*/
typedef enum sp_config_msg_t {
SP_CONFIG_MISSING_DIR,
SP_CONFIG_MISSING_PREFIX,
SP_CONFIG_MISSING_SUFFIX,
SP_CONFIG_MISSING_NUM_IMAGES,
SP_CONFIG_CANNOT_OPEN_FILE,
SP_CONFIG_ALLOC_FAIL,
SP_CONFIG_INVALID_INTEGER,
SP_CONFIG_INVALID_STRING,
SP_CONFIG_INVALID_ARGUMENT,
SP_CONFIG_INDEX_OUT_OF_RANGE,
SP_CONFIG_SUCCESS
} SP_CONFIG_MSG;
typedef struct sp_config_t* SPConfig;
/**
* Creates a new system configuration struct. The configuration struct
* is initialized based on the configuration file given by 'filename'.
*
* @param filename - the name of the configuration file
* @assert msg != NULL
* @param msg - pointer in which the msg returned by the function is stored
* @return NULL in case an error occurs. Otherwise, a pointer to a struct which
* contains all system configuration.
*
* The resulting value stored in msg is as follow:
* - SP_CONFIG_INVALID_ARGUMENT - if filename == NULL
* - SP_CONFIG_CANNOT_OPEN_FILE - if the configuration file given by filename cannot be open
* - SP_CONFIG_ALLOC_FAIL - if an allocation failure occurred
* - SP_CONFIG_INVALID_INTEGER - if a line in the config file contains invalid integer
* - SP_CONFIG_INVALID_STRING - if a line in the config file contains invalid string
* - SP_CONFIG_MISSING_DIR - if spImagesDirectory is missing
* - SP_CONFIG_MISSING_PREFIX - if spImagesPrefix is missing
* - SP_CONFIG_MISSING_SUFFIX - if spImagesSuffix is missing
* - SP_CONFIG_MISSING_NUM_IMAGES - if spNumOfImages is missing
* - SP_CONFIG_SUCCESS - in case of success
*
*
*/
SPConfig spConfigCreate(const char* filename, SP_CONFIG_MSG* msg);
/*
* Returns true if spExtractionMode = true, false otherwise.
*
* @param config - the configuration structure
* @assert msg != NULL
* @param msg - pointer in which the msg returned by the function is stored
* @return true if spExtractionMode = true, false otherwise.
*
* - SP_CONFIG_INVALID_ARGUMENT - if config == NULL
* - SP_CONFIG_SUCCESS - in case of success
*/
bool spConfigIsExtractionMode(const SPConfig config, SP_CONFIG_MSG* msg);
/*
* Returns true if spMinimalGUI = true, false otherwise.
*
* @param config - the configuration structure
* @assert msg != NULL
* @param msg - pointer in which the msg returned by the function is stored
* @return true if spExtractionMode = true, false otherwise.
*
* - SP_CONFIG_INVALID_ARGUMENT - if config == NULL
* - SP_CONFIG_SUCCESS - in case of success
*/
bool spConfigMinimalGui(const SPConfig config, SP_CONFIG_MSG* msg);
/*
* Returns the method set for splitting the kd tree.
* @param config - the configuration structure
* @assert msg != NULL
* @param msg - pointer in which the msg returned by the function is stored
* @return split method on success, default value (MAX_SPREAD) on failure
*
* - SP_CONFIG_INVALID_ARGUMENT - if config == NULL
* - SP_CONFIG_SUCCESS - in case of success
*/
SP_KDTREE_SPLIT_METHOD spConfigGetKDTreeSplitMethod(SPConfig config, SP_CONFIG_MSG* msg);
/*
* Returns the number of images set in the configuration file, i.e the value
* of spNumOfImages.
*
* @param config - the configuration structure
* @assert msg != NULL
* @param msg - pointer in which the msg returned by the function is stored
* @return positive integer in success, negative integer otherwise.
*
* - SP_CONFIG_INVALID_ARGUMENT - if config == NULL
* - SP_CONFIG_SUCCESS - in case of success
*/
int spConfigGetNumOfImages(const SPConfig config, SP_CONFIG_MSG* msg);
/*
* Returns the number of features to be extracted. i.e the value
* of spNumOfFeatures.
*
* @param config - the configuration structure
* @assert msg != NULL
* @param msg - pointer in which the msg returned by the function is stored
* @return positive integer in success, negative integer otherwise.
*
* - SP_CONFIG_INVALID_ARGUMENT - if config == NULL
* - SP_CONFIG_SUCCESS - in case of success
*/
int spConfigGetNumOfFeatures(const SPConfig config, SP_CONFIG_MSG* msg);
/**
* Returns the dimension of the PCA. i.e the value of spPCADimension.
*
* @param config - the configuration structure
* @assert msg != NULL
* @param msg - pointer in which the msg returned by the function is stored
* @return positive integer in success, negative integer otherwise.
*
* - SP_CONFIG_INVALID_ARGUMENT - if config == NULL
* - SP_CONFIG_SUCCESS - in case of success
*/
int spConfigGetPCADim(const SPConfig config, SP_CONFIG_MSG* msg);
/**
* Returns the level of the logger, i.e. the value of spLoggerLevel.
* 1 indicates error level, 2 indicates warning level, 3 indicates info level,
* 4 indicates debug level.
*
* @param config - the configuration structure
* @assert msg != NULL
* @param msg - pointer in which the msg returned by the function is stored
* @return positive integer in success, negative integer otherwise.
*
* - SP_CONFIG_INVALID_ARGUMENT - if config == NULL
* - SP_CONFIG_SUCCESS - in case of success
*/
int spConfigGetLoggerLevel(const SPConfig config, SP_CONFIG_MSG* msg);
/**
* Returns the number of similar images to be displayed.
*
* @param config - the configuration structure
* @assert msg != NULL
* @param msg - pointer in which the msg returned by the function is stored
* @return positive integer in success, negative integer otherwise.
*
* - SP_CONFIG_INVALID_ARGUMENT - if config == NULL
* - SP_CONFIG_SUCCESS - in case of success
*/
int spConfigGetNumOfSimilarImages(const SPConfig config, SP_CONFIG_MSG* msg);
/**
* Returns the valuf of KNN, i.e. the number of similar features to be selected.
*
* @param config - the configuration structure
* @assert msg != NULL
* @param msg - pointer in which the msg returned by the function is stored
* @return positive integer in success, negative integer otherwise.
*
* - SP_CONFIG_INVALID_ARGUMENT - if config == NULL
* - SP_CONFIG_SUCCESS - in case of success
*/
int spConfigGetKNN(const SPConfig config, SP_CONFIG_MSG* msg);
/**
* The function stores in loggerFilename the value of spLoggerFilename.
* Thus the address given by loggerFilename must contain enough space to
* store the resulting string.
*
* @param loggerFilename - an address to store the result in, it must contain enough space
* @param config - the configuration structure
* @return
* - SP_CONFIG_INVALID_ARGUMENT - if loggerFilename == NULL or config == NULL
* - SP_CONFIG_SUCCESS - in case of success
*/
SP_CONFIG_MSG spConfigGetLoggerFilename(char* loggerFilename, const SPConfig config);
/**
* Given an index 'index' the function stores in imagePath the full path of the
* ith image.
*
* For example:
* Given that the value of:
* spImagesDirectory = "./images/"
* spImagesPrefix = "img"
* spImagesSuffix = ".png"
* spNumOfImages = 17
* index = 10
*
* The functions stores "./images/img10.png" to the address given by imagePath.
* Thus the address given by imagePath must contain enough space to
* store the resulting string.
*
* @param imagePath - an address to store the result in, it must contain enough space.
* @param config - the configuration structure
* @param index - the index of the image.
*
* @return
* - SP_CONFIG_INVALID_ARGUMENT - if imagePath == NULL or config == NULL
* - SP_CONFIG_INDEX_OUT_OF_RANGE - if index >= spNumOfImages
* - SP_CONFIG_SUCCESS - in case of success
*/
SP_CONFIG_MSG spConfigGetImagePath(char* imagePath, const SPConfig config,
int index);
/**
* Given an index 'index' the function stores in featsPath the full path of the
* .feats file corresponding to the given image.
* Thus the address given by featsPath must contain enough space to
* store the resulting string.
*
* @param featsPath - an address to store the result in, it must contain enough space.
* @param config - the configuration structure
* @param index - the index of the image.
*
* @return
* - SP_CONFIG_INVALID_ARGUMENT - if featsPath == NULL or config == NULL
* - SP_CONFIG_INDEX_OUT_OF_RANGE - if index >= spNumOfImages
* - SP_CONFIG_SUCCESS - in case of success
*/
SP_CONFIG_MSG spConfigGetFeatsPath(char* featsPath, const SPConfig config,
int index);
/**
* The function stores in pcaPath the full path of the pca file.
* For example given the values of:
* spImagesDirectory = "./images/"
* spPcaFilename = "pca.yml"
*
* The functions stores "./images/pca.yml" to the address given by pcaPath.
* Thus the address given by pcaPath must contain enough space to
* store the resulting string.
*
* @param imagePath - an address to store the result in, it must contain enough space.
* @param config - the configuration structure
* @return
* - SP_CONFIG_INVALID_ARGUMENT - if imagePath == NULL or config == NULL
* - SP_CONFIG_SUCCESS - in case of success
*/
SP_CONFIG_MSG spConfigGetPCAPath(char* pcaPath, const SPConfig config);
/**
* Frees all memory resources associate with config.
* If config == NULL nothig is done.
*/
void spConfigDestroy(SPConfig config);
#endif /* SPCONFIG_H_ */