vrtdataset.h

00001 /******************************************************************************
00002  * $Id: vrtdataset.h 10646 2007-01-18 02:38:10Z warmerdam $
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  *
00011  * Permission is hereby granted, free of charge, to any person obtaining a
00012  * copy of this software and associated documentation files (the "Software"),
00013  * to deal in the Software without restriction, including without limitation
00014  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00015  * and/or sell copies of the Software, and to permit persons to whom the
00016  * Software is furnished to do so, subject to the following conditions:
00017  *
00018  * The above copyright notice and this permission notice shall be included
00019  * in all copies or substantial portions of the Software.
00020  *
00021  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00022  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00023  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00024  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00025  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00026  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00027  * DEALINGS IN THE SOFTWARE.
00028  ****************************************************************************/
00029 
00030 #ifndef VIRTUALDATASET_H_INCLUDED
00031 #define VIRTUALDATASET_H_INCLUDED
00032 
00033 #include "gdal_priv.h"
00034 #include "gdal_pam.h"
00035 #include "cpl_minixml.h"
00036 
00037 CPL_C_START
00038 void    GDALRegister_VRT(void);
00039 typedef CPLErr
00040 (*VRTImageReadFunc)( void *hCBData,
00041                      int nXOff, int nYOff, int nXSize, int nYSize,
00042                      void *pData );
00043 CPL_C_END
00044 
00045 int VRTApplyMetadata( CPLXMLNode *, GDALMajorObject * );
00046 CPLXMLNode *VRTSerializeMetadata( GDALMajorObject * );
00047 
00048 /************************************************************************/
00049 /*                              VRTSource                               */
00050 /************************************************************************/
00051 
00052 class VRTSource 
00053 {
00054 public:
00055     virtual ~VRTSource();
00056 
00057     virtual CPLErr  RasterIO( int nXOff, int nYOff, int nXSize, int nYSize, 
00058                               void *pData, int nBufXSize, int nBufYSize, 
00059                               GDALDataType eBufType, 
00060                               int nPixelSpace, int nLineSpace ) = 0;
00061 
00062     virtual CPLErr  XMLInit( CPLXMLNode *psTree, const char * ) = 0;
00063     virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ) = 0;
00064 };
00065 
00066 typedef VRTSource *(*VRTSourceParser)(CPLXMLNode *, const char *);
00067 
00068 VRTSource *VRTParseCoreSources( CPLXMLNode *psTree, const char * );
00069 VRTSource *VRTParseFilterSources( CPLXMLNode *psTree, const char * );
00070 
00071 /************************************************************************/
00072 /*                              VRTDataset                              */
00073 /************************************************************************/
00074 
00075 class CPL_DLL VRTDataset : public GDALDataset
00076 {
00077     char           *pszProjection;
00078 
00079     int            bGeoTransformSet;
00080     double         adfGeoTransform[6];
00081 
00082     int           nGCPCount;
00083     GDAL_GCP      *pasGCPList;
00084     char          *pszGCPProjection;
00085 
00086     int            bNeedsFlush;
00087     
00088     char          *pszVRTPath;
00089 
00090   public:
00091                  VRTDataset(int nXSize, int nYSize);
00092                 ~VRTDataset();
00093 
00094     void          SetNeedsFlush() { bNeedsFlush = TRUE; }
00095     virtual void  FlushCache();
00096 
00097     virtual const char *GetProjectionRef(void);
00098     virtual CPLErr SetProjection( const char * );
00099     virtual CPLErr GetGeoTransform( double * );
00100     virtual CPLErr SetGeoTransform( double * );
00101 
00102     virtual CPLErr SetMetadata( char **papszMD, const char *pszDomain = "" );
00103     virtual CPLErr SetMetadataItem( const char *pszName, const char *pszValue,
00104                                     const char *pszDomain = "" );
00105 
00106     virtual int    GetGCPCount();
00107     virtual const char *GetGCPProjection();
00108     virtual const GDAL_GCP *GetGCPs();
00109     virtual CPLErr SetGCPs( int nGCPCount, const GDAL_GCP *pasGCPList,
00110                             const char *pszGCPProjection );
00111 
00112     virtual CPLErr AddBand( GDALDataType eType, 
00113                             char **papszOptions=NULL );
00114 
00115     virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath);
00116     virtual CPLErr      XMLInit( CPLXMLNode *, const char * );
00117  
00118     static GDALDataset *Open( GDALOpenInfo * );
00119     static GDALDataset *OpenXML( const char *, const char * = NULL );
00120     static GDALDataset *Create( const char * pszName,
00121                                 int nXSize, int nYSize, int nBands,
00122                                 GDALDataType eType, char ** papszOptions );
00123 };
00124 
00125 /************************************************************************/
00126 /*                           VRTWarpedDataset                           */
00127 /************************************************************************/
00128 
00129 class GDALWarpOperation;
00130 class VRTWarpedRasterBand;
00131 
00132 class CPL_DLL VRTWarpedDataset : public VRTDataset
00133 {
00134     int               nBlockXSize;
00135     int               nBlockYSize;
00136     GDALWarpOperation *poWarper;
00137 
00138 public:
00139     int               nOverviewCount;
00140     VRTWarpedDataset  **papoOverviews;
00141 
00142 public:
00143                       VRTWarpedDataset( int nXSize, int nYSize );
00144                      ~VRTWarpedDataset();
00145 
00146     CPLErr            Initialize( /* GDALWarpOptions */ void * );
00147 
00148     virtual CPLErr IBuildOverviews( const char *, int, int *,
00149                                     int, int *, GDALProgressFunc, void * );
00150     
00151     virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00152     virtual CPLErr    XMLInit( CPLXMLNode *, const char * );
00153 
00154     virtual CPLErr AddBand( GDALDataType eType, 
00155                             char **papszOptions=NULL );
00156     
00157     CPLErr            ProcessBlock( int iBlockX, int iBlockY );
00158 
00159     void              GetBlockSize( int *, int * );
00160 };
00161 
00162 /************************************************************************/
00163 /*                            VRTRasterBand                             */
00164 /*                                                                      */
00165 /*      Provides support for all the various kinds of metadata but      */
00166 /*      no raster access.  That is handled by derived classes.          */
00167 /************************************************************************/
00168 
00169 class CPL_DLL VRTRasterBand : public GDALRasterBand
00170 {
00171   protected:
00172     int            bNoDataValueSet;
00173     double         dfNoDataValue;
00174 
00175     GDALColorTable *poColorTable;
00176 
00177     GDALColorInterp eColorInterp;
00178 
00179     char           *pszUnitType;
00180     char           **papszCategoryNames;
00181     
00182     double         dfOffset;
00183     double         dfScale;
00184 
00185     CPLXMLNode    *psSavedHistograms;
00186 
00187     void           Initialize( int nXSize, int nYSize );
00188 
00189   public:
00190 
00191                    VRTRasterBand();
00192     virtual        ~VRTRasterBand();
00193 
00194     virtual CPLErr         XMLInit( CPLXMLNode *, const char * );
00195     virtual CPLXMLNode *   SerializeToXML( const char *pszVRTPath );
00196 
00197 #define VRT_NODATA_UNSET -1234.56
00198 
00199     virtual CPLErr SetNoDataValue( double );
00200     virtual double GetNoDataValue( int *pbSuccess = NULL );
00201 
00202     virtual CPLErr SetColorTable( GDALColorTable * ); 
00203     virtual GDALColorTable *GetColorTable();
00204 
00205     virtual CPLErr SetColorInterpretation( GDALColorInterp );
00206     virtual GDALColorInterp GetColorInterpretation();
00207 
00208     virtual const char *GetUnitType();
00209     CPLErr SetUnitType( const char * ); 
00210 
00211     virtual char **GetCategoryNames();
00212     virtual CPLErr SetCategoryNames( char ** );
00213 
00214     virtual CPLErr SetMetadata( char **papszMD, const char *pszDomain = "" );
00215     virtual CPLErr SetMetadataItem( const char *pszName, const char *pszValue,
00216                                     const char *pszDomain = "" );
00217 
00218     virtual double GetOffset( int *pbSuccess = NULL );
00219     CPLErr SetOffset( double );
00220     virtual double GetScale( int *pbSuccess = NULL );
00221     CPLErr SetScale( double );
00222     
00223     virtual CPLErr  GetHistogram( double dfMin, double dfMax,
00224                           int nBuckets, int * panHistogram,
00225                           int bIncludeOutOfRange, int bApproxOK,
00226                           GDALProgressFunc, void *pProgressData );
00227 
00228     virtual CPLErr GetDefaultHistogram( double *pdfMin, double *pdfMax,
00229                                         int *pnBuckets, int ** ppanHistogram,
00230                                         int bForce,
00231                                         GDALProgressFunc, void *pProgressData);
00232 
00233     virtual CPLErr SetDefaultHistogram( double dfMin, double dfMax,
00234                                         int nBuckets, int *panHistogram );
00235 
00236     CPLErr         CopyCommonInfoFrom( GDALRasterBand * );
00237 };
00238 
00239 /************************************************************************/
00240 /*                         VRTSourcedRasterBand                         */
00241 /************************************************************************/
00242 
00243 class CPL_DLL VRTSourcedRasterBand : public VRTRasterBand
00244 {
00245 
00246     void           Initialize( int nXSize, int nYSize );
00247 
00248   public:
00249     int            nSources;
00250     VRTSource    **papoSources;
00251     int            bEqualAreas;
00252 
00253                    VRTSourcedRasterBand( GDALDataset *poDS, int nBand );
00254                    VRTSourcedRasterBand( GDALDataType eType, 
00255                                          int nXSize, int nYSize );
00256                    VRTSourcedRasterBand( GDALDataset *poDS, int nBand, 
00257                                          GDALDataType eType, 
00258                                          int nXSize, int nYSize );
00259     virtual        ~VRTSourcedRasterBand();
00260 
00261     virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
00262                               void *, int, int, GDALDataType,
00263                               int, int );
00264 
00265     virtual char      **GetMetadata( const char * pszDomain = "" );
00266     virtual CPLErr      SetMetadata( char ** papszMetadata,
00267                                      const char * pszDomain = "" );
00268     virtual CPLErr      SetMetadataItem( const char * pszName,
00269                                          const char * pszValue,
00270                                          const char * pszDomain = "" );
00271 
00272     virtual CPLErr         XMLInit( CPLXMLNode *, const char * );
00273     virtual CPLXMLNode *   SerializeToXML( const char *pszVRTPath );
00274 
00275     CPLErr         AddSource( VRTSource * );
00276     CPLErr         AddSimpleSource( GDALRasterBand *poSrcBand, 
00277                                     int nSrcXOff=-1, int nSrcYOff=-1, 
00278                                     int nSrcXSize=-1, int nSrcYSize=-1, 
00279                                     int nDstXOff=-1, int nDstYOff=-1, 
00280                                     int nDstXSize=-1, int nDstYSize=-1,
00281                                     const char *pszResampling = "near",
00282                                     double dfNoDataValue = VRT_NODATA_UNSET);
00283     CPLErr         AddComplexSource( GDALRasterBand *poSrcBand, 
00284                                      int nSrcXOff=-1, int nSrcYOff=-1, 
00285                                      int nSrcXSize=-1, int nSrcYSize=-1, 
00286                                      int nDstXOff=-1, int nDstYOff=-1, 
00287                                      int nDstXSize=-1, int nDstYSize=-1,
00288                                      double dfScaleOff=0.0, 
00289                                      double dfScaleRatio=1.0,
00290                                      double dfNoDataValue = VRT_NODATA_UNSET);
00291 
00292     CPLErr         AddFuncSource( VRTImageReadFunc pfnReadFunc, void *hCBData,
00293                                   double dfNoDataValue = VRT_NODATA_UNSET );
00294 
00295 
00296     virtual CPLErr IReadBlock( int, int, void * );
00297 };
00298 
00299 /************************************************************************/
00300 /*                         VRTWarpedRasterBand                          */
00301 /************************************************************************/
00302 
00303 class CPL_DLL VRTWarpedRasterBand : public VRTRasterBand
00304 {
00305   public:
00306                    VRTWarpedRasterBand( GDALDataset *poDS, int nBand,
00307                                      GDALDataType eType = GDT_Unknown );
00308     virtual        ~VRTWarpedRasterBand();
00309 
00310     virtual CPLErr         XMLInit( CPLXMLNode *, const char * );
00311     virtual CPLXMLNode *   SerializeToXML( const char *pszVRTPath );
00312 
00313     virtual CPLErr IReadBlock( int, int, void * );
00314 
00315     virtual int GetOverviewCount();
00316     virtual GDALRasterBand *GetOverview(int);
00317 };
00318 
00319 /************************************************************************/
00320 /*                         VRTDerivedRasterBand                         */
00321 /************************************************************************/
00322 
00323 class CPL_DLL VRTDerivedRasterBand : public VRTSourcedRasterBand
00324 {
00325 
00326  public:
00327     char *pszFuncName;
00328     GDALDataType eSourceTransferType;
00329 
00330     VRTDerivedRasterBand(GDALDataset *poDS, int nBand);
00331     VRTDerivedRasterBand(GDALDataset *poDS, int nBand, 
00332                          GDALDataType eType, int nXSize, int nYSize);
00333     virtual        ~VRTDerivedRasterBand();
00334 
00335     virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
00336                               void *, int, int, GDALDataType,
00337                               int, int );
00338 
00339     static CPLErr AddPixelFunction
00340         (const char *pszFuncName, GDALDerivedPixelFunc pfnPixelFunc);
00341     static GDALDerivedPixelFunc GetPixelFunction(const char *pszFuncName);
00342 
00343     void SetPixelFunctionName(const char *pszFuncName);
00344     void SetSourceTransferType(GDALDataType eDataType);
00345 
00346     virtual CPLErr         XMLInit( CPLXMLNode *, const char * );
00347     virtual CPLXMLNode *   SerializeToXML( const char *pszVRTPath );
00348 
00349 };
00350 
00351 /************************************************************************/
00352 /*                           VRTRawRasterBand                           */
00353 /************************************************************************/
00354 
00355 class RawRasterBand;
00356 
00357 class CPL_DLL VRTRawRasterBand : public VRTRasterBand
00358 {
00359     RawRasterBand  *poRawRaster;
00360 
00361     char           *pszSourceFilename;
00362     int            bRelativeToVRT;
00363 
00364   public:
00365                    VRTRawRasterBand( GDALDataset *poDS, int nBand,
00366                                      GDALDataType eType = GDT_Unknown );
00367     virtual        ~VRTRawRasterBand();
00368 
00369     virtual CPLErr         XMLInit( CPLXMLNode *, const char * );
00370     virtual CPLXMLNode *   SerializeToXML( const char *pszVRTPath );
00371 
00372     virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
00373                               void *, int, int, GDALDataType,
00374                               int, int );
00375 
00376     virtual CPLErr IReadBlock( int, int, void * );
00377     virtual CPLErr IWriteBlock( int, int, void * );
00378 
00379     CPLErr         SetRawLink( const char *pszFilename, 
00380                                const char *pszVRTPath,
00381                                int bRelativeToVRT, 
00382                                vsi_l_offset nImageOffset, 
00383                                int nPixelOffset, int nLineOffset, 
00384                                const char *pszByteOrder );
00385 
00386     void           ClearRawLink();
00387 
00388 };
00389 
00390 /************************************************************************/
00391 /*                              VRTDriver                               */
00392 /************************************************************************/
00393 
00394 class VRTDriver : public GDALDriver
00395 {
00396   public:
00397                  VRTDriver();
00398                  ~VRTDriver();
00399 
00400     char         **papszSourceParsers;
00401 
00402     virtual char      **GetMetadata( const char * pszDomain = "" );
00403     virtual CPLErr      SetMetadata( char ** papszMetadata,
00404                                      const char * pszDomain = "" );
00405 
00406     VRTSource   *ParseSource( CPLXMLNode *psSrc, const char *pszVRTPath );
00407     void         AddSourceParser( const char *pszElementName, 
00408                                   VRTSourceParser pfnParser );
00409 };
00410 
00411 /************************************************************************/
00412 /*                           VRTSimpleSource                            */
00413 /************************************************************************/
00414 
00415 class VRTSimpleSource : public VRTSource
00416 {
00417 protected:
00418     GDALRasterBand      *poRasterBand;
00419 
00420     int                 nSrcXOff;
00421     int                 nSrcYOff;
00422     int                 nSrcXSize;
00423     int                 nSrcYSize;
00424 
00425     int                 nDstXOff;
00426     int                 nDstYOff;
00427     int                 nDstXSize;
00428     int                 nDstYSize;
00429 
00430     int                 bNoDataSet;
00431     double              dfNoDataValue;
00432 
00433 public:
00434             VRTSimpleSource();
00435     virtual ~VRTSimpleSource();
00436 
00437     virtual CPLErr  XMLInit( CPLXMLNode *psTree, const char * );
00438     virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00439 
00440     void           SetSrcBand( GDALRasterBand * );
00441     void           SetSrcWindow( int, int, int, int );
00442     void           SetDstWindow( int, int, int, int );
00443     void           SetNoDataValue( double dfNoDataValue );
00444 
00445     int            GetSrcDstWindow( int, int, int, int, int, int, 
00446                                     int *, int *, int *, int *,
00447                                     int *, int *, int *, int * );
00448 
00449     virtual CPLErr  RasterIO( int nXOff, int nYOff, int nXSize, int nYSize, 
00450                               void *pData, int nBufXSize, int nBufYSize, 
00451                               GDALDataType eBufType, 
00452                               int nPixelSpace, int nLineSpace );
00453 
00454     void            DstToSrc( double dfX, double dfY,
00455                               double &dfXOut, double &dfYOut );
00456     void            SrcToDst( double dfX, double dfY,
00457                               double &dfXOut, double &dfYOut );
00458 
00459 };
00460 
00461 /************************************************************************/
00462 /*                          VRTAveragedSource                           */
00463 /************************************************************************/
00464 
00465 class VRTAveragedSource : public VRTSimpleSource
00466 {
00467 public:
00468                     VRTAveragedSource();
00469     virtual CPLErr  RasterIO( int nXOff, int nYOff, int nXSize, int nYSize, 
00470                               void *pData, int nBufXSize, int nBufYSize, 
00471                               GDALDataType eBufType, 
00472                               int nPixelSpace, int nLineSpace );
00473     virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00474 };
00475 
00476 /************************************************************************/
00477 /*                           VRTComplexSource                           */
00478 /************************************************************************/
00479 
00480 class VRTComplexSource : public VRTSimpleSource
00481 {
00482 public:
00483                    VRTComplexSource();
00484     virtual        ~VRTComplexSource();
00485 
00486     virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize, 
00487                              void *pData, int nBufXSize, int nBufYSize, 
00488                              GDALDataType eBufType, 
00489                              int nPixelSpace, int nLineSpace );
00490     virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00491     virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00492 
00493     int            bDoScaling;
00494     double         dfScaleOff;
00495     double         dfScaleRatio;
00496 
00497 };
00498 
00499 /************************************************************************/
00500 /*                           VRTFilteredSource                          */
00501 /************************************************************************/
00502 
00503 class VRTFilteredSource : public VRTComplexSource
00504 {
00505 private:
00506     int          IsTypeSupported( GDALDataType eType );
00507 
00508 protected:
00509     int          nSupportedTypesCount;
00510     GDALDataType aeSupportedTypes[20];
00511 
00512     int          nExtraEdgePixels;
00513 
00514 public:
00515             VRTFilteredSource();
00516     virtual ~VRTFilteredSource();
00517 
00518     void    SetExtraEdgePixels( int );
00519     void    SetFilteringDataTypesSupported( int, GDALDataType * );
00520 
00521     virtual CPLErr  FilterData( int nXSize, int nYSize, GDALDataType eType, 
00522                                 GByte *pabySrcData, GByte *pabyDstData ) = 0;
00523 
00524     virtual CPLErr  RasterIO( int nXOff, int nYOff, int nXSize, int nYSize, 
00525                               void *pData, int nBufXSize, int nBufYSize, 
00526                               GDALDataType eBufType, 
00527                               int nPixelSpace, int nLineSpace );
00528 };
00529 
00530 /************************************************************************/
00531 /*                       VRTKernelFilteredSource                        */
00532 /************************************************************************/
00533 
00534 class VRTKernelFilteredSource : public VRTFilteredSource
00535 {
00536 protected:
00537     int     nKernelSize;
00538 
00539     double  *padfKernelCoefs;
00540 
00541     int     bNormalized;
00542 
00543 public:
00544             VRTKernelFilteredSource();
00545     virtual ~VRTKernelFilteredSource();
00546 
00547     virtual CPLErr  XMLInit( CPLXMLNode *psTree, const char * );
00548     virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00549 
00550     virtual CPLErr  FilterData( int nXSize, int nYSize, GDALDataType eType, 
00551                                 GByte *pabySrcData, GByte *pabyDstData );
00552 
00553     CPLErr          SetKernel( int nKernelSize, double *padfCoefs );
00554     void            SetNormalized( int );
00555 };
00556 
00557 /************************************************************************/
00558 /*                       VRTAverageFilteredSource                       */
00559 /************************************************************************/
00560 
00561 class VRTAverageFilteredSource : public VRTKernelFilteredSource
00562 {
00563 public:
00564             VRTAverageFilteredSource( int nKernelSize );
00565     virtual ~VRTAverageFilteredSource();
00566 
00567     virtual CPLErr  XMLInit( CPLXMLNode *psTree, const char * );
00568     virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00569 };
00570 
00571 /************************************************************************/
00572 /*                            VRTFuncSource                             */
00573 /************************************************************************/
00574 class VRTFuncSource : public VRTSource
00575 {
00576 public:
00577             VRTFuncSource();
00578     virtual ~VRTFuncSource();
00579 
00580     virtual CPLErr  XMLInit( CPLXMLNode *, const char *) { return CE_Failure; }
00581     virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00582 
00583     virtual CPLErr  RasterIO( int nXOff, int nYOff, int nXSize, int nYSize, 
00584                               void *pData, int nBufXSize, int nBufYSize, 
00585                               GDALDataType eBufType, 
00586                               int nPixelSpace, int nLineSpace );
00587 
00588     VRTImageReadFunc    pfnReadFunc;
00589     void               *pCBData;
00590     GDALDataType        eType;
00591     
00592     float               fNoDataValue;
00593 };
00594 
00595 #endif /* ndef VIRTUALDATASET_H_INCLUDED */

Generated for GDAL by doxygen 1.4.7.