source: branches/pixel-map-branch/src/Cubes/plots.hh

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

Large raft of changes. Most are minor ones related to fixing up the use of std::string and std::vector (whether they are declared as using, or not...). Other changes include:

  • Moving the reconstruction filter class Filter into its own header/implementation files filter.{hh,cc}. As a result, the atrous.cc file is removed, but atrous.hh remains with just the function prototypes.
  • Incorporating a Filter object into the Param set, so that the reconstruction routines can see it without the messy "extern" call. The define() function is now called in both the Param() and Param::readParams() functions, and no longer in the main body.
  • Col functions in columns.cc moved into the Column namespace, while the template function printEntry is moved into the columns.hh file -- it would not compile on delphinus with it in the columns.cc, even though all the implementations were present.
  • Improved the introductory section of the Guide, with a bit more detail about each of the execution steps. This way the reader can read this section and have a reasonably good idea about what is happening.
  • Other minor changes to the Guide.
File size: 8.9 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#include <Utils/mycpgplot.hh>
10
11using namespace mycpgplot;
12
13/**
14 * A namespace to control plotting of the spectral output and the
15 * spatial image output.
16 */
17
18namespace Plot
19{
20  const float inchToCm=2.54;        ///< Conversion factor from inches to centimetres.
21  const float a4width=21.0;         ///< A4 width in cm
22  const float a4height=29.7;        ///< A4 height in cm
23  const float psHoffset=0.35;       ///< The default pgplot offset applied to ps files
24  const float psVoffset=0.25;       ///< The default pgplot 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 of current spectrum [cm]
33  const float spMainY2 =  3.8;      ///< max Y-value of box wrt base of current spectrum [cm]
34  const float spXlabelOffset = 3.0; ///< Offset for X-axis label.
35  const float spYlabelOffset = 4.0; ///< Offset for Y-axis label.
36  const float spTitleOffset1 = 3.8; ///< Offset for first title line.
37  const float spTitleOffset2 = 2.3; ///< Offset for second title line.
38  const float spTitleOffset3 = 0.8; ///< Offset for third title line.
39
40  // These are the constants used for spacing out elements in ImagePlot.
41  const float imTitleOffset = 2.7;  ///< Offset for title of map.
42
43  //***************************************************************************
44
45  /**
46   *  A class for plotting spectra of detections.
47   *  This class is designed to hold the dimensions and set up for the plotting
48   *   of the spectra (including the full spectra, the zoomed in part, and the
49   *   moment map).
50   *  The physical dimensions (in inches) of the plot and the elements
51   *   within it are stored, on the assumption that the plot will go on
52   *   an A4 page.
53   *  Simple accessor functions are provided to enable access to quantities
54   *   needed for pgplot routines.
55   */
56  class SpectralPlot
57  {
58  public:
59    SpectralPlot();    ///< Constructor
60    virtual ~SpectralPlot(); ///< Destructor
61
62    int setUpPlot(std::string pgDestination);   ///< Set up PGPLOT output.
63    void calcCoords();                     ///< Calculate boundaries for boxes.
64    void gotoHeader(std::string xlabel);        ///< Set up the header & write the X-label.
65    void firstHeaderLine(std::string line);   
66    ///< Write first line of header information (position/velocity info) in correct place.
67    void secondHeaderLine(std::string line); 
68    ///< Write second line of header information (widths and fluxes) in correct place.
69    void thirdHeaderLine(std::string line);   
70    ///< Write third line of header information (pixel coordinates) in correct place.
71    void gotoMainSpectrum(float x1, float x2, float y1, float y2,std::string ylabel);
72    ///< Set up main spectral plotting region.
73    void gotoZoomSpectrum(float x1, float x2, float y1, float y2);   
74    ///< Set up zoomed-in spectral plotting region.
75    void gotoMap();                        ///< Defines the region for the moment map.
76    void drawVelRange(float v1, float v2); ///< Draw lines indicating velocity range.
77    void drawMWRange(float v1, float v2);///< Draw box showing excluded range due to Milky Way.
78   
79    int   getNumOnPage();          ///< Return number of spectra that go on a page.
80    void  setNumOnPage(int i);     ///< Set number of spectra that go on a page.
81    float getPaperWidth();         ///< Return width of plottable region.
82    void  setPaperWidth(float f);  ///< Set width of plottable region.
83    float getPaperHeight();        ///< Return height of plottable region.
84    void  setPaperHeight(float f); ///< Set height of plottable region.
85    void  goToPlot()      ;        ///< Goes to the plot when more than one are open.
86
87  private:
88    int numOnPage;       ///< Number of spectra to put on one page.
89    int spectraCount;    ///< Number of spectra done so far: where on the page?
90    float mainCoords[4]; ///< Boundaries for the main spectrum [inches]
91    float zoomCoords[4]; ///< Boundaries for the zoomed-in spectrum [inches]
92    float mapCoords[4];  ///< Boundaries for the map box [inches]
93    float paperWidth;    ///< Width of plottable region of the paper [inches]
94    float paperHeight;   ///< Height of plottable region of the paper [inches]
95    float indexSize;     ///< PGPlot character height for tick mark labels
96    float labelSize;     ///< PGPlot character height for axis labels.
97    int   identifier;    ///< The identifier code used by cpgslct.
98   
99  };
100
101  //----------------------------------------------------------
102  // Inline SpectralPlot functions...
103  //----------------------------------------------------------
104  inline void  SpectralPlot::firstHeaderLine(std::string line){
105    cpgmtxt("t",Plot::spTitleOffset1,0.5,0.5,line.c_str());}
106  inline void  SpectralPlot::secondHeaderLine(std::string line){
107    cpgmtxt("t",Plot::spTitleOffset2,0.5,0.5,line.c_str());}
108  inline void  SpectralPlot::thirdHeaderLine(std::string line){
109    cpgmtxt("t",Plot::spTitleOffset3,0.5,0.5,line.c_str());}
110  inline int   SpectralPlot::getNumOnPage(){return numOnPage;}
111  inline void  SpectralPlot::setNumOnPage(int i){numOnPage=i;}
112  inline float SpectralPlot::getPaperWidth(){return paperWidth;}
113  inline void  SpectralPlot::setPaperWidth(float f){paperWidth=f;}
114  inline float SpectralPlot::getPaperHeight(){return paperHeight;}
115  inline void  SpectralPlot::setPaperHeight(float f){paperHeight=f;}
116  inline void  SpectralPlot::goToPlot(){cpgslct(identifier);}
117
118  //***************************************************************************
119  //***************************************************************************
120
121  /**
122   *  A class for plotting 2-dimensional maps.
123   *    A class to hold the dimensions and set up for the plots used by the
124   *     two functions below.
125   *    The physical dimensions (in inches) of the plot and the elements
126   *     within it are stored, including maximum widths and heights
127   *     (so that the plot will fit on an A4 page).
128   *    Simple accessor functions are provided to enable access to quantities
129   *     needed for pgplot routines.
130   */
131  class ImagePlot
132  {
133  public:
134    ImagePlot();  ///< Constructor
135    virtual ~ImagePlot(); ///< Destructor
136 
137    int   setUpPlot(std::string pgDestination, float x, float y); ///< Set up PGPLOT output.
138    void  drawMapBox(float x1, float x2, float y1, float y2,
139                     std::string xlabel, std::string ylabel);          ///< Defines and draws box.
140    void  makeTitle(std::string title);                           ///< Write plot title.
141
142    float cmToCoord(float cm);///< Converts distance in cm to coordinate distance on the plot.
143    float getMargin();        ///< Returns width of margin.
144    float getPaperWidth();    ///< Returns width of paper.
145    float imageWidth();       ///<  Returns the calculated total width of the image part of the plot [inches]   
146    float getImageHeight();   ///< Returns height of image [inches]
147    float getAspectRatio();   ///< Returns the aspect ratio of the image.
148    void  goToPlot();         ///< Goes to the plot when more than one are open
149
150  private:
151    float paperWidth;     ///< Default (maximum) width of "paper" [inches]
152    float maxPaperHeight; ///< Maximum allowed height of paper [inches]
153    float marginWidth;    ///< Width allowed for margins around main plot (ie. label & numbers) [inches]
154    float wedgeWidth;     ///< Width allowed for placement of wedge on right-hand side of plot. [inches]
155    float imageRatio;     ///< Aspect ratio of the image only (ie. y-value range / x-value range).
156    float aspectRatio;    ///< Aspect ratio of whole plot.
157    float xdim;           ///< Width of main plot, in display units.
158    float ydim;           ///< Height of main plot, in display units.
159    int   identifier;     ///< The identifier code used by cpgslct.
160  };
161  //----------------------------------------------------------
162  // Inline ImagePlot functions...
163  //----------------------------------------------------------
164
165  inline float ImagePlot::imageWidth(){ return paperWidth - 2*marginWidth - wedgeWidth;}
166  inline float ImagePlot::cmToCoord(float cm){/** \param cm Distance to be converted.*/
167    return (cm/inchToCm) * ydim / (imageWidth()*imageRatio);}
168  inline float ImagePlot::getMargin()     {return marginWidth;}
169  inline float ImagePlot::getPaperWidth() {return paperWidth;}
170  inline float ImagePlot::getImageHeight(){return imageWidth()*imageRatio;}
171  inline float ImagePlot::getAspectRatio(){return aspectRatio;}
172  inline void  ImagePlot::goToPlot(){cpgslct(identifier);}
173 
174}
175
176
177#endif
178
Note: See TracBrowser for help on using the repository browser.