GDAL
gdalpansharpen.h
Go to the documentation of this file.
1 /******************************************************************************
2  * $Id: gdalpansharpen.h fe2d81c8819bf9794bce0210098e637565728350 2018-05-06 00:49:51 +0200 Even Rouault $
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 
36 
47 typedef enum
48 {
52 
55 typedef struct
56 {
59 
62 
64  int nBitDepth;
65 
68 
70  double *padfWeights;
71 
74 
77 
85 
88 
91 
94 
97  double dfNoData;
98 
101  int nThreads;
102 
104  double dfMSShiftX;
105 
107  double dfMSShiftY;
108 
110 
114  const GDALPansharpenOptions* psOptions);
115 
118 
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 
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 
189 {
191 
192  GDALPansharpenOptions* psOptions = nullptr;
193  std::vector<int> anInputBands{};
194  std::vector<GDALDataset*> aVDS{}; // to destroy
195  std::vector<GDALRasterBand*> aMSBands{}; // original multispectral bands potentially warped into a VRT
196  int bPositiveWeights = TRUE;
197  CPLWorkerThreadPool* poThreadPool = nullptr;
198  int nKernelRadius = 0;
199 
200  static void PansharpenJobThreadFunc(void* pUserData);
201  static void PansharpenResampleJobThreadFunc(void* pUserData);
202 
203  template<class WorkDataType, class OutDataType> void WeightedBroveyWithNoData(
204  const WorkDataType* pPanBuffer,
205  const WorkDataType* pUpsampledSpectralBuffer,
206  OutDataType* pDataBuf,
207  int nValues,
208  int nBandValues,
209  WorkDataType nMaxValue) const;
210  template<class WorkDataType, class OutDataType, int bHasBitDepth> void WeightedBrovey3(
211  const WorkDataType* pPanBuffer,
212  const WorkDataType* pUpsampledSpectralBuffer,
213  OutDataType* pDataBuf,
214  int nValues,
215  int nBandValues,
216  WorkDataType nMaxValue) const;
217 
218  // cppcheck-suppress functionStatic
219  template<class WorkDataType, class OutDataType> void WeightedBrovey(
220  const WorkDataType* pPanBuffer,
221  const WorkDataType* pUpsampledSpectralBuffer,
222  OutDataType* pDataBuf,
223  int nValues,
224  int nBandValues,
225  WorkDataType nMaxValue) const;
226  template<class WorkDataType> CPLErr WeightedBrovey(
227  const WorkDataType* pPanBuffer,
228  const WorkDataType* pUpsampledSpectralBuffer,
229  void *pDataBuf,
230  GDALDataType eBufDataType,
231  int nValues,
232  int nBandValues,
233  WorkDataType nMaxValue) const;
234 
235  // cppcheck-suppress functionStatic
236  template<class WorkDataType> CPLErr WeightedBrovey(
237  const WorkDataType* pPanBuffer,
238  const WorkDataType* pUpsampledSpectralBuffer,
239  void *pDataBuf,
240  GDALDataType eBufDataType,
241  int nValues,
242  int nBandValues) const;
243  template<class T> void WeightedBroveyPositiveWeights(
244  const T* pPanBuffer,
245  const T* pUpsampledSpectralBuffer,
246  T* pDataBuf,
247  int nValues,
248  int nBandValues,
249  T nMaxValue) const;
250 
251  template<class T, int NINPUT, int NOUTPUT> int WeightedBroveyPositiveWeightsInternal(
252  const T* pPanBuffer,
253  const T* pUpsampledSpectralBuffer,
254  T* pDataBuf,
255  int nValues,
256  int nBandValues,
257  T nMaxValue) const;
258 
259  // cppcheck-suppress unusedPrivateFunction
260  template<class T> void WeightedBroveyGByteOrUInt16(
261  const T* pPanBuffer,
262  const T* pUpsampledSpectralBuffer,
263  T* pDataBuf,
264  int nValues,
265  int nBandValues,
266  T nMaxValue ) const;
267 
268  CPLErr PansharpenChunk( GDALDataType eWorkDataType, GDALDataType eBufDataType,
269  const void* pPanBuffer,
270  const void* pUpsampledSpectralBuffer,
271  void* pDataBuf,
272  int nValues,
273  int nBandValues,
274  GUInt32 nMaxValue) const;
275  public:
278 
279  CPLErr Initialize(const GDALPansharpenOptions* psOptions);
280  CPLErr ProcessRegion(int nXOff, int nYOff,
281  int nXSize, int nYSize,
282  void *pDataBuf,
283  GDALDataType eBufDataType);
285 };
286 
287 #endif /* __cplusplus */
288 
289 #endif /* GDALPANSHARPEN_H_INCLUDED */
GDALDataType
Definition: gdal.h:60
Definition: gdalpansharpen.h:50
double dfMSShiftY
Shift in pixels of multispectral bands w.r.t panchromatic band, in Y direction.
Definition: gdalpansharpen.h:107
GDALPansharpenOptions * GDALCreatePansharpenOptions(void)
Create pansharpening options.
Definition: gdalpansharpen.cpp:68
GDALPansharpenAlg ePansharpenAlg
Definition: gdalpansharpen.h:58
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:337
C++ GDAL entry points.
unsigned int GUInt32
Unsigned int32 type.
Definition: cpl_port.h:207
GDALRIOResampleAlg
RasterIO() resampling method.
Definition: gdal.h:128
double dfNoData
NoData value of the panchromatic and spectral bands (only taken into account if bHasNoData = TRUE)...
Definition: gdalpansharpen.h:97
int bHasNoData
Definition: gdalpansharpen.h:93
void * GDALRasterBandH
Opaque type used for the C bindings of the C++ GDALRasterBand class.
Definition: gdal.h:258
double dfMSShiftX
Shift in pixels of multispectral bands w.r.t panchromatic band, in X direction.
Definition: gdalpansharpen.h:104
Pansharpening operation class.
Definition: gdalpansharpen.h:188
GDALPansharpenAlg
Pansharpening algorithms.
Definition: gdalpansharpen.h:47
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:1802
int nWeightCount
Definition: gdalpansharpen.h:67
void * GDALPansharpenOperationH
Definition: gdalpansharpen.h:117
GDALPansharpenOptions * GDALClonePansharpenOptions(const GDALPansharpenOptions *psOptions)
Clone pansharpening options.
Definition: gdalpansharpen.cpp:113
int nThreads
Number of threads or -1 to mean ALL_CPUS.
Definition: gdalpansharpen.h:101
GIntBig GSpacing
Type to express pixel, line or band spacing.
Definition: gdal.h:273
int nBitDepth
Definition: gdalpansharpen.h:64
CPLErr Initialize(const GDALPansharpenOptions *psOptions)
Initialize the pansharpening operation.
Definition: gdalpansharpen.cpp:193
Public (C callable) GDAL entry points.
int nInputSpectralBands
Definition: gdalpansharpen.h:76
void GDALDestroyPansharpenOperation(GDALPansharpenOperationH)
Destroy a pansharpening operation.
Definition: gdalpansharpen.cpp:1768
~GDALPansharpenOperation()
Pansharpening operation destructor.
Definition: gdalpansharpen.cpp:174
int * panOutPansharpenedBands
Definition: gdalpansharpen.h:90
double * padfWeights
Definition: gdalpansharpen.h:70
Pansharpening options.
Definition: gdalpansharpen.h:55
void GDALDestroyPansharpenOptions(GDALPansharpenOptions *)
Destroy pansharpening options.
Definition: gdalpansharpen.cpp:89
GDALRasterBandH * pahInputSpectralBands
Array of nInputSpectralBands input spectral bands.
Definition: gdalpansharpen.h:84
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:1044
GDALPansharpenOperation()
Pansharpening operation constructor.
Class to manage a pool of worker threads.
Pool of worker threads.
Definition: cpl_worker_thread_pool.h:75
A set of associated raster bands, usually from one file.
Definition: gdal_priv.h:335
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:339
GDALPansharpenOperationH GDALCreatePansharpenOperation(const GDALPansharpenOptions *)
Instantiate a pansharpening operation.
Definition: gdalpansharpen.cpp:1747
GDALRasterBandH hPanchroBand
Definition: gdalpansharpen.h:73
GDALRIOResampleAlg eResampleAlg
Definition: gdalpansharpen.h:61
CPLErr
Error category.
Definition: cpl_error.h:52
GDALPansharpenOptions * GetOptions()
Return options.
Definition: gdalpansharpen.cpp:1727
#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:989
int nOutPansharpenedBands
Definition: gdalpansharpen.h:87

Generated for GDAL by doxygen 1.8.13.