QPRasterPlot.h

Go to the documentation of this file.
00001 //# QPRasterPlot.h: Qwt implementation of generic RasterPlot class.
00002 //# Copyright (C) 2008
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id: $
00027 #ifndef QPRASTERPLOT_H_
00028 #define QPRASTERPLOT_H_
00029 
00030 #ifdef AIPS_HAS_QWT
00031 
00032 #include <graphics/GenericPlotter/Plot.h>
00033 #include <casaqt/QwtPlotter/QPData.h>
00034 #include <casaqt/QwtPlotter/QPPlotItem.qo.h>
00035 
00036 #include <qwt_color_map.h>
00037 #include <qwt_plot_spectrogram.h>
00038 
00039 namespace casa {
00040 
00041 // Implementation of QwtColorMap that just returns the value as a color.
00042 class QPRasterMap : public QwtColorMap {
00043 public:
00044     // Constructor.
00045     QPRasterMap(bool isARGB = false);
00046     
00047     // Destructor.
00048     ~QPRasterMap();
00049 
00050     // Implements QwtColorMap::copy().
00051     QwtColorMap* copy() const;
00052     
00053     // Implements QwtColorMap::rgb().
00054     QRgb rgb(const QwtDoubleInterval& interval, double value) const;
00055     
00056     // Implements QwtColorMap::colorIndex().
00057     unsigned char colorIndex(const QwtDoubleInterval& intv, double val) const;
00058     
00059     // Sets whether the data format is argb or not.
00060     void setIsARGB(bool argb);
00061     
00062 private:
00063     // Whether the value is an rgb or an argb.
00064     bool m_isARGB;
00065 };
00066 
00067 
00068 // Implementation of RasterPlot for Qwt plotter.
00069 class QPRasterPlot : public QPPlotItem, public RasterPlot,
00070                      public QwtPlotSpectrogram {
00071 public:
00072     // Static //
00073     
00074     // Convenient access to class name (QPRasterPlot).
00075     static const String CLASS_NAME;
00076     
00077     
00078     // Non-Static //
00079     
00080     // Constructor which takes the data, optional format and title.
00081     QPRasterPlot(PlotRasterDataPtr data,
00082                  PlotRasterData::Format format = PlotRasterData::RGB32,
00083                  const String& title = "Qwt Raster Plot");
00084     
00085     // Copy constructor for generic RasterPlot.
00086     QPRasterPlot(const RasterPlot& copy);
00087     
00088     // Destructor.
00089     ~QPRasterPlot();
00090     
00091     
00092     // Include overloaded methods.    
00093     using Plot::setLine;
00094     
00095     
00096     // PlotItem Methods //
00097     
00098     // Implements PlotItem::isValid().
00099     bool isValid() const;
00100     
00101     // Implements PlotItem::drawCount().  This returns the number of points
00102     // that are needed to fill in the raster plot in the current state of the
00103     // canvas it is attached to.
00104     unsigned int drawCount() const;
00105 
00106     
00107     // QwtPlotItem Methods //
00108     
00109     // Overrides QwtPlotItem::itemChanged() to call QPPlotItem's definition
00110     // rather than QwtPlotSpectrogram's.  (Multiple inheritance trickery.)
00111     void itemChanged();
00112     
00113     
00114     // QPPlotItem Methods //
00115 
00116     // Overrides QwtPlotSpectrogram::boundingRect().
00117     QwtDoubleRect boundingRect() const;
00118     
00119 #if QWT_VERSION < 0x060000
00120     // Overrides QwtPlotSpectrogram::legendItem().
00121     QWidget* legendItem() const;
00122 #endif 
00123     
00124     // Plot Methods //
00125     
00126     // Implements Plot::dataChanged().
00127     void dataChanged() { itemChanged(); }
00128     
00129     // Implements Plot::linesShown().
00130     bool linesShown() const;
00131     
00132     // Implements Plot::setLinesShown().
00133     void setLinesShown(bool show = true);
00134     
00135     // Implements Plot::line().
00136     PlotLinePtr line() const;
00137     
00138     // Implements Plot::setLine().
00139     void setLine(const PlotLine& line);
00140 
00141     
00142     // RasterPlot Methods //
00143     
00144     // Implements RasterPlot::rasterData().
00145     PlotRasterDataPtr rasterData() const;
00146     
00147     // Implements RasterPlot::dataFormat().
00148     PlotRasterData::Format dataFormat() const;
00149     
00150     // Implements RasterPlot::setDataFormat().
00151     void setDataFormat(PlotRasterData::Format f);
00152     
00153     // Implements RasterPlot::dataOrigin().
00154     PlotRasterData::Origin dataOrigin() const;
00155     
00156     // Implements RasterPlot::setDataOrigin().
00157     void setDataOrigin(PlotRasterData::Origin o);
00158     
00159     // Implements RasterPlot::setXRange().
00160     void setXRange(double from, double to);
00161     
00162     // Implements RasterPlot::setYRange().
00163     void setYRange(double from, double to);
00164     
00165     // Implements RasterPlot::contourLines().
00166     vector<double> contourLines() const;
00167     
00168     // Implements RasterPlot::setContourLines().
00169     void setContourLines(const vector<double>& lines);
00170     
00171 protected:
00172     // QPPlotItem Methods //
00173     
00174     // Implements QPPlotItem::className().
00175     const String& className() const { return CLASS_NAME; }
00176     
00177     // Implements QPLayerItem::draw_().
00178 #if QWT_VERSION >= 0x060000
00179     void draw_(QPainter* painter, const QwtScaleMap& xMap,
00180               const QwtScaleMap& yMap, const QRectF& canvasRect,
00181               unsigned int drawIndex, unsigned int drawCount) const;
00182 #else
00183     void draw_(QPainter* painter, const QwtScaleMap& xMap,
00184               const QwtScaleMap& yMap, const QRect& canvasRect,
00185               unsigned int drawIndex, unsigned int drawCount) const;
00186 #endif
00187     
00188 private:
00189 
00190     QPRasterData m_data;                   // Data
00191     PlotRasterData::Format m_format;       // Data format
00192 #if QWT_VERSION >= 0x060000
00193     QwtLinearColorMap* m_spectMap;          // Spectrogram color map
00194     QPRasterMap* m_rasterMap;               // Raster color map
00195     
00196     QRectF totalArea() const;
00197     
00198 #else
00199     QwtLinearColorMap m_spectMap;          // Spectrogram color map
00200     QPRasterMap m_rasterMap;               // Raster color map
00201     
00202     // Returns the rectangle in screen pixel coordinates that will contain the
00203     // entire raster image.
00204     QRect totalArea() const;
00205     
00206 #endif
00207     
00208     // Converts between Qt's image format and CASA's.
00209     // <group>
00210     static QImage::Format format(PlotRasterData::Format f) {
00211         switch(f) {
00212         case PlotRasterData::RGB32: return QImage::Format_RGB32;
00213         case PlotRasterData::ARGB32: return QImage::Format_ARGB32;
00214         
00215         default: return QImage::Format_Invalid;
00216         }
00217     }    
00218     static PlotRasterData::Format format(QImage::Format f) {
00219         switch(f) {
00220         case QImage::Format_RGB32:  return PlotRasterData::RGB32;
00221         case QImage::Format_ARGB32: return PlotRasterData::ARGB32;
00222         
00223         default: return PlotRasterData::SPECTROGRAM;
00224         }
00225     }
00226     // </group>
00227 };
00228 
00229 }
00230 
00231 #endif
00232 
00233 #endif /*QPRASTERPLOT_H_*/
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1