GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GSkyRegionRectangle.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GSkyRegionRectangle.hpp - Rectangular sky region class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2019-2020 by Andreas Specovius *
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 GSkyRegionRectangle.hpp
23  * @brief Rectangular sky region class interface definition
24  * @author Andreas Specovius
25  */
26 
27 #ifndef GSKYREGIONRECTANGLE_HPP
28 #define GSKYREGIONRECTANGLE_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <vector>
32 #include <string>
33 #include "GSkyDir.hpp"
34 #include "GSkyRegion.hpp"
35 
36 /* __ Forward declarations _______________________________________________ */
37 class GSkyPixel;
38 
39 
40 /***********************************************************************//**
41  * @class GSkyRegionRectangle
42  *
43  * @brief Interface for the rectangular sky region class
44  *
45  * This class provides an implementation for a rectangular sky region. The sky
46  * region is defined by an array of parameters, the meaning of which is
47  * specific to the derived class where the region type or shape is defined.
48  *
49  * The class holds several properties such as solid angle subtended by the
50  * region and computed through internal method compute_solid().
51  *
52  * The position angle counts counter-clockwise from celestial North and is
53  * aligned with the height axis of the rectangle. Note, that height and width
54  * describe the diameter of the region.
55  *
56  * Sky directions can be transformed to the local/global coordinate system via
57  * the methods transform_to_local() / transform_to_global().
58  * The position (in global coordinates) of the 4 corners of the rectangle can
59  * be received via the method get_corner(index).
60  *
61  ***************************************************************************/
63 
64 public:
65  // Constructors and destructors
66  GSkyRegionRectangle(void);
68  const double& width,
69  const double& height,
70  const double& posang);
71  GSkyRegionRectangle(const double& ra,
72  const double& dec,
73  const double& width,
74  const double& height,
75  const double& posang);
76  explicit GSkyRegionRectangle(const std::string& line);
78  virtual ~GSkyRegionRectangle(void);
79 
80  // Operators
82 
83  // Implemented methods
84  void clear(void);
85  GSkyRegionRectangle* clone(void) const;
86  std::string classname(void) const;
87  const GSkyDir& centre(void) const;
88  void centre(const GSkyDir& centre);
89  void centre(const double& ra,const double& dec);
90  double ra(void) const;
91  double dec(void) const;
92  const double& width(void) const;
93  void width(const double& width);
94  const double& height(void) const;
95  void height(const double& height);
96  const double& posang(void) const;
97  void posang(const double& posang);
98  GSkyDir corner(const int& index) const;
99  void read(const std::string& line);
100  std::string write(void) const;
101  bool contains(const GSkyDir& dir) const;
102  bool contains(const GSkyRegion& reg) const;
103  bool overlaps(const GSkyRegion& reg) const;
104  std::string print(const GChatter& chatter = NORMAL) const;
105 
106 protected:
107  // Protected methods
108  void init_members(void);
109  void copy_members(const GSkyRegionRectangle& region);
110  void free_members(void);
111  void compute_solid_angle(void);
112  bool contains(const GSkyPixel& local) const;
113  GSkyPixel dir_to_local(const GSkyDir& dir) const;
114  GSkyDir local_to_dir(const GSkyPixel& local) const;
115 
116  // Protected members
117  GSkyDir m_centre; //!< Centre or reference point of the region
118  double m_width; //!< Width of the region (degrees)
119  double m_height; //!< Height of the region (degrees)
120  double m_posang; //!< Position angle, counterclockwise from North (degrees)
121 };
122 
123 
124 /***********************************************************************//**
125  * @brief Return class name
126  *
127  * @return String containing the class name ("GSkyRegionRectangle").
128  ***************************************************************************/
129 inline
130 std::string GSkyRegionRectangle::classname(void) const
131 {
132  return ("GSkyRegionRectangle");
133 }
134 
135 
136 /***********************************************************************//**
137  * @brief Return rectangular region centre
138  *
139  * @return Region centre.
140  *
141  * Returns the region centre.
142  ***************************************************************************/
143 inline
145 {
146  return (m_centre);
147 }
148 
149 
150 /***********************************************************************//**
151  * @brief Set rectangular region centre
152  *
153  * @param[in] dir Region centre.
154  *
155  * Sets the centre of the rectangular region to the specified sky direction.
156  ***************************************************************************/
157 inline
159 {
160  m_centre = dir;
161  return;
162 }
163 
164 
165 /***********************************************************************//**
166  * @brief Set rectangular region centre Right Ascension and Declincation
167  *
168  * @param[in] ra Right Ascension (degrees).
169  * @param[in] dec Declination (degrees).
170  *
171  * Sets the centre of the rectangular region to the specified Right Ascension
172  * and Declination.
173  ***************************************************************************/
174 inline
175 void GSkyRegionRectangle::centre(const double& ra, const double& dec)
176 {
177  m_centre.radec_deg(ra, dec);
178  return;
179 }
180 
181 
182 /***********************************************************************//**
183  * @brief Return rectangular region centre Right Ascension
184  *
185  * @return Region centre Right Ascension (degrees).
186  *
187  * Returns the region centre Right Ascension in degrees.
188  ***************************************************************************/
189 inline
190 double GSkyRegionRectangle::ra(void) const
191 {
192  return (m_centre.ra_deg());
193 }
194 
195 
196 /***********************************************************************//**
197  * @brief Return rectangular region centre Declination
198  *
199  * @return Region centre Declination (degrees).
200  *
201  * Returns the region centre Declination in degrees.
202  ***************************************************************************/
203 inline
204 double GSkyRegionRectangle::dec(void) const
205 {
206  return (m_centre.dec_deg());
207 }
208 
209 
210 /***********************************************************************//**
211  * @brief Return region width extension (in degrees)
212  *
213  * @return Region width (degrees).
214  *
215  * Returns the region width extension in degrees.
216  ***************************************************************************/
217 inline
218 const double& GSkyRegionRectangle::width(void) const
219 {
220  return (m_width);
221 }
222 
223 
224 /***********************************************************************//**
225  * @brief Return region height extension (in degrees)
226  *
227  * @return Region height (degrees).
228  *
229  * Returns the region height extension in degrees.
230  ***************************************************************************/
231 inline
232 const double& GSkyRegionRectangle::height(void) const
233 {
234  return (m_height);
235 }
236 
237 
238 /***********************************************************************//**
239  * @brief Return region position angle (in degrees)
240  *
241  * @return Region position angle (degrees).
242  *
243  * Returns the region position angle in degrees. The position angle is
244  * counted counterclockwise from North.
245  ***************************************************************************/
246 inline
247 const double& GSkyRegionRectangle::posang(void) const
248 {
249  return (m_posang);
250 }
251 
252 
253 /***********************************************************************//**
254  * @brief Set position angle of rectangular region
255  *
256  * @param[in] posang Position angle (degrees).
257  *
258  * Sets the position angle of the rectangular sky region. The position angle
259  * is counted counterclockwise from celestial North and is aligned to the
260  * rectangle height.
261  ***************************************************************************/
262 inline
263 void GSkyRegionRectangle::posang(const double& posang)
264 {
265  m_posang = posang;
266  return;
267 }
268 
269 #endif /* GSKYREGIONRECTANGLE_HPP */
void compute_solid_angle(void)
Compute solid angle of rectangle.
GSkyPixel dir_to_local(const GSkyDir &dir) const
Transform sky direction to local rectangle coordinates.
void free_members(void)
Delete class members.
double dec_deg(void) const
Returns Declination in degrees.
Definition: GSkyDir.hpp:256
std::string print(const GChatter &chatter=NORMAL) const
Print rectangular region.
GSkyRegionRectangle * clone(void) const
Clone rectangular sky region.
Sky direction class interface definition.
GSkyRegionRectangle & operator=(const GSkyRegionRectangle &region)
Assignment operator.
double dec(void) const
Return rectangular region centre Declination.
GSkyDir local_to_dir(const GSkyPixel &local) const
Transform local rectangle coordinates to sky direction.
std::string classname(void) const
Return class name.
const double & posang(void) const
Return region position angle (in degrees)
Interface for the rectangular sky region class.
std::string write(void) const
Write region into a string.
const double & height(void) const
Return region height extension (in degrees)
GSkyDir m_centre
Centre or reference point of the region.
Sky map pixel class.
Definition: GSkyPixel.hpp:74
const double & width(void) const
Return region width extension (in degrees)
Abstract interface for the sky region class.
Definition: GSkyRegion.hpp:57
double m_width
Width of the region (degrees)
bool contains(const GSkyDir &dir) const
Checks if sky direction lies within region.
GSkyRegionRectangle(void)
Void constructor.
double ra_deg(void) const
Returns Right Ascension in degrees.
Definition: GSkyDir.hpp:229
GChatter
Definition: GTypemaps.hpp:33
void radec_deg(const double &ra, const double &dec)
Set equatorial sky direction (degrees)
Definition: GSkyDir.cpp:224
void copy_members(const GSkyRegionRectangle &region)
Copy class members.
bool overlaps(const GSkyRegion &reg) const
Checks if region is overlapping with this region.
void clear(void)
Clear instance.
double ra(void) const
Return rectangular region centre Right Ascension.
GSkyDir corner(const int &index) const
Return sky direction of one corner of the rectangle.
double m_height
Height of the region (degrees)
const GSkyDir & centre(void) const
Return rectangular region centre.
double m_posang
Position angle, counterclockwise from North (degrees)
void init_members(void)
Initialise class members.
Sky direction class.
Definition: GSkyDir.hpp:62
void read(const std::string &line)
Read region from DS9 string.
Abstract sky region base class interface definition.
virtual ~GSkyRegionRectangle(void)
Destructor.