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 <visir_inputs.h>
00029
00030
00034
00035
00036
00037
00041
00042
00043 static void visir_img_check_box_test(void);
00044 static void visir_img_check_align_test(void);
00045
00046 #ifndef BOX_SIZE
00047 #define BOX_SIZE 11
00048 #endif
00049
00050 #ifndef LINE_SIZE
00051 #define LINE_SIZE BOX_SIZE
00052 #endif
00053
00054 int main(void)
00055 {
00056
00057 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
00058
00059 visir_img_check_align_test();
00060 visir_img_check_box_test();
00061
00062 return cpl_test_end(0);
00063
00064 }
00065
00066 static void visir_img_check_box_test(void)
00067 {
00068
00069 cpl_image * image;
00070 const double sigma = 1.0;
00071 cpl_apertures * appos;
00072 cpl_apertures * apneg;
00073 double ecc;
00074 cpl_boolean swapp, swapn;
00075 FILE * stream;
00076 cpl_error_code error = CPL_ERROR_NONE;
00077 int i, j;
00078
00079 stream = cpl_msg_get_level() > CPL_MSG_INFO
00080 ? fopen("/dev/null", "a") : stdout;
00081
00082 cpl_test_nonnull( stream );
00083
00084 image = cpl_image_new(3 * BOX_SIZE, 3 * BOX_SIZE, CPL_TYPE_INT);
00085
00086
00087 for (j = -1; j <= 1; j++) {
00088 for (i = -1; i <= 1; i++) {
00089 error |= cpl_image_set(image, BOX_SIZE + i, BOX_SIZE + j, -1.0);
00090 error |= cpl_image_set(image, 2*BOX_SIZE + i, 2*BOX_SIZE + j, -1.0);
00091 error |= cpl_image_set(image, BOX_SIZE + i, 2*BOX_SIZE + j, 1.0);
00092 error |= cpl_image_set(image, 2*BOX_SIZE + i, BOX_SIZE + j, 1.0);
00093 cpl_test_eq_error(error, CPL_ERROR_NONE);
00094 }
00095 }
00096
00097 appos = cpl_apertures_extract_sigma(image, sigma);
00098 cpl_test_error(CPL_ERROR_NONE);
00099 cpl_test_nonnull(appos);
00100 cpl_test_eq(cpl_apertures_get_size(appos), 2);
00101
00102 cpl_apertures_dump(appos, stream);
00103
00104 error = cpl_image_multiply_scalar(image, -1.0);
00105 cpl_test_eq_error(error, CPL_ERROR_NONE);
00106
00107 apneg = cpl_apertures_extract_sigma(image, sigma);
00108 cpl_test_error(CPL_ERROR_NONE);
00109 cpl_test_nonnull(apneg);
00110 cpl_test_eq(cpl_apertures_get_size(apneg), 2);
00111
00112 cpl_apertures_dump(apneg, stream);
00113
00114
00115 ecc = visir_img_check_box(NULL, 1, 2, apneg, 1, 2, BOX_SIZE,
00116 &swapp, &swapn);
00117 cpl_test_error(CPL_ERROR_NULL_INPUT);
00118
00119 ecc = visir_img_check_box(appos, 1, 2, NULL, 1, 2, BOX_SIZE,
00120 &swapp, &swapn);
00121 cpl_test_error(CPL_ERROR_NULL_INPUT);
00122
00123 ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 2, BOX_SIZE,
00124 &swapp, NULL);
00125 cpl_test_error(CPL_ERROR_UNSPECIFIED);
00126
00127 ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 2, BOX_SIZE,
00128 NULL, &swapn);
00129 cpl_test_error(CPL_ERROR_UNSPECIFIED);
00130
00131 ecc = visir_img_check_box(appos, 1, 2, appos, 1, 2, BOX_SIZE,
00132 &swapp, &swapn);
00133 cpl_test_error(CPL_ERROR_UNSPECIFIED);
00134
00135 ecc = visir_img_check_box(appos, 0, 2, apneg, 1, 2, BOX_SIZE,
00136 &swapp, &swapn);
00137 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
00138
00139 ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 0, BOX_SIZE,
00140 &swapp, &swapn);
00141 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
00142
00143 ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 3, BOX_SIZE,
00144 &swapp, &swapn);
00145 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
00146
00147 ecc = visir_img_check_box(appos, 3, 2, apneg, 1, 2, BOX_SIZE,
00148 &swapp, &swapn);
00149 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
00150
00151 ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 2, 0.0, &swapp, &swapn);
00152 cpl_test_error(CPL_ERROR_UNSPECIFIED);
00153
00154
00155 ecc = visir_img_check_box(appos, 1, 2, apneg, 1, 2, BOX_SIZE,
00156 &swapp, &swapn);
00157 cpl_test_error(CPL_ERROR_NONE);
00158
00159 cpl_test_abs(ecc, 0.0, FLT_EPSILON);
00160 cpl_test(swapp);
00161 cpl_test_zero(swapn);
00162
00163
00164 ecc = visir_img_check_box(appos, 2, 1, apneg, 2, 1, BOX_SIZE,
00165 &swapp, &swapn);
00166 cpl_test_error(CPL_ERROR_NONE);
00167
00168 cpl_test_abs(ecc, 0.0, FLT_EPSILON);
00169 cpl_test_zero(swapp);
00170 cpl_test(swapn);
00171
00172
00173 ecc = visir_img_check_box(apneg, 1, 2, appos, 1, 2, BOX_SIZE,
00174 &swapp, &swapn);
00175 cpl_test_error(CPL_ERROR_NONE);
00176
00177 cpl_test_abs(ecc, 2.0 * CPL_MATH_SQRT2, FLT_EPSILON);
00178 cpl_test_zero(swapp);
00179 cpl_test(swapn);
00180
00181
00182 ecc = visir_img_check_box(apneg, 2, 1, appos, 2, 1, BOX_SIZE,
00183 &swapp, &swapn);
00184 cpl_test_error(CPL_ERROR_NONE);
00185
00186 cpl_test_abs(ecc, 2.0 * CPL_MATH_SQRT2, FLT_EPSILON);
00187 cpl_test(swapp);
00188 cpl_test_zero(swapn);
00189
00190 cpl_image_delete(image);
00191 cpl_apertures_delete(appos);
00192 cpl_apertures_delete(apneg);
00193
00194 if (stream != stdout) cpl_test_zero( fclose(stream) );
00195
00196 }
00197
00198 static void visir_img_check_align_test(void)
00199 {
00200
00201 FILE * stream;
00202 cpl_error_code error = CPL_ERROR_NONE;
00203 int idir;
00204 cpl_boolean is_hor = CPL_FALSE;
00205
00206 stream = cpl_msg_get_level() > CPL_MSG_INFO
00207 ? fopen("/dev/null", "a") : stdout;
00208
00209 cpl_test_nonnull( stream );
00210
00211 for (idir = 0; idir < 2; idir++, is_hor = CPL_TRUE) {
00212 cpl_image * image = cpl_image_new(4 * LINE_SIZE, 4 * LINE_SIZE,
00213 CPL_TYPE_INT);
00214 const double sigma = 1.0;
00215 cpl_apertures * appos;
00216 cpl_apertures * apneg;
00217 double ecc;
00218 cpl_boolean swapn, swapn2;
00219 int i, j;
00220
00221
00222
00223 for (j = -1; j <= 1; j++) {
00224 for (i = -1; i <= 1; i++) {
00225 error |= cpl_image_set(image, 2*LINE_SIZE + i,
00226 2*LINE_SIZE + j, 1.0);
00227
00228 if (is_hor) {
00229 error |= cpl_image_set(image, LINE_SIZE + i,
00230 2*LINE_SIZE + j, -1.0);
00231 error |= cpl_image_set(image, 3*LINE_SIZE + i,
00232 2*LINE_SIZE + j, -1.0);
00233 } else {
00234 error |= cpl_image_set(image, 2*LINE_SIZE + i,
00235 LINE_SIZE + j, -1.0);
00236 error |= cpl_image_set(image, 2*LINE_SIZE + i,
00237 3*LINE_SIZE + j, -1.0);
00238 }
00239 cpl_test_eq_error(error, CPL_ERROR_NONE);
00240 }
00241 }
00242
00243 appos = cpl_apertures_extract_sigma(image, sigma);
00244 cpl_test_error(CPL_ERROR_NONE);
00245 cpl_test_nonnull(appos);
00246 cpl_test_eq(cpl_apertures_get_size(appos), 1);
00247
00248 cpl_apertures_dump(appos, stream);
00249
00250 error = cpl_image_multiply_scalar(image, -1.0);
00251 cpl_test_eq_error(error, CPL_ERROR_NONE);
00252
00253 apneg = cpl_apertures_extract_sigma(image, sigma);
00254 cpl_test_error(CPL_ERROR_NONE);
00255 cpl_test_nonnull(apneg);
00256 cpl_test_eq(cpl_apertures_get_size(apneg), 2);
00257
00258 cpl_apertures_dump(apneg, stream);
00259
00260
00261 ecc = visir_img_check_align(NULL, 1, apneg, 1, 2, LINE_SIZE, is_hor,
00262 &swapn);
00263 cpl_test_error(CPL_ERROR_NULL_INPUT);
00264
00265 ecc = visir_img_check_align(appos, 1, NULL, 1, 2, LINE_SIZE, is_hor,
00266 &swapn);
00267 cpl_test_error(CPL_ERROR_NULL_INPUT);
00268
00269 ecc = visir_img_check_align(appos, 1, apneg, 1, 2, LINE_SIZE, is_hor,
00270 NULL);
00271 cpl_test_error(CPL_ERROR_UNSPECIFIED);
00272
00273 ecc = visir_img_check_align(appos, 0, apneg, 1, 2, LINE_SIZE, is_hor,
00274 &swapn);
00275 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
00276
00277 ecc = visir_img_check_align(appos, 1, apneg, 1, 0, LINE_SIZE, is_hor,
00278 &swapn);
00279 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
00280
00281 ecc = visir_img_check_align(appos, 1, apneg, 0, 1, LINE_SIZE, is_hor,
00282 &swapn);
00283 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
00284
00285 ecc = visir_img_check_align(appos, 1, apneg, 1, 3, LINE_SIZE, is_hor,
00286 &swapn);
00287 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
00288
00289 ecc = visir_img_check_align(appos, 3, apneg, 1, 2, LINE_SIZE, is_hor,
00290 &swapn);
00291 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
00292
00293 ecc = visir_img_check_align(appos, 1, apneg, 1, 2, 0.0, is_hor, &swapn);
00294 cpl_test_error(CPL_ERROR_UNSPECIFIED);
00295
00296
00297 ecc = visir_img_check_align(appos, 1, apneg, 1, 2, LINE_SIZE, is_hor,
00298 &swapn);
00299 cpl_test_error(CPL_ERROR_NONE);
00300
00301 cpl_test_abs(ecc, 0.0, FLT_EPSILON);
00302 cpl_test_zero(swapn);
00303
00304
00305 ecc = visir_img_check_align(appos, 1, apneg, 2, 1, LINE_SIZE, is_hor,
00306 &swapn);
00307 cpl_test_error(CPL_ERROR_NONE);
00308
00309 cpl_test_abs(ecc, 0.0, FLT_EPSILON);
00310 cpl_test(swapn);
00311
00312
00313 ecc = visir_img_check_align(appos, 1, apneg, 1, 2, LINE_SIZE, !is_hor,
00314 &swapn);
00315 cpl_test_error(CPL_ERROR_NONE);
00316
00317 cpl_test_abs(ecc, 2.0, FLT_EPSILON);
00318
00319
00320 ecc = visir_img_check_align(appos, 1, apneg, 2, 1, LINE_SIZE, !is_hor,
00321 &swapn2);
00322 cpl_test_error(CPL_ERROR_NONE);
00323
00324 cpl_test_abs(ecc, 2.0, FLT_EPSILON);
00325
00326
00327
00328 cpl_image_delete(image);
00329 cpl_apertures_delete(appos);
00330 cpl_apertures_delete(apneg);
00331 }
00332
00333 if (stream != stdout) cpl_test_zero( fclose(stream) );
00334
00335 }