1 /* 2 # This file is part of the Astrometry.net suite. 3 # Licensed under a 3-clause BSD style license - see LICENSE 4 */ 5 6 #ifndef _TWEAK_INTERNAL_H 7 #define _TWEAK_INTERNAL_H 8 9 #include "astrometry/an-bool.h" 10 #include "astrometry/kdtree.h" 11 #include "astrometry/bl.h" 12 #include "astrometry/sip.h" 13 #include "astrometry/starutil.h" 14 #include "astrometry/starxy.h" 15 16 // These flags represent the work already done on a tweak problem 17 enum tweak_flags { 18 TWEAK_HAS_SIP = 0x1, 19 TWEAK_HAS_IMAGE_XY = 0x2, 20 TWEAK_HAS_IMAGE_XYZ = 0x4, 21 TWEAK_HAS_IMAGE_AD = 0x8, 22 TWEAK_HAS_REF_XY = 0x10, 23 TWEAK_HAS_REF_XYZ = 0x20, 24 TWEAK_HAS_REF_AD = 0x40, 25 TWEAK_HAS_CORRESPONDENCES = 0x100, 26 TWEAK_HAS_COARSLY_SHIFTED = 0x800, 27 TWEAK_HAS_FINELY_SHIFTED = 0x1000, 28 TWEAK_HAS_REALLY_FINELY_SHIFTED = 0x2000, 29 TWEAK_HAS_LINEAR_CD = 0x4000, 30 }; 31 32 typedef struct tweak_s { 33 sip_t* sip; 34 // bitfield of tweak_flags 35 unsigned int state; 36 37 // Sources in the image 38 int n; 39 // pixel x,y 40 double *x; 41 double *y; 42 // CACHED: 43 // RA,Dec 44 double *a; 45 double *d; 46 // vector on the unit sphere 47 double *xyz; 48 49 // Sources in the catalog 50 int n_ref; 51 // RA,Dec 52 double *a_ref; 53 double *d_ref; 54 // unit vector on the sphere 55 double *xyz_ref; 56 // CACHED: 57 // pixel 58 double *x_ref; 59 double *y_ref; 60 61 // Correspondences 62 il* image; 63 il* ref; 64 dl* dist2; 65 dl* weight; 66 67 // Size of Hough space for shift 68 double mindx, mindy, maxdx, maxdy; 69 70 // Size of last run shift operation 71 double xs, ys; 72 73 // Trees used for finding correspondences 74 kdtree_t* kd_image; 75 kdtree_t* kd_ref; 76 77 // star jitter, in arcseconds. 78 double jitter; 79 80 // (computed from jitter); star jitter in distance-squared on the unit sphere. 81 double jitterd2; 82 83 // Weighted or unweighted fit? 84 anbool weighted_fit; 85 86 // push SIP shift term onto CRPIX, or CRVAL? 87 // traditional behavior is CRPIX; ie push_crval = FALSE. 88 //anbool push_crval; 89 90 91 } tweak_t; 92 93 tweak_t* tweak_new(); 94 void tweak_init(tweak_t*); 95 void tweak_push_wcs_tan(tweak_t* t, const tan_t* wcs); 96 void tweak_push_ref_xyz(tweak_t* t, const double* xyz, int n); 97 void tweak_push_ref_ad(tweak_t* t, const double* a, const double *d, int n); 98 void tweak_push_ref_ad_array(tweak_t* t, const double* ad, int n); 99 void tweak_push_image_xy(tweak_t* t, const starxy_t* xy); 100 void tweak_push_correspondence_indices(tweak_t* t, il* image, il* ref, dl* distsq, dl* weight); 101 102 unsigned int tweak_advance_to(tweak_t* t, unsigned int flag); 103 void tweak_clear(tweak_t* t); 104 void tweak_dump_ascii(tweak_t* t); 105 void tweak_skip_shift(tweak_t* t); 106 char* tweak_get_state_string(const tweak_t* t); 107 void tweak_go_to(tweak_t* t, unsigned int flag); 108 void tweak_clear_correspondences(tweak_t* t); 109 void tweak_clear_on_sip_change(tweak_t* t); 110 void tweak_clear_image_ad(tweak_t* t); 111 void tweak_clear_ref_xy(tweak_t* t); 112 void tweak_clear_image_xyz(tweak_t* t); 113 void tweak_free(tweak_t* t); 114 115 void tweak_iterate_to_order(tweak_t* t, int maxorder, int iterations); 116 117 sip_t* tweak_just_do_it(const tan_t* wcs, const starxy_t* imagexy, 118 const double* starxyz, 119 const double* star_ra, const double* star_dec, 120 const double* star_radec, 121 int nstars, double jitter_arcsec, 122 int order, int inverse_order, int iterations, 123 anbool weighted, anbool skip_shift); 124 125 126 // TEST 127 void tchebyshev_tweak(tweak_t* t, int W, int H); 128 129 #endif 130