GSkyPixel.hpp
9.95 KB
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
/***************************************************************************
* GSkyPixel.hpp - Sky map pixel class *
* ----------------------------------------------------------------------- *
* copyright (C) 2010-2018 by Juergen Knoedlseder *
* ----------------------------------------------------------------------- *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
***************************************************************************/
/**
* @file GSkyPixel.hpp
* @brief Sky map pixel class definition
* @author Juergen Knoedlseder
*/
#ifndef GSKYPIXEL_HPP
#define GSKYPIXEL_HPP
/* __ Includes ___________________________________________________________ */
#include <string>
#include "GBase.hpp"
/***********************************************************************//**
* @class GSkyPixel
*
* @brief Sky map pixel class
*
* This class implements a sky map pixel. A sky map pixel may be either
* 1-dimensional (1D) or 2-dimensional (2D). 1D pixels are set and retrieved
* using the index() method. The X and Y components of 2D pixels are set and
* retrieved using the x() and y() methods. The xy() method allows setting
* of both the X and Y components simultaneously.
*
* There are integer and double precision variants for 1D and 2D pixel
* constructors:
*
* GSkyPixel int_1D_pixel(1); // Set index to 1
* GSkyPixel double_1D_pixel(1.0); // Set index to 1.0
* GSkyPixel int_2D_pixel(1,2); // Set (x,y)=(1,2)
* GSkyPixel double_2D_pixel(1.0,2.0); // Set (x,y)=(1.0,2.0)
*
* The 1D constructors allow for automatic type conversion:
*
* GSkyPixel int_1D_pixel = 1; // Set index to 1
* GSkyPixel double_1D_pixel = 1.0; // Set index to 1.0
*
* Note that the class also provides conversion operators to int and double
* allowing to write:
*
* int index = GSkyPixel(1); // Retrieve integer index
* double dindex = GSkyPixel(1.0); // Retrieve double precision index
*
* The dimensionality of a pixel is checked using the is_1D() and is_2D()
* methods. The size() method returns 1 for 1D pixels and 2 for 2D pixels.
* If a pixel is not initialised, e.g.
*
* GSkyPixel pixel; // Not initialised
*
* the is_1D() and is_2D() methods return false and the size() method returns
* 0.
***************************************************************************/
class GSkyPixel : public GBase {
// Operator friends
friend bool operator==(const GSkyPixel& a, const GSkyPixel& b);
friend bool operator!=(const GSkyPixel& a, const GSkyPixel& b);
public:
// Constructors and destructors
GSkyPixel(void);
GSkyPixel(const int& index);
GSkyPixel(const double& index);
GSkyPixel(const int& x, const int& y);
GSkyPixel(const double& x, const double& y);
GSkyPixel(const GSkyPixel& pixel);
virtual ~GSkyPixel(void);
// Operators
GSkyPixel& operator=(const GSkyPixel& pixel);
operator int() const;
operator double() const;
// Methods
void clear(void);
GSkyPixel* clone(void) const;
std::string classname(void) const;
int size(void) const;
bool is_1D(void) const;
bool is_2D(void) const;
void index(const double& index);
void x(const double& x);
void y(const double& y);
void xy(const double& x, const double& y);
const double& index(void) const;
const double& x(void) const;
const double& y(void) const;
std::string print(const GChatter& chatter = NORMAL) const;
private:
// Private methods
void init_members(void);
void copy_members(const GSkyPixel& pixel);
void free_members(void);
// Private data area
int m_size; //!< Pixel dimension (0=undefined, 1=1D, 2=2D)
double m_x; //!< X index
double m_y; //!< Y index
};
/***********************************************************************//**
* @brief Return class name
*
* @return String containing the class name ("GSkyPixel").
***************************************************************************/
inline
std::string GSkyPixel::classname(void) const
{
return ("GSkyPixel");
}
/***********************************************************************//**
* @brief Return pixel dimension
*
* @return Pixel dimension [0,1,2].
*
* Returns the pixel dimension. If the pixel is not defined the method
* returns 0.
***************************************************************************/
inline
int GSkyPixel::size(void) const
{
return m_size;
}
/***********************************************************************//**
* @brief Check if pixel is 1D
*
* @return True if pixel is 1D.
***************************************************************************/
inline
bool GSkyPixel::is_1D(void) const
{
return (m_size == 1);
}
/***********************************************************************//**
* @brief Check if pixel is 2D
*
* @return True if pixel is 2D.
***************************************************************************/
inline
bool GSkyPixel::is_2D(void) const
{
return (m_size == 2);
}
/***********************************************************************//**
* @brief Set sky map pixel index
*
* @param[in] index Pixel index.
*
* Sets the 1D pixel index.
***************************************************************************/
inline
void GSkyPixel::index(const double& index)
{
// Set pixel index
m_size = 1;
m_x = index;
m_y = 0.0;
// Return
return;
}
/***********************************************************************//**
* @brief Set x value of sky map pixel
*
* @param[in] x X pixel index.
*
* Sets the X value of a 2D pixel index. The method does not alter the Y
* pixel index.
***************************************************************************/
inline
void GSkyPixel::x(const double& x)
{
m_size = 2;
m_x = x;
return;
}
/***********************************************************************//**
* @brief Set y value of sky map pixel
*
* @param[in] y Y pixel index.
*
* Sets the Y value of a 2D pixel index. The method does not alter the X
* pixel index.
***************************************************************************/
inline
void GSkyPixel::y(const double& y)
{
m_size = 2;
m_y = y;
return;
}
/***********************************************************************//**
* @brief Set x and y value of sky map pixel
*
* @param[in] x X pixel index.
* @param[in] y Y pixel index.
*
* Sets the X and Y value of a 2D pixel index.
***************************************************************************/
inline
void GSkyPixel::xy(const double& x, const double& y)
{
m_size = 2;
m_x = x;
m_y = y;
return;
}
/***********************************************************************//**
* @brief Return sky map pixel index
*
* @return Sky map pixel index
*
* Returns the 1D index of a sky map pixel. The method does not check whether
* the pixel is indeed a 1D pixel.
***************************************************************************/
inline
const double& GSkyPixel::index(void) const
{
return m_x;
}
/***********************************************************************//**
* @brief Return x value of sky map pixel
*
* @return X value of sky map pixel
*
* Returns the X value of a 2D sky map pixel. The method does not check
* whether the pixel is indeed a 2D pixel.
***************************************************************************/
inline
const double& GSkyPixel::x(void) const
{
return m_x;
}
/***********************************************************************//**
* @brief Return y value of sky pixel
*
* @return Y value of sky map pixel
*
* Returns the Y value of a 2D sky map pixel. The method does not check
* whether the pixel is indeed a 2D pixel.
***************************************************************************/
inline
const double& GSkyPixel::y(void) const
{
return m_y;
}
/***********************************************************************//**
* @brief Equality operator
*
* @param[in] a First sky pixel.
* @param[in] b Second sky pixel.
* @return True if first and second sky pixels are identical.
***************************************************************************/
inline
bool operator==(const GSkyPixel &a, const GSkyPixel &b)
{
return ((a.m_size == b.m_size) && (a.m_x == b.m_x) && (a.m_y == b.m_y));
}
/***********************************************************************//**
* @brief Inqquality operator
*
* @param[in] a First sky pixel.
* @param[in] b Second sky pixel.
* @return True if first and second sky pixels are different.
***************************************************************************/
inline
bool operator!=(const GSkyPixel &a, const GSkyPixel &b)
{
return ((a.m_size != b.m_size) || (a.m_x != b.m_x) || (a.m_y != b.m_y));
}
#endif /* GSKYPIXEL_HPP */