source: tags/release-1.6.1/src/Outputs/CasaAnnotationWriter.cc @ 1441

Last change on this file since 1441 was 1293, checked in by MatthewWhiting, 11 years ago

Ticket #200 - Largely resolved. The getVertexSet function now resides in Object3D, and returns a set of Voxel vectors, that describe the bounding vertices of the object (in 2D projection). Changes also made to the functions that call this, and to the verification outputs that are affected (notably the .ann and .reg files).

File size: 5.6 KB
Line 
1// -----------------------------------------------------------------------
2// CasaAnnotationWriter.hh: Class for writing results to CASA annotation files.
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// -----------------------------------------------------------------------
28#include <duchamp/Outputs/CasaAnnotationWriter.hh>
29#include <duchamp/Outputs/AnnotationWriter.hh>
30#include <duchamp/Outputs/CatalogueWriter.hh>
31#include <duchamp/Outputs/FileCatalogueWriter.hh>
32#include <duchamp/Detection/detection.hh>
33#include <duchamp/Utils/utils.hh>
34#include <ios>
35#include <iostream>
36#include <iomanip>
37#include <fstream>
38#include <string>
39
40namespace duchamp {
41
42   CasaAnnotationWriter::CasaAnnotationWriter():
43    AnnotationWriter()
44  {
45    this->itsSpatialUnits="deg";
46  }
47
48  CasaAnnotationWriter::CasaAnnotationWriter(std::string name):
49    AnnotationWriter(name)
50  {
51    this->itsSpatialUnits="deg";
52  }
53
54  CasaAnnotationWriter::CasaAnnotationWriter(const CasaAnnotationWriter& other)
55  {
56    this->operator=(other);
57  }
58
59  CasaAnnotationWriter& CasaAnnotationWriter::operator= (const CasaAnnotationWriter& other)
60  {
61    if(this==&other) return *this;
62    ((AnnotationWriter &) *this) = other;
63    this->itsSpatialUnits = other.itsSpatialUnits;
64    return *this;
65  }
66
67  void CasaAnnotationWriter::writeHeader()
68  {
69    if(this->itsOpenFlag){
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) << ", ";
80      if(this->itsHead->isWCS()){
81        if(this->itsHead->getWCS()->equinox == 1950.) this->itsFileStream << "coord=1950 ";
82        else  this->itsFileStream << "coord=J2000 ";
83      }
84      else this->itsSpatialUnits="pix";
85      this->itsFileStream<<"\n#\n";
86      this->itsFileStream.setf(std::ios::fixed);
87      this->itsFileStream << std::setprecision(6);
88    }
89  }
90
91  void CasaAnnotationWriter::writeEntry(Detection *object)
92  {
93    if(this->itsOpenFlag){
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();
104      // this->box(wld[0],wld[3],wld[1],wld[4],ss.str());
105      this->AnnotationWriter::writeEntry(object);
106    }
107  }
108
109  void CasaAnnotationWriter::text(double x, double y, std::string text)
110  {
111    if(this->itsOpenFlag){
112      this->itsFileStream << "text[[" << x << this->itsSpatialUnits<<"," << y << this->itsSpatialUnits<<"], '" << text<<"']\n";
113    }
114  }
115  void CasaAnnotationWriter::line(double x1, double x2, double y1, double y2)
116  {
117    if(this->itsOpenFlag){
118      this->itsFileStream << "line[[" << x1 << this->itsSpatialUnits << "," << y1 << this->itsSpatialUnits << "], [" << x2 << this->itsSpatialUnits << "," << y2 << this->itsSpatialUnits << "]]\n";
119    }
120  }
121  void CasaAnnotationWriter::circle(double x, double y, double r)
122  {
123    if(this->itsOpenFlag){
124      this->itsFileStream << "ann circle[[" << x << this->itsSpatialUnits << "," << y << this->itsSpatialUnits << "], " << r << this->itsSpatialUnits << "]\n";
125    }
126  }
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  }
141
142  void CasaAnnotationWriter::joinTheDots(std::vector<double> x, std::vector<double> y)
143  {
144    if(this->itsOpenFlag){
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";
149      }
150    }
151  }
152 
153}
Note: See TracBrowser for help on using the repository browser.