source: trunk/src/Outputs/AnnotationWriter.cc

Last change on this file was 1438, checked in by MatthewWhiting, 7 years ago

Correcting the size of the ellipse passed to the AnnotationWriter?.
This is now given in degrees.
Fixes #524

File size: 6.9 KB
RevLine 
[1072]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// -----------------------------------------------------------------------
[1089]28#include <duchamp/duchamp.hh>
[1072]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  {
[1076]47    /// @details Sets the comment string to the default of '#' and the colour to.
[1072]48    this->itsComment = "#";
[1076]49    this->itsColour = duchamp::annotationColour;
[1072]50  }
51
52  AnnotationWriter::AnnotationWriter(std::string name):
53    FileCatalogueWriter(name)
54  {
[1075]55    /// @details Sets the comment string to the default of '#'.
[1072]56    this->itsComment = "#";
[1076]57    this->itsColour = duchamp::annotationColour;
58 }
[1072]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;
[1076]70    this->itsColour = other.itsColour;
[1072]71    return *this;
72  }
73 
74
75  void AnnotationWriter::writeHeader()
76  {
[1075]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
[1072]81    if(this->itsOpenFlag){
[1075]82      this->itsFileStream << this->itsComment << " Duchamp Source Finder v."<< VERSION <<"\n";
[1072]83      this->itsFileStream << this->itsComment << " Results for FITS file: " << this->itsParam->getFullImageFile() << "\n";
84    }
85  }
86
87  void AnnotationWriter::writeParameters()
88  {
[1075]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
[1072]95    if(this->itsOpenFlag){
96     
[1075]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";
[1072]103      }
104
105    }
106  }
107
108  void AnnotationWriter::writeStats()
109  {
[1075]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
[1072]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
[1228]124
125    void AnnotationWriter::writeCommentString(std::string line)
126    {
127        /// @details A simple way to write a line as a comment, where
128        /// the start of the line is given by the itsComment string.
129
130        if(this->itsOpenFlag){
131            this->itsFileStream << this->itsComment << line << "\n";
132        }
133    }
134
[1072]135  void AnnotationWriter::writeEntry(Detection *object)
136  {
[1075]137    /// @details The given object is written as an annotation. If the
138    /// parameter annotationType = "borders", then vertical &
139    /// horizontal lines are drawn around the spatial extent of the
140    /// detection, otherwise (annotationType = "circles") a circle is
141    /// drawn with radius of (half) the maximum spatial width. A text
142    /// string is also written showing the object ID. In all cases,
143    /// the derived class must define the actual methods for writing
144    /// lines, circles, text.
145
[1072]146    if(this->itsOpenFlag){
147
148      if(this->itsParam->getAnnotationType() == "borders"){
[1293]149
150        std::vector<std::vector<Voxel> > vertexSets = object->getVertexSet();
151        for(size_t n=0;n<vertexSets.size();n++){
152            // for each set of vertices
153         
154            std::vector<double> x,y;
155            for(size_t i=0;i<vertexSets[n].size();i++){
156                double *pix = new double[3];
157                double *wld = new double[3];
158                pix[0]=vertexSets[n][i].getX()-0.5;
159                pix[1]=vertexSets[n][i].getY()-0.5;
160                pix[2]=object->getZcentre();
161                if(this->itsHead->isWCS()){
162                    this->itsHead->pixToWCS(pix,wld);
163                    x.push_back(wld[0]);
164                    y.push_back(wld[1]);
165                }
166                else{
167                    x.push_back(pix[0]);
168                    y.push_back(pix[1]);
169                }
170                delete [] wld;
171                delete [] pix;
172            }
173            this->joinTheDots(x,y);             
174           
[1072]175        }
176      }
177      else if(this->itsParam->getAnnotationType()=="circles"){
178        float radius = std::max(object->getRAWidth(),object->getDecWidth())/120.;
179        this->circle(object->getRA(),object->getDec(),radius);
180      }
[1130]181      else if(this->itsParam->getAnnotationType()=="ellipses"){
[1438]182        this->ellipse(object->getRA(),object->getDec(),object->getMajorAxis()/60.,object->getMinorAxis()/60.,object->getPositionAngle());
[1131]183        //this->ellipse(object->getXaverage(),object->getYaverage(),object->getMajorAxis(),object->getMinorAxis(),object->getPositionAngle());
[1130]184      }
[1072]185
186      std::stringstream ss;
187      ss << object->getID();
188      this->text(object->getRA(),object->getDec(),ss.str());
189      this->itsFileStream << "\n";
190
191    }
192  }
193
194
195}
Note: See TracBrowser for help on using the repository browser.