HAWKI Pipeline Reference Manual  1.8.12
hawki_saa.c
1 /* $Id: hawki_saa.c,v 1.10 2010/03/08 16:20:54 cgarcia Exp $
2  *
3  * This file is part of the HAWKI Pipeline
4  * Copyright (C) 2002,2003 European Southern Observatory
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 /*
22  * $Author: cgarcia $
23  * $Date: 2010/03/08 16:20:54 $
24  * $Revision: 1.10 $
25  * $Name: hawki-1_8_12 $
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 
32 /*-----------------------------------------------------------------------------
33  Includes
34  -----------------------------------------------------------------------------*/
35 
36 #include <float.h>
37 #include <string.h>
38 #include <math.h>
39 #include <cpl.h>
40 
41 #include "hawki_saa.h"
42 
43 /*----------------------------------------------------------------------------*/
52 /*----------------------------------------------------------------------------*/
53 int hawki_geom_refine_images_offsets
54 (cpl_imagelist * in,
55  cpl_bivector * approx_offsets,
56  cpl_bivector * reference_objects,
57  int s_hx,
58  int s_hy,
59  int m_hx,
60  int m_hy,
61  cpl_bivector * refined_offsets,
62  cpl_vector * correl)
63 {
64  cpl_bivector * offs_ref ;
65  double * offs_ref_x ;
66  double * offs_ref_y ;
67  double * correl_data ;
68  int nimages;
69  int ngood;
70  int i;
71 
72  /* Check entries */
73  if (approx_offsets == NULL) return -1;
74  if (refined_offsets == NULL) return -1;
75 
76  /* Get the number of images */
77  nimages = cpl_imagelist_get_size(in) ;
78  if (cpl_bivector_get_size(approx_offsets) != nimages)
79  {
80  cpl_msg_error(__func__, "Invalid input objects sizes") ;
81  return -1;
82  }
83 
84  /* Refine the offsets */
85  cpl_msg_info(__func__, "Refine the offsets") ;
86  cpl_msg_indent_more() ;
87  if ((offs_ref = cpl_geom_img_offset_fine
88  (in, approx_offsets, reference_objects,
89  s_hx, s_hy, m_hx, m_hy, correl)) == NULL)
90  {
91  cpl_msg_error(cpl_func, "Cannot refine the offsets");
92  cpl_vector_delete(correl) ;
93  return -1;
94  }
95 
96  /* Display the results */
97  offs_ref_x = cpl_bivector_get_x_data(offs_ref) ;
98  offs_ref_y = cpl_bivector_get_y_data(offs_ref) ;
99  correl_data = cpl_vector_get_data(correl) ;
100  cpl_msg_info(cpl_func, "Refined relative offsets [correlation factor]") ;
101  ngood = 0 ;
102  for (i=0 ; i<nimages ; i++)
103  {
104  cpl_msg_info(cpl_func, "#%02d: %8.2f %8.2f [%12.2f]",
105  i+1, offs_ref_x[i], offs_ref_y[i], correl_data[i]) ;
106  if (correl_data[i] > -0.5) ngood++ ;
107  }
108  if (ngood == 0)
109  {
110  cpl_msg_error(__func__, "No frame correctly correlated") ;
111  cpl_bivector_delete(offs_ref) ;
112  cpl_vector_delete(correl) ;
113  return -1;
114  }
115  cpl_msg_indent_less();
116 
117  /* Copy the result */
118  cpl_vector_copy(cpl_bivector_get_x(refined_offsets),
119  cpl_bivector_get_x(offs_ref));
120  cpl_vector_copy(cpl_bivector_get_y(refined_offsets),
121  cpl_bivector_get_y(offs_ref));
122 
123  /* Free and return */
124  cpl_bivector_delete(offs_ref);
125  cpl_msg_indent_less() ;
126  return 0;
127 }