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