source: tags/release-1.2.2/src/Cubes/plots.cc

Last change on this file was 1015, checked in by MatthewWhiting, 12 years ago

Removing diagnostic output

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