1 : /******************************************************************************
2 : * $Id: vrtdataset.h 25109 2012-10-13 11:51:23Z rouault $
3 : *
4 : * Project: Virtual GDAL Datasets
5 : * Purpose: Declaration of virtual gdal dataset classes.
6 : * Author: Frank Warmerdam, warmerdam@pobox.com
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2001, Frank Warmerdam <warmerdam@pobox.com>
10 : *
11 : * Permission is hereby granted, free of charge, to any person obtaining a
12 : * copy of this software and associated documentation files (the "Software"),
13 : * to deal in the Software without restriction, including without limitation
14 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 : * and/or sell copies of the Software, and to permit persons to whom the
16 : * Software is furnished to do so, subject to the following conditions:
17 : *
18 : * The above copyright notice and this permission notice shall be included
19 : * in all copies or substantial portions of the Software.
20 : *
21 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 : * DEALINGS IN THE SOFTWARE.
28 : ****************************************************************************/
29 :
30 : #ifndef VIRTUALDATASET_H_INCLUDED
31 : #define VIRTUALDATASET_H_INCLUDED
32 :
33 : #include "gdal_priv.h"
34 : #include "gdal_pam.h"
35 : #include "gdal_vrt.h"
36 : #include "cpl_hash_set.h"
37 :
38 : int VRTApplyMetadata( CPLXMLNode *, GDALMajorObject * );
39 : CPLXMLNode *VRTSerializeMetadata( GDALMajorObject * );
40 :
41 : int VRTWarpedOverviewTransform( void *pTransformArg, int bDstToSrc,
42 : int nPointCount,
43 : double *padfX, double *padfY, double *padfZ,
44 : int *panSuccess );
45 : void* VRTDeserializeWarpedOverviewTransformer( CPLXMLNode *psTree );
46 :
47 : /************************************************************************/
48 : /* VRTOverviewInfo() */
49 : /************************************************************************/
50 : class VRTOverviewInfo
51 9 : {
52 : public:
53 : CPLString osFilename;
54 : int nBand;
55 : GDALRasterBand *poBand;
56 : int bTriedToOpen;
57 :
58 9 : VRTOverviewInfo() : poBand(NULL), bTriedToOpen(FALSE) {}
59 18 : ~VRTOverviewInfo() {
60 18 : if( poBand == NULL )
61 : /* do nothing */;
62 5 : else if( poBand->GetDataset()->GetShared() )
63 5 : GDALClose( (GDALDatasetH) poBand->GetDataset() );
64 : else
65 0 : poBand->GetDataset()->Dereference();
66 18 : }
67 : };
68 :
69 :
70 : /************************************************************************/
71 : /* VRTSource */
72 : /************************************************************************/
73 :
74 : class VRTSource
75 5567 : {
76 : public:
77 : virtual ~VRTSource();
78 :
79 : virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
80 : void *pData, int nBufXSize, int nBufYSize,
81 : GDALDataType eBufType,
82 : int nPixelSpace, int nLineSpace ) = 0;
83 :
84 : virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess ) = 0;
85 : virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess ) = 0;
86 : virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax ) = 0;
87 : virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
88 : int bApproxOK,
89 : double *pdfMin, double *pdfMax,
90 : double *pdfMean, double *pdfStdDev,
91 : GDALProgressFunc pfnProgress, void *pProgressData ) = 0;
92 : virtual CPLErr GetHistogram( int nXSize, int nYSize,
93 : double dfMin, double dfMax,
94 : int nBuckets, int * panHistogram,
95 : int bIncludeOutOfRange, int bApproxOK,
96 : GDALProgressFunc pfnProgress, void *pProgressData ) = 0;
97 :
98 : virtual CPLErr XMLInit( CPLXMLNode *psTree, const char * ) = 0;
99 : virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath ) = 0;
100 :
101 : virtual void GetFileList(char*** ppapszFileList, int *pnSize,
102 : int *pnMaxSize, CPLHashSet* hSetFiles);
103 :
104 0 : virtual int IsSimpleSource() { return FALSE; }
105 : };
106 :
107 : typedef VRTSource *(*VRTSourceParser)(CPLXMLNode *, const char *);
108 :
109 : VRTSource *VRTParseCoreSources( CPLXMLNode *psTree, const char * );
110 : VRTSource *VRTParseFilterSources( CPLXMLNode *psTree, const char * );
111 :
112 : /************************************************************************/
113 : /* VRTDataset */
114 : /************************************************************************/
115 :
116 : class VRTRasterBand;
117 :
118 : class CPL_DLL VRTDataset : public GDALDataset
119 : {
120 : friend class VRTRasterBand;
121 :
122 : char *pszProjection;
123 :
124 : int bGeoTransformSet;
125 : double adfGeoTransform[6];
126 :
127 : int nGCPCount;
128 : GDAL_GCP *pasGCPList;
129 : char *pszGCPProjection;
130 :
131 : int bNeedsFlush;
132 : int bWritable;
133 :
134 : char *pszVRTPath;
135 :
136 : VRTRasterBand *poMaskBand;
137 :
138 : int bCompatibleForDatasetIO;
139 : int CheckCompatibleForDatasetIO();
140 :
141 : protected:
142 : virtual int CloseDependentDatasets();
143 :
144 : public:
145 : VRTDataset(int nXSize, int nYSize);
146 : ~VRTDataset();
147 :
148 9622 : void SetNeedsFlush() { bNeedsFlush = TRUE; }
149 : virtual void FlushCache();
150 :
151 : void SetWritable(int bWritable) { this->bWritable = bWritable; }
152 :
153 : virtual CPLErr CreateMaskBand( int nFlags );
154 : void SetMaskBand(VRTRasterBand* poMaskBand);
155 :
156 : virtual const char *GetProjectionRef(void);
157 : virtual CPLErr SetProjection( const char * );
158 : virtual CPLErr GetGeoTransform( double * );
159 : virtual CPLErr SetGeoTransform( double * );
160 :
161 : virtual CPLErr SetMetadata( char **papszMD, const char *pszDomain = "" );
162 : virtual CPLErr SetMetadataItem( const char *pszName, const char *pszValue,
163 : const char *pszDomain = "" );
164 :
165 : virtual int GetGCPCount();
166 : virtual const char *GetGCPProjection();
167 : virtual const GDAL_GCP *GetGCPs();
168 : virtual CPLErr SetGCPs( int nGCPCount, const GDAL_GCP *pasGCPList,
169 : const char *pszGCPProjection );
170 :
171 : virtual CPLErr AddBand( GDALDataType eType,
172 : char **papszOptions=NULL );
173 :
174 : virtual char **GetFileList();
175 :
176 : virtual CPLErr IRasterIO( GDALRWFlag eRWFlag,
177 : int nXOff, int nYOff, int nXSize, int nYSize,
178 : void * pData, int nBufXSize, int nBufYSize,
179 : GDALDataType eBufType,
180 : int nBandCount, int *panBandMap,
181 : int nPixelSpace, int nLineSpace, int nBandSpace);
182 :
183 : virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath);
184 : virtual CPLErr XMLInit( CPLXMLNode *, const char * );
185 :
186 : /* Used by PDF driver for example */
187 : GDALDataset* GetSingleSimpleSource();
188 :
189 : static int Identify( GDALOpenInfo * );
190 : static GDALDataset *Open( GDALOpenInfo * );
191 : static GDALDataset *OpenXML( const char *, const char * = NULL, GDALAccess eAccess = GA_ReadOnly );
192 : static GDALDataset *Create( const char * pszName,
193 : int nXSize, int nYSize, int nBands,
194 : GDALDataType eType, char ** papszOptions );
195 : static CPLErr Delete( const char * pszFilename );
196 : };
197 :
198 : /************************************************************************/
199 : /* VRTWarpedDataset */
200 : /************************************************************************/
201 :
202 : class GDALWarpOperation;
203 : class VRTWarpedRasterBand;
204 :
205 : class CPL_DLL VRTWarpedDataset : public VRTDataset
206 : {
207 : int nBlockXSize;
208 : int nBlockYSize;
209 : GDALWarpOperation *poWarper;
210 :
211 : friend class VRTWarpedRasterBand;
212 :
213 : protected:
214 : virtual int CloseDependentDatasets();
215 :
216 : public:
217 : int nOverviewCount;
218 : VRTWarpedDataset **papoOverviews;
219 :
220 : public:
221 : VRTWarpedDataset( int nXSize, int nYSize );
222 : ~VRTWarpedDataset();
223 :
224 : CPLErr Initialize( /* GDALWarpOptions */ void * );
225 :
226 : virtual CPLErr IBuildOverviews( const char *, int, int *,
227 : int, int *, GDALProgressFunc, void * );
228 :
229 : virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
230 : virtual CPLErr XMLInit( CPLXMLNode *, const char * );
231 :
232 : virtual CPLErr AddBand( GDALDataType eType,
233 : char **papszOptions=NULL );
234 :
235 : virtual char **GetFileList();
236 :
237 : CPLErr ProcessBlock( int iBlockX, int iBlockY );
238 :
239 : void GetBlockSize( int *, int * );
240 : };
241 :
242 : /************************************************************************/
243 : /* VRTRasterBand */
244 : /* */
245 : /* Provides support for all the various kinds of metadata but */
246 : /* no raster access. That is handled by derived classes. */
247 : /************************************************************************/
248 :
249 : class CPL_DLL VRTRasterBand : public GDALRasterBand
250 : {
251 : protected:
252 : int bIsMaskBand;
253 :
254 : int bNoDataValueSet;
255 : int bHideNoDataValue; // If set to true, will not report the existance of nodata
256 : double dfNoDataValue;
257 :
258 : GDALColorTable *poColorTable;
259 :
260 : GDALColorInterp eColorInterp;
261 :
262 : char *pszUnitType;
263 : char **papszCategoryNames;
264 :
265 : double dfOffset;
266 : double dfScale;
267 :
268 : CPLXMLNode *psSavedHistograms;
269 :
270 : void Initialize( int nXSize, int nYSize );
271 :
272 : std::vector<VRTOverviewInfo> apoOverviews;
273 :
274 : VRTRasterBand *poMaskBand;
275 :
276 : public:
277 :
278 : VRTRasterBand();
279 : virtual ~VRTRasterBand();
280 :
281 : virtual CPLErr XMLInit( CPLXMLNode *, const char * );
282 : virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
283 :
284 : virtual CPLErr SetNoDataValue( double );
285 : virtual double GetNoDataValue( int *pbSuccess = NULL );
286 :
287 : virtual CPLErr SetColorTable( GDALColorTable * );
288 : virtual GDALColorTable *GetColorTable();
289 :
290 : virtual CPLErr SetColorInterpretation( GDALColorInterp );
291 : virtual GDALColorInterp GetColorInterpretation();
292 :
293 : virtual const char *GetUnitType();
294 : CPLErr SetUnitType( const char * );
295 :
296 : virtual char **GetCategoryNames();
297 : virtual CPLErr SetCategoryNames( char ** );
298 :
299 : virtual CPLErr SetMetadata( char **papszMD, const char *pszDomain = "" );
300 : virtual CPLErr SetMetadataItem( const char *pszName, const char *pszValue,
301 : const char *pszDomain = "" );
302 :
303 : virtual double GetOffset( int *pbSuccess = NULL );
304 : CPLErr SetOffset( double );
305 : virtual double GetScale( int *pbSuccess = NULL );
306 : CPLErr SetScale( double );
307 :
308 : virtual int GetOverviewCount();
309 : virtual GDALRasterBand *GetOverview(int);
310 :
311 : virtual CPLErr GetHistogram( double dfMin, double dfMax,
312 : int nBuckets, int * panHistogram,
313 : int bIncludeOutOfRange, int bApproxOK,
314 : GDALProgressFunc, void *pProgressData );
315 :
316 : virtual CPLErr GetDefaultHistogram( double *pdfMin, double *pdfMax,
317 : int *pnBuckets, int ** ppanHistogram,
318 : int bForce,
319 : GDALProgressFunc, void *pProgressData);
320 :
321 : virtual CPLErr SetDefaultHistogram( double dfMin, double dfMax,
322 : int nBuckets, int *panHistogram );
323 :
324 : CPLErr CopyCommonInfoFrom( GDALRasterBand * );
325 :
326 : virtual void GetFileList(char*** ppapszFileList, int *pnSize,
327 : int *pnMaxSize, CPLHashSet* hSetFiles);
328 :
329 : virtual void SetDescription( const char * );
330 :
331 : virtual GDALRasterBand *GetMaskBand();
332 : virtual int GetMaskFlags();
333 :
334 : virtual CPLErr CreateMaskBand( int nFlags );
335 :
336 : void SetMaskBand(VRTRasterBand* poMaskBand);
337 :
338 : void SetIsMaskBand();
339 :
340 : CPLErr UnsetNoDataValue();
341 :
342 : virtual int CloseDependentDatasets();
343 :
344 25 : virtual int IsSourcedRasterBand() { return FALSE; }
345 : };
346 :
347 : /************************************************************************/
348 : /* VRTSourcedRasterBand */
349 : /************************************************************************/
350 :
351 : class CPL_DLL VRTSourcedRasterBand : public VRTRasterBand
352 : {
353 : private:
354 : int bAntiRecursionFlag;
355 : CPLString osLastLocationInfo;
356 :
357 : void Initialize( int nXSize, int nYSize );
358 :
359 : public:
360 : int nSources;
361 : VRTSource **papoSources;
362 : int bEqualAreas;
363 :
364 : VRTSourcedRasterBand( GDALDataset *poDS, int nBand );
365 : VRTSourcedRasterBand( GDALDataType eType,
366 : int nXSize, int nYSize );
367 : VRTSourcedRasterBand( GDALDataset *poDS, int nBand,
368 : GDALDataType eType,
369 : int nXSize, int nYSize );
370 : virtual ~VRTSourcedRasterBand();
371 :
372 : virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
373 : void *, int, int, GDALDataType,
374 : int, int );
375 :
376 : virtual const char *GetMetadataItem( const char * pszName,
377 : const char * pszDomain = "" );
378 : virtual char **GetMetadata( const char * pszDomain = "" );
379 : virtual CPLErr SetMetadata( char ** papszMetadata,
380 : const char * pszDomain = "" );
381 : virtual CPLErr SetMetadataItem( const char * pszName,
382 : const char * pszValue,
383 : const char * pszDomain = "" );
384 :
385 : virtual CPLErr XMLInit( CPLXMLNode *, const char * );
386 : virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
387 :
388 : virtual double GetMinimum( int *pbSuccess = NULL );
389 : virtual double GetMaximum(int *pbSuccess = NULL );
390 : virtual CPLErr ComputeRasterMinMax( int bApproxOK, double* adfMinMax );
391 : virtual CPLErr ComputeStatistics( int bApproxOK,
392 : double *pdfMin, double *pdfMax,
393 : double *pdfMean, double *pdfStdDev,
394 : GDALProgressFunc pfnProgress, void *pProgressData );
395 : virtual CPLErr GetHistogram( double dfMin, double dfMax,
396 : int nBuckets, int * panHistogram,
397 : int bIncludeOutOfRange, int bApproxOK,
398 : GDALProgressFunc pfnProgress, void *pProgressData );
399 :
400 : CPLErr AddSource( VRTSource * );
401 : CPLErr AddSimpleSource( GDALRasterBand *poSrcBand,
402 : int nSrcXOff=-1, int nSrcYOff=-1,
403 : int nSrcXSize=-1, int nSrcYSize=-1,
404 : int nDstXOff=-1, int nDstYOff=-1,
405 : int nDstXSize=-1, int nDstYSize=-1,
406 : const char *pszResampling = "near",
407 : double dfNoDataValue = VRT_NODATA_UNSET);
408 : CPLErr AddComplexSource( GDALRasterBand *poSrcBand,
409 : int nSrcXOff=-1, int nSrcYOff=-1,
410 : int nSrcXSize=-1, int nSrcYSize=-1,
411 : int nDstXOff=-1, int nDstYOff=-1,
412 : int nDstXSize=-1, int nDstYSize=-1,
413 : double dfScaleOff=0.0,
414 : double dfScaleRatio=1.0,
415 : double dfNoDataValue = VRT_NODATA_UNSET,
416 : int nColorTableComponent = 0);
417 :
418 : CPLErr AddMaskBandSource( GDALRasterBand *poSrcBand,
419 : int nSrcXOff=-1, int nSrcYOff=-1,
420 : int nSrcXSize=-1, int nSrcYSize=-1,
421 : int nDstXOff=-1, int nDstYOff=-1,
422 : int nDstXSize=-1, int nDstYSize=-1 );
423 :
424 : CPLErr AddFuncSource( VRTImageReadFunc pfnReadFunc, void *hCBData,
425 : double dfNoDataValue = VRT_NODATA_UNSET );
426 :
427 :
428 : virtual CPLErr IReadBlock( int, int, void * );
429 :
430 : virtual void GetFileList(char*** ppapszFileList, int *pnSize,
431 : int *pnMaxSize, CPLHashSet* hSetFiles);
432 :
433 : virtual int CloseDependentDatasets();
434 :
435 1814 : virtual int IsSourcedRasterBand() { return TRUE; }
436 : };
437 :
438 : /************************************************************************/
439 : /* VRTWarpedRasterBand */
440 : /************************************************************************/
441 :
442 : class CPL_DLL VRTWarpedRasterBand : public VRTRasterBand
443 : {
444 : public:
445 : VRTWarpedRasterBand( GDALDataset *poDS, int nBand,
446 : GDALDataType eType = GDT_Unknown );
447 : virtual ~VRTWarpedRasterBand();
448 :
449 : virtual CPLErr XMLInit( CPLXMLNode *, const char * );
450 : virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
451 :
452 : virtual CPLErr IReadBlock( int, int, void * );
453 : virtual CPLErr IWriteBlock( int, int, void * );
454 :
455 : virtual int GetOverviewCount();
456 : virtual GDALRasterBand *GetOverview(int);
457 : };
458 :
459 : /************************************************************************/
460 : /* VRTDerivedRasterBand */
461 : /************************************************************************/
462 :
463 : class CPL_DLL VRTDerivedRasterBand : public VRTSourcedRasterBand
464 : {
465 :
466 : public:
467 : char *pszFuncName;
468 : GDALDataType eSourceTransferType;
469 :
470 : VRTDerivedRasterBand(GDALDataset *poDS, int nBand);
471 : VRTDerivedRasterBand(GDALDataset *poDS, int nBand,
472 : GDALDataType eType, int nXSize, int nYSize);
473 : virtual ~VRTDerivedRasterBand();
474 :
475 : virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
476 : void *, int, int, GDALDataType,
477 : int, int );
478 :
479 : static CPLErr AddPixelFunction
480 : (const char *pszFuncName, GDALDerivedPixelFunc pfnPixelFunc);
481 : static GDALDerivedPixelFunc GetPixelFunction(const char *pszFuncName);
482 :
483 : void SetPixelFunctionName(const char *pszFuncName);
484 : void SetSourceTransferType(GDALDataType eDataType);
485 :
486 : virtual CPLErr XMLInit( CPLXMLNode *, const char * );
487 : virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
488 :
489 : };
490 :
491 : /************************************************************************/
492 : /* VRTRawRasterBand */
493 : /************************************************************************/
494 :
495 : class RawRasterBand;
496 :
497 : class CPL_DLL VRTRawRasterBand : public VRTRasterBand
498 : {
499 : RawRasterBand *poRawRaster;
500 :
501 : char *pszSourceFilename;
502 : int bRelativeToVRT;
503 :
504 : public:
505 : VRTRawRasterBand( GDALDataset *poDS, int nBand,
506 : GDALDataType eType = GDT_Unknown );
507 : virtual ~VRTRawRasterBand();
508 :
509 : virtual CPLErr XMLInit( CPLXMLNode *, const char * );
510 : virtual CPLXMLNode * SerializeToXML( const char *pszVRTPath );
511 :
512 : virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
513 : void *, int, int, GDALDataType,
514 : int, int );
515 :
516 : virtual CPLErr IReadBlock( int, int, void * );
517 : virtual CPLErr IWriteBlock( int, int, void * );
518 :
519 : CPLErr SetRawLink( const char *pszFilename,
520 : const char *pszVRTPath,
521 : int bRelativeToVRT,
522 : vsi_l_offset nImageOffset,
523 : int nPixelOffset, int nLineOffset,
524 : const char *pszByteOrder );
525 :
526 : void ClearRawLink();
527 :
528 : virtual void GetFileList(char*** ppapszFileList, int *pnSize,
529 : int *pnMaxSize, CPLHashSet* hSetFiles);
530 : };
531 :
532 : /************************************************************************/
533 : /* VRTDriver */
534 : /************************************************************************/
535 :
536 : class VRTDriver : public GDALDriver
537 : {
538 : void *pDeserializerData;
539 :
540 : public:
541 : VRTDriver();
542 : ~VRTDriver();
543 :
544 : char **papszSourceParsers;
545 :
546 : virtual char **GetMetadata( const char * pszDomain = "" );
547 : virtual CPLErr SetMetadata( char ** papszMetadata,
548 : const char * pszDomain = "" );
549 :
550 : VRTSource *ParseSource( CPLXMLNode *psSrc, const char *pszVRTPath );
551 : void AddSourceParser( const char *pszElementName,
552 : VRTSourceParser pfnParser );
553 : };
554 :
555 : /************************************************************************/
556 : /* VRTSimpleSource */
557 : /************************************************************************/
558 :
559 : class VRTSimpleSource : public VRTSource
560 : {
561 : protected:
562 : GDALRasterBand *poRasterBand;
563 :
564 : /* when poRasterBand is a mask band, poMaskBandMainBand is the band */
565 : /* from which the mask band is taken */
566 : GDALRasterBand *poMaskBandMainBand;
567 :
568 : int nSrcXOff;
569 : int nSrcYOff;
570 : int nSrcXSize;
571 : int nSrcYSize;
572 :
573 : int nDstXOff;
574 : int nDstYOff;
575 : int nDstXSize;
576 : int nDstYSize;
577 :
578 : int bNoDataSet;
579 : double dfNoDataValue;
580 :
581 : public:
582 : VRTSimpleSource();
583 : virtual ~VRTSimpleSource();
584 :
585 : virtual CPLErr XMLInit( CPLXMLNode *psTree, const char * );
586 : virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
587 :
588 : void SetSrcBand( GDALRasterBand * );
589 : void SetSrcMaskBand( GDALRasterBand * );
590 : void SetSrcWindow( int, int, int, int );
591 : void SetDstWindow( int, int, int, int );
592 : void SetNoDataValue( double dfNoDataValue );
593 :
594 : int GetSrcDstWindow( int, int, int, int, int, int,
595 : int *, int *, int *, int *,
596 : int *, int *, int *, int * );
597 :
598 : virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
599 : void *pData, int nBufXSize, int nBufYSize,
600 : GDALDataType eBufType,
601 : int nPixelSpace, int nLineSpace );
602 :
603 : virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess );
604 : virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess );
605 : virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax );
606 : virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
607 : int bApproxOK,
608 : double *pdfMin, double *pdfMax,
609 : double *pdfMean, double *pdfStdDev,
610 : GDALProgressFunc pfnProgress, void *pProgressData );
611 : virtual CPLErr GetHistogram( int nXSize, int nYSize,
612 : double dfMin, double dfMax,
613 : int nBuckets, int * panHistogram,
614 : int bIncludeOutOfRange, int bApproxOK,
615 : GDALProgressFunc pfnProgress, void *pProgressData );
616 :
617 : void DstToSrc( double dfX, double dfY,
618 : double &dfXOut, double &dfYOut );
619 : void SrcToDst( double dfX, double dfY,
620 : double &dfXOut, double &dfYOut );
621 :
622 : virtual void GetFileList(char*** ppapszFileList, int *pnSize,
623 : int *pnMaxSize, CPLHashSet* hSetFiles);
624 :
625 1363 : virtual int IsSimpleSource() { return TRUE; }
626 5061 : virtual const char* GetType() { return "SimpleSource"; }
627 :
628 : GDALRasterBand* GetBand();
629 : int IsSameExceptBandNumber(VRTSimpleSource* poOtherSource);
630 : CPLErr DatasetRasterIO(
631 : int nXOff, int nYOff, int nXSize, int nYSize,
632 : void * pData, int nBufXSize, int nBufYSize,
633 : GDALDataType eBufType,
634 : int nBandCount, int *panBandMap,
635 : int nPixelSpace, int nLineSpace, int nBandSpace);
636 : };
637 :
638 : /************************************************************************/
639 : /* VRTAveragedSource */
640 : /************************************************************************/
641 :
642 : class VRTAveragedSource : public VRTSimpleSource
643 2 : {
644 : public:
645 : VRTAveragedSource();
646 : virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
647 : void *pData, int nBufXSize, int nBufYSize,
648 : GDALDataType eBufType,
649 : int nPixelSpace, int nLineSpace );
650 :
651 : virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess );
652 : virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess );
653 : virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax );
654 : virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
655 : int bApproxOK,
656 : double *pdfMin, double *pdfMax,
657 : double *pdfMean, double *pdfStdDev,
658 : GDALProgressFunc pfnProgress, void *pProgressData );
659 : virtual CPLErr GetHistogram( int nXSize, int nYSize,
660 : double dfMin, double dfMax,
661 : int nBuckets, int * panHistogram,
662 : int bIncludeOutOfRange, int bApproxOK,
663 : GDALProgressFunc pfnProgress, void *pProgressData );
664 :
665 : virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
666 0 : virtual const char* GetType() { return "AveragedSource"; }
667 : };
668 :
669 : /************************************************************************/
670 : /* VRTComplexSource */
671 : /************************************************************************/
672 :
673 : class VRTComplexSource : public VRTSimpleSource
674 : {
675 : protected:
676 : CPLErr RasterIOInternal( int nReqXOff, int nReqYOff,
677 : int nReqXSize, int nReqYSize,
678 : void *pData, int nOutXSize, int nOutYSize,
679 : GDALDataType eBufType,
680 : int nPixelSpace, int nLineSpace );
681 :
682 : public:
683 : VRTComplexSource();
684 : virtual ~VRTComplexSource();
685 :
686 : virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
687 : void *pData, int nBufXSize, int nBufYSize,
688 : GDALDataType eBufType,
689 : int nPixelSpace, int nLineSpace );
690 :
691 : virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess );
692 : virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess );
693 : virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax );
694 : virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
695 : int bApproxOK,
696 : double *pdfMin, double *pdfMax,
697 : double *pdfMean, double *pdfStdDev,
698 : GDALProgressFunc pfnProgress, void *pProgressData );
699 : virtual CPLErr GetHistogram( int nXSize, int nYSize,
700 : double dfMin, double dfMax,
701 : int nBuckets, int * panHistogram,
702 : int bIncludeOutOfRange, int bApproxOK,
703 : GDALProgressFunc pfnProgress, void *pProgressData );
704 :
705 : virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
706 : virtual CPLErr XMLInit( CPLXMLNode *, const char * );
707 9 : virtual const char* GetType() { return "ComplexSource"; }
708 :
709 : double LookupValue( double dfInput );
710 :
711 : int bDoScaling;
712 : double dfScaleOff;
713 : double dfScaleRatio;
714 : double *padfLUTInputs;
715 : double *padfLUTOutputs;
716 : int nLUTItemCount;
717 : int nColorTableComponent;
718 : };
719 :
720 : /************************************************************************/
721 : /* VRTFilteredSource */
722 : /************************************************************************/
723 :
724 : class VRTFilteredSource : public VRTComplexSource
725 : {
726 : private:
727 : int IsTypeSupported( GDALDataType eType );
728 :
729 : protected:
730 : int nSupportedTypesCount;
731 : GDALDataType aeSupportedTypes[20];
732 :
733 : int nExtraEdgePixels;
734 :
735 : public:
736 : VRTFilteredSource();
737 : virtual ~VRTFilteredSource();
738 :
739 : void SetExtraEdgePixels( int );
740 : void SetFilteringDataTypesSupported( int, GDALDataType * );
741 :
742 : virtual CPLErr FilterData( int nXSize, int nYSize, GDALDataType eType,
743 : GByte *pabySrcData, GByte *pabyDstData ) = 0;
744 :
745 : virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
746 : void *pData, int nBufXSize, int nBufYSize,
747 : GDALDataType eBufType,
748 : int nPixelSpace, int nLineSpace );
749 : };
750 :
751 : /************************************************************************/
752 : /* VRTKernelFilteredSource */
753 : /************************************************************************/
754 :
755 : class VRTKernelFilteredSource : public VRTFilteredSource
756 : {
757 : protected:
758 : int nKernelSize;
759 :
760 : double *padfKernelCoefs;
761 :
762 : int bNormalized;
763 :
764 : public:
765 : VRTKernelFilteredSource();
766 : virtual ~VRTKernelFilteredSource();
767 :
768 : virtual CPLErr XMLInit( CPLXMLNode *psTree, const char * );
769 : virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
770 :
771 : virtual CPLErr FilterData( int nXSize, int nYSize, GDALDataType eType,
772 : GByte *pabySrcData, GByte *pabyDstData );
773 :
774 : CPLErr SetKernel( int nKernelSize, double *padfCoefs );
775 : void SetNormalized( int );
776 : };
777 :
778 : /************************************************************************/
779 : /* VRTAverageFilteredSource */
780 : /************************************************************************/
781 :
782 : class VRTAverageFilteredSource : public VRTKernelFilteredSource
783 : {
784 : public:
785 : VRTAverageFilteredSource( int nKernelSize );
786 : virtual ~VRTAverageFilteredSource();
787 :
788 : virtual CPLErr XMLInit( CPLXMLNode *psTree, const char * );
789 : virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
790 : };
791 :
792 : /************************************************************************/
793 : /* VRTFuncSource */
794 : /************************************************************************/
795 : class VRTFuncSource : public VRTSource
796 : {
797 : public:
798 : VRTFuncSource();
799 : virtual ~VRTFuncSource();
800 :
801 0 : virtual CPLErr XMLInit( CPLXMLNode *, const char *) { return CE_Failure; }
802 : virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
803 :
804 : virtual CPLErr RasterIO( int nXOff, int nYOff, int nXSize, int nYSize,
805 : void *pData, int nBufXSize, int nBufYSize,
806 : GDALDataType eBufType,
807 : int nPixelSpace, int nLineSpace );
808 :
809 : virtual double GetMinimum( int nXSize, int nYSize, int *pbSuccess );
810 : virtual double GetMaximum( int nXSize, int nYSize, int *pbSuccess );
811 : virtual CPLErr ComputeRasterMinMax( int nXSize, int nYSize, int bApproxOK, double* adfMinMax );
812 : virtual CPLErr ComputeStatistics( int nXSize, int nYSize,
813 : int bApproxOK,
814 : double *pdfMin, double *pdfMax,
815 : double *pdfMean, double *pdfStdDev,
816 : GDALProgressFunc pfnProgress, void *pProgressData );
817 : virtual CPLErr GetHistogram( int nXSize, int nYSize,
818 : double dfMin, double dfMax,
819 : int nBuckets, int * panHistogram,
820 : int bIncludeOutOfRange, int bApproxOK,
821 : GDALProgressFunc pfnProgress, void *pProgressData );
822 :
823 : VRTImageReadFunc pfnReadFunc;
824 : void *pCBData;
825 : GDALDataType eType;
826 :
827 : float fNoDataValue;
828 : };
829 :
830 : #endif /* ndef VIRTUALDATASET_H_INCLUDED */
|