H3C HEALPix library for PostgreSQL  (version 1.2)
h3cpp_healpix.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 Gilles Landais (CDS)
3 
4  Author: Gilles Landais, Strasbourg astronomical Data Center (CDS)
5  Email: gilles.landais@unistra.fr
6 
7  This file is part of H3C.
8 
9  H3C is free software; you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13 
14  H3C is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with H3C; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23 
30 /* Local Includes */
31 #include "healpix_base.h"
32 #include "common.h"
33 #include "h3c_util.h"
34 #include "h3cpp_healpix.h"
35 
36 
37 /*****************************************************************************/
48 /*****************************************************************************/
49 h3c_ipix_t *h3cpp_disk_ipix(h3c_coord_t ra,
50  h3c_coord_t dec,
51  double radius,
52  int nside,
53  int *nresult,
54  int inclusive)
55 {
56  int i,order;
57  pointing ptg;
58 #ifdef H3C_INT8
59  vector<int64> list;
60 #else
61  vector<int> list;
62 #endif
63 
64  h3c_ipix_t *retlist = NULL;
65  *nresult = 0;
66 
67  ptg.theta = h3c_dec2theta(dec*H3C_DEGRA);
68  ptg.phi = h3c_ra2phi(ra*H3C_DEGRA);
69  order = h3c_order(nside);
70 
71 #ifdef H3C_INT8
72 #if 0
73  T_Healpix_Base<int64> healpix(order, NEST);
74 #else
75  T_Healpix_Base<int64> healpix(order, RING);
76 #endif
77 #else
78 #if 0
79  Healpix_Base healpix(order, NEST);
80 #else
81  Healpix_Base healpix(order, RING);
82 #endif
83 #endif
84 
85  if (inclusive)
86  healpix.query_disc_inclusive(ptg,radius*H3C_DEGRA,list);
87  else
88  healpix.query_disc(ptg,radius*H3C_DEGRA,list);
89 
90  if (list.size() > 0 && list.size() < H3C_DEFAULT_MAX_IPIX) {
91  retlist = (h3c_ipix_t*)malloc(sizeof(h3c_ipix_t)*(list.size()));
92  for (i = 0; i < list.size(); i++)
93 #if 0
94  retlist[i] = list[i];
95 #else
96  retlist[i] = healpix.ring2nest(list[i]);
97 #endif
98  }
99  else h3c_log(H3C_INFO, "too much ipix %d>%d", list.size(), H3C_DEFAULT_MAX_IPIX);
100 
101  *nresult = list.size();
102  list.clear();
103  return retlist;
104 }
105 
106 /*****************************************************************************/
111 /*****************************************************************************/
112 int h3cpp_number_ipix(int nside) {
113  int order = h3c_order(nside);
114 
115 #ifdef H3C_INT8
116  T_Healpix_Base<int64> healpix(order, RING);
117 #else
118  Healpix_Base healpix(order, RING);
119 #endif
120 
121  return healpix.Npix();
122 }
123 
124 /*****************************************************************************/
129 /*****************************************************************************/
130 h3c_coord_t h3cpp_radius(int nside) {
131  int order = h3c_order(nside);
132 
133 #ifdef H3C_INT8
134  T_Healpix_Base<int64> healpix(order, RING);
135 #else
136  Healpix_Base healpix(order, RING);
137 #endif
138  return healpix.max_pixrad()*H3C_RADEG;
139 }
140 
141 /*****************************************************************************/
147 /*****************************************************************************/
148 h3c_ipix_t *h3cpp_get_neighbors(h3c_ipix_t ipix, int nside) {
149  static h3c_ipix_t neighbors[8];
150  int i,order = h3c_order(nside);
151 
152 #ifdef H3C_INT8
153  T_Healpix_Base<int64> healpix(order, NEST);
154  fix_arr < int64, 8 > result;
155 #else
156  Healpix_Base healpix(order, NEST);
157  fix_arr < int, 8 > result;
158 #endif
159  healpix.neighbors(ipix, result);
160  for (i = 0; i < 8; i++) neighbors[i] = result[i];
161  return neighbors;
162 }
163 
164 /*****************************************************************************/
165 /* @brief pixel (in NEST) to angle (theta,phi)
166  * @param nside the nside level
167  * @param ipnest ipix (NEST)
168  * @param theta angle (OUT))
169  * @param phi angle (OUT)
170  */
171 /*****************************************************************************/
172 void h3cpp_pix2ang_nest(long nside,
173  h3c_ipix_t ipnest,
174  h3c_coord_t *theta,
175  h3c_coord_t *phi){
176  int order = h3c_order(nside);
177 #ifdef H3C_INT8
178  T_Healpix_Base<int64> healpix(order, NEST);
179 #else
180  Healpix_Base healpix(order, NEST);
181 #endif
182  pointing ptg;
183 
184  ptg = healpix.pix2ang(ipnest);
185  *theta = ptg.theta;
186  *phi = ptg.phi;
187 }
188 
189 /*****************************************************************************/
190 /* @brief angle (theta,phi) to ipix (NEST)
191  * @param nside the nside level
192  * @param theta angle (OUT))
193  * @param phi angle (OUT)
194  * @param ipnest ipix (NEST)
195  */
196 /*****************************************************************************/
197 void h3cpp_ang2pix_nest(long nside,
198  h3c_coord_t theta,
199  h3c_coord_t phi,
200  h3c_ipix_t *ipnest){
201  int order = h3c_order(nside);
202 #ifdef H3C_INT8
203  T_Healpix_Base<int64> healpix(order, NEST);
204 #else
205  Healpix_Base healpix(order, NEST);
206 #endif
207  pointing ptg;
208  ptg.theta = theta;
209  ptg.phi = phi;
210 
211  *ipnest = healpix.ang2pix(ptg);
212 }
213 
214 /*****************************************************************************/
219 /*****************************************************************************/
220 void h3cpp_ring2nest(long nside,
221  h3c_ipix_t ipring,
222  h3c_ipix_t *ipnest){
223  int order = h3c_order(nside);
224 #ifdef H3C_INT8
225  T_Healpix_Base<int64> healpix(order, NEST);
226 #else
227  Healpix_Base healpix(order, NEST);
228 #endif
229 
230  *ipnest = healpix.ring2nest(ipring);
231 }
232 
h3cpp_number_ipix
int h3cpp_number_ipix(int nside)
get the number of ipix for a given nside
Definition: h3cpp_healpix.cc:112
h3cpp_radius
h3c_coord_t h3cpp_radius(int nside)
get the max radius of the circles arround the ipix for a given nside
Definition: h3cpp_healpix.cc:130
h3c_log
void h3c_log(int level, char *fmt,...)
print statistics
Definition: h3c_util.c:57
h3c_ra2phi
h3c_coord_t h3c_ra2phi(h3c_coord_t ra)
get the phi value from the right ascension
Definition: h3c_util.c:161
h3c_dec2theta
h3c_coord_t h3c_dec2theta(h3c_coord_t dec)
get the theta value from the declination
Definition: h3c_util.c:136
h3cpp_disk_ipix
h3c_ipix_t * h3cpp_disk_ipix(h3c_coord_t ra, h3c_coord_t dec, double radius, int nside, int *nresult, int inclusive)
retrieve the ipix list for a cone
Definition: h3cpp_healpix.cc:49
h3cpp_ring2nest
void h3cpp_ring2nest(long nside, h3c_ipix_t ipring, h3c_ipix_t *ipnest)
transform ipix (RING) to ipix (NEST)
Definition: h3cpp_healpix.cc:220
h3cpp_get_neighbors
h3c_ipix_t * h3cpp_get_neighbors(h3c_ipix_t ipix, int nside)
get ipix neighbors
Definition: h3cpp_healpix.cc:148
h3cpp_healpix.h
Interface the Healpix C++ library.
h3c_order
int h3c_order(int nside)
get the order from the nside number
Definition: h3c_util.c:173
common.h
h3c_util.h
usefull functions in the library heaplix for PostgreSQL