casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QPRasterPlot.h
Go to the documentation of this file.
1 //# QPRasterPlot.h: Qwt implementation of generic RasterPlot class.
2 //# Copyright (C) 2008
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id: $
27 #ifndef QPRASTERPLOT_H_
28 #define QPRASTERPLOT_H_
29 
30 #ifdef AIPS_HAS_QWT
31 
35 
36 #include <qwt_color_map.h>
37 #include <qwt_plot_spectrogram.h>
38 
39 namespace casa {
40 
41 // Implementation of QwtColorMap that just returns the value as a color.
42 class QPRasterMap : public QwtColorMap {
43 public:
44  // Constructor.
45  QPRasterMap(bool isARGB = false);
46 
47  // Destructor.
48  ~QPRasterMap();
49 
50  // Implements QwtColorMap::copy().
51  QwtColorMap* copy() const;
52 
53  // Implements QwtColorMap::rgb().
54  QRgb rgb(const QwtDoubleInterval& interval, double value) const;
55 
56  // Implements QwtColorMap::colorIndex().
57  unsigned char colorIndex(const QwtDoubleInterval& intv, double val) const;
58 
59  // Sets whether the data format is argb or not.
60  void setIsARGB(bool argb);
61 
62 private:
63  // Whether the value is an rgb or an argb.
64  bool m_isARGB;
65 };
66 
67 
68 // Implementation of RasterPlot for Qwt plotter.
69 class QPRasterPlot : public QPPlotItem, public RasterPlot,
70  public QwtPlotSpectrogram {
71 public:
72  // Static //
73 
74  // Convenient access to class name (QPRasterPlot).
75  static const casacore::String CLASS_NAME;
76 
77 
78  // Non-Static //
79 
80  // Constructor which takes the data, optional format and title.
81  QPRasterPlot(PlotRasterDataPtr data,
82  PlotRasterData::Format format = PlotRasterData::RGB32,
83  const casacore::String& title = "Qwt Raster Plot");
84 
85  // Copy constructor for generic RasterPlot.
86  QPRasterPlot(const RasterPlot& copy);
87 
88  // Destructor.
89  ~QPRasterPlot();
90 
91 
92  // Include overloaded methods.
93  using Plot::setLine;
94 
95 
96  // PlotItem Methods //
97 
98  // Implements PlotItem::isValid().
99  bool isValid() const;
100 
101  // Implements PlotItem::drawCount(). This returns the number of points
102  // that are needed to fill in the raster plot in the current state of the
103  // canvas it is attached to.
104  unsigned int drawCount() const;
105 
106 
107  // QwtPlotItem Methods //
108 
109  // Overrides QwtPlotItem::itemChanged() to call QPPlotItem's definition
110  // rather than QwtPlotSpectrogram's. (Multiple inheritance trickery.)
111  void itemChanged();
112 
113 
114  // QPPlotItem Methods //
115 
116  // Overrides QwtPlotSpectrogram::boundingRect().
117  QwtDoubleRect boundingRect() const;
118 
119 #if QWT_VERSION < 0x060000
120  // Overrides QwtPlotSpectrogram::legendItem().
121  QWidget* legendItem() const;
122 #endif
123 
124  // Plot Methods //
125 
126  // Implements Plot::dataChanged().
127  void dataChanged() { itemChanged(); }
128 
129  // Implements Plot::linesShown().
130  bool linesShown() const;
131 
132  // Implements Plot::setLinesShown().
133  void setLinesShown(bool show = true);
134 
135  // Implements Plot::line().
136  PlotLinePtr line() const;
137 
138  // Implements Plot::setLine().
139  void setLine(const PlotLine& line);
140 
141 
142  // RasterPlot Methods //
143 
144  // Implements RasterPlot::rasterData().
145  PlotRasterDataPtr rasterData() const;
146 
147  // Implements RasterPlot::dataFormat().
148  PlotRasterData::Format dataFormat() const;
149 
150  // Implements RasterPlot::setDataFormat().
151  void setDataFormat(PlotRasterData::Format f);
152 
153  // Implements RasterPlot::dataOrigin().
154  PlotRasterData::Origin dataOrigin() const;
155 
156  // Implements RasterPlot::setDataOrigin().
157  void setDataOrigin(PlotRasterData::Origin o);
158 
159  // Implements RasterPlot::setXRange().
160  void setXRange(double from, double to);
161 
162  // Implements RasterPlot::setYRange().
163  void setYRange(double from, double to);
164 
165  // Implements RasterPlot::contourLines().
166  std::vector<double> contourLines() const;
167 
168  // Implements RasterPlot::setContourLines().
169  void setContourLines(const std::vector<double>& lines);
170 
171 protected:
172  // QPPlotItem Methods //
173 
174  // Implements QPPlotItem::className().
175  const casacore::String& className() const { return CLASS_NAME; }
176 
177  // Implements QPLayerItem::draw_().
178 #if QWT_VERSION >= 0x060000
179  void draw_(QPainter* painter, const QwtScaleMap& xMap,
180  const QwtScaleMap& yMap, const QRectF& canvasRect,
181  unsigned int drawIndex, unsigned int drawCount) const;
182 #else
183  void draw_(QPainter* painter, const QwtScaleMap& xMap,
184  const QwtScaleMap& yMap, const QRect& canvasRect,
185  unsigned int drawIndex, unsigned int drawCount) const;
186 #endif
187 
188 private:
189 
190  QPRasterData m_data; // Data
191  PlotRasterData::Format m_format; // casacore::Data format
192 #if QWT_VERSION >= 0x060000
193  QwtLinearColorMap* m_spectMap; // Spectrogram color map
194  QPRasterMap* m_rasterMap; // Raster color map
195 
196  QRectF totalArea() const;
197 
198 #else
199  QwtLinearColorMap m_spectMap; // Spectrogram color map
200  QPRasterMap m_rasterMap; // Raster color map
201 
202  // Returns the rectangle in screen pixel coordinates that will contain the
203  // entire raster image.
204  QRect totalArea() const;
205 
206 #endif
207 
208  // Converts between Qt's image format and CASA's.
209  // <group>
210  static QImage::Format format(PlotRasterData::Format f) {
211  switch(f) {
212  case PlotRasterData::RGB32: return QImage::Format_RGB32;
213  case PlotRasterData::ARGB32: return QImage::Format_ARGB32;
214 
215  default: return QImage::Format_Invalid;
216  }
217  }
218  static PlotRasterData::Format format(QImage::Format f) {
219  switch(f) {
220  case QImage::Format_RGB32: return PlotRasterData::RGB32;
221  case QImage::Format_ARGB32: return PlotRasterData::ARGB32;
222 
223  default: return PlotRasterData::SPECTROGRAM;
224  }
225  }
226  // </group>
227 };
228 
229 }
230 
231 #endif
232 
233 #endif /*QPRASTERPLOT_H_*/
StatsData< AccumType > copy(const StatsData< AccumType > &stats)
casacore::CountedPtr< PlotLine > PlotLinePtr
Definition: PlotOptions.h:446
void show(const variant &v)
ABSTRACT CLASSES Deliberately vague to be general enough to allow for many different types of data
Definition: PlotData.h:48
virtual void setYRange(double from, double to)=0
Sets the range of y.
Origin
casacore::Data for raster plots, which can be thought of as three-dimensional.
Definition: PlotData.h:263
virtual void setXRange(double from, double to)=0
Sets the range of x.
casacore::String m_format
Tracker text format.
Definition: PlotTool.h:585
String: the storage and methods of handling collections of characters.
Definition: String.h:223
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
virtual void setLine(const PlotLine &line)=0
Sets the plot lines to the given line.