Commit 37bbe9c24e7a0a0f08009b110a4ea082269ca5cc

Authored by Maria Krause
1 parent eb1cf759

adding 'contains' and 'overlap' function to GSkyRegionMap

include/GSkyRegionMap.hpp
... ... @@ -73,6 +73,7 @@ public:
73 73 bool contains(const GSkyRegion& reg) const;
74 74 bool contains(const GSkyPixel& pixel) const;
75 75 bool overlaps(const GSkyRegion& reg) const;
  76 + bool overlaps(const GSkyDir& dir) const;
76 77 virtual std::string print(const GChatter& chatter = NORMAL) const;
77 78 std::string write(void) const;
78 79 virtual void read(const std::string& regstring);
... ...
src/sky/GSkyRegionMap.cpp
... ... @@ -440,93 +440,46 @@ bool GSkymap::contains(const GSkyPixel& pixel) const
440 440 return inmap;
441 441 }
442 442  
443   -
444   -/***********************************************************************//**
445   - * @brief Checks if region is fully contained within this region
446   - *
447   - * @param[in] reg Sky region.
448   - *
449   - * @exception GException::feature_not_implemented
450   - * Regions differ in type.
451   - ***************************************************************************/
452   -/*bool GSkyRegionMap::contains(const GSkyRegion& reg) const
453   -{
454   - // Initialise return value
455   - bool fully_inside = false;
456   -
457   - // If other region is sky map region use a simple way to calculate
458   - if (reg.type() == "Circle") {
459   -
460   - // Create circular region from reg
461   - const GSkyRegionCircle* regcirc =
462   - dynamic_cast<const GSkyRegionCircle*>(&reg);
463   -
464   - // Calculate angular distance between the centres
465   - double ang_dist = m_centre.dist_deg(regcirc->centre());
466   -
467   - // Check if the region is contained in this
468   - if ((ang_dist + regcirc->radius()) <= m_radius) {
469   - fully_inside = true;
470   - }
471   -
472   - }
473   -
474   - // ... otherwise throw an exception
475   - else {
476   - throw GException::feature_not_implemented(G_CONTAINS,
477   - "Cannot compare two different region types yet");
478   - }
479   -
480   - // Return value
481   - return fully_inside;
482   -}
483   -*/
484   -
485 443 /***********************************************************************//**
486 444 * @brief Checks if region is overlapping with this region
487 445 *
488 446 * @param[in] reg Sky region.
489 447 *
  448 + * @TODO: region sky map overlap with ring or circle region
  449 + *
490 450 * @exception GException::feature_not_implemented
491 451 * Regions differ in type.
492 452 ***************************************************************************/
493   -bool GSkyRegionMap::overlaps(const GSkyRegion& reg) const
  453 +bool GSkyRegionMap::overlaps(const GSkyDir& dir) const
494 454 {
495 455 // Initialise return value
496 456 bool overlap = false;
497 457  
498   - // If other region is sky map region use a simple way to calculate
499   - if (reg.type() == "Map") {
500   -
501   - // Create circular region from reg
502   - const GSkyRegionMap* regregionmap =
503   - dynamic_cast<const GSkyRegionMap*>(&reg);
504   -
505   - //double ang_dist = m_map.dist_deg(regregionmap->map());
506   -
507   -
508   - // Check if the sky region map and circle overlap
509   - /* for (int i =0; i < m_map.npix(); ++i) {
510   - GSkyPixel pix=m_map.inx2pix(i);
511   - std::cout << pix.size() << std::endl;
512   - if (num_pix_map[i] == ){
513   - num_pix_map[i] = i;
514   - }
515   - }
516   - if () {
517   - overlap = true;
518   - }
519   - */
520   - }
521   -
522   - // ... otherwise throw an exception
523   - else {
524   - throw GException::feature_not_implemented(G_OVERLAPS,
525   - "Cannot compare two different region types yet");
526   - }
527   -
  458 + // Convert sky direction into sky pixel
  459 + GSkyPixel pixel = dir2pix(dir);
  460 +
  461 + // Return location flag
  462 + return (contains(pixel));
  463 +
  464 +/* GSkyDir dir;
  465 + for (int i=0; i<360; i++){
  466 + for (int j=0; j<90; j++){
  467 +
  468 + const GSkyDir* regdir =
  469 + dynamic_cast<const GSkyDir*>(&dir);
  470 + double direction = dir->radec_deg(i,j);
  471 +
  472 + if (reg->contains(dir)) {
  473 + overlap = true;
  474 + }
  475 + else {
  476 + overlap = false;
  477 + }
  478 + }
  479 + }
528 480 // Return value
529 481 return overlap;
  482 + */
530 483 }
531 484  
532 485  
... ...