00001 /** @file psCoord.h 00002 * 00003 * @brief Basic coordinate transformations 00004 * 00005 * This file defines the basic types for astronomical coordinate 00006 * transformation 00007 * 00008 * @author GLG, MHPCC 00009 * 00010 * @version $Revision: 1.56 $ $Name: $ 00011 * @date $Date: 2007/01/23 22:47:22 $ 00012 * 00013 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii 00014 */ 00015 00016 #ifndef PS_COORD_H 00017 #define PS_COORD_H 00018 00019 /// @addtogroup Astro Astronomy 00020 /// @{ 00021 00022 #include "psType.h" 00023 #include "psImage.h" 00024 #include "psArray.h" 00025 #include "psList.h" 00026 #include "psPolynomial.h" 00027 #include "psPixels.h" 00028 #include "psRegion.h" 00029 //#include "psTime.h" 00030 00031 /** Euclidiean Coordinate System. 00032 * 00033 * Both detector and sky positions will be used extensively in the IPP. One 00034 * coordinate system to be used is linear coordinates which conform to 00035 * Euclidean geometry. 00036 * 00037 */ 00038 typedef struct 00039 { 00040 double x; ///< x position 00041 double y; ///< y position 00042 double xErr; ///< Error in x position 00043 double yErr; ///< Error in y position 00044 } 00045 psPlane; 00046 00047 /** Angular Coordinate System 00048 * 00049 * Both detector and sky positions will be used extensively in the IPP. One 00050 * coordinate system to be used is angular coordinates for which additional 00051 * care must often be taken in comparison to a euclidiean coordinate system. 00052 * 00053 */ 00054 typedef struct 00055 { 00056 double r; ///< RA 00057 double d; ///< Dec 00058 double rErr; ///< Error in RA 00059 double dErr; ///< Error in Dec 00060 } 00061 psSphere; 00062 00063 /** 3-Dimensional Euclidean Coordinate System 00064 * 00065 * Both detector and sky positions will be used extensively in the IPP. One 00066 * coordinate system to be used is cubic coordinates for which additional 00067 * care must often be taken in comparison to an angular coordinate system. 00068 * 00069 */ 00070 typedef struct 00071 { 00072 double x; ///< cos (DEC) cos (RA) 00073 double y; ///< cos (DEC) sin (RA) 00074 double z; ///< sin (DEC) 00075 double xErr; ///< Error in x 00076 double yErr; ///< Error in y 00077 double zErr; ///< Error in z 00078 } 00079 psCube; 00080 00081 /** 2D Polynomial Transform 00082 * 00083 * A transform between coordinate systems that consists simply of two 2D 00084 * polynomials to transform both components - the output coordinates depend 00085 * only on the input coordinates and no other quantities of objects at those 00086 * coordinates. 00087 * 00088 */ 00089 typedef struct 00090 { 00091 psPolynomial2D* x; ///< 2D polynomial transform of X coordinates 00092 psPolynomial2D* y; ///< 2D polynomial transform of Y coordinates 00093 } 00094 psPlaneTransform; 00095 00096 /** 4D Polynomial Transform 00097 * 00098 * A transform between coordinate systems that consists of two 4D polynomials 00099 * in which the output coordinates are also specified to be a function of the 00100 * magnitude and color of the object with the given coordinates. This type of 00101 * coordinate transformation is necessary to represent the (color-dependent) 00102 * optical distortions caused by the atmosphere and camera optics, and the 00103 * possibly effects of charge transfer inefficiency. 00104 * 00105 * The lowest two terms are the x and y axis of the target system. The higher 00106 * two terms may represent magnitude and color terms. 00107 */ 00108 typedef struct 00109 { 00110 psPolynomial4D* x; ///< 4D polynomial transform of X coordinates 00111 psPolynomial4D* y; ///< 4D polynomial transform of Y coordinates 00112 } 00113 psPlaneDistort; 00114 00115 /** Projection type for projection/deprojection 00116 * 00117 * @see psProject, psDeproject 00118 * 00119 */ 00120 typedef enum { 00121 PS_PROJ_LIN, ///< Linear projection 00122 PS_PROJ_PLY, ///< Linear polynomial projection 00123 PS_PROJ_WRP, ///< Linear polynomial projection 00124 PS_PROJ_TAN, ///< Tangent projection 00125 PS_PROJ_DIS, ///< Sine projection 00126 PS_PROJ_SIN, ///< Sine projection 00127 PS_PROJ_STG, ///< Sine projection 00128 PS_PROJ_ZEA, ///< Sine projection 00129 PS_PROJ_ZPL, ///< Sine projection 00130 PS_PROJ_AIT, ///< Aitoff projection 00131 PS_PROJ_PAR, ///< Par projection 00132 PS_PROJ_GLS, ///< GLS projection 00133 PS_PROJ_CAR, ///< CAR projection 00134 PS_PROJ_MER, ///< MER projection 00135 PS_PROJ_NTYPE ///< Number of types; must be last. 00136 } psProjectionType; 00137 00138 /** Parameter set for projection/deprojection 00139 * 00140 * @see psProject, psDeproject 00141 * 00142 */ 00143 typedef struct 00144 { 00145 double R; ///< Coordinates of projection center 00146 double D; ///< Coordinates of projection center 00147 double Xs; ///< plate-scale in X direction 00148 double Ys; ///< plate-scale in Y direction 00149 psProjectionType type; ///< Projection type 00150 } 00151 psProjection; 00152 00153 /** Allocates a psPlane 00154 * 00155 * @return psPlane* resulting plane structure. 00156 */ 00157 psPlane* psPlaneAlloc(void); 00158 00159 /** Allocates a psSphere 00160 * 00161 * @return psSphere* resulting sphere structure. 00162 */ 00163 psSphere* psSphereAlloc(void); 00164 00165 /** Allocates a psCube 00166 * 00167 * @return psCube* resulting cubic structure. 00168 */ 00169 psCube* psCubeAlloc(void); 00170 00171 /** Allocates a psPlaneTransform transform. 00172 * 00173 * @return psPlaneTransform* resulting plane transform 00174 */ 00175 00176 psPlaneTransform* psPlaneTransformAlloc( 00177 int order1, ///< The order of the x term in the transform. 00178 int order2 ///< The order of the y term in the transform. 00179 ); 00180 00181 /** Applies the psPlaneTransform transform to a specified coordinate 00182 * 00183 * @return psPlane* resulting coordinate based on transform 00184 */ 00185 psPlane* psPlaneTransformApply( 00186 psPlane* out, ///< a psPlane to recycle. If NULL, a new one is generated. 00187 const psPlaneTransform* transform, ///< the transform to apply 00188 const psPlane* coords ///< the coordinate to apply the transform above. 00189 ); 00190 00191 /** Allocates a psPlaneDistort transform. 00192 * 00193 * @return psPlaneDistort* resulting plane distort transform 00194 */ 00195 00196 psPlaneDistort* psPlaneDistortAlloc( 00197 int order1, ///< The order of the w term in the transform. 00198 int order2, ///< The order of the x term in the transform. 00199 int order3, ///< The order of the y term in the transform. 00200 int order4 ///< The order of the z term in the transform. 00201 ); 00202 00203 00204 /** Applies the psPlaneDistort transform to a specified coordinate 00205 * 00206 * @return psPlane* resulting coordinate based on transform 00207 */ 00208 psPlane* psPlaneDistortApply( 00209 psPlane* out, ///< a psPlane to recycle. If NULL, a new one is generated. 00210 const psPlaneDistort* distort, ///< the transform to apply 00211 const psPlane* coords, ///< the coordinate to apply the transform above. 00212 float mag, ///< third term -- maybe magnitude 00213 float color ///< forth term -- maybe color 00214 ); 00215 00216 /** Allocates memory for a psProjection structure 00217 * 00218 * @return psProjection* psProjection structure 00219 */ 00220 psProjection* psProjectionAlloc( 00221 double R, ///< Right-ascension of projection center. 00222 double D, ///< Declination of projection center. 00223 double Xs, ///< Scale in x-dimension 00224 double Ys, ///< Scale in y-dimension 00225 psProjectionType type 00226 ); 00227 00228 /** Checks the type of a particular pointer. 00229 * 00230 * Uses the appropriate deallocation function in psMemBlock to check the ptr datatype. 00231 * 00232 * @return bool: True if the pointer matches a psPlane structure, false otherwise. 00233 */ 00234 bool psMemCheckPlane( 00235 psPtr ptr ///< the pointer whose type to check 00236 ); 00237 00238 /** Checks the type of a particular pointer. 00239 * 00240 * Uses the appropriate deallocation function in psMemBlock to check the ptr datatype. 00241 * 00242 * @return bool: True if the pointer matches a psSphere structure, false otherwise. 00243 */ 00244 bool psMemCheckSphere( 00245 psPtr ptr ///< the pointer whose type to check 00246 ); 00247 00248 /** Checks the type of a particular pointer. 00249 * 00250 * Uses the appropriate deallocation function in psMemBlock to check the ptr datatype. 00251 * 00252 * @return bool: True if the pointer matches a psCube structure, false otherwise. 00253 */ 00254 bool psMemCheckCube( 00255 psPtr ptr ///< the pointer whose type to check 00256 ); 00257 00258 /** Checks the type of a particular pointer. 00259 * 00260 * Uses the appropriate deallocation function in psMemBlock to check the ptr datatype. 00261 * 00262 * @return bool: True if the pointer matches a psPlaneTransform structure, false otherwise. 00263 */ 00264 bool psMemCheckPlaneTransform( 00265 psPtr ptr ///< the pointer whose type to check 00266 ); 00267 00268 /** Checks the type of a particular pointer. 00269 * 00270 * Uses the appropriate deallocation function in psMemBlock to check the ptr datatype. 00271 * 00272 * @return bool: True if the pointer matches a psPlaneDistort structure, false otherwise. 00273 */ 00274 bool psMemCheckPlaneDistort( 00275 psPtr ptr ///< the pointer whose type to check 00276 ); 00277 00278 /** Checks the type of a particular pointer. 00279 * 00280 * Uses the appropriate deallocation function in psMemBlock to check the ptr datatype. 00281 * 00282 * @return bool: True if the pointer matches a psProjection structure, false otherwise. 00283 */ 00284 bool psMemCheckProjection( 00285 psPtr ptr ///< the pointer whose type to check 00286 ); 00287 00288 00289 /** Projects a spherical coordinate to a linear coordinate system 00290 * 00291 * @return psPlane* projected coordinate 00292 */ 00293 psPlane* psProject( 00294 psPlane *out, 00295 const psSphere* coord, ///< coordinate to project 00296 const psProjection* projection ///< parameters of the projection 00297 ); 00298 00299 /** Reverse projection of a linear coordinate to a spherical coordinate system 00300 * 00301 * @return psPlane* projected coordinate 00302 */ 00303 psSphere* psDeproject( 00304 psSphere *outSphere, 00305 const psPlane* coord, ///< coordinate to project 00306 const psProjection* projection ///< parameters of the projection 00307 ); 00308 00309 /** Takes a given transform and inverts it linearly if possible. 00310 * 00311 * @return psPlaneTransform 00312 * the linearly inverted transform 00313 */ 00314 psPlaneTransform *p_psPlaneTransformLinearInvert( 00315 psPlaneTransform *transform ///< transform to invert 00316 ); 00317 00318 /** Takes a transform and tests whether or not it is a linear projection. 00319 * 00320 * @return psS32 00321 * the order of the projection 00322 */ 00323 psBool p_psIsProjectionLinear( 00324 psPlaneTransform *transform ///< transform to test for linearity 00325 ); 00326 00327 00328 /** inverts a given transformation. 00329 * 00330 * It may assume that the input transformation is one-to-one, and that the 00331 * inverse transformation may be specified through using polynomials of the 00332 * same type and order as the forward transformation. In the event that the 00333 * input transformation is linear, an exact solution may be calculated; 00334 * otherwise nSamples samples in each axis, covering the region specified by 00335 * region shall be used as a grid to fit the best inverse transformation. The 00336 * function shall return NULL if it was unable to generate the inverse 00337 * transformation; otherwise it shall return the inverse transformation. In 00338 * the event that out is NULL, a new psPlaneTransform shall be allocated and 00339 * returned. 00340 * 00341 * @return psPlaneTransform* the resulting inverted transform 00342 */ 00343 psPlaneTransform* psPlaneTransformInvert( 00344 psPlaneTransform *out, ///< a transform to recycle, or NULL if one is to be created. 00345 const psPlaneTransform *in, ///< transform to invert 00346 psRegion region, ///< region to fit for non-linear transform inversion 00347 int nSamples ///< number of samples in each axis for fit 00348 ); 00349 00350 /** Creates a single transformation that has the effect of performing trans1 00351 * followed by trans2. 00352 * 00353 * psPlaneTransformCombine takes two transformations (trans1 and trans2) and 00354 * returns a single transformation that has the effect of performing trans1 00355 * followed by trans2. In the event that the input transformation is linear, 00356 * an exact solution may be calculated; otherwise nSamples samples in each 00357 * axis, covering the region specified by region shall be used as a grid to 00358 * fit the best inverse transformation. The function shall return NULL if it 00359 * was unable to generate the transformation; otherwise it shall return the 00360 * transformation. 00361 * 00362 * @return psPlaneTransform* resulting transformation 00363 */ 00364 psPlaneTransform* psPlaneTransformCombine( 00365 psPlaneTransform *out, ///< a transform to recycle, or NULL if one is to be created. 00366 const psPlaneTransform *trans1, ///< first transform to combine 00367 const psPlaneTransform *trans2, ///< first transform to combine 00368 psRegion region, ///< region to cover (for non-linear transforms) 00369 int nSamples ///< number of samples on each axis (for non-linear transforms) 00370 ); 00371 00372 00373 /** takes two arrays containing matched coordinates and returns the 00374 * best-fitting transformation. 00375 * 00376 * psPlaneTransformFit takes two arrays containing matched coordinates (i.e., 00377 * coordinates in the source array correspond to the coordinates in the dest 00378 * array) and returns the best-fitting transformation. The source and dest 00379 * will contain psCoords. In the event that the number of coordinates in each 00380 * is not identical, the function shall generate a warning, and extra 00381 * coordinates in the longer of the two shall be ignored. The trans transform 00382 * may not be NULL, since it specifies the desired order, polynomial type and 00383 * any polynomial terms to mask. nRejIter rejection iterations shall be 00384 * performed, wherein coordinates lying more than sigmaClip standard 00385 * deviations from the fit shall be rejected. 00386 * 00387 * @return bool TRUE if successful, otherwise FALSE. 00388 */ 00389 bool psPlaneTransformFit( 00390 psPlaneTransform *trans, ///< desired order, polynomial type, & polynomial mask terms 00391 const psArray *source, ///< coordinates matching those in dest 00392 const psArray *dest, ///< coordinates matching those in source 00393 int nRejIter, ///< number of rejection iterations to be performed 00394 float sigmaClip ///< coordinates above this number of standard deviations will be rejected 00395 ); 00396 //XXX: need to add doxygen comments on the parameters above. -rdd 00397 00398 /** Converts from a 3-dimensional coordinate system to an angular coordinate system. 00399 * 00400 * @return psSphere* The former psCube in terms of a psSphere. 00401 */ 00402 psSphere *psCubeToSphere( 00403 const psCube *cube ///< psCube to convert 00404 ); 00405 00406 /** Converts from an angular coordinate system to a 3-dimensional coordinate system. 00407 * 00408 * @return psCube* The former psSphere in terms of a psCube. 00409 */ 00410 psCube *psSphereToCube( 00411 const psSphere *sphere ///< psSphere to convert 00412 ); 00413 00414 00415 /** Calculates the derivative of the specified psPlaneTransform with respect to x and y. 00416 * 00417 * @return psPlane* The derivative. 00418 */ 00419 psPlane *psPlaneTransformDeriv( 00420 psPlane *out, 00421 const psPlaneTransform *transformation, 00422 const psPlane *coord 00423 ); 00424 00425 /** Generates a list of pixels in the output coordinate frame that overlap the input 00426 * pixels in the input coordinate frame through the specified transformation, inToOut. 00427 * 00428 * psPixelsTransform is more complicated than simply transforming the input pixels, 00429 * but requires the evaluation of the derivatives of the transformation in order to 00430 * obtain the list of all pixels in the output coordinate frame that possibly overlap 00431 * the pixel in the input coordinate frame. In the event that input or inToOut are 00432 * NULL, the function shall generate an error and return NULL. If out is non-NULL it 00433 * shall be modified and returned; otherwise a new psPixels shall be allocated and 00434 * returned. 00435 * 00436 * @return psPixels*: the list of overlapping pixels. 00437 */ 00438 psPixels *psPixelsTransform( 00439 psPixels *out, ///< output list of overlapping pixels 00440 const psPixels *input, ///< input list of pixels 00441 const psPlaneTransform *inToOut ///< specified transformation 00442 ); 00443 00444 char * psProjectTypeToString (psProjectionType type, char *prefix); 00445 psProjectionType psProjectTypeFromString (char *name); 00446 00447 00448 #define PS_PRINT_PLANE_TRANSFORM(NAME) \ 00449 { \ 00450 printf("---------------------- Plane Transform ----------------------\n"); \ 00451 printf("x:\n"); \ 00452 PS_POLY_PRINT_2D(NAME->x); \ 00453 printf("y:\n"); \ 00454 PS_POLY_PRINT_2D(NAME->y); \ 00455 } \ 00456 00457 /// @} 00458 #endif // #ifndef PS_COORD_H
1.5.1