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