00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef HEALPIX_BASE2_H
00033 #define HEALPIX_BASE2_H
00034
00035 #include "healpix_base.h"
00036 #include "datatypes.h"
00037
00038
00039
00040 class Healpix_Base2
00041 {
00042 protected:
00043 enum { order_max=29 };
00044
00045 class Tablefiller
00046 {
00047 public:
00048 Tablefiller();
00049 };
00050 static Tablefiller Filler;
00051 friend class Tablefiller;
00052
00053 static short ctab[0x100], utab[0x100];
00054
00055 static const int jrll[];
00056 static const int jpll[];
00057
00058
00059 int order_;
00060
00061 int64 nside_;
00062 int64 npface_, ncap_, npix_;
00063 double fact1_, fact2_;
00064
00065 Healpix_Ordering_Scheme scheme_;
00066
00067 inline int64 ring_above (double z) const;
00068 void in_ring (int64 iz, double phi0, double dphi,
00069 std::vector<int64> &listir) const;
00070
00071 int64 xyf2nest(int ix, int iy, int face_num) const;
00072 void nest2xyf(int64 pix, int &ix, int &iy, int &face_num) const;
00073 int64 xyf2ring(int ix, int iy, int face_num) const;
00074 void ring2xyf(int64 pix, int &ix, int &iy, int &face_num) const;
00075
00076 typedef int64 (Healpix_Base2::*swapfunc)(int64 pix) const;
00077 typedef void (Healpix_Base2::*pix2xyf)
00078 (int64 pix, int &x, int &y, int &f) const;
00079 typedef int64 (Healpix_Base2::*xyf2pix) (int x, int y, int f) const;
00080
00081 public:
00082
00083
00084
00085 static int nside2order (int64 nside)
00086 {
00087 planck_assert (nside>0, "invalid value for Nside");
00088 if ((nside)&(nside-1)) return -1;
00089 return ilog2(nside);
00090 }
00091
00092
00093 static int64 npix2nside (int64 npix);
00094
00095 Healpix_Base2 ()
00096 : order_(-1), nside_(0), npface_(0), ncap_(0), npix_(0),
00097 fact1_(0), fact2_(0), scheme_(RING) {}
00098
00099
00100 Healpix_Base2 (int order, Healpix_Ordering_Scheme scheme)
00101 { Set (order, scheme); }
00102
00103
00104
00105 Healpix_Base2 (int64 nside, Healpix_Ordering_Scheme scheme,
00106 const nside_dummy)
00107 { SetNside (nside, scheme); }
00108
00109
00110 void Set (int order, Healpix_Ordering_Scheme scheme)
00111 {
00112 planck_assert ((order>=0)&&(order<=order_max), "bad order");
00113 order_ = order;
00114 nside_ = int64(1)<<order;
00115 npface_ = nside_<<order_;
00116 ncap_ = (npface_-nside_)<<1;
00117 npix_ = 12*npface_;
00118 fact2_ = 4./npix_;
00119 fact1_ = (nside_<<1)*fact2_;
00120 scheme_ = scheme;
00121 }
00122
00123 void SetNside (int64 nside, Healpix_Ordering_Scheme scheme)
00124 {
00125 order_ = nside2order(nside);
00126 planck_assert ((scheme!=NEST) || (order_>=0),
00127 "SetNside: nside must be power of 2 for nested maps");
00128 nside_ = nside;
00129 npface_ = nside_*nside_;
00130 ncap_ = (npface_-nside_)<<1;
00131 npix_ = 12*npface_;
00132 fact2_ = 4./npix_;
00133 fact1_ = (nside_<<1)*fact2_;
00134 scheme_ = scheme;
00135 }
00136
00137
00138
00139 double ring2z (int64 ring) const;
00140
00141 int64 pix2ring (int64 pix) const;
00142
00143
00144 int64 nest2ring (int64 pix) const;
00145
00146 int64 ring2nest (int64 pix) const;
00147
00148 int64 nest2peano (int64 pix) const;
00149
00150 int64 peano2nest (int64 pix) const;
00151
00152 int64 ang2pix_z_phi (double z, double phi) const;
00153
00154
00155
00156 int64 ang2pix (const pointing &ang) const
00157 { return ang2pix_z_phi (cos(ang.theta), ang.phi); }
00158
00159
00160 int64 vec2pix (const vec3 &vec) const
00161 { return ang2pix_z_phi (vec.z/vec.Length(), safe_atan2(vec.y,vec.x)); }
00162
00163 void pix2ang_z_phi (int64 pix, double &z, double &phi) const;
00164
00165
00166
00167 pointing pix2ang (int64 pix) const
00168 {
00169 double z, phi;
00170 pix2ang_z_phi (pix,z,phi);
00171 return pointing(acos(z),phi);
00172 }
00173
00174 vec3 pix2vec (int64 pix) const
00175 {
00176 double z, phi;
00177 pix2ang_z_phi (pix,z,phi);
00178 vec3 res;
00179 res.set_z_phi (z, phi);
00180 return res;
00181 }
00182
00183
00184
00185
00186
00187
00188
00189
00190 void query_disc (const pointing &dir, double radius,
00191 std::vector<int64> &listpix) const;
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202 void query_disc_inclusive (const pointing &dir, double radius,
00203 std::vector<int64> &listpix) const
00204 { query_disc (dir,radius+1.362*pi/(4*nside_),listpix); }
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214 void get_ring_info (int64 ring, int64 &startpix, int64 &ringpix,
00215 double &costheta, double &sintheta, bool &shifted) const;
00216
00217
00218
00219
00220
00221
00222
00223 void get_ring_info2 (int64 ring, int64 &startpix, int64 &ringpix,
00224 double &theta, bool &shifted) const;
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234 void neighbors (int64 pix, fix_arr<int64,8> &result) const;
00235
00236
00237
00238
00239
00240 void get_interpol (const pointing &ptg, fix_arr<int64,4> &pix,
00241 fix_arr<double,4> &wgt) const;
00242
00243
00244 int Order() const { return order_; }
00245
00246 int64 Nside() const { return nside_; }
00247
00248 int64 Npix() const { return npix_; }
00249
00250 Healpix_Ordering_Scheme Scheme() const { return scheme_; }
00251
00252
00253
00254 bool conformable (const Healpix_Base2 &other) const
00255 { return ((nside_==other.nside_) && (scheme_==other.scheme_)); }
00256
00257
00258 void swap (Healpix_Base2 &other)
00259 {
00260 std::swap(order_,other.order_);
00261 std::swap(nside_,other.nside_);
00262 std::swap(npface_,other.npface_);
00263 std::swap(ncap_,other.ncap_);
00264 std::swap(npix_,other.npix_);
00265 std::swap(fact1_,other.fact1_);
00266 std::swap(fact2_,other.fact2_);
00267 std::swap(scheme_,other.scheme_);
00268 }
00269
00270
00271
00272 double max_pixrad() const;
00273 };
00274
00275 #endif