source: trunk/src/Plotting/SimpleSpectralPlot.cc @ 1241

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

Ticket #195 - Large amount of code refactoring the plotting classes into separate ones with inheritance.

File size: 5.1 KB
Line 
1// -----------------------------------------------------------------------
2// SimpleSpectralPlot.hh: Definition of the class producing a single spectral plot
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/Plotting/SimpleSpectralPlot.hh>
29#include <duchamp/Plotting/SpectralPlot.hh>
30#include <duchamp/FitsHeader.hh>
31#include <duchamp/PixelMap/Scan.hh>
32#include <duchamp/PixelMap/Object2D.hh>
33#include <string>
34
35namespace duchamp {
36
37    namespace Plot {
38
39        SimpleSpectralPlot::SimpleSpectralPlot():
40            SpectralPlot()
41        {
42            this->numOnPage = 1;
43        }
44         
45        SimpleSpectralPlot::SimpleSpectralPlot(const SimpleSpectralPlot& other)
46        {
47            this->operator=(other);
48        }
49
50        SimpleSpectralPlot& SimpleSpectralPlot::operator=(const SimpleSpectralPlot& other)
51        {
52            if(this == &other) return *this;
53            ((SpectralPlot &) *this) = other;
54            return *this;
55        }
56
57        int SimpleSpectralPlot::setUpPlot(std::string pgDestination)
58        {
59            if(pgDestination == "/xs") this->paperWidth=12.;
60            this->paperHeight = this->paperWidth*this->aspectRatio;
61            this->open(pgDestination);
62            float scaling = this->paperWidth*inchToCm / a4width;
63            this->mainCoords[0] = Plot::spMainX1/inchToCm * scaling;
64            this->mainCoords[1] = (Plot::spMapX1+Plot::spMainY2-Plot::spMainY1)/inchToCm * scaling;
65            this->mainCoords[2] = Plot::spMainY1/inchToCm * scaling;
66            this->mainCoords[3] = Plot::spMainY2/inchToCm * scaling;
67            return this->identifier;
68
69        }
70
71        void SimpleSpectralPlot::label(std::string xlabel, std::string ylabel, std::string title)
72        {
73            /// @details
74            /// Calls calcCoords, to calculate correct coordinates for this spectrum.
75            /// Defines the region for the header information, making it centred
76            ///  on the page.
77            /// Also writes the velocity (x axis) label, given by the string argument.
78            /// \param xlabel Label to go on the velocity/spectral axis.
79
80            cpgvsiz(this->mainCoords[0],this->mainCoords[1],this->mainCoords[2],this->mainCoords[3]);
81            cpgsch(2.);
82            cpgmtxt("B",3.,0.5,0.5,xlabel.c_str());
83            cpgmtxt("L",4.,0.5,0.5,ylabel.c_str());
84            cpgmtxt("T",2.,0.5,0.5,title.c_str());
85        }
86
87        void SimpleSpectralPlot::gotoMainSpectrum(float x1, float x2, float y1, float y2)
88        {
89            /// @details
90            ///  Defines the region for the main spectrum.
91            ///  Draws the box, with tick marks, and
92            ///   writes the flux (y axis) label, given by the string argument.
93            /// \param x1 Minimum X-coordinate of box.
94            /// \param x2 Maximum X-coordinate of box.
95            /// \param y1 Minimum Y-coordinate of box.
96            /// \param y2 Maximum Y-coordinate of box.
97            /// \param ylabel Label for the flux (Y) axis.
98
99            cpgvsiz(this->mainCoords[0],this->mainCoords[1],this->mainCoords[2],this->mainCoords[3]);
100            cpgsch(2.);
101            cpgswin(x1,x2,y1,y2);
102            cpgbox("1bcnst",0.,0,"bcnst1v",0.,0);
103        }
104
105        void SimpleSpectralPlot::markDetectedPixels(short *detectMap, size_t size, FitsHeader &head)
106        {
107            PixelInfo::Object2D detectionLine;
108            for(size_t z=0;z<size;z++)
109                if(detectMap[z]>0) detectionLine.addPixel(z,0);
110            std::vector<PixelInfo::Scan> detlist = detectionLine.getScanlist();     
111            // size_t dim[2]; dim[0]=size; dim[1]=1;
112            // Image detIm(dim);
113            // detIm.setMinSize(1);
114            // for(size_t z=0;z<size;z++) detIm.setPixValue(z,float(detectMap[z]));
115            // detIm.stats().setThreshold(0.5);
116            // std::vector<PixelInfo::Scan> detlist=detIm.findSources1D();
117            for(std::vector<PixelInfo::Scan>::iterator sc=detlist.begin();sc<detlist.end();sc++){
118                float v1,v2;
119                double zero=0.;
120                if(head.isWCS()){
121                    double zpt=double(sc->getX()-0.5);
122                    v1=head.pixToVel(zero,zero,zpt);
123                    zpt=double(sc->getXmax()+0.5);
124                    v2=head.pixToVel(zero,zero,zpt);
125                }
126                else{
127                    v1=float(sc->getX()-0.5);
128                    v2=float(sc->getXmax()+0.5);
129                }
130                float x1,x2,y1,y2;
131                cpgqwin(&x1,&x2,&y1,&y2);
132                float ymax=y2-0.04*(y2-y1);
133                float ymin=y2-0.06*(y2-y1);
134                int lw,fs;
135                cpgqlw(&lw);
136                cpgqfs(&fs);
137                cpgslw(3);
138                cpgsfs(1);
139                cpgrect(v1,v2,ymin,ymax);
140                cpgslw(lw);
141                cpgsfs(fs);
142            }
143        }
144
145    }
146
147}
Note: See TracBrowser for help on using the repository browser.