source: trunk/src/Outputs/KarmaAnnotationWriter.cc

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

For the Karma annotation files, reverting back to using individual lines (with LINE), rather than join the dots with CLINES. The reason for this is that CLINES has some built-in limit that prevents very large perimeters from being drawn.

File size: 5.3 KB
RevLine 
[1072]1// -----------------------------------------------------------------------
2// KarmaAnnotationWriter.hh: Class for writing results to karma 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/KarmaAnnotationWriter.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 <ios>
34#include <iostream>
35#include <fstream>
[1074]36#include <iomanip>
[1072]37#include <string>
38
39namespace duchamp {
40
41   KarmaAnnotationWriter::KarmaAnnotationWriter():
42    AnnotationWriter()
43  {
44  }
45
46  KarmaAnnotationWriter::KarmaAnnotationWriter(std::string name):
47    AnnotationWriter(name)
48  {
49  }
50
51  KarmaAnnotationWriter::KarmaAnnotationWriter(const KarmaAnnotationWriter& other)
52  {
53    this->operator=(other);
54  }
55
56  KarmaAnnotationWriter& KarmaAnnotationWriter::operator= (const KarmaAnnotationWriter& other)
57  {
58    if(this==&other) return *this;
59    ((AnnotationWriter &) *this) = other;
60    return *this;
61  }
62  void KarmaAnnotationWriter::writeTableHeader()
63  {
64    if(this->itsOpenFlag){
[1076]65      this->itsFileStream << "COLOR " << this->itsColour<<"\n";
[1131]66      this->itsFileStream << "PA STANDARD\n";
67      this->itsFileStream << "COORD W\n";
[1074]68      this->itsFileStream << std::setprecision(6);
69      this->itsFileStream.setf(std::ios::fixed);
[1072]70    }
71  }
72
[1074]73  void KarmaAnnotationWriter::text(double x, double y, std::string text)
[1072]74  {
75    if(this->itsOpenFlag){
76      this->itsFileStream << "TEXT " << x << " " << y << " " << text<<"\n";
77    }
78  }
[1074]79  void KarmaAnnotationWriter::line(double x1, double x2, double y1, double y2)
[1072]80  {
81    if(this->itsOpenFlag){
82      this->itsFileStream << "LINE " << x1 << " " << y1 << " " << x2 << " " << y2 << "\n";
83    }
84  }
[1074]85  void KarmaAnnotationWriter::circle(double x, double y, double r)
[1072]86  {
87    if(this->itsOpenFlag){
88      this->itsFileStream << "CIRCLE " << x << " " << y << " " << r << "\n";
89    }
90  }
[1126]91  void KarmaAnnotationWriter::box(double x1, double x2, double y1, double y2, std::string label)
92  {
93    if(this->itsOpenFlag){
94      this->itsFileStream << "BOX " << x1 << " " << y1 << " " << x2 << " " << y2 <<"\n";
95    }
96  }
[1074]97  void KarmaAnnotationWriter::ellipse(double x, double y, double r1, double r2, double angle)
[1072]98  {
99    if(this->itsOpenFlag){
[1131]100      double angleUsed=angle;
101      // Need to correct the angle here. This is what the Karma documentation says, at http://www.atnf.csiro.au/computing/software/karma/user-manual/node17.html:
[1143]102      //
[1131]103      // Standard Postition Angles are generally defined in the Cartesian sense where PA=0 specifies {X>0,Y=0}, PA=90 specifies {X=0,Y>0}, and so forth.
104      // In a coordinate system where X increases from left to right, and Y increases from bottom to top, PA will increase in a counter-clockwise direction.
105      // However this will be reversed if the X increases from right to left, or Y from top to bottom (though not both). So be careful! To summarize:
106      //  PA is measured CCW from right in R coords, and CW from right in P coords. How it is measured in W coords depends on the coordinate system:
107      // in many cases, it will be the same as R coords, but this is not always true! For example, most astronomical maps of the sky have the X coordinate
108      // increasing toward the left, in which case, PA will be measured CW from left!
109      //
110      // So, we need to invert the sign of the PA when RA increases to the left (as is usual), then subtract 90degrees.
111      if(this->itsHead->getWCS()->cdelt[0]<0.) angleUsed *= -1.;
112      angleUsed -= 90.;
113      this->itsFileStream << "ELLIPSE " << x << " " << y << " " << r1 << " " << r2 << " " << angleUsed << "\n";
[1072]114    }
115  }
116
[1076]117  void KarmaAnnotationWriter::joinTheDots(std::vector<double> x, std::vector<double> y)
118  {
119    if(this->itsOpenFlag){
120      if(x.size()==y.size()){
[1415]121        // this->itsFileStream << "CLINES";
122        // for(size_t i=0;i<x.size();i++) this->itsFileStream <<" " << x[i] << " " << y[i];
123        // this->itsFileStream << "\n";
124         
125          for(size_t i=0;i<x.size()-1;i++) this->line(x[i],x[i+1],y[i],y[i+1]);
126          this->line(x[x.size()-1],x[0],y[x.size()-1],y[0]);
127
[1076]128      }
129    }
130  }
131
[1072]132 
133}
Note: See TracBrowser for help on using the repository browser.