Commit 94f5193c0e6cde30def2f29b57bd0634d0046f26

Authored by knodlseder
1 parent e23ca974

implement dir2xy and xy2dir methods

include/GWcsCAR.hpp
@@ -20,6 +20,9 @@ @@ -20,6 +20,9 @@
20 #define GWCSCAR_HPP 20 #define GWCSCAR_HPP
21 21
22 /* __ Includes ___________________________________________________________ */ 22 /* __ Includes ___________________________________________________________ */
  23 +#ifdef HAVE_CONFIG_H
  24 +#include <config.h>
  25 +#endif
23 #include "GWcs.hpp" 26 #include "GWcs.hpp"
24 #include "GSkyDir.hpp" 27 #include "GSkyDir.hpp"
25 #include "GSkyPixel.hpp" 28 #include "GSkyPixel.hpp"
@@ -66,10 +69,6 @@ private: @@ -66,10 +69,6 @@ private:
66 void free_members(void); 69 void free_members(void);
67 GWcsCAR* clone(void) const; 70 GWcsCAR* clone(void) const;
68 71
69 - // Implemented pure virtual private methods  
70 - void wcsxy2sph(const double& x, const double& y, double* lon, double* lat) const;  
71 - void wcssph2xy(const double& lon, const double& lat, double* x, double* y) const;  
72 -  
73 // Private data area 72 // Private data area
74 }; 73 };
75 74
src/sky/GWcsCAR.cpp
@@ -18,7 +18,11 @@ @@ -18,7 +18,11 @@
18 */ 18 */
19 19
20 /* __ Includes ___________________________________________________________ */ 20 /* __ Includes ___________________________________________________________ */
  21 +#ifdef HAVE_CONFIG_H
  22 +#include <config.h>
  23 +#endif
21 #include "GException.hpp" 24 #include "GException.hpp"
  25 +#include "GTools.hpp"
22 #include "GWcsCAR.hpp" 26 #include "GWcsCAR.hpp"
23 27
24 /* __ Method name definitions ____________________________________________ */ 28 /* __ Method name definitions ____________________________________________ */
@@ -30,6 +34,8 @@ @@ -30,6 +34,8 @@
30 /* __ Coding definitions _________________________________________________ */ 34 /* __ Coding definitions _________________________________________________ */
31 35
32 /* __ Debug definitions __________________________________________________ */ 36 /* __ Debug definitions __________________________________________________ */
  37 +#define G_DIR2XY_DEBUG // Debug dir2xy
  38 +#define G_XY2DIR_DEBUG // Debug xy2dir
33 39
34 /* __ Local prototypes ___________________________________________________ */ 40 /* __ Local prototypes ___________________________________________________ */
35 41
@@ -81,6 +87,12 @@ GWcsCAR::GWcsCAR(const std::string&amp; coords, @@ -81,6 +87,12 @@ GWcsCAR::GWcsCAR(const std::string&amp; coords,
81 // Initialise class members 87 // Initialise class members
82 init_members(); 88 init_members();
83 89
  90 + // Derive projection parameters
  91 + m_theta0 = 0.0;
  92 + m_native_pole = wcs_getpole(m_theta0);
  93 + m_rot = wcs_get_rot();
  94 + m_trot = transpose(m_rot);
  95 +
84 // Return 96 // Return
85 return; 97 return;
86 } 98 }
@@ -194,7 +206,14 @@ std::string GWcsCAR::type(void) const @@ -194,7 +206,14 @@ std::string GWcsCAR::type(void) const
194 GSkyDir GWcsCAR::pix2dir(const int& pix) 206 GSkyDir GWcsCAR::pix2dir(const int& pix)
195 { 207 {
196 // Throw error 208 // Throw error
197 - throw GException::wcs(G_XY2DIR, "WCS method not defined for CAR projection."); 209 + throw GException::wcs(G_XY2DIR,
  210 + "WCS method not defined for CAR projection.");
  211 +
  212 + // Define constant direction
  213 + const GSkyDir dir;
  214 +
  215 + // Return
  216 + return dir;
198 } 217 }
199 218
200 219
@@ -202,14 +221,36 @@ GSkyDir GWcsCAR::pix2dir(const int&amp; pix) @@ -202,14 +221,36 @@ GSkyDir GWcsCAR::pix2dir(const int&amp; pix)
202 * @brief Returns sky direction of pixel 221 * @brief Returns sky direction of pixel
203 * 222 *
204 * @param[in] pix Sky pixel. 223 * @param[in] pix Sky pixel.
  224 + *
  225 + * Note that pixel indices start from 0.
205 ***************************************************************************/ 226 ***************************************************************************/
206 GSkyDir GWcsCAR::xy2dir(const GSkyPixel& pix) 227 GSkyDir GWcsCAR::xy2dir(const GSkyPixel& pix)
207 { 228 {
208 - // Allocate sky direction  
209 - GSkyDir dir;  
210 -  
211 - //TODO: Implement 229 + // Set constants
  230 + const int __permutation[2] = {1,0};
  231 +
  232 + // Determine offset
  233 + GVector offset = GVector(pix.x(), pix.y());
  234 +
  235 + // Determine xy
  236 + GVector xy = m_cd * (offset - m_refpix);
  237 +
  238 + // Swap result if coordinates are reversed
  239 + if (m_reverse)
  240 + xy = perm(xy, __permutation);
  241 +
  242 + // Perform CAR map projection
  243 + GVector native = xy * deg2rad;
  244 +
  245 + // Get sky direction for native coordinates
  246 + GSkyDir dir = wcs_native2dir(native);
212 247
  248 + // Debug: Dump transformation steps
  249 + #if defined(G_XY2DIR_DEBUG)
  250 + std::cout << "xy2dir: pixel=" << offset << " xy=" << xy
  251 + << " native=" << native << " dir=" << dir << std::endl;
  252 + #endif
  253 +
213 // Return 254 // Return
214 return dir; 255 return dir;
215 } 256 }
@@ -223,7 +264,11 @@ GSkyDir GWcsCAR::xy2dir(const GSkyPixel&amp; pix) @@ -223,7 +264,11 @@ GSkyDir GWcsCAR::xy2dir(const GSkyPixel&amp; pix)
223 int GWcsCAR::dir2pix(GSkyDir dir) const 264 int GWcsCAR::dir2pix(GSkyDir dir) const
224 { 265 {
225 // Throw error 266 // Throw error
226 - throw GException::wcs(G_DIR2XY, "WCS method not defined for CAR projection."); 267 + throw GException::wcs(G_DIR2XY,
  268 + "WCS method not defined for CAR projection.");
  269 +
  270 + // Return
  271 + return 0;
227 } 272 }
228 273
229 274
@@ -231,15 +276,37 @@ int GWcsCAR::dir2pix(GSkyDir dir) const @@ -231,15 +276,37 @@ int GWcsCAR::dir2pix(GSkyDir dir) const
231 * @brief Returns pixel of sky direction 276 * @brief Returns pixel of sky direction
232 * 277 *
233 * @param[in] dir Sky direction. 278 * @param[in] dir Sky direction.
  279 + *
  280 + * Note that pixel indices start from 0.
234 ***************************************************************************/ 281 ***************************************************************************/
235 GSkyPixel GWcsCAR::dir2xy(GSkyDir dir) const 282 GSkyPixel GWcsCAR::dir2xy(GSkyDir dir) const
236 { 283 {
237 - // Allocate sky pixel  
238 - GSkyPixel pixel; 284 + // Set constants
  285 + const int __permutation[2] = {1,0};
  286 +
  287 + // Get native coordinates for sky direction in radians
  288 + GVector native = wcs_dir2native(dir);
239 289
240 - //TODO: Implement 290 + // Perform CAR map projection
  291 + GVector xy = native * rad2deg;
241 292
242 - // Return 293 + // Swap result if coordinates are reversed
  294 + if (m_reverse)
  295 + xy = perm(xy, __permutation);
  296 +
  297 + // Determine pixel offset
  298 + GVector offset = m_invcd * xy + m_refpix;
  299 +
  300 + // Set sky pixel
  301 + GSkyPixel pixel(offset(0), offset(1));
  302 +
  303 + // Debug: Dump transformation steps
  304 + #if defined(G_DIR2XY_DEBUG)
  305 + std::cout << "dir2xy: dir=" << dir << " native=" << native
  306 + << " xy=" << xy << " pixel=" << offset << std::endl;
  307 + #endif
  308 +
  309 + // Return sky pixel
243 return pixel; 310 return pixel;
244 } 311 }
245 312
@@ -323,17 +390,6 @@ GWcsCAR* GWcsCAR::clone(void) const @@ -323,17 +390,6 @@ GWcsCAR* GWcsCAR::clone(void) const
323 } 390 }
324 391
325 392
326 -/***********************************************************************//**  
327 - * @brief Clone instance  
328 - ***************************************************************************/  
329 -void GWcsCAR::wcsxy2sph(const double& x, const double& y, double* lon, double* lat) const  
330 -{  
331 -}  
332 -void GWcsCAR::wcssph2xy(const double& lon, const double& lat, double* x, double* y) const  
333 -{  
334 -}  
335 -  
336 -  
337 /*========================================================================== 393 /*==========================================================================
338 = = 394 = =
339 = GWcsCAR friends = 395 = GWcsCAR friends =
@@ -350,7 +406,9 @@ std::ostream&amp; operator&lt;&lt; (std::ostream&amp; os, const GWcsCAR&amp; wcs) @@ -350,7 +406,9 @@ std::ostream&amp; operator&lt;&lt; (std::ostream&amp; os, const GWcsCAR&amp; wcs)
350 { 406 {
351 // Put header in stream 407 // Put header in stream
352 os << "=== GWcsCAR ===" << std::endl; 408 os << "=== GWcsCAR ===" << std::endl;
353 - os << " Coordinate system .........: " << wcs.coordsys(); 409 +
  410 + // Add WCS information
  411 + wcs.dump_wcs(os);
354 412
355 // Return output stream 413 // Return output stream
356 return os; 414 return os;