GDAL

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
62 GDALRIOResampleAlg eResampleAlg;
63
66 int nBitDepth;
67
69 int nWeightCount;
70
72 double *padfWeights;
73
75 GDALRasterBandH hPanchroBand;
76
78 int nInputSpectralBands;
79
86 GDALRasterBandH *pahInputSpectralBands;
87
89 int nOutPansharpenedBands;
90
93 int *panOutPansharpenedBands;
94
96 int bHasNoData;
97
101 double dfNoData;
102
106 int nThreads;
107} GDALPansharpenOptions;
108
109 GDALPansharpenOptions CPL_DLL *GDALCreatePansharpenOptions(void);
110void CPL_DLL GDALDestroyPansharpenOptions(GDALPansharpenOptions *);
111 GDALPansharpenOptions CPL_DLL *
112 GDALClonePansharpenOptions(const GDALPansharpenOptions *psOptions);
113
115 typedef void *GDALPansharpenOperationH;
116
117 GDALPansharpenOperationH CPL_DLL
118 GDALCreatePansharpenOperation(const GDALPansharpenOptions *);
119void CPL_DLL GDALDestroyPansharpenOperation(GDALPansharpenOperationH);
120 CPLErr CPL_DLL GDALPansharpenProcessRegion(GDALPansharpenOperationH hOperation,
121 int nXOff, int nYOff, int nXSize,
122 int nYSize, void *pDataBuf,
123 GDALDataType eBufDataType);
124
125 CPL_C_END
126
127#ifdef __cplusplus
128
129#include <array>
130#include <vector>
131#include "gdal_priv.h"
132
133#ifdef DEBUG_TIMING
134#include <sys/time.h>
135#endif
136
137class GDALPansharpenOperation;
138
140typedef struct
141{
142 GDALPansharpenOperation *poPansharpenOperation;
143 GDALDataType eWorkDataType;
144 GDALDataType eBufDataType;
145 const void *pPanBuffer;
146 const void *pUpsampledSpectralBuffer;
147 void *pDataBuf;
148 size_t nValues;
149 size_t nBandValues;
150 GUInt32 nMaxValue;
151
152#ifdef DEBUG_TIMING
153 struct timeval *ptv;
154#endif
155
156 CPLErr eErr;
157} GDALPansharpenJob;
158
159typedef struct
160{
161 GDALDataset *poMEMDS;
162 int nXOff;
163 int nYOff;
164 int nXSize;
165 int nYSize;
166 double dfXOff;
167 double dfYOff;
168 double dfXSize;
169 double dfYSize;
170 void *pBuffer;
171 GDALDataType eDT;
172 int nBufXSize;
173 int nBufYSize;
174 int nBandCount;
175 GDALRIOResampleAlg eResampleAlg;
176 GSpacing nBandSpace;
177
178#ifdef DEBUG_TIMING
179 struct timeval *ptv;
180#endif
181} GDALPansharpenResampleJob;
182
183class CPLWorkerThreadPool;
184
186
189 class GDALPansharpenOperation
190{
191 CPL_DISALLOW_COPY_ASSIGN(GDALPansharpenOperation)
192
193 GDALPansharpenOptions *psOptions = nullptr;
194 std::vector<int> anInputBands{};
195 std::vector<GDALDataset *> aVDS{}; // to destroy
196 std::vector<GDALRasterBand *> aMSBands{}; // original multispectral bands
197 // potentially warped into a VRT
198 int bPositiveWeights = TRUE;
199 CPLWorkerThreadPool *poThreadPool = nullptr;
200 int nKernelRadius = 0;
201 std::array<double, 6> m_adfPanToMSGT = {{0.0, 1.0, 0, 0.0, 0.0, 1.0}};
202
203 static void PansharpenJobThreadFunc(void *pUserData);
204 static void PansharpenResampleJobThreadFunc(void *pUserData);
205
206 template <class WorkDataType, class OutDataType>
207 void WeightedBroveyWithNoData(const WorkDataType *pPanBuffer,
208 const WorkDataType *pUpsampledSpectralBuffer,
209 OutDataType *pDataBuf, size_t nValues,
210 size_t nBandValues,
211 WorkDataType nMaxValue) const;
212 template <class WorkDataType, class OutDataType, int bHasBitDepth>
213 void WeightedBrovey3(const WorkDataType *pPanBuffer,
214 const WorkDataType *pUpsampledSpectralBuffer,
215 OutDataType *pDataBuf, size_t nValues,
216 size_t nBandValues, WorkDataType nMaxValue) const;
217
218 // cppcheck-suppress functionStatic
219 template <class WorkDataType, class OutDataType>
220 void WeightedBrovey(const WorkDataType *pPanBuffer,
221 const WorkDataType *pUpsampledSpectralBuffer,
222 OutDataType *pDataBuf, size_t nValues,
223 size_t nBandValues, WorkDataType nMaxValue) const;
224 template <class WorkDataType>
225 CPLErr WeightedBrovey(const WorkDataType *pPanBuffer,
226 const WorkDataType *pUpsampledSpectralBuffer,
227 void *pDataBuf, GDALDataType eBufDataType,
228 size_t nValues, size_t nBandValues,
229 WorkDataType nMaxValue) const;
230
231 // cppcheck-suppress functionStatic
232 template <class WorkDataType>
233 CPLErr WeightedBrovey(const WorkDataType *pPanBuffer,
234 const WorkDataType *pUpsampledSpectralBuffer,
235 void *pDataBuf, GDALDataType eBufDataType,
236 size_t nValues, size_t nBandValues) const;
237 template <class T>
238 void WeightedBroveyPositiveWeights(const T *pPanBuffer,
239 const T *pUpsampledSpectralBuffer,
240 T *pDataBuf, size_t nValues,
241 size_t nBandValues, T nMaxValue) const;
242
243 template <class T, int NINPUT, int NOUTPUT>
244 size_t WeightedBroveyPositiveWeightsInternal(
245 const T *pPanBuffer, const T *pUpsampledSpectralBuffer, T *pDataBuf,
246 size_t nValues, size_t nBandValues, T nMaxValue) const;
247
248 // cppcheck-suppress unusedPrivateFunction
249 template <class T>
250 void WeightedBroveyGByteOrUInt16(const T *pPanBuffer,
251 const T *pUpsampledSpectralBuffer,
252 T *pDataBuf, size_t nValues,
253 size_t nBandValues, T nMaxValue) const;
254
255 // cppcheck-suppress functionStatic
256 CPLErr PansharpenChunk(GDALDataType eWorkDataType,
257 GDALDataType eBufDataType, const void *pPanBuffer,
258 const void *pUpsampledSpectralBuffer, void *pDataBuf,
259 size_t nValues, size_t nBandValues,
260 GUInt32 nMaxValue) const;
261
262 public:
263 GDALPansharpenOperation();
264 ~GDALPansharpenOperation();
265
266 CPLErr Initialize(const GDALPansharpenOptions *psOptions);
267 CPLErr ProcessRegion(int nXOff, int nYOff, int nXSize, int nYSize,
268 void *pDataBuf, GDALDataType eBufDataType);
269 GDALPansharpenOptions *GetOptions();
270};
271
272#endif /* __cplusplus */
273
274#endif /* GDALPANSHARPEN_H_INCLUDED */
CPLWorkerThreadPool
Pool of worker threads.
Definition: cpl_worker_thread_pool.h:79
GDALDataset
A set of associated raster bands, usually from one file.
Definition: gdal_priv.h:490
GDALPansharpenOperation
Pansharpening operation class.
Definition: gdalpansharpen.h:190
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:1173
GDALPansharpenOperation::GDALPansharpenOperation
GDALPansharpenOperation()
Pansharpening operation constructor.
GDALPansharpenOperation::~GDALPansharpenOperation
~GDALPansharpenOperation()
Pansharpening operation destructor.
Definition: gdalpansharpen.cpp:171
GDALPansharpenOperation::GetOptions
GDALPansharpenOptions * GetOptions()
Return options.
Definition: gdalpansharpen.cpp:1807
GDALPansharpenOperation::Initialize
CPLErr Initialize(const GDALPansharpenOptions *psOptions)
Initialize the pansharpening operation.
Definition: gdalpansharpen.cpp:190
CPLErr
CPLErr
Error category.
Definition: cpl_error.h:53
CPL_C_END
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:299
CPL_C_START
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:295
GUInt32
unsigned int GUInt32
Unsigned int32 type.
Definition: cpl_port.h:177
CPL_DISALLOW_COPY_ASSIGN
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition: cpl_port.h:1042
gdal.h
Public (C callable) GDAL entry points.
GSpacing
GIntBig GSpacing
Type to express pixel, line or band spacing.
Definition: gdal.h:315
GDALDataType
GDALDataType
Definition: gdal.h:64
GDALRIOResampleAlg
GDALRIOResampleAlg
RasterIO() resampling method.
Definition: gdal.h:143
GDALRasterBandH
void * GDALRasterBandH
Opaque type used for the C bindings of the C++ GDALRasterBand class.
Definition: gdal.h:294
gdal_priv.h
C++ GDAL entry points.
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:1882
GDALCreatePansharpenOperation
GDALPansharpenOperationH GDALCreatePansharpenOperation(const GDALPansharpenOptions *)
Instantiate a pansharpening operation.
Definition: gdalpansharpen.cpp:1828
GDALPansharpenAlg
GDALPansharpenAlg
Pansharpening algorithms.
Definition: gdalpansharpen.h:48
GDAL_PSH_WEIGHTED_BROVEY
@ GDAL_PSH_WEIGHTED_BROVEY
Definition: gdalpansharpen.h:50
GDALDestroyPansharpenOptions
void GDALDestroyPansharpenOptions(GDALPansharpenOptions *)
Destroy pansharpening options.
Definition: gdalpansharpen.cpp:89
GDALPansharpenOperationH
void * GDALPansharpenOperationH
Definition: gdalpansharpen.h:115
GDALCreatePansharpenOptions
GDALPansharpenOptions * GDALCreatePansharpenOptions(void)
Create pansharpening options.
Definition: gdalpansharpen.cpp:68
GDALClonePansharpenOptions
GDALPansharpenOptions * GDALClonePansharpenOptions(const GDALPansharpenOptions *psOptions)
Clone pansharpening options.
Definition: gdalpansharpen.cpp:114
GDALDestroyPansharpenOperation
void GDALDestroyPansharpenOperation(GDALPansharpenOperationH)
Destroy a pansharpening operation.
Definition: gdalpansharpen.cpp:1848
GDALPansharpenOptions
Pansharpening options.
Definition: gdalpansharpen.h:56
GDALPansharpenOptions::ePansharpenAlg
GDALPansharpenAlg ePansharpenAlg
Definition: gdalpansharpen.h:58
GDALPansharpenOptions::bHasNoData
int bHasNoData
Definition: gdalpansharpen.h:96
GDALPansharpenOptions::nBitDepth
int nBitDepth
Definition: gdalpansharpen.h:66
GDALPansharpenOptions::padfWeights
double * padfWeights
Definition: gdalpansharpen.h:72
GDALPansharpenOptions::nThreads
int nThreads
Number of threads or -1 to mean ALL_CPUS.
Definition: gdalpansharpen.h:106
GDALPansharpenOptions::nWeightCount
int nWeightCount
Definition: gdalpansharpen.h:69
GDALPansharpenOptions::pahInputSpectralBands
GDALRasterBandH * pahInputSpectralBands
Array of nInputSpectralBands input spectral bands.
Definition: gdalpansharpen.h:86
GDALPansharpenOptions::panOutPansharpenedBands
int * panOutPansharpenedBands
Definition: gdalpansharpen.h:93
GDALPansharpenOptions::eResampleAlg
GDALRIOResampleAlg eResampleAlg
Definition: gdalpansharpen.h:62
GDALPansharpenOptions::hPanchroBand
GDALRasterBandH hPanchroBand
Definition: gdalpansharpen.h:75
GDALPansharpenOptions::nInputSpectralBands
int nInputSpectralBands
Definition: gdalpansharpen.h:78
GDALPansharpenOptions::nOutPansharpenedBands
int nOutPansharpenedBands
Definition: gdalpansharpen.h:89
GDALPansharpenOptions::dfNoData
double dfNoData
NoData value of the panchromatic and spectral bands (only taken into account if bHasNoData = TRUE).
Definition: gdalpansharpen.h:101