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

Interface for the rectangular sky region class. More...

#include <GSkyRegionRectangle.hpp>

Inheritance diagram for GSkyRegionRectangle:
GSkyRegion GBase

Public Member Functions

 GSkyRegionRectangle (void)
 Void constructor. More...
 
 GSkyRegionRectangle (const GSkyDir &centre, const double &width, const double &height, const double &posang)
 Sky direction constructor. More...
 
 GSkyRegionRectangle (const double &ra, const double &dec, const double &width, const double &height, const double &posang)
 Right Ascension and Declination constructor. More...
 
 GSkyRegionRectangle (const std::string &line)
 String constructor. More...
 
 GSkyRegionRectangle (const GSkyRegionRectangle &region)
 Copy constructor. More...
 
virtual ~GSkyRegionRectangle (void)
 Destructor. More...
 
GSkyRegionRectangleoperator= (const GSkyRegionRectangle &region)
 Assignment operator. More...
 
void clear (void)
 Clear instance. More...
 
GSkyRegionRectangleclone (void) const
 Clone rectangular sky region. More...
 
std::string classname (void) const
 Return class name. More...
 
const GSkyDircentre (void) const
 Return rectangular region centre. More...
 
void centre (const GSkyDir &centre)
 Set rectangular region centre. More...
 
void centre (const double &ra, const double &dec)
 Set rectangular region centre Right Ascension and Declincation. More...
 
double ra (void) const
 Return rectangular region centre Right Ascension. More...
 
double dec (void) const
 Return rectangular region centre Declination. More...
 
const double & width (void) const
 Return region width extension (in degrees) More...
 
void width (const double &width)
 Set width of rectangular region. More...
 
const double & height (void) const
 Return region height extension (in degrees) More...
 
void height (const double &height)
 Set height of rectangular region. More...
 
const double & posang (void) const
 Return region position angle (in degrees) More...
 
void posang (const double &posang)
 Set position angle of rectangular region. More...
 
GSkyDir corner (const int &index) const
 Return sky direction of one corner of the rectangle. More...
 
void read (const std::string &line)
 Read region from DS9 string. More...
 
std::string write (void) const
 Write region into a string. More...
 
bool contains (const GSkyDir &dir) const
 Checks if sky direction lies within region. More...
 
bool contains (const GSkyRegion &reg) const
 Checks if region is fully contained within this region. More...
 
bool overlaps (const GSkyRegion &reg) const
 Checks if region is overlapping with this region. More...
 
std::string print (const GChatter &chatter=NORMAL) const
 Print rectangular region. More...
 
- Public Member Functions inherited from GSkyRegion
 GSkyRegion (void)
 Void constructor. More...
 
 GSkyRegion (const GSkyRegion &region)
 Copy constructor. More...
 
virtual ~GSkyRegion (void)
 Destructor. More...
 
virtual GSkyRegionoperator= (const GSkyRegion &region)
 Assignment operator. More...
 
const std::string & type (void) const
 Return region type. More...
 
const std::string & name (void) const
 Return region name. More...
 
const double & solidangle (void) const
 Return solid angle of region. More...
 
void type (const std::string &type)
 Set region type. More...
 
void name (const std::string &name)
 Set region name. More...
 
void solidangle (const double &solidangle)
 Set solid angle of region. 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 GSkyRegionRectangle &region)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
void compute_solid_angle (void)
 Compute solid angle of rectangle. More...
 
bool contains (const GSkyPixel &local) const
 Checks if local direction lies within region. More...
 
GSkyPixel dir_to_local (const GSkyDir &dir) const
 Transform sky direction to local rectangle coordinates. More...
 
GSkyDir local_to_dir (const GSkyPixel &local) const
 Transform local rectangle coordinates to sky direction. More...
 
- Protected Member Functions inherited from GSkyRegion
void init_members (void)
 Initialise class members. More...
 
void copy_members (const GSkyRegion &region)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 

Protected Attributes

GSkyDir m_centre
 Centre or reference point of the region. More...
 
double m_width
 Width of the region (degrees) More...
 
double m_height
 Height of the region (degrees) More...
 
double m_posang
 Position angle, counterclockwise from North (degrees) More...
 
- Protected Attributes inherited from GSkyRegion
std::string m_type
 Type of the region (circle, rectangle,...) More...
 
std::string m_name
 Name of the region. More...
 
double m_solid
 Solid angle subtended by the region (sr) More...
 

Detailed Description

Interface for the rectangular sky region class.

This class provides an implementation for a rectangular sky region. The sky region is defined by an array of parameters, the meaning of which is specific to the derived class where the region type or shape is defined.

The class holds several properties such as solid angle subtended by the region and computed through internal method compute_solid().

The position angle counts counter-clockwise from celestial North and is aligned with the height axis of the rectangle. Note, that height and width describe the diameter of the region.

Sky directions can be transformed to the local/global coordinate system via the methods transform_to_local() / transform_to_global(). The position (in global coordinates) of the 4 corners of the rectangle can be received via the method get_corner(index).

Definition at line 62 of file GSkyRegionRectangle.hpp.

Constructor & Destructor Documentation

GSkyRegionRectangle::GSkyRegionRectangle ( void  )

Void constructor.

Definition at line 62 of file GSkyRegionRectangle.cpp.

References init_members().

Referenced by clone().

GSkyRegionRectangle::GSkyRegionRectangle ( const GSkyDir centre,
const double &  width,
const double &  height,
const double &  posang 
)

Sky direction constructor.

Parameters
[in]centreCentre of rectangle.
[in]widthRegion width (degrees).
[in]heightRegion height (degrees).
[in]posangPosition angle (degrees).

Definition at line 80 of file GSkyRegionRectangle.cpp.

References centre(), compute_solid_angle(), height(), init_members(), posang(), and width().

GSkyRegionRectangle::GSkyRegionRectangle ( const double &  ra,
const double &  dec,
const double &  width,
const double &  height,
const double &  posang 
)

Right Ascension and Declination constructor.

Parameters
[in]raRight Ascension of region centre (degrees).
[in]decDeclination of region centre (degrees).
[in]widthRegion width (degrees).
[in]heightRegion height (degrees).
[in]posangPosition angle (degrees).

Definition at line 111 of file GSkyRegionRectangle.cpp.

References centre(), compute_solid_angle(), height(), init_members(), posang(), and width().

GSkyRegionRectangle::GSkyRegionRectangle ( const std::string &  line)
explicit

String constructor.

Parameters
[in]lineDS9 region file line.

Constructs region from a DS9 region file line.

Definition at line 141 of file GSkyRegionRectangle.cpp.

References init_members(), and read().

GSkyRegionRectangle::GSkyRegionRectangle ( const GSkyRegionRectangle region)

Copy constructor.

Parameters
[in]regionRectangular sky region.

Definition at line 160 of file GSkyRegionRectangle.cpp.

References copy_members(), and init_members().

GSkyRegionRectangle::~GSkyRegionRectangle ( void  )
virtual

Destructor.

Definition at line 177 of file GSkyRegionRectangle.cpp.

References free_members().

Member Function Documentation

const GSkyDir & GSkyRegionRectangle::centre ( void  ) const
inline

Return rectangular region centre.

Returns
Region centre.

Returns the region centre.

Definition at line 144 of file GSkyRegionRectangle.hpp.

References m_centre.

Referenced by GSkyRegionRectangle(), read(), and GSkyRegionMap::set_region_rectangle().

void GSkyRegionRectangle::centre ( const GSkyDir dir)
inline

Set rectangular region centre.

Parameters
[in]dirRegion centre.

Sets the centre of the rectangular region to the specified sky direction.

Definition at line 158 of file GSkyRegionRectangle.hpp.

References m_centre.

void GSkyRegionRectangle::centre ( const double &  ra,
const double &  dec 
)
inline

Set rectangular region centre Right Ascension and Declincation.

Parameters
[in]raRight Ascension (degrees).
[in]decDeclination (degrees).

Sets the centre of the rectangular region to the specified Right Ascension and Declination.

Definition at line 175 of file GSkyRegionRectangle.hpp.

References m_centre, and GSkyDir::radec_deg().

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

Return class name.

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

Implements GSkyRegion.

Definition at line 130 of file GSkyRegionRectangle.hpp.

void GSkyRegionRectangle::clear ( void  )
virtual

Clear instance.

Implements GSkyRegion.

Definition at line 232 of file GSkyRegionRectangle.cpp.

References GSkyRegion::free_members(), free_members(), GSkyRegion::init_members(), and init_members().

Referenced by read().

GSkyRegionRectangle * GSkyRegionRectangle::clone ( void  ) const
virtual

Clone rectangular sky region.

Returns
Deep copy to rectangular sky region.

Implements GSkyRegion.

Definition at line 252 of file GSkyRegionRectangle.cpp.

References GSkyRegionRectangle().

void GSkyRegionRectangle::compute_solid_angle ( void  )
protected

Compute solid angle of rectangle.

This method computes the solid angle of the rectangle in steradians and stores the result in the m_solid member.

The solid angle is computed using

\[ \Omega = 2 {\rm width} \sin \left( \frac{\rm height}{2} \right) \]

where \({\rm width}\) and \({\rm height}\) are the width and the height of the rectangle expressed in radians.

Definition at line 861 of file GSkyRegionRectangle.cpp.

References gammalib::deg2rad, m_height, GSkyRegion::m_solid, m_width, and sin().

Referenced by GSkyRegionRectangle(), height(), read(), and width().

bool GSkyRegionRectangle::contains ( const GSkyDir dir) const
virtual

Checks if sky direction lies within region.

Parameters
[in]dirSky direction.
Returns
True if sky direction is contained in region.

A sky direction lies within a region when its distance to the region centre is not larger than the region extension in both axes directions.

Implements GSkyRegion.

Definition at line 491 of file GSkyRegionRectangle.cpp.

References dir_to_local().

Referenced by contains(), and GSkyRegionMap::set_region_rectangle().

bool GSkyRegionRectangle::contains ( const GSkyRegion reg) const
virtual

Checks if region is fully contained within this region.

Parameters
[in]regSky region.
Returns
True if region is contained in region.
Exceptions
GException::feature_not_implementedNot all region types supported currently.

Implements GSkyRegion.

Definition at line 513 of file GSkyRegionRectangle.cpp.

References abs(), GSkyRegionCircle::centre(), contains(), corner(), dir_to_local(), G_CONTAINS, m_height, m_width, GSkyRegionMap::map(), GSkyRegionMap::nonzero_indices(), gammalib::rad2deg, GSkyRegionCircle::radius(), GSkyRegion::type(), GSkyPixel::x(), and GSkyPixel::y().

bool GSkyRegionRectangle::contains ( const GSkyPixel local) const
protected

Checks if local direction lies within region.

Parameters
[in]localSky direction in local coordinate system.

A local direction lies within a region when its distance to the region centre is not larger than the region extension in both axes directions.

Definition at line 879 of file GSkyRegionRectangle.cpp.

References abs(), contains(), m_height, m_width, gammalib::rad2deg, GSkyPixel::x(), and GSkyPixel::y().

void GSkyRegionRectangle::copy_members ( const GSkyRegionRectangle region)
protected

Copy class members.

Parameters
[in]regionRectangular sky region.

Definition at line 823 of file GSkyRegionRectangle.cpp.

References m_centre, m_height, m_posang, and m_width.

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

GSkyDir GSkyRegionRectangle::corner ( const int &  index) const

Return sky direction of one corner of the rectangle.

Parameters
[in]indexCorner index [0,3]
Returns
Sky direction of corner.
Exceptions
GException::out_of_rangeCorner index is not in [0,3].

Returns the sky direction of one corner of the rectangle. The corner index is counted counterclockwise from the positive Right Ascension and Declination directions:

  • index = 0 : \((\alpha + \frac{\rm width}{2}, \delta + \frac{\rm height}{2})\)
  • index = 1 : \((\alpha + \frac{\rm width}{2}, \delta - \frac{\rm height}{2})\)
  • index = 2 : \((\alpha - \frac{\rm width}{2}, \delta + \frac{\rm height}{2})\)
  • index = 3 : \((\alpha - \frac{\rm width}{2}, \delta - \frac{\rm height}{2})\)

where \(\alpha\) and \(\delta\) are the Right Ascension and Declination of the rectangle centre, and \({\rm width}\) and \({\rm height}\) are the width and height of the rectangle.

Definition at line 733 of file GSkyRegionRectangle.cpp.

References gammalib::deg2rad, G_CORNER, local_to_dir(), m_height, and m_width.

Referenced by GSkyRegionCircle::contains(), contains(), and GSkyRegionMap::set_region_rectangle().

double GSkyRegionRectangle::dec ( void  ) const
inline

Return rectangular region centre Declination.

Returns
Region centre Declination (degrees).

Returns the region centre Declination in degrees.

Definition at line 204 of file GSkyRegionRectangle.hpp.

References GSkyDir::dec_deg(), and m_centre.

Referenced by print(), and GSkyRegionMap::set_region_rectangle().

GSkyPixel GSkyRegionRectangle::dir_to_local ( const GSkyDir dir) const
protected

Transform sky direction to local rectangle coordinates.

Parameters
[in]dirSky direction.
Returns
Local cartesian region object coordinates.

Transform the sky direction dir to the local cartesian coordinate system. The local coordinates \((x,y)\) are defined by

\[ x = d \sin(\phi) \]

and

\[ y = d \cos(\phi) \]

where \(d\) is the angular distance between the sky direction dir and the centre of the rectangle in radians, and \(\phi\) is the position angle of the sky direction dir with respect to the position angle of the rectangle, computed counter clockwise.

Definition at line 930 of file GSkyRegionRectangle.cpp.

References cos(), gammalib::deg2rad, GSkyDir::dist(), m_centre, m_posang, GSkyDir::posang(), and sin().

Referenced by contains(), and overlaps().

void GSkyRegionRectangle::free_members ( void  )
protected

Delete class members.

Definition at line 839 of file GSkyRegionRectangle.cpp.

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

const double & GSkyRegionRectangle::height ( void  ) const
inline

Return region height extension (in degrees)

Returns
Region height (degrees).

Returns the region height extension in degrees.

Definition at line 232 of file GSkyRegionRectangle.hpp.

References m_height.

Referenced by GSkyRegionRectangle(), height(), overlaps(), print(), and read().

void GSkyRegionRectangle::height ( const double &  height)

Set height of rectangular region.

Parameters
[in]heightRectangle height (degrees).
Exceptions
GException::invalid_argumentHeight value is less than 0.

Sets the height of the rectangular sky region. Only non-negative heights are allowed.

Note that for a position angle of zero, the height axis is pointing to celestial north.

Definition at line 306 of file GSkyRegionRectangle.cpp.

References compute_solid_angle(), G_HEIGHT, height(), m_height, and gammalib::str().

void GSkyRegionRectangle::init_members ( void  )
protected

Initialise class members.

Definition at line 804 of file GSkyRegionRectangle.cpp.

References GSkyDir::clear(), m_centre, m_height, m_posang, GSkyRegion::m_type, and m_width.

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

GSkyDir GSkyRegionRectangle::local_to_dir ( const GSkyPixel local) const
protected

Transform local rectangle coordinates to sky direction.

Parameters
[in]localLocal rectangle coordinates.
Returns
Sky direction.

Transform the local coordinates local to a sky direction. See GSkyRegionRectangle::dir_to_local for the relation between local rectangle coordinates and the sky direction.

Definition at line 958 of file GSkyRegionRectangle.cpp.

References gammalib::atan2(), gammalib::deg2rad, m_centre, m_posang, gammalib::pihalf, GSkyDir::rotate(), sqrt(), GSkyPixel::x(), and GSkyPixel::y().

Referenced by corner().

GSkyRegionRectangle & GSkyRegionRectangle::operator= ( const GSkyRegionRectangle region)

Assignment operator.

Parameters
[in]regionRectangular sky region.
Returns
Rectangular sky region.

Definition at line 199 of file GSkyRegionRectangle.cpp.

References copy_members(), free_members(), init_members(), and GSkyRegion::operator=().

bool GSkyRegionRectangle::overlaps ( const GSkyRegion reg) const
virtual

Checks if region is overlapping with this region.

Parameters
[in]regSky region.
Returns
True if region overlaps with region.
Exceptions
GException::feature_not_implementedRegions differ in type.

Checks whether a region overlaps with the rectangle.

Todo:
Improve implementation for rectangle-rectangle

Implements GSkyRegion.

Definition at line 625 of file GSkyRegionRectangle.cpp.

References abs(), GSkyRegionCircle::centre(), dir_to_local(), G_CONTAINS, height(), GSkyRegionMap::overlaps(), gammalib::rad2deg, GSkyRegionCircle::radius(), GSkyRegion::type(), width(), GSkyPixel::x(), and GSkyPixel::y().

Referenced by GSkyRegionCircle::overlaps().

const double & GSkyRegionRectangle::posang ( void  ) const
inline

Return region position angle (in degrees)

Returns
Region position angle (degrees).

Returns the region position angle in degrees. The position angle is counted counterclockwise from North.

Definition at line 247 of file GSkyRegionRectangle.hpp.

References m_posang.

Referenced by GSkyRegionRectangle(), posang(), print(), and read().

void GSkyRegionRectangle::posang ( const double &  posang)
inline

Set position angle of rectangular region.

Parameters
[in]posangPosition angle (degrees).

Sets the position angle of the rectangular sky region. The position angle is counted counterclockwise from celestial North and is aligned to the rectangle height.

Definition at line 263 of file GSkyRegionRectangle.hpp.

References m_posang, and posang().

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

Print rectangular region.

Parameters
[in]chatterChattiness
Returns
String containing region information.

Implements GSkyRegion.

Definition at line 765 of file GSkyRegionRectangle.cpp.

References dec(), height(), gammalib::parformat(), posang(), ra(), SILENT, gammalib::str(), and width().

double GSkyRegionRectangle::ra ( void  ) const
inline

Return rectangular region centre Right Ascension.

Returns
Region centre Right Ascension (degrees).

Returns the region centre Right Ascension in degrees.

Definition at line 190 of file GSkyRegionRectangle.hpp.

References m_centre, and GSkyDir::ra_deg().

Referenced by print(), and GSkyRegionMap::set_region_rectangle().

void GSkyRegionRectangle::read ( const std::string &  line)
virtual

Read region from DS9 string.

Parameters
[in]lineString in DS9 format.
Exceptions
GException::invalid_valueInvalid value found in DS9 format string.

Implements GSkyRegion.

Definition at line 335 of file GSkyRegionRectangle.cpp.

References centre(), clear(), compute_solid_angle(), gammalib::contains(), G_READ, height(), GSkyDir::lb_deg(), GSkyRegion::m_name, posang(), GSkyDir::radec_deg(), gammalib::split(), gammalib::str(), gammalib::todouble(), and width().

Referenced by GSkyRegionRectangle(), and GSkyRegions::load().

const double & GSkyRegionRectangle::width ( void  ) const
inline

Return region width extension (in degrees)

Returns
Region width (degrees).

Returns the region width extension in degrees.

Definition at line 218 of file GSkyRegionRectangle.hpp.

References m_width.

Referenced by GSkyRegionRectangle(), overlaps(), print(), read(), and width().

void GSkyRegionRectangle::width ( const double &  width)

Set width of rectangular region.

Parameters
[in]widthRectangle width (degrees).
Exceptions
GException::invalid_argumentWidth value is less than 0.

Sets the width of the rectangular sky region. Only non-negative widths are allowed.

Definition at line 270 of file GSkyRegionRectangle.cpp.

References compute_solid_angle(), G_WIDTH, m_width, gammalib::str(), and width().

std::string GSkyRegionRectangle::write ( void  ) const
virtual

Write region into a string.

Returns
String to be written in a DS9 region file

Writes a DS9 region into a string. The region name is only written if it is defined.

Implements GSkyRegion.

Definition at line 453 of file GSkyRegionRectangle.cpp.

References GSkyDir::dec_deg(), m_centre, m_height, GSkyRegion::m_name, m_posang, m_width, GSkyDir::ra_deg(), and gammalib::str().

Member Data Documentation

GSkyDir GSkyRegionRectangle::m_centre
protected

Centre or reference point of the region.

Definition at line 117 of file GSkyRegionRectangle.hpp.

Referenced by centre(), copy_members(), dec(), dir_to_local(), init_members(), local_to_dir(), ra(), and write().

double GSkyRegionRectangle::m_height
protected

Height of the region (degrees)

Definition at line 119 of file GSkyRegionRectangle.hpp.

Referenced by compute_solid_angle(), contains(), copy_members(), corner(), height(), init_members(), and write().

double GSkyRegionRectangle::m_posang
protected

Position angle, counterclockwise from North (degrees)

Definition at line 120 of file GSkyRegionRectangle.hpp.

Referenced by copy_members(), dir_to_local(), init_members(), local_to_dir(), posang(), and write().

double GSkyRegionRectangle::m_width
protected

Width of the region (degrees)

Definition at line 118 of file GSkyRegionRectangle.hpp.

Referenced by compute_solid_angle(), contains(), copy_members(), corner(), init_members(), width(), and write().


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