Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

healpix_base.h

Go to the documentation of this file.
00001 /*
00002  *  This file is part of Healpix_cxx.
00003  *
00004  *  Healpix_cxx is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  Healpix_cxx is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with Healpix_cxx; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017  *
00018  *  For more information about HEALPix, see http://healpix.jpl.nasa.gov
00019  */
00020 
00021 /*
00022  *  Healpix_cxx is being developed at the Max-Planck-Institut fuer Astrophysik
00023  *  and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
00024  *  (DLR).
00025  */
00026 
00027 /*! \file healpix_base.h
00028  *  Copyright (C) 2003, 2004 Max-Planck-Society
00029  *  \author Martin Reinecke
00030  */
00031 
00032 #ifndef HEALPIX_BASE_H
00033 #define HEALPIX_BASE_H
00034 
00035 #include <vector>
00036 #include "constants.h"
00037 #include "pointing.h"
00038 template<typename T, unsigned int sz> class fix_arr;
00039 
00040 /*! The two possible ordering schemes of a HEALPix map. */
00041 typedef enum { RING, /*!< RING scheme */
00042                NEST  /*!< NESTED scheme */
00043              }  Healpix_Ordering_Scheme;
00044 
00045 class nside_dummy {};
00046 extern const nside_dummy SET_NSIDE;
00047 
00048 /*! Functionality related to the HEALPix pixelisation. */
00049 class Healpix_Base
00050   {
00051   protected:
00052     enum { order_max=13 };
00053 
00054     class Tablefiller
00055       {
00056       public:
00057         Tablefiller();
00058       };
00059     static Tablefiller Filler;
00060     friend class Tablefiller;
00061 
00062     static short ctab[0x100], utab[0x100];
00063 
00064     static const int jrll[];
00065     static const int jpll[];
00066 
00067     /*! The order of the map; -1 for nonhierarchical map. */
00068     int order_;
00069     /*! The N_side parameter of the map; 0 if not allocated. */
00070     int nside_;
00071     int npface_, ncap_, npix_;
00072     double fact1_, fact2_;
00073     /*! The map's ordering scheme. */
00074     Healpix_Ordering_Scheme scheme_;
00075 
00076     static inline int xy2pix (int x, int y);
00077     static inline int x2pix (int x);
00078     static inline int y2pix (int y);
00079     static inline void pix2xy (int pix, int &x, int &y);
00080 
00081     inline int ring_above (double z) const;
00082     void in_ring (int iz, double phi0, double dphi,
00083       std::vector<int> &listir) const;
00084 
00085     int xyf2nest(int ix, int iy, int face_num) const;
00086     void nest2xyf(int pix, int &ix, int &iy, int &face_num) const;
00087     int xyf2ring(int ix, int iy, int face_num) const;
00088     void ring2xyf(int pix, int &ix, int &iy, int &face_num) const;
00089 
00090     typedef int (Healpix_Base::*swapfunc)(int pix) const;
00091     typedef void (Healpix_Base::*pix2xyf)
00092                  (int pix, int &x, int &y, int &f) const;
00093     typedef int (Healpix_Base::*xyf2pix) (int x, int y, int f) const;
00094 
00095   public:
00096     /*! Calculates the map order from its \a N_side parameter.
00097         Returns -1 if \a nside is not a power of 2.
00098         \param nside the \a N_side parameter */
00099     static int nside2order (int nside);
00100     /*! Calculates the map order from its \a N_side parameter.
00101         \param nside the \a N_side parameter */
00102     static int npix2nside (int nside);
00103     /*! Constructs an unallocated object. */
00104     Healpix_Base ()
00105       : order_(-1), nside_(0), npface_(0), ncap_(0), npix_(0),
00106         fact1_(0), fact2_(0), scheme_(RING) {}
00107     /*! Constructs an object with a given \a order and the ordering
00108         scheme \a scheme. */
00109     Healpix_Base (int order, Healpix_Ordering_Scheme scheme)
00110       { Set (order, scheme); }
00111     /*! Constructs an object with a given \a nside and the ordering
00112         scheme \a scheme. The \a nside_dummy parameter must be set to
00113         SET_NSIDE. */
00114     Healpix_Base (int nside, Healpix_Ordering_Scheme scheme, const nside_dummy)
00115       { SetNside (nside, scheme); }
00116 
00117     /* Adjusts the object to \a order and \a scheme. */
00118     void Set (int order, Healpix_Ordering_Scheme scheme)
00119       {
00120       planck_assert ((order>=0)&&(order<=order_max), "bad order");
00121       order_  = order;
00122       nside_  = 1<<order;
00123       npface_ = nside_*nside_;
00124       ncap_   = 2*(npface_-nside_);
00125       npix_   = 12*npface_;
00126       fact2_  = 4./npix_;
00127       fact1_  = 2*nside_*fact2_;
00128       scheme_ = scheme;
00129       }
00130     /* Adjusts the object to \a nside and \a scheme. */
00131     void SetNside (int nside, Healpix_Ordering_Scheme scheme)
00132       {
00133       order_  = nside2order(nside);
00134       planck_assert ((scheme!=NEST) || (order_>0),
00135         "SetNside: nside must be power of 2 for nested maps");
00136       nside_  = nside;
00137       npface_ = nside_*nside_;
00138       ncap_   = 2*(npface_-nside_);
00139       npix_   = 12*npface_;
00140       fact2_  = 4./npix_;
00141       fact1_  = 2*nside_*fact2_;
00142       scheme_ = scheme;
00143       }
00144 
00145     /*! Translates a pixel number from NEST to RING. */
00146     int nest2ring (int pix) const;
00147     /*! Translates a pixel number from RING to NEST. */
00148     int ring2nest (int pix) const;
00149 
00150     int ang2pix_z_phi (double z, double phi) const;
00151 
00152     /*! Returns the number of the pixel which contains the angular coordinates
00153         \a ang. */
00154     int ang2pix (const pointing &ang) const
00155       { return ang2pix_z_phi (cos(ang.theta), ang.phi); }
00156     /*! Returns the number of the pixel which contains the vector \a vec
00157         (\a vec is normalized if necessary). */
00158     int vec2pix (const vec3 &vec) const
00159       { return ang2pix_z_phi (vec.z/vec.Length(), safe_atan2(vec.y,vec.x)); }
00160     /*! Returns the angular coordinates of the center of the pixel with
00161         number \a pix. */
00162     pointing pix2ang (int pix) const;
00163 
00164     /*! Returns the numbers of all pixels whose centers lie within \a radius
00165         of \a dir in \a listpix.
00166         \param dir the angular coordinates of the disc center
00167         \param radius the radius (in radians) of the disc
00168         \param listpix a vector containing the numbers of all pixels within
00169                the disc
00170         \note This method is more efficient in the RING scheme. */
00171     void query_disc (const pointing &dir, double radius,
00172       std::vector<int> &listpix) const;
00173     /*! Returns the numbers of all pixels that lie at least partially within
00174         \a radius of \a dir in \a listpix. It may also return a few pixels
00175         which do not lie in the disk at all.
00176         \param dir the angular coordinates of the disc center
00177         \param radius the radius (in radians) of the disc
00178         \param listpix a vector containing the numbers of all pixels within
00179                the disc
00180         \note This method works in both RING and NEST schemes, but is
00181           considerably faster in the RING scheme. */
00182     void query_disc_inclusive (const pointing &dir, double radius,
00183       std::vector<int> &listpix) const
00184 // FIXME: verify the factor 1.35
00185         { query_disc (dir,radius+1.35*pi/(4*nside_),listpix); }
00186     void query_strip (const pointing &dir, double theta1, double theta2,
00187       std::vector<int> &listpix) const;
00188 
00189     /*! Returns useful information about a given ring of the map.
00190         \param ring the ring number (the number of the first ring is 1)
00191         \param startpix the number of the first pixel in the ring
00192         \param ringpix the number of pixels in the ring
00193         \param costheta the cosine of the colatitude (in radians) of the ring
00194         \param sintheta the sine of the colatitude (in radians) of the ring
00195         \param shifted if \a true, the center of the first pixel is not at
00196                \a phi=0 */
00197     void get_ring_info (int ring, int &startpix, int &ringpix,
00198       double &costheta, double &sintheta, bool &shifted) const;
00199     /*! Returns useful information about a given ring of the map.
00200         \param ring the ring number (the number of the first ring is 1)
00201         \param startpix the number of the first pixel in the ring
00202         \param ringpix the number of pixels in the ring
00203         \param theta the colatitude (in radians) of the ring
00204         \param shifted if \a true, the center of the first pixel is not at
00205                \a phi=0 */
00206     void get_ring_info2 (int ring, int &startpix, int &ringpix,
00207       double &theta, bool &shifted) const;
00208 
00209     /*! Returns the neighboring pixels of \a pix in \a result.
00210         On exit, \a result contains (in this order)
00211         the pixel numbers of the SW, W, NW, N, NE, E, SE and S neighbor
00212         of \a pix. If a neighbor does not exist (this can only be the case
00213         for the W, N, E and S neighbors), its entry is set to -1.
00214 
00215         \note This method works in both RING and NEST schemes, but is
00216           considerably faster in the NEST scheme. */
00217     void neighbors (int pix, fix_arr<int,8> &result) const;
00218     /*! Returns interpolation information for the direction \a ptg.
00219         The surrounding pixels are returned in \a pix, their corresponding
00220         weights in \a wgt.
00221         \note This method works in both RING and NEST schemes, but is
00222           considerably faster in the NEST scheme. */
00223     void get_interpol (const pointing &ptg, fix_arr<int,4> &pix,
00224                        fix_arr<double,4> &wgt) const;
00225     /*! Returns interpolation information for the direction \a ptg.
00226         The surrounding pixels are returned in \a pix, their corresponding
00227         weights in \a wgt.
00228         \note This method works in both RING and NEST schemes, but is
00229           considerably faster in the RING scheme. */
00230     void get_interpol2 (const pointing &ptg, fix_arr<int,4> &pix,
00231                         fix_arr<double,4> &wgt) const;
00232 
00233     /*! Returns the order parameter of the object. */
00234     int Order() const { return order_; }
00235     /*! Returns the \a N_side parameter of the object. */
00236     int Nside() const { return nside_; }
00237     /*! Returns the number of pixels of the object. */
00238     int Npix() const { return npix_; }
00239     /*! Returns the ordering scheme of the object. */
00240     Healpix_Ordering_Scheme Scheme() const { return scheme_; }
00241 
00242     /*! Returns \a true, if both objects have the same nside and scheme,
00243         else  \a false. */
00244     bool conformable (const Healpix_Base &other) const
00245       { return ((nside_==other.nside_) && (scheme_==other.scheme_)); }
00246 
00247     /*! Swaps the contents of two Healpix_Base objects. */
00248     void swap (Healpix_Base &other)
00249       {
00250       std::swap(order_,other.order_);
00251       std::swap(nside_,other.nside_);
00252       std::swap(npface_,other.npface_);
00253       std::swap(ncap_,other.ncap_);
00254       std::swap(npix_,other.npix_);
00255       std::swap(fact1_,other.fact1_);
00256       std::swap(fact2_,other.fact2_);
00257       std::swap(scheme_,other.scheme_);
00258       }
00259   };
00260 
00261 #endif

Generated on Fri Jul 8 09:37:15 2005 for Healpix C++