visir_inputs-test.c

00001 /*                                                                              *
00002  *   This file is part of the ESO VISIR package                                 *
00003  *   Copyright (C) 2004,2005 European Southern Observatory                      *
00004  *                                                                              *
00005  *   This library is free software; you can redistribute it and/or modify       *
00006  *   it under the terms of the GNU General Public License as published by       *
00007  *   the Free Software Foundation; either version 2 of the License, or          *
00008  *   (at your option) any later version.                                        *
00009  *                                                                              *
00010  *   This program is distributed in the hope that it will be useful,            *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of             *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
00013  *   GNU General Public License for more details.                               *
00014  *                                                                              *
00015  *   You should have received a copy of the GNU General Public License          *
00016  *   along with this program; if not, write to the Free Software                *
00017  *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA       *
00018  *                                                                              */
00019  
00020 #ifdef HAVE_CONFIG_H
00021 #  include <config.h>
00022 #endif
00023 
00024 /*-----------------------------------------------------------------------------
00025                                 Includes
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     /* Create four 3x3-pixel objects */
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     /* Various error checks */
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     /* Verify output of correct call - with zero eccentricity */
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     /* - and points are swapped when needed */
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     /* Verify output of correct call - with maximum (?) eccentricity */
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     /* - and points are swapped when needed */
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         /* Create three 3x3-pixel objects */
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         /* Various error checks */
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         /* Verify output of correct call - with zero eccentricity */
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         /* - and points are swapped when needed */
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         /* Verify output of correct call - with maximum (?) eccentricity */
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         /* - also with points swapped */
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         /* FIXME: When to exactly swap here is not well-defined. */
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 }

Generated on Thu Mar 24 11:59:39 2011 for VISIR Pipeline Reference Manual by  doxygen 1.5.8