1 | // ----------------------------------------------------------------------- |
---|
2 | // ImagePlot.hh: Definition of the class for plotting 2D images |
---|
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 <duchamp/Plotting/ImagePlot.hh> |
---|
29 | #include <duchamp/Plotting/DuchampPlot.hh> |
---|
30 | #include <string> |
---|
31 | #include <cpgplot.h> |
---|
32 | |
---|
33 | namespace duchamp |
---|
34 | { |
---|
35 | namespace Plot { |
---|
36 | ImagePlot::ImagePlot(): |
---|
37 | DuchampPlot() |
---|
38 | { |
---|
39 | this->paperWidth = 7.5; |
---|
40 | this->maxPaperHeight = 10.; |
---|
41 | this->marginWidth = 0.8; |
---|
42 | this->wedgeWidth = 0.7; |
---|
43 | } |
---|
44 | |
---|
45 | ImagePlot::ImagePlot(long x, long y): |
---|
46 | DuchampPlot() |
---|
47 | { |
---|
48 | this->paperWidth = 7.5; |
---|
49 | this->maxPaperHeight = 10.; |
---|
50 | this->marginWidth = 0.8; |
---|
51 | this->wedgeWidth = 0.7; |
---|
52 | this->xdim = float(x); |
---|
53 | this->ydim = float(y); |
---|
54 | this->imageRatio= this->ydim / this->xdim; |
---|
55 | this->aspectRatio = (this->imageRatio*this->imageWidth() + 2*this->marginWidth) / this->paperWidth; |
---|
56 | } |
---|
57 | |
---|
58 | ImagePlot::ImagePlot(const ImagePlot& other) |
---|
59 | { |
---|
60 | this->operator=(other); |
---|
61 | } |
---|
62 | |
---|
63 | ImagePlot& ImagePlot::operator=(const ImagePlot& other) |
---|
64 | { |
---|
65 | if(this==&other) return *this; |
---|
66 | ((DuchampPlot &) *this) = other; |
---|
67 | this->maxPaperHeight = other.maxPaperHeight; |
---|
68 | this->marginWidth = other.marginWidth; |
---|
69 | this->wedgeWidth = other.wedgeWidth; |
---|
70 | this->imageRatio = other.imageRatio; |
---|
71 | this->xdim = other.xdim; |
---|
72 | this->ydim = other.ydim; |
---|
73 | return *this; |
---|
74 | } |
---|
75 | |
---|
76 | int ImagePlot::setUpPlot(std::string pgDestination) |
---|
77 | { |
---|
78 | float correction; |
---|
79 | if((this->imageRatio*this->imageWidth() + 2*this->marginWidth) > this->maxPaperHeight){ |
---|
80 | correction = this->maxPaperHeight / (this->imageRatio*this->imageWidth()+2*this->marginWidth); |
---|
81 | this->paperWidth *= correction; |
---|
82 | this->marginWidth *= correction; |
---|
83 | this->wedgeWidth *= correction; |
---|
84 | } |
---|
85 | return this->open(pgDestination); |
---|
86 | } |
---|
87 | |
---|
88 | void ImagePlot::drawMapBox(float x1, float x2, float y1, float y2, std::string xlabel, std::string ylabel) |
---|
89 | { |
---|
90 | /// @details |
---|
91 | /// Defines the region that the box containing the map is to go in, |
---|
92 | /// and draws the box with limits given by the arguments. |
---|
93 | /// Also writes labels on both X- and Y-axes. |
---|
94 | /// \param x1 Minimum X-axis value. |
---|
95 | /// \param x2 Maximum X-axis value. |
---|
96 | /// \param y1 Minimum Y-axis value. |
---|
97 | /// \param y2 Maximum Y-axis value. |
---|
98 | /// \param xlabel The label to be put on the X-axis. |
---|
99 | /// \param ylabel The label to be put on the Y-axis. |
---|
100 | |
---|
101 | cpgvsiz(this->marginWidth, this->marginWidth + this->imageWidth(), |
---|
102 | this->marginWidth, this->marginWidth + (this->imageWidth()*this->imageRatio) ); |
---|
103 | cpgslw(2); |
---|
104 | cpgswin(x1,x2,y1,y2); |
---|
105 | cpgbox("bcst",0.,0,"bcst",0.,0); |
---|
106 | cpgslw(1); |
---|
107 | cpgbox("bcnst",0.,0,"bcnst",0.,0); |
---|
108 | cpglab(xlabel.c_str(), ylabel.c_str(), ""); |
---|
109 | } |
---|
110 | |
---|
111 | void ImagePlot::makeTitle(std::string title) |
---|
112 | { |
---|
113 | /// @details |
---|
114 | /// Writes the title for the plot, making it centred for the entire |
---|
115 | /// plot and not just the map. |
---|
116 | /// \param title String with title for plot. |
---|
117 | |
---|
118 | cpgvstd(); |
---|
119 | cpgmtxt("t", Plot::imTitleOffset, 0.5, 0.5, title.c_str()); |
---|
120 | } |
---|
121 | |
---|
122 | float ImagePlot::imageWidth() |
---|
123 | { |
---|
124 | return this->paperWidth - 2*this->marginWidth - this->wedgeWidth; |
---|
125 | } |
---|
126 | |
---|
127 | float ImagePlot::cmToCoord(float cm){ |
---|
128 | /** \param cm Distance to be converted.*/ |
---|
129 | return (cm/Plot::inchToCm) * this->ydim / (this->imageWidth()*this->imageRatio); |
---|
130 | } |
---|
131 | |
---|
132 | } |
---|
133 | |
---|
134 | } |
---|