Commit bed0350acbbbe147ef8c6c0f87815cc9a9e8fbd5
1 parent
7ddd1bc2
Review of GSkyRegionRect code (#3248)
Showing
5 changed files
with
289 additions
and
344 deletions
include/GSkyRegionMap.hpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GSkyRegionMap.hpp - Sky region map class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2017-2018 by Pierrick Martin * | |
| 4 | + * copyright (C) 2017-2020 by Pierrick Martin * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * | ... | ... |
include/GSkyRegionRect.hpp
| ... | ... | @@ -30,10 +30,12 @@ |
| 30 | 30 | /* __ Includes ___________________________________________________________ */ |
| 31 | 31 | #include <vector> |
| 32 | 32 | #include <string> |
| 33 | -#include "GMath.hpp" | |
| 33 | +//#include "GMath.hpp" | |
| 34 | 34 | #include "GSkyDir.hpp" |
| 35 | 35 | #include "GSkyRegion.hpp" |
| 36 | -#include "GTools.hpp" | |
| 36 | +//#include "GTools.hpp" | |
| 37 | + | |
| 38 | +/* __ Forward declarations _______________________________________________ */ | |
| 37 | 39 | |
| 38 | 40 | |
| 39 | 41 | /***********************************************************************//** |
| ... | ... | @@ -63,14 +65,15 @@ class GSkyRegionRect : public GSkyRegion { |
| 63 | 65 | public: |
| 64 | 66 | // Constructors and destructors |
| 65 | 67 | GSkyRegionRect(void); |
| 66 | - GSkyRegionRect(const GSkyDir& centre | |
| 67 | - ,const double& w, const double& h | |
| 68 | - ,const double& posang_deg | |
| 69 | - ); | |
| 70 | - GSkyRegionRect(const double& ra, const double& dec | |
| 71 | - ,const double& w, const double& h | |
| 72 | - ,const double& posang_deg | |
| 73 | - ); | |
| 68 | + GSkyRegionRect(const GSkyDir& centre, | |
| 69 | + const double& width, | |
| 70 | + const double& height, | |
| 71 | + const double& posang); | |
| 72 | + GSkyRegionRect(const double& ra, | |
| 73 | + const double& dec, | |
| 74 | + const double& width, | |
| 75 | + const double& height, | |
| 76 | + const double& posang); | |
| 74 | 77 | explicit GSkyRegionRect(const std::string& line); |
| 75 | 78 | GSkyRegionRect(const GSkyRegionRect& region); |
| 76 | 79 | virtual ~GSkyRegionRect(void); |
| ... | ... | @@ -79,33 +82,30 @@ public: |
| 79 | 82 | GSkyRegionRect& operator=(const GSkyRegionRect& region); |
| 80 | 83 | |
| 81 | 84 | // Implemented methods |
| 82 | - void clear(void); | |
| 83 | - GSkyRegionRect* clone(void) const; | |
| 84 | - std::string classname(void) const; | |
| 85 | - double posang(void) const; | |
| 86 | - void posang(const double& posang); | |
| 87 | - double posang_deg(void) const; | |
| 88 | - void posang_deg(const double& posang); | |
| 89 | - double width(void) const; | |
| 90 | - void width(const double& width); | |
| 91 | - double height(void) const; | |
| 92 | - void height(const double& height); | |
| 93 | - const GSkyDir& centre(void) const; | |
| 94 | - void centre(const GSkyDir& centre); | |
| 95 | - void centre(const double& ra,const double& dec); | |
| 96 | - double ra(void) const; | |
| 97 | - double dec(void) const; | |
| 98 | - void read(const std::string& line); | |
| 99 | - std::string write(void) const; | |
| 100 | - bool contains(const GSkyDir& dir) const; | |
| 101 | - bool contains_local(const GSkyDir& locdir) const; | |
| 102 | - bool contains(const GSkyRegion& reg) const; | |
| 103 | - bool overlaps(const GSkyRegion& reg) const; | |
| 104 | - std::string print(const GChatter& chatter = NORMAL) const; | |
| 105 | - | |
| 106 | - GSkyDir transform_to_local(const GSkyDir& skydir) const; | |
| 107 | - GSkyDir transform_to_global(const GSkyDir& locdir) const; | |
| 108 | - GSkyDir get_corner(const int& index) const; | |
| 85 | + void clear(void); | |
| 86 | + GSkyRegionRect* clone(void) const; | |
| 87 | + std::string classname(void) const; | |
| 88 | + const GSkyDir& centre(void) const; | |
| 89 | + void centre(const GSkyDir& centre); | |
| 90 | + void centre(const double& ra,const double& dec); | |
| 91 | + double ra(void) const; | |
| 92 | + double dec(void) const; | |
| 93 | + const double& width(void) const; | |
| 94 | + void width(const double& width); | |
| 95 | + const double& height(void) const; | |
| 96 | + void height(const double& height); | |
| 97 | + const double& posang(void) const; | |
| 98 | + void posang(const double& posang); | |
| 99 | + void read(const std::string& line); | |
| 100 | + std::string write(void) const; | |
| 101 | + bool contains(const GSkyDir& dir) const; | |
| 102 | + bool contains_local(const GSkyDir& locdir) const; | |
| 103 | + bool contains(const GSkyRegion& reg) const; | |
| 104 | + bool overlaps(const GSkyRegion& reg) const; | |
| 105 | + GSkyDir transform_to_local(const GSkyDir& skydir) const; | |
| 106 | + GSkyDir transform_to_global(const GSkyDir& locdir) const; | |
| 107 | + GSkyDir get_corner(const int& index) const; | |
| 108 | + std::string print(const GChatter& chatter = NORMAL) const; | |
| 109 | 109 | |
| 110 | 110 | protected: |
| 111 | 111 | // Protected methods |
| ... | ... | @@ -116,9 +116,9 @@ protected: |
| 116 | 116 | |
| 117 | 117 | // Protected members |
| 118 | 118 | GSkyDir m_centre; //!< Centre or reference point of the region |
| 119 | - double m_halfwidth; //!< Half width of the region [deg] | |
| 120 | - double m_halfheight; //!< Half height of the region [deg] | |
| 121 | - double m_posang; //!< Position angle, counterclockwise from North [radians] | |
| 119 | + double m_width; //!< Width of the region (degrees) | |
| 120 | + double m_height; //!< Height of the region (degrees) | |
| 121 | + double m_posang; //!< Position angle, counterclockwise from North (degrees) | |
| 122 | 122 | }; |
| 123 | 123 | |
| 124 | 124 | |
| ... | ... | @@ -135,144 +135,136 @@ std::string GSkyRegionRect::classname(void) const |
| 135 | 135 | |
| 136 | 136 | |
| 137 | 137 | /***********************************************************************//** |
| 138 | - * @brief Return region position angle (in radians) | |
| 138 | + * @brief Return rectangular region centre | |
| 139 | 139 | * |
| 140 | - * @return Region position angle [radians]. | |
| 140 | + * @return Region centre. | |
| 141 | 141 | * |
| 142 | - * Returns the region position angle in radians. The position angle is | |
| 143 | - * counted counterclockwise from North. | |
| 142 | + * Returns the region centre. | |
| 144 | 143 | ***************************************************************************/ |
| 145 | 144 | inline |
| 146 | -double GSkyRegionRect::posang(void) const | |
| 145 | +const GSkyDir& GSkyRegionRect::centre(void) const | |
| 147 | 146 | { |
| 148 | - // Return | |
| 149 | - return (m_posang); | |
| 147 | + return (m_centre); | |
| 150 | 148 | } |
| 151 | 149 | |
| 152 | 150 | |
| 153 | 151 | /***********************************************************************//** |
| 154 | - * @brief Return region position angle (in degrees) | |
| 152 | + * @brief Set rectangular region centre | |
| 155 | 153 | * |
| 156 | - * @return Region position angle [degrees]. | |
| 154 | + * @param[in] dir Region centre. | |
| 157 | 155 | * |
| 158 | - * Returns the region position angle in degrees. The position angle is | |
| 159 | - * counted counterclockwise from North. | |
| 156 | + * Sets the centre of the rectangular region to the specified sky direction. | |
| 160 | 157 | ***************************************************************************/ |
| 161 | 158 | inline |
| 162 | -double GSkyRegionRect::posang_deg(void) const | |
| 159 | +void GSkyRegionRect::centre(const GSkyDir& dir) | |
| 163 | 160 | { |
| 164 | - // Return | |
| 165 | - return (m_posang * gammalib::rad2deg); | |
| 161 | + m_centre = dir; | |
| 162 | + return; | |
| 166 | 163 | } |
| 167 | 164 | |
| 168 | 165 | |
| 169 | 166 | /***********************************************************************//** |
| 170 | - * @brief Return region width extension (in degrees) | |
| 167 | + * @brief Set rectangular region centre Right Ascension and Declincation | |
| 171 | 168 | * |
| 172 | - * @return Region width [deg]. | |
| 169 | + * @param[in] ra Right Ascension (degrees). | |
| 170 | + * @param[in] dec Declination (degrees). | |
| 173 | 171 | * |
| 174 | - * Returns the region width extension in degrees. | |
| 172 | + * Sets the centre of the rectangular region to the specified Right Ascension | |
| 173 | + * and Declination. | |
| 175 | 174 | ***************************************************************************/ |
| 176 | 175 | inline |
| 177 | -double GSkyRegionRect::width(void) const | |
| 176 | +void GSkyRegionRect::centre(const double& ra, const double& dec) | |
| 178 | 177 | { |
| 179 | - double width = 2*m_halfwidth; | |
| 180 | - return (width); | |
| 178 | + m_centre.radec_deg(ra, dec); | |
| 179 | + return; | |
| 181 | 180 | } |
| 182 | 181 | |
| 183 | 182 | |
| 184 | 183 | /***********************************************************************//** |
| 185 | - * @brief Return region height extension (in degrees) | |
| 184 | + * @brief Return rectangular region centre Right Ascension | |
| 186 | 185 | * |
| 187 | - * @return Region height [deg]. | |
| 186 | + * @return Region centre Right Ascension (degrees). | |
| 188 | 187 | * |
| 189 | - * Returns the region height extension in degrees. | |
| 188 | + * Returns the region centre Right Ascension in degrees. | |
| 190 | 189 | ***************************************************************************/ |
| 191 | 190 | inline |
| 192 | -double GSkyRegionRect::height(void) const | |
| 191 | +double GSkyRegionRect::ra(void) const | |
| 193 | 192 | { |
| 194 | - double height = 2*m_halfheight; | |
| 195 | - return (height); | |
| 193 | + return (m_centre.ra_deg()); | |
| 196 | 194 | } |
| 197 | 195 | |
| 198 | 196 | |
| 199 | 197 | /***********************************************************************//** |
| 200 | - * @brief Return rectangular region centre | |
| 198 | + * @brief Return rectangular region centre Declination | |
| 201 | 199 | * |
| 202 | - * @return Region centre. | |
| 200 | + * @return Region centre Declination (degrees). | |
| 203 | 201 | * |
| 204 | - * Returns the region centre. | |
| 202 | + * Returns the region centre Declination in degrees. | |
| 205 | 203 | ***************************************************************************/ |
| 206 | 204 | inline |
| 207 | -const GSkyDir& GSkyRegionRect::centre(void) const | |
| 205 | +double GSkyRegionRect::dec(void) const | |
| 208 | 206 | { |
| 209 | - return (m_centre); | |
| 207 | + return (m_centre.dec_deg()); | |
| 210 | 208 | } |
| 211 | 209 | |
| 212 | 210 | |
| 213 | 211 | /***********************************************************************//** |
| 214 | - * @brief Set rectangular region centre | |
| 212 | + * @brief Return region width extension (in degrees) | |
| 215 | 213 | * |
| 216 | - * @param[in] dir Region centre. | |
| 214 | + * @return Region width (degrees). | |
| 217 | 215 | * |
| 218 | - * Sets the centre of the rectangular region to the specified sky direction. | |
| 216 | + * Returns the region width extension in degrees. | |
| 219 | 217 | ***************************************************************************/ |
| 220 | 218 | inline |
| 221 | -void GSkyRegionRect::centre(const GSkyDir& dir) | |
| 219 | +const double& GSkyRegionRect::width(void) const | |
| 222 | 220 | { |
| 223 | - // Set centre | |
| 224 | - m_centre = dir; | |
| 225 | - | |
| 226 | - // Return | |
| 227 | - return; | |
| 221 | + return (m_width); | |
| 228 | 222 | } |
| 229 | 223 | |
| 230 | 224 | |
| 231 | 225 | /***********************************************************************//** |
| 232 | - * @brief Set rectangular region centre Right Ascension and Declincation | |
| 226 | + * @brief Return region height extension (in degrees) | |
| 233 | 227 | * |
| 234 | - * @param[in] ra Right Ascension [deg]. | |
| 235 | - * @param[in] dec Declination [deg]. | |
| 228 | + * @return Region height (degrees). | |
| 236 | 229 | * |
| 237 | - * Sets the centre of the rectangular region to the specified Right Ascension | |
| 238 | - * and Declination. | |
| 230 | + * Returns the region height extension in degrees. | |
| 239 | 231 | ***************************************************************************/ |
| 240 | 232 | inline |
| 241 | -void GSkyRegionRect::centre(const double& ra, const double& dec) | |
| 233 | +const double& GSkyRegionRect::height(void) const | |
| 242 | 234 | { |
| 243 | - // Set centre values | |
| 244 | - m_centre.radec_deg(ra,dec); | |
| 245 | - | |
| 246 | - // Return | |
| 247 | - return; | |
| 235 | + return (m_height); | |
| 248 | 236 | } |
| 249 | 237 | |
| 250 | 238 | |
| 251 | 239 | /***********************************************************************//** |
| 252 | - * @brief Return rectangular region centre Right Ascension | |
| 240 | + * @brief Return region position angle (in degrees) | |
| 253 | 241 | * |
| 254 | - * @return Region centre Right Ascension [deg]. | |
| 242 | + * @return Region position angle (degrees). | |
| 255 | 243 | * |
| 256 | - * Returns the region centre Right Ascension in degrees. | |
| 244 | + * Returns the region position angle in degrees. The position angle is | |
| 245 | + * counted counterclockwise from North. | |
| 257 | 246 | ***************************************************************************/ |
| 258 | 247 | inline |
| 259 | -double GSkyRegionRect::ra(void) const | |
| 248 | +const double& GSkyRegionRect::posang(void) const | |
| 260 | 249 | { |
| 261 | - return (m_centre.ra_deg()); | |
| 250 | + return (m_posang); | |
| 262 | 251 | } |
| 263 | 252 | |
| 264 | 253 | |
| 265 | 254 | /***********************************************************************//** |
| 266 | - * @brief Return rectangular region centre Declination | |
| 255 | + * @brief Set position angle of rectangular region | |
| 267 | 256 | * |
| 268 | - * @return Region centre Declination [deg]. | |
| 257 | + * @param[in] posang Position angle (degrees). | |
| 269 | 258 | * |
| 270 | - * Returns the region centre Declination in degrees. | |
| 259 | + * Sets the position angle of the rectangular sky region. The position angle | |
| 260 | + * is counted counterclockwise from celestial North and is aligned to the | |
| 261 | + * rectangle height. | |
| 271 | 262 | ***************************************************************************/ |
| 272 | 263 | inline |
| 273 | -double GSkyRegionRect::dec(void) const | |
| 264 | +void GSkyRegionRect::posang(const double& posang) | |
| 274 | 265 | { |
| 275 | - return (m_centre.dec_deg()); | |
| 266 | + m_posang = posang; | |
| 267 | + return; | |
| 276 | 268 | } |
| 277 | 269 | |
| 278 | 270 | #endif /* GSKYREGIONRECT_HPP */ | ... | ... |
pyext/GSkyRegionRect.i
| ... | ... | @@ -35,48 +35,47 @@ |
| 35 | 35 | * @brief Interface for the rectangular sky region class |
| 36 | 36 | ***************************************************************************/ |
| 37 | 37 | class GSkyRegionRect : public GSkyRegion { |
| 38 | + | |
| 38 | 39 | public: |
| 39 | 40 | // Constructors and destructors |
| 40 | 41 | GSkyRegionRect(void); |
| 41 | - GSkyRegionRect(const GSkyDir& centre | |
| 42 | - ,const double& w, const double& h | |
| 43 | - ,const double& posang_deg | |
| 44 | - ); | |
| 45 | - GSkyRegionRect(const double& ra, const double& dec | |
| 46 | - ,const double& w, const double& h | |
| 47 | - ,const double& posang_deg | |
| 48 | - ); | |
| 42 | + GSkyRegionRect(const GSkyDir& centre, | |
| 43 | + const double& width, | |
| 44 | + const double& height, | |
| 45 | + const double& posang); | |
| 46 | + GSkyRegionRect(const double& ra, | |
| 47 | + const double& dec, | |
| 48 | + const double& width, | |
| 49 | + const double& height, | |
| 50 | + const double& posang); | |
| 49 | 51 | explicit GSkyRegionRect(const std::string& line); |
| 50 | 52 | GSkyRegionRect(const GSkyRegionRect& region); |
| 51 | 53 | virtual ~GSkyRegionRect(void); |
| 52 | 54 | |
| 53 | 55 | // Implemented methods |
| 54 | - void clear(void); | |
| 55 | - GSkyRegionRect* clone(void) const; | |
| 56 | - std::string classname(void) const; | |
| 57 | - double posang(void) const; | |
| 58 | - void posang(const double& posang); | |
| 59 | - double posang_deg(void) const; | |
| 60 | - void posang_deg(const double& posang); | |
| 61 | - double width(void) const; | |
| 62 | - void width(const double& width); | |
| 63 | - double height(void) const; | |
| 64 | - void height(const double& height); | |
| 65 | - const GSkyDir& centre(void) const; | |
| 66 | - void centre(const GSkyDir& centre); | |
| 67 | - void centre(const double& ra,const double& dec); | |
| 68 | - double ra(void) const; | |
| 69 | - double dec(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_local(const GSkyDir& locdir) const; | |
| 74 | - bool contains(const GSkyRegion& reg) const; | |
| 75 | - bool overlaps(const GSkyRegion& reg) const; | |
| 76 | - | |
| 77 | - GSkyDir transform_to_local(const GSkyDir& skydir) const; | |
| 78 | - GSkyDir transform_to_global(const GSkyDir& localdir) const; | |
| 79 | - GSkyDir get_corner(const int& index) const; | |
| 56 | + void clear(void); | |
| 57 | + GSkyRegionRect* clone(void) const; | |
| 58 | + std::string classname(void) const; | |
| 59 | + const GSkyDir& centre(void) const; | |
| 60 | + void centre(const GSkyDir& centre); | |
| 61 | + void centre(const double& ra,const double& dec); | |
| 62 | + double ra(void) const; | |
| 63 | + double dec(void) const; | |
| 64 | + const double& width(void) const; | |
| 65 | + void width(const double& width); | |
| 66 | + const double& height(void) const; | |
| 67 | + void height(const double& height); | |
| 68 | + const double& posang(void) const; | |
| 69 | + void posang(const double& posang); | |
| 70 | + void read(const std::string& line); | |
| 71 | + std::string write(void) const; | |
| 72 | + bool contains(const GSkyDir& dir) const; | |
| 73 | + bool contains_local(const GSkyDir& locdir) const; | |
| 74 | + bool contains(const GSkyRegion& reg) const; | |
| 75 | + bool overlaps(const GSkyRegion& reg) const; | |
| 76 | + GSkyDir transform_to_local(const GSkyDir& skydir) const; | |
| 77 | + GSkyDir transform_to_global(const GSkyDir& locdir) const; | |
| 78 | + GSkyDir get_corner(const int& index) const; | |
| 80 | 79 | }; |
| 81 | 80 | |
| 82 | 81 | ... | ... |
src/sky/GSkyRegionMap.cpp
| ... | ... | @@ -657,24 +657,24 @@ void GSkyRegionMap::set_region_circle(const GSkyRegionCircle* circle) |
| 657 | 657 | * @param[in] rect Region rectangle |
| 658 | 658 | * |
| 659 | 659 | * Sets a region map from a region rectangle. |
| 660 | - * A skymap is allocated with a resolution goal of 0.01 degrees (same for both | |
| 661 | - * axes). | |
| 662 | - * The particular resolution of either axes depends on the w/h of the RoI of the | |
| 663 | - * rotated rectangle. | |
| 664 | - * The map extent is chosen dynamically to match the RoI of the rotated rectangle. | |
| 665 | - * Three sparse pixels are added at either side of the map. | |
| 666 | - * The sky map is created in celestial coordinates and TAN projection. | |
| 660 | + * | |
| 661 | + * A skymap is allocated with a resolution goal of 0.01 degrees (same for | |
| 662 | + * both axes). The particular resolution of either axes depends on the width | |
| 663 | + * over height of the RoI of the rotated rectangle. The map extent is chosen | |
| 664 | + * dynamically to match the RoI of the rotated rectangle. Three sparse pixels | |
| 665 | + * are added at either side of the map. The sky map is created in celestial | |
| 666 | + * coordinates and TAN projection. | |
| 667 | 667 | ***************************************************************************/ |
| 668 | 668 | void GSkyRegionMap::set_region_rect(const GSkyRegionRect* rect) |
| 669 | 669 | { |
| 670 | 670 | // Define desired resolution (in degrees) |
| 671 | - const double resolution_goal = 0.01; | |
| 671 | + const double resolution_goal = 0.01; | |
| 672 | 672 | |
| 673 | 673 | // Try to estimate extent of the (rotated) rectangle: |
| 674 | 674 | // Loop over the rectangle corners to get the extension |
| 675 | - double dxmax=0; | |
| 676 | - double dymax=0; | |
| 677 | - for(int icorner=0; icorner<4; ++icorner) { | |
| 675 | + double dxmax = 0.0; | |
| 676 | + double dymax = 0.0; | |
| 677 | + for (int icorner = 0; icorner < 4; ++icorner) { | |
| 678 | 678 | |
| 679 | 679 | // Get skydir of current corner |
| 680 | 680 | GSkyDir corner = rect->get_corner(icorner); |
| ... | ... | @@ -691,22 +691,19 @@ void GSkyRegionMap::set_region_rect(const GSkyRegionRect* rect) |
| 691 | 691 | if (dy > dymax) { |
| 692 | 692 | dymax = dy; |
| 693 | 693 | } |
| 694 | - | |
| 695 | 694 | if (dx > dxmax) { |
| 696 | 695 | dxmax = dx; |
| 697 | 696 | } |
| 698 | - } | |
| 697 | + | |
| 698 | + } // endfor: looped over all corners | |
| 699 | 699 | |
| 700 | 700 | // Compute width of map RoI in degrees |
| 701 | - double map_width = 2*dxmax *gammalib::rad2deg; | |
| 702 | - double map_height = 2*dymax *gammalib::rad2deg; | |
| 703 | - // std::cout<<"Generate map for rectangle:\n"<<(*rect)<<std::endl; | |
| 704 | - // std::cout<<"Found map extension: (w,h)=("<<map_width<<","<<map_height<<")\n"; | |
| 701 | + double map_width = 2.0 * dxmax * gammalib::rad2deg; | |
| 702 | + double map_height = 2.0 * dymax * gammalib::rad2deg; | |
| 705 | 703 | |
| 706 | 704 | // Compute num of bins in x direction, round |
| 707 | - int nbins_x = int(map_width / resolution_goal +0.5); | |
| 708 | - int nbins_y = int(map_height / resolution_goal +0.5); | |
| 709 | - // std::cout<<" nbins: x="<<nbins_x<<", y="<<nbins_y<<std::endl; | |
| 705 | + int nbins_x = int(map_width / resolution_goal + 0.5); | |
| 706 | + int nbins_y = int(map_height / resolution_goal + 0.5); | |
| 710 | 707 | |
| 711 | 708 | // Ensure a minimum num of bins |
| 712 | 709 | if (nbins_x < 10) { |
| ... | ... | @@ -719,7 +716,6 @@ void GSkyRegionMap::set_region_rect(const GSkyRegionRect* rect) |
| 719 | 716 | // Compute actual resolution using nbins |
| 720 | 717 | double resolution_x = map_width / nbins_x; |
| 721 | 718 | double resolution_y = map_height / nbins_y; |
| 722 | - // std::cout<<" resolution for roi: x="<<resolution_x<<", y="<<resolution_y<<std::endl; | |
| 723 | 719 | |
| 724 | 720 | // Add leakage pixels |
| 725 | 721 | nbins_x += 6; |
| ... | ... | @@ -728,22 +724,18 @@ void GSkyRegionMap::set_region_rect(const GSkyRegionRect* rect) |
| 728 | 724 | // Create fine sky map |
| 729 | 725 | GSkyMap map_fine("TAN", "CEL", rect->ra(), rect->dec(), |
| 730 | 726 | -resolution_x, resolution_y, |
| 731 | - nbins_x, nbins_y | |
| 732 | - ); | |
| 727 | + nbins_x, nbins_y); | |
| 733 | 728 | |
| 734 | - // Set sky map pixels | |
| 729 | + // Set sky map pixels that are contained in rectangle to 1 | |
| 735 | 730 | for (int ipix = 0; ipix < map_fine.npix(); ++ipix) { |
| 736 | - | |
| 737 | - // If pixel is contained in rectangle then set map pixel to 1 | |
| 738 | 731 | if (rect->contains(map_fine.inx2dir(ipix))) { |
| 739 | 732 | map_fine(ipix) = 1.0; |
| 740 | 733 | } |
| 741 | - | |
| 742 | - } // endfor: looped over sky map pixels | |
| 734 | + } | |
| 743 | 735 | |
| 744 | 736 | // Set sky map as region map |
| 745 | 737 | this->map(map_fine); |
| 746 | 738 | |
| 747 | 739 | // Return |
| 748 | 740 | return; |
| 749 | -} | |
| 750 | 741 | \ No newline at end of file |
| 742 | +} | ... | ... |
src/sky/GSkyRegionRect.cpp
| ... | ... | @@ -28,18 +28,19 @@ |
| 28 | 28 | #ifdef HAVE_CONFIG_H |
| 29 | 29 | #include <config.h> |
| 30 | 30 | #endif |
| 31 | +//#include "GMath.hpp" | |
| 32 | +#include "GTools.hpp" | |
| 31 | 33 | #include "GSkyRegionCircle.hpp" |
| 32 | 34 | #include "GSkyRegionRect.hpp" |
| 33 | 35 | #include "GSkyRegionMap.hpp" |
| 34 | -#include "GTools.hpp" | |
| 35 | 36 | |
| 36 | 37 | /* __ Method name definitions ____________________________________________ */ |
| 37 | -#define G_WIDTH "GSkyRegionRect::width(double&)" | |
| 38 | -#define G_HEIGHT "GSkyRegionRect::height(double&)" | |
| 39 | -#define G_READ "GSkyRegionRect::read(std::string&)" | |
| 40 | -#define G_CONTAINS "GSkyRegionRect::contains(GSkyRegion&)" | |
| 41 | -#define G_OVERLAPS "GSkyRegionRect::overlaps(GSkyRegion&)" | |
| 42 | -#define G_GET_CORNER "GSkyRegionRect::get_corner(int&)" | |
| 38 | +#define G_WIDTH "GSkyRegionRect::width(double&)" | |
| 39 | +#define G_HEIGHT "GSkyRegionRect::height(double&)" | |
| 40 | +#define G_READ "GSkyRegionRect::read(std::string&)" | |
| 41 | +#define G_CONTAINS "GSkyRegionRect::contains(GSkyRegion&)" | |
| 42 | +#define G_OVERLAPS "GSkyRegionRect::overlaps(GSkyRegion&)" | |
| 43 | +#define G_GET_CORNER "GSkyRegionRect::get_corner(int&)" | |
| 43 | 44 | |
| 44 | 45 | /* __ Macros _____________________________________________________________ */ |
| 45 | 46 | |
| ... | ... | @@ -70,24 +71,26 @@ GSkyRegionRect::GSkyRegionRect(void) : GSkyRegion() |
| 70 | 71 | |
| 71 | 72 | |
| 72 | 73 | /***********************************************************************//** |
| 73 | - * @brief Direction constructor | |
| 74 | + * @brief Sky direction constructor | |
| 74 | 75 | * |
| 75 | - * @param[in] centre Centre sky direction. | |
| 76 | - * @param[in] w Region width [deg]. | |
| 77 | - * @param[in] h Region height [deg]. | |
| 76 | + * @param[in] centre Centre of rectangle. | |
| 77 | + * @param[in] width Region width (degrees). | |
| 78 | + * @param[in] height Region height (degrees). | |
| 79 | + * @param[in] posang Position angle (degrees). | |
| 78 | 80 | ***************************************************************************/ |
| 79 | -GSkyRegionRect::GSkyRegionRect(const GSkyDir& centre, const double& w, | |
| 80 | - const double& h, const double& posang_deg) : | |
| 81 | - GSkyRegion() | |
| 81 | +GSkyRegionRect::GSkyRegionRect(const GSkyDir& centre, | |
| 82 | + const double& width, | |
| 83 | + const double& height, | |
| 84 | + const double& posang) : GSkyRegion() | |
| 82 | 85 | { |
| 83 | 86 | // Initialise members |
| 84 | 87 | init_members(); |
| 85 | 88 | |
| 86 | 89 | // Set members |
| 87 | 90 | this->centre(centre); |
| 88 | - this->width(w); | |
| 89 | - this->height(h); | |
| 90 | - this->posang_deg(posang_deg); | |
| 91 | + this->width(width); | |
| 92 | + this->height(height); | |
| 93 | + this->posang(posang); | |
| 91 | 94 | |
| 92 | 95 | // Compute solid angle |
| 93 | 96 | compute_solid_angle(); |
| ... | ... | @@ -98,26 +101,28 @@ GSkyRegionRect::GSkyRegionRect(const GSkyDir& centre, const double& w, |
| 98 | 101 | |
| 99 | 102 | |
| 100 | 103 | /***********************************************************************//** |
| 101 | - * @brief Direction constructor | |
| 104 | + * @brief Right Ascension and Declination constructor | |
| 102 | 105 | * |
| 103 | 106 | * @param[in] ra Right Ascension of region centre [deg]. |
| 104 | 107 | * @param[in] dec Declination of region centre [deg]. |
| 105 | - * @param[in] radius Region radius [deg]. | |
| 106 | - * @param[in] radius Region radius [deg]. | |
| 108 | + * @param[in] width Region width (degrees). | |
| 109 | + * @param[in] height Region height (degrees). | |
| 110 | + * @param[in] posang Position angle (degrees). | |
| 107 | 111 | ***************************************************************************/ |
| 108 | -GSkyRegionRect::GSkyRegionRect(const double& ra, const double& dec, | |
| 109 | - const double& w, const double& h, | |
| 110 | - const double& posang_deg) : | |
| 111 | - GSkyRegion() | |
| 112 | +GSkyRegionRect::GSkyRegionRect(const double& ra, | |
| 113 | + const double& dec, | |
| 114 | + const double& width, | |
| 115 | + const double& height, | |
| 116 | + const double& posang) : GSkyRegion() | |
| 112 | 117 | { |
| 113 | 118 | // Initialise members |
| 114 | 119 | init_members(); |
| 115 | 120 | |
| 116 | 121 | // Set members |
| 117 | 122 | this->centre(ra, dec); |
| 118 | - this->width(w); | |
| 119 | - this->height(h); | |
| 120 | - this->posang_deg(posang_deg); | |
| 123 | + this->width(width); | |
| 124 | + this->height(height); | |
| 125 | + this->posang(posang); | |
| 121 | 126 | |
| 122 | 127 | // Compute solid angle |
| 123 | 128 | compute_solid_angle(); |
| ... | ... | @@ -153,8 +158,7 @@ GSkyRegionRect::GSkyRegionRect(const std::string& line) : GSkyRegion() |
| 153 | 158 | * |
| 154 | 159 | * @param[in] region Rectangular sky region. |
| 155 | 160 | ***************************************************************************/ |
| 156 | -GSkyRegionRect::GSkyRegionRect(const GSkyRegionRect& region) : | |
| 157 | - GSkyRegion(region) | |
| 161 | +GSkyRegionRect::GSkyRegionRect(const GSkyRegionRect& region) : GSkyRegion(region) | |
| 158 | 162 | { |
| 159 | 163 | // Initialise members |
| 160 | 164 | init_members(); |
| ... | ... | @@ -253,67 +257,29 @@ GSkyRegionRect* GSkyRegionRect::clone(void) const |
| 253 | 257 | |
| 254 | 258 | |
| 255 | 259 | /***********************************************************************//** |
| 256 | - * @brief Set position angle of rectangular region | |
| 257 | - * | |
| 258 | - * @param[in] posang Position angle [radians]. | |
| 259 | - * | |
| 260 | - * Sets the position angle of the rectangular sky region. The position angle | |
| 261 | - * is counted counterclockwise from cel. North and is aligned to the rect | |
| 262 | - * height. | |
| 263 | - ***************************************************************************/ | |
| 264 | -void GSkyRegionRect::posang(const double& posang) | |
| 265 | -{ | |
| 266 | - // Set the position angle | |
| 267 | - m_posang = posang; | |
| 268 | - | |
| 269 | - // Return | |
| 270 | - return; | |
| 271 | -} | |
| 272 | - | |
| 273 | - | |
| 274 | -/***********************************************************************//** | |
| 275 | - * @brief Set position angle of rectangular region | |
| 276 | - * | |
| 277 | - * @param[in] posang Position angle [degrees]. | |
| 278 | - * | |
| 279 | - * Sets the position angle of the rectangular sky region. The position angle | |
| 280 | - * is counted counterclockwise from cel. North and is aligned to the rect | |
| 281 | - * height. | |
| 282 | - ***************************************************************************/ | |
| 283 | -void GSkyRegionRect::posang_deg(const double& posang) | |
| 284 | -{ | |
| 285 | - // Set the position angle | |
| 286 | - this->posang(posang * gammalib::deg2rad); | |
| 287 | - | |
| 288 | - // Return | |
| 289 | - return; | |
| 290 | -} | |
| 291 | - | |
| 292 | - | |
| 293 | -/***********************************************************************//** | |
| 294 | 260 | * @brief Set width of rectangular region |
| 295 | 261 | * |
| 296 | - * @param[in] width Width [deg]. | |
| 262 | + * @param[in] width Width (degrees). | |
| 297 | 263 | * |
| 298 | 264 | * @exception GException::invalid_argument |
| 299 | 265 | * Width value is less than 0. |
| 300 | 266 | * |
| 301 | - * Sets the width of the rectangular sky region. Only non-negative radii are | |
| 302 | - * allowed. | |
| 267 | + * Sets the @p width of the rectangular sky region. Only non-negative widths | |
| 268 | + * are allowed. | |
| 303 | 269 | ***************************************************************************/ |
| 304 | 270 | void GSkyRegionRect::width(const double& width) |
| 305 | 271 | { |
| 272 | + // Throw an exception if the width is less than zero | |
| 306 | 273 | if (width < 0.0) { |
| 307 | 274 | std::string msg = |
| 308 | - "A width of "+gammalib::str(width)+" degrees has been" | |
| 309 | - " specified for a rectangular sky region.\n" | |
| 310 | - "The width of a rectangular sky region can't be less than 0" | |
| 311 | - " degrees."; | |
| 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."; | |
| 312 | 278 | throw GException::invalid_argument(G_WIDTH, msg); |
| 313 | 279 | } |
| 314 | 280 | |
| 315 | 281 | // Set radius value |
| 316 | - m_halfwidth = 0.5*width; | |
| 282 | + m_width = width; | |
| 317 | 283 | |
| 318 | 284 | // Compute the solid angle |
| 319 | 285 | compute_solid_angle(); |
| ... | ... | @@ -326,27 +292,29 @@ void GSkyRegionRect::width(const double& width) |
| 326 | 292 | /***********************************************************************//** |
| 327 | 293 | * @brief Set height of rectangular region |
| 328 | 294 | * |
| 329 | - * @param[in] height Height [deg]. | |
| 295 | + * @param[in] height Height (degrees). | |
| 330 | 296 | * |
| 331 | 297 | * @exception GException::invalid_argument |
| 332 | 298 | * Height value is less than 0. |
| 333 | 299 | * |
| 334 | - * Sets the height of the rectangular sky region. Only non-negative radii are | |
| 335 | - * allowed. For zero posang, the height axis is pointing to celestial north. | |
| 300 | + * Sets the @p height of the rectangular sky region. Only non-negative | |
| 301 | + * heights are allowed. | |
| 302 | + * | |
| 303 | + * Note that for a position angle of zero, the height axis is pointing to | |
| 304 | + * celestial north. | |
| 336 | 305 | ***************************************************************************/ |
| 337 | 306 | void GSkyRegionRect::height(const double& height) |
| 338 | 307 | { |
| 339 | 308 | if (height < 0.0) { |
| 340 | 309 | std::string msg = |
| 341 | - "A height of "+gammalib::str(height)+" degrees has been" | |
| 342 | - " specified for a rectangular sky region.\n" | |
| 343 | - "The height of a rectangular sky region can't be less than 0" | |
| 344 | - " degrees."; | |
| 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."; | |
| 345 | 313 | throw GException::invalid_argument(G_HEIGHT, msg); |
| 346 | 314 | } |
| 347 | 315 | |
| 348 | 316 | // Set radius value |
| 349 | - m_halfheight = 0.5*height; | |
| 317 | + m_height = height; | |
| 350 | 318 | |
| 351 | 319 | // Compute the solid angle |
| 352 | 320 | compute_solid_angle(); |
| ... | ... | @@ -377,9 +345,8 @@ void GSkyRegionRect::read(const std::string& line) |
| 377 | 345 | // Finding the box |
| 378 | 346 | if (region_def.find("box") == std::string::npos) { |
| 379 | 347 | std::string msg = |
| 380 | - "Unable to find the key word \"box\" in provided string" | |
| 381 | - " \""+line+"\".\n" | |
| 382 | - "The \"box\" key word is mandatory."; | |
| 348 | + "Unable to find the key word \"box\" in provided string " | |
| 349 | + "\""+line+"\". The \"box\" key word is mandatory."; | |
| 383 | 350 | throw GException::invalid_value(G_READ, msg); |
| 384 | 351 | } |
| 385 | 352 | |
| ... | ... | @@ -396,29 +363,29 @@ void GSkyRegionRect::read(const std::string& line) |
| 396 | 363 | std::vector<std::string> values = gammalib::split(regionstring,","); |
| 397 | 364 | if (values.size() != 5) { |
| 398 | 365 | std::string msg = |
| 399 | - "Invalid number of "+gammalib::str(values.size())+" arguments" | |
| 400 | - " after the \"box\" key word in provided string \""+line+"\".\n" | |
| 366 | + "Invalid number of "+gammalib::str(values.size())+" arguments " | |
| 367 | + "after the \"box\" key word in provided string \""+line+"\". " | |
| 401 | 368 | "Exactly 5 arguments are expected."; |
| 402 | 369 | throw GException::invalid_value(G_READ, msg); |
| 403 | 370 | } |
| 404 | 371 | double x = gammalib::todouble(values[0]); |
| 405 | 372 | double y = gammalib::todouble(values[1]); |
| 406 | - double w = gammalib::todouble(values[2]); | |
| 407 | - double h = gammalib::todouble(values[3]); | |
| 373 | + double width = gammalib::todouble(values[2]); | |
| 374 | + double height = gammalib::todouble(values[3]); | |
| 408 | 375 | double posang = gammalib::todouble(values[4]); |
| 409 | 376 | |
| 410 | 377 | // Get radius units |
| 411 | 378 | if (gammalib::contains(values[2], "'")) { |
| 412 | - w /= 60.0; | |
| 379 | + width /= 60.0; | |
| 413 | 380 | } |
| 414 | 381 | else if (gammalib::contains(values[2], "\"")) { |
| 415 | - w /= 3600.0; | |
| 382 | + width /= 3600.0; | |
| 416 | 383 | } |
| 417 | 384 | if (gammalib::contains(values[3], "'")) { |
| 418 | - h /= 60.0; | |
| 385 | + height /= 60.0; | |
| 419 | 386 | } |
| 420 | 387 | else if (gammalib::contains(values[3], "\"")) { |
| 421 | - h /= 3600.0; | |
| 388 | + height /= 3600.0; | |
| 422 | 389 | } |
| 423 | 390 | if (gammalib::contains(values[4], "'")) { |
| 424 | 391 | posang /= 60.0; |
| ... | ... | @@ -439,32 +406,31 @@ void GSkyRegionRect::read(const std::string& line) |
| 439 | 406 | } |
| 440 | 407 | else { |
| 441 | 408 | std::string msg = |
| 442 | - "Unsupported coordinate system \""+system+"\" in provided string" | |
| 443 | - " \""+line+"\".\n" | |
| 444 | - "Only the following coordinate systems are supported: " | |
| 445 | - "\"fk5\", \"icrs\" and \"galactic\"."; | |
| 409 | + "Unsupported coordinate system \""+system+"\" in provided string " | |
| 410 | + "\""+line+"\". Only the following coordinate systems are " | |
| 411 | + "supported: \"fk5\", \"icrs\" and \"galactic\"."; | |
| 446 | 412 | throw GException::invalid_value(G_READ, msg); |
| 447 | 413 | } |
| 448 | 414 | |
| 449 | 415 | // Set members |
| 450 | 416 | this->centre(centre); |
| 451 | - this->width(w); | |
| 452 | - this->height(h); | |
| 453 | - this->posang_deg(posang); | |
| 417 | + this->width(width); | |
| 418 | + this->height(height); | |
| 419 | + this->posang(posang); | |
| 454 | 420 | |
| 455 | 421 | // Compute solid angle |
| 456 | 422 | compute_solid_angle(); |
| 457 | 423 | |
| 458 | 424 | // Check if there is a given name for the region and set it |
| 459 | 425 | std::vector<std::string>comments = gammalib::split(comment, " "); |
| 460 | - for (int i = 0; i < comments.size(); i++) { | |
| 426 | + for (int i = 0; i < comments.size(); ++i) { | |
| 461 | 427 | if (gammalib::contains(comments[i], "text")) { |
| 462 | 428 | std::vector<std::string> attributes = gammalib::split(comments[i], "="); |
| 463 | 429 | if (attributes.size() < 2) { |
| 464 | 430 | std::string msg = |
| 465 | - "Invalid character sequence encountered in provided" | |
| 466 | - " string \""+line+"\".\n" | |
| 467 | - "An attribute of the type \"text=Name\" is expected."; | |
| 431 | + "Invalid character sequence encountered in provided " | |
| 432 | + "string \""+line+"\". An attribute of the type " | |
| 433 | + "\"text=Name\" is expected."; | |
| 468 | 434 | throw GException::invalid_value(G_READ, msg); |
| 469 | 435 | } |
| 470 | 436 | m_name = attributes[1]; |
| ... | ... | @@ -495,11 +461,11 @@ std::string GSkyRegionRect::write(void) const |
| 495 | 461 | result.append(","); |
| 496 | 462 | result.append(gammalib::str(m_centre.dec_deg())); |
| 497 | 463 | result.append(","); |
| 498 | - result.append(gammalib::str(2*m_halfwidth)); | |
| 464 | + result.append(gammalib::str(m_width)); | |
| 499 | 465 | result.append(","); |
| 500 | - result.append(gammalib::str(2*m_halfheight)); | |
| 466 | + result.append(gammalib::str(m_height)); | |
| 501 | 467 | result.append(","); |
| 502 | - result.append(gammalib::str(m_posang*gammalib::rad2deg)); | |
| 468 | + result.append(gammalib::str(m_posang)); | |
| 503 | 469 | result.append(")"); |
| 504 | 470 | |
| 505 | 471 | // Optionally add region name |
| ... | ... | @@ -514,41 +480,6 @@ std::string GSkyRegionRect::write(void) const |
| 514 | 480 | |
| 515 | 481 | |
| 516 | 482 | /***********************************************************************//** |
| 517 | - * @brief Print rectangular region | |
| 518 | - * | |
| 519 | - * @param[in] chatter Chattiness | |
| 520 | - * @return String containing region information. | |
| 521 | - ***************************************************************************/ | |
| 522 | -std::string GSkyRegionRect::print(const GChatter& chatter) const | |
| 523 | -{ | |
| 524 | - // Initialise result string | |
| 525 | - std::string result;; | |
| 526 | - | |
| 527 | - // Continue only if chatter is not silent | |
| 528 | - if (chatter != SILENT) { | |
| 529 | - | |
| 530 | - // Append header | |
| 531 | - result.append("=== GSkyRegionRect ==="); | |
| 532 | - | |
| 533 | - // Append sky region information | |
| 534 | - result.append("\n"+gammalib::parformat("Right Ascension of centre")); | |
| 535 | - result.append(gammalib::str(m_centre.ra_deg())+" deg"); | |
| 536 | - result.append("\n"+gammalib::parformat("Declination of centre")); | |
| 537 | - result.append(gammalib::str(m_centre.dec_deg())+" deg"); | |
| 538 | - result.append("\n"+gammalib::parformat("Width")); | |
| 539 | - result.append(gammalib::str(2*m_halfwidth)+" deg"); | |
| 540 | - result.append("\n"+gammalib::parformat("Height")); | |
| 541 | - result.append(gammalib::str(2*m_halfheight)+" deg"); | |
| 542 | - result.append("\n"+gammalib::parformat("PA")); | |
| 543 | - result.append(gammalib::str(m_posang*gammalib::rad2deg)+" deg"); | |
| 544 | - | |
| 545 | - } // endif: chatter was not silent | |
| 546 | - | |
| 547 | - // Return result | |
| 548 | - return result; | |
| 549 | -} | |
| 550 | - | |
| 551 | -/***********************************************************************//** | |
| 552 | 483 | * @brief Checks if sky direction lies within region |
| 553 | 484 | * |
| 554 | 485 | * @param[in] dir Sky direction. |
| ... | ... | @@ -572,7 +503,7 @@ bool GSkyRegionRect::contains(const GSkyDir& dir) const |
| 572 | 503 | /***********************************************************************//** |
| 573 | 504 | * @brief Checks if local direction lies within region |
| 574 | 505 | * |
| 575 | - * @param[in] dir Direction in local coordinate system. | |
| 506 | + * @param[in] locdir Sky direction in local coordinate system. | |
| 576 | 507 | * |
| 577 | 508 | * A local direction lies within a region when its distance to the region |
| 578 | 509 | * centre is not larger than the region extension in both axes directions. |
| ... | ... | @@ -583,10 +514,10 @@ bool GSkyRegionRect::contains_local(const GSkyDir& locdir) const |
| 583 | 514 | bool dir_is_in = false; |
| 584 | 515 | |
| 585 | 516 | // Check containment: declination axis |
| 586 | - if ((std::abs(locdir.dec_deg()) - 1.0e-10) <= m_halfheight) { | |
| 517 | + if ((std::abs(locdir.dec_deg()) - 1.0e-10) <= 0.5 * m_height) { | |
| 587 | 518 | |
| 588 | 519 | // Check containment: right ascension axis |
| 589 | - if ((std::abs(locdir.ra_deg()) - 1.0e-10) <= m_halfwidth) { | |
| 520 | + if ((std::abs(locdir.ra_deg()) - 1.0e-10) <= 0.5 * m_width) { | |
| 590 | 521 | |
| 591 | 522 | // Sky direction is inside the rectangle |
| 592 | 523 | dir_is_in = true; |
| ... | ... | @@ -625,10 +556,10 @@ bool GSkyRegionRect::contains(const GSkyRegion& reg) const |
| 625 | 556 | const double circ_rad = regcirc->radius(); |
| 626 | 557 | |
| 627 | 558 | // Check extension of circle along declination axis |
| 628 | - if ((std::abs(local_centre.dec_deg()) + circ_rad) <= m_halfheight) { | |
| 559 | + if ((std::abs(local_centre.dec_deg()) + circ_rad) <= 0.5 * m_height) { | |
| 629 | 560 | |
| 630 | 561 | // Check extension of circle along right ascension axis |
| 631 | - if ((std::abs(local_centre.ra_deg()) + circ_rad) <= m_halfwidth) { | |
| 562 | + if ((std::abs(local_centre.ra_deg()) + circ_rad) <= 0.5 * m_width) { | |
| 632 | 563 | |
| 633 | 564 | // Circle is fully contained in this rectangle |
| 634 | 565 | is_fully_inside = true; |
| ... | ... | @@ -644,7 +575,7 @@ bool GSkyRegionRect::contains(const GSkyRegion& reg) const |
| 644 | 575 | dynamic_cast<const GSkyRegionRect*>(®); |
| 645 | 576 | |
| 646 | 577 | // Loop over the four corners of the rectangle :regrect: |
| 647 | - for(int icorner=0; icorner<4; ++icorner) { | |
| 578 | + for (int icorner = 0; icorner < 4; ++icorner) { | |
| 648 | 579 | |
| 649 | 580 | // Get skydir of current corner |
| 650 | 581 | GSkyDir corner = regrect->get_corner(icorner); |
| ... | ... | @@ -654,7 +585,7 @@ bool GSkyRegionRect::contains(const GSkyRegion& reg) const |
| 654 | 585 | break; |
| 655 | 586 | } |
| 656 | 587 | // Did we arrive at the last corner? |
| 657 | - else if (icorner==3) { | |
| 588 | + else if (icorner == 3) { | |
| 658 | 589 | |
| 659 | 590 | // As we reached this point, the three prior corners were inside |
| 660 | 591 | // and the last corner now is also inside: |
| ... | ... | @@ -705,10 +636,10 @@ bool GSkyRegionRect::overlaps(const GSkyRegion& reg) const |
| 705 | 636 | const double circ_rad = regcirc->radius(); |
| 706 | 637 | |
| 707 | 638 | // Check extension of circle along declination axis |
| 708 | - if (std::abs(local_centre.dec_deg()) <= (m_halfheight + circ_rad)) { | |
| 639 | + if (std::abs(local_centre.dec_deg()) <= (0.5 * m_height + circ_rad)) { | |
| 709 | 640 | |
| 710 | 641 | // Check extension of circle along right ascension axis |
| 711 | - if (std::abs(local_centre.ra_deg()) <= (m_halfwidth + circ_rad)) { | |
| 642 | + if (std::abs(local_centre.ra_deg()) <= (0.5 * m_width + circ_rad)) { | |
| 712 | 643 | |
| 713 | 644 | // Circle is fully contained in this rectangle |
| 714 | 645 | is_overlapping = true; |
| ... | ... | @@ -722,7 +653,7 @@ bool GSkyRegionRect::overlaps(const GSkyRegion& reg) const |
| 722 | 653 | const GSkyRegionRect* regrect = |
| 723 | 654 | dynamic_cast<const GSkyRegionRect*>(®); |
| 724 | 655 | |
| 725 | - // Dirty cludge: compare vs map | |
| 656 | + // Dirty kludge: compare vs map | |
| 726 | 657 | GSkyRegionMap regmap = GSkyRegionMap(regrect); |
| 727 | 658 | is_overlapping = regmap.overlaps(*this); |
| 728 | 659 | |
| ... | ... | @@ -746,17 +677,17 @@ bool GSkyRegionRect::overlaps(const GSkyRegion& reg) const |
| 746 | 677 | * @param[in] skydir Sky direction in global coordinate system. |
| 747 | 678 | * @return Sky direction in local cartesian region object coordinates. |
| 748 | 679 | * |
| 749 | - * Transform the sky direction :skydir: to the local cartesian coordinate system. | |
| 750 | - * The origin of the local coordinate system is fixed to the center of the | |
| 751 | - * rectangle and aligned in +ra (width) and +dec (height). | |
| 752 | - * Please note, that a GSkyDir object is returned, even if the local coordsys | |
| 680 | + * Transform the sky direction @p skydir to the local cartesian coordinate | |
| 681 | + * system. The origin of the local coordinate system is fixed to the center | |
| 682 | + * of the rectangle and aligned in +ra (width) and +dec (height). Please | |
| 683 | + * note, that a GSkyDir object is returned, even if the local coordsys is | |
| 753 | 684 | * is cartesian. |
| 754 | 685 | ***************************************************************************/ |
| 755 | 686 | GSkyDir GSkyRegionRect::transform_to_local(const GSkyDir& skydir) const |
| 756 | 687 | { |
| 757 | 688 | // Get distance and polar angle relative to rectangle centre |
| 758 | 689 | double dist = m_centre.dist(skydir); |
| 759 | - double pa = m_centre.posang(skydir) - m_posang; | |
| 690 | + double pa = m_centre.posang(skydir) - m_posang * gammalib::deg2rad; | |
| 760 | 691 | |
| 761 | 692 | // Compute corresponding x and y coordinate from polar coords |
| 762 | 693 | double x = dist * std::sin(pa); |
| ... | ... | @@ -777,7 +708,7 @@ GSkyDir GSkyRegionRect::transform_to_local(const GSkyDir& skydir) const |
| 777 | 708 | * @param[in] locdir Direction in local coordinate system. |
| 778 | 709 | * @return Sky direction in global coordinate system. |
| 779 | 710 | * |
| 780 | - * Transform the local direction :locdir: to the global coordinate system. | |
| 711 | + * Transform the local direction @p locdir to the global coordinate system. | |
| 781 | 712 | * The origin of the local coordinate system is fixed to the center of the |
| 782 | 713 | * rectangle and aligned in +ra (width) and +dec (height). |
| 783 | 714 | ***************************************************************************/ |
| ... | ... | @@ -793,11 +724,8 @@ GSkyDir GSkyRegionRect::transform_to_global(const GSkyDir& locdir) const |
| 793 | 724 | |
| 794 | 725 | // Compute dist and position angle in polar coords |
| 795 | 726 | double dist = std::sqrt(x*x + y*y); |
| 796 | - double pa = gammalib::pihalf - std::atan2(y, x) + m_posang; | |
| 797 | - | |
| 798 | - // // Compute distance and position angle for locdir in global coordinates | |
| 799 | - // double dist = centre_local.dist(locdir); | |
| 800 | - // double pa = centre_local.posang(locdir) + m_posang; | |
| 727 | + double pa = gammalib::pihalf - std::atan2(y, x) + | |
| 728 | + m_posang * gammalib::deg2rad; | |
| 801 | 729 | |
| 802 | 730 | // Create output global sky direction |
| 803 | 731 | GSkyDir transformed(m_centre); |
| ... | ... | @@ -822,14 +750,14 @@ GSkyDir GSkyRegionRect::transform_to_global(const GSkyDir& locdir) const |
| 822 | 750 | GSkyDir GSkyRegionRect::get_corner(const int& index) const |
| 823 | 751 | { |
| 824 | 752 | // Assert index is in [0,3] |
| 825 | - if ((index<0) || (index>3)) { | |
| 826 | - throw GException::out_of_range(G_GET_CORNER, index, 0, 3); | |
| 753 | + if ((index < 0) || (index > 3)) { | |
| 754 | + throw GException::out_of_range(G_GET_CORNER, "Corner index", index, 3); | |
| 827 | 755 | } |
| 828 | 756 | |
| 829 | 757 | // Compute the offset to the corners |
| 830 | 758 | // Index counts CCW starting from +RA,+DEC: +R+D, +R-D, -R-D, -R+D |
| 831 | - double dx = m_halfwidth * (1 - 2*int(index >= 2)); | |
| 832 | - double dy = m_halfheight * (1 - 2*int((index==1) || (index==2))); | |
| 759 | + double dx = 0.5 * m_width * (1 - 2*int(index >= 2)); | |
| 760 | + double dy = 0.5 * m_height * (1 - 2*int((index==1) || (index==2))); | |
| 833 | 761 | |
| 834 | 762 | // Define local corner sky direction |
| 835 | 763 | GSkyDir corner; |
| ... | ... | @@ -843,6 +771,41 @@ GSkyDir GSkyRegionRect::get_corner(const int& index) const |
| 843 | 771 | } |
| 844 | 772 | |
| 845 | 773 | |
| 774 | +/***********************************************************************//** | |
| 775 | + * @brief Print rectangular region | |
| 776 | + * | |
| 777 | + * @param[in] chatter Chattiness | |
| 778 | + * @return String containing region information. | |
| 779 | + ***************************************************************************/ | |
| 780 | +std::string GSkyRegionRect::print(const GChatter& chatter) const | |
| 781 | +{ | |
| 782 | + // Initialise result string | |
| 783 | + std::string result;; | |
| 784 | + | |
| 785 | + // Continue only if chatter is not silent | |
| 786 | + if (chatter != SILENT) { | |
| 787 | + | |
| 788 | + // Append header | |
| 789 | + result.append("=== GSkyRegionRect ==="); | |
| 790 | + | |
| 791 | + // Append sky region information | |
| 792 | + result.append("\n"+gammalib::parformat("Right Ascension of centre")); | |
| 793 | + result.append(gammalib::str(ra())+" deg"); | |
| 794 | + result.append("\n"+gammalib::parformat("Declination of centre")); | |
| 795 | + result.append(gammalib::str(dec())+" deg"); | |
| 796 | + result.append("\n"+gammalib::parformat("Width")); | |
| 797 | + result.append(gammalib::str(width())+" deg"); | |
| 798 | + result.append("\n"+gammalib::parformat("Height")); | |
| 799 | + result.append(gammalib::str(height())+" deg"); | |
| 800 | + result.append("\n"+gammalib::parformat("PA")); | |
| 801 | + result.append(gammalib::str(posang())+" deg"); | |
| 802 | + | |
| 803 | + } // endif: chatter was not silent | |
| 804 | + | |
| 805 | + // Return result | |
| 806 | + return result; | |
| 807 | +} | |
| 808 | + | |
| 846 | 809 | |
| 847 | 810 | /*========================================================================== |
| 848 | 811 | = = |
| ... | ... | @@ -856,11 +819,11 @@ GSkyDir GSkyRegionRect::get_corner(const int& index) const |
| 856 | 819 | void GSkyRegionRect::init_members(void) |
| 857 | 820 | { |
| 858 | 821 | // Initialise members |
| 859 | - m_centre = GSkyDir(); | |
| 860 | - m_halfwidth = 0.0; | |
| 861 | - m_halfheight = 0.0; | |
| 862 | - m_posang = 0.0; | |
| 863 | 822 | m_type = "Rect"; |
| 823 | + m_centre.clear(); | |
| 824 | + m_width = 0.0; | |
| 825 | + m_height = 0.0; | |
| 826 | + m_posang = 0.0; | |
| 864 | 827 | |
| 865 | 828 | //Return |
| 866 | 829 | return; |
| ... | ... | @@ -875,10 +838,10 @@ void GSkyRegionRect::init_members(void) |
| 875 | 838 | void GSkyRegionRect::copy_members(const GSkyRegionRect& region) |
| 876 | 839 | { |
| 877 | 840 | // Copy attributes |
| 878 | - m_centre = region.m_centre; | |
| 879 | - m_halfwidth = region.m_halfwidth; | |
| 880 | - m_halfheight = region.m_halfheight; | |
| 881 | - m_posang = region.m_posang; | |
| 841 | + m_centre = region.m_centre; | |
| 842 | + m_width = region.m_width; | |
| 843 | + m_height = region.m_height; | |
| 844 | + m_posang = region.m_posang; | |
| 882 | 845 | |
| 883 | 846 | // Return |
| 884 | 847 | return; |
| ... | ... | @@ -896,13 +859,12 @@ void GSkyRegionRect::free_members(void) |
| 896 | 859 | |
| 897 | 860 | |
| 898 | 861 | /***********************************************************************//** |
| 899 | - * @brief Compute solid angle [sr] | |
| 862 | + * @brief Compute solid angle (sr) | |
| 900 | 863 | ***************************************************************************/ |
| 901 | 864 | void GSkyRegionRect::compute_solid_angle(void) |
| 902 | 865 | { |
| 903 | 866 | // Compute solid angle |
| 904 | - m_solid = (2*m_halfwidth) * (2*m_halfheight) * \ | |
| 905 | - (gammalib::deg2rad * gammalib::deg2rad); | |
| 867 | + m_solid = m_width * m_height * gammalib::deg2rad * gammalib::deg2rad; | |
| 906 | 868 | |
| 907 | 869 | // Return |
| 908 | 870 | return; | ... | ... |