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

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

Largely just cleaning up #include and "using namespace" statements to prevent unnecessary declarations.

File size: 9.1 KB
Line 
1#ifndef PLOTS_H
2#define PLOTS_H
3
4#include <iostream>
5#include <sstream>
6#include <string>
7#include <math.h>
8#include <cpgplot.h>
9
10/**
11 * A namespace to control plotting of the spectral output and the
12 * spatial image output.
13 */
14
15namespace Plot
16{
17  const float inchToCm=2.54;        ///< Conversion factor from inches
18                                    ///   to centimetres.
19  const float a4width=21.0;         ///< A4 width in cm
20  const float a4height=29.7;        ///< A4 height in cm
21  const float psHoffset=0.35;       ///< The default horizontal pgplot
22                                    ///   offset applied to ps files
23  const float psVoffset=0.25;       ///< The default vertical pgplot
24                                    ///   offset applied to ps files
25
26  // These are the constants used for spacing out elements in SpectralPlot.
27  const float spMainX1 =  2.0;      ///< min X-value of main box [cm]
28  const float spMainX2 = 13.7;      ///< max X-value of main box [cm]
29  const float spZoomX1 = 15.0;      ///< min X-value of zoom box [cm]
30  const float spZoomX2 = 16.8;      ///< max X-value of zoom box [cm]
31  const float spMapX1  = 17.0;      ///< min X-value of map box [cm]
32  const float spMainY1 =  1.8;      ///< min Y-value of box wrt base
33                                    ///   of current spectrum [cm]
34  const float spMainY2 =  3.8;      ///< max Y-value of box wrt base
35                                    ///   of current spectrum [cm]
36  const float spXlabelOffset = 3.0; ///< Offset for X-axis label.
37  const float spYlabelOffset = 4.0; ///< Offset for Y-axis label.
38  const float spTitleOffset1 = 3.8; ///< Offset for first title line.
39  const float spTitleOffset2 = 2.3; ///< Offset for second title line.
40  const float spTitleOffset3 = 0.8; ///< Offset for third title line.
41
42  // These are the constants used for spacing out elements in ImagePlot.
43  const float imTitleOffset = 2.7;  ///< Offset for title of map.
44
45  //***************************************************************************
46  //***************************************************************************
47
48  /**
49   *  A class for plotting spectra of detections.
50   *  This class is designed to hold the dimensions and set up for the
51   *  plotting of the spectra (including the full spectra, the zoomed
52   *  in part, and the moment map).
53   *  The physical dimensions (in inches) of the plot and the elements
54   *   within it are stored, on the assumption that the plot will go on
55   *   an A4 page.
56   *  Simple accessor functions are provided to enable access to quantities
57   *   needed for pgplot routines.
58   */
59  class SpectralPlot
60  {
61  public:
62    SpectralPlot();    ///< Constructor
63    virtual ~SpectralPlot(); ///< Destructor
64
65    /** Set up PGPLOT output.*/
66    int setUpPlot(std::string pgDestination);
67
68    /** Calculate boundaries for boxes.*/
69    void calcCoords();
70    /** Set up the header & write the X-label.*/
71    void gotoHeader(std::string xlabel);
72
73    /** Write first line of header information (position/velocity
74        info) in correct place.*/
75    void firstHeaderLine(std::string line);   
76   
77    /** Write second line of header information (widths and fluxes) in
78        correct place.*/
79    void secondHeaderLine(std::string line); 
80
81    /** Write third line of header information (pixel coordinates) in
82        correct place. */
83    void thirdHeaderLine(std::string line);   
84
85    /** Set up main spectral plotting region.*/
86    void gotoMainSpectrum(float x1, float x2, float y1, float y2,
87                          std::string ylabel);
88   
89    /** Set up zoomed-in spectral plotting region.*/
90    void gotoZoomSpectrum(float x1, float x2, float y1, float y2);   
91   
92    /** Defines the region for the moment map.*/
93    void gotoMap();
94
95    /** Draw lines indicating velocity range.*/
96    void drawVelRange(float v1, float v2);
97
98    /** Draw box showing excluded range due to Milky Way.*/
99    void drawMWRange(float v1, float v2);
100   
101    /** Return number of spectra that go on a page.*/
102    int   getNumOnPage();
103
104    /** Set number of spectra that go on a page.*/
105    void  setNumOnPage(int i);
106    float getPaperWidth();         ///< Return width of plottable region.
107    void  setPaperWidth(float f);  ///< Set width of plottable region.
108    float getPaperHeight();        ///< Return height of plottable region.
109    void  setPaperHeight(float f); ///< Set height of plottable region.
110    void  goToPlot();              ///< Goes to the plot when more
111                                   ///   than one are open.
112
113  private:
114    int numOnPage;       ///< Number of spectra to put on one page.
115    int spectraCount;    ///< Number of spectra done so far: where on the page?
116    float mainCoords[4]; ///< Boundaries for the main spectrum [inches]
117    float zoomCoords[4]; ///< Boundaries for the zoomed-in spectrum [inches]
118    float mapCoords[4];  ///< Boundaries for the map box [inches]
119    float paperWidth;    ///< Width of plottable region of the paper [inches]
120    float paperHeight;   ///< Height of plottable region of the paper [inches]
121    float indexSize;     ///< PGPlot character height for tick mark labels
122    float labelSize;     ///< PGPlot character height for axis labels.
123    int   identifier;    ///< The identifier code used by cpgslct.
124   
125  };
126
127  //----------------------------------------------------------
128  // Inline SpectralPlot functions...
129  //----------------------------------------------------------
130  inline void  SpectralPlot::firstHeaderLine(std::string line){
131    cpgmtxt("t",Plot::spTitleOffset1,0.5,0.5,line.c_str());}
132  inline void  SpectralPlot::secondHeaderLine(std::string line){
133    cpgmtxt("t",Plot::spTitleOffset2,0.5,0.5,line.c_str());}
134  inline void  SpectralPlot::thirdHeaderLine(std::string line){
135    cpgmtxt("t",Plot::spTitleOffset3,0.5,0.5,line.c_str());}
136  inline int   SpectralPlot::getNumOnPage(){return numOnPage;}
137  inline void  SpectralPlot::setNumOnPage(int i){numOnPage=i;}
138  inline float SpectralPlot::getPaperWidth(){return paperWidth;}
139  inline void  SpectralPlot::setPaperWidth(float f){paperWidth=f;}
140  inline float SpectralPlot::getPaperHeight(){return paperHeight;}
141  inline void  SpectralPlot::setPaperHeight(float f){paperHeight=f;}
142  inline void  SpectralPlot::goToPlot(){cpgslct(identifier);}
143
144  //***************************************************************************
145  //***************************************************************************
146
147  /**
148   *  A class for plotting 2-dimensional maps.
149   *    A class to hold the dimensions and set up for the plots used by the
150   *     two functions below.
151   *    The physical dimensions (in inches) of the plot and the elements
152   *     within it are stored, including maximum widths and heights
153   *     (so that the plot will fit on an A4 page).
154   *    Simple accessor functions are provided to enable access to quantities
155   *     needed for pgplot routines.
156   */
157  class ImagePlot
158  {
159  public:
160    ImagePlot();  ///< Constructor
161    virtual ~ImagePlot(); ///< Destructor
162 
163    /** Set up PGPLOT output.*/
164    int   setUpPlot(std::string pgDestination, float x, float y);
165
166    /** Defines and draws box.*/
167    void  drawMapBox(float x1, float x2, float y1, float y2,
168                     std::string xlabel, std::string ylabel);
169
170    /** Write plot title.*/
171    void  makeTitle(std::string title);
172
173    float cmToCoord(float cm);///< Converts distance in cm to
174                              ///   coordinate distance on the plot.
175    float getMargin();        ///< Returns width of margin.
176    float getPaperWidth();    ///< Returns width of paper.
177    float imageWidth();       ///< Returns the calculated total width
178                              ///   of the image part of the plot
179                              ///   [inches]
180    float getImageHeight();   ///< Returns height of image [inches]
181    float getAspectRatio();   ///< Returns the aspect ratio of the image.
182    void  goToPlot();         ///< Goes to the plot when more than one
183                              ///   are open
184
185  private:
186    float paperWidth;     ///< Default (maximum) width of "paper" [inches]
187    float maxPaperHeight; ///< Maximum allowed height of paper [inches]
188    float marginWidth;    ///< Width allowed for margins around main
189                          ///   plot (ie. label & numbers) [inches]
190    float wedgeWidth;     ///< Width allowed for placement of wedge on
191                          ///   right-hand side of plot. [inches]
192    float imageRatio;     ///< Aspect ratio of the image only
193                          ///   (ie. y-value range / x-value range).
194    float aspectRatio;    ///< Aspect ratio of whole plot.
195    float xdim;           ///< Width of main plot, in display units.
196    float ydim;           ///< Height of main plot, in display units.
197    int   identifier;     ///< The identifier code used by cpgslct.
198  };
199  //----------------------------------------------------------
200  // Inline ImagePlot functions...
201  //----------------------------------------------------------
202
203  inline float ImagePlot::imageWidth(){
204    return paperWidth - 2*marginWidth - wedgeWidth;
205  }
206  inline float ImagePlot::cmToCoord(float cm){
207    /** \param cm Distance to be converted.*/
208    return (cm/inchToCm) * ydim / (imageWidth()*imageRatio);
209  }
210  inline float ImagePlot::getMargin()     {return marginWidth;}
211  inline float ImagePlot::getPaperWidth() {return paperWidth;}
212  inline float ImagePlot::getImageHeight(){return imageWidth()*imageRatio;}
213  inline float ImagePlot::getAspectRatio(){return aspectRatio;}
214  inline void  ImagePlot::goToPlot(){cpgslct(identifier);}
215 
216}
217
218
219#endif
220
Note: See TracBrowser for help on using the repository browser.