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