GDAL

- Main Page
- Related Pages
- Classes
- Files
- Download
- Issue Tracker

- File List
- File Members

gdalpansharpen.h
Go to the documentation of this file.
1 /******************************************************************************
2 * $Id$
3 *
4 * Project: GDAL Pansharpening module
5 * Purpose: Prototypes, and definitions for pansharpening related work.
6 * Author: Even Rouault <even.rouault at spatialys.com>
7 *
8 ******************************************************************************
9 * Copyright (c) 2015, Even Rouault <even.rouault at spatialys.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 GDALPANSHARPEN_H_INCLUDED
31 #define GDALPANSHARPEN_H_INCLUDED
32
33 #include "gdal.h"
34
35 CPL_C_START
36
47 typedef enum
48 {
50 GDAL_PSH_WEIGHTED_BROVEY
51 } GDALPansharpenAlg;
52
55 typedef struct
56 {
58 GDALPansharpenAlg ePansharpenAlg;
59
61 GDALRIOResampleAlg eResampleAlg;
62
64 int nBitDepth;
65
67 int nWeightCount;
68
70 double *padfWeights;
71
73 GDALRasterBandH hPanchroBand;
74
76 int nInputSpectralBands;
77
84 GDALRasterBandH *pahInputSpectralBands;
85
87 int nOutPansharpenedBands;
88
90 int *panOutPansharpenedBands;
91
93 int bHasNoData;
94
97 double dfNoData;
98
101 int nThreads;
102
104 double dfMSShiftX;
105
107 double dfMSShiftY;
108
109 } GDALPansharpenOptions;
110
111 GDALPansharpenOptions CPL_DLL * GDALCreatePansharpenOptions(void);
112 void CPL_DLL GDALDestroyPansharpenOptions( GDALPansharpenOptions * );
113 GDALPansharpenOptions CPL_DLL * GDALClonePansharpenOptions(
114 const GDALPansharpenOptions* psOptions);
115
117 typedef void* GDALPansharpenOperationH;
118
119 GDALPansharpenOperationH CPL_DLL GDALCreatePansharpenOperation(const GDALPansharpenOptions* );
120 void CPL_DLL GDALDestroyPansharpenOperation( GDALPansharpenOperationH );
121 CPLErr CPL_DLL GDALPansharpenProcessRegion( GDALPansharpenOperationH hOperation,
122 int nXOff, int nYOff,
123 int nXSize, int nYSize,
124 void *pDataBuf,
125 GDALDataType eBufDataType);
126
127 CPL_C_END
128
129 #ifdef __cplusplus
130
131 #include <vector>
132 #include "gdal_priv.h"
133 #include "cpl_worker_thread_pool.h"
134
135 #ifdef DEBUG_TIMING
136 #include <sys/time.h>
137 #endif
138
139 class GDALPansharpenOperation;
140
142 typedef struct
143 {
144 GDALPansharpenOperation* poPansharpenOperation;
145 GDALDataType eWorkDataType;
146 GDALDataType eBufDataType;
147 const void* pPanBuffer;
148 const void* pUpsampledSpectralBuffer;
149 void* pDataBuf;
150 int nValues;
151 int nBandValues;
152 GUInt32 nMaxValue;
153
154 #ifdef DEBUG_TIMING
155 struct timeval* ptv;
156 #endif
157
158 CPLErr eErr;
159 } GDALPansharpenJob;
160
161 typedef struct
162 {
163 GDALDataset* poMEMDS;
164 int nXOff;
165 int nYOff;
166 int nXSize;
167 int nYSize;
168 double dfXOff;
169 double dfYOff;
170 double dfXSize;
171 double dfYSize;
172 void *pBuffer;
173 GDALDataType eDT;
174 int nBufXSize;
175 int nBufYSize;
176 int nBandCount;
177 GDALRIOResampleAlg eResampleAlg;
178 GSpacing nBandSpace;
179
180 #ifdef DEBUG_TIMING
181 struct timeval* ptv;
182 #endif
183 } GDALPansharpenResampleJob;
185
188 class GDALPansharpenOperation
189 {
190 GDALPansharpenOptions* psOptions;
191 std::vector<int> anInputBands;
192 std::vector<GDALDataset*> aVDS; // to destroy
193 std::vector<GDALRasterBand*> aMSBands; // original multispectral bands potentially warped into a VRT
194 int bPositiveWeights;
195 CPLWorkerThreadPool* poThreadPool;
196 int nKernelRadius;
197
198 static void PansharpenJobThreadFunc(void* pUserData);
199 static void PansharpenResampleJobThreadFunc(void* pUserData);
200
201 template<class WorkDataType, class OutDataType> void WeightedBroveyWithNoData(
202 const WorkDataType* pPanBuffer,
203 const WorkDataType* pUpsampledSpectralBuffer,
204 OutDataType* pDataBuf,
205 int nValues,
206 int nBandValues,
207 WorkDataType nMaxValue) const;
208 template<class WorkDataType, class OutDataType, int bHasBitDepth> void WeightedBrovey3(
209 const WorkDataType* pPanBuffer,
210 const WorkDataType* pUpsampledSpectralBuffer,
211 OutDataType* pDataBuf,
212 int nValues,
213 int nBandValues,
214 WorkDataType nMaxValue) const;
215
216 // cppcheck-suppress functionStatic
217 template<class WorkDataType, class OutDataType> void WeightedBrovey(
218 const WorkDataType* pPanBuffer,
219 const WorkDataType* pUpsampledSpectralBuffer,
220 OutDataType* pDataBuf,
221 int nValues,
222 int nBandValues,
223 WorkDataType nMaxValue) const;
224 template<class WorkDataType> CPLErr WeightedBrovey(
225 const WorkDataType* pPanBuffer,
226 const WorkDataType* pUpsampledSpectralBuffer,
227 void *pDataBuf,
228 GDALDataType eBufDataType,
229 int nValues,
230 int nBandValues,
231 WorkDataType nMaxValue) const;
232
233 // cppcheck-suppress functionStatic
234 template<class WorkDataType> CPLErr WeightedBrovey(
235 const WorkDataType* pPanBuffer,
236 const WorkDataType* pUpsampledSpectralBuffer,
237 void *pDataBuf,
238 GDALDataType eBufDataType,
239 int nValues,
240 int nBandValues) const;
241 template<class T> void WeightedBroveyPositiveWeights(
242 const T* pPanBuffer,
243 const T* pUpsampledSpectralBuffer,
244 T* pDataBuf,
245 int nValues,
246 int nBandValues,
247 T nMaxValue) const;
248
249 template<class T, int NINPUT, int NOUTPUT> int WeightedBroveyPositiveWeightsInternal(
250 const T* pPanBuffer,
251 const T* pUpsampledSpectralBuffer,
252 T* pDataBuf,
253 int nValues,
254 int nBandValues,
255 T nMaxValue) const;
256
257 // cppcheck-suppress unusedPrivateFunction
258 template<class T> void WeightedBroveyGByteOrUInt16(
259 const T* pPanBuffer,
260 const T* pUpsampledSpectralBuffer,
261 T* pDataBuf,
262 int nValues,
263 int nBandValues,
264 T nMaxValue ) const;
265
266 CPLErr PansharpenChunk( GDALDataType eWorkDataType, GDALDataType eBufDataType,
267 const void* pPanBuffer,
268 const void* pUpsampledSpectralBuffer,
269 void* pDataBuf,
270 int nValues,
271 int nBandValues,
272 GUInt32 nMaxValue) const;
273 public:
274 GDALPansharpenOperation();
275 ~GDALPansharpenOperation();
276
277 CPLErr Initialize(const GDALPansharpenOptions* psOptions);
278 CPLErr ProcessRegion(int nXOff, int nYOff,
279 int nXSize, int nYSize,
280 void *pDataBuf,
281 GDALDataType eBufDataType);
282 GDALPansharpenOptions* GetOptions();
283 };
284
285 #endif /* __cplusplus */
286
287 #endif /* GDALPANSHARPEN_H_INCLUDED */
GDALDataType
GDALDataType
Definition: gdal.h:60
GDAL_PSH_WEIGHTED_BROVEY
Definition: gdalpansharpen.h:50
GDALPansharpenOptions::dfMSShiftY
double dfMSShiftY
Shift in pixels of multispectral bands w.r.t panchromatic band, in Y direction.
Definition: gdalpansharpen.h:107
GDALCreatePansharpenOptions
GDALPansharpenOptions * GDALCreatePansharpenOptions(void)
Create pansharpening options.
Definition: gdalpansharpen.cpp:67
GDALPansharpenOptions::ePansharpenAlg
GDALPansharpenAlg ePansharpenAlg
Definition: gdalpansharpen.h:58
CPL_C_START
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:335
gdal_priv.h
C++ GDAL entry points.
GUInt32
unsigned int GUInt32
Unsigned int32 type.
Definition: cpl_port.h:205
GDALRIOResampleAlg
GDALRIOResampleAlg
RasterIO() resampling method.
Definition: gdal.h:128
GDALPansharpenOptions::dfNoData
double dfNoData
NoData value of the panchromatic and spectral bands (only taken into account if bHasNoData = TRUE)...
Definition: gdalpansharpen.h:97
GDALPansharpenOptions::bHasNoData
int bHasNoData
Definition: gdalpansharpen.h:93
GDALRasterBandH
void * GDALRasterBandH
Opaque type used for the C bindings of the C++ GDALRasterBand class.
Definition: gdal.h:258
GDALPansharpenOptions::dfMSShiftX
double dfMSShiftX
Shift in pixels of multispectral bands w.r.t panchromatic band, in X direction.
Definition: gdalpansharpen.h:104
GDALPansharpenOperation
Pansharpening operation class.
Definition: gdalpansharpen.h:188
GDALPansharpenAlg
GDALPansharpenAlg
Pansharpening algorithms.
Definition: gdalpansharpen.h:47
GDALPansharpenProcessRegion
CPLErr GDALPansharpenProcessRegion(GDALPansharpenOperationH hOperation, int nXOff, int nYOff, int nXSize, int nYSize, void *pDataBuf, GDALDataType eBufDataType)
Executes a pansharpening operation on a rectangular region of the resulting dataset.
Definition: gdalpansharpen.cpp:1806
GDALPansharpenOptions::nWeightCount
int nWeightCount
Definition: gdalpansharpen.h:67
GDALPansharpenOperationH
void * GDALPansharpenOperationH
Definition: gdalpansharpen.h:117
GDALClonePansharpenOptions
GDALPansharpenOptions * GDALClonePansharpenOptions(const GDALPansharpenOptions *psOptions)
Clone pansharpening options.
Definition: gdalpansharpen.cpp:112
GDALPansharpenOptions::nThreads
int nThreads
Number of threads or -1 to mean ALL_CPUS.
Definition: gdalpansharpen.h:101
GSpacing
GIntBig GSpacing
Type to express pixel, line or band spacing.
Definition: gdal.h:273
GDALPansharpenOptions::nBitDepth
int nBitDepth
Definition: gdalpansharpen.h:64
GDALPansharpenOperation::Initialize
CPLErr Initialize(const GDALPansharpenOptions *psOptions)
Initialize the pansharpening operation.
Definition: gdalpansharpen.cpp:197
gdal.h
Public (C callable) GDAL entry points.
GDALPansharpenOptions::nInputSpectralBands
int nInputSpectralBands
Definition: gdalpansharpen.h:76
GDALDestroyPansharpenOperation
void GDALDestroyPansharpenOperation(GDALPansharpenOperationH)
Destroy a pansharpening operation.
Definition: gdalpansharpen.cpp:1772
GDALPansharpenOperation::~GDALPansharpenOperation
~GDALPansharpenOperation()
Pansharpening operation destructor.
Definition: gdalpansharpen.cpp:178
GDALPansharpenOptions::panOutPansharpenedBands
int * panOutPansharpenedBands
Definition: gdalpansharpen.h:90
GDALPansharpenOptions::padfWeights
double * padfWeights
Definition: gdalpansharpen.h:70
GDALPansharpenOptions
Pansharpening options.
Definition: gdalpansharpen.h:55
GDALDestroyPansharpenOptions
void GDALDestroyPansharpenOptions(GDALPansharpenOptions *)
Destroy pansharpening options.
Definition: gdalpansharpen.cpp:88
GDALPansharpenOptions::pahInputSpectralBands
GDALRasterBandH * pahInputSpectralBands
Array of nInputSpectralBands input spectral bands.
Definition: gdalpansharpen.h:84
GDALPansharpenOperation::ProcessRegion
CPLErr ProcessRegion(int nXOff, int nYOff, int nXSize, int nYSize, void *pDataBuf, GDALDataType eBufDataType)
Executes a pansharpening operation on a rectangular region of the resulting dataset.
Definition: gdalpansharpen.cpp:1048
GDALPansharpenOperation::GDALPansharpenOperation
GDALPansharpenOperation()
Pansharpening operation constructor.
Definition: gdalpansharpen.cpp:164
cpl_worker_thread_pool.h
Class to manage a pool of worker threads.
CPLWorkerThreadPool
Pool of worker threads.
Definition: cpl_worker_thread_pool.h:75
GDALDataset
A set of associated raster bands, usually from one file.
Definition: gdal_priv.h:339
CPL_C_END
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:337
GDALCreatePansharpenOperation
GDALPansharpenOperationH GDALCreatePansharpenOperation(const GDALPansharpenOptions *)
Instantiate a pansharpening operation.
Definition: gdalpansharpen.cpp:1751
GDALPansharpenOptions::hPanchroBand
GDALRasterBandH hPanchroBand
Definition: gdalpansharpen.h:73
GDALPansharpenOptions::eResampleAlg
GDALRIOResampleAlg eResampleAlg
Definition: gdalpansharpen.h:61
CPLErr
CPLErr
Error category.
Definition: cpl_error.h:52
GDALPansharpenOperation::GetOptions
GDALPansharpenOptions * GetOptions()
Return options.
Definition: gdalpansharpen.cpp:1731
GDALPansharpenOptions::nOutPansharpenedBands
int nOutPansharpenedBands
Definition: gdalpansharpen.h:87

Generated for GDAL by 1.8.8.