source: trunk/src/Outputs/AnnotationWriter.cc @ 1089

Last change on this file since 1089 was 1089, checked in by MatthewWhiting, 12 years ago

Getting the order of includes right, so that we get the version correct.

File size: 6.3 KB
Line 
1// -----------------------------------------------------------------------
2// AnnotationWriter.cc: Writing output catalogues to VOTable 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/duchamp.hh>
29#include <duchamp/Outputs/AnnotationWriter.hh>
30#include <duchamp/Outputs/CatalogueWriter.hh>
31#include <duchamp/Outputs/FileCatalogueWriter.hh>
32#include <duchamp/fitsHeader.hh>
33#include <duchamp/param.hh>
34#include <duchamp/Detection/detection.hh>
35#include <ios>
36#include <iostream>
37#include <fstream>
38#include <sstream>
39#include <string>
40
41
42namespace duchamp {
43
44  AnnotationWriter::AnnotationWriter():
45    FileCatalogueWriter()
46  {
47    /// @details Sets the comment string to the default of '#' and the colour to.
48    this->itsComment = "#";
49    this->itsColour = duchamp::annotationColour;
50  }
51
52  AnnotationWriter::AnnotationWriter(std::string name):
53    FileCatalogueWriter(name)
54  {
55    /// @details Sets the comment string to the default of '#'.
56    this->itsComment = "#";
57    this->itsColour = duchamp::annotationColour;
58 }
59
60  AnnotationWriter::AnnotationWriter(const AnnotationWriter& other)
61  {
62    this->operator=(other);
63  }
64
65  AnnotationWriter& AnnotationWriter::operator= (const AnnotationWriter& other)
66  {
67    if(this==&other) return *this;
68    ((FileCatalogueWriter &) *this) = other;
69    this->itsComment = other.itsComment;
70    this->itsColour = other.itsColour;
71    return *this;
72  }
73 
74
75  void AnnotationWriter::writeHeader()
76  {
77    /// @details Writes, as comments, two lines indicating the file
78    /// comes from Duchamp (giving the version number) and the name of
79    /// the FITS file (with subsection if used).
80
81    if(this->itsOpenFlag){
82      this->itsFileStream << this->itsComment << " Duchamp Source Finder v."<< VERSION <<"\n";
83      this->itsFileStream << this->itsComment << " Results for FITS file: " << this->itsParam->getFullImageFile() << "\n";
84    }
85  }
86
87  void AnnotationWriter::writeParameters()
88  {
89    /// @details Writes, as comments, a summary of the parameters used
90    /// in running Duchamp. Uses the VOParam interface (as for
91    /// VOTableCatalogeWriter), taking just the name and the value -
92    /// this provides the effective parameter set that generated the
93    /// detection list
94
95    if(this->itsOpenFlag){
96     
97      std::vector<VOParam> paramList = this->itsParam->getVOParams();
98      size_t width=0;
99      for(std::vector<VOParam>::iterator param=paramList.begin();param<paramList.end();param++) width=std::max(width,param->name().size()+2);
100      for(std::vector<VOParam>::iterator param=paramList.begin();param<paramList.end();param++){
101        this->itsFileStream.setf(std::ios::left);
102        this->itsFileStream << this->itsComment << " "<< std::setw(width) << param->name() << param->value() <<"\n";
103      }
104
105    }
106  }
107
108  void AnnotationWriter::writeStats()
109  {
110    /// @details Writes, as comments, the detection threshold, plus
111    /// the mean and std.deviation (or their robust estimates) of the
112    /// noise. If robust methods are used, a note is added to that
113    /// effect.
114
115    if(this->itsOpenFlag){
116      this->itsFileStream << this->itsComment << " Detection threshold used = " << this->itsStats->getThreshold() <<"\n";
117      this->itsFileStream << this->itsComment << " Mean of noise background = " << this->itsStats->getMiddle() << "\n";
118      this->itsFileStream << this->itsComment << " Std. Deviation of noise background = " << this->itsStats->getSpread() << "\n";
119      if(this->itsParam->getFlagRobustStats())
120        this->itsFileStream << this->itsComment << "  [Using robust methods]\n";
121    }
122  }
123
124  void AnnotationWriter::writeEntry(Detection *object)
125  {
126    /// @details The given object is written as an annotation. If the
127    /// parameter annotationType = "borders", then vertical &
128    /// horizontal lines are drawn around the spatial extent of the
129    /// detection, otherwise (annotationType = "circles") a circle is
130    /// drawn with radius of (half) the maximum spatial width. A text
131    /// string is also written showing the object ID. In all cases,
132    /// the derived class must define the actual methods for writing
133    /// lines, circles, text.
134
135    if(this->itsOpenFlag){
136
137      if(this->itsParam->getAnnotationType() == "borders"){
138        double *pix = new double[3];
139        double *wld = new double[3];
140        double x1,x2,y1,y2;
141        std::vector<int> vertexSet = object->getVertexSet();
142        for(size_t i=0;i<vertexSet.size()/4;i++){
143          pix[0] = vertexSet[i*4]-0.5;
144          pix[1] = vertexSet[i*4+1]-0.5;
145          pix[2] = object->getZcentre();
146          if(this->itsHead->isWCS()){
147            this->itsHead->pixToWCS(pix,wld);
148            x1=wld[0];
149            y1=wld[1];
150          }
151          else{
152            x1=pix[0];
153            y1=pix[1];
154          }
155          pix[0] = vertexSet[i*4+2]-0.5;
156          pix[1] = vertexSet[i*4+3]-0.5;
157          if(this->itsHead->isWCS()){
158            this->itsHead->pixToWCS(pix,wld);
159            x2=wld[0];
160            y2=wld[1];
161          }
162          else{
163            x2=wld[0];
164            y2=wld[1];
165          }
166          this->line(x1,x2,y1,y2);
167        }
168      }
169      else if(this->itsParam->getAnnotationType()=="circles"){
170        float radius = std::max(object->getRAWidth(),object->getDecWidth())/120.;
171        this->circle(object->getRA(),object->getDec(),radius);
172      }
173
174      std::stringstream ss;
175      ss << object->getID();
176      this->text(object->getRA(),object->getDec(),ss.str());
177      this->itsFileStream << "\n";
178
179    }
180  }
181
182
183}
Note: See TracBrowser for help on using the repository browser.