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