Quantum GIS API Documentation  master-693a1fe
src/core/raster/qgsrasterinterface.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     qgsrasterface.h - Internal raster processing modules interface
00003      --------------------------------------
00004     Date                 : Jun 21, 2012
00005     Copyright            : (C) 2012 by Radim Blazek
00006     email                : radim dot blazek at gmail dot com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef QGSRASTERINTERFACE_H
00019 #define QGSRASTERINTERFACE_H
00020 
00021 #include <limits>
00022 
00023 #include <QCoreApplication> // for tr()
00024 #include <QImage>
00025 
00026 #include "qgslogger.h"
00027 #include "qgsrasterbandstats.h"
00028 #include "qgsrasterblock.h"
00029 #include "qgsrasterhistogram.h"
00030 #include "qgsrectangle.h"
00031 
00035 class CORE_EXPORT QgsRasterInterface
00036 {
00037     Q_DECLARE_TR_FUNCTIONS( QgsRasterInterface );
00038 
00039   public:
00041     enum Capability
00042     {
00043       NoCapabilities =          0,
00044       Size =                    1 << 1, // original data source size (and thus resolution) is known, it is not always available, for example for WMS
00045       Create =                  1 << 2, // create new datasets
00046       Remove =                  1 << 3, // delete datasets
00047       BuildPyramids =           1 << 4, // supports building of pyramids (overviews)
00048       Identify =                1 << 5, // at least one identify format supported
00049       IdentifyValue =           1 << 6, // numerical values
00050       IdentifyText =            1 << 7, // WMS text
00051       IdentifyHtml =            1 << 8, // WMS HTML
00052       IdentifyFeature =         1 << 9  // WMS GML -> feature
00053     };
00054 
00055     QgsRasterInterface( QgsRasterInterface * input = 0 );
00056 
00057     virtual ~QgsRasterInterface();
00058 
00060     virtual QgsRasterInterface *clone() const = 0;
00061 
00063     virtual int capabilities() const
00064     {
00065       return QgsRasterInterface::NoCapabilities;
00066     }
00067 
00071     QString capabilitiesString() const;
00072 
00074     virtual QGis::DataType dataType( int bandNo ) const = 0;
00075 
00078     virtual QGis::DataType srcDataType( int bandNo ) const { if ( mInput ) return mInput->srcDataType( bandNo ); else return QGis::UnknownDataType; };
00079 
00084     virtual QgsRectangle extent() { if ( mInput ) return mInput->extent(); else return QgsRectangle(); }
00085 
00086     int dataTypeSize( int bandNo ) { return QgsRasterBlock::typeSize( dataType( bandNo ) ); }
00087 
00089     virtual int bandCount() const = 0;
00090 
00092     virtual int xBlockSize() const { if ( mInput ) return mInput->xBlockSize(); else return 0; }
00093     virtual int yBlockSize() const { if ( mInput ) return mInput->yBlockSize(); else return 0; }
00094 
00096     virtual int xSize() const { if ( mInput ) return mInput->xSize(); else return 0; }
00097     virtual int ySize() const { if ( mInput ) return mInput->ySize(); else return 0; }
00098 
00100     virtual QString  generateBandName( int theBandNumber ) const
00101     {
00102       return tr( "Band" ) + QString( " %1" ) .arg( theBandNumber,  1 + ( int ) log10(( float ) bandCount() ), 10, QChar( '0' ) );
00103     }
00104 
00113     virtual QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height ) = 0;
00114 
00117     virtual bool setInput( QgsRasterInterface* input ) { mInput = input; return true; }
00118 
00120     virtual QgsRasterInterface * input() const { return mInput; }
00121 
00123     virtual bool on() const { return mOn; }
00124 
00126     virtual void setOn( bool on ) { mOn = on; }
00127 
00132     virtual const QgsRasterInterface *srcInput() const
00133     {
00134       QgsDebugMsg( "Entered" );
00135       return mInput ? mInput->srcInput() : this;
00136     }
00137     virtual QgsRasterInterface * srcInput()
00138     {
00139       QgsDebugMsg( "Entered" );
00140       return mInput ? mInput->srcInput() : this;
00141     }
00142 
00150     virtual QgsRasterBandStats bandStatistics( int theBandNo,
00151         int theStats = QgsRasterBandStats::All,
00152         const QgsRectangle & theExtent = QgsRectangle(),
00153         int theSampleSize = 0 );
00154 
00158     virtual bool hasStatistics( int theBandNo,
00159                                 int theStats = QgsRasterBandStats::All,
00160                                 const QgsRectangle & theExtent = QgsRectangle(),
00161                                 int theSampleSize = 0 );
00162 
00174     virtual QgsRasterHistogram histogram( int theBandNo,
00175                                           int theBinCount = 0,
00176                                           double theMinimum = std::numeric_limits<double>::quiet_NaN(),
00177                                           double theMaximum = std::numeric_limits<double>::quiet_NaN(),
00178                                           const QgsRectangle & theExtent = QgsRectangle(),
00179                                           int theSampleSize = 0,
00180                                           bool theIncludeOutOfRange = false );
00181 
00185     virtual bool hasHistogram( int theBandNo,
00186                                int theBinCount,
00187                                double theMinimum = std::numeric_limits<double>::quiet_NaN(),
00188                                double theMaximum = std::numeric_limits<double>::quiet_NaN(),
00189                                const QgsRectangle & theExtent = QgsRectangle(),
00190                                int theSampleSize = 0,
00191                                bool theIncludeOutOfRange = false );
00192 
00202     virtual void cumulativeCut( int theBandNo,
00203                                 double theLowerCount,
00204                                 double theUpperCount,
00205                                 double &theLowerValue,
00206                                 double &theUpperValue,
00207                                 const QgsRectangle & theExtent = QgsRectangle(),
00208                                 int theSampleSize = 0 );
00209 
00211     virtual void writeXML( QDomDocument& doc, QDomElement& parentElem ) const { Q_UNUSED( doc ); Q_UNUSED( parentElem ); }
00213     virtual void readXML( const QDomElement& filterElem ) { Q_UNUSED( filterElem ); }
00214 
00215   protected:
00216     // QgsRasterInterface used as input
00217     QgsRasterInterface* mInput;
00218 
00220     QList <QgsRasterBandStats> mStatistics;
00221 
00223     QList <QgsRasterHistogram> mHistograms;
00224 
00225     // On/off state, if off, it does not do anything, replicates input
00226     bool mOn;
00227 
00231     void initHistogram( QgsRasterHistogram &theHistogram, int theBandNo,
00232                         int theBinCount = 0,
00233                         double theMinimum = std::numeric_limits<double>::quiet_NaN(),
00234                         double theMaximum = std::numeric_limits<double>::quiet_NaN(),
00235                         const QgsRectangle & theExtent = QgsRectangle(),
00236                         int theSampleSize = 0,
00237                         bool theIncludeOutOfRange = false );
00238 
00240     void initStatistics( QgsRasterBandStats &theStatistics, int theBandNo,
00241                          int theStats = QgsRasterBandStats::All,
00242                          const QgsRectangle & theExtent = QgsRectangle(),
00243                          int theBinCount = 0 );
00244 };
00245 
00246 #endif
00247 
00248 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines