GDAL
vrtdataset.h
00001 /******************************************************************************
00002  * $Id: vrtdataset.h 29294 2015-06-05 08:52:15Z rouault $
00003  *
00004  * Project:  Virtual GDAL Datasets
00005  * Purpose:  Declaration of virtual gdal dataset classes.
00006  * Author:   Frank Warmerdam, warmerdam@pobox.com
00007  *
00008  ******************************************************************************
00009  * Copyright (c) 2001, Frank Warmerdam <warmerdam@pobox.com>
00010  * Copyright (c) 2007-2013, Even Rouault <even dot rouault at mines-paris dot org>
00011  *
00012  * Permission is hereby granted, free of charge, to any person obtaining a
00013  * copy of this software and associated documentation files (the "Software"),
00014  * to deal in the Software without restriction, including without limitation
00015  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00016  * and/or sell copies of the Software, and to permit persons to whom the
00017  * Software is furnished to do so, subject to the following conditions:
00018  *
00019  * The above copyright notice and this permission notice shall be included
00020  * in all copies or substantial portions of the Software.
00021  *
00022  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00023  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00024  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00025  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00026  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00027  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00028  * DEALINGS IN THE SOFTWARE.
00029  ****************************************************************************/
00030 
00031 #ifndef VIRTUALDATASET_H_INCLUDED
00032 #define VIRTUALDATASET_H_INCLUDED
00033 
00034 #include "gdal_priv.h"
00035 #include "gdal_pam.h"
00036 #include "gdal_vrt.h"
00037 #include "cpl_hash_set.h"
00038 
00039 int VRTApplyMetadata( CPLXMLNode *, GDALMajorObject * );
00040 CPLXMLNode *VRTSerializeMetadata( GDALMajorObject * );
00041 
00042 #if 0
00043 int VRTWarpedOverviewTransform( void *pTransformArg, int bDstToSrc,
00044                                 int nPointCount,
00045                                 double *padfX, double *padfY, double *padfZ,
00046                                 int *panSuccess );
00047 void* VRTDeserializeWarpedOverviewTransformer( CPLXMLNode *psTree );
00048 #endif
00049 
00050 /************************************************************************/
00051 /*                          VRTOverviewInfo()                           */
00052 /************************************************************************/
00053 class VRTOverviewInfo
00054 {
00055 public:
00056     CPLString       osFilename;
00057     int             nBand;
00058     GDALRasterBand *poBand;
00059     int             bTriedToOpen;
00060     
00061     VRTOverviewInfo() : poBand(NULL), bTriedToOpen(FALSE) {}
00062     ~VRTOverviewInfo() {
00063         if( poBand == NULL ) 
00064             /* do nothing */;
00065         else if( poBand->GetDataset()->GetShared() )
00066             GDALClose( (GDALDatasetH) poBand->GetDataset() );
00067         else
00068             poBand->GetDataset()->Dereference();
00069     }
00070 };
00071 
00072 
00073 /************************************************************************/
00074 /*                              VRTSource                               */
00075 /************************************************************************/
00076 
00077 class CPL_DLL VRTSource 
00078 {
00079 public:
00080     virtual ~VRTSource();
00081 
00082     virtual CPLErr  RasterIO( int nXOff, int nYOff, int nXSize, int nYSize, 
00083                               void *pData, int nBufXSize, int nBufYSize, 
00084                               GDALDataType eBufType, 
00085                               GSpacing nPixelSpace, GSpacing nLineSpace,
00086                               GDALRasterIOExtraArg* psExtraArg ) = 0;
00087 
00088     virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess ) = 0;
00089     virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess ) = 0;
00090     virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax ) = 0;
00091     virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
00092                                       int bApproxOK, 
00093                                       double *pdfMin, double *pdfMax, 
00094                                       double *pdfMean, double *pdfStdDev,
00095                                       GDALProgressFunc pfnProgress, void *pProgressData ) = 0;
00096     virtual CPLErr  GetHistogram( int nXSize, int nYSize,
00097                                   double dfMin, double dfMax,
00098                                   int nBuckets, GUIntBig * panHistogram,
00099                                   int bIncludeOutOfRange, int bApproxOK,
00100                                   GDALProgressFunc pfnProgress, void *pProgressData ) = 0;
00101 
00102     virtual CPLErr  XMLInit( CPLXMLNode *psTree, const char * ) = 0;
00103     virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ) = 0;
00104     
00105     virtual void   GetFileList(char*** ppapszFileList, int *pnSize,
00106                                int *pnMaxSize, CPLHashSet* hSetFiles);
00107 
00108     virtual int    IsSimpleSource() { return FALSE; }
00109 };
00110 
00111 typedef VRTSource *(*VRTSourceParser)(CPLXMLNode *, const char *);
00112 
00113 VRTSource *VRTParseCoreSources( CPLXMLNode *psTree, const char * );
00114 VRTSource *VRTParseFilterSources( CPLXMLNode *psTree, const char * );
00115 
00116 /************************************************************************/
00117 /*                              VRTDataset                              */
00118 /************************************************************************/
00119 
00120 class VRTRasterBand;
00121 
00122 class CPL_DLL VRTDataset : public GDALDataset
00123 {
00124     friend class VRTRasterBand;
00125 
00126     char           *pszProjection;
00127 
00128     int            bGeoTransformSet;
00129     double         adfGeoTransform[6];
00130 
00131     int           nGCPCount;
00132     GDAL_GCP      *pasGCPList;
00133     char          *pszGCPProjection;
00134 
00135     int            bNeedsFlush;
00136     int            bWritable;
00137     
00138     char          *pszVRTPath;
00139 
00140     VRTRasterBand *poMaskBand;
00141 
00142     int            bCompatibleForDatasetIO;
00143     int            CheckCompatibleForDatasetIO();
00144 
00145   protected:
00146     virtual int         CloseDependentDatasets();
00147 
00148   public:
00149                  VRTDataset(int nXSize, int nYSize);
00150                 ~VRTDataset();
00151 
00152     void          SetNeedsFlush() { bNeedsFlush = TRUE; }
00153     virtual void  FlushCache();
00154     
00155     void SetWritable(int bWritable) { this->bWritable = bWritable; }
00156 
00157     virtual CPLErr          CreateMaskBand( int nFlags );
00158     void SetMaskBand(VRTRasterBand* poMaskBand);
00159 
00160     virtual const char *GetProjectionRef(void);
00161     virtual CPLErr SetProjection( const char * );
00162     virtual CPLErr GetGeoTransform( double * );
00163     virtual CPLErr SetGeoTransform( double * );
00164 
00165     virtual CPLErr SetMetadata( char **papszMD, const char *pszDomain = "" );
00166     virtual CPLErr SetMetadataItem( const char *pszName, const char *pszValue,
00167                                     const char *pszDomain = "" );
00168 
00169     virtual int    GetGCPCount();
00170     virtual const char *GetGCPProjection();
00171     virtual const GDAL_GCP *GetGCPs();
00172     virtual CPLErr SetGCPs( int nGCPCount, const GDAL_GCP *pasGCPList,
00173                             const char *pszGCPProjection );
00174 
00175     virtual CPLErr AddBand( GDALDataType eType, 
00176                             char **papszOptions=NULL );
00177                             
00178     virtual char      **GetFileList();
00179 
00180     virtual CPLErr  IRasterIO( GDALRWFlag eRWFlag,
00181                                int nXOff, int nYOff, int nXSize, int nYSize,
00182                                void * pData, int nBufXSize, int nBufYSize,
00183                                GDALDataType eBufType,
00184                                int nBandCount, int *panBandMap,
00185                                GSpacing nPixelSpace, GSpacing nLineSpace,
00186                                GSpacing nBandSpace,
00187                                GDALRasterIOExtraArg* psExtraArg);
00188 
00189     virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath);
00190     virtual CPLErr      XMLInit( CPLXMLNode *, const char * );
00191 
00192     /* Used by PDF driver for example */
00193     GDALDataset*        GetSingleSimpleSource();
00194     
00195     void                UnsetPreservedRelativeFilenames();
00196  
00197     static int          Identify( GDALOpenInfo * );
00198     static GDALDataset *Open( GDALOpenInfo * );
00199     static GDALDataset *OpenXML( const char *, const char * = NULL, GDALAccess eAccess = GA_ReadOnly );
00200     static GDALDataset *Create( const char * pszName,
00201                                 int nXSize, int nYSize, int nBands,
00202                                 GDALDataType eType, char ** papszOptions );
00203     static CPLErr       Delete( const char * pszFilename );
00204 };
00205 
00206 /************************************************************************/
00207 /*                           VRTWarpedDataset                           */
00208 /************************************************************************/
00209 
00210 class GDALWarpOperation;
00211 class VRTWarpedRasterBand;
00212 
00213 class CPL_DLL VRTWarpedDataset : public VRTDataset
00214 {
00215     int               nBlockXSize;
00216     int               nBlockYSize;
00217     GDALWarpOperation *poWarper;
00218 
00219     int               nOverviewCount;
00220     VRTWarpedDataset **papoOverviews;
00221     int               nSrcOvrLevel;
00222     
00223     void              CreateImplicitOverviews();
00224 
00225     friend class VRTWarpedRasterBand;
00226 
00227   protected:
00228     virtual int         CloseDependentDatasets();
00229 
00230 public:
00231                       VRTWarpedDataset( int nXSize, int nYSize );
00232                      ~VRTWarpedDataset();
00233 
00234     CPLErr            Initialize( /* GDALWarpOptions */ void * );
00235 
00236     virtual CPLErr IBuildOverviews( const char *, int, int *,
00237                                     int, int *, GDALProgressFunc, void * );
00238     
00239     virtual CPLErr SetMetadataItem( const char *pszName, const char *pszValue,
00240                                     const char *pszDomain = "" );
00241 
00242     virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00243     virtual CPLErr    XMLInit( CPLXMLNode *, const char * );
00244 
00245     virtual CPLErr AddBand( GDALDataType eType, 
00246                             char **papszOptions=NULL );
00247                             
00248     virtual char      **GetFileList();
00249     
00250     CPLErr            ProcessBlock( int iBlockX, int iBlockY );
00251 
00252     void              GetBlockSize( int *, int * );
00253 };
00254 
00255 /************************************************************************/
00256 /*                            VRTRasterBand                             */
00257 /*                                                                      */
00258 /*      Provides support for all the various kinds of metadata but      */
00259 /*      no raster access.  That is handled by derived classes.          */
00260 /************************************************************************/
00261 
00262 class CPL_DLL VRTRasterBand : public GDALRasterBand
00263 {
00264   protected:
00265     int            bIsMaskBand;
00266 
00267     int            bNoDataValueSet;
00268     int            bHideNoDataValue; // If set to true, will not report the existance of nodata
00269     double         dfNoDataValue;
00270 
00271     GDALColorTable *poColorTable;
00272 
00273     GDALColorInterp eColorInterp;
00274 
00275     char           *pszUnitType;
00276     char           **papszCategoryNames;
00277     
00278     double         dfOffset;
00279     double         dfScale;
00280 
00281     CPLXMLNode    *psSavedHistograms;
00282 
00283     void           Initialize( int nXSize, int nYSize );
00284 
00285     std::vector<VRTOverviewInfo> apoOverviews;
00286 
00287     VRTRasterBand *poMaskBand;
00288 
00289   public:
00290 
00291                     VRTRasterBand();
00292     virtual        ~VRTRasterBand();
00293 
00294     virtual CPLErr         XMLInit( CPLXMLNode *, const char * );
00295     virtual CPLXMLNode *   SerializeToXML( const char *pszVRTPath );
00296 
00297     virtual CPLErr SetNoDataValue( double );
00298     virtual double GetNoDataValue( int *pbSuccess = NULL );
00299 
00300     virtual CPLErr SetColorTable( GDALColorTable * ); 
00301     virtual GDALColorTable *GetColorTable();
00302 
00303     virtual CPLErr SetColorInterpretation( GDALColorInterp );
00304     virtual GDALColorInterp GetColorInterpretation();
00305 
00306     virtual const char *GetUnitType();
00307     CPLErr SetUnitType( const char * ); 
00308 
00309     virtual char **GetCategoryNames();
00310     virtual CPLErr SetCategoryNames( char ** );
00311 
00312     virtual CPLErr SetMetadata( char **papszMD, const char *pszDomain = "" );
00313     virtual CPLErr SetMetadataItem( const char *pszName, const char *pszValue,
00314                                     const char *pszDomain = "" );
00315 
00316     virtual double GetOffset( int *pbSuccess = NULL );
00317     CPLErr SetOffset( double );
00318     virtual double GetScale( int *pbSuccess = NULL );
00319     CPLErr SetScale( double );
00320 
00321     virtual int GetOverviewCount();
00322     virtual GDALRasterBand *GetOverview(int);
00323     
00324     virtual CPLErr  GetHistogram( double dfMin, double dfMax,
00325                           int nBuckets, GUIntBig * panHistogram,
00326                           int bIncludeOutOfRange, int bApproxOK,
00327                           GDALProgressFunc, void *pProgressData );
00328 
00329     virtual CPLErr GetDefaultHistogram( double *pdfMin, double *pdfMax,
00330                                         int *pnBuckets, GUIntBig ** ppanHistogram,
00331                                         int bForce,
00332                                         GDALProgressFunc, void *pProgressData);
00333 
00334     virtual CPLErr SetDefaultHistogram( double dfMin, double dfMax,
00335                                         int nBuckets, GUIntBig *panHistogram );
00336 
00337     CPLErr         CopyCommonInfoFrom( GDALRasterBand * );
00338     
00339     virtual void   GetFileList(char*** ppapszFileList, int *pnSize,
00340                                int *pnMaxSize, CPLHashSet* hSetFiles);
00341     
00342     virtual void   SetDescription( const char * );
00343 
00344     virtual GDALRasterBand *GetMaskBand();
00345     virtual int             GetMaskFlags();
00346 
00347     virtual CPLErr          CreateMaskBand( int nFlags );
00348     
00349     void SetMaskBand(VRTRasterBand* poMaskBand);
00350 
00351     void SetIsMaskBand();
00352 
00353     CPLErr UnsetNoDataValue();
00354 
00355     virtual int         CloseDependentDatasets();
00356 
00357     virtual int         IsSourcedRasterBand() { return FALSE; }
00358 };
00359 
00360 /************************************************************************/
00361 /*                         VRTSourcedRasterBand                         */
00362 /************************************************************************/
00363 
00364 class VRTSimpleSource;
00365 
00366 class CPL_DLL VRTSourcedRasterBand : public VRTRasterBand
00367 {
00368   private:
00369     int            nRecursionCounter;
00370     CPLString      osLastLocationInfo;
00371     char         **papszSourceList;
00372 
00373     void           Initialize( int nXSize, int nYSize );
00374 
00375     int            CanUseSourcesMinMaxImplementations();
00376 
00377   public:
00378     int            nSources;
00379     VRTSource    **papoSources;
00380     int            bEqualAreas;
00381 
00382                    VRTSourcedRasterBand( GDALDataset *poDS, int nBand );
00383                    VRTSourcedRasterBand( GDALDataType eType, 
00384                                          int nXSize, int nYSize );
00385                    VRTSourcedRasterBand( GDALDataset *poDS, int nBand, 
00386                                          GDALDataType eType, 
00387                                          int nXSize, int nYSize );
00388     virtual        ~VRTSourcedRasterBand();
00389 
00390     virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
00391                               void *, int, int, GDALDataType,
00392                               GSpacing nPixelSpace, GSpacing nLineSpace,
00393                               GDALRasterIOExtraArg* psExtraArg);
00394 
00395     virtual char      **GetMetadataDomainList();
00396     virtual const char *GetMetadataItem( const char * pszName,
00397                                          const char * pszDomain = "" );
00398     virtual char      **GetMetadata( const char * pszDomain = "" );
00399     virtual CPLErr      SetMetadata( char ** papszMetadata,
00400                                      const char * pszDomain = "" );
00401     virtual CPLErr      SetMetadataItem( const char * pszName,
00402                                          const char * pszValue,
00403                                          const char * pszDomain = "" );
00404 
00405     virtual CPLErr         XMLInit( CPLXMLNode *, const char * );
00406     virtual CPLXMLNode *   SerializeToXML( const char *pszVRTPath );
00407 
00408     virtual double GetMinimum( int *pbSuccess = NULL );
00409     virtual double GetMaximum(int *pbSuccess = NULL );
00410     virtual CPLErr ComputeRasterMinMax( int bApproxOK, double* adfMinMax );
00411     virtual CPLErr ComputeStatistics( int bApproxOK, 
00412                                       double *pdfMin, double *pdfMax, 
00413                                       double *pdfMean, double *pdfStdDev,
00414                                       GDALProgressFunc pfnProgress, void *pProgressData );
00415     virtual CPLErr  GetHistogram( double dfMin, double dfMax,
00416                                   int nBuckets, GUIntBig * panHistogram,
00417                                   int bIncludeOutOfRange, int bApproxOK,
00418                                   GDALProgressFunc pfnProgress, void *pProgressData );
00419 
00420     CPLErr         AddSource( VRTSource * );
00421     CPLErr         AddSimpleSource( GDALRasterBand *poSrcBand, 
00422                                     int nSrcXOff=-1, int nSrcYOff=-1, 
00423                                     int nSrcXSize=-1, int nSrcYSize=-1, 
00424                                     int nDstXOff=-1, int nDstYOff=-1, 
00425                                     int nDstXSize=-1, int nDstYSize=-1,
00426                                     const char *pszResampling = "near",
00427                                     double dfNoDataValue = VRT_NODATA_UNSET);
00428     CPLErr         AddComplexSource( GDALRasterBand *poSrcBand, 
00429                                      int nSrcXOff=-1, int nSrcYOff=-1, 
00430                                      int nSrcXSize=-1, int nSrcYSize=-1, 
00431                                      int nDstXOff=-1, int nDstYOff=-1, 
00432                                      int nDstXSize=-1, int nDstYSize=-1,
00433                                      double dfScaleOff=0.0, 
00434                                      double dfScaleRatio=1.0,
00435                                      double dfNoDataValue = VRT_NODATA_UNSET,
00436                                      int nColorTableComponent = 0);
00437 
00438     CPLErr         AddMaskBandSource( GDALRasterBand *poSrcBand,
00439                                       int nSrcXOff=-1, int nSrcYOff=-1,
00440                                       int nSrcXSize=-1, int nSrcYSize=-1,
00441                                       int nDstXOff=-1, int nDstYOff=-1,
00442                                       int nDstXSize=-1, int nDstYSize=-1 );
00443 
00444     CPLErr         AddFuncSource( VRTImageReadFunc pfnReadFunc, void *hCBData,
00445                                   double dfNoDataValue = VRT_NODATA_UNSET );
00446 
00447     void           ConfigureSource(VRTSimpleSource *poSimpleSource,
00448                                            GDALRasterBand *poSrcBand,
00449                                            int bAddAsMaskBand,
00450                                            int nSrcXOff, int nSrcYOff,
00451                                            int nSrcXSize, int nSrcYSize,
00452                                            int nDstXOff, int nDstYOff,
00453                                            int nDstXSize, int nDstYSize);
00454 
00455     virtual CPLErr IReadBlock( int, int, void * );
00456     
00457     virtual void   GetFileList(char*** ppapszFileList, int *pnSize,
00458                                int *pnMaxSize, CPLHashSet* hSetFiles);
00459 
00460     virtual int         CloseDependentDatasets();
00461 
00462     virtual int         IsSourcedRasterBand() { return TRUE; }
00463 };
00464 
00465 /************************************************************************/
00466 /*                         VRTWarpedRasterBand                          */
00467 /************************************************************************/
00468 
00469 class CPL_DLL VRTWarpedRasterBand : public VRTRasterBand
00470 {
00471   public:
00472                    VRTWarpedRasterBand( GDALDataset *poDS, int nBand,
00473                                      GDALDataType eType = GDT_Unknown );
00474     virtual        ~VRTWarpedRasterBand();
00475 
00476     virtual CPLErr         XMLInit( CPLXMLNode *, const char * );
00477     virtual CPLXMLNode *   SerializeToXML( const char *pszVRTPath );
00478 
00479     virtual CPLErr IReadBlock( int, int, void * );
00480     virtual CPLErr IWriteBlock( int, int, void * );
00481 
00482     virtual int GetOverviewCount();
00483     virtual GDALRasterBand *GetOverview(int);
00484 };
00485 
00486 /************************************************************************/
00487 /*                         VRTDerivedRasterBand                         */
00488 /************************************************************************/
00489 
00490 class CPL_DLL VRTDerivedRasterBand : public VRTSourcedRasterBand
00491 {
00492 
00493  public:
00494     char *pszFuncName;
00495     GDALDataType eSourceTransferType;
00496 
00497     VRTDerivedRasterBand(GDALDataset *poDS, int nBand);
00498     VRTDerivedRasterBand(GDALDataset *poDS, int nBand, 
00499                          GDALDataType eType, int nXSize, int nYSize);
00500     virtual        ~VRTDerivedRasterBand();
00501 
00502     virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
00503                               void *, int, int, GDALDataType,
00504                               GSpacing nPixelSpace, GSpacing nLineSpace,
00505                               GDALRasterIOExtraArg* psExtraArg );
00506 
00507     static CPLErr AddPixelFunction
00508         (const char *pszFuncName, GDALDerivedPixelFunc pfnPixelFunc);
00509     static GDALDerivedPixelFunc GetPixelFunction(const char *pszFuncName);
00510 
00511     void SetPixelFunctionName(const char *pszFuncName);
00512     void SetSourceTransferType(GDALDataType eDataType);
00513 
00514     virtual CPLErr         XMLInit( CPLXMLNode *, const char * );
00515     virtual CPLXMLNode *   SerializeToXML( const char *pszVRTPath );
00516 
00517 };
00518 
00519 /************************************************************************/
00520 /*                           VRTRawRasterBand                           */
00521 /************************************************************************/
00522 
00523 class RawRasterBand;
00524 
00525 class CPL_DLL VRTRawRasterBand : public VRTRasterBand
00526 {
00527     RawRasterBand  *poRawRaster;
00528 
00529     char           *pszSourceFilename;
00530     int            bRelativeToVRT;
00531 
00532   public:
00533                    VRTRawRasterBand( GDALDataset *poDS, int nBand,
00534                                      GDALDataType eType = GDT_Unknown );
00535     virtual        ~VRTRawRasterBand();
00536 
00537     virtual CPLErr         XMLInit( CPLXMLNode *, const char * );
00538     virtual CPLXMLNode *   SerializeToXML( const char *pszVRTPath );
00539 
00540     virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
00541                               void *, int, int, GDALDataType,
00542                               GSpacing nPixelSpace, GSpacing nLineSpace,
00543                               GDALRasterIOExtraArg* psExtraArg );
00544 
00545     virtual CPLErr IReadBlock( int, int, void * );
00546     virtual CPLErr IWriteBlock( int, int, void * );
00547 
00548     CPLErr         SetRawLink( const char *pszFilename, 
00549                                const char *pszVRTPath,
00550                                int bRelativeToVRT, 
00551                                vsi_l_offset nImageOffset, 
00552                                int nPixelOffset, int nLineOffset, 
00553                                const char *pszByteOrder );
00554 
00555     void           ClearRawLink();
00556 
00557     virtual void   GetFileList(char*** ppapszFileList, int *pnSize,
00558                                int *pnMaxSize, CPLHashSet* hSetFiles);
00559 };
00560 
00561 /************************************************************************/
00562 /*                              VRTDriver                               */
00563 /************************************************************************/
00564 
00565 class VRTDriver : public GDALDriver
00566 {
00567     void        *pDeserializerData;
00568 
00569   public:
00570                  VRTDriver();
00571                  ~VRTDriver();
00572 
00573     char         **papszSourceParsers;
00574 
00575     virtual char      **GetMetadataDomainList();
00576     virtual char      **GetMetadata( const char * pszDomain = "" );
00577     virtual CPLErr      SetMetadata( char ** papszMetadata,
00578                                      const char * pszDomain = "" );
00579 
00580     VRTSource   *ParseSource( CPLXMLNode *psSrc, const char *pszVRTPath );
00581     void         AddSourceParser( const char *pszElementName, 
00582                                   VRTSourceParser pfnParser );
00583 };
00584 
00585 /************************************************************************/
00586 /*                           VRTSimpleSource                            */
00587 /************************************************************************/
00588 
00589 class CPL_DLL VRTSimpleSource : public VRTSource
00590 {
00591 protected:
00592     GDALRasterBand      *poRasterBand;
00593 
00594     /* when poRasterBand is a mask band, poMaskBandMainBand is the band */
00595     /* from which the mask band is taken */
00596     GDALRasterBand      *poMaskBandMainBand; 
00597 
00598     int                 nSrcXOff;
00599     int                 nSrcYOff;
00600     int                 nSrcXSize;
00601     int                 nSrcYSize;
00602 
00603     int                 nDstXOff;
00604     int                 nDstYOff;
00605     int                 nDstXSize;
00606     int                 nDstYSize;
00607 
00608     int                 bNoDataSet;
00609     double              dfNoDataValue;
00610     CPLString           osResampling;
00611     
00612     int                 bRelativeToVRTOri;
00613     CPLString           osSourceFileNameOri;
00614 
00615 public:
00616             VRTSimpleSource();
00617     virtual ~VRTSimpleSource();
00618 
00619     virtual CPLErr  XMLInit( CPLXMLNode *psTree, const char * );
00620     virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00621 
00622     void           SetSrcBand( GDALRasterBand * );
00623     void           SetSrcMaskBand( GDALRasterBand * );
00624     void           SetSrcWindow( int, int, int, int );
00625     void           SetDstWindow( int, int, int, int );
00626     void           SetNoDataValue( double dfNoDataValue );
00627     const CPLString& GetResampling() const { return osResampling; }
00628     void           SetResampling( const char* pszResampling );
00629 
00630     int            GetSrcDstWindow( int, int, int, int, int, int, 
00631                                     double *pdfReqXOff, double *pdfReqYOff,
00632                                     double *pdfReqXSize, double *pdfReqYSize,
00633                                     int *, int *, int *, int *,
00634                                     int *, int *, int *, int * );
00635 
00636     virtual CPLErr  RasterIO( int nXOff, int nYOff, int nXSize, int nYSize, 
00637                               void *pData, int nBufXSize, int nBufYSize, 
00638                               GDALDataType eBufType, 
00639                               GSpacing nPixelSpace, GSpacing nLineSpace,
00640                               GDALRasterIOExtraArg* psExtraArg );
00641 
00642     virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess );
00643     virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess );
00644     virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax );
00645     virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
00646                                       int bApproxOK, 
00647                                       double *pdfMin, double *pdfMax, 
00648                                       double *pdfMean, double *pdfStdDev,
00649                                       GDALProgressFunc pfnProgress, void *pProgressData );
00650     virtual CPLErr  GetHistogram( int nXSize, int nYSize,
00651                                   double dfMin, double dfMax,
00652                                   int nBuckets, GUIntBig * panHistogram,
00653                                   int bIncludeOutOfRange, int bApproxOK,
00654                                   GDALProgressFunc pfnProgress, void *pProgressData );
00655 
00656     void            DstToSrc( double dfX, double dfY,
00657                               double &dfXOut, double &dfYOut );
00658     void            SrcToDst( double dfX, double dfY,
00659                               double &dfXOut, double &dfYOut );
00660     
00661     virtual void   GetFileList(char*** ppapszFileList, int *pnSize,
00662                                int *pnMaxSize, CPLHashSet* hSetFiles);
00663 
00664     virtual int    IsSimpleSource() { return TRUE; }
00665     virtual const char* GetType() { return "SimpleSource"; }
00666 
00667     GDALRasterBand* GetBand();
00668     int             IsSameExceptBandNumber(VRTSimpleSource* poOtherSource);
00669     CPLErr          DatasetRasterIO(
00670                                int nXOff, int nYOff, int nXSize, int nYSize,
00671                                void * pData, int nBufXSize, int nBufYSize,
00672                                GDALDataType eBufType,
00673                                int nBandCount, int *panBandMap,
00674                                GSpacing nPixelSpace, GSpacing nLineSpace,
00675                                GSpacing nBandSpace,
00676                                GDALRasterIOExtraArg* psExtraArg);
00677 
00678     void             UnsetPreservedRelativeFilenames();
00679 };
00680 
00681 /************************************************************************/
00682 /*                          VRTAveragedSource                           */
00683 /************************************************************************/
00684 
00685 class VRTAveragedSource : public VRTSimpleSource
00686 {
00687 public:
00688                     VRTAveragedSource();
00689     virtual CPLErr  RasterIO( int nXOff, int nYOff, int nXSize, int nYSize, 
00690                               void *pData, int nBufXSize, int nBufYSize, 
00691                               GDALDataType eBufType, 
00692                               GSpacing nPixelSpace, GSpacing nLineSpace,
00693                               GDALRasterIOExtraArg* psExtraArg );
00694 
00695     virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess );
00696     virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess );
00697     virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax );
00698     virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
00699                                       int bApproxOK, 
00700                                       double *pdfMin, double *pdfMax, 
00701                                       double *pdfMean, double *pdfStdDev,
00702                                       GDALProgressFunc pfnProgress, void *pProgressData );
00703     virtual CPLErr  GetHistogram( int nXSize, int nYSize,
00704                                   double dfMin, double dfMax,
00705                                   int nBuckets, GUIntBig * panHistogram,
00706                                   int bIncludeOutOfRange, int bApproxOK,
00707                                   GDALProgressFunc pfnProgress, void *pProgressData );
00708 
00709     virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00710     virtual const char* GetType() { return "AveragedSource"; }
00711 };
00712 
00713 /************************************************************************/
00714 /*                           VRTComplexSource                           */
00715 /************************************************************************/
00716 
00717 typedef enum
00718 {
00719     VRT_SCALING_NONE,
00720     VRT_SCALING_LINEAR,
00721     VRT_SCALING_EXPONENTIAL,
00722 } VRTComplexSourceScaling;
00723 
00724 class CPL_DLL VRTComplexSource : public VRTSimpleSource
00725 {
00726 protected:
00727     VRTComplexSourceScaling eScalingType;
00728     double         dfScaleOff; /* for linear scaling */
00729     double         dfScaleRatio; /* for linear scaling */
00730 
00731     /* For non-linear scaling with a power function. */
00732     int            bSrcMinMaxDefined;
00733     double         dfSrcMin;
00734     double         dfSrcMax;
00735     double         dfDstMin;
00736     double         dfDstMax;
00737     double         dfExponent;
00738 
00739     int            nColorTableComponent;
00740 
00741     CPLErr          RasterIOInternal( int nReqXOff, int nReqYOff,
00742                                       int nReqXSize, int nReqYSize,
00743                                       void *pData, int nOutXSize, int nOutYSize,
00744                                       GDALDataType eBufType,
00745                                       GSpacing nPixelSpace, GSpacing nLineSpace,
00746                                       GDALRasterIOExtraArg* psExtraArg );
00747 
00748 public:
00749                    VRTComplexSource();
00750     virtual        ~VRTComplexSource();
00751 
00752     virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize, 
00753                              void *pData, int nBufXSize, int nBufYSize, 
00754                              GDALDataType eBufType, 
00755                              GSpacing nPixelSpace, GSpacing nLineSpace,
00756                              GDALRasterIOExtraArg* psExtraArg );
00757 
00758     virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess );
00759     virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess );
00760     virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax );
00761     virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
00762                                       int bApproxOK, 
00763                                       double *pdfMin, double *pdfMax, 
00764                                       double *pdfMean, double *pdfStdDev,
00765                                       GDALProgressFunc pfnProgress, void *pProgressData );
00766     virtual CPLErr  GetHistogram( int nXSize, int nYSize,
00767                                   double dfMin, double dfMax,
00768                                   int nBuckets, GUIntBig * panHistogram,
00769                                   int bIncludeOutOfRange, int bApproxOK,
00770                                   GDALProgressFunc pfnProgress, void *pProgressData );
00771 
00772     virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00773     virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00774     virtual const char* GetType() { return "ComplexSource"; }
00775 
00776     double  LookupValue( double dfInput );
00777     
00778     void    SetLinearScaling(double dfOffset, double dfScale);
00779     void    SetPowerScaling(double dfExponent,
00780                             double dfSrcMin,
00781                             double dfSrcMax,
00782                             double dfDstMin,
00783                             double dfDstMax);
00784     void    SetColorTableComponent(int nComponent);
00785 
00786     double         *padfLUTInputs;
00787     double         *padfLUTOutputs;
00788     int            nLUTItemCount;
00789 
00790 };
00791 
00792 /************************************************************************/
00793 /*                           VRTFilteredSource                          */
00794 /************************************************************************/
00795 
00796 class VRTFilteredSource : public VRTComplexSource
00797 {
00798 private:
00799     int          IsTypeSupported( GDALDataType eType );
00800 
00801 protected:
00802     int          nSupportedTypesCount;
00803     GDALDataType aeSupportedTypes[20];
00804 
00805     int          nExtraEdgePixels;
00806 
00807 public:
00808             VRTFilteredSource();
00809     virtual ~VRTFilteredSource();
00810 
00811     void    SetExtraEdgePixels( int );
00812     void    SetFilteringDataTypesSupported( int, GDALDataType * );
00813 
00814     virtual CPLErr  FilterData( int nXSize, int nYSize, GDALDataType eType, 
00815                                 GByte *pabySrcData, GByte *pabyDstData ) = 0;
00816 
00817     virtual CPLErr  RasterIO( int nXOff, int nYOff, int nXSize, int nYSize, 
00818                               void *pData, int nBufXSize, int nBufYSize, 
00819                               GDALDataType eBufType, 
00820                               GSpacing nPixelSpace, GSpacing nLineSpace,
00821                               GDALRasterIOExtraArg* psExtraArg );
00822 };
00823 
00824 /************************************************************************/
00825 /*                       VRTKernelFilteredSource                        */
00826 /************************************************************************/
00827 
00828 class VRTKernelFilteredSource : public VRTFilteredSource
00829 {
00830 protected:
00831     int     nKernelSize;
00832 
00833     double  *padfKernelCoefs;
00834 
00835     int     bNormalized;
00836 
00837 public:
00838             VRTKernelFilteredSource();
00839     virtual ~VRTKernelFilteredSource();
00840 
00841     virtual CPLErr  XMLInit( CPLXMLNode *psTree, const char * );
00842     virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00843 
00844     virtual CPLErr  FilterData( int nXSize, int nYSize, GDALDataType eType, 
00845                                 GByte *pabySrcData, GByte *pabyDstData );
00846 
00847     CPLErr          SetKernel( int nKernelSize, double *padfCoefs );
00848     void            SetNormalized( int );
00849 };
00850 
00851 /************************************************************************/
00852 /*                       VRTAverageFilteredSource                       */
00853 /************************************************************************/
00854 
00855 class VRTAverageFilteredSource : public VRTKernelFilteredSource
00856 {
00857 public:
00858             VRTAverageFilteredSource( int nKernelSize );
00859     virtual ~VRTAverageFilteredSource();
00860 
00861     virtual CPLErr  XMLInit( CPLXMLNode *psTree, const char * );
00862     virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00863 };
00864 
00865 /************************************************************************/
00866 /*                            VRTFuncSource                             */
00867 /************************************************************************/
00868 class VRTFuncSource : public VRTSource
00869 {
00870 public:
00871             VRTFuncSource();
00872     virtual ~VRTFuncSource();
00873 
00874     virtual CPLErr  XMLInit( CPLXMLNode *, const char *) { return CE_Failure; }
00875     virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00876 
00877     virtual CPLErr  RasterIO( int nXOff, int nYOff, int nXSize, int nYSize, 
00878                               void *pData, int nBufXSize, int nBufYSize, 
00879                               GDALDataType eBufType, 
00880                               GSpacing nPixelSpace, GSpacing nLineSpace,
00881                               GDALRasterIOExtraArg* psExtraArg );
00882 
00883     virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess );
00884     virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess );
00885     virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax );
00886     virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
00887                                       int bApproxOK, 
00888                                       double *pdfMin, double *pdfMax, 
00889                                       double *pdfMean, double *pdfStdDev,
00890                                       GDALProgressFunc pfnProgress, void *pProgressData );
00891     virtual CPLErr  GetHistogram( int nXSize, int nYSize,
00892                                   double dfMin, double dfMax,
00893                                   int nBuckets, GUIntBig * panHistogram,
00894                                   int bIncludeOutOfRange, int bApproxOK,
00895                                   GDALProgressFunc pfnProgress, void *pProgressData );
00896 
00897     VRTImageReadFunc    pfnReadFunc;
00898     void               *pCBData;
00899     GDALDataType        eType;
00900     
00901     float               fNoDataValue;
00902 };
00903 
00904 #endif /* ndef VIRTUALDATASET_H_INCLUDED */

Generated for GDAL by doxygen 1.7.6.1.