summaryrefslogtreecommitdiffstats
path: root/ast/sphmap.h
blob: 905703bb48b094ee8afb4f5e3c7fa725b7563e6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
#if !defined( SPHMAP_INCLUDED ) /* Include this file only once */
#define SPHMAP_INCLUDED
/*
*+
*  Name:
*     sphmap.h

*  Type:
*     C include file.

*  Purpose:
*     Define the interface to the SphMap class.

*  Invocation:
*     #include "sphmap.h"

*  Description:
*     This include file defines the interface to the SphMap class and
*     provides the type definitions, function prototypes and macros,
*     etc.  needed to use this class.
*
*     The SphMap class implements Mappings which maps positions from
*     3-dimensional Cartesian coordinates into 2-dimensional spherical
*     coordinates (i.e. longitude and latitude on a unit sphere). The
*     inverse Mapping always produces vectors of unit length.
*
*     The spherical coordinates are longitude (positive anti-clockwise
*     looking from the positive latitude pole) and latitude. The
*     Cartesian coordinates are right-handed, with the x-axis (axis 1)
*     at zero longitude and latitude, and the z-axis (axis 3) at the
*     positive latitude pole.
*
*     At either pole, the longitude is set to the value of the PolarLong
*     attribute. If the Cartesian coordinates are all zero, then the
*     longitude and latitude values are set to AST__BAD.

*  Inheritance:
*     The SphMap class inherits from the Mapping class.

*  Attributes Over-Ridden:
*     None.

*  New Attributes Defined:
*     PolarLong (double)
*        This attribute holds the longitude value, in radians, to be
*        returned when a Cartesian position corresponding to either the north
*        or south pole is transformed into spherical coordinates. The
*        default value is zero.
*     UnitRadius (integer)
*        This is a boolean attribute which indicates whether the
*        3-dimensional vectors which are supplied as input to a SphMap
*        are known to always have unit length, so that they lie on a
*        unit sphere centred on the origin.
*
*        If this condition is true (indicated by setting UnitRadius
*        non-zero), it implies that a CmpMap which is composed of a
*        SphMap applied in the forward direction followed by a similar
*        SphMap applied in the inverse direction may be simplified
*        (e.g. by astSimplify) to become a UnitMap. This is because
*        the input and output vectors will both have unit length and
*        will therefore have the same coordinate values.
*
*        If UnitRadius is zero (the default), then although the output
*        vector produced by the CmpMap (above) will still have unit
*        length, the input vector may not have. This will, in general,
*        change the coordinate values, so it prevents the pair of
*        SphMaps being simplified.

*  Methods Over-Ridden:
*     Public:
*        None.
*
*     Protected:
*        astClearAttrib
*           Clear an attribute value for a SphMap.
*        astGetAttrib
*           Get an attribute value for a SphMap.
*        astMapMerge
*           Simplify a sequence of Mappings containing a SphMap.
*        astSetAttrib
*           Set an attribute value for a SphMap.
*        astTestAttrib
*           Test if an attribute value has been set for a SphMap.
*        astTransform
*           Apply a SphMap to transform a set of points.

*  New Methods Defined:
*     Public:
*        None.
*
*     Protected:
*        astClearUnitRadius
*           Clear the UnitRadius attribute value for a SphMap.
*        astGetUnitRadius
*           Get the UnitRadius attribute value for a SphMap.
*        astSetUnitRadius
*           Set the UnitRadius attribute value for a SphMap.
*        astTestUnitRadius
*           Test if a UnitRadius attribute value has been set for a SphMap.
*        astClearPolarLong
*           Clear the PolarLong attribute value for a SphMap.
*        astGetPolarLong
*           Get the PolarLong attribute value for a SphMap.
*        astSetPolarLong
*           Set the PolarLong attribute value for a SphMap.
*        astTestPolarLong
*           Test if a PolarLong attribute value has been set for a SphMap.

*  Other Class Functions:
*     Public:
*        astIsASphMap
*           Test class membership.
*        astSphMap
*           Create a SphMap.
*
*     Protected:
*        astCheckSphMap
*           Validate class membership.
*        astInitSphMap
*           Initialise a SphMap.
*        astInitSphMapVtab
*           Initialise the virtual function table for the SphMap class.
*        astLoadSphMap
*           Load a SphMap.

*  Macros:
*     None.

*  Type Definitions:
*     Public:
*        AstSphMap
*           SphMap object type.
*
*     Protected:
*        AstSphMapVtab
*           SphMap virtual function table type.

*  Feature Test Macros:
*     astCLASS
*        If the astCLASS macro is undefined, only public symbols are
*        made available, otherwise protected symbols (for use in other
*        class implementations) are defined. This macro also affects
*        the reporting of error context information, which is only
*        provided for external calls to the AST library.

*  Copyright:
*     Copyright (C) 1997-2006 Council for the Central Laboratory of the
*     Research Councils

*  Licence:
*     This program is free software: you can redistribute it and/or
*     modify it under the terms of the GNU Lesser General Public
*     License as published by the Free Software Foundation, either
*     version 3 of the License, or (at your option) any later
*     version.
*     
*     This program is distributed in the hope that it will be useful,
*     but WITHOUT ANY WARRANTY; without even the implied warranty of
*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*     GNU Lesser General Public License for more details.
*     
*     You should have received a copy of the GNU Lesser General
*     License along with this program.  If not, see
*     <http://www.gnu.org/licenses/>.

*  Authors:
*     DSB: D.S. Berry (Starlink)

*  History:
*     25-OCT-1996 (DSB):
*        Original version.
*     24-MAR-1998 (RFWS):
*        Override the astMapMerge method.
*     4-SEP-1998 (DSB):
*        Added UnitRadius attribute.
*     8-JAN-2003 (DSB):
*        Added protected astInitSphMapVtab method.
*     11-JUN-2003 (DSB):
*        Added PolarLong attribute.
*-
*/

/* Include files. */
/* ============== */
/* Interface definitions. */
/* ---------------------- */
#include "mapping.h"             /* Coordinate mappings (parent class) */

#if defined(astCLASS)            /* Protected */
#include "pointset.h"            /* Sets of points/coordinates */
#include "channel.h"             /* I/O channels */
#endif

/* C header files. */
/* --------------- */
#if defined(astCLASS)            /* Protected */
#include <stddef.h>
#endif

/* Macros */
/* ====== */

/* Define a dummy __attribute__ macro for use on non-GNU compilers. */
#ifndef __GNUC__
#  define  __attribute__(x)  /*NOTHING*/
#endif

/* Type Definitions. */
/* ================= */
/* SphMap structure. */
/* ------------------ */
/* This structure contains all information that is unique to each object in
   the class (e.g. its instance variables). */
typedef struct AstSphMap {

/* Attributes inherited from the parent class. */
   AstMapping mapping;           /* Parent class structure */

/* Attributes specific to objects in this class. */
   double polarlong;             /* Longitude to assign to either pole */
   int unitradius;               /* Are input vectors always of unit length? */
} AstSphMap;

/* Virtual function table. */
/* ----------------------- */
/* This table contains all information that is the same for all
   objects in the class (e.g. pointers to its virtual functions). */
#if defined(astCLASS)            /* Protected */
typedef struct AstSphMapVtab {

/* Properties (e.g. methods) inherited from the parent class. */
   AstMappingVtab mapping_vtab;  /* Parent class virtual function table */

/* A Unique identifier to determine class membership. */
   AstClassIdentifier id;

/* Properties (e.g. methods) specific to this class. */
   int (* GetUnitRadius)( AstSphMap *, int * );
   int (* TestUnitRadius)( AstSphMap *, int * );
   void (* ClearUnitRadius)( AstSphMap *, int * );
   void (* SetUnitRadius)( AstSphMap *, int, int * );

   double (* GetPolarLong)( AstSphMap *, int * );
   int (* TestPolarLong)( AstSphMap *, int * );
   void (* ClearPolarLong)( AstSphMap *, int * );
   void (* SetPolarLong)( AstSphMap *, double, int * );
} AstSphMapVtab;

#if defined(THREAD_SAFE)

/* Define a structure holding all data items that are global within this
   class. */
typedef struct AstSphMapGlobals {
   AstSphMapVtab Class_Vtab;
   int Class_Init;
   char GetAttrib_Buff[ 51 ];
} AstSphMapGlobals;
#endif

#endif

/* Function prototypes. */
/* ==================== */
/* Prototypes for standard class functions. */
/* ---------------------------------------- */
astPROTO_CHECK(SphMap)          /* Check class membership */
astPROTO_ISA(SphMap)            /* Test class membership */

/* Constructor. */
#if defined(astCLASS)            /* Protected. */
AstSphMap *astSphMap_( const char *, int *, ...);
#else
AstSphMap *astSphMapId_( const char *, ...)__attribute__((format(printf,1,2)));
#endif

#if defined(astCLASS)            /* Protected */

/* Initialiser. */
AstSphMap *astInitSphMap_( void *, size_t, int, AstSphMapVtab *,
                           const char *, int * );

/* Vtab initialiser. */
void astInitSphMapVtab_( AstSphMapVtab *, const char *, int * );

/* Loader. */
AstSphMap *astLoadSphMap_( void *, size_t, AstSphMapVtab *,
                           const char *, AstChannel *, int * );

/* Thread-safe initialiser for all global data used by this module. */
#if defined(THREAD_SAFE)
void astInitSphMapGlobals_( AstSphMapGlobals * );
#endif

#endif

/* Prototypes for member functions. */
/* -------------------------------- */
# if defined(astCLASS)           /* Protected */
int astGetUnitRadius_( AstSphMap *, int * );
int astTestUnitRadius_( AstSphMap *, int * );
void astClearUnitRadius_( AstSphMap *, int * );
void astSetUnitRadius_( AstSphMap *, int, int * );

double astGetPolarLong_( AstSphMap *, int * );
int astTestPolarLong_( AstSphMap *, int * );
void astClearPolarLong_( AstSphMap *, int * );
void astSetPolarLong_( AstSphMap *, double, int * );
#endif

/* Function interfaces. */
/* ==================== */
/* These macros are wrap-ups for the functions defined by this class
   to make them easier to invoke (e.g. to avoid type mis-matches when
   passing pointers to objects from derived classes). */

/* Interfaces to standard class functions. */
/* --------------------------------------- */
/* Some of these functions provide validation, so we cannot use them
   to validate their own arguments. We must use a cast when passing
   object pointers (so that they can accept objects from derived
   classes). */

/* Check class membership. */
#define astCheckSphMap(this) astINVOKE_CHECK(SphMap,this,0)
#define astVerifySphMap(this) astINVOKE_CHECK(SphMap,this,1)

/* Test class membership. */
#define astIsASphMap(this) astINVOKE_ISA(SphMap,this)

/* Constructor. */
#if defined(astCLASS)            /* Protected. */
#define astSphMap astINVOKE(F,astSphMap_)
#else
#define astSphMap astINVOKE(F,astSphMapId_)
#endif

#if defined(astCLASS)            /* Protected */

/* Initialiser. */
#define \
astInitSphMap(mem,size,init,vtab,name) \
astINVOKE(O,astInitSphMap_(mem,size,init,vtab,name,STATUS_PTR))

/* Vtab Initialiser. */
#define astInitSphMapVtab(vtab,name) astINVOKE(V,astInitSphMapVtab_(vtab,name,STATUS_PTR))
/* Loader. */
#define astLoadSphMap(mem,size,vtab,name,channel) \
astINVOKE(O,astLoadSphMap_(mem,size,vtab,name,astCheckChannel(channel),STATUS_PTR))
#endif

/* Interfaces to public member functions. */
/* -------------------------------------- */
/* Here we make use of astCheckSphMap to validate SphMap pointers
   before use.  This provides a contextual error report if a pointer
   to the wrong sort of Object is supplied. */

#if defined(astCLASS)            /* Protected */
#define astClearUnitRadius(this)     astINVOKE(V,astClearUnitRadius_(astCheckSphMap(this),STATUS_PTR))
#define astGetUnitRadius(this)       astINVOKE(V,astGetUnitRadius_(astCheckSphMap(this),STATUS_PTR))
#define astSetUnitRadius(this,value) astINVOKE(V,astSetUnitRadius_(astCheckSphMap(this),value,STATUS_PTR))
#define astTestUnitRadius(this)      astINVOKE(V,astTestUnitRadius_(astCheckSphMap(this),STATUS_PTR))

#define astClearPolarLong(this)     astINVOKE(V,astClearPolarLong_(astCheckSphMap(this),STATUS_PTR))
#define astGetPolarLong(this)       astINVOKE(V,astGetPolarLong_(astCheckSphMap(this),STATUS_PTR))
#define astSetPolarLong(this,value) astINVOKE(V,astSetPolarLong_(astCheckSphMap(this),value,STATUS_PTR))
#define astTestPolarLong(this)      astINVOKE(V,astTestPolarLong_(astCheckSphMap(this),STATUS_PTR))
#endif

#endif