source: branches/NewStructure/src/Outputs/CasaAnnotationWriter.cc

Last change on this file was 1411, checked in by MatthewWhiting, 10 years ago

Results of merging Outputs with trunk

File size: 5.6 KB
RevLine 
[1072]1// -----------------------------------------------------------------------
[1126]2// CasaAnnotationWriter.hh: Class for writing results to CASA annotation files.
[1072]3// -----------------------------------------------------------------------
4// Copyright (C) 2006, Matthew Whiting, ATNF
5//
6// This program is free software; you can redistribute it and/or modify it
7// under the terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 2 of the License, or (at your
9// option) any later version.
10//
11// Duchamp is distributed in the hope that it will be useful, but WITHOUT
12// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14// for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with Duchamp; if not, write to the Free Software Foundation,
18// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
19//
20// Correspondence concerning Duchamp may be directed to:
21//    Internet email: Matthew.Whiting [at] atnf.csiro.au
22//    Postal address: Dr. Matthew Whiting
23//                    Australia Telescope National Facility, CSIRO
24//                    PO Box 76
25//                    Epping NSW 1710
26//                    AUSTRALIA
27// -----------------------------------------------------------------------
[1126]28#include <duchamp/Outputs/CasaAnnotationWriter.hh>
[1072]29#include <duchamp/Outputs/AnnotationWriter.hh>
30#include <duchamp/Outputs/CatalogueWriter.hh>
31#include <duchamp/Outputs/FileCatalogueWriter.hh>
32#include <duchamp/Detection/detection.hh>
[1076]33#include <duchamp/Utils/utils.hh>
[1072]34#include <ios>
35#include <iostream>
[1074]36#include <iomanip>
[1072]37#include <fstream>
38#include <string>
39
40namespace duchamp {
41
[1126]42   CasaAnnotationWriter::CasaAnnotationWriter():
[1072]43    AnnotationWriter()
44  {
[1126]45    this->itsSpatialUnits="deg";
[1072]46  }
47
[1126]48  CasaAnnotationWriter::CasaAnnotationWriter(std::string name):
[1072]49    AnnotationWriter(name)
50  {
[1126]51    this->itsSpatialUnits="deg";
[1072]52  }
53
[1126]54  CasaAnnotationWriter::CasaAnnotationWriter(const CasaAnnotationWriter& other)
[1072]55  {
56    this->operator=(other);
57  }
58
[1126]59  CasaAnnotationWriter& CasaAnnotationWriter::operator= (const CasaAnnotationWriter& other)
[1072]60  {
61    if(this==&other) return *this;
62    ((AnnotationWriter &) *this) = other;
[1126]63    this->itsSpatialUnits = other.itsSpatialUnits;
[1072]64    return *this;
65  }
[1126]66
67  void CasaAnnotationWriter::writeHeader()
[1072]68  {
69    if(this->itsOpenFlag){
[1126]70      this->itsFileStream << "#CRTFv0\n";  //This MUST be written as the first line in a CASA region file
71      this->AnnotationWriter::writeHeader();
72    }
73
74  }
75
76  void CasaAnnotationWriter::writeTableHeader()
77  {
78    if(this->itsOpenFlag){
79      this->itsFileStream << "global color=" << makelower(this->itsColour) << ", ";
[1077]80      if(this->itsHead->isWCS()){
[1126]81        if(this->itsHead->getWCS()->equinox == 1950.) this->itsFileStream << "coord=1950 ";
82        else  this->itsFileStream << "coord=J2000 ";
[1077]83      }
[1126]84      else this->itsSpatialUnits="pix";
85      this->itsFileStream<<"\n#\n";
[1074]86      this->itsFileStream.setf(std::ios::fixed);
87      this->itsFileStream << std::setprecision(6);
[1072]88    }
89  }
90
[1126]91  void CasaAnnotationWriter::writeEntry(Detection *object)
[1072]92  {
93    if(this->itsOpenFlag){
[1126]94      double pix[6],wld[6];
95      pix[0]=object->getXmin()-0.5;
96      pix[1]=object->getYmin()-0.5;
97      pix[2]=object->getZcentre();
98      pix[3]=object->getXmax()+0.5;
99      pix[4]=object->getYmax()+0.5;
100      pix[5]=object->getZcentre();
101      this->itsHead->pixToWCS(pix,wld,2);
102      std::stringstream ss;
103      ss << object->getID();
[1411]104      // this->box(wld[0],wld[3],wld[1],wld[4],ss.str());
[1126]105      this->AnnotationWriter::writeEntry(object);
[1072]106    }
107  }
[1126]108
109  void CasaAnnotationWriter::text(double x, double y, std::string text)
[1072]110  {
111    if(this->itsOpenFlag){
[1126]112      this->itsFileStream << "text[[" << x << this->itsSpatialUnits<<"," << y << this->itsSpatialUnits<<"], '" << text<<"']\n";
[1072]113    }
114  }
[1126]115  void CasaAnnotationWriter::line(double x1, double x2, double y1, double y2)
[1072]116  {
117    if(this->itsOpenFlag){
[1126]118      this->itsFileStream << "line[[" << x1 << this->itsSpatialUnits << "," << y1 << this->itsSpatialUnits << "], [" << x2 << this->itsSpatialUnits << "," << y2 << this->itsSpatialUnits << "]]\n";
[1072]119    }
120  }
[1126]121  void CasaAnnotationWriter::circle(double x, double y, double r)
[1072]122  {
123    if(this->itsOpenFlag){
[1126]124      this->itsFileStream << "ann circle[[" << x << this->itsSpatialUnits << "," << y << this->itsSpatialUnits << "], " << r << this->itsSpatialUnits << "]\n";
[1072]125    }
126  }
[1126]127  void CasaAnnotationWriter::box(double x1, double x2, double y1, double y2, std::string label)
128  {
129    if(this->itsOpenFlag){
130      this->itsFileStream << "box[["<<x1<<this->itsSpatialUnits<<","<<y1<<this->itsSpatialUnits<<"], ["<<x2<<this->itsSpatialUnits<<","<<y2<<this->itsSpatialUnits<<"]]";
131      if(label=="") this->itsFileStream << "\n";
132      else this->itsFileStream << ", label='"<<label<<"'\n";
133    }
134  }
135  void CasaAnnotationWriter::ellipse(double x, double y, double r1, double r2, double angle)
136  {
137    if(this->itsOpenFlag){
138      this->itsFileStream << "ann ellipse[[" << x << this->itsSpatialUnits << "," << y << this->itsSpatialUnits << "], [" << r1 << this->itsSpatialUnits << "," << r2 << this->itsSpatialUnits << "], " << angle << "deg]\n";
139    }
140  }
[1072]141
[1126]142  void CasaAnnotationWriter::joinTheDots(std::vector<double> x, std::vector<double> y)
[1076]143  {
144    if(this->itsOpenFlag){
[1411]145        if(x.size()==y.size() && x.size()>0){
146            this->itsFileStream << "ann poly[["<<x[0]<<this->itsSpatialUnits<<", "<<y[0]<<this->itsSpatialUnits<<"]";
147            for(size_t i=0;i<x.size();i++) this->itsFileStream <<", [" << x[i]<<this->itsSpatialUnits << ", " << y[i]<<this->itsSpatialUnits<<"]";
148        this->itsFileStream << "]\n";
[1076]149      }
150    }
151  }
[1072]152 
153}
Note: See TracBrowser for help on using the repository browser.