00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifdef HAVE_CONFIG_H
00021 # include <config.h>
00022 #endif
00023
00024
00025
00026
00027
00028 #include <irplib_utils.h>
00029 #include <string.h>
00030 #include <float.h>
00031
00032
00033 #include <time.h>
00034
00035
00036
00037
00038
00039 static IRPLIB_UTIL_SET_ROW(my_table_set_row);
00040 static IRPLIB_UTIL_CHECK(my_table_check);
00041
00042 static void test_irplib_image_split(void);
00043 static void test_irplib_dfs_table_convert(void);
00044 static void test_irplib_isnaninf(void);
00045 static void bench_irplib_image_split(int, int);
00046
00047
00048
00052
00053
00054
00055
00059
00060
00061 int main(void)
00062 {
00063
00064 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
00065
00066 test_irplib_isnaninf();
00067
00068 test_irplib_dfs_table_convert();
00069
00070 test_irplib_image_split();
00071
00072 if (cpl_msg_get_level() <= CPL_MSG_INFO) {
00073 bench_irplib_image_split(1024, 100);
00074 } else {
00075 bench_irplib_image_split(64, 1);
00076 }
00077
00078 return cpl_test_end(0);
00079 }
00080
00081
00082
00086
00087 static void test_irplib_isnaninf(void)
00088 {
00089 double infinity = DBL_MAX * DBL_MAX;
00090 double number[] = {17, 0};
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 cpl_test_zero(irplib_isnan(infinity) );
00104
00105 cpl_test_zero(irplib_isnan(number[0]) );
00106 cpl_test_zero(irplib_isnan(number[1]) );
00107
00108 cpl_test( irplib_isinf(infinity) );
00109
00110 cpl_test_zero(irplib_isinf(number[0]) );
00111 cpl_test_zero(irplib_isinf(number[1]) );
00112
00113 return;
00114 }
00115
00116
00117 static cpl_boolean my_table_set_row(cpl_table * self,
00118 const char * line,
00119 int irow,
00120 const cpl_frame * rawframe,
00121 const cpl_parameterlist * parlist)
00122 {
00123
00124 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
00125 cpl_ensure_code(line != NULL, CPL_ERROR_NULL_INPUT);
00126 cpl_ensure_code(irow >= 0, CPL_ERROR_ILLEGAL_INPUT);
00127 cpl_ensure_code(rawframe != NULL, CPL_ERROR_NULL_INPUT);
00128 cpl_ensure_code(parlist != NULL, CPL_ERROR_NULL_INPUT);
00129
00130 return CPL_ERROR_NONE;
00131
00132 }
00133
00134 static cpl_error_code my_table_check(cpl_table * self,
00135 const cpl_frameset * useframes,
00136 const cpl_parameterlist * parlist)
00137 {
00138
00139 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
00140 cpl_ensure_code(useframes != NULL, CPL_ERROR_NULL_INPUT);
00141 cpl_ensure_code(parlist != NULL, CPL_ERROR_NULL_INPUT);
00142
00143 return CPL_ERROR_NONE;
00144
00145 }
00146
00147
00148
00153
00154 static void test_irplib_dfs_table_convert(void)
00155 {
00156
00157
00158 cpl_error_code error
00159 = irplib_dfs_table_convert(NULL, NULL, NULL, 1024, '#',
00160 NULL, NULL, NULL, NULL, NULL, NULL,
00161 NULL, NULL, NULL, my_table_set_row,
00162 my_table_check);
00163
00164 cpl_test_error(CPL_ERROR_NULL_INPUT);
00165 cpl_test_eq(error, CPL_ERROR_NULL_INPUT);
00166
00167 error =
00168 irplib_table_read_from_frameset(NULL, NULL, 1024, '#', NULL,
00169 my_table_set_row);
00170
00171 cpl_test_error(CPL_ERROR_NULL_INPUT);
00172 cpl_test_eq(error, CPL_ERROR_NULL_INPUT);
00173 }
00174
00175
00176
00181
00182 static void bench_irplib_image_split(int nxy, int nsplit) {
00183
00184 const double th_low = 0.0;
00185 const double th_high = 50.0;
00186 const double alt_low = th_low - 1.0;
00187 const double alt_high = th_high + 1.0;
00188 cpl_image * test = cpl_image_new(nxy, nxy, CPL_TYPE_FLOAT);
00189 clock_t tsum = 0;
00190 int i;
00191
00192 for (i = 0; i < nsplit; i++) {
00193 const clock_t t = clock();
00194 #if 1
00195 (void)irplib_image_split(test, NULL, test, NULL,
00196 th_low, CPL_TRUE, th_high, CPL_TRUE,
00197 alt_low, alt_high,
00198 CPL_TRUE, CPL_FALSE, CPL_TRUE);
00199 #else
00200 (void)cpl_image_threshold(test, th_low, th_high, alt_low, alt_high);
00201 #endif
00202 tsum += clock() - t;
00203 }
00204
00205 cpl_msg_info(cpl_func,"Time to split with image size %d [ms]: %g", nxy,
00206 1e3*((double)tsum/CLOCKS_PER_SEC)/nsplit);
00207
00208 cpl_test_error(CPL_ERROR_NONE);
00209
00210 cpl_image_delete(test);
00211
00212 }
00213
00214
00215
00220
00221 static void test_irplib_image_split(void) {
00222
00223 const double th_low = 0.0;
00224 const double th_high = 50.0;
00225 const double alt_low = th_low - 1.0;
00226 const double alt_high = th_high + 1.0;
00227
00228 cpl_image * test = cpl_image_new(100, 100, CPL_TYPE_DOUBLE);
00229 cpl_image * result = cpl_image_new(100, 100, CPL_TYPE_DOUBLE);
00230
00231
00232 cpl_error_code error
00233 = irplib_image_split(NULL, test, result, test,
00234 0.0, CPL_FALSE, 0.0, CPL_FALSE,
00235 0.0, 0.0,
00236 CPL_FALSE, CPL_FALSE, CPL_FALSE);
00237 cpl_test_error(CPL_ERROR_NULL_INPUT);
00238 cpl_test_eq(error, CPL_ERROR_NULL_INPUT);
00239
00240
00241 error = irplib_image_split(test, NULL, NULL, NULL,
00242 th_low, CPL_TRUE, th_high, CPL_TRUE,
00243 alt_low, alt_high,
00244 CPL_TRUE, CPL_FALSE, CPL_TRUE);
00245 cpl_test_error(CPL_ERROR_NULL_INPUT);
00246 cpl_test_eq(error, CPL_ERROR_NULL_INPUT);
00247
00248 error = irplib_image_split(test, NULL, result, NULL,
00249 th_low, CPL_TRUE, alt_low, CPL_TRUE,
00250 alt_low, alt_high,
00251 CPL_TRUE, CPL_FALSE, CPL_TRUE);
00252
00253 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
00254 cpl_test_eq(error, CPL_ERROR_ILLEGAL_INPUT);
00255
00256
00257
00258 error = cpl_image_fill_noise_uniform(test, -100.0, 100.0);
00259 cpl_test_error(CPL_ERROR_NONE);
00260 cpl_test_eq(error, CPL_ERROR_NONE);
00261
00262 error = irplib_image_split(test, NULL, result, NULL,
00263 th_low, CPL_TRUE, th_high, CPL_TRUE,
00264 alt_low, alt_high,
00265 CPL_TRUE, CPL_FALSE, CPL_TRUE);
00266 cpl_test_error(CPL_ERROR_NONE);
00267 cpl_test_eq(error, CPL_ERROR_NONE);
00268
00269 error = cpl_image_threshold(test, th_low, th_high, alt_low, alt_high);
00270 cpl_test_error(CPL_ERROR_NONE);
00271 cpl_test_eq(error, CPL_ERROR_NONE);
00272
00273
00274 error = cpl_image_subtract(result, test);
00275 cpl_test_error(CPL_ERROR_NONE);
00276 cpl_test_eq(error, CPL_ERROR_NONE);
00277
00278 cpl_test_leq(cpl_image_get_absflux(result), DBL_EPSILON);
00279
00280 cpl_image_delete(test);
00281 cpl_image_delete(result);
00282
00283 }