1 | // ----------------------------------------------------------------------- |
---|
2 | // plots.cc: Functions defining SpectralPlot and ImagePlot classes. |
---|
3 | // ----------------------------------------------------------------------- |
---|
4 | // Copyright (C) 2006, Matthew Whiting, ATNF |
---|
5 | // |
---|
6 | // This program is free software; you can redistribute it and/or modify it |
---|
7 | // under the terms of the GNU General Public License as published by the |
---|
8 | // Free Software Foundation; either version 2 of the License, or (at your |
---|
9 | // option) any later version. |
---|
10 | // |
---|
11 | // Duchamp is distributed in the hope that it will be useful, but WITHOUT |
---|
12 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
13 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
---|
14 | // for more details. |
---|
15 | // |
---|
16 | // You should have received a copy of the GNU General Public License |
---|
17 | // along with Duchamp; if not, write to the Free Software Foundation, |
---|
18 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA |
---|
19 | // |
---|
20 | // Correspondence concerning Duchamp may be directed to: |
---|
21 | // Internet email: Matthew.Whiting [at] atnf.csiro.au |
---|
22 | // Postal address: Dr. Matthew Whiting |
---|
23 | // Australia Telescope National Facility, CSIRO |
---|
24 | // PO Box 76 |
---|
25 | // Epping NSW 1710 |
---|
26 | // AUSTRALIA |
---|
27 | // ----------------------------------------------------------------------- |
---|
28 | #include <iostream> |
---|
29 | #include <sstream> |
---|
30 | #include <string> |
---|
31 | #include <math.h> |
---|
32 | #include <cpgplot.h> |
---|
33 | #include <duchamp/param.hh> |
---|
34 | #include <duchamp/fitsHeader.hh> |
---|
35 | #include <duchamp/duchamp.hh> |
---|
36 | #include <duchamp/Utils/mycpgplot.hh> |
---|
37 | #include <duchamp/Cubes/plots.hh> |
---|
38 | |
---|
39 | using std::stringstream; |
---|
40 | using namespace mycpgplot; |
---|
41 | |
---|
42 | namespace duchamp |
---|
43 | { |
---|
44 | |
---|
45 | namespace Plot |
---|
46 | { |
---|
47 | |
---|
48 | //---------------------------------------------------------- |
---|
49 | // SpectralPlot functions |
---|
50 | //---------------------------------------------------------- |
---|
51 | |
---|
52 | SpectralPlot::SpectralPlot(){ |
---|
53 | this->paperWidth=a4width/inchToCm - 2*psHoffset; |
---|
54 | this->aspectRatio = M_SQRT2; |
---|
55 | this->spectraCount=0; |
---|
56 | this->numOnPage = 5; |
---|
57 | } |
---|
58 | |
---|
59 | SpectralPlot::~SpectralPlot(){} |
---|
60 | |
---|
61 | SpectralPlot::SpectralPlot(const SpectralPlot& p) |
---|
62 | { |
---|
63 | operator=(p); |
---|
64 | } |
---|
65 | |
---|
66 | SpectralPlot& SpectralPlot::operator=(const SpectralPlot& p) |
---|
67 | { |
---|
68 | if(this==&p) return *this; |
---|
69 | this->numOnPage = p.numOnPage; |
---|
70 | this->spectraCount = p.spectraCount; |
---|
71 | for(int i=0;i<4;i++) this->mainCoords[i] = p.mainCoords[i]; |
---|
72 | for(int i=0;i<4;i++) this->zoomCoords[i] = p.zoomCoords[i]; |
---|
73 | for(int i=0;i<4;i++) this->mapCoords[i] = p.mapCoords[i]; |
---|
74 | this->paperWidth = p.paperWidth; |
---|
75 | this->paperHeight = p.paperHeight; |
---|
76 | this->aspectRatio = p.aspectRatio; |
---|
77 | this->identifier = p.identifier; |
---|
78 | return *this; |
---|
79 | } |
---|
80 | |
---|
81 | //---------------------------------------------------------- |
---|
82 | int SpectralPlot::setUpPlot(std::string pgDestination) |
---|
83 | { |
---|
84 | /// @details |
---|
85 | /// Opens the designated pgplot device. Scales the paper so that |
---|
86 | /// it fits on an A4 sheet (using known values of the default |
---|
87 | /// pgplot offsets). |
---|
88 | /// |
---|
89 | /// \param pgDestination The std::string indicating the PGPLOT device to |
---|
90 | /// be written to. |
---|
91 | /// |
---|
92 | /// \return The value returned by mycpgopen. If <= 0, then an error |
---|
93 | /// has occurred. |
---|
94 | |
---|
95 | this->paperHeight = this->paperWidth*this->aspectRatio; |
---|
96 | if(this->paperHeight+2*Plot::psVoffset > Plot::a4height){ |
---|
97 | this->paperHeight = Plot::a4height - 2*Plot::psVoffset; |
---|
98 | this->paperWidth = this->paperHeight / this->aspectRatio; |
---|
99 | } |
---|
100 | this->identifier = mycpgopen(pgDestination); |
---|
101 | if(this->identifier>0) cpgpap(this->paperWidth, this->aspectRatio); |
---|
102 | // make paper size to fit on A4. |
---|
103 | return this->identifier; |
---|
104 | } |
---|
105 | //---------------------------------------------------------- |
---|
106 | void SpectralPlot::close() |
---|
107 | { |
---|
108 | cpgclos(); |
---|
109 | } |
---|
110 | //---------------------------------------------------------- |
---|
111 | void SpectralPlot::calcCoords() |
---|
112 | { |
---|
113 | /// @details |
---|
114 | /// Calculates the boundaries for the various boxes, in inches measured |
---|
115 | /// from the lower left corner. |
---|
116 | /// Based on the fact that there are numOnPage spectra shown on each |
---|
117 | /// page, going down the page in increasing number (given by |
---|
118 | /// SpectralPlot::spectraCount). |
---|
119 | |
---|
120 | int posOnPage = (this->numOnPage - |
---|
121 | (this->spectraCount%this->numOnPage)) |
---|
122 | %this->numOnPage; |
---|
123 | this->mainCoords[0] = Plot::spMainX1/inchToCm; |
---|
124 | this->mainCoords[1] = Plot::spMainX2/inchToCm; |
---|
125 | this->zoomCoords[0] = Plot::spZoomX1/inchToCm; |
---|
126 | this->zoomCoords[1] = Plot::spZoomX2/inchToCm; |
---|
127 | this->mainCoords[2] = this->zoomCoords[2] = this->mapCoords[2] = |
---|
128 | posOnPage*paperHeight/float(this->numOnPage) + Plot::spMainY1/inchToCm; |
---|
129 | this->mainCoords[3] = this->zoomCoords[3] = this->mapCoords[3] = |
---|
130 | posOnPage*paperHeight/float(this->numOnPage) + Plot::spMainY2/inchToCm; |
---|
131 | this->mapCoords[0] = Plot::spMapX1/inchToCm; |
---|
132 | this->mapCoords[1] = this->mapCoords[0] + (this->mapCoords[3]-this->mapCoords[2]); |
---|
133 | } |
---|
134 | //---------------------------------------------------------- |
---|
135 | void SpectralPlot::gotoHeader(std::string xlabel) |
---|
136 | { |
---|
137 | /// @details |
---|
138 | /// Calls calcCoords, to calculate correct coordinates for this spectrum. |
---|
139 | /// Defines the region for the header information, making it centred |
---|
140 | /// on the page. |
---|
141 | /// Also writes the velocity (x axis) label, given by the string argument. |
---|
142 | /// \param xlabel Label to go on the velocity/spectral axis. |
---|
143 | |
---|
144 | if(spectraCount%numOnPage==0) cpgpage(); |
---|
145 | spectraCount++; |
---|
146 | this->calcCoords(); |
---|
147 | cpgvsiz(0., this->paperWidth, this->mainCoords[2], this->mainCoords[3]); |
---|
148 | cpgsch(Plot::spLabelSize); |
---|
149 | cpgmtxt("b",Plot::spXlabelOffset,0.5,0.5,xlabel.c_str()); |
---|
150 | } |
---|
151 | //---------------------------------------------------------- |
---|
152 | void SpectralPlot::gotoMainSpectrum(float x1, float x2, float y1, float y2, std::string ylabel) |
---|
153 | { |
---|
154 | /// @details |
---|
155 | /// Defines the region for the main spectrum. |
---|
156 | /// Draws the box, with tick marks, and |
---|
157 | /// writes the flux (y axis) label, given by the string argument. |
---|
158 | /// \param x1 Minimum X-coordinate of box. |
---|
159 | /// \param x2 Maximum X-coordinate of box. |
---|
160 | /// \param y1 Minimum Y-coordinate of box. |
---|
161 | /// \param y2 Maximum Y-coordinate of box. |
---|
162 | /// \param ylabel Label for the flux (Y) axis. |
---|
163 | |
---|
164 | cpgvsiz(this->mainCoords[0],this->mainCoords[1], |
---|
165 | this->mainCoords[2],this->mainCoords[3]); |
---|
166 | cpgsch(Plot::spIndexSize); |
---|
167 | cpgswin(x1,x2,y1,y2); |
---|
168 | cpgbox("1bcnst",0.,0,"bcnst1v",0.,0); |
---|
169 | cpgsch(Plot::spLabelSize); |
---|
170 | cpgmtxt("l",Plot::spYlabelOffset,0.5,0.5,ylabel.c_str()); |
---|
171 | } |
---|
172 | //---------------------------------------------------------- |
---|
173 | void SpectralPlot::gotoZoomSpectrum(float x1, float x2, float y1, float y2) |
---|
174 | { |
---|
175 | /// @details |
---|
176 | /// Defines the region for the zoomed-in part of the spectrum. |
---|
177 | /// Draws the box, with special tick marks on the bottom axis. |
---|
178 | /// \param x1 Minimum X-coordinate of box. |
---|
179 | /// \param x2 Maximum X-coordinate of box. |
---|
180 | /// \param y1 Minimum Y-coordinate of box. |
---|
181 | /// \param y2 Maximum Y-coordinate of box. |
---|
182 | |
---|
183 | cpgvsiz(this->zoomCoords[0],this->zoomCoords[1], |
---|
184 | this->zoomCoords[2],this->zoomCoords[3]); |
---|
185 | cpgsch(Plot::spIndexSize); |
---|
186 | cpgswin(x1,x2,y1,y2); |
---|
187 | cpgbox("bc",0.,0,"bcstn1v",0.,0); |
---|
188 | float lengthL,lengthR,disp,tickpt,step; |
---|
189 | stringstream label; |
---|
190 | for(int i=1;i<10;i++){ |
---|
191 | tickpt = x1+(x2-x1)*float(i)/10.; // spectral coord of the tick |
---|
192 | switch(i) |
---|
193 | { |
---|
194 | case 2: |
---|
195 | case 8: |
---|
196 | lengthL = lengthR = 0.5; |
---|
197 | disp = 0.3 + float(i-2)/6.; // i==2 --> disp=0.3, i==8 --> disp=1.3 |
---|
198 | label.str(""); |
---|
199 | label << tickpt; |
---|
200 | // do a labelled tick mark |
---|
201 | cpgtick(x1,y1,x2,y1,float(i)/10.,lengthL,lengthR, |
---|
202 | disp, 0., label.str().c_str()); |
---|
203 | break; |
---|
204 | default: |
---|
205 | label.str(""); |
---|
206 | lengthL = 0.25; |
---|
207 | lengthR = 0.; |
---|
208 | disp = 0.; // not used in this case, but set it anyway. |
---|
209 | break; |
---|
210 | } |
---|
211 | // first the bottom axis, just the ticks |
---|
212 | if(fabs(tickpt)<(x2-x1)/1.e4) step = 2.*(x2-x1); |
---|
213 | else step = tickpt; |
---|
214 | cpgaxis("", |
---|
215 | tickpt-0.001*(x2-x1), y1, |
---|
216 | tickpt+0.001*(x2-x1), y1, |
---|
217 | tickpt-0.001*(x2-x1), tickpt+0.001*(x2-x1), |
---|
218 | step, -1, lengthL,lengthR, 0.5, disp, 0.); |
---|
219 | //and now the top -- no labels, just tick marks |
---|
220 | cpgtick(x1,y2,x2,y2,float(i)/10.,lengthL,lengthR,0.,0.,""); |
---|
221 | } |
---|
222 | } |
---|
223 | //---------------------------------------------------------- |
---|
224 | void SpectralPlot::gotoMap() |
---|
225 | { |
---|
226 | cpgvsiz(this->mapCoords[0],this->mapCoords[1], |
---|
227 | this->mapCoords[2],this->mapCoords[3]); |
---|
228 | cpgsch(Plot::spIndexSize); |
---|
229 | } |
---|
230 | //---------------------------------------------------------- |
---|
231 | void SpectralPlot::drawVelRange(float v1, float v2) |
---|
232 | { |
---|
233 | /// @details |
---|
234 | /// Draws two vertical lines at the limits of velocity |
---|
235 | /// given by the arguments. |
---|
236 | /// \param v1 Minimum velocity. |
---|
237 | /// \param v2 Maximum velocity. |
---|
238 | |
---|
239 | int ci,ls; |
---|
240 | float dud,min,max; |
---|
241 | cpgqwin(&dud,&dud,&min,&max); |
---|
242 | cpgqci(&ci); |
---|
243 | cpgqls(&ls); |
---|
244 | cpgsci(DUCHAMP_OBJECT_OUTLINE_COLOUR); |
---|
245 | cpgsls(DASHED); |
---|
246 | cpgmove(v1,min); cpgdraw(v1,max); |
---|
247 | cpgmove(v2,min); cpgdraw(v2,max); |
---|
248 | cpgsci(ci); |
---|
249 | cpgsls(ls); |
---|
250 | } |
---|
251 | //---------------------------------------------------------- |
---|
252 | void SpectralPlot::drawMWRange(float v1, float v2) |
---|
253 | { |
---|
254 | /// @details |
---|
255 | /// Draws a box showing the extent of channels masked by the |
---|
256 | /// Milky Way parameters |
---|
257 | /// \param v1 Minimum velocity of the Milky Way range. |
---|
258 | /// \param v2 Maximum velocity of the Milky Way range. |
---|
259 | |
---|
260 | int ci,fs; |
---|
261 | float dud,min,max,height; |
---|
262 | cpgqwin(&dud,&dud,&min,&max); |
---|
263 | height = max-min; |
---|
264 | max += 0.01*height; |
---|
265 | min -= 0.01*height; |
---|
266 | cpgqci(&ci); |
---|
267 | cpgqfs(&fs); |
---|
268 | setDarkGreen(); |
---|
269 | cpgsci(DUCHAMP_MILKY_WAY_COLOUR); |
---|
270 | cpgsfs(HATCHED); |
---|
271 | cpgrect(v1,v2,min,max); |
---|
272 | cpgsfs(OUTLINE); |
---|
273 | cpgrect(v1,v2,min,max); |
---|
274 | cpgsci(ci); |
---|
275 | cpgsfs(fs); |
---|
276 | } |
---|
277 | //---------------------------------------------------------- |
---|
278 | // SpectralPlot functions... |
---|
279 | //---------------------------------------------------------- |
---|
280 | void SpectralPlot::firstHeaderLine(std::string line) |
---|
281 | { |
---|
282 | cpgsch(Plot::spTitleSize); |
---|
283 | cpgmtxt("t",Plot::spTitleOffset1*Plot::spLabelSize/Plot::spTitleSize, |
---|
284 | 0.5,0.5,line.c_str()); |
---|
285 | } |
---|
286 | void SpectralPlot::secondHeaderLine(std::string line) |
---|
287 | { |
---|
288 | cpgsch(Plot::spLabelSize); |
---|
289 | cpgmtxt("t",Plot::spTitleOffset2,0.5,0.5,line.c_str()); |
---|
290 | } |
---|
291 | void SpectralPlot::thirdHeaderLine(std::string line) |
---|
292 | { |
---|
293 | cpgsch(Plot::spLabelSize); |
---|
294 | cpgmtxt("t",Plot::spTitleOffset3,0.5,0.5,line.c_str()); |
---|
295 | } |
---|
296 | void SpectralPlot::fourthHeaderLine(std::string line) |
---|
297 | { |
---|
298 | cpgsch(Plot::spLabelSize); |
---|
299 | cpgmtxt("t",Plot::spTitleOffset4,0.5,0.5,line.c_str()); |
---|
300 | } |
---|
301 | void SpectralPlot::goToPlot(){cpgslct(this->identifier);} |
---|
302 | |
---|
303 | //---------------------------------------------------------- |
---|
304 | // SimpleSpectralPlot functions |
---|
305 | //---------------------------------------------------------- |
---|
306 | |
---|
307 | SimpleSpectralPlot::SimpleSpectralPlot(){ |
---|
308 | this->paperWidth=a4width/inchToCm - 2*psHoffset; |
---|
309 | this->aspectRatio = M_SQRT2/5.; |
---|
310 | } |
---|
311 | |
---|
312 | SimpleSpectralPlot::~SimpleSpectralPlot(){} |
---|
313 | |
---|
314 | SimpleSpectralPlot::SimpleSpectralPlot(const SimpleSpectralPlot& p) |
---|
315 | { |
---|
316 | operator=(p); |
---|
317 | } |
---|
318 | |
---|
319 | SimpleSpectralPlot& SimpleSpectralPlot::operator=(const SimpleSpectralPlot& p) |
---|
320 | { |
---|
321 | if(this==&p) return *this; |
---|
322 | for(int i=0;i<4;i++) this->mainCoords[i] = p.mainCoords[i]; |
---|
323 | this->paperWidth = p.paperWidth; |
---|
324 | this->paperHeight = p.paperHeight; |
---|
325 | this->aspectRatio = p.aspectRatio; |
---|
326 | this->identifier = p.identifier; |
---|
327 | return *this; |
---|
328 | } |
---|
329 | |
---|
330 | //---------------------------------------------------------- |
---|
331 | int SimpleSpectralPlot::setUpPlot(std::string pgDestination) |
---|
332 | { |
---|
333 | /// @details |
---|
334 | /// Opens the designated pgplot device. Scales the paper so that |
---|
335 | /// it fits on an A4 sheet (using known values of the default |
---|
336 | /// pgplot offsets). |
---|
337 | /// |
---|
338 | /// \param pgDestination The std::string indicating the PGPLOT device to |
---|
339 | /// be written to. |
---|
340 | /// |
---|
341 | /// \return The value returned by mycpgopen. If <= 0, then an error |
---|
342 | /// has occurred. |
---|
343 | |
---|
344 | if(pgDestination == "/xs") this->paperWidth=12.; |
---|
345 | |
---|
346 | this->paperHeight = this->paperWidth*this->aspectRatio; |
---|
347 | this->identifier = mycpgopen(pgDestination); |
---|
348 | if(this->identifier>0) cpgpap(this->paperWidth, this->aspectRatio); |
---|
349 | // make paper size to fit on A4. |
---|
350 | float scaling = this->paperWidth*inchToCm / a4width; |
---|
351 | this->mainCoords[0] = Plot::spMainX1/inchToCm * scaling; |
---|
352 | this->mainCoords[1] = (Plot::spMapX1+Plot::spMainY2-Plot::spMainY1)/inchToCm * scaling; |
---|
353 | this->mainCoords[2] = Plot::spMainY1/inchToCm * scaling; |
---|
354 | this->mainCoords[3] = Plot::spMainY2/inchToCm * scaling; |
---|
355 | return this->identifier; |
---|
356 | } |
---|
357 | //---------------------------------------------------------- |
---|
358 | void SimpleSpectralPlot::close() |
---|
359 | { |
---|
360 | cpgclos(); |
---|
361 | } |
---|
362 | void SimpleSpectralPlot::label(std::string xlabel,std::string ylabel, std::string title) |
---|
363 | { |
---|
364 | /// @details |
---|
365 | /// Calls calcCoords, to calculate correct coordinates for this spectrum. |
---|
366 | /// Defines the region for the header information, making it centred |
---|
367 | /// on the page. |
---|
368 | /// Also writes the velocity (x axis) label, given by the string argument. |
---|
369 | /// \param xlabel Label to go on the velocity/spectral axis. |
---|
370 | |
---|
371 | cpgvsiz(this->mainCoords[0],this->mainCoords[1],this->mainCoords[2],this->mainCoords[3]); |
---|
372 | cpgsch(2.); |
---|
373 | cpgmtxt("B",3.,0.5,0.5,xlabel.c_str()); |
---|
374 | cpgmtxt("L",4.,0.5,0.5,ylabel.c_str()); |
---|
375 | cpgmtxt("T",2.,0.5,0.5,title.c_str()); |
---|
376 | } |
---|
377 | //---------------------------------------------------------- |
---|
378 | void SimpleSpectralPlot::gotoMainSpectrum(float x1, float x2, float y1, float y2) |
---|
379 | { |
---|
380 | /// @details |
---|
381 | /// Defines the region for the main spectrum. |
---|
382 | /// Draws the box, with tick marks, and |
---|
383 | /// writes the flux (y axis) label, given by the string argument. |
---|
384 | /// \param x1 Minimum X-coordinate of box. |
---|
385 | /// \param x2 Maximum X-coordinate of box. |
---|
386 | /// \param y1 Minimum Y-coordinate of box. |
---|
387 | /// \param y2 Maximum Y-coordinate of box. |
---|
388 | /// \param ylabel Label for the flux (Y) axis. |
---|
389 | |
---|
390 | cpgvsiz(this->mainCoords[0],this->mainCoords[1],this->mainCoords[2],this->mainCoords[3]); |
---|
391 | cpgsch(2.); |
---|
392 | cpgswin(x1,x2,y1,y2); |
---|
393 | cpgbox("1bcnst",0.,0,"bcnst1v",0.,0); |
---|
394 | } |
---|
395 | //---------------------------------------------------------- |
---|
396 | void SimpleSpectralPlot::drawDetectPixel(int z, FitsHeader &head) |
---|
397 | { |
---|
398 | float v1,v2; |
---|
399 | double zero=0.; |
---|
400 | if(head.isWCS()){ |
---|
401 | double zpt=double(z-0.5); |
---|
402 | v1=head.pixToVel(zero,zero,zpt); |
---|
403 | zpt=double(z+0.5); |
---|
404 | v2=head.pixToVel(zero,zero,zpt); |
---|
405 | } |
---|
406 | else{ |
---|
407 | v1=float(z-0.5); |
---|
408 | v2=float(z+0.5); |
---|
409 | } |
---|
410 | float x1,x2,y1,y2; |
---|
411 | cpgqwin(&x1,&x2,&y1,&y2); |
---|
412 | float y=y2-0.05*(y2-y1); |
---|
413 | int lw; |
---|
414 | cpgqlw(&lw); |
---|
415 | cpgslw(3); |
---|
416 | cpgmove(v1,y); |
---|
417 | cpgdraw(v2,y); |
---|
418 | cpgslw(lw); |
---|
419 | } |
---|
420 | //---------------------------------------------------------- |
---|
421 | void SimpleSpectralPlot::drawVelRange(float v1, float v2) |
---|
422 | { |
---|
423 | /// @details |
---|
424 | /// Draws two vertical lines at the limits of velocity |
---|
425 | /// given by the arguments. |
---|
426 | /// \param v1 Minimum velocity. |
---|
427 | /// \param v2 Maximum velocity. |
---|
428 | |
---|
429 | int ci,ls; |
---|
430 | float dud,min,max; |
---|
431 | cpgqwin(&dud,&dud,&min,&max); |
---|
432 | cpgqci(&ci); |
---|
433 | cpgqls(&ls); |
---|
434 | cpgsci(DUCHAMP_OBJECT_OUTLINE_COLOUR); |
---|
435 | cpgsls(DASHED); |
---|
436 | cpgmove(v1,min); cpgdraw(v1,max); |
---|
437 | cpgmove(v2,min); cpgdraw(v2,max); |
---|
438 | cpgsci(ci); |
---|
439 | cpgsls(ls); |
---|
440 | } |
---|
441 | //---------------------------------------------------------- |
---|
442 | void SimpleSpectralPlot::drawMWRange(float v1, float v2) |
---|
443 | { |
---|
444 | /// @details |
---|
445 | /// Draws a box showing the extent of channels masked by the |
---|
446 | /// Milky Way parameters |
---|
447 | /// \param v1 Minimum velocity of the Milky Way range. |
---|
448 | /// \param v2 Maximum velocity of the Milky Way range. |
---|
449 | |
---|
450 | int ci,fs; |
---|
451 | float dud,min,max,height; |
---|
452 | cpgqwin(&dud,&dud,&min,&max); |
---|
453 | height = max-min; |
---|
454 | max += 0.01*height; |
---|
455 | min -= 0.01*height; |
---|
456 | cpgqci(&ci); |
---|
457 | cpgqfs(&fs); |
---|
458 | setDarkGreen(); |
---|
459 | cpgsci(DUCHAMP_MILKY_WAY_COLOUR); |
---|
460 | cpgsfs(HATCHED); |
---|
461 | cpgrect(v1,v2,min,max); |
---|
462 | cpgsfs(OUTLINE); |
---|
463 | cpgrect(v1,v2,min,max); |
---|
464 | cpgsci(ci); |
---|
465 | cpgsfs(fs); |
---|
466 | } |
---|
467 | |
---|
468 | |
---|
469 | //---------------------------------------------------------- |
---|
470 | //---------------------------------------------------------- |
---|
471 | // ImagePlot functions |
---|
472 | //---------------------------------------------------------- |
---|
473 | |
---|
474 | ImagePlot::ImagePlot(){ |
---|
475 | this->paperWidth = 7.5; |
---|
476 | this->maxPaperHeight = 10.; |
---|
477 | this->marginWidth = 0.8; |
---|
478 | this->wedgeWidth = 0.7; |
---|
479 | } |
---|
480 | |
---|
481 | ImagePlot::~ImagePlot(){} |
---|
482 | |
---|
483 | ImagePlot::ImagePlot(const ImagePlot& p) |
---|
484 | { |
---|
485 | operator=(p); |
---|
486 | } |
---|
487 | |
---|
488 | ImagePlot& ImagePlot::operator=(const ImagePlot& p) |
---|
489 | { |
---|
490 | if(this==&p) return *this; |
---|
491 | this->paperWidth = p.paperWidth; |
---|
492 | this->maxPaperHeight = p.maxPaperHeight; |
---|
493 | this->marginWidth = p.marginWidth; |
---|
494 | this->wedgeWidth = p.wedgeWidth; |
---|
495 | this->imageRatio = p.imageRatio; |
---|
496 | this->aspectRatio = p.aspectRatio; |
---|
497 | this->xdim = p.xdim; |
---|
498 | this->ydim = p.ydim; |
---|
499 | this->identifier = p.identifier; |
---|
500 | return *this; |
---|
501 | } |
---|
502 | |
---|
503 | //---------------------------------------------------------- |
---|
504 | |
---|
505 | int ImagePlot::setUpPlot(std::string pgDestination, float x, float y) |
---|
506 | { |
---|
507 | /// @details |
---|
508 | /// Opens a pgplot device and scales it to the correct shape. |
---|
509 | /// In doing so, the dimensions for the image are set, and the required |
---|
510 | /// aspect ratios of the image and of the plot are calculated. |
---|
511 | /// If the resulting image is going to be tall enough to exceed the |
---|
512 | /// maximum height (given the default width), then scale everything |
---|
513 | /// down by enough to make the height equal to maxPaperHeight. |
---|
514 | /// \param pgDestination The string indicating the PGPLOT device to be |
---|
515 | /// written to. |
---|
516 | /// \param x The length of the X-axis. |
---|
517 | /// \param y The length of the Y-axis. |
---|
518 | /// \return The value returned by mycpgopen: if <= 0, then an error |
---|
519 | /// has occurred. |
---|
520 | |
---|
521 | this->xdim = x; |
---|
522 | this->ydim = y; |
---|
523 | this->imageRatio= this->ydim / this->xdim; |
---|
524 | this->aspectRatio = (this->imageRatio*this->imageWidth() + 2*this->marginWidth) |
---|
525 | / this->paperWidth; |
---|
526 | float correction; |
---|
527 | if((this->imageRatio*this->imageWidth() + 2*this->marginWidth) > |
---|
528 | this->maxPaperHeight){ |
---|
529 | correction = this->maxPaperHeight / |
---|
530 | (this->imageRatio*this->imageWidth()+2*this->marginWidth); |
---|
531 | this->paperWidth *= correction; |
---|
532 | this->marginWidth *= correction; |
---|
533 | this->wedgeWidth *= correction; |
---|
534 | } |
---|
535 | this->identifier = mycpgopen(pgDestination); |
---|
536 | if(this->identifier>0) cpgpap(this->paperWidth, this->aspectRatio); |
---|
537 | return this->identifier; |
---|
538 | } |
---|
539 | //---------------------------------------------------------- |
---|
540 | void ImagePlot::close() |
---|
541 | { |
---|
542 | cpgclos(); |
---|
543 | } |
---|
544 | //---------------------------------------------------------- |
---|
545 | void ImagePlot::drawMapBox(float x1, float x2, float y1, float y2, |
---|
546 | std::string xlabel, std::string ylabel) |
---|
547 | { |
---|
548 | /// @details |
---|
549 | /// Defines the region that the box containing the map is to go in, |
---|
550 | /// and draws the box with limits given by the arguments. |
---|
551 | /// Also writes labels on both X- and Y-axes. |
---|
552 | /// \param x1 Minimum X-axis value. |
---|
553 | /// \param x2 Maximum X-axis value. |
---|
554 | /// \param y1 Minimum Y-axis value. |
---|
555 | /// \param y2 Maximum Y-axis value. |
---|
556 | /// \param xlabel The label to be put on the X-axis. |
---|
557 | /// \param ylabel The label to be put on the Y-axis. |
---|
558 | |
---|
559 | cpgvsiz(this->marginWidth, this->marginWidth + this->imageWidth(), |
---|
560 | this->marginWidth, this->marginWidth + (this->imageWidth()*this->imageRatio) ); |
---|
561 | cpgslw(2); |
---|
562 | cpgswin(x1,x2,y1,y2); |
---|
563 | cpgbox("bcst",0.,0,"bcst",0.,0); |
---|
564 | cpgslw(1); |
---|
565 | cpgbox("bcnst",0.,0,"bcnst",0.,0); |
---|
566 | cpglab(xlabel.c_str(), ylabel.c_str(), ""); |
---|
567 | } |
---|
568 | //---------------------------------------------------------- |
---|
569 | |
---|
570 | void ImagePlot::makeTitle(std::string title) |
---|
571 | { |
---|
572 | /// @details |
---|
573 | /// Writes the title for the plot, making it centred for the entire |
---|
574 | /// plot and not just the map. |
---|
575 | /// \param title String with title for plot. |
---|
576 | |
---|
577 | cpgvstd(); |
---|
578 | cpgmtxt("t", Plot::imTitleOffset, 0.5, 0.5, title.c_str()); |
---|
579 | } |
---|
580 | |
---|
581 | void ImagePlot::goToPlot(){cpgslct(this->identifier);} |
---|
582 | |
---|
583 | float ImagePlot::imageWidth(){ |
---|
584 | return this->paperWidth - 2*this->marginWidth - this->wedgeWidth; |
---|
585 | } |
---|
586 | |
---|
587 | float ImagePlot::cmToCoord(float cm){ |
---|
588 | /** \param cm Distance to be converted.*/ |
---|
589 | return (cm/Plot::inchToCm) * this->ydim / (this->imageWidth()*this->imageRatio); |
---|
590 | } |
---|
591 | |
---|
592 | |
---|
593 | //---------------------------------------------------------- |
---|
594 | //---------------------------------------------------------- |
---|
595 | // CutoutPlot functions |
---|
596 | //---------------------------------------------------------- |
---|
597 | //---------------------------------------------------------- |
---|
598 | |
---|
599 | CutoutPlot::CutoutPlot(){ |
---|
600 | this->paperWidth=a4width/inchToCm - 2*psHoffset; |
---|
601 | this->sourceCount=0; |
---|
602 | this->numOnPage = 7; |
---|
603 | } |
---|
604 | |
---|
605 | CutoutPlot::~CutoutPlot(){} |
---|
606 | |
---|
607 | CutoutPlot::CutoutPlot(const CutoutPlot& p) |
---|
608 | { |
---|
609 | operator=(p); |
---|
610 | } |
---|
611 | |
---|
612 | CutoutPlot& CutoutPlot::operator=(const CutoutPlot& p) |
---|
613 | { |
---|
614 | if(this==&p) return *this; |
---|
615 | this->numOnPage = p.numOnPage; |
---|
616 | this->sourceCount = p.sourceCount; |
---|
617 | for(int i=0;i<4;i++) this->mainCoords[i] = p.mainCoords[i]; |
---|
618 | for(int i=0;i<4;i++) this->mapCoords[i] = p.mapCoords[i]; |
---|
619 | this->paperWidth = p.paperWidth; |
---|
620 | this->paperHeight = p.paperHeight; |
---|
621 | this->identifier = p.identifier; |
---|
622 | return *this; |
---|
623 | } |
---|
624 | |
---|
625 | //---------------------------------------------------------- |
---|
626 | int CutoutPlot::setUpPlot(std::string pgDestination) |
---|
627 | { |
---|
628 | /// @details |
---|
629 | /// Opens the designated pgplot device. Scales the paper so that |
---|
630 | /// it fits on an A4 sheet (using known values of the default |
---|
631 | /// pgplot offsets). |
---|
632 | /// |
---|
633 | /// \param pgDestination The std::string indicating the PGPLOT device to |
---|
634 | /// be written to. |
---|
635 | /// |
---|
636 | /// \return The value returned by mycpgopen. If <= 0, then an error |
---|
637 | /// has occurred. |
---|
638 | |
---|
639 | this->paperHeight = this->paperWidth*M_SQRT2; |
---|
640 | if(this->paperHeight+2*Plot::psVoffset > Plot::a4height){ |
---|
641 | this->paperHeight = Plot::a4height - 2*Plot::psVoffset; |
---|
642 | this->paperWidth = this->paperHeight / M_SQRT2; |
---|
643 | } |
---|
644 | this->identifier = mycpgopen(pgDestination); |
---|
645 | if(this->identifier>0) cpgpap(this->paperWidth, this->paperHeight/this->paperWidth); |
---|
646 | // make paper size to fit on A4. |
---|
647 | return this->identifier; |
---|
648 | } |
---|
649 | //---------------------------------------------------------- |
---|
650 | void CutoutPlot::calcCoords() |
---|
651 | { |
---|
652 | /// @details |
---|
653 | /// Calculates the boundaries for the various boxes, in inches measured |
---|
654 | /// from the lower left corner. |
---|
655 | /// Based on the fact that there are numOnPage spectra shown on each |
---|
656 | /// page, going down the page in increasing number (given by |
---|
657 | /// CutoutPlot::spectraCount). |
---|
658 | |
---|
659 | int posOnPage = (this->numOnPage - |
---|
660 | (this->sourceCount%this->numOnPage)) |
---|
661 | %this->numOnPage; |
---|
662 | this->mainCoords[0] = Plot::cuMainX1/inchToCm; |
---|
663 | this->mainCoords[1] = Plot::cuMainX2/inchToCm; |
---|
664 | this->mainCoords[2] = this->mapCoords[2] = |
---|
665 | posOnPage*paperHeight/float(this->numOnPage) + Plot::cuMainY1/inchToCm; |
---|
666 | this->mainCoords[3] = this->mapCoords[3] = |
---|
667 | posOnPage*paperHeight/float(this->numOnPage) + Plot::cuMainY2/inchToCm; |
---|
668 | this->mapCoords[0] = Plot::cuMapX1/inchToCm; |
---|
669 | this->mapCoords[1] = this->mapCoords[0] + (this->mapCoords[3]-this->mapCoords[2]); |
---|
670 | } |
---|
671 | //---------------------------------------------------------- |
---|
672 | void CutoutPlot::gotoHeader() |
---|
673 | { |
---|
674 | /// @details |
---|
675 | /// Calls calcCoords, to calculate correct coordinates for this spectrum. |
---|
676 | /// Defines the region for the header information, making it centred |
---|
677 | /// on the page. |
---|
678 | /// Also writes the velocity (x axis) label, given by the string argument. |
---|
679 | /// \param xlabel Label to go on the velocity/spectral axis. |
---|
680 | |
---|
681 | if(sourceCount%numOnPage==0) cpgpage(); |
---|
682 | sourceCount++; |
---|
683 | this->calcCoords(); |
---|
684 | // cpgvsiz(0., this->paperWidth, this->mainCoords[2], this->mainCoords[3]); |
---|
685 | cpgvsiz(this->mainCoords[0], this->mainCoords[1], |
---|
686 | this->mainCoords[2], this->mainCoords[3]); |
---|
687 | cpgsch(Plot::spLabelSize); |
---|
688 | // cpgmtxt("b",Plot::spXlabelOffset,0.5,0.5,xlabel.c_str()); |
---|
689 | cpgswin(0.,1.,0.,1.); |
---|
690 | // cpgbox("bc",0,0,"bc",0,0); |
---|
691 | } |
---|
692 | //---------------------------------------------------------- |
---|
693 | |
---|
694 | void CutoutPlot::gotoMap(){ |
---|
695 | cpgvsiz(this->mapCoords[0],this->mapCoords[1], |
---|
696 | this->mapCoords[2],this->mapCoords[3]); |
---|
697 | cpgsch(Plot::spIndexSize); |
---|
698 | } |
---|
699 | //---------------------------------------------------------- |
---|
700 | // CutoutPlot functions... |
---|
701 | //---------------------------------------------------------- |
---|
702 | void CutoutPlot::firstHeaderLine(std::string line) |
---|
703 | { |
---|
704 | cpgsch(Plot::spTitleSize); |
---|
705 | // cpgmtxt("t",Plot::spTitleOffset1*Plot::spLabelSize/Plot::spTitleSize, |
---|
706 | // 0.5,0.5,line.c_str()); |
---|
707 | cpgptxt(0.5,0.8,0.,0.5,line.c_str()); |
---|
708 | } |
---|
709 | void CutoutPlot::secondHeaderLine(std::string line) |
---|
710 | { |
---|
711 | cpgsch(Plot::spLabelSize); |
---|
712 | // cpgmtxt("t",Plot::spTitleOffset2,0.5,0.5,line.c_str()); |
---|
713 | cpgptxt(0.5,0.6,0.,0.5,line.c_str()); |
---|
714 | } |
---|
715 | void CutoutPlot::thirdHeaderLine(std::string line) |
---|
716 | { |
---|
717 | cpgsch(Plot::spLabelSize); |
---|
718 | // cpgmtxt("t",Plot::spTitleOffset3,0.5,0.5,line.c_str()); |
---|
719 | cpgptxt(0.5,0.4,0.,0.5,line.c_str()); |
---|
720 | } |
---|
721 | void CutoutPlot::fourthHeaderLine(std::string line) |
---|
722 | { |
---|
723 | cpgsch(Plot::spLabelSize); |
---|
724 | // cpgmtxt("t",Plot::spTitleOffset4,0.5,0.5,line.c_str()); |
---|
725 | cpgptxt(0.5,0.2,0.,0.5,line.c_str()); |
---|
726 | } |
---|
727 | void CutoutPlot::goToPlot(){cpgslct(this->identifier);} |
---|
728 | |
---|
729 | } |
---|
730 | |
---|
731 | } |
---|