source: trunk/src/Cubes/plots.hh @ 485

Last change on this file since 485 was 485, checked in by MatthewWhiting, 16 years ago

Some minor changes, primarily affecting the text written to screen.

File size: 13.4 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 to centimetres.
49    const float a4width=21.0;         ///< A4 width in cm
50    const float a4height=29.7;        ///< A4 height in cm
51    const float psHoffset=0.35;       ///< The default horizontal pgplot offset applied to ps files
52    const float psVoffset=0.25;       ///< The default vertical pgplot offset applied to ps files
53
54    // These are the constants used for spacing out elements in SpectralPlot.
55    const float spMainX1 =  2.0;      ///< min X-value of main box [cm]
56    const float spMainX2 = 13.7;      ///< max X-value of main box [cm]
57    const float spZoomX1 = 15.0;      ///< min X-value of zoom box [cm]
58    const float spZoomX2 = 16.8;      ///< max X-value of zoom box [cm]
59    const float spMapX1  = 17.0;      ///< min X-value of map box [cm]
60    const float spMainY1 =  1.5;      ///< min Y-value of box wrt base of current spectrum [cm]
61    const float spMainY2 =  3.4;      ///< max Y-value of box wrt base of current spectrum [cm]
62    const float spXlabelOffset = 3.0; ///< Offset for X-axis label.
63    const float spYlabelOffset = 4.0; ///< Offset for Y-axis label.
64    const float spTitleOffset1 = 5.1; ///< Offset for first title line.
65    const float spTitleOffset2 = 3.6; ///< Offset for second title line.
66    const float spTitleOffset3 = 2.1; ///< Offset for third title line.
67    const float spTitleOffset4 = 0.6; ///< Offset for fourth title line.
68
69    const float spIndexSize = 0.6;    ///< PGPlot character height for tick mark labels
70    const float spLabelSize = 0.7;    ///< PGPlot character height for axis labels
71    const float spTitleSize = 0.8;    ///< PGPlot character height for plot title line
72
73    // These are the constants used for spacing out elements in ImagePlot.
74    const float imTitleOffset = 2.7;  ///< Offset for title of map.
75
76    // These are the constants used for spacing out elements in CutoutPlot.
77    const float cuMainX1 = 1.0;
78    const float cuMainX2 = 15.8;
79    const float cuMainY1 = 1.0;
80    const float cuMainY2 = 3.8;
81    const float cuMapX1 = 16.0;
82
83    //***************************************************************************
84    //***************************************************************************
85
86    /**
87     *  A class for plotting spectra of detections.
88     *  This class is designed to hold the dimensions and set up for the
89     *  plotting of the spectra (including the full spectra, the zoomed
90     *  in part, and the moment map).
91     *  The physical dimensions (in inches) of the plot and the elements
92     *   within it are stored, on the assumption that the plot will go on
93     *   an A4 page.
94     *  Simple accessor functions are provided to enable access to quantities
95     *   needed for pgplot routines.
96     */
97    class SpectralPlot
98    {
99    public:
100      SpectralPlot();    ///< Constructor
101      virtual ~SpectralPlot(); ///< Destructor
102      SpectralPlot(const SpectralPlot& p);
103      SpectralPlot& operator=(const SpectralPlot& p);
104
105      /** Set up PGPLOT output.*/
106      int setUpPlot(std::string pgDestination);
107
108      /** Calculate boundaries for boxes.*/
109      void calcCoords();
110      /** Set up the header & write the X-label.*/
111      void gotoHeader(std::string xlabel);
112
113      /** Write first line of header information (position/velocity
114          info) in correct place.*/
115      void firstHeaderLine(std::string line);   
116   
117      /** Write second line of header information (fluxes) in
118          correct place.*/
119      void secondHeaderLine(std::string line); 
120
121      /** Write third line of header information (WCS widths) in
122          correct place. */
123      void thirdHeaderLine(std::string line);   
124
125      /** Write fourth line of header information (pixel coordinates) in
126          correct place. */
127      void fourthHeaderLine(std::string line);   
128
129      /** Set up main spectral plotting region.*/
130      void gotoMainSpectrum(float x1, float x2, float y1, float y2,
131                            std::string ylabel);
132   
133      /** Set up zoomed-in spectral plotting region.*/
134      void gotoZoomSpectrum(float x1, float x2, float y1, float y2);   
135   
136      /** Defines the region for the moment map.*/
137      void gotoMap();
138
139      /** Draw lines indicating velocity range.*/
140      void drawVelRange(float v1, float v2);
141
142      /** Draw box showing excluded range due to Milky Way.*/
143      void drawMWRange(float v1, float v2);
144   
145      /** Return number of spectra that go on a page.*/
146      int   getNumOnPage();
147
148      /** Set number of spectra that go on a page.*/
149      void  setNumOnPage(int i);
150      float getPaperWidth();         ///< Return width of plottable region.
151      void  setPaperWidth(float f);  ///< Set width of plottable region.
152      float getPaperHeight();        ///< Return height of plottable region.
153      void  setPaperHeight(float f); ///< Set height of plottable region.
154      void  goToPlot();              ///< Goes to the plot when more
155      ///   than one are open.
156
157    private:
158      int numOnPage;       ///< Number of spectra to put on one page.
159      int spectraCount;    ///< Number of spectra done so far: where on the page?
160      float mainCoords[4]; ///< Boundaries for the main spectrum [inches]
161      float zoomCoords[4]; ///< Boundaries for the zoomed-in spectrum [inches]
162      float mapCoords[4];  ///< Boundaries for the map box [inches]
163      float paperWidth;    ///< Width of plottable region of the paper [inches]
164      float paperHeight;   ///< Height of plottable region of the paper [inches]
165      int   identifier;    ///< The identifier code used by cpgslct.
166   
167    };
168
169    inline int   SpectralPlot::getNumOnPage(){return numOnPage;}
170    inline void  SpectralPlot::setNumOnPage(int i){numOnPage=i;}
171    inline float SpectralPlot::getPaperWidth(){return paperWidth;}
172    inline void  SpectralPlot::setPaperWidth(float f){paperWidth=f;}
173    inline float SpectralPlot::getPaperHeight(){return paperHeight;}
174    inline void  SpectralPlot::setPaperHeight(float f){paperHeight=f;}
175
176    //***************************************************************************
177    //***************************************************************************
178
179    /**
180     *  A class for plotting 2-dimensional maps.
181     *    A class to hold the dimensions and set up for the plots used by the
182     *     two functions below.
183     *    The physical dimensions (in inches) of the plot and the elements
184     *     within it are stored, including maximum widths and heights
185     *     (so that the plot will fit on an A4 page).
186     *    Simple accessor functions are provided to enable access to quantities
187     *     needed for pgplot routines.
188     */
189    class ImagePlot
190    {
191    public:
192      ImagePlot();  ///< Constructor
193      virtual ~ImagePlot(); ///< Destructor
194      ImagePlot(const ImagePlot& p);
195      ImagePlot& operator=(const ImagePlot& p);
196 
197      /** Set up PGPLOT output.*/
198      int   setUpPlot(std::string pgDestination, float x, float y);
199
200      /** Defines and draws box.*/
201      void  drawMapBox(float x1, float x2, float y1, float y2,
202                       std::string xlabel, std::string ylabel);
203
204      /** Write plot title.*/
205      void  makeTitle(std::string title);
206
207      float cmToCoord(float cm);///< Converts distance in cm to coordinate distance on the plot.
208      float getMargin();        ///< Returns width of margin.
209      float getPaperWidth();    ///< Returns width of paper.
210      float imageWidth();       ///< Returns the calculated total width of the image part of the plot [inches]
211      float getImageHeight();   ///< Returns height of image [inches]
212      float getAspectRatio();   ///< Returns the aspect ratio of the image.
213      void  goToPlot();         ///< Goes to the plot when more than one are open
214
215    private:
216      float paperWidth;     ///< Default (maximum) width of "paper" [inches]
217      float maxPaperHeight; ///< Maximum allowed height of paper [inches]
218      float marginWidth;    ///< Width allowed for margins around main plot (ie. label & numbers) [inches]
219      float wedgeWidth;     ///< Width allowed for placement of wedge on right-hand side of plot. [inches]
220      float imageRatio;     ///< Aspect ratio of the image only (ie. y-value range / x-value range).
221      float aspectRatio;    ///< Aspect ratio of whole plot.
222      float xdim;           ///< Width of main plot, in display units.
223      float ydim;           ///< Height of main plot, in display units.
224      int   identifier;     ///< The identifier code used by cpgslct.
225    };
226    //----------------------------------------------------------
227    // Inline ImagePlot functions...
228    //----------------------------------------------------------
229
230    inline float ImagePlot::getMargin()     {return marginWidth;}
231    inline float ImagePlot::getPaperWidth() {return paperWidth;}
232    inline float ImagePlot::getImageHeight(){return imageWidth()*imageRatio;}
233    inline float ImagePlot::getAspectRatio(){return aspectRatio;}
234 
235    //***************************************************************************
236    //***************************************************************************
237
238    /**
239     *  A class for plotting just the image cutouts of individual sources.
240     *  This class is designed to hold the dimensions and set up for the
241     *  plotting of the cutouts, plus the textual information for each source.
242     *  The physical dimensions (in inches) of the plot and the elements
243     *   within it are stored, on the assumption that the plot will go on
244     *   an A4 page.
245     *  Simple accessor functions are provided to enable access to quantities
246     *   needed for pgplot routines.
247     */
248    class CutoutPlot
249    {
250    public:
251      CutoutPlot();    ///< Constructor
252      virtual ~CutoutPlot(); ///< Destructor
253      CutoutPlot(const CutoutPlot& p);
254      CutoutPlot& operator=(const CutoutPlot& p);
255
256      /** Set up PGPLOT output.*/
257      int setUpPlot(std::string pgDestination);
258
259      /** Calculate boundaries for boxes.*/
260      void calcCoords();
261      /** Set up the header box */
262      void gotoHeader();
263
264      /** Write first line of header information (position/velocity
265          info) in correct place.*/
266      void firstHeaderLine(std::string line);   
267   
268      /** Write second line of header information (fluxes) in
269          correct place.*/
270      void secondHeaderLine(std::string line); 
271
272      /** Write third line of header information (WCS widths) in
273          correct place. */
274      void thirdHeaderLine(std::string line);   
275
276      /** Write fourth line of header information (pixel coordinates) in
277          correct place. */
278      void fourthHeaderLine(std::string line);   
279
280      /** Defines the region for the moment map.*/
281      void gotoMap();
282
283      /** Goes to the plot when more than one are open.*/
284      void  goToPlot();   
285
286      /** Return the number of objects that go on a page. */           
287      int   getNumOnPage(){return numOnPage;}
288      /** Set number of objects that go on a page.*/
289      void  setNumOnPage(int i){numOnPage=i;}
290
291      /** Return width of plottable region.*/
292      float getPaperWidth(){return paperWidth;}
293      /** Set width of plottable region.*/
294      void  setPaperWidth(float f){paperWidth=f;}
295      /** Return height of plottable region.*/
296      float getPaperHeight(){return paperHeight;}
297      /** Set height of plottable region.*/
298      void  setPaperHeight(float f){paperHeight=f;}
299
300    private:
301      int numOnPage;       ///< Number of sources to put on one page.
302      int sourceCount;     ///< Number of sources done so far: where on the page?
303      float mainCoords[4]; ///< Boundaries for the main spectrum [inches]
304      float mapCoords[4];  ///< Boundaries for the map box [inches]
305      float paperWidth;    ///< Width of plottable region of the paper [inches]
306      float paperHeight;   ///< Height of plottable region of the paper [inches]
307      int   identifier;    ///< The identifier code used by cpgslct.
308   
309    };
310
311
312  }
313
314}
315
316#endif
317
Note: See TracBrowser for help on using the repository browser.