source: tags/release-1.1/src/Cubes/plots.hh @ 1391

Last change on this file since 1391 was 299, checked in by Matthew Whiting, 17 years ago

Adding distribution text at the start of each file...

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