healpixmap.h

Go to the documentation of this file.
00001 #ifndef HEALPIXMAP_HPP
00002 #define HEALPIXMAP_HPP
00003 /* ============================================================================
00004 'healpixmap.h' extends the Skymap class to support HEALPIX maps.  The non-
00005 inline methods are defined in 'healpixmap.cpp'.
00006 
00007 Written by Michael R. Greason, ADNET, 29 December 2006.
00008 ============================================================================ */
00009 #include <math.h>
00010 #include "skymap.h"
00011 
00012 class ControlDialog;
00013 /* =============================================================================
00014 The HealpixMap class defines a skymap that uses the HEALPIX pixelization scheme.
00015 ============================================================================= */
00016 class HealpixMap : public Skymap
00017 {
00018         public:
00019                 enum PixOrder {
00020                         Undefined,                              // Hasn't been set.
00021                         Nested,                                 // Nested pixel ordering.
00022                         Ring                                    // Ring pixel ordering.
00023                 };
00024 
00025                 // Healpix utilities.
00026                 static unsigned int NSide2NPix (unsigned int ns);
00027                 static unsigned int NPix2NSide (unsigned int np);
00028                 static unsigned int Res2NSide  (unsigned int res);
00029                 static unsigned int Res2NPix   (unsigned int res);
00030                 static unsigned int NSide2Res  (unsigned int ns);
00031                 static unsigned int NPix2Res   (unsigned int np);
00032         protected:
00033                 PixOrder     ordering_;         // Pixel ordering scheme.
00034                 unsigned int nside_;            // Map resolution parameter.
00035 
00036                 // Functions to read/write the FITS headers.
00037                 virtual void readFITSPrimaryHeader    (fitsfile *fptr);
00038                 virtual void writeFITSPrimaryHeader   (fitsfile *fptr);
00039                 virtual void readFITSExtensionHeader  (fitsfile *fptr);
00040                 virtual void writeFITSExtensionHeader (fitsfile *fptr);
00041 
00042                 unsigned int degrade_pixindex (unsigned int i, unsigned int nsi, unsigned int nso);
00043                 void degrade_map (unsigned int ns);
00044                 void upgrade_map (unsigned int ns);
00045         public:
00046                 // Constructors and destructor.
00047                 HealpixMap ();
00048                 HealpixMap (unsigned int n_in, Type type_in, PixOrder ord = Undefined);
00049                 virtual ~HealpixMap();
00050 
00051                 void copy (HealpixMap &imap);
00052 
00053                 // Return ordering and resolution.
00054                 unsigned int nside      () const { return nside_; }
00055                 PixOrder     pixordenum () const { return ordering_; }
00056                 unsigned int pixorder   () const { return ordering_; }
00057                 const char*  ordering   () const;
00058                 
00059                 // Pixel coordinate conversions.
00060                 void pixel2vector (long pix, double *vector);
00061                 void vector2pixel (double *vector, long &pix);
00062 
00063                 void pixel2angles (long pix, double &theta, double &phi, int deg = 0);
00064                 void angles2pixel (double theta, double phi, long &pix, int deg = 0);
00065                 
00066                 long pix2ordering (long ipix, PixOrder dord);
00067 
00068                 // Resize.
00069                 void resize (unsigned int ns);
00070                 
00071                 // Copy operator.
00072                 HealpixMap& operator= (HealpixMap &imap);
00073 
00074                 // Pixel access.
00075                 BasePixel& getPixel (double theta, double phi, int deg = 0);
00076                 BasePixel& getPixel (double *vector);
00077 
00078                 // FITS I/O.
00079                 /*
00080                 virtual void readFITS (const char* filename, fileProgress *progwin = NULL);
00081                 virtual void readFITS (std::string filename, fileProgress *progwin = NULL);
00082                 virtual void readFITS (QString filename, fileProgress *progwin = NULL);
00083                 */
00084                 // FITS I/O.
00085                 virtual void readFITS (const char* filename, ControlDialog *progwin = NULL);
00086                 virtual void readFITS (std::string filename, ControlDialog *progwin = NULL);
00087                 virtual void readFITS (QString filename, ControlDialog *progwin = NULL);
00088 };
00089 /* ----------------------------------------------------------------------------
00090 'NSide2NPix' computes the number of pixels from NSide.
00091 
00092 Static function.
00093 
00094 Arguments:
00095         ns - NSide.
00096 
00097 Returned:
00098         The number of pixels.
00099 ---------------------------------------------------------------------------- */
00100 inline unsigned int HealpixMap::NSide2NPix (unsigned int ns)
00101 {
00102         return 12 * ns * ns;
00103 }
00104 /* ----------------------------------------------------------------------------
00105 'NPix2NSide' computes the NSide parameter from a number of pixels.  It assumes
00106 that the math will work out evenly.
00107 
00108 Static function.
00109 
00110 Arguments:
00111         np - The number of pixels.
00112 
00113 Returned:
00114         NSide.
00115 ---------------------------------------------------------------------------- */
00116 inline unsigned int HealpixMap::NPix2NSide (unsigned int np)
00117 {
00118         return (unsigned int) (sqrt(double(np) / 12.0) + 0.4);
00119 }
00120 /* ----------------------------------------------------------------------------
00121 'Res2NSide' computes the number of pixels from NSide.
00122 
00123 Static function.
00124 
00125 Arguments:
00126         res - The map resolution.
00127 
00128 Returned:
00129         NSide.
00130 ---------------------------------------------------------------------------- */
00131 inline unsigned int HealpixMap::Res2NSide (unsigned int res)
00132 {
00133         unsigned int i = 1;
00134         return i << res;
00135 }
00136 /* ----------------------------------------------------------------------------
00137 'Res2NPix' computes the NSide parameter from a number of pixels.  It assumes
00138 that the math will work out evenly.
00139 
00140 Static function.
00141 
00142 Arguments:
00143         res - The map resolution.
00144 
00145 Returned:
00146         The number of pixels.
00147 ---------------------------------------------------------------------------- */
00148 inline unsigned int HealpixMap::Res2NPix (unsigned int res)
00149 {
00150         return NSide2NPix(Res2NSide(res));
00151 }
00152 /* ----------------------------------------------------------------------------
00153 'NSide2Res' computes the resolution from NSide.
00154 
00155 Static function.
00156 
00157 Arguments:
00158         ns - NSide.
00159 
00160 Returned:
00161         The map resolution.
00162 ---------------------------------------------------------------------------- */
00163 inline unsigned int HealpixMap::NSide2Res (unsigned int ns)
00164 {
00165         return (unsigned int) (0.4 + (log(double(ns)) / log(2.0)));
00166 }
00167 /* ----------------------------------------------------------------------------
00168 'NPix2Res' computes the resolution from the number of pixels.
00169 
00170 Static function.
00171 
00172 Arguments:
00173         np - The number of pixels.
00174 
00175 Returned:
00176         The map resolution.
00177 ---------------------------------------------------------------------------- */
00178 inline unsigned int HealpixMap::NPix2Res (unsigned int np)
00179 {
00180         return NSide2Res(NPix2NSide(np));
00181 }
00182 /* ----------------------------------------------------------------------------
00183 'operator=' copies another map into this one using the assignment operator.
00184 
00185 Arguments:
00186         imap - The source map.
00187 
00188 Returned:
00189         A reference to this map.
00190 ---------------------------------------------------------------------------- */
00191 inline HealpixMap& HealpixMap::operator= (HealpixMap &imap)
00192 {
00193         copy(imap);
00194         return *this;
00195 }
00196 #endif
00197 
00198 

Generated on Fri Feb 6 15:32:42 2009 for Skyviewer by  doxygen 1.4.7