casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
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 #include <casa/namespace.h>
00040 using namespace std;
00041 
00042 namespace casa {
00043 
00044 // Implementation of QwtColorMap that just returns the value as a color.
00045 class QPRasterMap : public QwtColorMap {
00046 public:
00047     // Constructor.
00048     QPRasterMap(bool isARGB = false);
00049     
00050     // Destructor.
00051     ~QPRasterMap();
00052 
00053     // Implements QwtColorMap::copy().
00054     QwtColorMap* copy() const;
00055     
00056     // Implements QwtColorMap::rgb().
00057     QRgb rgb(const QwtDoubleInterval& interval, double value) const;
00058     
00059     // Implements QwtColorMap::colorIndex().
00060     unsigned char colorIndex(const QwtDoubleInterval& intv, double val) const;
00061     
00062     // Sets whether the data format is argb or not.
00063     void setIsARGB(bool argb);
00064     
00065 private:
00066     // Whether the value is an rgb or an argb.
00067     bool m_isARGB;
00068 };
00069 
00070 
00071 // Implementation of RasterPlot for Qwt plotter.
00072 class QPRasterPlot : public QPPlotItem, public RasterPlot,
00073                      public QwtPlotSpectrogram {
00074 public:
00075     // Static //
00076     
00077     // Convenient access to class name (QPRasterPlot).
00078     static const String CLASS_NAME;
00079     
00080     
00081     // Non-Static //
00082     
00083     // Constructor which takes the data, optional format and title.
00084     QPRasterPlot(PlotRasterDataPtr data,
00085                  PlotRasterData::Format format = PlotRasterData::RGB32,
00086                  const String& title = "Qwt Raster Plot");
00087     
00088     // Copy constructor for generic RasterPlot.
00089     QPRasterPlot(const RasterPlot& copy);
00090     
00091     // Destructor.
00092     ~QPRasterPlot();
00093     
00094     
00095     // Include overloaded methods.    
00096     using Plot::setLine;
00097     
00098     
00099     // PlotItem Methods //
00100     
00101     // Implements PlotItem::isValid().
00102     bool isValid() const;
00103     
00104     // Implements PlotItem::drawCount().  This returns the number of points
00105     // that are needed to fill in the raster plot in the current state of the
00106     // canvas it is attached to.
00107     unsigned int drawCount() const;
00108 
00109     
00110     // QwtPlotItem Methods //
00111     
00112     // Overrides QwtPlotItem::itemChanged() to call QPPlotItem's definition
00113     // rather than QwtPlotSpectrogram's.  (Multiple inheritance trickery.)
00114     void itemChanged();
00115     
00116     
00117     // QPPlotItem Methods //
00118 
00119     // Overrides QwtPlotSpectrogram::boundingRect().
00120     QwtDoubleRect boundingRect() const;
00121     
00122     // Overrides QwtPlotSpectrogram::legendItem().
00123     QWidget* legendItem() const;
00124     
00125     
00126     // Plot Methods //
00127     
00128     // Implements Plot::dataChanged().
00129     void dataChanged() { itemChanged(); }
00130     
00131     // Implements Plot::linesShown().
00132     bool linesShown() const;
00133     
00134     // Implements Plot::setLinesShown().
00135     void setLinesShown(bool show = true);
00136     
00137     // Implements Plot::line().
00138     PlotLinePtr line() const;
00139     
00140     // Implements Plot::setLine().
00141     void setLine(const PlotLine& line);
00142 
00143     
00144     // RasterPlot Methods //
00145     
00146     // Implements RasterPlot::rasterData().
00147     PlotRasterDataPtr rasterData() const;
00148     
00149     // Implements RasterPlot::dataFormat().
00150     PlotRasterData::Format dataFormat() const;
00151     
00152     // Implements RasterPlot::setDataFormat().
00153     void setDataFormat(PlotRasterData::Format f);
00154     
00155     // Implements RasterPlot::dataOrigin().
00156     PlotRasterData::Origin dataOrigin() const;
00157     
00158     // Implements RasterPlot::setDataOrigin().
00159     void setDataOrigin(PlotRasterData::Origin o);
00160     
00161     // Implements RasterPlot::setXRange().
00162     void setXRange(double from, double to);
00163     
00164     // Implements RasterPlot::setYRange().
00165     void setYRange(double from, double to);
00166     
00167     // Implements RasterPlot::contourLines().
00168     vector<double> contourLines() const;
00169     
00170     // Implements RasterPlot::setContourLines().
00171     void setContourLines(const vector<double>& lines);
00172     
00173 protected:
00174     // QPPlotItem Methods //
00175     
00176     // Implements QPPlotItem::className().
00177     const String& className() const { return CLASS_NAME; }
00178     
00179     // Implements QPLayerItem::draw_().
00180     void draw_(QPainter* painter, const QwtScaleMap& xMap,
00181               const QwtScaleMap& yMap, const QRect& canvasRect,
00182               unsigned int drawIndex, unsigned int drawCount) const;
00183     
00184 private:
00185     QPRasterData m_data;                   // Data
00186     PlotRasterData::Format m_format;       // Data format
00187     QwtLinearColorMap m_spectMap;          // Spectrogram color map
00188     QPRasterMap m_rasterMap;               // Raster color map
00189     
00190     
00191     // Returns the rectangle in screen pixel coordinates that will contain the
00192     // entire raster image.
00193     QRect totalArea() const;
00194     
00195     // Converts between Qt's image format and CASA's.
00196     // <group>
00197     static QImage::Format format(PlotRasterData::Format f) {
00198         switch(f) {
00199         case PlotRasterData::RGB32: return QImage::Format_RGB32;
00200         case PlotRasterData::ARGB32: return QImage::Format_ARGB32;
00201         
00202         default: return QImage::Format_Invalid;
00203         }
00204     }    
00205     static PlotRasterData::Format format(QImage::Format f) {
00206         switch(f) {
00207         case QImage::Format_RGB32:  return PlotRasterData::RGB32;
00208         case QImage::Format_ARGB32: return PlotRasterData::ARGB32;
00209         
00210         default: return PlotRasterData::SPECTROGRAM;
00211         }
00212     }
00213     // </group>
00214 };
00215 
00216 }
00217 
00218 #endif
00219 
00220 #endif /*QPRASTERPLOT_H_*/