vrtdataset.h

00001 /******************************************************************************
00002  * $Id: vrtdataset.h,v 1.20 2005/05/05 13:56:53 fwarmerdam Exp $
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  * $Log: vrtdataset.h,v $
00031  * Revision 1.20  2005/05/05 13:56:53  fwarmerdam
00032  * include gdal_pam.h
00033  *
00034  * Revision 1.19  2005/04/07 17:27:33  fwarmerdam
00035  * Default path in OpenXML to NULL.
00036  *
00037  * Revision 1.18  2004/08/12 08:24:26  warmerda
00038  * added overview support
00039  *
00040  * Revision 1.17  2004/08/11 18:51:48  warmerda
00041  * added warped dataset support
00042  *
00043  * Revision 1.16  2004/07/30 21:51:00  warmerda
00044  * added support for VRTRawRasterBand
00045  *
00046  * Revision 1.15  2004/07/28 17:47:33  warmerda
00047  * Disable VRTWarpedRasterBand for now.
00048  *
00049  * Revision 1.14  2004/07/28 16:56:02  warmerda
00050  * added VRTSourcedRasterBand
00051  *
00052  * Revision 1.13  2004/04/15 18:54:38  warmerda
00053  * added UnitType, Offset, Scale and CategoryNames support
00054  *
00055  * Revision 1.12  2004/03/16 18:34:35  warmerda
00056  * added support for relativeToVRT attribute on SourceFilename
00057  *
00058  * Revision 1.11  2003/09/11 23:00:04  aamici
00059  * add class constructors and destructors where needed in order to
00060  * let the mingw/cygwin binutils produce sensible partially linked objet files
00061  * with 'ld -r'.
00062  *
00063  * Revision 1.10  2003/08/07 17:11:21  warmerda
00064  * added normalized flag for kernel based filters
00065  *
00066  * Revision 1.9  2003/07/17 20:30:24  warmerda
00067  * Added custom VRTDriver and moved all the sources class declarations in here.
00068  *
00069  * Revision 1.8  2003/06/10 19:59:33  warmerda
00070  * added new Func based source type for passthrough to a callback
00071  *
00072  * Revision 1.7  2003/03/13 20:38:30  dron
00073  * bNoDataValueSet added to VRTRasterBand class.
00074  *
00075  * Revision 1.6  2002/11/30 16:55:49  warmerda
00076  * added OpenXML method
00077  *
00078  * Revision 1.5  2002/11/24 04:29:02  warmerda
00079  * Substantially rewrote VRTSimpleSource.  Now VRTSource is base class, and
00080  * sources do their own SerializeToXML(), and XMLInit().  New VRTComplexSource
00081  * supports scaling and nodata values.
00082  *
00083  * Revision 1.4  2002/05/29 18:13:44  warmerda
00084  * added nodata handling for averager
00085  *
00086  * Revision 1.3  2002/05/29 16:06:05  warmerda
00087  * complete detailed band metadata
00088  *
00089  * Revision 1.2  2001/11/18 15:46:45  warmerda
00090  * added SRS and GeoTransform
00091  *
00092  * Revision 1.1  2001/11/16 21:14:31  warmerda
00093  * New
00094  *
00095  */
00096 
00097 #ifndef VIRTUALDATASET_H_INCLUDED
00098 #define VIRTUALDATASET_H_INCLUDED
00099 
00100 #include "gdal_priv.h"
00101 #include "gdal_pam.h"
00102 #include "cpl_minixml.h"
00103 
00104 CPL_C_START
00105 void    GDALRegister_VRT(void);
00106 typedef CPLErr
00107 (*VRTImageReadFunc)( void *hCBData,
00108                      int nXOff, int nYOff, int nXSize, int nYSize,
00109                      void *pData );
00110 CPL_C_END
00111 
00112 int VRTApplyMetadata( CPLXMLNode *, GDALMajorObject * );
00113 CPLXMLNode *VRTSerializeMetadata( GDALMajorObject * );
00114 
00115 /************************************************************************/
00116 /*                              VRTSource                               */
00117 /************************************************************************/
00118 
00119 class VRTSource 
00120 {
00121 public:
00122     virtual ~VRTSource();
00123 
00124     virtual CPLErr  RasterIO( int nXOff, int nYOff, int nXSize, int nYSize, 
00125                               void *pData, int nBufXSize, int nBufYSize, 
00126                               GDALDataType eBufType, 
00127                               int nPixelSpace, int nLineSpace ) = 0;
00128 
00129     virtual CPLErr  XMLInit( CPLXMLNode *psTree, const char * ) = 0;
00130     virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ) = 0;
00131 };
00132 
00133 typedef VRTSource *(*VRTSourceParser)(CPLXMLNode *, const char *);
00134 
00135 VRTSource *VRTParseCoreSources( CPLXMLNode *psTree, const char * );
00136 VRTSource *VRTParseFilterSources( CPLXMLNode *psTree, const char * );
00137 
00138 /************************************************************************/
00139 /*                              VRTDataset                              */
00140 /************************************************************************/
00141 
00142 class CPL_DLL VRTDataset : public GDALDataset
00143 {
00144     char           *pszProjection;
00145 
00146     int            bGeoTransformSet;
00147     double         adfGeoTransform[6];
00148 
00149     int           nGCPCount;
00150     GDAL_GCP      *pasGCPList;
00151     char          *pszGCPProjection;
00152 
00153     int            bNeedsFlush;
00154     
00155     char          *pszVRTPath;
00156 
00157   public:
00158                  VRTDataset(int nXSize, int nYSize);
00159                 ~VRTDataset();
00160 
00161     void          SetNeedsFlush() { bNeedsFlush = TRUE; }
00162     virtual void  FlushCache();
00163 
00164     virtual const char *GetProjectionRef(void);
00165     virtual CPLErr SetProjection( const char * );
00166     virtual CPLErr GetGeoTransform( double * );
00167     virtual CPLErr SetGeoTransform( double * );
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 CPLXMLNode *SerializeToXML( const char *pszVRTPath);
00179     virtual CPLErr      XMLInit( CPLXMLNode *, const char * );
00180  
00181     static GDALDataset *Open( GDALOpenInfo * );
00182     static GDALDataset *OpenXML( const char *, const char * = NULL );
00183     static GDALDataset *Create( const char * pszName,
00184                                 int nXSize, int nYSize, int nBands,
00185                                 GDALDataType eType, char ** papszOptions );
00186 };
00187 
00188 /************************************************************************/
00189 /*                           VRTWarpedDataset                           */
00190 /************************************************************************/
00191 
00192 class GDALWarpOperation;
00193 class VRTWarpedRasterBand;
00194 
00195 class CPL_DLL VRTWarpedDataset : public VRTDataset
00196 {
00197     int               nBlockXSize;
00198     int               nBlockYSize;
00199     GDALWarpOperation *poWarper;
00200 
00201 public:
00202     int               nOverviewCount;
00203     VRTWarpedDataset  **papoOverviews;
00204 
00205 public:
00206                       VRTWarpedDataset( int nXSize, int nYSize );
00207                      ~VRTWarpedDataset();
00208 
00209     CPLErr            Initialize( /* GDALWarpOptions */ void * );
00210 
00211     virtual CPLErr IBuildOverviews( const char *, int, int *,
00212                                     int, int *, GDALProgressFunc, void * );
00213     
00214     virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00215     virtual CPLErr    XMLInit( CPLXMLNode *, const char * );
00216 
00217     virtual CPLErr AddBand( GDALDataType eType, 
00218                             char **papszOptions=NULL );
00219     
00220     CPLErr            ProcessBlock( int iBlockX, int iBlockY );
00221 
00222     void              GetBlockSize( int *, int * );
00223 };
00224 
00225 /************************************************************************/
00226 /*                            VRTRasterBand                             */
00227 /*                                                                      */
00228 /*      Provides support for all the various kinds of metadata but      */
00229 /*      no raster access.  That is handled by derived classes.          */
00230 /************************************************************************/
00231 
00232 class CPL_DLL VRTRasterBand : public GDALRasterBand
00233 {
00234   protected:
00235     int            bNoDataValueSet;
00236     double         dfNoDataValue;
00237 
00238     GDALColorTable *poColorTable;
00239 
00240     GDALColorInterp eColorInterp;
00241 
00242     char           *pszUnitType;
00243     char           **papszCategoryNames;
00244     
00245     double         dfOffset;
00246     double         dfScale;
00247 
00248     void           Initialize( int nXSize, int nYSize );
00249 
00250   public:
00251 
00252                    VRTRasterBand();
00253     virtual        ~VRTRasterBand();
00254 
00255     virtual CPLErr         XMLInit( CPLXMLNode *, const char * );
00256     virtual CPLXMLNode *   SerializeToXML( const char *pszVRTPath );
00257 
00258 #define VRT_NODATA_UNSET -1234.56
00259 
00260     virtual CPLErr SetNoDataValue( double );
00261     virtual double GetNoDataValue( int *pbSuccess = NULL );
00262 
00263     virtual CPLErr SetColorTable( GDALColorTable * ); 
00264     virtual GDALColorTable *GetColorTable();
00265 
00266     virtual CPLErr SetColorInterpretation( GDALColorInterp );
00267     virtual GDALColorInterp GetColorInterpretation();
00268 
00269     virtual const char *GetUnitType();
00270     CPLErr SetUnitType( const char * ); 
00271 
00272     virtual char **GetCategoryNames();
00273     virtual CPLErr SetCategoryNames( char ** );
00274 
00275     virtual double GetOffset( int *pbSuccess = NULL );
00276     CPLErr SetOffset( double );
00277     virtual double GetScale( int *pbSuccess = NULL );
00278     CPLErr SetScale( double );
00279     
00280     CPLErr         CopyCommonInfoFrom( GDALRasterBand * );
00281 };
00282 
00283 /************************************************************************/
00284 /*                         VRTSourcedRasterBand                         */
00285 /************************************************************************/
00286 
00287 class CPL_DLL VRTSourcedRasterBand : public VRTRasterBand
00288 {
00289     int            nSources;
00290     VRTSource    **papoSources;
00291 
00292     int            bEqualAreas;
00293 
00294     void           Initialize( int nXSize, int nYSize );
00295 
00296     virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
00297                               void *, int, int, GDALDataType,
00298                               int, int );
00299   public:
00300 
00301                    VRTSourcedRasterBand( GDALDataset *poDS, int nBand );
00302                    VRTSourcedRasterBand( GDALDataType eType, 
00303                                          int nXSize, int nYSize );
00304                    VRTSourcedRasterBand( GDALDataset *poDS, int nBand, 
00305                                          GDALDataType eType, 
00306                                          int nXSize, int nYSize );
00307     virtual        ~VRTSourcedRasterBand();
00308 
00309     virtual char      **GetMetadata( const char * pszDomain = "" );
00310     virtual CPLErr      SetMetadata( char ** papszMetadata,
00311                                      const char * pszDomain = "" );
00312 
00313     virtual CPLErr         XMLInit( CPLXMLNode *, const char * );
00314     virtual CPLXMLNode *   SerializeToXML( const char *pszVRTPath );
00315 
00316     CPLErr         AddSource( VRTSource * );
00317     CPLErr         AddSimpleSource( GDALRasterBand *poSrcBand, 
00318                                     int nSrcXOff=-1, int nSrcYOff=-1, 
00319                                     int nSrcXSize=-1, int nSrcYSize=-1, 
00320                                     int nDstXOff=-1, int nDstYOff=-1, 
00321                                     int nDstXSize=-1, int nDstYSize=-1,
00322                                     const char *pszResampling = "near",
00323                                     double dfNoDataValue = VRT_NODATA_UNSET);
00324     CPLErr         AddComplexSource( GDALRasterBand *poSrcBand, 
00325                                      int nSrcXOff=-1, int nSrcYOff=-1, 
00326                                      int nSrcXSize=-1, int nSrcYSize=-1, 
00327                                      int nDstXOff=-1, int nDstYOff=-1, 
00328                                      int nDstXSize=-1, int nDstYSize=-1,
00329                                      double dfScaleOff=0.0, 
00330                                      double dfScaleRatio=1.0,
00331                                      double dfNoDataValue = VRT_NODATA_UNSET);
00332 
00333     CPLErr         AddFuncSource( VRTImageReadFunc pfnReadFunc, void *hCBData,
00334                                   double dfNoDataValue = VRT_NODATA_UNSET );
00335 
00336 
00337     virtual CPLErr IReadBlock( int, int, void * );
00338 };
00339 
00340 /************************************************************************/
00341 /*                         VRTWarpedRasterBand                          */
00342 /************************************************************************/
00343 
00344 class CPL_DLL VRTWarpedRasterBand : public VRTRasterBand
00345 {
00346   public:
00347                    VRTWarpedRasterBand( GDALDataset *poDS, int nBand,
00348                                      GDALDataType eType = GDT_Unknown );
00349     virtual        ~VRTWarpedRasterBand();
00350 
00351     virtual CPLErr         XMLInit( CPLXMLNode *, const char * );
00352     virtual CPLXMLNode *   SerializeToXML( const char *pszVRTPath );
00353 
00354     virtual CPLErr IReadBlock( int, int, void * );
00355 
00356     virtual int GetOverviewCount();
00357     virtual GDALRasterBand *GetOverview(int);
00358 };
00359 
00360 /************************************************************************/
00361 /*                           VRTRawRasterBand                           */
00362 /************************************************************************/
00363 
00364 class RawRasterBand;
00365 
00366 class CPL_DLL VRTRawRasterBand : public VRTRasterBand
00367 {
00368     RawRasterBand  *poRawRaster;
00369 
00370     char           *pszSourceFilename;
00371     int            bRelativeToVRT;
00372 
00373   public:
00374                    VRTRawRasterBand( GDALDataset *poDS, int nBand,
00375                                      GDALDataType eType = GDT_Unknown );
00376     virtual        ~VRTRawRasterBand();
00377 
00378     virtual CPLErr         XMLInit( CPLXMLNode *, const char * );
00379     virtual CPLXMLNode *   SerializeToXML( const char *pszVRTPath );
00380 
00381     virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
00382                               void *, int, int, GDALDataType,
00383                               int, int );
00384 
00385     virtual CPLErr IReadBlock( int, int, void * );
00386     virtual CPLErr IWriteBlock( int, int, void * );
00387 
00388     CPLErr         SetRawLink( const char *pszFilename, 
00389                                const char *pszVRTPath,
00390                                int bRelativeToVRT, 
00391                                vsi_l_offset nImageOffset, 
00392                                int nPixelOffset, int nLineOffset, 
00393                                const char *pszByteOrder );
00394 
00395     void           ClearRawLink();
00396 
00397 };
00398 
00399 /************************************************************************/
00400 /*                              VRTDriver                               */
00401 /************************************************************************/
00402 
00403 class VRTDriver : public GDALDriver
00404 {
00405   public:
00406                  VRTDriver();
00407                  ~VRTDriver();
00408 
00409     char         **papszSourceParsers;
00410 
00411     virtual char      **GetMetadata( const char * pszDomain = "" );
00412     virtual CPLErr      SetMetadata( char ** papszMetadata,
00413                                      const char * pszDomain = "" );
00414 
00415     VRTSource   *ParseSource( CPLXMLNode *psSrc, const char *pszVRTPath );
00416     void         AddSourceParser( const char *pszElementName, 
00417                                   VRTSourceParser pfnParser );
00418 };
00419 
00420 /************************************************************************/
00421 /*                           VRTSimpleSource                            */
00422 /************************************************************************/
00423 
00424 class VRTSimpleSource : public VRTSource
00425 {
00426 protected:
00427     GDALRasterBand      *poRasterBand;
00428 
00429     int                 nSrcXOff;
00430     int                 nSrcYOff;
00431     int                 nSrcXSize;
00432     int                 nSrcYSize;
00433 
00434     int                 nDstXOff;
00435     int                 nDstYOff;
00436     int                 nDstXSize;
00437     int                 nDstYSize;
00438 
00439     int                 bNoDataSet;
00440     double              dfNoDataValue;
00441 
00442 public:
00443             VRTSimpleSource();
00444     virtual ~VRTSimpleSource();
00445 
00446     virtual CPLErr  XMLInit( CPLXMLNode *psTree, const char * );
00447     virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00448 
00449     void           SetSrcBand( GDALRasterBand * );
00450     void           SetSrcWindow( int, int, int, int );
00451     void           SetDstWindow( int, int, int, int );
00452     void           SetNoDataValue( double dfNoDataValue );
00453 
00454     int            GetSrcDstWindow( int, int, int, int, int, int, 
00455                                     int *, int *, int *, int *,
00456                                     int *, int *, int *, int * );
00457 
00458     virtual CPLErr  RasterIO( int nXOff, int nYOff, int nXSize, int nYSize, 
00459                               void *pData, int nBufXSize, int nBufYSize, 
00460                               GDALDataType eBufType, 
00461                               int nPixelSpace, int nLineSpace );
00462 
00463     void            DstToSrc( double dfX, double dfY,
00464                               double &dfXOut, double &dfYOut );
00465     void            SrcToDst( double dfX, double dfY,
00466                               double &dfXOut, double &dfYOut );
00467 
00468 };
00469 
00470 /************************************************************************/
00471 /*                          VRTAveragedSource                           */
00472 /************************************************************************/
00473 
00474 class VRTAveragedSource : public VRTSimpleSource
00475 {
00476 public:
00477                     VRTAveragedSource();
00478     virtual CPLErr  RasterIO( int nXOff, int nYOff, int nXSize, int nYSize, 
00479                               void *pData, int nBufXSize, int nBufYSize, 
00480                               GDALDataType eBufType, 
00481                               int nPixelSpace, int nLineSpace );
00482     virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00483 };
00484 
00485 /************************************************************************/
00486 /*                           VRTComplexSource                           */
00487 /************************************************************************/
00488 
00489 class VRTComplexSource : public VRTSimpleSource
00490 {
00491 public:
00492                    VRTComplexSource();
00493     virtual        ~VRTComplexSource();
00494 
00495     virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize, 
00496                              void *pData, int nBufXSize, int nBufYSize, 
00497                              GDALDataType eBufType, 
00498                              int nPixelSpace, int nLineSpace );
00499     virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00500     virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00501 
00502     int            bDoScaling;
00503     double         dfScaleOff;
00504     double         dfScaleRatio;
00505 
00506 };
00507 
00508 /************************************************************************/
00509 /*                           VRTFilteredSource                          */
00510 /************************************************************************/
00511 
00512 class VRTFilteredSource : public VRTComplexSource
00513 {
00514 private:
00515     int          IsTypeSupported( GDALDataType eType );
00516 
00517 protected:
00518     int          nSupportedTypesCount;
00519     GDALDataType aeSupportedTypes[20];
00520 
00521     int          nExtraEdgePixels;
00522 
00523 public:
00524             VRTFilteredSource();
00525     virtual ~VRTFilteredSource();
00526 
00527     void    SetExtraEdgePixels( int );
00528     void    SetFilteringDataTypesSupported( int, GDALDataType * );
00529 
00530     virtual CPLErr  FilterData( int nXSize, int nYSize, GDALDataType eType, 
00531                                 GByte *pabySrcData, GByte *pabyDstData ) = 0;
00532 
00533     virtual CPLErr  RasterIO( int nXOff, int nYOff, int nXSize, int nYSize, 
00534                               void *pData, int nBufXSize, int nBufYSize, 
00535                               GDALDataType eBufType, 
00536                               int nPixelSpace, int nLineSpace );
00537 };
00538 
00539 /************************************************************************/
00540 /*                       VRTKernelFilteredSource                        */
00541 /************************************************************************/
00542 
00543 class VRTKernelFilteredSource : public VRTFilteredSource
00544 {
00545 protected:
00546     int     nKernelSize;
00547 
00548     double  *padfKernelCoefs;
00549 
00550     int     bNormalized;
00551 
00552 public:
00553             VRTKernelFilteredSource();
00554     virtual ~VRTKernelFilteredSource();
00555 
00556     virtual CPLErr  XMLInit( CPLXMLNode *psTree, const char * );
00557     virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00558 
00559     virtual CPLErr  FilterData( int nXSize, int nYSize, GDALDataType eType, 
00560                                 GByte *pabySrcData, GByte *pabyDstData );
00561 
00562     CPLErr          SetKernel( int nKernelSize, double *padfCoefs );
00563     void            SetNormalized( int );
00564 };
00565 
00566 /************************************************************************/
00567 /*                       VRTAverageFilteredSource                       */
00568 /************************************************************************/
00569 
00570 class VRTAverageFilteredSource : public VRTKernelFilteredSource
00571 {
00572 public:
00573             VRTAverageFilteredSource( int nKernelSize );
00574     virtual ~VRTAverageFilteredSource();
00575 
00576     virtual CPLErr  XMLInit( CPLXMLNode *psTree, const char * );
00577     virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00578 };
00579 
00580 /************************************************************************/
00581 /*                            VRTFuncSource                             */
00582 /************************************************************************/
00583 class VRTFuncSource : public VRTSource
00584 {
00585 public:
00586             VRTFuncSource();
00587     virtual ~VRTFuncSource();
00588 
00589     virtual CPLErr  XMLInit( CPLXMLNode *, const char *) { return CE_Failure; }
00590     virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00591 
00592     virtual CPLErr  RasterIO( int nXOff, int nYOff, int nXSize, int nYSize, 
00593                               void *pData, int nBufXSize, int nBufYSize, 
00594                               GDALDataType eBufType, 
00595                               int nPixelSpace, int nLineSpace );
00596 
00597     VRTImageReadFunc    pfnReadFunc;
00598     void               *pCBData;
00599     GDALDataType        eType;
00600     
00601     float               fNoDataValue;
00602 };
00603 
00604 #endif /* ndef VIRTUALDATASET_H_INCLUDED */

Generated on Sun Jul 2 22:18:26 2006 for GDAL by  doxygen 1.4.6