00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef VIRTUALDATASET_H_INCLUDED
00032 #define VIRTUALDATASET_H_INCLUDED
00033
00034 #include "cpl_hash_set.h"
00035 #include "gdal_pam.h"
00036 #include "gdal_priv.h"
00037 #include "gdal_vrt.h"
00038
00039 #include <map>
00040 #include <vector>
00041
00042 int VRTApplyMetadata( CPLXMLNode *, GDALMajorObject * );
00043 CPLXMLNode *VRTSerializeMetadata( GDALMajorObject * );
00044
00045 #if 0
00046 int VRTWarpedOverviewTransform( void *pTransformArg, int bDstToSrc,
00047 int nPointCount,
00048 double *padfX, double *padfY, double *padfZ,
00049 int *panSuccess );
00050 void* VRTDeserializeWarpedOverviewTransformer( CPLXMLNode *psTree );
00051 #endif
00052
00053
00054
00055
00056 class VRTOverviewInfo
00057 {
00058 public:
00059 CPLString osFilename;
00060 int nBand;
00061 GDALRasterBand *poBand;
00062 int bTriedToOpen;
00063
00064 VRTOverviewInfo() : nBand(0), poBand(NULL), bTriedToOpen(FALSE) {}
00065 ~VRTOverviewInfo() {
00066 if( poBand == NULL )
00067 ;
00068 else if( poBand->GetDataset()->GetShared() )
00069 GDALClose( (GDALDatasetH) poBand->GetDataset() );
00070 else
00071 poBand->GetDataset()->Dereference();
00072 }
00073 };
00074
00075
00076
00077
00078
00079
00080 class CPL_DLL VRTSource
00081 {
00082 public:
00083 virtual ~VRTSource();
00084
00085 virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
00086 void *pData, int nBufXSize, int nBufYSize,
00087 GDALDataType eBufType,
00088 GSpacing nPixelSpace, GSpacing nLineSpace,
00089 GDALRasterIOExtraArg* psExtraArg ) = 0;
00090
00091 virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess ) = 0;
00092 virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess ) = 0;
00093 virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax ) = 0;
00094 virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
00095 int bApproxOK,
00096 double *pdfMin, double *pdfMax,
00097 double *pdfMean, double *pdfStdDev,
00098 GDALProgressFunc pfnProgress, void *pProgressData ) = 0;
00099 virtual CPLErr GetHistogram( int nXSize, int nYSize,
00100 double dfMin, double dfMax,
00101 int nBuckets, GUIntBig * panHistogram,
00102 int bIncludeOutOfRange, int bApproxOK,
00103 GDALProgressFunc pfnProgress, void *pProgressData ) = 0;
00104
00105 virtual CPLErr XMLInit( CPLXMLNode *psTree, const char * ) = 0;
00106 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ) = 0;
00107
00108 virtual void GetFileList(char*** ppapszFileList, int *pnSize,
00109 int *pnMaxSize, CPLHashSet* hSetFiles);
00110
00111 virtual int IsSimpleSource() { return FALSE; }
00112 };
00113
00114 typedef VRTSource *(*VRTSourceParser)(CPLXMLNode *, const char *);
00115
00116 VRTSource *VRTParseCoreSources( CPLXMLNode *psTree, const char * );
00117 VRTSource *VRTParseFilterSources( CPLXMLNode *psTree, const char * );
00118
00119
00120
00121
00122
00123 class VRTRasterBand;
00124
00125 class CPL_DLL VRTDataset : public GDALDataset
00126 {
00127 friend class VRTRasterBand;
00128
00129 char *m_pszProjection;
00130
00131 int m_bGeoTransformSet;
00132 double m_adfGeoTransform[6];
00133
00134 int m_nGCPCount;
00135 GDAL_GCP *m_pasGCPList;
00136 char *m_pszGCPProjection;
00137
00138 int m_bNeedsFlush;
00139 int m_bWritable;
00140
00141 char *m_pszVRTPath;
00142
00143 VRTRasterBand *m_poMaskBand;
00144
00145 int m_bCompatibleForDatasetIO;
00146 int CheckCompatibleForDatasetIO();
00147 std::vector<GDALDataset*> m_apoOverviews;
00148 std::vector<GDALDataset*> m_apoOverviewsBak;
00149
00150 protected:
00151 virtual int CloseDependentDatasets();
00152
00153 public:
00154 VRTDataset(int nXSize, int nYSize);
00155 virtual ~VRTDataset();
00156
00157 void SetNeedsFlush() { m_bNeedsFlush = TRUE; }
00158 virtual void FlushCache();
00159
00160 void SetWritable(int bWritableIn) { m_bWritable = bWritableIn; }
00161
00162 virtual CPLErr CreateMaskBand( int nFlags );
00163 void SetMaskBand(VRTRasterBand* poMaskBand);
00164
00165 virtual const char *GetProjectionRef(void);
00166 virtual CPLErr SetProjection( const char * );
00167 virtual CPLErr GetGeoTransform( double * );
00168 virtual CPLErr SetGeoTransform( double * );
00169
00170 virtual CPLErr SetMetadata( char **papszMD, const char *pszDomain = "" );
00171 virtual CPLErr SetMetadataItem( const char *pszName, const char *pszValue,
00172 const char *pszDomain = "" );
00173
00174 virtual char** GetMetadata( const char *pszDomain = "" );
00175
00176 virtual int GetGCPCount();
00177 virtual const char *GetGCPProjection();
00178 virtual const GDAL_GCP *GetGCPs();
00179 virtual CPLErr SetGCPs( int nGCPCount, const GDAL_GCP *pasGCPList,
00180 const char *pszGCPProjection );
00181
00182 virtual CPLErr AddBand( GDALDataType eType,
00183 char **papszOptions=NULL );
00184
00185 virtual char **GetFileList();
00186
00187 virtual CPLErr IRasterIO( GDALRWFlag eRWFlag,
00188 int nXOff, int nYOff, int nXSize, int nYSize,
00189 void * pData, int nBufXSize, int nBufYSize,
00190 GDALDataType eBufType,
00191 int nBandCount, int *panBandMap,
00192 GSpacing nPixelSpace, GSpacing nLineSpace,
00193 GSpacing nBandSpace,
00194 GDALRasterIOExtraArg* psExtraArg);
00195
00196 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath);
00197 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00198
00199 virtual CPLErr IBuildOverviews( const char *, int, int *,
00200 int, int *, GDALProgressFunc, void * );
00201
00202
00203 GDALDataset* GetSingleSimpleSource();
00204 void BuildVirtualOverviews();
00205
00206 void UnsetPreservedRelativeFilenames();
00207
00208 static int Identify( GDALOpenInfo * );
00209 static GDALDataset *Open( GDALOpenInfo * );
00210 static GDALDataset *OpenXML( const char *, const char * = NULL, GDALAccess eAccess = GA_ReadOnly );
00211 static GDALDataset *Create( const char * pszName,
00212 int nXSize, int nYSize, int nBands,
00213 GDALDataType eType, char ** papszOptions );
00214 static CPLErr Delete( const char * pszFilename );
00215 };
00216
00217
00218
00219
00220
00221 class GDALWarpOperation;
00222 class VRTWarpedRasterBand;
00223
00224 class CPL_DLL VRTWarpedDataset : public VRTDataset
00225 {
00226 int m_nBlockXSize;
00227 int m_nBlockYSize;
00228 GDALWarpOperation *m_poWarper;
00229
00230 int m_nOverviewCount;
00231 VRTWarpedDataset **m_papoOverviews;
00232 int m_nSrcOvrLevel;
00233
00234 void CreateImplicitOverviews();
00235
00236 friend class VRTWarpedRasterBand;
00237
00238 protected:
00239 virtual int CloseDependentDatasets();
00240
00241 public:
00242 VRTWarpedDataset( int nXSize, int nYSize );
00243 virtual ~VRTWarpedDataset();
00244
00245 CPLErr Initialize( void * );
00246
00247 virtual CPLErr IBuildOverviews( const char *, int, int *,
00248 int, int *, GDALProgressFunc, void * );
00249
00250 virtual CPLErr SetMetadataItem( const char *pszName, const char *pszValue,
00251 const char *pszDomain = "" );
00252
00253 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00254 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00255
00256 virtual CPLErr AddBand( GDALDataType eType,
00257 char **papszOptions=NULL );
00258
00259 virtual char **GetFileList();
00260
00261 CPLErr ProcessBlock( int iBlockX, int iBlockY );
00262
00263 void GetBlockSize( int *, int * );
00264 };
00265
00266
00267
00268
00269
00270 class GDALPansharpenOperation;
00271
00272 typedef enum
00273 {
00274 GTAdjust_Union,
00275 GTAdjust_Intersection,
00276 GTAdjust_None,
00277 GTAdjust_NoneWithoutWarning
00278 } GTAdjustment;
00279
00280 class VRTPansharpenedDataset : public VRTDataset
00281 {
00282 friend class VRTPansharpenedRasterBand;
00283
00284 int m_nBlockXSize;
00285 int m_nBlockYSize;
00286 GDALPansharpenOperation* m_poPansharpener;
00287 VRTPansharpenedDataset* m_poMainDataset;
00288 std::vector<VRTPansharpenedDataset*> m_apoOverviewDatasets;
00289 std::map<CPLString,CPLString> m_oMapToRelativeFilenames;
00290
00291 int m_bLoadingOtherBands;
00292
00293 GByte *m_pabyLastBufferBandRasterIO;
00294 int m_nLastBandRasterIOXOff;
00295 int m_nLastBandRasterIOYOff;
00296 int m_nLastBandRasterIOXSize;
00297 int m_nLastBandRasterIOYSize;
00298 GDALDataType m_eLastBandRasterIODataType;
00299
00300 GTAdjustment m_eGTAdjustment;
00301 int m_bNoDataDisabled;
00302
00303 std::vector<GDALDataset*> m_apoDatasetsToClose;
00304
00305 protected:
00306 virtual int CloseDependentDatasets();
00307
00308 public:
00309 VRTPansharpenedDataset( int nXSize, int nYSize );
00310 ~VRTPansharpenedDataset();
00311
00312 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00313 virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
00314
00315 CPLErr XMLInit( CPLXMLNode *psTree, const char *pszVRTPath,
00316 GDALRasterBandH hPanchroBandIn,
00317 int nInputSpectralBandsIn,
00318 GDALRasterBandH* pahInputSpectralBandsIn );
00319
00320 virtual CPLErr AddBand( GDALDataType eType,
00321 char **papszOptions=NULL );
00322
00323 virtual char **GetFileList();
00324
00325 virtual CPLErr IRasterIO( GDALRWFlag eRWFlag,
00326 int nXOff, int nYOff, int nXSize, int nYSize,
00327 void * pData, int nBufXSize, int nBufYSize,
00328 GDALDataType eBufType,
00329 int nBandCount, int *panBandMap,
00330 GSpacing nPixelSpace, GSpacing nLineSpace,
00331 GSpacing nBandSpace,
00332 GDALRasterIOExtraArg* psExtraArg);
00333
00334 void GetBlockSize( int *, int * );
00335
00336 GDALPansharpenOperation* GetPansharpener() { return m_poPansharpener; }
00337 };
00338
00339
00340
00341
00342
00343
00344
00345
00346 class CPL_DLL VRTRasterBand : public GDALRasterBand
00347 {
00348 protected:
00349 int m_bIsMaskBand;
00350
00351 int m_bNoDataValueSet;
00352 int m_bHideNoDataValue;
00353 double m_dfNoDataValue;
00354
00355 GDALColorTable *m_poColorTable;
00356
00357 GDALColorInterp m_eColorInterp;
00358
00359 char *m_pszUnitType;
00360 char **m_papszCategoryNames;
00361
00362 double m_dfOffset;
00363 double m_dfScale;
00364
00365 CPLXMLNode *m_psSavedHistograms;
00366
00367 void Initialize( int nXSize, int nYSize );
00368
00369 std::vector<VRTOverviewInfo> m_apoOverviews;
00370
00371 VRTRasterBand *m_poMaskBand;
00372
00373 public:
00374
00375 VRTRasterBand();
00376 virtual ~VRTRasterBand();
00377
00378 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00379 virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
00380
00381 virtual CPLErr SetNoDataValue( double );
00382 virtual double GetNoDataValue( int *pbSuccess = NULL );
00383 virtual CPLErr DeleteNoDataValue();
00384
00385 virtual CPLErr SetColorTable( GDALColorTable * );
00386 virtual GDALColorTable *GetColorTable();
00387
00388 virtual CPLErr SetColorInterpretation( GDALColorInterp );
00389 virtual GDALColorInterp GetColorInterpretation();
00390
00391 virtual const char *GetUnitType();
00392 CPLErr SetUnitType( const char * );
00393
00394 virtual char **GetCategoryNames();
00395 virtual CPLErr SetCategoryNames( char ** );
00396
00397 virtual CPLErr SetMetadata( char **papszMD, const char *pszDomain = "" );
00398 virtual CPLErr SetMetadataItem( const char *pszName, const char *pszValue,
00399 const char *pszDomain = "" );
00400
00401 virtual double GetOffset( int *pbSuccess = NULL );
00402 CPLErr SetOffset( double );
00403 virtual double GetScale( int *pbSuccess = NULL );
00404 CPLErr SetScale( double );
00405
00406 virtual int GetOverviewCount();
00407 virtual GDALRasterBand *GetOverview(int);
00408
00409 virtual CPLErr GetHistogram( double dfMin, double dfMax,
00410 int nBuckets, GUIntBig * panHistogram,
00411 int bIncludeOutOfRange, int bApproxOK,
00412 GDALProgressFunc, void *pProgressData );
00413
00414 virtual CPLErr GetDefaultHistogram( double *pdfMin, double *pdfMax,
00415 int *pnBuckets, GUIntBig ** ppanHistogram,
00416 int bForce,
00417 GDALProgressFunc, void *pProgressData);
00418
00419 virtual CPLErr SetDefaultHistogram( double dfMin, double dfMax,
00420 int nBuckets, GUIntBig *panHistogram );
00421
00422 CPLErr CopyCommonInfoFrom( GDALRasterBand * );
00423
00424 virtual void GetFileList(char*** ppapszFileList, int *pnSize,
00425 int *pnMaxSize, CPLHashSet* hSetFiles);
00426
00427 virtual void SetDescription( const char * );
00428
00429 virtual GDALRasterBand *GetMaskBand();
00430 virtual int GetMaskFlags();
00431
00432 virtual CPLErr CreateMaskBand( int nFlags );
00433
00434 void SetMaskBand(VRTRasterBand* poMaskBand);
00435
00436 void SetIsMaskBand();
00437
00438 CPLErr UnsetNoDataValue();
00439
00440 virtual int CloseDependentDatasets();
00441
00442 virtual int IsSourcedRasterBand() { return FALSE; }
00443 virtual int IsPansharpenRasterBand() { return FALSE; }
00444 };
00445
00446
00447
00448
00449
00450 class VRTSimpleSource;
00451
00452 class CPL_DLL VRTSourcedRasterBand : public VRTRasterBand
00453 {
00454 private:
00455 int m_nRecursionCounter;
00456 CPLString m_osLastLocationInfo;
00457 char **m_papszSourceList;
00458
00459 void Initialize( int nXSize, int nYSize );
00460
00461 int CanUseSourcesMinMaxImplementations();
00462
00463 public:
00464 int nSources;
00465 VRTSource **papoSources;
00466 int bEqualAreas;
00467
00468 VRTSourcedRasterBand( GDALDataset *poDS, int nBand );
00469 VRTSourcedRasterBand( GDALDataType eType,
00470 int nXSize, int nYSize );
00471 VRTSourcedRasterBand( GDALDataset *poDS, int nBand,
00472 GDALDataType eType,
00473 int nXSize, int nYSize );
00474 virtual ~VRTSourcedRasterBand();
00475
00476 virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
00477 void *, int, int, GDALDataType,
00478 GSpacing nPixelSpace, GSpacing nLineSpace,
00479 GDALRasterIOExtraArg* psExtraArg);
00480
00481 virtual char **GetMetadataDomainList();
00482 virtual const char *GetMetadataItem( const char * pszName,
00483 const char * pszDomain = "" );
00484 virtual char **GetMetadata( const char * pszDomain = "" );
00485 virtual CPLErr SetMetadata( char ** papszMetadata,
00486 const char * pszDomain = "" );
00487 virtual CPLErr SetMetadataItem( const char * pszName,
00488 const char * pszValue,
00489 const char * pszDomain = "" );
00490
00491 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00492 virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
00493
00494 virtual double GetMinimum( int *pbSuccess = NULL );
00495 virtual double GetMaximum(int *pbSuccess = NULL );
00496 virtual CPLErr ComputeRasterMinMax( int bApproxOK, double* adfMinMax );
00497 virtual CPLErr ComputeStatistics( int bApproxOK,
00498 double *pdfMin, double *pdfMax,
00499 double *pdfMean, double *pdfStdDev,
00500 GDALProgressFunc pfnProgress, void *pProgressData );
00501 virtual CPLErr GetHistogram( double dfMin, double dfMax,
00502 int nBuckets, GUIntBig * panHistogram,
00503 int bIncludeOutOfRange, int bApproxOK,
00504 GDALProgressFunc pfnProgress, void *pProgressData );
00505
00506 CPLErr AddSource( VRTSource * );
00507 CPLErr AddSimpleSource( GDALRasterBand *poSrcBand,
00508 double dfSrcXOff=-1, double dfSrcYOff=-1,
00509 double dfSrcXSize=-1, double dfSrcYSize=-1,
00510 double dfDstXOff=-1, double dfDstYOff=-1,
00511 double dfDstXSize=-1, double dfDstYSize=-1,
00512 const char *pszResampling = "near",
00513 double dfNoDataValue = VRT_NODATA_UNSET);
00514 CPLErr AddComplexSource( GDALRasterBand *poSrcBand,
00515 double dfSrcXOff=-1, double dfSrcYOff=-1,
00516 double dfSrcXSize=-1, double dfSrcYSize=-1,
00517 double dfDstXOff=-1, double dfDstYOff=-1,
00518 double dfDstXSize=-1, double dfDstYSize=-1,
00519 double dfScaleOff=0.0,
00520 double dfScaleRatio=1.0,
00521 double dfNoDataValue = VRT_NODATA_UNSET,
00522 int nColorTableComponent = 0);
00523
00524 CPLErr AddMaskBandSource( GDALRasterBand *poSrcBand,
00525 double dfSrcXOff=-1, double dfSrcYOff=-1,
00526 double dfSrcXSize=-1, double dfSrcYSize=-1,
00527 double dfDstXOff=-1, double dfDstYOff=-1,
00528 double dfDstXSize=-1, double dfDstYSize=-1 );
00529
00530 CPLErr AddFuncSource( VRTImageReadFunc pfnReadFunc, void *hCBData,
00531 double dfNoDataValue = VRT_NODATA_UNSET );
00532
00533 void ConfigureSource(VRTSimpleSource *poSimpleSource,
00534 GDALRasterBand *poSrcBand,
00535 int bAddAsMaskBand,
00536 double dfSrcXOff, double dfSrcYOff,
00537 double dfSrcXSize, double dfSrcYSize,
00538 double dfDstXOff, double dfDstYOff,
00539 double dfDstXSize, double dfDstYSize);
00540
00541 virtual CPLErr IReadBlock( int, int, void * );
00542
00543 virtual void GetFileList(char*** ppapszFileList, int *pnSize,
00544 int *pnMaxSize, CPLHashSet* hSetFiles);
00545
00546 virtual int CloseDependentDatasets();
00547
00548 virtual int IsSourcedRasterBand() { return TRUE; }
00549 };
00550
00551
00552
00553
00554
00555 class CPL_DLL VRTWarpedRasterBand : public VRTRasterBand
00556 {
00557 public:
00558 VRTWarpedRasterBand( GDALDataset *poDS, int nBand,
00559 GDALDataType eType = GDT_Unknown );
00560 virtual ~VRTWarpedRasterBand();
00561
00562 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00563 virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
00564
00565 virtual CPLErr IReadBlock( int, int, void * );
00566 virtual CPLErr IWriteBlock( int, int, void * );
00567
00568 virtual int GetOverviewCount();
00569 virtual GDALRasterBand *GetOverview(int);
00570 };
00571
00572
00573
00574
00575 class VRTPansharpenedRasterBand : public VRTRasterBand
00576 {
00577 int m_nIndexAsPansharpenedBand;
00578
00579 public:
00580 VRTPansharpenedRasterBand( GDALDataset *poDS, int nBand,
00581 GDALDataType eDataType = GDT_Unknown );
00582 virtual ~VRTPansharpenedRasterBand();
00583
00584 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00585 virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
00586
00587 virtual CPLErr IReadBlock( int, int, void * );
00588
00589 virtual CPLErr IRasterIO( GDALRWFlag eRWFlag,
00590 int nXOff, int nYOff, int nXSize, int nYSize,
00591 void * pData, int nBufXSize, int nBufYSize,
00592 GDALDataType eBufType,
00593 GSpacing nPixelSpace, GSpacing nLineSpace,
00594 GDALRasterIOExtraArg* psExtraArg);
00595
00596 virtual int GetOverviewCount();
00597 virtual GDALRasterBand *GetOverview(int);
00598
00599 virtual int IsPansharpenRasterBand() { return TRUE; }
00600
00601 void SetIndexAsPansharpenedBand(int nIdx) { m_nIndexAsPansharpenedBand = nIdx; }
00602 int GetIndexAsPansharpenedBand() const { return m_nIndexAsPansharpenedBand; }
00603 };
00604
00605
00606
00607
00608
00609 class CPL_DLL VRTDerivedRasterBand : public VRTSourcedRasterBand
00610 {
00611
00612 public:
00613 char *pszFuncName;
00614 GDALDataType eSourceTransferType;
00615
00616 VRTDerivedRasterBand(GDALDataset *poDS, int nBand);
00617 VRTDerivedRasterBand(GDALDataset *poDS, int nBand,
00618 GDALDataType eType, int nXSize, int nYSize);
00619 virtual ~VRTDerivedRasterBand();
00620
00621 virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
00622 void *, int, int, GDALDataType,
00623 GSpacing nPixelSpace, GSpacing nLineSpace,
00624 GDALRasterIOExtraArg* psExtraArg );
00625
00626 static CPLErr AddPixelFunction
00627 (const char *pszFuncName, GDALDerivedPixelFunc pfnPixelFunc);
00628 static GDALDerivedPixelFunc GetPixelFunction(const char *pszFuncName);
00629
00630 void SetPixelFunctionName(const char *pszFuncName);
00631 void SetSourceTransferType(GDALDataType eDataType);
00632
00633 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00634 virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
00635
00636 };
00637
00638
00639
00640
00641
00642 class RawRasterBand;
00643
00644 class CPL_DLL VRTRawRasterBand : public VRTRasterBand
00645 {
00646 RawRasterBand *m_poRawRaster;
00647
00648 char *m_pszSourceFilename;
00649 int m_bRelativeToVRT;
00650
00651 public:
00652 VRTRawRasterBand( GDALDataset *poDS, int nBand,
00653 GDALDataType eType = GDT_Unknown );
00654 virtual ~VRTRawRasterBand();
00655
00656 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00657 virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
00658
00659 virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
00660 void *, int, int, GDALDataType,
00661 GSpacing nPixelSpace, GSpacing nLineSpace,
00662 GDALRasterIOExtraArg* psExtraArg );
00663
00664 virtual CPLErr IReadBlock( int, int, void * );
00665 virtual CPLErr IWriteBlock( int, int, void * );
00666
00667 CPLErr SetRawLink( const char *pszFilename,
00668 const char *pszVRTPath,
00669 int bRelativeToVRT,
00670 vsi_l_offset nImageOffset,
00671 int nPixelOffset, int nLineOffset,
00672 const char *pszByteOrder );
00673
00674 void ClearRawLink();
00675
00676 virtual void GetFileList(char*** ppapszFileList, int *pnSize,
00677 int *pnMaxSize, CPLHashSet* hSetFiles);
00678 };
00679
00680
00681
00682
00683
00684 class VRTDriver : public GDALDriver
00685 {
00686 void *m_pDeserializerData;
00687
00688 public:
00689 VRTDriver();
00690 ~VRTDriver();
00691
00692 char **papszSourceParsers;
00693
00694 virtual char **GetMetadataDomainList();
00695 virtual char **GetMetadata( const char * pszDomain = "" );
00696 virtual CPLErr SetMetadata( char ** papszMetadata,
00697 const char * pszDomain = "" );
00698
00699 VRTSource *ParseSource( CPLXMLNode *psSrc, const char *pszVRTPath );
00700 void AddSourceParser( const char *pszElementName,
00701 VRTSourceParser pfnParser );
00702 };
00703
00704
00705
00706
00707
00708 class CPL_DLL VRTSimpleSource : public VRTSource
00709 {
00710 protected:
00711 GDALRasterBand *m_poRasterBand;
00712
00713
00714
00715 GDALRasterBand *m_poMaskBandMainBand;
00716
00717 double m_dfSrcXOff;
00718 double m_dfSrcYOff;
00719 double m_dfSrcXSize;
00720 double m_dfSrcYSize;
00721
00722 double m_dfDstXOff;
00723 double m_dfDstYOff;
00724 double m_dfDstXSize;
00725 double m_dfDstYSize;
00726
00727 int m_bNoDataSet;
00728 double m_dfNoDataValue;
00729 CPLString m_osResampling;
00730
00731 int m_nMaxValue;
00732
00733 int m_bRelativeToVRTOri;
00734 CPLString m_osSourceFileNameOri;
00735
00736 int NeedMaxValAdjustment() const;
00737
00738 public:
00739 VRTSimpleSource();
00740 VRTSimpleSource(const VRTSimpleSource* poSrcSource,
00741 double dfXDstRatio, double dfYDstRatio);
00742 virtual ~VRTSimpleSource();
00743
00744 virtual CPLErr XMLInit( CPLXMLNode *psTree, const char * );
00745 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00746
00747 void SetSrcBand( GDALRasterBand * );
00748 void SetSrcMaskBand( GDALRasterBand * );
00749 void SetSrcWindow( double, double, double, double );
00750 void SetDstWindow( double, double, double, double );
00751 void SetNoDataValue( double dfNoDataValue );
00752 const CPLString& GetResampling() const { return m_osResampling; }
00753 void SetResampling( const char* pszResampling );
00754
00755 int GetSrcDstWindow( int, int, int, int, int, int,
00756 double *pdfReqXOff, double *pdfReqYOff,
00757 double *pdfReqXSize, double *pdfReqYSize,
00758 int *, int *, int *, int *,
00759 int *, int *, int *, int * );
00760
00761 virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
00762 void *pData, int nBufXSize, int nBufYSize,
00763 GDALDataType eBufType,
00764 GSpacing nPixelSpace, GSpacing nLineSpace,
00765 GDALRasterIOExtraArg* psExtraArg );
00766
00767 virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess );
00768 virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess );
00769 virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax );
00770 virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
00771 int bApproxOK,
00772 double *pdfMin, double *pdfMax,
00773 double *pdfMean, double *pdfStdDev,
00774 GDALProgressFunc pfnProgress, void *pProgressData );
00775 virtual CPLErr GetHistogram( int nXSize, int nYSize,
00776 double dfMin, double dfMax,
00777 int nBuckets, GUIntBig * panHistogram,
00778 int bIncludeOutOfRange, int bApproxOK,
00779 GDALProgressFunc pfnProgress, void *pProgressData );
00780
00781 void DstToSrc( double dfX, double dfY,
00782 double &dfXOut, double &dfYOut );
00783 void SrcToDst( double dfX, double dfY,
00784 double &dfXOut, double &dfYOut );
00785
00786 virtual void GetFileList(char*** ppapszFileList, int *pnSize,
00787 int *pnMaxSize, CPLHashSet* hSetFiles);
00788
00789 virtual int IsSimpleSource() { return TRUE; }
00790 virtual const char* GetType() { return "SimpleSource"; }
00791
00792 GDALRasterBand* GetBand();
00793 int IsSameExceptBandNumber(VRTSimpleSource* poOtherSource);
00794 CPLErr DatasetRasterIO(
00795 int nXOff, int nYOff, int nXSize, int nYSize,
00796 void * pData, int nBufXSize, int nBufYSize,
00797 GDALDataType eBufType,
00798 int nBandCount, int *panBandMap,
00799 GSpacing nPixelSpace, GSpacing nLineSpace,
00800 GSpacing nBandSpace,
00801 GDALRasterIOExtraArg* psExtraArg);
00802
00803 void UnsetPreservedRelativeFilenames();
00804
00805 void SetMaxValue(int nVal) { m_nMaxValue = nVal; }
00806 };
00807
00808
00809
00810
00811
00812 class VRTAveragedSource : public VRTSimpleSource
00813 {
00814 public:
00815 VRTAveragedSource();
00816 virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
00817 void *pData, int nBufXSize, int nBufYSize,
00818 GDALDataType eBufType,
00819 GSpacing nPixelSpace, GSpacing nLineSpace,
00820 GDALRasterIOExtraArg* psExtraArg );
00821
00822 virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess );
00823 virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess );
00824 virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax );
00825 virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
00826 int bApproxOK,
00827 double *pdfMin, double *pdfMax,
00828 double *pdfMean, double *pdfStdDev,
00829 GDALProgressFunc pfnProgress, void *pProgressData );
00830 virtual CPLErr GetHistogram( int nXSize, int nYSize,
00831 double dfMin, double dfMax,
00832 int nBuckets, GUIntBig * panHistogram,
00833 int bIncludeOutOfRange, int bApproxOK,
00834 GDALProgressFunc pfnProgress, void *pProgressData );
00835
00836 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00837 virtual const char* GetType() { return "AveragedSource"; }
00838 };
00839
00840
00841
00842
00843
00844 typedef enum
00845 {
00846 VRT_SCALING_NONE,
00847 VRT_SCALING_LINEAR,
00848 VRT_SCALING_EXPONENTIAL,
00849 } VRTComplexSourceScaling;
00850
00851 class CPL_DLL VRTComplexSource : public VRTSimpleSource
00852 {
00853 protected:
00854 VRTComplexSourceScaling m_eScalingType;
00855 double m_dfScaleOff;
00856 double m_dfScaleRatio;
00857
00858
00859 int m_bSrcMinMaxDefined;
00860 double m_dfSrcMin;
00861 double m_dfSrcMax;
00862 double m_dfDstMin;
00863 double m_dfDstMax;
00864 double m_dfExponent;
00865
00866 int m_nColorTableComponent;
00867
00868 template <class WorkingDT>
00869 CPLErr RasterIOInternal( int nReqXOff, int nReqYOff,
00870 int nReqXSize, int nReqYSize,
00871 void *pData, int nOutXSize, int nOutYSize,
00872 GDALDataType eBufType,
00873 GSpacing nPixelSpace, GSpacing nLineSpace,
00874 GDALRasterIOExtraArg* psExtraArg,
00875 GDALDataType eWrkDataType );
00876
00877 public:
00878 VRTComplexSource();
00879 VRTComplexSource(const VRTComplexSource* poSrcSource,
00880 double dfXDstRatio, double dfYDstRatio);
00881 virtual ~VRTComplexSource();
00882
00883 virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
00884 void *pData, int nBufXSize, int nBufYSize,
00885 GDALDataType eBufType,
00886 GSpacing nPixelSpace, GSpacing nLineSpace,
00887 GDALRasterIOExtraArg* psExtraArg );
00888
00889 virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess );
00890 virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess );
00891 virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax );
00892 virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
00893 int bApproxOK,
00894 double *pdfMin, double *pdfMax,
00895 double *pdfMean, double *pdfStdDev,
00896 GDALProgressFunc pfnProgress, void *pProgressData );
00897 virtual CPLErr GetHistogram( int nXSize, int nYSize,
00898 double dfMin, double dfMax,
00899 int nBuckets, GUIntBig * panHistogram,
00900 int bIncludeOutOfRange, int bApproxOK,
00901 GDALProgressFunc pfnProgress, void *pProgressData );
00902
00903 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00904 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
00905 virtual const char* GetType() { return "ComplexSource"; }
00906
00907 double LookupValue( double dfInput );
00908
00909 void SetLinearScaling(double dfOffset, double dfScale);
00910 void SetPowerScaling(double dfExponent,
00911 double dfSrcMin,
00912 double dfSrcMax,
00913 double dfDstMin,
00914 double dfDstMax);
00915 void SetColorTableComponent(int nComponent);
00916
00917 double *m_padfLUTInputs;
00918 double *m_padfLUTOutputs;
00919 int m_nLUTItemCount;
00920
00921 };
00922
00923
00924
00925
00926
00927 class VRTFilteredSource : public VRTComplexSource
00928 {
00929 private:
00930 int IsTypeSupported( GDALDataType eType );
00931
00932 protected:
00933 int m_nSupportedTypesCount;
00934 GDALDataType m_aeSupportedTypes[20];
00935
00936 int m_nExtraEdgePixels;
00937
00938 public:
00939 VRTFilteredSource();
00940 virtual ~VRTFilteredSource();
00941
00942 void SetExtraEdgePixels( int );
00943 void SetFilteringDataTypesSupported( int, GDALDataType * );
00944
00945 virtual CPLErr FilterData( int nXSize, int nYSize, GDALDataType eType,
00946 GByte *pabySrcData, GByte *pabyDstData ) = 0;
00947
00948 virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
00949 void *pData, int nBufXSize, int nBufYSize,
00950 GDALDataType eBufType,
00951 GSpacing nPixelSpace, GSpacing nLineSpace,
00952 GDALRasterIOExtraArg* psExtraArg );
00953 };
00954
00955
00956
00957
00958
00959 class VRTKernelFilteredSource : public VRTFilteredSource
00960 {
00961 protected:
00962 int m_nKernelSize;
00963
00964 double *m_padfKernelCoefs;
00965
00966 int m_bNormalized;
00967
00968 public:
00969 VRTKernelFilteredSource();
00970 virtual ~VRTKernelFilteredSource();
00971
00972 virtual CPLErr XMLInit( CPLXMLNode *psTree, const char * );
00973 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00974
00975 virtual CPLErr FilterData( int nXSize, int nYSize, GDALDataType eType,
00976 GByte *pabySrcData, GByte *pabyDstData );
00977
00978 CPLErr SetKernel( int nKernelSize, double *padfCoefs );
00979 void SetNormalized( int );
00980 };
00981
00982
00983
00984
00985
00986 class VRTAverageFilteredSource : public VRTKernelFilteredSource
00987 {
00988 public:
00989 explicit VRTAverageFilteredSource( int nKernelSize );
00990 virtual ~VRTAverageFilteredSource();
00991
00992 virtual CPLErr XMLInit( CPLXMLNode *psTree, const char * );
00993 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
00994 };
00995
00996
00997
00998
00999 class VRTFuncSource : public VRTSource
01000 {
01001 public:
01002 VRTFuncSource();
01003 virtual ~VRTFuncSource();
01004
01005 virtual CPLErr XMLInit( CPLXMLNode *, const char *) { return CE_Failure; }
01006 virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
01007
01008 virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
01009 void *pData, int nBufXSize, int nBufYSize,
01010 GDALDataType eBufType,
01011 GSpacing nPixelSpace, GSpacing nLineSpace,
01012 GDALRasterIOExtraArg* psExtraArg );
01013
01014 virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess );
01015 virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess );
01016 virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax );
01017 virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
01018 int bApproxOK,
01019 double *pdfMin, double *pdfMax,
01020 double *pdfMean, double *pdfStdDev,
01021 GDALProgressFunc pfnProgress, void *pProgressData );
01022 virtual CPLErr GetHistogram( int nXSize, int nYSize,
01023 double dfMin, double dfMax,
01024 int nBuckets, GUIntBig * panHistogram,
01025 int bIncludeOutOfRange, int bApproxOK,
01026 GDALProgressFunc pfnProgress, void *pProgressData );
01027
01028 VRTImageReadFunc pfnReadFunc;
01029 void *pCBData;
01030 GDALDataType eType;
01031
01032 float fNoDataValue;
01033 };
01034
01035 #endif