vrtdataset.h

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

Generated on Mon Jan 9 18:03:35 2006 for GDAL by  doxygen 1.4.6