source: tags/release-1.1.2/src/Cubes/plots.hh @ 1441

Last change on this file since 1441 was 393, checked in by MatthewWhiting, 17 years ago

Fixed up headers for trunk as well.

File size: 13.6 KB
Line 
1// -----------------------------------------------------------------------
2// plots.hh: Definition of the SpectralPlot and ImagePlot classes, for
3//           plotting spectra and maps of detected objects.
4// -----------------------------------------------------------------------
5// Copyright (C) 2006, Matthew Whiting, ATNF
6//
7// This program is free software; you can redistribute it and/or modify it
8// under the terms of the GNU General Public License as published by the
9// Free Software Foundation; either version 2 of the License, or (at your
10// option) any later version.
11//
12// Duchamp is distributed in the hope that it will be useful, but WITHOUT
13// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15// for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with Duchamp; if not, write to the Free Software Foundation,
19// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
20//
21// Correspondence concerning Duchamp may be directed to:
22//    Internet email: Matthew.Whiting [at] atnf.csiro.au
23//    Postal address: Dr. Matthew Whiting
24//                    Australia Telescope National Facility, CSIRO
25//                    PO Box 76
26//                    Epping NSW 1710
27//                    AUSTRALIA
28// -----------------------------------------------------------------------
29#ifndef PLOTS_H
30#define PLOTS_H
31
32#include <iostream>
33#include <sstream>
34#include <string>
35#include <math.h>
36#include <duchamp/pgheader.hh>
37
38namespace duchamp
39{
40
41  /**
42   * A namespace to control plotting of the spectral output and the
43   * spatial image output.
44   */
45
46  namespace Plot
47  {
48    const float inchToCm=2.54;        ///< Conversion factor from inches
49    ///   to centimetres.
50    const float a4width=21.0;         ///< A4 width in cm
51    const float a4height=29.7;        ///< A4 height in cm
52    const float psHoffset=0.35;       ///< The default horizontal pgplot
53    ///   offset applied to ps files
54    const float psVoffset=0.25;       ///< The default vertical pgplot
55    ///   offset applied to ps files
56
57    // These are the constants used for spacing out elements in SpectralPlot.
58    const float spMainX1 =  2.0;      ///< min X-value of main box [cm]
59    const float spMainX2 = 13.7;      ///< max X-value of main box [cm]
60    const float spZoomX1 = 15.0;      ///< min X-value of zoom box [cm]
61    const float spZoomX2 = 16.8;      ///< max X-value of zoom box [cm]
62    const float spMapX1  = 17.0;      ///< min X-value of map box [cm]
63    const float spMainY1 =  1.5;      ///< min Y-value of box wrt base
64    ///   of current spectrum [cm]
65    const float spMainY2 =  3.4;      ///< max Y-value of box wrt base
66    ///   of current spectrum [cm]
67    const float spXlabelOffset = 3.0; ///< Offset for X-axis label.
68    const float spYlabelOffset = 4.0; ///< Offset for Y-axis label.
69    const float spTitleOffset1 = 5.1; ///< Offset for first title line.
70    const float spTitleOffset2 = 3.6; ///< Offset for second title line.
71    const float spTitleOffset3 = 2.1; ///< Offset for third title line.
72    const float spTitleOffset4 = 0.6; ///< Offset for fourth title line.
73
74    const float spIndexSize = 0.6;    ///< PGPlot character height for
75    ///   tick mark labels
76    const float spLabelSize = 0.7;    ///< PGPlot character height for
77    ///   axis labels
78    const float spTitleSize = 0.8;    ///< PGPlot character height for
79    ///   plot title line
80
81    // These are the constants used for spacing out elements in ImagePlot.
82    const float imTitleOffset = 2.7;  ///< Offset for title of map.
83
84    // These are the constants used for spacing out elements in CutoutPlot.
85    const float cuMainX1 = 1.0;
86    const float cuMainX2 = 15.8;
87    const float cuMainY1 = 1.0;
88    const float cuMainY2 = 3.8;
89    const float cuMapX1 = 16.0;
90
91    //***************************************************************************
92    //***************************************************************************
93
94    /**
95     *  A class for plotting spectra of detections.
96     *  This class is designed to hold the dimensions and set up for the
97     *  plotting of the spectra (including the full spectra, the zoomed
98     *  in part, and the moment map).
99     *  The physical dimensions (in inches) of the plot and the elements
100     *   within it are stored, on the assumption that the plot will go on
101     *   an A4 page.
102     *  Simple accessor functions are provided to enable access to quantities
103     *   needed for pgplot routines.
104     */
105    class SpectralPlot
106    {
107    public:
108      SpectralPlot();    ///< Constructor
109      virtual ~SpectralPlot(); ///< Destructor
110      SpectralPlot(const SpectralPlot& p);
111      SpectralPlot& operator=(const SpectralPlot& p);
112
113      /** Set up PGPLOT output.*/
114      int setUpPlot(std::string pgDestination);
115
116      /** Calculate boundaries for boxes.*/
117      void calcCoords();
118      /** Set up the header & write the X-label.*/
119      void gotoHeader(std::string xlabel);
120
121      /** Write first line of header information (position/velocity
122          info) in correct place.*/
123      void firstHeaderLine(std::string line);   
124   
125      /** Write second line of header information (fluxes) in
126          correct place.*/
127      void secondHeaderLine(std::string line); 
128
129      /** Write third line of header information (WCS widths) in
130          correct place. */
131      void thirdHeaderLine(std::string line);   
132
133      /** Write fourth line of header information (pixel coordinates) in
134          correct place. */
135      void fourthHeaderLine(std::string line);   
136
137      /** Set up main spectral plotting region.*/
138      void gotoMainSpectrum(float x1, float x2, float y1, float y2,
139                            std::string ylabel);
140   
141      /** Set up zoomed-in spectral plotting region.*/
142      void gotoZoomSpectrum(float x1, float x2, float y1, float y2);   
143   
144      /** Defines the region for the moment map.*/
145      void gotoMap();
146
147      /** Draw lines indicating velocity range.*/
148      void drawVelRange(float v1, float v2);
149
150      /** Draw box showing excluded range due to Milky Way.*/
151      void drawMWRange(float v1, float v2);
152   
153      /** Return number of spectra that go on a page.*/
154      int   getNumOnPage();
155
156      /** Set number of spectra that go on a page.*/
157      void  setNumOnPage(int i);
158      float getPaperWidth();         ///< Return width of plottable region.
159      void  setPaperWidth(float f);  ///< Set width of plottable region.
160      float getPaperHeight();        ///< Return height of plottable region.
161      void  setPaperHeight(float f); ///< Set height of plottable region.
162      void  goToPlot();              ///< Goes to the plot when more
163      ///   than one are open.
164
165    private:
166      int numOnPage;       ///< Number of spectra to put on one page.
167      int spectraCount;    ///< Number of spectra done so far: where on the page?
168      float mainCoords[4]; ///< Boundaries for the main spectrum [inches]
169      float zoomCoords[4]; ///< Boundaries for the zoomed-in spectrum [inches]
170      float mapCoords[4];  ///< Boundaries for the map box [inches]
171      float paperWidth;    ///< Width of plottable region of the paper [inches]
172      float paperHeight;   ///< Height of plottable region of the paper [inches]
173      int   identifier;    ///< The identifier code used by cpgslct.
174   
175    };
176
177    inline int   SpectralPlot::getNumOnPage(){return numOnPage;}
178    inline void  SpectralPlot::setNumOnPage(int i){numOnPage=i;}
179    inline float SpectralPlot::getPaperWidth(){return paperWidth;}
180    inline void  SpectralPlot::setPaperWidth(float f){paperWidth=f;}
181    inline float SpectralPlot::getPaperHeight(){return paperHeight;}
182    inline void  SpectralPlot::setPaperHeight(float f){paperHeight=f;}
183
184    //***************************************************************************
185    //***************************************************************************
186
187    /**
188     *  A class for plotting 2-dimensional maps.
189     *    A class to hold the dimensions and set up for the plots used by the
190     *     two functions below.
191     *    The physical dimensions (in inches) of the plot and the elements
192     *     within it are stored, including maximum widths and heights
193     *     (so that the plot will fit on an A4 page).
194     *    Simple accessor functions are provided to enable access to quantities
195     *     needed for pgplot routines.
196     */
197    class ImagePlot
198    {
199    public:
200      ImagePlot();  ///< Constructor
201      virtual ~ImagePlot(); ///< Destructor
202      ImagePlot(const ImagePlot& p);
203      ImagePlot& operator=(const ImagePlot& p);
204 
205      /** Set up PGPLOT output.*/
206      int   setUpPlot(std::string pgDestination, float x, float y);
207
208      /** Defines and draws box.*/
209      void  drawMapBox(float x1, float x2, float y1, float y2,
210                       std::string xlabel, std::string ylabel);
211
212      /** Write plot title.*/
213      void  makeTitle(std::string title);
214
215      float cmToCoord(float cm);///< Converts distance in cm to
216      ///   coordinate distance on the plot.
217      float getMargin();        ///< Returns width of margin.
218      float getPaperWidth();    ///< Returns width of paper.
219      float imageWidth();       ///< Returns the calculated total width
220      ///   of the image part of the plot
221      ///   [inches]
222      float getImageHeight();   ///< Returns height of image [inches]
223      float getAspectRatio();   ///< Returns the aspect ratio of the image.
224      void  goToPlot();         ///< Goes to the plot when more than one
225      ///   are open
226
227    private:
228      float paperWidth;     ///< Default (maximum) width of "paper" [inches]
229      float maxPaperHeight; ///< Maximum allowed height of paper [inches]
230      float marginWidth;    ///< Width allowed for margins around main
231      ///   plot (ie. label & numbers) [inches]
232      float wedgeWidth;     ///< Width allowed for placement of wedge on
233      ///   right-hand side of plot. [inches]
234      float imageRatio;     ///< Aspect ratio of the image only
235      ///   (ie. y-value range / x-value range).
236      float aspectRatio;    ///< Aspect ratio of whole plot.
237      float xdim;           ///< Width of main plot, in display units.
238      float ydim;           ///< Height of main plot, in display units.
239      int   identifier;     ///< The identifier code used by cpgslct.
240    };
241    //----------------------------------------------------------
242    // Inline ImagePlot functions...
243    //----------------------------------------------------------
244
245    inline float ImagePlot::getMargin()     {return marginWidth;}
246    inline float ImagePlot::getPaperWidth() {return paperWidth;}
247    inline float ImagePlot::getImageHeight(){return imageWidth()*imageRatio;}
248    inline float ImagePlot::getAspectRatio(){return aspectRatio;}
249 
250    //***************************************************************************
251    //***************************************************************************
252
253    /**
254     *  A class for plotting just the image cutouts of individual sources.
255     *  This class is designed to hold the dimensions and set up for the
256     *  plotting of the cutouts, plus the textual information for each source.
257     *  The physical dimensions (in inches) of the plot and the elements
258     *   within it are stored, on the assumption that the plot will go on
259     *   an A4 page.
260     *  Simple accessor functions are provided to enable access to quantities
261     *   needed for pgplot routines.
262     */
263    class CutoutPlot
264    {
265    public:
266      CutoutPlot();    ///< Constructor
267      virtual ~CutoutPlot(); ///< Destructor
268      CutoutPlot(const CutoutPlot& p);
269      CutoutPlot& operator=(const CutoutPlot& p);
270
271      /** Set up PGPLOT output.*/
272      int setUpPlot(std::string pgDestination);
273
274      /** Calculate boundaries for boxes.*/
275      void calcCoords();
276      /** Set up the header box */
277      void gotoHeader();
278
279      /** Write first line of header information (position/velocity
280          info) in correct place.*/
281      void firstHeaderLine(std::string line);   
282   
283      /** Write second line of header information (fluxes) in
284          correct place.*/
285      void secondHeaderLine(std::string line); 
286
287      /** Write third line of header information (WCS widths) in
288          correct place. */
289      void thirdHeaderLine(std::string line);   
290
291      /** Write fourth line of header information (pixel coordinates) in
292          correct place. */
293      void fourthHeaderLine(std::string line);   
294
295      /** Defines the region for the moment map.*/
296      void gotoMap();
297
298      /** Goes to the plot when more than one are open.*/
299      void  goToPlot();   
300
301      /** Return the number of objects that go on a page. */           
302      int   getNumOnPage(){return numOnPage;}
303      /** Set number of objects that go on a page.*/
304      void  setNumOnPage(int i){numOnPage=i;}
305
306      /** Return width of plottable region.*/
307      float getPaperWidth(){return paperWidth;}
308      /** Set width of plottable region.*/
309      void  setPaperWidth(float f){paperWidth=f;}
310      /** Return height of plottable region.*/
311      float getPaperHeight(){return paperHeight;}
312      /** Set height of plottable region.*/
313      void  setPaperHeight(float f){paperHeight=f;}
314
315    private:
316      int numOnPage;       ///< Number of sources to put on one page.
317      int sourceCount;     ///< Number of sources done so far: where on the page?
318      float mainCoords[4]; ///< Boundaries for the main spectrum [inches]
319      float mapCoords[4];  ///< Boundaries for the map box [inches]
320      float paperWidth;    ///< Width of plottable region of the paper [inches]
321      float paperHeight;   ///< Height of plottable region of the paper [inches]
322      int   identifier;    ///< The identifier code used by cpgslct.
323   
324    };
325
326
327  }
328
329}
330
331#endif
332
Note: See TracBrowser for help on using the repository browser.