37 #define G_WIDTH "GSkyRegionRectangle::width(double&)"
38 #define G_HEIGHT "GSkyRegionRectangle::height(double&)"
39 #define G_READ "GSkyRegionRectangle::read(std::string&)"
40 #define G_CONTAINS "GSkyRegionRectangle::contains(GSkyRegion&)"
41 #define G_OVERLAPS "GSkyRegionRectangle::overlaps(GSkyRegion&)"
42 #define G_CORNER "GSkyRegionRectangle::corner(int&)"
114 const double& height,
202 if (
this != ®ion) {
275 "A negative width of "+
gammalib::str(width)+
" degrees has been "
276 "specified for a rectangular sky region. Please specify a "
277 "non-negative width.";
310 "A negative height of "+
gammalib::str(height)+
" degrees has been "
311 "specified for a rectangular sky region. Please specify a "
312 "non-negative height.";
342 std::string region_def = (!substrings.empty()) ? substrings[0] :
"";
343 std::string comment = (substrings.size() > 1) ? substrings[1] :
"";
346 if (region_def.find(
"box") == std::string::npos) {
348 "Unable to find the key word \"box\" in provided string "
349 "\""+line+
"\". The \"box\" key word is mandatory.";
357 unsigned pos = region_def.find(
"box(");
358 unsigned end = region_def.find(
")");
359 std::string regionstring = region_def.substr(pos+4, end);
360 regionstring.erase(regionstring.find(
")"), 1);
364 if (values.size() != 5) {
366 "Invalid number of "+
gammalib::str(values.size())+
" arguments "
367 "after the \"box\" key word in provided string \""+line+
"\". "
368 "Exactly 5 arguments are expected.";
401 if (system ==
"fk5" || system ==
"icrs") {
404 else if (system ==
"galactic") {
409 "Unsupported coordinate system \""+system+
"\" in provided string "
410 "\""+line+
"\". Only the following coordinate systems are "
411 "supported: \"fk5\", \"icrs\" and \"galactic\".";
426 for (
int i = 0; i < comments.size(); ++i) {
428 std::vector<std::string> attributes =
gammalib::split(comments[i],
"=");
429 if (attributes.size() < 2) {
431 "Invalid character sequence encountered in provided "
432 "string \""+line+
"\". An attribute of the type "
433 "\"text=Name\" is expected.";
459 result.append(
"fk5;box(");
472 if (
m_name.length() > 0) {
473 result.append(
" # text=");
520 if (reg.
type() ==
"Circle") {
532 double radius = circle->
radius();
545 else if (reg.
type() ==
"Rectangle") {
555 for (
int i = 0; i < 4; ++i) {
573 else if (reg.
type() ==
"Map") {
585 for (
int i = 0; i < indices.size(); ++i) {
604 "Cannot compare to region type \""+reg.
type()+
"\" yet.");
628 bool overlap =
false;
633 if (reg.
type() ==
"Circle") {
645 double radius = circle->
radius();
648 double half_width = 0.5 *
width();
649 double half_height = 0.5 *
height();
652 if (x_deg > (half_width + radius)) {
655 else if (y_deg > (half_height + radius)) {
658 else if (x_deg <= half_width) {
661 else if (y_deg <= half_height) {
665 double dx = x_deg - half_width;
666 double dy = y_deg - half_height;
667 double d2 = dx * dx + dy * dy;
668 if (d2 <= radius*radius) {
677 else if (reg.
type() ==
"Rectangle") {
690 else if (reg.
type() ==
"Map") {
703 "Cannot compare to region type \""+reg.
type()+
"\" yet.");
736 if ((index < 0) || (index > 3)) {
741 double dx = 0.5 *
m_width * (1 - 2*int(index >= 2));
742 double dy = 0.5 *
m_height * (1 - 2*int((index==1) || (index==2)));
774 result.append(
"=== GSkyRegionRectangle ===");
961 double x = local.
x();
962 double y = local.
y();
bool contains(const std::string &str, const std::string &substring)
Checks if a substring is in a string.
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.
double m_solid
Solid angle subtended by the region (sr)
Rectangular sky region class interface definition.
void free_members(void)
Delete class members.
double dec_deg(void) const
Returns Declination in degrees.
void x(const double &x)
Set x value of sky map pixel.
std::string print(const GChatter &chatter=NORMAL) const
Print rectangular region.
GSkyRegionRectangle * clone(void) const
Clone rectangular sky region.
GVector abs(const GVector &vector)
Computes absolute of vector elements.
GSkyRegionRectangle & operator=(const GSkyRegionRectangle ®ion)
Assignment operator.
double dec(void) const
Return rectangular region centre Declination.
void free_members(void)
Delete class members.
GVector cos(const GVector &vector)
Computes cosine of vector elements.
void init_members(void)
Initialise class members.
const std::string & type(void) const
Return region type.
std::vector< std::string > split(const std::string &s, const std::string &sep)
Split string.
GSkyDir local_to_dir(const GSkyPixel &local) const
Transform local rectangle coordinates to sky direction.
void y(const double &y)
Set y value of sky map pixel.
Interface for the circular sky region class.
const double & posang(void) const
Return region position angle (in degrees)
Interface for the rectangular sky region class.
std::string m_type
Type of the region (circle, rectangle,...)
std::string centre(const std::string &s, const int &n, const char &c= ' ')
Centre string to achieve a length of n characters.
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.
const double & radius(void) const
Return circular region radius (in degrees)
void map(const GSkyMap &map)
Set sky map.
const double & width(void) const
Return region width extension (in degrees)
GVector sqrt(const GVector &vector)
Computes square root of vector elements.
const std::vector< int > & nonzero_indices(void) const
Get non-zero index vector.
Abstract interface for the sky region class.
double m_width
Width of the region (degrees)
std::string m_name
Name of the region.
bool overlaps(const GSkyRegion ®) const
Checks if a given region is overlapping with this region.
bool contains(const GSkyDir &dir) const
Checks if sky direction lies within region.
void rotate(const double &phi, const double &theta)
Rotate sky direction by zenith and azimuth angle.
GSkyRegionRectangle(void)
Void constructor.
virtual GSkyRegion & operator=(const GSkyRegion ®ion)
Assignment operator.
double ra_deg(void) const
Returns Right Ascension in degrees.
Interface for a sky region map.
void radec_deg(const double &ra, const double &dec)
Set equatorial sky direction (degrees)
void copy_members(const GSkyRegionRectangle ®ion)
Copy class members.
bool overlaps(const GSkyRegion ®) const
Checks if region is overlapping with this region.
double posang(const GSkyDir &dir, const std::string &coordsys="CEL") const
Compute position angle between sky directions in radians.
void clear(void)
Clear instance.
const GSkyDir & centre(void) const
Return circular region centre.
void clear(void)
Clear sky direction.
double ra(void) const
Return rectangular region centre Right Ascension.
Sky region map class interface definition.
void lb_deg(const double &l, const double &b)
Set galactic sky direction (degrees)
GVector sin(const GVector &vector)
Computes sine of vector elements.
double dist(const GSkyDir &dir) const
Compute angular distance between sky directions in radians.
GSkyDir corner(const int &index) const
Return sky direction of one corner of the rectangle.
double atan2(const double &y, const double &x)
Compute arc tangens in radians.
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.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
void read(const std::string &line)
Read region from DS9 string.
Circular sky region class interface definition.
virtual ~GSkyRegionRectangle(void)
Destructor.
double todouble(const std::string &arg)
Convert string into double precision value.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.