00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include <strings.h>
00032 #include <string.h>
00033 #include <irplib_utils.h>
00034 #include <stdio.h>
00035
00036 #ifdef HAVE_CONFIG_H
00037 #include <config.h>
00038 #endif
00039
00040 #include <cpl.h>
00041
00042
00043 #include <sinfo_key_names.h>
00044 #include <sinfo_globals.h>
00045 #include <sinfo_pro_types.h>
00046 #include <sinfo_product_config.h>
00047 #include <sinfo_prepare_stacked_frames_config.h>
00048 #include <sinfo_north_south_test_config.h>
00049
00050 #include <sinfo_new_prepare_stacked_frames.h>
00051 #include <sinfo_distortion_config.h>
00052 #include <sinfo_new_find_distortions.h>
00053 #include <sinfo_new_nst.h>
00054 #include <sinfo_hidden.h>
00055 #include <sinfo_tpl_dfs.h>
00056 #include <sinfo_globals.h>
00057 #include <sinfo_functions.h>
00058 #include <sinfo_tpl_utils.h>
00059 #include <sinfo_error.h>
00060 #include <sinfo_utils_wrappers.h>
00061
00062 #include <sinfo_dfs.h>
00063
00064 int sinfo_step_distortion_create(cpl_plugin *plugin);
00065 int sinfo_step_distortion_exec(cpl_plugin *plugin);
00066 int sinfo_step_distortion_destroy(cpl_plugin *plugin);
00067 static int sinfo_step_distortion(cpl_parameterlist *config, cpl_frameset *set);
00068
00069
00070
00074
00075
00076
00077 void sinfo_find_distortion_config_add(cpl_parameterlist *);
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 int
00088 sinfo_step_distortion_create(cpl_plugin *plugin)
00089 {
00090
00091
00092
00093
00094
00095
00096 cpl_recipe *recipe = (cpl_recipe *)plugin;
00097 recipe->parameters = cpl_parameterlist_new();
00098 if(recipe->parameters == NULL) {
00099 return 1;
00100 }
00101 cpl_error_reset();
00102 irplib_reset();
00103
00104
00105
00106
00107 sinfo_product_config_add(recipe->parameters);
00108 sinfo_prepare_stacked_frames_config_add(recipe->parameters);
00109 sinfo_distortion_config_add(recipe->parameters);
00110 sinfo_north_south_test_config_add(recipe->parameters);
00111
00112 return 0;
00113
00114 }
00115
00116 int
00117 sinfo_step_distortion_exec(cpl_plugin *plugin)
00118 {
00119
00120 cpl_recipe *recipe = (cpl_recipe *) plugin;
00121 if(recipe->parameters == NULL) {
00122 return 1;
00123 }
00124 if(recipe->frames == NULL) {
00125 return 1;
00126 }
00127
00128
00129 return sinfo_step_distortion(recipe->parameters, recipe->frames);
00130
00131 }
00132
00133 int
00134 sinfo_step_distortion_destroy(cpl_plugin *plugin)
00135 {
00136
00137 cpl_recipe *recipe = (cpl_recipe *) plugin;
00138
00139
00140
00141
00142
00143
00144 cpl_parameterlist_delete(recipe->parameters);
00145
00146 return 0;
00147
00148 }
00149
00150 int
00151 cpl_plugin_get_info(cpl_pluginlist *list)
00152 {
00153
00154 cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
00155 cpl_plugin *plugin = &recipe->interface;
00156
00157
00158 cpl_plugin_init(plugin,
00159 CPL_PLUGIN_API,
00160 SINFONI_BINARY_VERSION,
00161 CPL_PLUGIN_TYPE_RECIPE,
00162 "sinfo_step_distortion",
00163 "Find Distortions in frames",
00164 "TBD",
00165 "A. Modigliani",
00166 "amodigli@eso.org",
00167 "No license",
00168 sinfo_step_distortion_create,
00169 sinfo_step_distortion_exec,
00170 sinfo_step_distortion_destroy);
00171
00172 cpl_pluginlist_append(list, plugin);
00173
00174 return 0;
00175
00176 }
00177
00178
00179
00180
00181
00182
00183 static int
00184 sinfo_step_distortion(cpl_parameterlist *config, cpl_frameset *set)
00185 {
00186
00187
00188 cpl_frame* frame=NULL;
00189 char file_name[FILE_NAME_SZ];
00190 cpl_propertylist* plist=NULL;
00191
00192 cpl_image* ima=NULL;
00193 fake* fk=NULL;
00194
00195 ck0(sinfo_dfs_set_groups(set),"Cannot indentify RAW and CALIB frames") ;
00196
00197
00198
00199
00200
00201
00202
00203
00204 sinfo_msg("COMPUTE DISTORTIONS") ;
00205 ck0(sinfo_new_find_distortions(cpl_func,config,set),
00206 "COMPUTE DISTORTION FAILED");
00207
00208 if(NULL != cpl_frameset_find(set,PRO_FIBRE_NS_STACKED)) {
00209 frame = cpl_frameset_find(set,PRO_FIBRE_NS_STACKED);
00210 strcpy(file_name,cpl_frame_get_filename(frame));
00211 } else {
00212 sinfo_msg_error("Frame %s not found!", PRO_FIBRE_NS_STACKED);
00213 goto cleanup;
00214 }
00215 ima=cpl_image_load(file_name,CPL_TYPE_FLOAT,0,0);
00216
00217 cknull(plist = cpl_propertylist_load(file_name, 0),
00218 "getting header from reference ima frame %s",file_name);
00219
00220
00221 if (sinfo_propertylist_has(plist, KEY_NAME_LAMP_HALO)) {
00222 cpl_propertylist_set_bool(plist, KEY_NAME_LAMP_HALO, LAMP_ON);
00223 } else {
00224 cpl_propertylist_append_bool(plist, KEY_NAME_LAMP_HALO,LAMP_ON) ;
00225 }
00226
00227 sinfo_free_image(&ima);
00228 sinfo_free_propertylist(&plist);
00229 sinfo_msg("SUCCESS: COMPUTED DISTORTIONS") ;
00230
00231
00232
00233
00234
00235
00236
00237 sinfo_msg("DISTORT FAKE FRAME");
00238 fk=sinfo_fake_new();
00239
00240 strcpy(fk->pro_class,PRO_FIBRE_NS_STACKED);
00241 fk->frm_switch=1;
00242 fk->mask_index=1;
00243 fk->ind_index=1;
00244 fk->flat_index=0;
00245 fk->wfix_index=1;
00246 fk->low_rej=0.0;
00247 fk->hig_rej=0.0;
00248 ck0(sinfo_new_prepare_stacked_frames(cpl_func,config, set,
00249 PRO_FIBRE_NS_STACKED_DIST, 0,fk),
00250 "FAILED STACKING FRAME") ;
00251
00252 sinfo_msg("SUCCESS: DISTORTED FAKE FRAME\n") ;
00253 sinfo_fake_delete(&fk);
00254
00255
00256 if(NULL != cpl_frameset_find(set,PRO_FIBRE_NS_STACKED_DIST)) {
00257 frame = cpl_frameset_find(set,PRO_FIBRE_NS_STACKED_DIST);
00258 strcpy(file_name,cpl_frame_get_filename(frame));
00259 } else {
00260 sinfo_msg_error("Frame %s not found!", PRO_FIBRE_NS_STACKED_DIST);
00261 goto cleanup;
00262 }
00263 ima=cpl_image_load(file_name,CPL_TYPE_FLOAT,0,0);
00264
00265 cknull(plist = cpl_propertylist_load(file_name, 0),
00266 "getting header from reference ima frame %s",file_name);
00267
00268
00269 if (sinfo_propertylist_has(plist, KEY_NAME_LAMP_HALO)) {
00270 cpl_propertylist_set_bool(plist, KEY_NAME_LAMP_HALO, LAMP_ON);
00271 } else {
00272 cpl_propertylist_append_bool(plist, KEY_NAME_LAMP_HALO,LAMP_ON) ;
00273 }
00274 sinfo_free_propertylist(&plist);
00275 sinfo_free_image(&ima);
00276 sinfo_msg("SUCCESS: COMPUTED DISTORTIONS\n") ;
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287 sinfo_msg("RUN NORD SUD TEST") ;
00288 ck0(sinfo_new_nst(cpl_func,config, set ),"NORTH SOUTH TEST FAILED") ;
00289 sinfo_msg("SUCCESS: RUNNED NORD SUD TEST") ;
00290 sinfo_msg("SUCCESS: RECIPE\n") ;
00291
00292
00293 cleanup:
00294
00295 sinfo_fake_delete(&fk);
00296 sinfo_free_propertylist(&plist) ;
00297 sinfo_free_image(&ima);
00298
00299 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00300 return -1;
00301 } else {
00302 return 0;
00303 }
00304 }
00305