gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

290 lines
12KB

  1. /******************************************************************************
  2. * $Id: gdalpansharpen.h cde29aa7b4807045c418e469b59b60f92af59468 2019-02-18 15:49:24 +0100 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. #ifndef GDALPANSHARPEN_H_INCLUDED
  30. #define GDALPANSHARPEN_H_INCLUDED
  31. #include "gdal.h"
  32. CPL_C_START
  33. /**
  34. * \file gdalpansharpen.h
  35. *
  36. * GDAL pansharpening related entry points and definitions.
  37. *
  38. * @since GDAL 2.1
  39. */
  40. /** Pansharpening algorithms.
  41. */
  42. typedef enum
  43. {
  44. /*! Weighted Brovery. */
  45. GDAL_PSH_WEIGHTED_BROVEY
  46. } GDALPansharpenAlg;
  47. /** Pansharpening options.
  48. */
  49. typedef struct
  50. {
  51. /*! Pan sharpening algorithm/method. Only weighed Brovey for now. */
  52. GDALPansharpenAlg ePansharpenAlg;
  53. /*! Resampling algorithm to upsample spectral bands to pan band resolution. */
  54. GDALRIOResampleAlg eResampleAlg;
  55. /*! Bit depth of the spectral bands. Can be let to 0 for default behaviour. */
  56. int nBitDepth;
  57. /*! Number of weight coefficients in padfWeights. */
  58. int nWeightCount;
  59. /*! Array of nWeightCount weights used by weighted Brovey. */
  60. double *padfWeights;
  61. /*! Panchromatic band. */
  62. GDALRasterBandH hPanchroBand;
  63. /*! Number of input spectral bands. */
  64. int nInputSpectralBands;
  65. /** Array of nInputSpectralBands input spectral bands. The spectral band have
  66. * generally a coarser resolution than the panchromatic band, but they
  67. * are assumed to have the same spatial extent (and projection) at that point.
  68. * Necessary spatial adjustments must be done beforehand, for example by wrapping
  69. * inside a VRT dataset.
  70. */
  71. GDALRasterBandH *pahInputSpectralBands;
  72. /*! Number of output pansharpened spectral bands. */
  73. int nOutPansharpenedBands;
  74. /*! Array of nOutPansharpendBands values such as panOutPansharpenedBands[k] is a value in the range [0,nInputSpectralBands-1] . */
  75. int *panOutPansharpenedBands;
  76. /*! Whether the panchromatic and spectral bands have a noData value. */
  77. int bHasNoData;
  78. /** NoData value of the panchromatic and spectral bands (only taken into account if bHasNoData = TRUE).
  79. This will also be use has the output nodata value. */
  80. double dfNoData;
  81. /** Number of threads or -1 to mean ALL_CPUS. By default (0), single threaded mode is enabled
  82. * unless the GDAL_NUM_THREADS configuration option is set to an integer or ALL_CPUS. */
  83. int nThreads;
  84. /** Shift in pixels of multispectral bands w.r.t panchromatic band, in X direction */
  85. double dfMSShiftX;
  86. /** Shift in pixels of multispectral bands w.r.t panchromatic band, in Y direction */
  87. double dfMSShiftY;
  88. } GDALPansharpenOptions;
  89. GDALPansharpenOptions CPL_DLL * GDALCreatePansharpenOptions(void);
  90. void CPL_DLL GDALDestroyPansharpenOptions( GDALPansharpenOptions * );
  91. GDALPansharpenOptions CPL_DLL * GDALClonePansharpenOptions(
  92. const GDALPansharpenOptions* psOptions);
  93. /*! Pansharpening operation handle. */
  94. typedef void* GDALPansharpenOperationH;
  95. GDALPansharpenOperationH CPL_DLL GDALCreatePansharpenOperation(const GDALPansharpenOptions* );
  96. void CPL_DLL GDALDestroyPansharpenOperation( GDALPansharpenOperationH );
  97. CPLErr CPL_DLL GDALPansharpenProcessRegion( GDALPansharpenOperationH hOperation,
  98. int nXOff, int nYOff,
  99. int nXSize, int nYSize,
  100. void *pDataBuf,
  101. GDALDataType eBufDataType);
  102. CPL_C_END
  103. #ifdef __cplusplus
  104. #include <vector>
  105. #include "gdal_priv.h"
  106. #include "cpl_worker_thread_pool.h"
  107. #ifdef DEBUG_TIMING
  108. #include <sys/time.h>
  109. #endif
  110. class GDALPansharpenOperation;
  111. //! @cond Doxygen_Suppress
  112. typedef struct
  113. {
  114. GDALPansharpenOperation* poPansharpenOperation;
  115. GDALDataType eWorkDataType;
  116. GDALDataType eBufDataType;
  117. const void* pPanBuffer;
  118. const void* pUpsampledSpectralBuffer;
  119. void* pDataBuf;
  120. size_t nValues;
  121. size_t nBandValues;
  122. GUInt32 nMaxValue;
  123. #ifdef DEBUG_TIMING
  124. struct timeval* ptv;
  125. #endif
  126. CPLErr eErr;
  127. } GDALPansharpenJob;
  128. typedef struct
  129. {
  130. GDALDataset* poMEMDS;
  131. int nXOff;
  132. int nYOff;
  133. int nXSize;
  134. int nYSize;
  135. double dfXOff;
  136. double dfYOff;
  137. double dfXSize;
  138. double dfYSize;
  139. void *pBuffer;
  140. GDALDataType eDT;
  141. int nBufXSize;
  142. int nBufYSize;
  143. int nBandCount;
  144. GDALRIOResampleAlg eResampleAlg;
  145. GSpacing nBandSpace;
  146. #ifdef DEBUG_TIMING
  147. struct timeval* ptv;
  148. #endif
  149. } GDALPansharpenResampleJob;
  150. //! @endcond
  151. /** Pansharpening operation class.
  152. */
  153. class GDALPansharpenOperation
  154. {
  155. CPL_DISALLOW_COPY_ASSIGN(GDALPansharpenOperation)
  156. GDALPansharpenOptions* psOptions = nullptr;
  157. std::vector<int> anInputBands{};
  158. std::vector<GDALDataset*> aVDS{}; // to destroy
  159. std::vector<GDALRasterBand*> aMSBands{}; // original multispectral bands potentially warped into a VRT
  160. int bPositiveWeights = TRUE;
  161. CPLWorkerThreadPool* poThreadPool = nullptr;
  162. int nKernelRadius = 0;
  163. static void PansharpenJobThreadFunc(void* pUserData);
  164. static void PansharpenResampleJobThreadFunc(void* pUserData);
  165. template<class WorkDataType, class OutDataType> void WeightedBroveyWithNoData(
  166. const WorkDataType* pPanBuffer,
  167. const WorkDataType* pUpsampledSpectralBuffer,
  168. OutDataType* pDataBuf,
  169. size_t nValues,
  170. size_t nBandValues,
  171. WorkDataType nMaxValue) const;
  172. template<class WorkDataType, class OutDataType, int bHasBitDepth> void WeightedBrovey3(
  173. const WorkDataType* pPanBuffer,
  174. const WorkDataType* pUpsampledSpectralBuffer,
  175. OutDataType* pDataBuf,
  176. size_t nValues,
  177. size_t nBandValues,
  178. WorkDataType nMaxValue) const;
  179. // cppcheck-suppress functionStatic
  180. template<class WorkDataType, class OutDataType> void WeightedBrovey(
  181. const WorkDataType* pPanBuffer,
  182. const WorkDataType* pUpsampledSpectralBuffer,
  183. OutDataType* pDataBuf,
  184. size_t nValues,
  185. size_t nBandValues,
  186. WorkDataType nMaxValue) const;
  187. template<class WorkDataType> CPLErr WeightedBrovey(
  188. const WorkDataType* pPanBuffer,
  189. const WorkDataType* pUpsampledSpectralBuffer,
  190. void *pDataBuf,
  191. GDALDataType eBufDataType,
  192. size_t nValues,
  193. size_t nBandValues,
  194. WorkDataType nMaxValue) const;
  195. // cppcheck-suppress functionStatic
  196. template<class WorkDataType> CPLErr WeightedBrovey(
  197. const WorkDataType* pPanBuffer,
  198. const WorkDataType* pUpsampledSpectralBuffer,
  199. void *pDataBuf,
  200. GDALDataType eBufDataType,
  201. size_t nValues,
  202. size_t nBandValues) const;
  203. template<class T> void WeightedBroveyPositiveWeights(
  204. const T* pPanBuffer,
  205. const T* pUpsampledSpectralBuffer,
  206. T* pDataBuf,
  207. size_t nValues,
  208. size_t nBandValues,
  209. T nMaxValue) const;
  210. template<class T, int NINPUT, int NOUTPUT> size_t WeightedBroveyPositiveWeightsInternal(
  211. const T* pPanBuffer,
  212. const T* pUpsampledSpectralBuffer,
  213. T* pDataBuf,
  214. size_t nValues,
  215. size_t nBandValues,
  216. T nMaxValue) const;
  217. // cppcheck-suppress unusedPrivateFunction
  218. template<class T> void WeightedBroveyGByteOrUInt16(
  219. const T* pPanBuffer,
  220. const T* pUpsampledSpectralBuffer,
  221. T* pDataBuf,
  222. size_t nValues,
  223. size_t nBandValues,
  224. T nMaxValue ) const;
  225. CPLErr PansharpenChunk( GDALDataType eWorkDataType, GDALDataType eBufDataType,
  226. const void* pPanBuffer,
  227. const void* pUpsampledSpectralBuffer,
  228. void* pDataBuf,
  229. size_t nValues,
  230. size_t nBandValues,
  231. GUInt32 nMaxValue) const;
  232. public:
  233. GDALPansharpenOperation();
  234. ~GDALPansharpenOperation();
  235. CPLErr Initialize(const GDALPansharpenOptions* psOptions);
  236. CPLErr ProcessRegion(int nXOff, int nYOff,
  237. int nXSize, int nYSize,
  238. void *pDataBuf,
  239. GDALDataType eBufDataType);
  240. GDALPansharpenOptions* GetOptions();
  241. };
  242. #endif /* __cplusplus */
  243. #endif /* GDALPANSHARPEN_H_INCLUDED */
上海开阖软件有限公司 沪ICP备12045867号-1