source: tags/release-1.1.7/src/Cubes/plots.hh @ 1455

Last change on this file since 1455 was 528, checked in by MatthewWhiting, 15 years ago

Changing the documentation comments to match the askapsoft style. Also have split ChanMap? and Object3D into separate files.

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