GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GHealpix.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GHealpix.hpp - Healpix projection class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2010-2020 by Juergen Knoedlseder *
5  * ----------------------------------------------------------------------- *
6  * *
7  * This program is free software: you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19  * *
20  ***************************************************************************/
21 /**
22  * @file GHealpix.hpp
23  * @brief HealPix projection class definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GHEALPIX_HPP
28 #define GHEALPIX_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include "GSkyProjection.hpp"
32 #include "GFitsHDU.hpp"
33 #include "GSkyDir.hpp"
34 #include "GSkyPixel.hpp"
35 #include "GBilinear.hpp"
36 
37 /* __ Forward declarations _______________________________________________ */
38 class GSkyDirs;
39 
40 
41 /***********************************************************************//**
42  * @class GHealpix
43  *
44  * @brief HealPix projection class interface definition
45  *
46  * The HealPix projection class has been implemented by adapting code from
47  * the HealPix library (version 2.1). For more information about HEALPix, see
48  * http://healpix.jpl.nasa.gov
49  ***************************************************************************/
50 class GHealpix : public GSkyProjection {
51 
52 public:
53  // Constructors and destructors
54  GHealpix(void);
55  GHealpix(const int& nside,
56  const std::string& ordering = "NESTED",
57  const std::string& coordsys = "CEL");
58  explicit GHealpix(const GFitsHDU& hdu);
59  GHealpix(const GHealpix& wcs);
60  virtual ~GHealpix(void);
61 
62  // Operators
63  GHealpix& operator=(const GHealpix& wcs);
64 
65  // Implemented pure virtual base class methods
66  virtual void clear(void);
67  virtual GHealpix* clone(void) const;
68  virtual std::string classname(void) const;
69  virtual int size(void) const;
70  virtual std::string code(void) const;
71  virtual std::string name(void) const;
72  virtual void read(const GFitsHDU& hdu);
73  virtual void write(GFitsHDU& hdu) const;
74  virtual double solidangle(const GSkyPixel& pixel) const;
75  virtual GSkyDir pix2dir(const GSkyPixel& pixel) const;
76  virtual GSkyPixel dir2pix(const GSkyDir& dir) const;
77  virtual GBilinear interpolator(const GSkyDir& dir) const;
78  virtual std::string print(const GChatter& chatter = NORMAL) const;
79 
80  // Other methods
81  const int& npix(void) const;
82  const int& nside(void) const;
83  std::string ordering(void) const;
84  void ordering(const std::string& ordering);
85  std::vector<int> neighbours(const GSkyPixel& pixel) const;
86  GSkyDirs boundaries(const GSkyPixel& pixel, const int& step = 1) const;
87  double max_pixrad(void) const;
88 
89 private:
90  // Private methods
91  void init_members(void);
92  void copy_members(const GHealpix& wcs);
93  void free_members(void);
94  virtual bool compare(const GSkyProjection& proj) const;
95 
96  // Low-level HealPix methods
97  int compress_bits(const int& value) const;
98  int spread_bits(const int& value) const;
99  void pix2xyf(const int& pix, int* ix, int* iy, int* face) const;
100  void nest2xyf(const int& pix, int* ix, int* iy, int* face) const;
101  void ring2xyf(const int& pix, int* ix, int* iy, int* face) const;
102  int xyf2nest(const int& ix, const int& iy, const int& face) const;
103  int xyf2ring(const int& ix, const int& iy, const int& face) const;
104  void xyf2loc(const double& x, const double& y, const int& face,
105  double* z, double* phi) const;
106  int nside2order(const int& nside) const;
107  int nest2ring(const int& pix) const;
108  int ring2nest(const int& pix) const;
109  void pix2xy(const int& ipix, int* x, int* y) const;
110  int xy2pix(int x, int y) const;
111  void pix2ang_ring(int ipix, double* theta, double* phi) const;
112  void pix2ang_nest(int ipix, double* theta, double* phi) const;
113  int ang2pix_z_phi_ring(double z, double phi) const;
114  int ang2pix_z_phi_nest(double z, double phi) const;
115  int ring_above(const double& z) const;
116  void get_ring_info(const int& ring, int* startpix, int* ringpix,
117  bool* shifted) const;
118  void get_ring_info(const int& ring, int* startpix, int* ringpix,
119  double* theta, bool* shifted) const;
120  GBilinear interpolator(const double& theta, const double& phi) const;
121  unsigned int isqrt(unsigned int arg) const;
122  GVector set_z_phi(const double& z, const double& phi) const;
123  GSkyDir loc2dir(const double& z, const double& phi) const;
124 
125  // Private data area
126  int m_nside; //!< Number of divisions of each base pixel (1-8192)
127  int m_npface; //!<
128  int m_ncap; //!< Number of pixels in polar cap
129  int m_order; //!< Order
130  int m_ordering; //!< Pixel ordering (0=ring, 1=nested, -1=?)
131  int m_num_pixels; //!< Number of pixels in projection
132  double m_fact1; //!<
133  double m_fact2; //!<
134  double m_solidangle; //!< Solid angle of pixel
135 };
136 
137 
138 /***********************************************************************//**
139  * @brief Return class name
140  *
141  * @return String containing the class name ("GHealpix").
142  ***************************************************************************/
143 inline
144 std::string GHealpix::classname(void) const
145 {
146  return ("GHealpix");
147 }
148 
149 
150 /***********************************************************************//**
151  * @brief Return dimension of projection
152  *
153  * @return Dimension of projection.
154  *
155  * Returns the dimension of the projection.
156  ***************************************************************************/
157 inline
158 int GHealpix::size(void) const
159 {
160  return 1;
161 }
162 
163 
164 /***********************************************************************//**
165  * @brief Return projection code
166  *
167  * @return Projection code.
168  *
169  * Returns the projection code "HPX".
170  ***************************************************************************/
171 inline
172 std::string GHealpix::code(void) const
173 {
174  return "HPX";
175 }
176 
177 
178 /***********************************************************************//**
179  * @brief Return projection name
180  *
181  * @return Projection name.
182  *
183  * Returns the projection name.
184  ***************************************************************************/
185 inline
186 std::string GHealpix::name(void) const
187 {
188  return "HealPix";
189 }
190 
191 
192 /***********************************************************************//**
193  * @brief Returns number of pixels
194  ***************************************************************************/
195 inline
196 const int& GHealpix::npix(void) const
197 {
198  // Return number of pixels
199  return m_num_pixels;
200 }
201 
202 
203 /***********************************************************************//**
204  * @brief Returns number of divisions of the side of each base pixel.
205  ***************************************************************************/
206 inline
207 const int& GHealpix::nside(void) const
208 {
209  return m_nside;
210 }
211 
212 
213 /***********************************************************************//**
214  * @brief Returns solid angle of pixel
215  *
216  * @param[in] pixel Sky pixel.
217  * @return Solid angle of pixel.
218  *
219  * Returns the solid angle of the specified @p pixel. Note that HEALPix
220  * pixels have all the same solid angle, hence the @p pixel argument is in
221  * fact not used by the method.
222  ***************************************************************************/
223 inline
224 double GHealpix::solidangle(const GSkyPixel& pixel) const
225 {
226  return m_solidangle;
227 }
228 
229 #endif /* GHEALPIX_HPP */
virtual std::string classname(void) const
Return class name.
Definition: GHealpix.hpp:144
double m_solidangle
Solid angle of pixel.
Definition: GHealpix.hpp:134
GSkyDirs boundaries(const GSkyPixel &pixel, const int &step=1) const
Return pixel boundaries.
Definition: GHealpix.cpp:711
void nest2xyf(const int &pix, int *ix, int *iy, int *face) const
Convert pixel number in nested scheme to (x,y,face) tuple.
Definition: GHealpix.cpp:1021
void init_members(void)
Initialise class members.
Definition: GHealpix.cpp:846
virtual void clear(void)
Clear object.
Definition: GHealpix.cpp:255
GHealpix(void)
Void constructor.
Definition: GHealpix.cpp:103
double m_fact1
Definition: GHealpix.hpp:132
const int & nside(void) const
Returns number of divisions of the side of each base pixel.
Definition: GHealpix.hpp:207
std::vector< int > neighbours(const GSkyPixel &pixel) const
Return neighbouring pixels of a pixel.
Definition: GHealpix.cpp:579
void copy_members(const GHealpix &wcs)
Copy class members.
Definition: GHealpix.cpp:879
GHealpix & operator=(const GHealpix &wcs)
Assignment operator.
Definition: GHealpix.cpp:220
Sky direction class interface definition.
Abstract FITS extension base class.
Definition: GFitsHDU.hpp:51
virtual GSkyPixel dir2pix(const GSkyDir &dir) const
Returns sky map pixel of sky coordinate.
Definition: GHealpix.cpp:433
int m_order
Order.
Definition: GHealpix.hpp:129
virtual void read(const GFitsHDU &hdu)
Read Healpix definition from FITS header.
Definition: GHealpix.cpp:287
int m_nside
Number of divisions of each base pixel (1-8192)
Definition: GHealpix.hpp:126
unsigned int isqrt(unsigned int arg) const
Integer n that fulfills n*n &lt;= arg &lt; (n+1)*(n+1)
Definition: GHealpix.cpp:1893
double max_pixrad(void) const
Return maximum angular distance between pixel centre and corners.
Definition: GHealpix.cpp:778
virtual GBilinear interpolator(const GSkyDir &dir) const
Return interpolator for given sky direction.
Definition: GHealpix.cpp:474
virtual std::string print(const GChatter &chatter=NORMAL) const
Print WCS information.
Definition: GHealpix.cpp:802
void pix2ang_ring(int ipix, double *theta, double *phi) const
Convert pixel index to (theta,phi) angles for ring ordering.
Definition: GHealpix.cpp:1402
double m_fact2
Definition: GHealpix.hpp:133
void ring2xyf(const int &pix, int *ix, int *iy, int *face) const
Convert pixel number in ring scheme to (x,y,face) tuple.
Definition: GHealpix.cpp:1049
void get_ring_info(const int &ring, int *startpix, int *ringpix, bool *shifted) const
Returns useful information about a given ring of the projection.
Definition: GHealpix.cpp:1674
Abstract sky projection base class definition.
int nside2order(const int &nside) const
Convert nside to order.
Definition: GHealpix.cpp:1268
int m_ordering
Pixel ordering (0=ring, 1=nested, -1=?)
Definition: GHealpix.hpp:130
int xyf2ring(const int &ix, const int &iy, const int &face) const
Convert (x,y,face) tuple to pixel number in ring scheme.
Definition: GHealpix.cpp:1148
void pix2ang_nest(int ipix, double *theta, double *phi) const
Convert pixel index to (theta,phi) angles for nested ordering.
Definition: GHealpix.cpp:1453
int m_ncap
Number of pixels in polar cap.
Definition: GHealpix.hpp:128
Abstract FITS extension base class definition.
Sky map pixel class.
Definition: GSkyPixel.hpp:74
virtual GSkyDir pix2dir(const GSkyPixel &pixel) const
Returns sky direction of pixel.
Definition: GHealpix.cpp:384
HealPix projection class interface definition.
Definition: GHealpix.hpp:50
int spread_bits(const int &value) const
Spread Bits.
Definition: GHealpix.cpp:972
int ang2pix_z_phi_nest(double z, double phi) const
Returns pixel which contains angular coordinates (z,phi)
Definition: GHealpix.cpp:1568
GVector set_z_phi(const double &z, const double &phi) const
Return 3D vector.
Definition: GHealpix.cpp:1910
Bilinear interpolator class.
Definition: GBilinear.hpp:40
virtual double solidangle(const GSkyPixel &pixel) const
Returns solid angle of pixel.
Definition: GHealpix.hpp:224
int ring2nest(const int &pix) const
Converts pixel number in ring indexing scheme to nested scheme.
Definition: GHealpix.cpp:1335
virtual std::string name(void) const
Return projection name.
Definition: GHealpix.hpp:186
void pix2xy(const int &ipix, int *x, int *y) const
Convert pixel index to (x,y) coordinate.
Definition: GHealpix.cpp:1364
GChatter
Definition: GTypemaps.hpp:33
int compress_bits(const int &value) const
Compress Bits.
Definition: GHealpix.cpp:952
const int & npix(void) const
Returns number of pixels.
Definition: GHealpix.hpp:196
int nest2ring(const int &pix) const
Converts pixel number in nested indexing scheme to ring scheme.
Definition: GHealpix.cpp:1301
int xyf2nest(const int &ix, const int &iy, const int &face) const
Convert (x,y,face) tuple to pixel number in nested scheme.
Definition: GHealpix.cpp:1126
virtual std::string coordsys(void) const
Returns coordinate system.
int xy2pix(int x, int y) const
Convert (x,y) coordinate to pixel.
Definition: GHealpix.cpp:1385
virtual bool compare(const GSkyProjection &proj) const
Returns true if argument is identical.
Definition: GHealpix.cpp:914
GSkyDir loc2dir(const double &z, const double &phi) const
Convert local coordinate into sky direction.
Definition: GHealpix.cpp:1237
int ang2pix_z_phi_ring(double z, double phi) const
Returns pixel which contains angular coordinates (z,phi)
Definition: GHealpix.cpp:1520
void xyf2loc(const double &x, const double &y, const int &face, double *z, double *phi) const
Convert (x,y,f) tuple into local coordinates.
Definition: GHealpix.cpp:1189
int m_npface
Definition: GHealpix.hpp:127
Bilinear interpolator class interface definition.
std::string ordering(void) const
Returns ordering parameter.
Definition: GHealpix.cpp:511
virtual ~GHealpix(void)
Destructor.
Definition: GHealpix.cpp:198
void pix2xyf(const int &pix, int *ix, int *iy, int *face) const
Convert pixel number in to (x,y,face) tuple.
Definition: GHealpix.cpp:993
Vector class.
Definition: GVector.hpp:46
virtual std::string code(void) const
Return projection code.
Definition: GHealpix.hpp:172
Abstract sky projection base class.
int m_num_pixels
Number of pixels in projection.
Definition: GHealpix.hpp:131
virtual GHealpix * clone(void) const
Clone instance.
Definition: GHealpix.cpp:273
int ring_above(const double &z) const
Get ring index north of cos(theta)
Definition: GHealpix.cpp:1636
virtual void write(GFitsHDU &hdu) const
Write Healpix definition into FITS HDU.
Definition: GHealpix.cpp:356
Sky map pixel class definition.
Sky direction class.
Definition: GSkyDir.hpp:62
virtual int size(void) const
Return dimension of projection.
Definition: GHealpix.hpp:158
void free_members(void)
Delete class members.
Definition: GHealpix.cpp:900
Sky directions container class.
Definition: GSkyDirs.hpp:49