2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2 of the License, or (at your option) any later version.
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 * Copyright (C) 2008 Liam Girdwood
21 #include <libastrodb/db.h>
22 #include <libastrodb/astro.h>
23 #include <libastrodb/table.h>
24 #include <libastrodb/adbstdio.h>
26 #define D2R (1.7453292519943295769e-2) /* deg->radian */
27 #define R2D (5.7295779513082320877e1) /* radian->deg */
29 /*! \fn int table_get_objects_mem(astrodb_table * table, astrodb_slist ** result)
30 * \brief Get objects from memory based on posn
32 int table_get_objects_mem(struct astrodb_table
*table
,
33 struct astrodb_slist
**result
)
35 int count
= 0, ra
, dec
, mag
, offset
;
38 for (ra
= table
->clip_min_ra
; ra
<= table
->clip_max_ra
; ra
++) {
40 for (dec
= table
->clip_min_dec
;
41 dec
<= table
->clip_max_dec
; dec
++) {
43 for (mag
= table
->clip_bright_mag
;
44 mag
<= table
->clip_faint_mag
; mag
++) {
46 offset
= table_calc_deep_offset(table
, ra
, dec
, mag
);
48 if (*(table
->objects
+ offset
)) {
49 *result
= astrodb_slist_prepend(*result
,
50 (char *) *(table
->objects
+ offset
));
51 count
+= (table
->status
+ offset
)->size
;
59 /*! \fn int table_get_objects_cache(astrodb_table * table, astrodb_slist ** result, astrodb_progress progress)
60 * \brief Get objects from memory based on posn
62 int table_get_objects_cache(struct astrodb_table
*table
,
63 struct astrodb_slist
**result
)
68 /*! \fn int table_get_objects_raw(astrodb_table * table, astrodb_slist ** result, astrodb_progress progress)
69 * \brief Get objects from memory based on posn
71 int table_get_objects_raw(struct astrodb_table
*table
,
72 struct astrodb_slist
**result
)
77 /*! \fn int table_get_objects_online(astrodb_table * table, astrodb_slist ** result, astrodb_progress progress)
78 * \brief Get objects from memory based on posn
80 int table_get_objects_online(struct astrodb_table
*table
,
81 struct astrodb_slist
**result
)
86 static inline void get_ra_bounds(struct astrodb_table
*table
, int theta
,
89 double dtheta
= theta
* D2R
;
90 *ra
= ceil(table
->clip_radius
* cos(dtheta
));
91 *dec
= ceil(table
->clip_radius
* sin(dtheta
));
94 static int append_region(struct astrodb_table
*table
,
95 struct astrodb_slist
**result
)
97 int ra
, dec
= table
->clip_min_dec
, mag
, count
= 0, offset
;
99 for (ra
= table
->clip_min_ra
; ra
<= table
->clip_max_ra
; ra
++) {
101 for (mag
= table
->clip_bright_mag
;
102 mag
<= table
->clip_faint_mag
; mag
++) {
104 offset
= table_calc_deep_offset(table
, ra
, dec
, mag
);
106 if (*(table
->objects
+ offset
) &&
107 (((table
->status
+ offset
)->flags
& ADB_SUSED
) == 0)) {
109 *result
= astrodb_slist_prepend(*result
,
110 (char *) *(table
->objects
+ offset
));
111 count
+= (table
->status
+ offset
)->size
;
112 (table
->status
+ offset
)->flags
|= ADB_SUSED
;
119 static int get_region(struct astrodb_table
*table
,
120 struct astrodb_slist
**result
,
121 int min_ra
, int max_ra
, int dec
)
125 table
->clip_min_dec
= (dec
+ 90) / table
->dec_stride_size
;
127 if (min_ra
>=0 && max_ra
<= 360) {
130 min_ra
-= table
->db
->ra_min
;
131 max_ra
-= table
->db
->ra_min
;
132 table
->clip_min_ra
= min_ra
/ table
->ra_stride_size
;
133 table
->clip_max_ra
= (max_ra
/ table
->ra_stride_size
) + 1;
134 count
= append_region(table
, result
);
136 } else if (min_ra
>=0 && max_ra
> 360) {
140 a
= min_ra
- table
->db
->ra_min
;
141 b
= 360 - table
->db
->ra_min
;
142 table
->clip_min_ra
= a
/ table
->ra_stride_size
;
143 table
->clip_max_ra
= (b
/ table
->ra_stride_size
) + 1;
144 count
= append_region(table
, result
);
146 a
= table
->db
->ra_min
- 0;
147 b
= (max_ra
- 360) - table
->db
->ra_min
;
148 table
->clip_min_ra
= a
/ table
->ra_stride_size
;
149 table
->clip_max_ra
= (b
/ table
->ra_stride_size
) + 1;
150 count
+= append_region(table
, result
);
151 } else if (min_ra
< 0 && max_ra
<= 360) {
155 a
= table
->db
->ra_min
- 0;
156 b
= max_ra
- table
->db
->ra_min
;
157 table
->clip_min_ra
= a
/ table
->ra_stride_size
;
158 table
->clip_max_ra
= (b
/ table
->ra_stride_size
) + 1;
159 count
= append_region(table
, result
);
161 a
= (360 + min_ra
) - table
->db
->ra_min
;
162 b
= 360 - table
->db
->ra_min
;
163 table
->clip_min_ra
= a
/ table
->ra_stride_size
;
164 table
->clip_max_ra
= (b
/ table
->ra_stride_size
) + 1;
165 count
+= append_region(table
, result
);
168 table
->clip_min_ra
= 0;
169 table
->clip_max_ra
= table
->ra_stride_size
;
170 count
= append_region(table
, result
);
176 /*! \fn int table_get_objects_memc(astrodb_table * table, astrodb_slist ** result)
177 * \brief Get objects from memory based on posn
179 int table_get_objects_memc_old(struct astrodb_table
*table
,
180 struct astrodb_slist
**result
)
183 int ra
, dec
, ra_min
, ra_max
, cdec
;
187 for(i
= 0; i
<= 90; i
++) {
188 get_ra_bounds(table
, i
, &ra
, &dec
);
189 cdec
= table
->clip_centre_dec
+ dec
+ 1;
193 ra
= ra
+ (ra
* fabs(tan(D2R
* cdec
)));
194 ra_max
= table
->clip_centre_ra
+ ra
;
195 ra_min
= table
->clip_centre_ra
- ra
;
209 count
+= get_region(table
, result
, ra_min
, ra_max
, cdec
);
212 get_ra_bounds(table
, i
, &ra
, &dec
);
213 cdec
= table
->clip_centre_dec
- dec
;
216 ra
= ra
+ (ra
* tan(D2R
* fabs(cdec
)));
217 ra_max
= table
->clip_centre_ra
+ ra
;
218 ra_min
= table
->clip_centre_ra
- ra
;
232 count
+= get_region(table
, result
, ra_min
, ra_max
, cdec
);
237 static inline void unit_vector(struct render
*r
, int i
)
239 gdouble ra
= r
->c
[i
].posn
->ra
* D2R
;
240 gdouble dec
= r
->c
[i
].posn
->dec
* D2R
;
242 r
->c
[i
].x
= cos(dec
) * sin(ra
);
243 r
->c
[i
].y
= sin(dec
);
244 r
->c
[i
].z
= cos(dec
) * cos(ra
);
248 /*! \fn int table_get_objects_memc(astrodb_table * table, astrodb_slist ** result)
249 * \brief Get objects from memory based on posn
251 int table_get_objects_memc(struct astrodb_table
*table
,
252 struct astrodb_slist
**result
)
254 int count
= 0, i
, ra
, dec
, ra_min
, ra_max
, cdec
;
258 for (i
= 0; i
<= 90; i
++) {
259 get_ra_bounds(table
, i
, &ra
, &dec
);
260 cdec
= table
->clip_centre_dec
+ dec
+ 1;
264 ra
= ra
+ (ra
* fabs(tan(D2R
* cdec
)));
265 ra_max
= table
->clip_centre_ra
+ ra
;
266 ra_min
= table
->clip_centre_ra
- ra
;
280 count
+= get_region(table
, result
, ra_min
, ra_max
, cdec
);
283 get_ra_bounds(table
, i
, &ra
, &dec
);
284 cdec
= table
->clip_centre_dec
- dec
;
287 ra
= ra
+ (ra
* tan(D2R
* fabs(cdec
)));
288 ra_max
= table
->clip_centre_ra
+ ra
;
289 ra_min
= table
->clip_centre_ra
- ra
;
303 count
+= get_region(table
, result
, ra_min
, ra_max
, cdec
);
308 /*! \fn int table_get_objects_cachec(astrodb_table * table, astrodb_slist ** result, astrodb_progress progress)
309 * \brief Get objects from memory based on posn
311 int table_get_objects_cachec(struct astrodb_table
*table
,
312 struct astrodb_slist
**result
)
317 /*! \fn int table_get_objects_rawc(astrodb_table * table, astrodb_slist ** result, astrodb_progress progress)
318 * \brief Get objects from memory based on posn
320 int table_get_objects_rawc(struct astrodb_table
*table
,
321 struct astrodb_slist
**result
)
326 /*! \fn int table_get_objects_onlinec(astrodb_table * table, astrodb_slist ** result, astrodb_progress progress)
327 * \brief Get objects from memory based on posn
329 int table_get_objects_onlinec(struct astrodb_table
*table
,
330 struct astrodb_slist
**result
)
336 /*! \fn int table_get_objects_cache_near(astrodb_table * table, astrodb_slist ** result)
337 * \brief Get objects from memory based on distance
339 int table_get_objects_cache_near(struct astrodb_table
*table
,
340 struct astrodb_slist
**result
)
345 for (ra
= table
->clip_min_ra
; ra
<= table
->clip_max_ra
; ra
++) {
347 if (*(table
->objects
+ ra
)) {
348 *result
= astrodb_slist_prepend(*result
,
349 (char *) *(table
->objects
+ ra
));
350 count
+= (table
->status
+ ra
)->size
;