HAWKI Pipeline Reference Manual 1.8.12
hawki_saa.c
00001 /* $Id: hawki_saa.c,v 1.10 2010/03/08 16:20:54 cgarcia Exp $
00002  *
00003  * This file is part of the HAWKI Pipeline
00004  * Copyright (C) 2002,2003 European Southern Observatory
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: cgarcia $
00023  * $Date: 2010/03/08 16:20:54 $
00024  * $Revision: 1.10 $
00025  * $Name: hawki-1_8_12 $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 /*-----------------------------------------------------------------------------
00033                                    Includes
00034  -----------------------------------------------------------------------------*/
00035 
00036 #include <float.h>
00037 #include <string.h>
00038 #include <math.h>
00039 #include <cpl.h>
00040 
00041 #include "hawki_saa.h"
00042 
00043 /*----------------------------------------------------------------------------*/
00052 /*----------------------------------------------------------------------------*/
00053 int hawki_geom_refine_images_offsets
00054 (cpl_imagelist  *  in,
00055  cpl_bivector   *  approx_offsets,
00056  cpl_bivector   *  reference_objects,
00057  int               s_hx,
00058  int               s_hy,
00059  int               m_hx,
00060  int               m_hy,
00061  cpl_bivector   *  refined_offsets,
00062  cpl_vector     *  correl)
00063 {
00064     cpl_bivector        *   offs_ref ;
00065     double              *   offs_ref_x ;
00066     double              *   offs_ref_y ;
00067     double              *   correl_data ;
00068     int                     nimages;
00069     int                     ngood;
00070     int                     i;
00071 
00072     /* Check entries */
00073     if (approx_offsets  == NULL) return -1;
00074     if (refined_offsets == NULL) return -1;
00075 
00076     /* Get the number of images */
00077     nimages = cpl_imagelist_get_size(in) ;
00078     if (cpl_bivector_get_size(approx_offsets) != nimages) 
00079     {
00080         cpl_msg_error(__func__, "Invalid input objects sizes") ; 
00081         return -1;
00082     }
00083     
00084     /* Refine the offsets */
00085     cpl_msg_info(__func__, "Refine the offsets") ;
00086     cpl_msg_indent_more() ;
00087     if ((offs_ref = cpl_geom_img_offset_fine
00088             (in, approx_offsets, reference_objects,
00089              s_hx, s_hy, m_hx, m_hy, correl)) == NULL)
00090     {
00091         cpl_msg_error(cpl_func, "Cannot refine the offsets");
00092         cpl_vector_delete(correl) ;
00093         return -1;
00094     }
00095 
00096     /* Display the results */
00097     offs_ref_x = cpl_bivector_get_x_data(offs_ref) ;
00098     offs_ref_y = cpl_bivector_get_y_data(offs_ref) ;
00099     correl_data = cpl_vector_get_data(correl) ;
00100     cpl_msg_info(cpl_func, "Refined relative offsets [correlation factor]") ;
00101     ngood = 0 ;
00102     for (i=0 ; i<nimages ; i++) 
00103     {
00104         cpl_msg_info(cpl_func, "#%02d: %8.2f %8.2f [%12.2f]",
00105                      i+1, offs_ref_x[i], offs_ref_y[i], correl_data[i]) ;
00106         if (correl_data[i] > -0.5) ngood++ ;
00107     }
00108     if (ngood == 0) 
00109     {
00110         cpl_msg_error(__func__, "No frame correctly correlated") ;
00111         cpl_bivector_delete(offs_ref) ;
00112         cpl_vector_delete(correl) ;
00113         return -1;
00114     }
00115     cpl_msg_indent_less();
00116 
00117     /* Copy the result */
00118     cpl_vector_copy(cpl_bivector_get_x(refined_offsets),
00119                     cpl_bivector_get_x(offs_ref));
00120     cpl_vector_copy(cpl_bivector_get_y(refined_offsets),
00121                     cpl_bivector_get_y(offs_ref));
00122 
00123     /* Free and return */
00124     cpl_bivector_delete(offs_ref);
00125     cpl_msg_indent_less() ;
00126     return 0;
00127 }