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 typedef struct
144{
145 GDALDataset *poMEMDS;
146 int nXOff;
147 int nYOff;
148 int nXSize;
149 int nYSize;
150 double dfXOff;
151 double dfYOff;
152 double dfXSize;
153 double dfYSize;
154 void *pBuffer;
155 GDALDataType eDT;
156 int nBufXSize;
157 int nBufYSize;
158 int nBandCount;
159 GDALRIOResampleAlg eResampleAlg;
160 GSpacing nBandSpace;
161
162#ifdef DEBUG_TIMING
163 struct timeval *ptv;
164#endif
165} GDALPansharpenResampleJob;
166
167 class CPLWorkerThreadPool;
168
170
173 class GDALPansharpenOperation
174{
175 CPL_DISALLOW_COPY_ASSIGN(GDALPansharpenOperation)
176
177 GDALPansharpenOptions *psOptions = nullptr;
178 std::vector<int> anInputBands{};
179 std::vector<GDALDataset *> aVDS{}; // to destroy
180 std::vector<GDALRasterBand *> aMSBands{}; // original multispectral bands
181 // potentially warped into a VRT
182 int bPositiveWeights = TRUE;
183 CPLWorkerThreadPool *poThreadPool = nullptr;
184 int nKernelRadius = 0;
185 std::array<double, 6> m_adfPanToMSGT = {{0.0, 1.0, 0, 0.0, 0.0, 1.0}};
186
187 static void PansharpenJobThreadFunc(void *pUserData);
188 static void PansharpenResampleJobThreadFunc(void *pUserData);
189
190 template <class WorkDataType, class OutDataType>
191 void WeightedBroveyWithNoData(const WorkDataType *pPanBuffer,
192 const WorkDataType *pUpsampledSpectralBuffer,
193 OutDataType *pDataBuf, size_t nValues,
194 size_t nBandValues,
195 WorkDataType nMaxValue) const;
196 template <class WorkDataType, class OutDataType, int bHasBitDepth>
197 void WeightedBrovey3(const WorkDataType *pPanBuffer,
198 const WorkDataType *pUpsampledSpectralBuffer,
199 OutDataType *pDataBuf, size_t nValues,
200 size_t nBandValues, WorkDataType nMaxValue) const;
201
202 // cppcheck-suppress functionStatic
203 template <class WorkDataType, class OutDataType>
204 void WeightedBrovey(const WorkDataType *pPanBuffer,
205 const WorkDataType *pUpsampledSpectralBuffer,
206 OutDataType *pDataBuf, size_t nValues,
207 size_t nBandValues, WorkDataType nMaxValue) const;
208 template <class WorkDataType>
209 CPLErr WeightedBrovey(const WorkDataType *pPanBuffer,
210 const WorkDataType *pUpsampledSpectralBuffer,
211 void *pDataBuf, GDALDataType eBufDataType,
212 size_t nValues, size_t nBandValues,
213 WorkDataType nMaxValue) const;
214
215 // cppcheck-suppress functionStatic
216 template <class WorkDataType>
217 CPLErr WeightedBrovey(const WorkDataType *pPanBuffer,
218 const WorkDataType *pUpsampledSpectralBuffer,
219 void *pDataBuf, GDALDataType eBufDataType,
220 size_t nValues, size_t nBandValues) const;
221 template <class T>
222 void WeightedBroveyPositiveWeights(const T *pPanBuffer,
223 const T *pUpsampledSpectralBuffer,
224 T *pDataBuf, size_t nValues,
225 size_t nBandValues, T nMaxValue) const;
226
227 template <class T, int NINPUT, int NOUTPUT>
228 size_t WeightedBroveyPositiveWeightsInternal(
229 const T *pPanBuffer, const T *pUpsampledSpectralBuffer, T *pDataBuf,
230 size_t nValues, size_t nBandValues, T nMaxValue) const;
231
232 // cppcheck-suppress unusedPrivateFunction
233 template <class T>
234 void WeightedBroveyGByteOrUInt16(const T *pPanBuffer,
235 const T *pUpsampledSpectralBuffer,
236 T *pDataBuf, size_t nValues,
237 size_t nBandValues, T nMaxValue) const;
238
239 // cppcheck-suppress functionStatic
240 CPLErr PansharpenChunk(GDALDataType eWorkDataType,
241 GDALDataType eBufDataType, const void *pPanBuffer,
242 const void *pUpsampledSpectralBuffer, void *pDataBuf,
243 size_t nValues, size_t nBandValues,
244 GUInt32 nMaxValue) const;
245
246 public:
247 GDALPansharpenOperation();
248 ~GDALPansharpenOperation();
249
250 CPLErr Initialize(const GDALPansharpenOptions *psOptions);
251 CPLErr ProcessRegion(int nXOff, int nYOff, int nXSize, int nYSize,
252 void *pDataBuf, GDALDataType eBufDataType);
253 GDALPansharpenOptions *GetOptions();
254};
255
256#endif /* __cplusplus */
257
258#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:174
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:1798
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
GDALRIOResampleAlg
GDALRIOResampleAlg
RasterIO() resampling method.
Definition: gdal.h:128
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:1873
GDALCreatePansharpenOperation
GDALPansharpenOperationH GDALCreatePansharpenOperation(const GDALPansharpenOptions *)
Instantiate a pansharpening operation.
Definition: gdalpansharpen.cpp:1819
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:1839
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