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 34 #include "GSkyDir.hpp"
35 35 #include "GSkyRegion.hpp"
36 36 #include "GSkyRegionCircle.hpp"
  37 +#include "GSkyRegionRect.hpp"
37 38 #include "GSkyRegions.hpp"
38 39  
39 40 /* __ Method name definitions ____________________________________________ */
... ... @@ -369,7 +370,7 @@ void GSkyRegions::remove(const int& index)
369 370  
370 371 // Erase region component from container
371 372 m_regions.erase(m_regions.begin() + index);
372   -
  373 +
373 374 // Return
374 375 return;
375 376 }
... ... @@ -395,7 +396,7 @@ void GSkyRegions::extend(const GSkyRegions& regions)
395 396 // Reserve enough space
396 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 400 for (int i = 0; i < num; ++i) {
400 401  
401 402 // Append region to container
... ... @@ -404,7 +405,7 @@ void GSkyRegions::extend(const GSkyRegions&amp; regions)
404 405 } // endfor: looped over all regions
405 406  
406 407 } // endif: region container was not empty
407   -
  408 +
408 409 // Return
409 410 return;
410 411 }
... ... @@ -424,7 +425,7 @@ bool GSkyRegions::contains(const GSkyDir&amp; dir) const
424 425 {
425 426 // Initialise return value
426 427 bool overlap = false;
427   -
  428 +
428 429 // Loop over regions
429 430 for (int i = 0; i < size(); ++i) {
430 431 overlap = m_regions[i]->contains(dir);
... ... @@ -432,12 +433,12 @@ bool GSkyRegions::contains(const GSkyDir&amp; dir) const
432 433 break;
433 434 }
434 435 }
435   -
  436 +
436 437 // Return result
437 438 return overlap;
438 439 }
439 440  
440   -
  441 +
441 442 /***********************************************************************//**
442 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 452 {
452 453 // Initialise return value
453 454 bool overlap = false;
454   -
  455 +
455 456 // Loop over regions
456 457 for (int i = 0; i < size(); ++i) {
457 458 overlap = m_regions[i]->overlaps(region);
... ... @@ -459,7 +460,7 @@ bool GSkyRegions::overlaps(const GSkyRegion&amp; region) const
459 460 break;
460 461 }
461 462 }
462   -
  463 +
463 464 // Return result
464 465 return overlap;
465 466 }
... ... @@ -473,14 +474,14 @@ bool GSkyRegions::overlaps(const GSkyRegion&amp; region) const
473 474 * with one of the regions in the container, false otherwise
474 475 *
475 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 478 * each other
478 479 ***************************************************************************/
479 480 bool GSkyRegions::overlaps(const GSkyRegions& regions) const
480 481 {
481 482 // Initialize return value
482 483 bool overlap = false;
483   -
  484 +
484 485 // Loop over each region in the container
485 486 for (int i = 0; i < size(); ++i) {
486 487 overlap = regions.overlaps(*m_regions[i]);
... ... @@ -488,7 +489,7 @@ bool GSkyRegions::overlaps(const GSkyRegions&amp; regions) const
488 489 break;
489 490 }
490 491 }
491   -
  492 +
492 493 // Return result
493 494 return overlap;
494 495 }
... ... @@ -513,7 +514,7 @@ void GSkyRegions::load(const GFilename&amp; filename)
513 514 std::ifstream ds9file;
514 515 ds9file.open(filename.url().c_str());
515 516 if (ds9file.is_open()) {
516   -
  517 +
517 518 // Loop over file lines
518 519 std::string fileline = "";
519 520 std::string coordsys = "galactic";
... ... @@ -548,7 +549,50 @@ void GSkyRegions::load(const GFilename&amp; filename)
548 549 region.read(fileline);
549 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 596 // else, prepend the coordinate system
553 597 else {
554 598 std::string newfileline = coordsys;
... ... @@ -557,7 +601,7 @@ void GSkyRegions::load(const GFilename&amp; filename)
557 601 region.read(newfileline);
558 602 append(region);
559 603 }
560   - }
  604 + }
561 605 }
562 606  
563 607 // Close file
... ... @@ -566,7 +610,7 @@ void GSkyRegions::load(const GFilename&amp; filename)
566 610 // Store filename
567 611 m_filename = filename;
568 612  
569   - }
  613 + }
570 614  
571 615 // File could not be opened
572 616 else {
... ... @@ -596,7 +640,7 @@ void GSkyRegions::save(const GFilename&amp; filename) const
596 640  
597 641 // If file opened correctly, then save regions
598 642 if (ds9file.is_open()) {
599   -
  643 +
600 644 // Write global definition
601 645 std::string fileline;
602 646 fileline.append("# Region file format: DS9 version 4.1\n");
... ... @@ -610,7 +654,7 @@ void GSkyRegions::save(const GFilename&amp; filename) const
610 654  
611 655 // Close file
612 656 ds9file.close();
613   -
  657 +
614 658 // Store filename
615 659 m_filename = filename;
616 660  
... ...