GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GSkyRegions Class Reference

Sky region container class. More...

#include <GSkyRegions.hpp>

Inheritance diagram for GSkyRegions:
GContainer GBase

Public Member Functions

 GSkyRegions (void)
 Void constructor. More...
 
 GSkyRegions (const GSkyRegions &regions)
 Copy constructor. More...
 
 GSkyRegions (const GFilename &filename)
 Load constructor. More...
 
virtual ~GSkyRegions (void)
 Destructor. More...
 
GSkyRegionsoperator= (const GSkyRegions &regions)
 Assignment operator. More...
 
GSkyRegionoperator[] (const int &index)
 Return pointer to region. More...
 
const GSkyRegionoperator[] (const int &index) const
 Return pointer to region (const version) More...
 
void clear (void)
 Clear object. More...
 
GSkyRegionsclone (void) const
 Clone instance. More...
 
std::string classname (void) const
 Return class name. More...
 
GSkyRegionat (const int &index)
 Return pointer to region. More...
 
const GSkyRegionat (const int &index) const
 Return pointer to region (const version) More...
 
int size (void) const
 Return number of regions in container. More...
 
bool is_empty (void) const
 Signals if there are no regions in container. More...
 
GSkyRegionset (const int &index, const GSkyRegion &region)
 Set region in container. More...
 
GSkyRegionappend (const GSkyRegion &region)
 Append region to container. More...
 
GSkyRegioninsert (const int &index, const GSkyRegion &region)
 Insert region into container. More...
 
void remove (const int &index)
 Remove region from container. More...
 
void reserve (const int &num)
 Reserves space for regions in container. More...
 
void extend (const GSkyRegions &regions)
 Append region container. More...
 
bool contains (const GSkyDir &dir) const
 Check if direction is contained in one of the regions. More...
 
bool overlaps (const GSkyRegion &region) const
 Check if region overlaps one of the regions. More...
 
bool overlaps (const GSkyRegions &regions) const
 Check if any of the regions in two containers overlap. More...
 
void load (const GFilename &filename)
 Load regions from DS9 region file. More...
 
void save (const GFilename &filename) const
 Save regions into DS9 region file. More...
 
const GFilenamefilename (void) const
 Return regions file name. More...
 
void filename (const GFilename &filename)
 Set regions file name. More...
 
std::string print (const GChatter &chatter=NORMAL) const
 Print regions. More...
 
- Public Member Functions inherited from GContainer
virtual ~GContainer (void)
 Destructor. More...
 
- Public Member Functions inherited from GBase
virtual ~GBase (void)
 Destructor. More...
 

Protected Member Functions

void init_members (void)
 Initialise class members. More...
 
void copy_members (const GSkyRegions &regions)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 

Protected Attributes

GFilename m_filename
 Filename of origin. More...
 
std::vector< GSkyRegion * > m_regions
 List of regions. More...
 

Detailed Description

Sky region container class.

This container class collects sky regions objects derived from the GSkyRegion abstract class. These can be accessed from the access operator[] or through the at() method with index checking. Access to the region can be done from index or name, so the name of each region in the container has to be unique.

The object can be initialised from a DS9 region file, and has load and save methods from/to a DS9 region file.

Definition at line 56 of file GSkyRegions.hpp.

Constructor & Destructor Documentation

GSkyRegions::GSkyRegions ( void  )

Void constructor.

Definition at line 70 of file GSkyRegions.cpp.

References init_members().

Referenced by clone().

GSkyRegions::GSkyRegions ( const GSkyRegions regions)

Copy constructor.

Parameters
[in]regionsregion container.

Definition at line 85 of file GSkyRegions.cpp.

References copy_members(), and init_members().

GSkyRegions::GSkyRegions ( const GFilename filename)
explicit

Load constructor.

Parameters
[in]filenameDS9 region file.

Constructs region container from a DS9 region file.

Definition at line 105 of file GSkyRegions.cpp.

References init_members(), and load().

GSkyRegions::~GSkyRegions ( void  )
virtual

Destructor.

Definition at line 121 of file GSkyRegions.cpp.

References free_members().

Member Function Documentation

GSkyRegion * GSkyRegions::append ( const GSkyRegion region)

Append region to container.

Parameters
[in]regionregion.
Returns
Pointer to deep copy of region.
Exceptions
GException::invalid_valueName of region exists already in container.

Appends region to the container by making a deep copy of the region and storing its pointer.

Definition at line 297 of file GSkyRegions.cpp.

References GSkyRegion::clone(), and m_regions.

Referenced by load(), and GCTAOnOffObservation::set().

GSkyRegion * GSkyRegions::at ( const int &  index)

Return pointer to region.

Parameters
[in]indexSky region index [0,...,size()[.
Exceptions
GException::out_of_rangeSky region index is out of range.

Returns a pointer to the region with the specified index.

Definition at line 211 of file GSkyRegions.cpp.

References G_AT, m_regions, and size().

const GSkyRegion * GSkyRegions::at ( const int &  index) const

Return pointer to region (const version)

Parameters
[in]indexSky region index [0,...,size()[.
Exceptions
GException::out_of_rangeSky region index is out of range.

Returns a const pointer to the region with the specified index.

Definition at line 234 of file GSkyRegions.cpp.

References G_AT, m_regions, and size().

std::string GSkyRegions::classname ( void  ) const
inlinevirtual

Return class name.

Returns
String containing the class name ("GSkyRegions").

Implements GBase.

Definition at line 111 of file GSkyRegions.hpp.

void GSkyRegions::clear ( void  )
virtual

Clear object.

Removes all regions from the container.

Implements GBase.

Definition at line 175 of file GSkyRegions.cpp.

References free_members(), and init_members().

Referenced by GCTAObservation::init_members(), and load().

GSkyRegions * GSkyRegions::clone ( void  ) const
virtual

Clone instance.

Returns
Pointer to deep copy of region container

Makes a deep copy of the region container instance.

Implements GBase.

Definition at line 195 of file GSkyRegions.cpp.

References GSkyRegions().

Referenced by extend().

bool GSkyRegions::contains ( const GSkyDir dir) const

Check if direction is contained in one of the regions.

Parameters
[in]dirSky direction.
Returns
True if the sky direction is container in one of the regions, falls otherwise.

Checks if a sky direction is contained in one of the regions of the container.

Definition at line 430 of file GSkyRegions.cpp.

References m_regions, and size().

Referenced by GSkyMap::extract(), GSkyMap::flux(), GCTAOnOffObservation::set(), and GSkyMap::solidangle().

void GSkyRegions::copy_members ( const GSkyRegions regions)
protected

Copy class members.

Parameters
[in]regionsregion container.

Makes a copy of all class members. All regions are deep copied.

Definition at line 729 of file GSkyRegions.cpp.

References m_filename, and m_regions.

Referenced by GSkyRegions(), and operator=().

void GSkyRegions::extend ( const GSkyRegions regions)

Append region container.

Parameters
[in]regionsregion container.

Append region container to the container.

Definition at line 392 of file GSkyRegions.cpp.

References clone(), is_empty(), m_regions, reserve(), and size().

const GFilename & GSkyRegions::filename ( void  ) const
inline

Return regions file name.

Returns
File name from which the regions have been loaded or into which the regions have been saved.

Returns the file name from which the regions have been loaded or into which the regions have been saved. The returned string will be set if the load(), save() or filename() setter methods were called.

Definition at line 199 of file GSkyRegions.hpp.

References m_filename.

Referenced by filename(), load(), save(), and GCTAObservation::write().

void GSkyRegions::filename ( const GFilename filename)
inline

Set regions file name.

Parameters
[in]filenameRegions file name.

Set the regions file name.

Definition at line 213 of file GSkyRegions.hpp.

References filename(), and m_filename.

void GSkyRegions::free_members ( void  )
protected

Delete class members.

Deallocates all regions. The method loops over the region container and deallocates the memory that has been allocated before.

Definition at line 750 of file GSkyRegions.cpp.

References m_regions.

Referenced by clear(), operator=(), and ~GSkyRegions().

void GSkyRegions::init_members ( void  )
protected

Initialise class members.

Definition at line 711 of file GSkyRegions.cpp.

References GFilename::clear(), m_filename, and m_regions.

Referenced by clear(), GSkyRegions(), and operator=().

GSkyRegion * GSkyRegions::insert ( const int &  index,
const GSkyRegion region 
)

Insert region into container.

Parameters
[in]indexSky region index [0,...,size()[.
[in]regionSky region.
Returns
Pointer to deep copy of sky region.
Exceptions
GException::out_of_rangeSky region index is out of range.
GException::invalid_valueName of region exists already in container.

Inserts a region into the container before the region with the specified index.

Definition at line 325 of file GSkyRegions.cpp.

References GSkyRegion::clone(), G_INSERT1, is_empty(), m_regions, and size().

bool GSkyRegions::is_empty ( void  ) const
inlinevirtual

Signals if there are no regions in container.

Returns
True if container is empty, false otherwise.

Signals if the region container does not contain any region.

Implements GContainer.

Definition at line 167 of file GSkyRegions.hpp.

References m_regions.

Referenced by extend(), and insert().

void GSkyRegions::load ( const GFilename filename)

Load regions from DS9 region file.

Parameters
[in]filenameDS9 region filename.
Exceptions
GException::file_errorUnable to open file.

Loads all regions from a DS9 region file.

Definition at line 514 of file GSkyRegions.cpp.

References append(), clear(), filename(), G_LOAD, m_filename, GSkyRegionCircle::read(), GSkyRegionRectangle::read(), and GFilename::url().

Referenced by GSkyRegions().

GSkyRegions & GSkyRegions::operator= ( const GSkyRegions regions)

Assignment operator.

Parameters
[in]regionsregion container.
Returns
region container.

Definition at line 143 of file GSkyRegions.cpp.

References copy_members(), free_members(), and init_members().

GSkyRegion * GSkyRegions::operator[] ( const int &  index)
inline

Return pointer to region.

Parameters
[in]indexregion index [0,...,size()-1].

Returns a pointer to the region with the specified index.

Definition at line 125 of file GSkyRegions.hpp.

References m_regions.

const GSkyRegion * GSkyRegions::operator[] ( const int &  index) const
inline

Return pointer to region (const version)

Parameters
[in]indexregion index [0,...,size()-1].

Returns a const pointer to the region with the specified index.

Definition at line 139 of file GSkyRegions.hpp.

References m_regions.

bool GSkyRegions::overlaps ( const GSkyRegion region) const

Check if region overlaps one of the regions.

Parameters
[in]regionSky region.
Returns
True if region overlaps with one of the regions in the region container, false otherwise

Tells if region overlaps one of the regions

Definition at line 457 of file GSkyRegions.cpp.

References m_regions, and size().

Referenced by overlaps().

bool GSkyRegions::overlaps ( const GSkyRegions regions) const

Check if any of the regions in two containers overlap.

Parameters
[in]regionsSky region container.
Returns
True if one of the regions in the regions container overlaps with one of the regions in the container, false otherwise

Tells if all regions in overlaps one of the regions. Note, this method returns true if ANY of the regions in the two containers overlap with each other

Definition at line 486 of file GSkyRegions.cpp.

References m_regions, overlaps(), and size().

std::string GSkyRegions::print ( const GChatter chatter = NORMAL) const
virtual

Print regions.

Parameters
[in]chatterChattiness.
Returns
String containing region container information.

Prints all regions into a string.

Implements GBase.

Definition at line 675 of file GSkyRegions.cpp.

References m_regions, gammalib::parformat(), SILENT, size(), and gammalib::str().

void GSkyRegions::remove ( const int &  index)
virtual

Remove region from container.

Parameters
[in]indexSky region index [0,...,size()[.
Exceptions
GException::out_of_rangeSky region index is out of range.

Remove sky region of specified index from container.

Implements GContainer.

Definition at line 364 of file GSkyRegions.cpp.

References G_REMOVE1, m_regions, and size().

void GSkyRegions::reserve ( const int &  num)
inlinevirtual

Reserves space for regions in container.

Parameters
[in]numNumber of regions

Reserves space for num regions in the container.

Implements GContainer.

Definition at line 181 of file GSkyRegions.hpp.

References m_regions.

Referenced by extend().

void GSkyRegions::save ( const GFilename filename) const

Save regions into DS9 region file.

Parameters
[in]filenameDS9 region filename.
Exceptions
GException::file_errorUnable to open file.

Saves all regions in the container into a DS9 region file.

Definition at line 627 of file GSkyRegions.cpp.

References filename(), G_SAVE, m_filename, m_regions, size(), and GFilename::url().

GSkyRegion * GSkyRegions::set ( const int &  index,
const GSkyRegion region 
)

Set region in container.

Parameters
[in]indexSky region index [0,...,size()[.
[in]regionSky region.
Returns
Pointer to deep copy of sky region.
Exceptions
GException::out_of_rangeSky region index is out of range.
GException::invalid_valueName of region exists already in container.

Set sky region in the container. A deep copy of the region will be made.

Definition at line 261 of file GSkyRegions.cpp.

References GSkyRegion::clone(), G_SET1, m_regions, and size().

int GSkyRegions::size ( void  ) const
inlinevirtual

Return number of regions in container.

Returns
Number of regions in container.

Returns the number of regions in the region container.

Implements GContainer.

Definition at line 153 of file GSkyRegions.hpp.

References m_regions.

Referenced by GCTAOnOffObservation::arf_rad_max(), at(), GCTAOnOffObservation::compute_alpha(), GCTAOnOffObservation::compute_arf(), GCTAOnOffObservation::compute_arf_cut(), GCTAOnOffObservation::compute_bgd(), GCTAOnOffObservation::compute_rmf(), contains(), extend(), insert(), overlaps(), print(), remove(), save(), set(), and GCTAOnOffObservation::set().

Member Data Documentation

GFilename GSkyRegions::m_filename
mutableprotected

Filename of origin.

Definition at line 100 of file GSkyRegions.hpp.

Referenced by copy_members(), filename(), init_members(), load(), and save().

std::vector<GSkyRegion*> GSkyRegions::m_regions
protected

The documentation for this class was generated from the following files: