GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GSkyRegionMap.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GSkyRegionMap.hpp - Sky region map class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2017-2020 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 GSkyRegionMap.hpp
23  * @brief Sky region map class interface definition
24  * @author Pierrick Martin
25  */
26 
27 #ifndef GSKYREGIONMAP_HPP
28 #define GSKYREGIONMAP_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <vector>
32 #include <string>
33 #include "GSkyRegion.hpp"
34 #include "GSkyMap.hpp"
35 #include "GFilename.hpp"
36 
37 /* __ Forward declarations _______________________________________________ */
38 class GSkyDir;
39 class GSkyRegionMap;
41 
42 
43 /***********************************************************************//**
44  * @class GSkyRegionMap
45  *
46  * @brief Interface for a sky region map
47  *
48  * This class provides an implementation for a sky region defined by a
49  * sky map. The map is provided as a FITS file. Pixels with non-zero values
50  * are within the region, pixels with zero values outside the region.
51  ***************************************************************************/
52 class GSkyRegionMap : public GSkyRegion {
53 
54 public:
55  // Constructors and destructors
56  GSkyRegionMap(void);
57  explicit GSkyRegionMap(const GFilename& filename);
58  explicit GSkyRegionMap(const GSkyMap& map);
59  explicit GSkyRegionMap(const GSkyRegion* region);
60  GSkyRegionMap(const GSkyRegionMap& region);
61  virtual ~GSkyRegionMap(void);
62 
63  // Operators
64  GSkyRegionMap& operator=(const GSkyRegionMap& region);
65 
66  // Implemented pure virtual methods
67  void clear(void);
68  GSkyRegionMap* clone(void) const;
69  std::string classname(void) const;
70  void read(const std::string& line);
71  std::string write(void) const;
72  bool contains(const GSkyDir& dir) const;
73  bool contains(const GSkyRegion& reg) const;
74  bool overlaps(const GSkyRegion& reg) const;
75  std::string print(const GChatter& chatter = NORMAL) const;
76 
77  // Other methods
78  void load(const GFilename& filename);
79  void map(const GSkyMap& map);
80  const GSkyMap& map(void) const;
81  const std::vector<int>& nonzero_indices(void) const;
82 
83 protected:
84  // Protected methods
85  void init_members(void);
86  void copy_members(const GSkyRegionMap& region);
87  void free_members(void);
88  void compute_solid_angle(void);
89  void set_nonzero_indices(void);
90  void set_region_circle(const GSkyRegionCircle* circle);
91  void set_region_rectangle(const GSkyRegionRectangle* rect);
92 
93  // Protected members
94  GSkyMap m_map; //!< The region map
95  std::vector<int> m_nonzero_indices; //!< Vector of non-zero pixel indices
96 };
97 
98 
99 /***********************************************************************//**
100  * @brief Return class name
101  *
102  * @return String containing the class name ("GSkyRegionMap").
103  ***************************************************************************/
104 inline
105 std::string GSkyRegionMap::classname(void) const
106 {
107  return ("GSkyRegionMap");
108 }
109 
110 
111 /***********************************************************************//**
112  * @brief Return sky map
113  *
114 * @return region sky map.
115  ***************************************************************************/
116 inline
117 const GSkyMap& GSkyRegionMap::map(void) const
118 {
119  return (m_map);
120 }
121 
122 
123 /***********************************************************************//**
124  * @brief Get non-zero index vector
125  *
126  * @return Reference to non-zero pixel indices vector.
127  ***************************************************************************/
128 inline
129 const std::vector<int>& GSkyRegionMap::nonzero_indices(void) const
130 {
131  return (m_nonzero_indices);
132 }
133 
134 
135 /***********************************************************************//**
136  * @brief Return file name
137  *
138  * @return File name from which the region was loaded or into which
139  * the region was saved.
140  *
141  * Returns the file name from which the region was loaded or into
142  * which the region was saved. The returned string will be empty if
143  * no load() or save() method has been called before.
144  ***************************************************************************/
145 /*
146 inline
147 const GFilename& GSkyRegionMap::filename(void) const
148 {
149  return (m_filename);
150 }
151 */
152 
153 #endif /* GSKYREGIONMAP_HPP */
void set_nonzero_indices(void)
Create an array of non-zero pixel indices.
GSkyRegionMap(void)
Void constructor.
Sky map class.
Definition: GSkyMap.hpp:89
void copy_members(const GSkyRegionMap &region)
Copy class members.
const GSkyMap & map(void) const
Return sky map.
void compute_solid_angle(void)
Compute solid angle.
bool contains(const GSkyDir &dir) const
Check if a given direction is contained in this region.
Interface for the circular sky region class.
Interface for the rectangular sky region class.
Sky map class definition.
GSkyRegionMap & operator=(const GSkyRegionMap &region)
Assignment operator.
void clear(void)
Clear instance.
const std::vector< int > & nonzero_indices(void) const
Get non-zero index vector.
Abstract interface for the sky region class.
Definition: GSkyRegion.hpp:57
GSkyRegionMap * clone(void) const
Clone sky region map.
bool overlaps(const GSkyRegion &reg) const
Checks if a given region is overlapping with this region.
Filename class.
Definition: GFilename.hpp:62
virtual ~GSkyRegionMap(void)
Destructor.
void init_members(void)
Initialise class members.
GChatter
Definition: GTypemaps.hpp:33
Interface for a sky region map.
void free_members(void)
Delete class members.
void read(const std::string &line)
Create region from a string in DS9 format.
std::vector< int > m_nonzero_indices
Vector of non-zero pixel indices.
void set_region_circle(const GSkyRegionCircle *circle)
Set region map from region circle.
std::string write(void) const
Write string describing region in DS9 region format.
GSkyMap m_map
The region map.
void set_region_rectangle(const GSkyRegionRectangle *rect)
Set region map from region rectangle.
std::string print(const GChatter &chatter=NORMAL) const
Print region description.
void load(const GFilename &filename)
Load region map from FITS file.
std::string classname(void) const
Return class name.
Sky direction class.
Definition: GSkyDir.hpp:62
Abstract sky region base class interface definition.
Filename class interface definition.