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 * SPDX-License-Identifier: MIT
12 ****************************************************************************/
13
14#ifndef GDALPANSHARPEN_H_INCLUDED
15#define GDALPANSHARPEN_H_INCLUDED
16
17#include "gdal.h"
18
19 CPL_C_START
20
31 typedef enum
32{
34 GDAL_PSH_WEIGHTED_BROVEY
35} GDALPansharpenAlg;
36
39 typedef struct
40{
42 GDALPansharpenAlg ePansharpenAlg;
43
46 GDALRIOResampleAlg eResampleAlg;
47
50 int nBitDepth;
51
53 int nWeightCount;
54
56 double *padfWeights;
57
59 GDALRasterBandH hPanchroBand;
60
62 int nInputSpectralBands;
63
70 GDALRasterBandH *pahInputSpectralBands;
71
73 int nOutPansharpenedBands;
74
77 int *panOutPansharpenedBands;
78
80 int bHasNoData;
81
85 double dfNoData;
86
90 int nThreads;
91} GDALPansharpenOptions;
92
93 GDALPansharpenOptions CPL_DLL *GDALCreatePansharpenOptions(void);
94 void CPL_DLL GDALDestroyPansharpenOptions(GDALPansharpenOptions *);
95 GDALPansharpenOptions CPL_DLL *
96 GDALClonePansharpenOptions(const GDALPansharpenOptions *psOptions);
97
99 typedef void *GDALPansharpenOperationH;
100
101 GDALPansharpenOperationH CPL_DLL
102 GDALCreatePansharpenOperation(const GDALPansharpenOptions *);
103 void CPL_DLL GDALDestroyPansharpenOperation(GDALPansharpenOperationH);
104 CPLErr CPL_DLL GDALPansharpenProcessRegion(GDALPansharpenOperationH hOperation,
105 int nXOff, int nYOff, int nXSize,
106 int nYSize, void *pDataBuf,
107 GDALDataType eBufDataType);
108
109 CPL_C_END
110
111#ifdef __cplusplus
112
113#include <array>
114#include <vector>
115#include "gdal_priv.h"
116
117#ifdef DEBUG_TIMING
118#include <sys/time.h>
119#endif
120
121 class GDALPansharpenOperation;
122
124 typedef struct
125{
126 GDALPansharpenOperation *poPansharpenOperation;
127 GDALDataType eWorkDataType;
128 GDALDataType eBufDataType;
129 const void *pPanBuffer;
130 const void *pUpsampledSpectralBuffer;
131 void *pDataBuf;
132 size_t nValues;
133 size_t nBandValues;
134 GUInt32 nMaxValue;
135
136#ifdef DEBUG_TIMING
137 struct timeval *ptv;
138#endif
139
140 CPLErr eErr;
141} GDALPansharpenJob;
142
143 struct GDALPansharpenResampleJob
144{
145 GDALDataset *poMEMDS = nullptr;
146 int nXOff = 0;
147 int nYOff = 0;
148 int nXSize = 0;
149 int nYSize = 0;
150 double dfXOff = 0;
151 double dfYOff = 0;
152 double dfXSize = 0;
153 double dfYSize = 0;
154 void *pBuffer = nullptr;
155 GDALDataType eDT = GDT_Unknown;
156 int nBufXSize = 0;
157 int nBufYSize = 0;
158 int nBandCount = 0;
159 GDALRIOResampleAlg eResampleAlg = GRIORA_NearestNeighbour;
160 GSpacing nBandSpace = 0;
161
162#ifdef DEBUG_TIMING
163 struct timeval *ptv = nullptr;
164#endif
165
166 CPLErr eErr = CE_Failure;
167 std::string osLastErrorMsg{};
168};
169
170 class CPLWorkerThreadPool;
171
173
176 class GDALPansharpenOperation
177{
178 CPL_DISALLOW_COPY_ASSIGN(GDALPansharpenOperation)
179
180 GDALPansharpenOptions *psOptions = nullptr;
181 std::vector<int> anInputBands{};
182 std::vector<GDALDataset *> aVDS{}; // to destroy
183 std::vector<GDALRasterBand *> aMSBands{}; // original multispectral bands
184 // potentially warped into a VRT
185 int bPositiveWeights = TRUE;
186 CPLWorkerThreadPool *poThreadPool = nullptr;
187 int nKernelRadius = 0;
188 std::array<double, 6> m_adfPanToMSGT = {{0.0, 1.0, 0, 0.0, 0.0, 1.0}};
189
190 static void PansharpenJobThreadFunc(void *pUserData);
191 static void PansharpenResampleJobThreadFunc(void *pUserData);
192
193 template <class WorkDataType, class OutDataType>
194 void WeightedBroveyWithNoData(const WorkDataType *pPanBuffer,
195 const WorkDataType *pUpsampledSpectralBuffer,
196 OutDataType *pDataBuf, size_t nValues,
197 size_t nBandValues,
198 WorkDataType nMaxValue) const;
199 template <class WorkDataType, class OutDataType, int bHasBitDepth>
200 void WeightedBrovey3(const WorkDataType *pPanBuffer,
201 const WorkDataType *pUpsampledSpectralBuffer,
202 OutDataType *pDataBuf, size_t nValues,
203 size_t nBandValues, WorkDataType nMaxValue) const;
204
205 // cppcheck-suppress functionStatic
206 template <class WorkDataType, class OutDataType>
207 void WeightedBrovey(const WorkDataType *pPanBuffer,
208 const WorkDataType *pUpsampledSpectralBuffer,
209 OutDataType *pDataBuf, size_t nValues,
210 size_t nBandValues, WorkDataType nMaxValue) const;
211 template <class WorkDataType>
212 CPLErr WeightedBrovey(const WorkDataType *pPanBuffer,
213 const WorkDataType *pUpsampledSpectralBuffer,
214 void *pDataBuf, GDALDataType eBufDataType,
215 size_t nValues, size_t nBandValues,
216 WorkDataType nMaxValue) const;
217
218 // cppcheck-suppress functionStatic
219 template <class WorkDataType>
220 CPLErr WeightedBrovey(const WorkDataType *pPanBuffer,
221 const WorkDataType *pUpsampledSpectralBuffer,
222 void *pDataBuf, GDALDataType eBufDataType,
223 size_t nValues, size_t nBandValues) const;
224 template <class T>
225 void WeightedBroveyPositiveWeights(const T *pPanBuffer,
226 const T *pUpsampledSpectralBuffer,
227 T *pDataBuf, size_t nValues,
228 size_t nBandValues, T nMaxValue) const;
229
230 template <class T, int NINPUT, int NOUTPUT>
231 size_t WeightedBroveyPositiveWeightsInternal(
232 const T *pPanBuffer, const T *pUpsampledSpectralBuffer, T *pDataBuf,
233 size_t nValues, size_t nBandValues, T nMaxValue) const;
234
235 // cppcheck-suppress unusedPrivateFunction
236 template <class T>
237 void WeightedBroveyGByteOrUInt16(const T *pPanBuffer,
238 const T *pUpsampledSpectralBuffer,
239 T *pDataBuf, size_t nValues,
240 size_t nBandValues, T nMaxValue) const;
241
242 // cppcheck-suppress functionStatic
243 CPLErr PansharpenChunk(GDALDataType eWorkDataType,
244 GDALDataType eBufDataType, const void *pPanBuffer,
245 const void *pUpsampledSpectralBuffer, void *pDataBuf,
246 size_t nValues, size_t nBandValues,
247 GUInt32 nMaxValue) const;
248
249 public:
250 GDALPansharpenOperation();
251 ~GDALPansharpenOperation();
252
253 CPLErr Initialize(const GDALPansharpenOptions *psOptions);
254 CPLErr ProcessRegion(int nXOff, int nYOff, int nXSize, int nYSize,
255 void *pDataBuf, GDALDataType eBufDataType);
256 GDALPansharpenOptions *GetOptions();
257};
258
259#endif /* __cplusplus */
260
261#endif /* GDALPANSHARPEN_H_INCLUDED */
CPLWorkerThreadPool
Pool of worker threads.
Definition cpl_worker_thread_pool.h:66
GDALDataset
A set of associated raster bands, usually from one file.
Definition gdal_priv.h:495
GDALPansharpenOperation
Pansharpening operation class.
Definition gdalpansharpen.h:177
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:1157
GDALPansharpenOperation::GDALPansharpenOperation
GDALPansharpenOperation()
Pansharpening operation constructor.
GDALPansharpenOperation::~GDALPansharpenOperation
~GDALPansharpenOperation()
Pansharpening operation destructor.
Definition gdalpansharpen.cpp:155
GDALPansharpenOperation::GetOptions
GDALPansharpenOptions * GetOptions()
Return options.
Definition gdalpansharpen.cpp:1819
GDALPansharpenOperation::Initialize
CPLErr Initialize(const GDALPansharpenOptions *psOptions)
Initialize the pansharpening operation.
Definition gdalpansharpen.cpp:174
CPLErr
CPLErr
Error category.
Definition cpl_error.h:37
CPL_C_END
#define CPL_C_END
Macro to end a block of C symbols.
Definition cpl_port.h:283
CPL_C_START
#define CPL_C_START
Macro to start a block of C symbols.
Definition cpl_port.h:279
GUInt32
unsigned int GUInt32
Unsigned int32 type.
Definition cpl_port.h:161
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:1030
gdal.h
Public (C callable) GDAL entry points.
GSpacing
GIntBig GSpacing
Type to express pixel, line or band spacing.
Definition gdal.h:400
GDALDataType
GDALDataType
Definition gdal.h:48
GDT_Unknown
@ GDT_Unknown
Definition gdal.h:49
GDALRIOResampleAlg
GDALRIOResampleAlg
RasterIO() resampling method.
Definition gdal.h:128
GRIORA_NearestNeighbour
@ GRIORA_NearestNeighbour
Definition gdal.h:129
GDALRasterBandH
void * GDALRasterBandH
Opaque type used for the C bindings of the C++ GDALRasterBand class.
Definition gdal.h:379
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:1894
GDALCreatePansharpenOperation
GDALPansharpenOperationH GDALCreatePansharpenOperation(const GDALPansharpenOptions *)
Instantiate a pansharpening operation.
Definition gdalpansharpen.cpp:1840
GDALPansharpenAlg
GDALPansharpenAlg
Pansharpening algorithms.
Definition gdalpansharpen.h:32
GDAL_PSH_WEIGHTED_BROVEY
@ GDAL_PSH_WEIGHTED_BROVEY
Definition gdalpansharpen.h:34
GDALDestroyPansharpenOptions
void GDALDestroyPansharpenOptions(GDALPansharpenOptions *)
Destroy pansharpening options.
Definition gdalpansharpen.cpp:73
GDALPansharpenOperationH
void * GDALPansharpenOperationH
Definition gdalpansharpen.h:99
GDALCreatePansharpenOptions
GDALPansharpenOptions * GDALCreatePansharpenOptions(void)
Create pansharpening options.
Definition gdalpansharpen.cpp:52
GDALClonePansharpenOptions
GDALPansharpenOptions * GDALClonePansharpenOptions(const GDALPansharpenOptions *psOptions)
Clone pansharpening options.
Definition gdalpansharpen.cpp:98
GDALDestroyPansharpenOperation
void GDALDestroyPansharpenOperation(GDALPansharpenOperationH)
Destroy a pansharpening operation.
Definition gdalpansharpen.cpp:1860
GDALPansharpenOptions
Pansharpening options.
Definition gdalpansharpen.h:40
GDALPansharpenOptions::ePansharpenAlg
GDALPansharpenAlg ePansharpenAlg
Definition gdalpansharpen.h:42
GDALPansharpenOptions::bHasNoData
int bHasNoData
Definition gdalpansharpen.h:80
GDALPansharpenOptions::nBitDepth
int nBitDepth
Definition gdalpansharpen.h:50
GDALPansharpenOptions::padfWeights
double * padfWeights
Definition gdalpansharpen.h:56
GDALPansharpenOptions::nThreads
int nThreads
Number of threads or -1 to mean ALL_CPUS.
Definition gdalpansharpen.h:90
GDALPansharpenOptions::nWeightCount
int nWeightCount
Definition gdalpansharpen.h:53
GDALPansharpenOptions::pahInputSpectralBands
GDALRasterBandH * pahInputSpectralBands
Array of nInputSpectralBands input spectral bands.
Definition gdalpansharpen.h:70
GDALPansharpenOptions::panOutPansharpenedBands
int * panOutPansharpenedBands
Definition gdalpansharpen.h:77
GDALPansharpenOptions::eResampleAlg
GDALRIOResampleAlg eResampleAlg
Definition gdalpansharpen.h:46
GDALPansharpenOptions::hPanchroBand
GDALRasterBandH hPanchroBand
Definition gdalpansharpen.h:59
GDALPansharpenOptions::nInputSpectralBands
int nInputSpectralBands
Definition gdalpansharpen.h:62
GDALPansharpenOptions::nOutPansharpenedBands
int nOutPansharpenedBands
Definition gdalpansharpen.h:73
GDALPansharpenOptions::dfNoData
double dfNoData
NoData value of the panchromatic and spectral bands (only taken into account if bHasNoData = TRUE).
Definition gdalpansharpen.h:85