GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GSkyPixel.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GSkyPixel.hpp - Sky map pixel class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2010-2018 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 GSkyPixel.hpp
23  * @brief Sky map pixel class definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GSKYPIXEL_HPP
28 #define GSKYPIXEL_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include "GBase.hpp"
33 
34 
35 /***********************************************************************//**
36  * @class GSkyPixel
37  *
38  * @brief Sky map pixel class
39  *
40  * This class implements a sky map pixel. A sky map pixel may be either
41  * 1-dimensional (1D) or 2-dimensional (2D). 1D pixels are set and retrieved
42  * using the index() method. The X and Y components of 2D pixels are set and
43  * retrieved using the x() and y() methods. The xy() method allows setting
44  * of both the X and Y components simultaneously.
45  *
46  * There are integer and double precision variants for 1D and 2D pixel
47  * constructors:
48  *
49  * GSkyPixel int_1D_pixel(1); // Set index to 1
50  * GSkyPixel double_1D_pixel(1.0); // Set index to 1.0
51  * GSkyPixel int_2D_pixel(1,2); // Set (x,y)=(1,2)
52  * GSkyPixel double_2D_pixel(1.0,2.0); // Set (x,y)=(1.0,2.0)
53  *
54  * The 1D constructors allow for automatic type conversion:
55  *
56  * GSkyPixel int_1D_pixel = 1; // Set index to 1
57  * GSkyPixel double_1D_pixel = 1.0; // Set index to 1.0
58  *
59  * Note that the class also provides conversion operators to int and double
60  * allowing to write:
61  *
62  * int index = GSkyPixel(1); // Retrieve integer index
63  * double dindex = GSkyPixel(1.0); // Retrieve double precision index
64  *
65  * The dimensionality of a pixel is checked using the is_1D() and is_2D()
66  * methods. The size() method returns 1 for 1D pixels and 2 for 2D pixels.
67  * If a pixel is not initialised, e.g.
68  *
69  * GSkyPixel pixel; // Not initialised
70  *
71  * the is_1D() and is_2D() methods return false and the size() method returns
72  * 0.
73  ***************************************************************************/
74 class GSkyPixel : public GBase {
75 
76  // Operator friends
77  friend bool operator==(const GSkyPixel& a, const GSkyPixel& b);
78  friend bool operator!=(const GSkyPixel& a, const GSkyPixel& b);
79 
80 public:
81  // Constructors and destructors
82  GSkyPixel(void);
83  GSkyPixel(const int& index);
84  GSkyPixel(const double& index);
85  GSkyPixel(const int& x, const int& y);
86  GSkyPixel(const double& x, const double& y);
87  GSkyPixel(const GSkyPixel& pixel);
88  virtual ~GSkyPixel(void);
89 
90  // Operators
91  GSkyPixel& operator=(const GSkyPixel& pixel);
92  operator int() const;
93  operator double() const;
94 
95  // Methods
96  void clear(void);
97  GSkyPixel* clone(void) const;
98  std::string classname(void) const;
99  int size(void) const;
100  bool is_1D(void) const;
101  bool is_2D(void) const;
102  void index(const double& index);
103  void x(const double& x);
104  void y(const double& y);
105  void xy(const double& x, const double& y);
106  const double& index(void) const;
107  const double& x(void) const;
108  const double& y(void) const;
109  std::string print(const GChatter& chatter = NORMAL) const;
110 
111 private:
112  // Private methods
113  void init_members(void);
114  void copy_members(const GSkyPixel& pixel);
115  void free_members(void);
116 
117  // Private data area
118  int m_size; //!< Pixel dimension (0=undefined, 1=1D, 2=2D)
119  double m_x; //!< X index
120  double m_y; //!< Y index
121 };
122 
123 
124 /***********************************************************************//**
125  * @brief Return class name
126  *
127  * @return String containing the class name ("GSkyPixel").
128  ***************************************************************************/
129 inline
130 std::string GSkyPixel::classname(void) const
131 {
132  return ("GSkyPixel");
133 }
134 
135 
136 /***********************************************************************//**
137  * @brief Return pixel dimension
138  *
139  * @return Pixel dimension [0,1,2].
140  *
141  * Returns the pixel dimension. If the pixel is not defined the method
142  * returns 0.
143  ***************************************************************************/
144 inline
145 int GSkyPixel::size(void) const
146 {
147  return m_size;
148 }
149 
150 
151 /***********************************************************************//**
152  * @brief Check if pixel is 1D
153  *
154  * @return True if pixel is 1D.
155  ***************************************************************************/
156 inline
157 bool GSkyPixel::is_1D(void) const
158 {
159  return (m_size == 1);
160 }
161 
162 
163 /***********************************************************************//**
164  * @brief Check if pixel is 2D
165  *
166  * @return True if pixel is 2D.
167  ***************************************************************************/
168 inline
169 bool GSkyPixel::is_2D(void) const
170 {
171  return (m_size == 2);
172 }
173 
174 
175 /***********************************************************************//**
176  * @brief Set sky map pixel index
177  *
178  * @param[in] index Pixel index.
179  *
180  * Sets the 1D pixel index.
181  ***************************************************************************/
182 inline
183 void GSkyPixel::index(const double& index)
184 {
185  // Set pixel index
186  m_size = 1;
187  m_x = index;
188  m_y = 0.0;
189 
190  // Return
191  return;
192 }
193 
194 
195 /***********************************************************************//**
196  * @brief Set x value of sky map pixel
197  *
198  * @param[in] x X pixel index.
199  *
200  * Sets the X value of a 2D pixel index. The method does not alter the Y
201  * pixel index.
202  ***************************************************************************/
203 inline
204 void GSkyPixel::x(const double& x)
205 {
206  m_size = 2;
207  m_x = x;
208  return;
209 }
210 
211 
212 /***********************************************************************//**
213  * @brief Set y value of sky map pixel
214  *
215  * @param[in] y Y pixel index.
216  *
217  * Sets the Y value of a 2D pixel index. The method does not alter the X
218  * pixel index.
219  ***************************************************************************/
220 inline
221 void GSkyPixel::y(const double& y)
222 {
223  m_size = 2;
224  m_y = y;
225  return;
226 }
227 
228 
229 /***********************************************************************//**
230  * @brief Set x and y value of sky map pixel
231  *
232  * @param[in] x X pixel index.
233  * @param[in] y Y pixel index.
234  *
235  * Sets the X and Y value of a 2D pixel index.
236  ***************************************************************************/
237 inline
238 void GSkyPixel::xy(const double& x, const double& y)
239 {
240  m_size = 2;
241  m_x = x;
242  m_y = y;
243  return;
244 }
245 
246 
247 /***********************************************************************//**
248  * @brief Return sky map pixel index
249  *
250  * @return Sky map pixel index
251  *
252  * Returns the 1D index of a sky map pixel. The method does not check whether
253  * the pixel is indeed a 1D pixel.
254  ***************************************************************************/
255 inline
256 const double& GSkyPixel::index(void) const
257 {
258  return m_x;
259 }
260 
261 
262 /***********************************************************************//**
263  * @brief Return x value of sky map pixel
264  *
265  * @return X value of sky map pixel
266  *
267  * Returns the X value of a 2D sky map pixel. The method does not check
268  * whether the pixel is indeed a 2D pixel.
269  ***************************************************************************/
270 inline
271 const double& GSkyPixel::x(void) const
272 {
273  return m_x;
274 }
275 
276 
277 /***********************************************************************//**
278  * @brief Return y value of sky pixel
279  *
280  * @return Y value of sky map pixel
281  *
282  * Returns the Y value of a 2D sky map pixel. The method does not check
283  * whether the pixel is indeed a 2D pixel.
284  ***************************************************************************/
285 inline
286 const double& GSkyPixel::y(void) const
287 {
288  return m_y;
289 }
290 
291 
292 /***********************************************************************//**
293  * @brief Equality operator
294  *
295  * @param[in] a First sky pixel.
296  * @param[in] b Second sky pixel.
297  * @return True if first and second sky pixels are identical.
298  ***************************************************************************/
299 inline
300 bool operator==(const GSkyPixel &a, const GSkyPixel &b)
301 {
302  return ((a.m_size == b.m_size) && (a.m_x == b.m_x) && (a.m_y == b.m_y));
303 }
304 
305 
306 /***********************************************************************//**
307  * @brief Inqquality operator
308  *
309  * @param[in] a First sky pixel.
310  * @param[in] b Second sky pixel.
311  * @return True if first and second sky pixels are different.
312  ***************************************************************************/
313 inline
314 bool operator!=(const GSkyPixel &a, const GSkyPixel &b)
315 {
316  return ((a.m_size != b.m_size) || (a.m_x != b.m_x) || (a.m_y != b.m_y));
317 }
318 
319 #endif /* GSKYPIXEL_HPP */
GSkyPixel & operator=(const GSkyPixel &pixel)
Assignment operator.
Definition: GSkyPixel.cpp:180
std::string print(const GChatter &chatter=NORMAL) const
Print pixel.
Definition: GSkyPixel.cpp:292
void free_members(void)
Delete class members.
Definition: GSkyPixel.cpp:360
int size(void) const
Return pixel dimension.
Definition: GSkyPixel.hpp:145
bool is_1D(void) const
Check if pixel is 1D.
Definition: GSkyPixel.hpp:157
int m_size
Pixel dimension (0=undefined, 1=1D, 2=2D)
Definition: GSkyPixel.hpp:118
GSkyPixel * clone(void) const
Clone sky map pixel.
Definition: GSkyPixel.cpp:279
double m_y
Y index.
Definition: GSkyPixel.hpp:120
void init_members(void)
Initialise class members.
Definition: GSkyPixel.cpp:328
void xy(const double &x, const double &y)
Set x and y value of sky map pixel.
Definition: GSkyPixel.hpp:238
Definition of interface for all GammaLib classes.
virtual ~GSkyPixel(void)
Destructor.
Definition: GSkyPixel.cpp:158
void clear(void)
Clear instance.
Definition: GSkyPixel.cpp:259
double m_x
X index.
Definition: GSkyPixel.hpp:119
const double & index(void) const
Return sky map pixel index.
Definition: GSkyPixel.hpp:256
Sky map pixel class.
Definition: GSkyPixel.hpp:74
friend bool operator!=(const GSkyPixel &a, const GSkyPixel &b)
Inqquality operator.
Definition: GSkyPixel.hpp:314
void copy_members(const GSkyPixel &pixel)
Copy class members.
Definition: GSkyPixel.cpp:345
Interface class for all GammaLib classes.
Definition: GBase.hpp:52
GChatter
Definition: GTypemaps.hpp:33
const double & x(void) const
Return x value of sky map pixel.
Definition: GSkyPixel.hpp:271
friend bool operator==(const GSkyPixel &a, const GSkyPixel &b)
Equality operator.
Definition: GSkyPixel.hpp:300
std::string classname(void) const
Return class name.
Definition: GSkyPixel.hpp:130
GSkyPixel(void)
Void constructor.
Definition: GSkyPixel.cpp:57
bool operator==(const GEnergy &a, const GEnergy &b)
Energy equality operator friend.
Definition: GEnergy.hpp:297
bool is_2D(void) const
Check if pixel is 2D.
Definition: GSkyPixel.hpp:169
bool operator!=(const GEbounds &a, const GEbounds &b)
Energy boundaries inequality operator friend.
Definition: GEbounds.hpp:207
const double & y(void) const
Return y value of sky pixel.
Definition: GSkyPixel.hpp:286