1 : /******************************************************************************
2 : * $Id: gdal_proxy.h 20962 2010-10-25 23:00:16Z rouault $
3 : *
4 : * Project: GDAL Core
5 : * Purpose: GDAL Core C++/Private declarations
6 : * Author: Even Rouault <even dot rouault at mines dash paris dot org>
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2008, Even Rouault
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 GDAL_PROXY_H_INCLUDED
31 : #define GDAL_PROXY_H_INCLUDED
32 :
33 : #include "gdal.h"
34 :
35 : #ifdef __cplusplus
36 :
37 : #include "gdal_priv.h"
38 : #include "cpl_hash_set.h"
39 :
40 : /* ******************************************************************** */
41 : /* GDALProxyDataset */
42 : /* ******************************************************************** */
43 :
44 : class CPL_DLL GDALProxyDataset : public GDALDataset
45 606 : {
46 : protected:
47 : virtual GDALDataset *RefUnderlyingDataset() = 0;
48 : virtual void UnrefUnderlyingDataset(GDALDataset* poUnderlyingDataset);
49 :
50 : virtual CPLErr IBuildOverviews( const char *, int, int *,
51 : int, int *, GDALProgressFunc, void * );
52 : virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
53 : void *, int, int, GDALDataType,
54 : int, int *, int, int, int );
55 : public:
56 :
57 : virtual char **GetMetadata( const char * pszDomain );
58 : virtual CPLErr SetMetadata( char ** papszMetadata,
59 : const char * pszDomain );
60 : virtual const char *GetMetadataItem( const char * pszName,
61 : const char * pszDomain );
62 : virtual CPLErr SetMetadataItem( const char * pszName,
63 : const char * pszValue,
64 : const char * pszDomain );
65 :
66 : virtual void FlushCache(void);
67 :
68 : virtual const char *GetProjectionRef(void);
69 : virtual CPLErr SetProjection( const char * );
70 :
71 : virtual CPLErr GetGeoTransform( double * );
72 : virtual CPLErr SetGeoTransform( double * );
73 :
74 : virtual void *GetInternalHandle( const char * );
75 : virtual GDALDriver *GetDriver(void);
76 : virtual char **GetFileList(void);
77 :
78 : virtual int GetGCPCount();
79 : virtual const char *GetGCPProjection();
80 : virtual const GDAL_GCP *GetGCPs();
81 : virtual CPLErr SetGCPs( int nGCPCount, const GDAL_GCP *pasGCPList,
82 : const char *pszGCPProjection );
83 :
84 : virtual CPLErr AdviseRead( int nXOff, int nYOff, int nXSize, int nYSize,
85 : int nBufXSize, int nBufYSize,
86 : GDALDataType eDT,
87 : int nBandCount, int *panBandList,
88 : char **papszOptions );
89 :
90 : virtual CPLErr CreateMaskBand( int nFlags );
91 :
92 : };
93 :
94 : /* ******************************************************************** */
95 : /* GDALProxyRasterBand */
96 : /* ******************************************************************** */
97 :
98 : class CPL_DLL GDALProxyRasterBand : public GDALRasterBand
99 828 : {
100 : protected:
101 : virtual GDALRasterBand* RefUnderlyingRasterBand() = 0;
102 : virtual void UnrefUnderlyingRasterBand(GDALRasterBand* poUnderlyingRasterBand);
103 :
104 : virtual CPLErr IReadBlock( int, int, void * );
105 : virtual CPLErr IWriteBlock( int, int, void * );
106 : virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
107 : void *, int, int, GDALDataType,
108 : int, int );
109 :
110 : public:
111 :
112 : virtual char **GetMetadata( const char * pszDomain );
113 : virtual CPLErr SetMetadata( char ** papszMetadata,
114 : const char * pszDomain );
115 : virtual const char *GetMetadataItem( const char * pszName,
116 : const char * pszDomain );
117 : virtual CPLErr SetMetadataItem( const char * pszName,
118 : const char * pszValue,
119 : const char * pszDomain );
120 : virtual CPLErr FlushCache();
121 : virtual char **GetCategoryNames();
122 : virtual double GetNoDataValue( int *pbSuccess = NULL );
123 : virtual double GetMinimum( int *pbSuccess = NULL );
124 : virtual double GetMaximum(int *pbSuccess = NULL );
125 : virtual double GetOffset( int *pbSuccess = NULL );
126 : virtual double GetScale( int *pbSuccess = NULL );
127 : virtual const char *GetUnitType();
128 : virtual GDALColorInterp GetColorInterpretation();
129 : virtual GDALColorTable *GetColorTable();
130 : virtual CPLErr Fill(double dfRealValue, double dfImaginaryValue = 0);
131 :
132 : virtual CPLErr SetCategoryNames( char ** );
133 : virtual CPLErr SetNoDataValue( double );
134 : virtual CPLErr SetColorTable( GDALColorTable * );
135 : virtual CPLErr SetColorInterpretation( GDALColorInterp );
136 : virtual CPLErr SetOffset( double );
137 : virtual CPLErr SetScale( double );
138 : virtual CPLErr SetUnitType( const char * );
139 :
140 : virtual CPLErr GetStatistics( int bApproxOK, int bForce,
141 : double *pdfMin, double *pdfMax,
142 : double *pdfMean, double *padfStdDev );
143 : virtual CPLErr ComputeStatistics( int bApproxOK,
144 : double *pdfMin, double *pdfMax,
145 : double *pdfMean, double *pdfStdDev,
146 : GDALProgressFunc, void *pProgressData );
147 : virtual CPLErr SetStatistics( double dfMin, double dfMax,
148 : double dfMean, double dfStdDev );
149 : virtual CPLErr ComputeRasterMinMax( int, double* );
150 :
151 : virtual int HasArbitraryOverviews();
152 : virtual int GetOverviewCount();
153 : virtual GDALRasterBand *GetOverview(int);
154 : virtual GDALRasterBand *GetRasterSampleOverview( int );
155 : virtual CPLErr BuildOverviews( const char *, int, int *,
156 : GDALProgressFunc, void * );
157 :
158 : virtual CPLErr AdviseRead( int nXOff, int nYOff, int nXSize, int nYSize,
159 : int nBufXSize, int nBufYSize,
160 : GDALDataType eDT, char **papszOptions );
161 :
162 : virtual CPLErr GetHistogram( double dfMin, double dfMax,
163 : int nBuckets, int * panHistogram,
164 : int bIncludeOutOfRange, int bApproxOK,
165 : GDALProgressFunc, void *pProgressData );
166 :
167 : virtual CPLErr GetDefaultHistogram( double *pdfMin, double *pdfMax,
168 : int *pnBuckets, int ** ppanHistogram,
169 : int bForce,
170 : GDALProgressFunc, void *pProgressData);
171 : virtual CPLErr SetDefaultHistogram( double dfMin, double dfMax,
172 : int nBuckets, int *panHistogram );
173 :
174 : virtual const GDALRasterAttributeTable *GetDefaultRAT();
175 : virtual CPLErr SetDefaultRAT( const GDALRasterAttributeTable * );
176 :
177 : virtual GDALRasterBand *GetMaskBand();
178 : virtual int GetMaskFlags();
179 : virtual CPLErr CreateMaskBand( int nFlags );
180 :
181 : };
182 :
183 :
184 : /* ******************************************************************** */
185 : /* GDALProxyPoolDataset */
186 : /* ******************************************************************** */
187 :
188 : typedef struct _GDALProxyPoolCacheEntry GDALProxyPoolCacheEntry;
189 : class GDALProxyPoolRasterBand;
190 :
191 : class CPL_DLL GDALProxyPoolDataset : public GDALProxyDataset
192 : {
193 : private:
194 : GIntBig responsiblePID;
195 :
196 : char *pszProjectionRef;
197 : double adfGeoTransform[6];
198 : int bHasSrcProjection;
199 : int bHasSrcGeoTransform;
200 : char *pszGCPProjection;
201 : int nGCPCount;
202 : GDAL_GCP *pasGCPList;
203 : CPLHashSet *metadataSet;
204 : CPLHashSet *metadataItemSet;
205 :
206 : GDALProxyPoolCacheEntry* cacheEntry;
207 :
208 : protected:
209 : virtual GDALDataset *RefUnderlyingDataset();
210 : virtual void UnrefUnderlyingDataset(GDALDataset* poUnderlyingDataset);
211 :
212 : friend class GDALProxyPoolRasterBand;
213 :
214 : public:
215 : GDALProxyPoolDataset(const char* pszSourceDatasetDescription,
216 : int nRasterXSize, int nRasterYSize,
217 : GDALAccess eAccess = GA_ReadOnly,
218 : int bShared = FALSE,
219 : const char * pszProjectionRef = NULL,
220 : double * padfGeoTransform = NULL);
221 : ~GDALProxyPoolDataset();
222 :
223 : void AddSrcBandDescription( GDALDataType eDataType, int nBlockXSize, int nBlockYSize);
224 :
225 : virtual const char *GetProjectionRef(void);
226 : virtual CPLErr SetProjection( const char * );
227 :
228 : virtual CPLErr GetGeoTransform( double * );
229 : virtual CPLErr SetGeoTransform( double * );
230 :
231 : /* Special behaviour for the following methods : they return a pointer */
232 : /* data type, that must be cached by the proxy, so it doesn't become invalid */
233 : /* when the underlying object get closed */
234 : virtual char **GetMetadata( const char * pszDomain );
235 : virtual const char *GetMetadataItem( const char * pszName,
236 : const char * pszDomain );
237 :
238 : virtual void *GetInternalHandle( const char * pszRequest );
239 :
240 : virtual const char *GetGCPProjection();
241 : virtual const GDAL_GCP *GetGCPs();
242 : };
243 :
244 : /* ******************************************************************** */
245 : /* GDALProxyPoolRasterBand */
246 : /* ******************************************************************** */
247 :
248 : class GDALProxyPoolOverviewRasterBand;
249 : class GDALProxyPoolMaskBand;
250 :
251 : class CPL_DLL GDALProxyPoolRasterBand : public GDALProxyRasterBand
252 : {
253 : private:
254 : CPLHashSet *metadataSet;
255 : CPLHashSet *metadataItemSet;
256 : char *pszUnitType;
257 : char **papszCategoryNames;
258 : GDALColorTable *poColorTable;
259 :
260 : int nSizeProxyOverviewRasterBand;
261 : GDALProxyPoolOverviewRasterBand **papoProxyOverviewRasterBand;
262 : GDALProxyPoolMaskBand *poProxyMaskBand;
263 :
264 : void Init();
265 :
266 : protected:
267 : virtual GDALRasterBand* RefUnderlyingRasterBand();
268 : virtual void UnrefUnderlyingRasterBand(GDALRasterBand* poUnderlyingRasterBand);
269 :
270 : friend class GDALProxyPoolOverviewRasterBand;
271 : friend class GDALProxyPoolMaskBand;
272 :
273 : public:
274 : GDALProxyPoolRasterBand(GDALProxyPoolDataset* poDS, int nBand,
275 : GDALDataType eDataType,
276 : int nBlockXSize, int nBlockYSize);
277 : GDALProxyPoolRasterBand(GDALProxyPoolDataset* poDS,
278 : GDALRasterBand* poUnderlyingRasterBand);
279 : ~GDALProxyPoolRasterBand();
280 :
281 : void AddSrcMaskBandDescription( GDALDataType eDataType, int nBlockXSize, int nBlockYSize);
282 :
283 : /* Special behaviour for the following methods : they return a pointer */
284 : /* data type, that must be cached by the proxy, so it doesn't become invalid */
285 : /* when the underlying object get closed */
286 : virtual char **GetMetadata( const char * pszDomain );
287 : virtual const char *GetMetadataItem( const char * pszName,
288 : const char * pszDomain );
289 : virtual char **GetCategoryNames();
290 : virtual const char *GetUnitType();
291 : virtual GDALColorTable *GetColorTable();
292 : virtual GDALRasterBand *GetOverview(int);
293 : virtual GDALRasterBand *GetRasterSampleOverview( int nDesiredSamples); // TODO
294 : virtual GDALRasterBand *GetMaskBand();
295 :
296 : };
297 :
298 : /* ******************************************************************** */
299 : /* GDALProxyPoolOverviewRasterBand */
300 : /* ******************************************************************** */
301 :
302 : class GDALProxyPoolOverviewRasterBand : public GDALProxyPoolRasterBand
303 : {
304 : private:
305 : GDALProxyPoolRasterBand *poMainBand;
306 : int nOverviewBand;
307 :
308 : GDALRasterBand *poUnderlyingMainRasterBand;
309 : int nRefCountUnderlyingMainRasterBand;
310 :
311 : protected:
312 : virtual GDALRasterBand* RefUnderlyingRasterBand();
313 : virtual void UnrefUnderlyingRasterBand(GDALRasterBand* poUnderlyingRasterBand);
314 :
315 : public:
316 : GDALProxyPoolOverviewRasterBand(GDALProxyPoolDataset* poDS,
317 : GDALRasterBand* poUnderlyingOverviewBand,
318 : GDALProxyPoolRasterBand* poMainBand,
319 : int nOverviewBand);
320 : ~GDALProxyPoolOverviewRasterBand();
321 : };
322 :
323 : /* ******************************************************************** */
324 : /* GDALProxyPoolMaskBand */
325 : /* ******************************************************************** */
326 :
327 : class GDALProxyPoolMaskBand : public GDALProxyPoolRasterBand
328 : {
329 : private:
330 : GDALProxyPoolRasterBand *poMainBand;
331 :
332 : GDALRasterBand *poUnderlyingMainRasterBand;
333 : int nRefCountUnderlyingMainRasterBand;
334 :
335 : protected:
336 : virtual GDALRasterBand* RefUnderlyingRasterBand();
337 : virtual void UnrefUnderlyingRasterBand(GDALRasterBand* poUnderlyingRasterBand);
338 :
339 : public:
340 : GDALProxyPoolMaskBand(GDALProxyPoolDataset* poDS,
341 : GDALRasterBand* poUnderlyingMaskBand,
342 : GDALProxyPoolRasterBand* poMainBand);
343 : GDALProxyPoolMaskBand(GDALProxyPoolDataset* poDS,
344 : GDALProxyPoolRasterBand* poMainBand,
345 : GDALDataType eDataType,
346 : int nBlockXSize, int nBlockYSize);
347 : ~GDALProxyPoolMaskBand();
348 : };
349 :
350 : #endif
351 :
352 :
353 : /* ******************************************************************** */
354 : /* C types and methods declarations */
355 : /* ******************************************************************** */
356 :
357 :
358 : CPL_C_START
359 :
360 : typedef struct GDALProxyPoolDatasetHS *GDALProxyPoolDatasetH;
361 :
362 : GDALProxyPoolDatasetH CPL_DLL GDALProxyPoolDatasetCreate(const char* pszSourceDatasetDescription,
363 : int nRasterXSize, int nRasterYSize,
364 : GDALAccess eAccess, int bShared,
365 : const char * pszProjectionRef,
366 : double * padfGeoTransform);
367 :
368 : void CPL_DLL GDALProxyPoolDatasetDelete(GDALProxyPoolDatasetH hProxyPoolDataset);
369 :
370 : void CPL_DLL GDALProxyPoolDatasetAddSrcBandDescription( GDALProxyPoolDatasetH hProxyPoolDataset,
371 : GDALDataType eDataType,
372 : int nBlockXSize, int nBlockYSize);
373 :
374 : CPL_C_END
375 :
376 : #endif /* GDAL_PROXY_H_INCLUDED */
|