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 | // ----------------------------------------------------------------------- |
---|
29 | #ifndef PLOTS_H |
---|
30 | #define PLOTS_H |
---|
31 | |
---|
32 | #include <iostream> |
---|
33 | #include <sstream> |
---|
34 | #include <string> |
---|
35 | #include <math.h> |
---|
36 | #include <duchamp/duchamp.hh> |
---|
37 | #include <duchamp/pgheader.hh> |
---|
38 | |
---|
39 | namespace duchamp |
---|
40 | { |
---|
41 | |
---|
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 | |
---|
45 | /// @brief A namespace to control plotting of the spectral output and the |
---|
46 | /// spatial image output. |
---|
47 | |
---|
48 | namespace Plot |
---|
49 | { |
---|
50 | const float inchToCm=2.54; ///< Conversion factor from inches to centimetres. |
---|
51 | const float a4width=21.0; ///< A4 width in cm |
---|
52 | const float a4height=29.7; ///< A4 height in cm |
---|
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 |
---|
55 | |
---|
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] |
---|
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] |
---|
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. |
---|
70 | |
---|
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 |
---|
74 | |
---|
75 | // These are the constants used for spacing out elements in ImagePlot. |
---|
76 | const float imTitleOffset = 2.7; ///< Offset for title of map. |
---|
77 | |
---|
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; |
---|
84 | |
---|
85 | //*************************************************************************** |
---|
86 | //*************************************************************************** |
---|
87 | |
---|
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 | |
---|
97 | class SpectralPlot |
---|
98 | { |
---|
99 | public: |
---|
100 | SpectralPlot(); ///< Constructor |
---|
101 | virtual ~SpectralPlot(); ///< Destructor |
---|
102 | SpectralPlot(const SpectralPlot& p); |
---|
103 | SpectralPlot& operator=(const SpectralPlot& p); |
---|
104 | |
---|
105 | /// @brief Set up PGPLOT output. |
---|
106 | int setUpPlot(std::string pgDestination); |
---|
107 | |
---|
108 | /// @brief Calculate boundaries for boxes. |
---|
109 | void calcCoords(); |
---|
110 | /// @brief Set up the header & write the X-label. |
---|
111 | void gotoHeader(std::string xlabel); |
---|
112 | |
---|
113 | /// @brief Write first line of header information (position/velocity info) in correct place. |
---|
114 | void firstHeaderLine(std::string line); |
---|
115 | |
---|
116 | /// @brief Write second line of header information (fluxes) in correct place. |
---|
117 | void secondHeaderLine(std::string line); |
---|
118 | |
---|
119 | /// @brief Write third line of header information (WCS widths) in correct place. |
---|
120 | void thirdHeaderLine(std::string line); |
---|
121 | |
---|
122 | /// @brief Write fourth line of header information (pixel coordinates) in correct place. |
---|
123 | void fourthHeaderLine(std::string line); |
---|
124 | |
---|
125 | /// @brief Set up main spectral plotting region. |
---|
126 | void gotoMainSpectrum(float x1, float x2, float y1, float y2, |
---|
127 | std::string ylabel); |
---|
128 | |
---|
129 | /// @brief Set up zoomed-in spectral plotting region. |
---|
130 | void gotoZoomSpectrum(float x1, float x2, float y1, float y2); |
---|
131 | |
---|
132 | /// @brief Defines the region for the moment map. |
---|
133 | void gotoMap(); |
---|
134 | |
---|
135 | /// @brief Draw lines indicating velocity range. |
---|
136 | void drawVelRange(float v1, float v2); |
---|
137 | |
---|
138 | /// @brief Draw box showing excluded range due to Milky Way. |
---|
139 | void drawMWRange(float v1, float v2); |
---|
140 | |
---|
141 | /// @brief Return number of spectra that go on a page. |
---|
142 | int getNumOnPage(); |
---|
143 | |
---|
144 | /// @brief Set number of spectra that go on a page. |
---|
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. |
---|
150 | void goToPlot(); ///< Goes to the plot when more than one are open. |
---|
151 | |
---|
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. |
---|
161 | |
---|
162 | }; |
---|
163 | |
---|
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;} |
---|
170 | |
---|
171 | //*************************************************************************** |
---|
172 | //*************************************************************************** |
---|
173 | |
---|
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 | |
---|
183 | class ImagePlot |
---|
184 | { |
---|
185 | public: |
---|
186 | ImagePlot(); ///< Constructor |
---|
187 | virtual ~ImagePlot(); ///< Destructor |
---|
188 | ImagePlot(const ImagePlot& p); |
---|
189 | ImagePlot& operator=(const ImagePlot& p); |
---|
190 | |
---|
191 | /// @brief Set up PGPLOT output. |
---|
192 | int setUpPlot(std::string pgDestination, float x, float y); |
---|
193 | |
---|
194 | /// @brief Defines and draws box. |
---|
195 | void drawMapBox(float x1, float x2, float y1, float y2, |
---|
196 | std::string xlabel, std::string ylabel); |
---|
197 | |
---|
198 | /// @brief Write plot title. |
---|
199 | void makeTitle(std::string title); |
---|
200 | |
---|
201 | float cmToCoord(float cm);///< Converts distance in cm to coordinate distance on the plot. |
---|
202 | float getMargin(); ///< Returns width of margin. |
---|
203 | float getPaperWidth(); ///< Returns width of paper. |
---|
204 | float imageWidth(); ///< Returns the calculated total width of the image part of the plot [inches] |
---|
205 | float getImageHeight(); ///< Returns height of image [inches] |
---|
206 | float getAspectRatio(); ///< Returns the aspect ratio of the image. |
---|
207 | void goToPlot(); ///< Goes to the plot when more than one are open |
---|
208 | |
---|
209 | private: |
---|
210 | float paperWidth; ///< Default (maximum) width of "paper" [inches] |
---|
211 | float maxPaperHeight; ///< Maximum allowed height of paper [inches] |
---|
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). |
---|
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 | //---------------------------------------------------------- |
---|
223 | |
---|
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;} |
---|
228 | |
---|
229 | //*************************************************************************** |
---|
230 | //*************************************************************************** |
---|
231 | |
---|
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 | |
---|
241 | class CutoutPlot |
---|
242 | { |
---|
243 | public: |
---|
244 | CutoutPlot(); ///< Constructor |
---|
245 | virtual ~CutoutPlot(); ///< Destructor |
---|
246 | CutoutPlot(const CutoutPlot& p); |
---|
247 | CutoutPlot& operator=(const CutoutPlot& p); |
---|
248 | |
---|
249 | /// @brief Set up PGPLOT output. |
---|
250 | int setUpPlot(std::string pgDestination); |
---|
251 | |
---|
252 | /// @brief Calculate boundaries for boxes. |
---|
253 | void calcCoords(); |
---|
254 | /// @brief Set up the header box |
---|
255 | void gotoHeader(); |
---|
256 | |
---|
257 | /// @brief Write first line of header information (position/velocity info) in correct place. |
---|
258 | void firstHeaderLine(std::string line); |
---|
259 | |
---|
260 | /// @brief Write second line of header information (fluxes) in correct place. |
---|
261 | void secondHeaderLine(std::string line); |
---|
262 | |
---|
263 | /// @brief Write third line of header information (WCS widths) in correct place. |
---|
264 | void thirdHeaderLine(std::string line); |
---|
265 | |
---|
266 | /// @brief Write fourth line of header information (pixel coordinates) in correct place. |
---|
267 | void fourthHeaderLine(std::string line); |
---|
268 | |
---|
269 | /// @brief Defines the region for the moment map. |
---|
270 | void gotoMap(); |
---|
271 | |
---|
272 | /// @brief Goes to the plot when more than one are open. |
---|
273 | void goToPlot(); |
---|
274 | |
---|
275 | /// @brief Return the number of objects that go on a page. |
---|
276 | int getNumOnPage(){return numOnPage;} |
---|
277 | /// @brief Set number of objects that go on a page. |
---|
278 | void setNumOnPage(int i){numOnPage=i;} |
---|
279 | |
---|
280 | /// @brief Return width of plottable region. |
---|
281 | float getPaperWidth(){return paperWidth;} |
---|
282 | /// @brief Set width of plottable region. |
---|
283 | void setPaperWidth(float f){paperWidth=f;} |
---|
284 | /// @brief Return height of plottable region. |
---|
285 | float getPaperHeight(){return paperHeight;} |
---|
286 | /// @brief Set height of plottable region. |
---|
287 | void setPaperHeight(float f){paperHeight=f;} |
---|
288 | |
---|
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. |
---|
297 | |
---|
298 | }; |
---|
299 | |
---|
300 | |
---|
301 | } |
---|
302 | |
---|
303 | } |
---|
304 | |
---|
305 | #endif |
---|
306 | |
---|