source: branches/pixel-map-branch/src/Cubes/plots.cc

Last change on this file was 232, checked in by Matthew Whiting, 17 years ago

Large raft of changes. Most are minor ones related to fixing up the use of std::string and std::vector (whether they are declared as using, or not...). Other changes include:

  • Moving the reconstruction filter class Filter into its own header/implementation files filter.{hh,cc}. As a result, the atrous.cc file is removed, but atrous.hh remains with just the function prototypes.
  • Incorporating a Filter object into the Param set, so that the reconstruction routines can see it without the messy "extern" call. The define() function is now called in both the Param() and Param::readParams() functions, and no longer in the main body.
  • Col functions in columns.cc moved into the Column namespace, while the template function printEntry is moved into the columns.hh file -- it would not compile on delphinus with it in the columns.cc, even though all the implementations were present.
  • Improved the introductory section of the Guide, with a bit more detail about each of the execution steps. This way the reader can read this section and have a reasonably good idea about what is happening.
  • Other minor changes to the Guide.
File size: 9.9 KB
Line 
1#include <iostream>
2#include <sstream>
3#include <string>
4#include <math.h>
5#include <cpgplot.h>
6#include <param.hh>
7#include <Utils/mycpgplot.hh>
8#include <Cubes/plots.hh>
9
10using std::stringstream;
11using namespace mycpgplot;
12
13namespace Plot
14{
15
16  //----------------------------------------------------------
17  // SpectralPlot functions
18  //----------------------------------------------------------
19
20  SpectralPlot::SpectralPlot(){
21    paperWidth=a4width/inchToCm - 2*psHoffset;
22    spectraCount=0;
23    numOnPage = 5;
24    indexSize = 0.6;
25    labelSize = 0.7;
26  };
27
28  SpectralPlot::~SpectralPlot(){};
29  //----------------------------------------------------------
30  int SpectralPlot::setUpPlot(std::string pgDestination){
31    /**
32     * Opens the designated pgplot device.  Scales the paper so that
33     * it fits on an A4 sheet (using known values of the default
34     * pgplot offsets). 
35     *
36     * \param pgDestination The std::string indicating the PGPLOT device to
37     * be written to.
38     *
39     * \return The value returned by cpgopen. If <= 0, then an error
40     * has occurred.
41     */
42    paperHeight = paperWidth*M_SQRT2;
43    if(paperHeight+2*psVoffset > a4height){
44      paperHeight = a4height - 2*psVoffset;
45      paperWidth = paperHeight / M_SQRT2;
46    }
47    identifier = cpgopen(pgDestination.c_str());
48    if(identifier>0) cpgpap(paperWidth, paperHeight/paperWidth);
49    // make paper size to fit on A4.
50    return identifier;
51  }
52  //----------------------------------------------------------
53  void SpectralPlot::calcCoords(){
54    /**
55     * Calculates the boundaries for the various boxes, in inches measured
56     *  from the lower left corner.
57     * Based on the fact that there are numOnPage spectra shown on each
58     *  page, going down the page in increasing number (given by
59     *  SpectralPlot::spectraCount).
60     */
61    int posOnPage = (numOnPage - (spectraCount%numOnPage))%numOnPage;
62    mainCoords[0] = Plot::spMainX1/inchToCm;
63    mainCoords[1] = Plot::spMainX2/inchToCm;
64    zoomCoords[0] = Plot::spZoomX1/inchToCm;
65    zoomCoords[1] = Plot::spZoomX2/inchToCm;
66    mainCoords[2] = zoomCoords[2] = mapCoords[2] =
67      posOnPage*paperHeight/float(numOnPage) + Plot::spMainY1/inchToCm;
68    mainCoords[3] = zoomCoords[3] = mapCoords[3] =
69      posOnPage*paperHeight/float(numOnPage) + Plot::spMainY2/inchToCm;
70    mapCoords[0]  = Plot::spMapX1/inchToCm;
71    mapCoords[1]  = mapCoords[0] + (mapCoords[3]-mapCoords[2]);
72  }
73  //----------------------------------------------------------
74  void SpectralPlot::gotoHeader(std::string xlabel){
75    /**
76     * Calls calcCoords, to calculate correct coordinates for this spectrum.
77     * Defines the region for the header information, making it centred
78     *  on the page.
79     * Also writes the velocity (x axis) label, given by the string argument.
80     * \param xlabel Label to go on the velocity/spectral axis.
81     */
82    if(spectraCount%numOnPage==0) cpgpage();
83    spectraCount++;
84    calcCoords();
85    cpgvsiz(0., paperWidth, mainCoords[2], mainCoords[3]); 
86    cpgsch(labelSize);
87    cpgmtxt("b",Plot::spXlabelOffset,0.5,0.5,xlabel.c_str());
88  }
89  //----------------------------------------------------------
90  void SpectralPlot::gotoMainSpectrum(float x1, float x2, float y1, float y2, std::string ylabel){
91    /**
92     *  Defines the region for the main spectrum.
93     *  Draws the box, with tick marks, and
94     *   writes the flux (y axis) label, given by the string argument.
95     * \param x1 Minimum X-coordinate of box.
96     * \param x2 Maximum X-coordinate of box.
97     * \param y1 Minimum Y-coordinate of box.
98     * \param y2 Maximum Y-coordinate of box.
99     * \param ylabel Label for the flux (Y) axis.
100     */
101    cpgvsiz(mainCoords[0],mainCoords[1],mainCoords[2],mainCoords[3]);
102    cpgsch(indexSize);
103    cpgswin(x1,x2,y1,y2);
104    cpgbox("1bcnst",0.,0,"bcnst1v",0.,0);
105    cpgsch(labelSize);
106    cpgmtxt("l",Plot::spYlabelOffset,0.5,0.5,ylabel.c_str());
107  }
108  //----------------------------------------------------------
109  void SpectralPlot::gotoZoomSpectrum(float x1, float x2, float y1, float y2){
110    /**
111     *   Defines the region for the zoomed-in part of the spectrum.
112     *   Draws the box, with special tick marks on the bottom axis.
113     * \param x1 Minimum X-coordinate of box.
114     * \param x2 Maximum X-coordinate of box.
115     * \param y1 Minimum Y-coordinate of box.
116     * \param y2 Maximum Y-coordinate of box.
117     */
118    cpgvsiz(zoomCoords[0],zoomCoords[1],zoomCoords[2],zoomCoords[3]);
119    cpgsch(indexSize);
120    cpgswin(x1,x2,y1,y2);
121    cpgbox("bc",0.,0,"bcstn1v",0.,0);
122    float lengthL,lengthR,disp,tickpt,step;
123    stringstream label;
124    for(int i=1;i<10;i++){
125      tickpt = x1+(x2-x1)*float(i)/10.;  // spectral coord of the tick
126      switch(i)
127        {
128        case 2:
129        case 8:
130          lengthL = lengthR = 0.5;
131          disp = 0.3 + float(i-2)/6.; // i==2 --> disp=0.3, i==8 --> disp=1.3
132          label.str("");
133          label << tickpt;
134          // do a labelled tick mark
135          cpgtick(x1,y1,x2,y1,float(i)/10.,lengthL,lengthR,
136                  disp, 0., label.str().c_str());
137          break;
138        default:
139          label.str("");
140          lengthL = 0.25;
141          lengthR = 0.;
142          disp = 0.;  // not used in this case, but set it anyway.
143          break;
144        }
145      // first the bottom axis, just the ticks
146      if(fabs(tickpt)<(x2-x1)/1.e4) step = 2.*(x2-x1);
147      else step = tickpt;
148      cpgaxis("",
149              tickpt-0.001*(x2-x1), y1,
150              tickpt+0.001*(x2-x1), y1,
151              tickpt-0.001*(x2-x1), tickpt+0.001*(x2-x1),
152              step, -1, lengthL,lengthR, 0.5, disp, 0.);
153      //and now the top -- no labels, just tick marks
154      cpgtick(x1,y2,x2,y2,float(i)/10.,lengthL,lengthR,0.,0.,"");
155    }
156  }
157  //----------------------------------------------------------
158  void SpectralPlot::gotoMap(){
159    cpgvsiz(mapCoords[0],mapCoords[1],mapCoords[2],mapCoords[3]);
160    cpgsch(indexSize);
161  }
162  //----------------------------------------------------------
163  void SpectralPlot::drawVelRange(float v1, float v2){
164    /**
165     * Draws two vertical lines at the limits of velocity
166     *  given by the arguments.
167     * \param v1 Minimum velocity.
168     * \param v2 Maximum velocity.
169     */
170    int ci,ls;
171    float dud,min,max;
172    cpgqwin(&dud,&dud,&min,&max);
173    cpgqci(&ci);
174    cpgqls(&ls);
175    cpgsci(BLUE);
176    cpgsls(DASHED);
177    cpgmove(v1,min);  cpgdraw(v1,max);
178    cpgmove(v2,min);  cpgdraw(v2,max);
179    cpgsci(ci);
180    cpgsls(ls);
181  }
182  //----------------------------------------------------------
183  void SpectralPlot::drawMWRange(float v1, float v2){
184    /**
185     * Draws a box showing the extent of channels masked by the
186     *  Milky Way parameters
187     * \param v1 Minimum velocity of the Milky Way range.
188     * \param v2 Maximum velocity of the Milky Way range.
189     */
190    int ci,fs;
191    float dud,min,max,height;
192    cpgqwin(&dud,&dud,&min,&max);
193    height = max-min;
194    max += 0.01*height;
195    min -= 0.01*height;
196    cpgqci(&ci);
197    cpgqfs(&fs);
198    setDarkGreen();
199    cpgsci(DARKGREEN);
200    cpgsfs(HATCHED);
201    cpgrect(v1,v2,min,max);
202    cpgsfs(OUTLINE);
203    cpgrect(v1,v2,min,max);
204    cpgsci(ci);
205    cpgsfs(fs);
206  }
207
208  //----------------------------------------------------------
209  //----------------------------------------------------------
210  // ImagePlot functions
211  //----------------------------------------------------------
212
213  ImagePlot::ImagePlot(){
214    paperWidth = 7.5;
215    maxPaperHeight = 10.;
216    marginWidth = 0.8;
217    wedgeWidth = 0.7;
218  };
219
220  ImagePlot::~ImagePlot(){};
221  //----------------------------------------------------------
222
223  int ImagePlot::setUpPlot(std::string pgDestination, float x, float y){
224    /**
225     *  Opens a pgplot device and scales it to the correct shape.
226     *  In doing so, the dimensions for the image are set, and the required
227     *   aspect ratios of the image and of the plot are calculated.
228     *  If the resulting image is going to be tall enough to exceed the
229     *   maximum height (given the default width), then scale everything
230     *   down by enough to make the height equal to maxPaperHeight.
231     * \param pgDestination  The string indicating the PGPLOT device to be
232     *   written to.
233     * \param x The length of the X-axis.
234     * \param y The length of the Y-axis.
235     * \return The value returned by cpgopen: if <= 0, then an error
236     *  has occurred.
237     */
238    xdim = x;
239    ydim = y;
240    imageRatio= ydim / xdim;
241    aspectRatio =  (imageRatio*imageWidth() + 2*marginWidth) / paperWidth;
242    float correction;
243    if((imageRatio*imageWidth() + 2*marginWidth) > maxPaperHeight){
244      correction = maxPaperHeight / (imageRatio*imageWidth()+2*marginWidth);
245      paperWidth *= correction;
246      marginWidth *= correction;
247      wedgeWidth *= correction;
248    }
249    identifier = cpgopen(pgDestination.c_str());
250    if(identifier>0) cpgpap(paperWidth, aspectRatio);
251    return identifier;
252  }
253  //----------------------------------------------------------
254  void ImagePlot::drawMapBox(float x1, float x2, float y1, float y2,
255                             std::string xlabel, std::string ylabel){
256    /**
257     *  Defines the region that the box containing the map is to go in,
258     *  and draws the box with limits given by the arguments.
259     *  Also writes labels on both X- and Y-axes.
260     * \param x1 Minimum X-axis value.
261     * \param x2 Maximum X-axis value.
262     * \param y1 Minimum Y-axis value.
263     * \param y2 Maximum Y-axis value.
264     * \param xlabel The label to be put on the X-axis.
265     * \param ylabel The label to be put on the Y-axis.
266     */
267    cpgvsiz(marginWidth, marginWidth + imageWidth(),
268            marginWidth, marginWidth + (imageWidth()*imageRatio));
269    cpgslw(2);
270    cpgswin(x1,x2,y1,y2);
271    cpgbox("bcst",0.,0,"bcst",0.,0);
272    cpgslw(1);
273    cpgbox("bcnst",0.,0,"bcnst",0.,0);
274    cpglab(xlabel.c_str(), ylabel.c_str(), "");
275  }
276  //----------------------------------------------------------
277  void ImagePlot::makeTitle(std::string title){
278    /**
279     *    Writes the title for the plot, making it centred for the entire
280     *     plot and not just the map.
281     *   \param title String with title for plot.
282     */
283    cpgvstd();
284    cpgmtxt("t", Plot::imTitleOffset, 0.5, 0.5, title.c_str());
285  }
286
287
288}
Note: See TracBrowser for help on using the repository browser.