Commit 80c8d71d467b4b3bea8ba51a18b9ca152b832f1d

Authored by Andreas Specovius
Committed by Jürgen Knödlseder
1 parent cc862b5b

Implemented reading from ds9 file. Rectangles are named box there. (No rotation angle yet.)

Showing 1 changed file with 61 additions and 17 deletions
src/sky/GSkyRegions.cpp
@@ -34,6 +34,7 @@ @@ -34,6 +34,7 @@
34 #include "GSkyDir.hpp" 34 #include "GSkyDir.hpp"
35 #include "GSkyRegion.hpp" 35 #include "GSkyRegion.hpp"
36 #include "GSkyRegionCircle.hpp" 36 #include "GSkyRegionCircle.hpp"
  37 +#include "GSkyRegionRect.hpp"
37 #include "GSkyRegions.hpp" 38 #include "GSkyRegions.hpp"
38 39
39 /* __ Method name definitions ____________________________________________ */ 40 /* __ Method name definitions ____________________________________________ */
@@ -369,7 +370,7 @@ void GSkyRegions::remove(const int& index) @@ -369,7 +370,7 @@ void GSkyRegions::remove(const int& index)
369 370
370 // Erase region component from container 371 // Erase region component from container
371 m_regions.erase(m_regions.begin() + index); 372 m_regions.erase(m_regions.begin() + index);
372 - 373 +
373 // Return 374 // Return
374 return; 375 return;
375 } 376 }
@@ -395,7 +396,7 @@ void GSkyRegions::extend(const GSkyRegions& regions) @@ -395,7 +396,7 @@ void GSkyRegions::extend(const GSkyRegions& regions)
395 // Reserve enough space 396 // Reserve enough space
396 reserve(size() + num); 397 reserve(size() + num);
397 398
398 - // Loop over all region components and append pointers to deep copies 399 + // Loop over all region components and append pointers to deep copies
399 for (int i = 0; i < num; ++i) { 400 for (int i = 0; i < num; ++i) {
400 401
401 // Append region to container 402 // Append region to container
@@ -404,7 +405,7 @@ void GSkyRegions::extend(const GSkyRegions&amp; regions) @@ -404,7 +405,7 @@ void GSkyRegions::extend(const GSkyRegions&amp; regions)
404 } // endfor: looped over all regions 405 } // endfor: looped over all regions
405 406
406 } // endif: region container was not empty 407 } // endif: region container was not empty
407 - 408 +
408 // Return 409 // Return
409 return; 410 return;
410 } 411 }
@@ -424,7 +425,7 @@ bool GSkyRegions::contains(const GSkyDir&amp; dir) const @@ -424,7 +425,7 @@ bool GSkyRegions::contains(const GSkyDir&amp; dir) const
424 { 425 {
425 // Initialise return value 426 // Initialise return value
426 bool overlap = false; 427 bool overlap = false;
427 - 428 +
428 // Loop over regions 429 // Loop over regions
429 for (int i = 0; i < size(); ++i) { 430 for (int i = 0; i < size(); ++i) {
430 overlap = m_regions[i]->contains(dir); 431 overlap = m_regions[i]->contains(dir);
@@ -432,12 +433,12 @@ bool GSkyRegions::contains(const GSkyDir&amp; dir) const @@ -432,12 +433,12 @@ bool GSkyRegions::contains(const GSkyDir&amp; dir) const
432 break; 433 break;
433 } 434 }
434 } 435 }
435 - 436 +
436 // Return result 437 // Return result
437 return overlap; 438 return overlap;
438 } 439 }
439 440
440 - 441 +
441 /***********************************************************************//** 442 /***********************************************************************//**
442 * @brief Check if region overlaps one of the regions 443 * @brief Check if region overlaps one of the regions
443 * 444 *
@@ -451,7 +452,7 @@ bool GSkyRegions::overlaps(const GSkyRegion&amp; region) const @@ -451,7 +452,7 @@ bool GSkyRegions::overlaps(const GSkyRegion&amp; region) const
451 { 452 {
452 // Initialise return value 453 // Initialise return value
453 bool overlap = false; 454 bool overlap = false;
454 - 455 +
455 // Loop over regions 456 // Loop over regions
456 for (int i = 0; i < size(); ++i) { 457 for (int i = 0; i < size(); ++i) {
457 overlap = m_regions[i]->overlaps(region); 458 overlap = m_regions[i]->overlaps(region);
@@ -459,7 +460,7 @@ bool GSkyRegions::overlaps(const GSkyRegion&amp; region) const @@ -459,7 +460,7 @@ bool GSkyRegions::overlaps(const GSkyRegion&amp; region) const
459 break; 460 break;
460 } 461 }
461 } 462 }
462 - 463 +
463 // Return result 464 // Return result
464 return overlap; 465 return overlap;
465 } 466 }
@@ -473,14 +474,14 @@ bool GSkyRegions::overlaps(const GSkyRegion&amp; region) const @@ -473,14 +474,14 @@ bool GSkyRegions::overlaps(const GSkyRegion&amp; region) const
473 * with one of the regions in the container, false otherwise 474 * with one of the regions in the container, false otherwise
474 * 475 *
475 * Tells if all regions in overlaps one of the regions. Note, this method 476 * Tells if all regions in overlaps one of the regions. Note, this method
476 - * returns true if ANY of the regions in the two containers overlap with 477 + * returns true if ANY of the regions in the two containers overlap with
477 * each other 478 * each other
478 ***************************************************************************/ 479 ***************************************************************************/
479 bool GSkyRegions::overlaps(const GSkyRegions& regions) const 480 bool GSkyRegions::overlaps(const GSkyRegions& regions) const
480 { 481 {
481 // Initialize return value 482 // Initialize return value
482 bool overlap = false; 483 bool overlap = false;
483 - 484 +
484 // Loop over each region in the container 485 // Loop over each region in the container
485 for (int i = 0; i < size(); ++i) { 486 for (int i = 0; i < size(); ++i) {
486 overlap = regions.overlaps(*m_regions[i]); 487 overlap = regions.overlaps(*m_regions[i]);
@@ -488,7 +489,7 @@ bool GSkyRegions::overlaps(const GSkyRegions&amp; regions) const @@ -488,7 +489,7 @@ bool GSkyRegions::overlaps(const GSkyRegions&amp; regions) const
488 break; 489 break;
489 } 490 }
490 } 491 }
491 - 492 +
492 // Return result 493 // Return result
493 return overlap; 494 return overlap;
494 } 495 }
@@ -513,7 +514,7 @@ void GSkyRegions::load(const GFilename&amp; filename) @@ -513,7 +514,7 @@ void GSkyRegions::load(const GFilename&amp; filename)
513 std::ifstream ds9file; 514 std::ifstream ds9file;
514 ds9file.open(filename.url().c_str()); 515 ds9file.open(filename.url().c_str());
515 if (ds9file.is_open()) { 516 if (ds9file.is_open()) {
516 - 517 +
517 // Loop over file lines 518 // Loop over file lines
518 std::string fileline = ""; 519 std::string fileline = "";
519 std::string coordsys = "galactic"; 520 std::string coordsys = "galactic";
@@ -548,7 +549,50 @@ void GSkyRegions::load(const GFilename&amp; filename) @@ -548,7 +549,50 @@ void GSkyRegions::load(const GFilename&amp; filename)
548 region.read(fileline); 549 region.read(fileline);
549 append(region); 550 append(region);
550 } 551 }
551 - 552 +
  553 + // else, prepend the coordinate system
  554 + else {
  555 + std::string newfileline = coordsys;
  556 + newfileline.append("; ");
  557 + newfileline.append(fileline);
  558 + region.read(newfileline);
  559 + append(region);
  560 + }
  561 + }
  562 +
  563 + // If region is a rectangle
  564 + if (std::string::npos != fileline.find("box")) {
  565 +
  566 + // Create instance of GSkyRegion object
  567 + GSkyRegionRect region;
  568 +
  569 + // If coordinate system and region defined on the same line
  570 + if ((std::string::npos != fileline.find("fk5")) ||
  571 + (std::string::npos != fileline.find("icrs")) ||
  572 + (std::string::npos != fileline.find("galactic"))) {
  573 + region.read(fileline);
  574 + append(region);
  575 + }
  576 +
  577 + // else, prepend the coordinate system
  578 + else {
  579 + coordsys = "icrs";
  580 + }
  581 +
  582 + // If region is a circle
  583 + if (std::string::npos != fileline.find("circle")) {
  584 +
  585 + // Create instance of GSkyRegion object
  586 + GSkyRegionCircle region;
  587 +
  588 + // If coordinate system and region defined on the same line
  589 + if ((std::string::npos != fileline.find("fk5")) ||
  590 + (std::string::npos != fileline.find("icrs")) ||
  591 + (std::string::npos != fileline.find("galactic"))) {
  592 + region.read(fileline);
  593 + append(region);
  594 + }
  595 +
552 // else, prepend the coordinate system 596 // else, prepend the coordinate system
553 else { 597 else {
554 std::string newfileline = coordsys; 598 std::string newfileline = coordsys;
@@ -557,7 +601,7 @@ void GSkyRegions::load(const GFilename&amp; filename) @@ -557,7 +601,7 @@ void GSkyRegions::load(const GFilename&amp; filename)
557 region.read(newfileline); 601 region.read(newfileline);
558 append(region); 602 append(region);
559 } 603 }
560 - } 604 + }
561 } 605 }
562 606
563 // Close file 607 // Close file
@@ -566,7 +610,7 @@ void GSkyRegions::load(const GFilename&amp; filename) @@ -566,7 +610,7 @@ void GSkyRegions::load(const GFilename&amp; filename)
566 // Store filename 610 // Store filename
567 m_filename = filename; 611 m_filename = filename;
568 612
569 - } 613 + }
570 614
571 // File could not be opened 615 // File could not be opened
572 else { 616 else {
@@ -596,7 +640,7 @@ void GSkyRegions::save(const GFilename&amp; filename) const @@ -596,7 +640,7 @@ void GSkyRegions::save(const GFilename&amp; filename) const
596 640
597 // If file opened correctly, then save regions 641 // If file opened correctly, then save regions
598 if (ds9file.is_open()) { 642 if (ds9file.is_open()) {
599 - 643 +
600 // Write global definition 644 // Write global definition
601 std::string fileline; 645 std::string fileline;
602 fileline.append("# Region file format: DS9 version 4.1\n"); 646 fileline.append("# Region file format: DS9 version 4.1\n");
@@ -610,7 +654,7 @@ void GSkyRegions::save(const GFilename&amp; filename) const @@ -610,7 +654,7 @@ void GSkyRegions::save(const GFilename&amp; filename) const
610 654
611 // Close file 655 // Close file
612 ds9file.close(); 656 ds9file.close();
613 - 657 +
614 // Store filename 658 // Store filename
615 m_filename = filename; 659 m_filename = filename;
616 660