GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GSkyRegions.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GSkyRegions.hpp - Sky region container class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2013-2017 by Pierrick Martin *
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 GSkyRegions.hpp
23  * @brief Sky regions container class definition
24  * @author Pierrick Martin
25  */
26 
27 #ifndef GSKYREGIONS_HPP
28 #define GSKYREGIONS_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include <vector>
33 #include "GContainer.hpp"
34 #include "GSkyRegion.hpp"
35 #include "GException.hpp"
36 #include "GFilename.hpp"
37 
38 /* __ Forward declarations _______________________________________________ */
39 class GSkyDir;
40 
41 
42 /***********************************************************************//**
43  * @class GSkyRegions
44  *
45  * @brief Sky region container class
46  *
47  * This container class collects sky regions objects derived from the
48  * GSkyRegion abstract class. These can be accessed from the access
49  * operator[] or through the at() method with index checking. Access to
50  * the region can be done from index or name, so the name of each region
51  * in the container has to be unique.
52  *
53  * The object can be initialised from a DS9 region file, and has load and
54  * save methods from/to a DS9 region file.
55  ***************************************************************************/
56 class GSkyRegions : public GContainer {
57 
58 public:
59  // Constructors and destructors
60  GSkyRegions(void);
61  GSkyRegions(const GSkyRegions& regions);
62  explicit GSkyRegions(const GFilename& filename);
63  virtual ~GSkyRegions(void);
64 
65  // Operators
66  GSkyRegions& operator=(const GSkyRegions& regions);
67  GSkyRegion* operator[](const int& index);
68  const GSkyRegion* operator[](const int& index) const;
69 
70  // Methods
71  void clear(void);
72  GSkyRegions* clone(void) const;
73  std::string classname(void) const;
74  GSkyRegion* at(const int& index);
75  const GSkyRegion* at(const int& index) const;
76  int size(void) const;
77  bool is_empty(void) const;
78  GSkyRegion* set(const int& index, const GSkyRegion& region);
79  GSkyRegion* append(const GSkyRegion& region);
80  GSkyRegion* insert(const int& index, const GSkyRegion& region);
81  void remove(const int& index);
82  void reserve(const int& num);
83  void extend(const GSkyRegions& regions);
84  bool contains(const GSkyDir& dir) const;
85  bool overlaps(const GSkyRegion& region) const;
86  bool overlaps(const GSkyRegions& regions) const;
87  void load(const GFilename& filename);
88  void save(const GFilename& filename) const;
89  const GFilename& filename(void) const;
90  void filename(const GFilename& filename);
91  std::string print(const GChatter& chatter = NORMAL) const;
92 
93 protected:
94  // Protected methods
95  void init_members(void);
96  void copy_members(const GSkyRegions& regions);
97  void free_members(void);
98 
99  // Protected members
100  mutable GFilename m_filename; //!< Filename of origin
101  std::vector<GSkyRegion*> m_regions; //!< List of regions
102 };
103 
104 
105 /***********************************************************************//**
106  * @brief Return class name
107  *
108  * @return String containing the class name ("GSkyRegions").
109  ***************************************************************************/
110 inline
111 std::string GSkyRegions::classname(void) const
112 {
113  return ("GSkyRegions");
114 }
115 
116 
117 /***********************************************************************//**
118  * @brief Return pointer to region
119  *
120  * @param[in] index region index [0,...,size()-1].
121  *
122  * Returns a pointer to the region with the specified @p index.
123  ***************************************************************************/
124 inline
126 {
127  return (m_regions[index]);
128 }
129 
130 
131 /***********************************************************************//**
132  * @brief Return pointer to region (const version)
133  *
134  * @param[in] index region index [0,...,size()-1].
135  *
136  * Returns a const pointer to the region with the specified @p index.
137  ***************************************************************************/
138 inline
139 const GSkyRegion* GSkyRegions::operator[](const int& index) const
140 {
141  return (m_regions[index]);
142 }
143 
144 
145 /***********************************************************************//**
146  * @brief Return number of regions in container
147  *
148  * @return Number of regions in container.
149  *
150  * Returns the number of regions in the region container.
151  ***************************************************************************/
152 inline
153 int GSkyRegions::size(void) const
154 {
155  return (int)m_regions.size();
156 }
157 
158 
159 /***********************************************************************//**
160  * @brief Signals if there are no regions in container
161  *
162  * @return True if container is empty, false otherwise.
163  *
164  * Signals if the region container does not contain any region.
165  ***************************************************************************/
166 inline
167 bool GSkyRegions::is_empty(void) const
168 {
169  return (m_regions.empty());
170 }
171 
172 
173 /***********************************************************************//**
174  * @brief Reserves space for regions in container
175  *
176  * @param[in] num Number of regions
177  *
178  * Reserves space for @p num regions in the container.
179  ***************************************************************************/
180 inline
181 void GSkyRegions::reserve(const int& num)
182 {
183  m_regions.reserve(num);
184  return;
185 }
186 
187 
188 /***********************************************************************//**
189  * @brief Return regions file name
190  *
191  * @return File name from which the regions have been loaded or into which
192  * the regions have been saved.
193  *
194  * Returns the file name from which the regions have been loaded or into
195  * which the regions have been saved. The returned string will be set if
196  * the load(), save() or filename() setter methods were called.
197  ***************************************************************************/
198 inline
200 {
201  return (m_filename);
202 }
203 
204 
205 /***********************************************************************//**
206  * @brief Set regions file name
207  *
208  * @param[in] filename Regions file name.
209  *
210  * Set the regions file name.
211  ***************************************************************************/
212 inline
213 void GSkyRegions::filename(const GFilename& filename)
214 {
216  return;
217 }
218 
219 #endif /* GSKYREGIONS_HPP */
void clear(void)
Clear object.
std::vector< GSkyRegion * > m_regions
List of regions.
GSkyRegion * insert(const int &index, const GSkyRegion &region)
Insert region into container.
void copy_members(const GSkyRegions &regions)
Copy class members.
GSkyRegions * clone(void) const
Clone instance.
GSkyRegions & operator=(const GSkyRegions &regions)
Assignment operator.
GSkyRegions(void)
Void constructor.
Definition: GSkyRegions.cpp:70
std::string print(const GChatter &chatter=NORMAL) const
Print regions.
const GFilename & filename(void) const
Return regions file name.
Abstract interface for the sky region class.
Definition: GSkyRegion.hpp:57
GFilename m_filename
Filename of origin.
Filename class.
Definition: GFilename.hpp:62
void save(const GFilename &filename) const
Save regions into DS9 region file.
GChatter
Definition: GTypemaps.hpp:33
int size(void) const
Return number of regions in container.
GSkyRegion * at(const int &index)
Return pointer to region.
virtual ~GSkyRegions(void)
Destructor.
Sky region container class.
Definition: GSkyRegions.hpp:56
bool is_empty(void) const
Signals if there are no regions in container.
GSkyRegion * operator[](const int &index)
Return pointer to region.
bool overlaps(const GSkyRegion &region) const
Check if region overlaps one of the regions.
void free_members(void)
Delete class members.
void extend(const GSkyRegions &regions)
Append region container.
Exception handler interface definition.
void init_members(void)
Initialise class members.
GSkyRegion * set(const int &index, const GSkyRegion &region)
Set region in container.
Definition of interface for container classes.
Sky direction class.
Definition: GSkyDir.hpp:62
bool contains(const GSkyDir &dir) const
Check if direction is contained in one of the regions.
Abstract sky region base class interface definition.
void reserve(const int &num)
Reserves space for regions in container.
std::string classname(void) const
Return class name.
Interface class for container classes.
Definition: GContainer.hpp:52
Filename class interface definition.
void load(const GFilename &filename)
Load regions from DS9 region file.
GSkyRegion * append(const GSkyRegion &region)
Append region to container.