GDAL
gdalpansharpen.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  * $Id: gdalpansharpen.h 36427 2016-11-22 12:56:01Z rouault $
00003  *
00004  * Project:  GDAL Pansharpening module
00005  * Purpose:  Prototypes, and definitions for pansharpening related work.
00006  * Author:   Even Rouault <even.rouault at spatialys.com>
00007  *
00008  ******************************************************************************
00009  * Copyright (c) 2015, Even Rouault <even.rouault at spatialys.com>
00010  *
00011  * Permission is hereby granted, free of charge, to any person obtaining a
00012  * copy of this software and associated documentation files (the "Software"),
00013  * to deal in the Software without restriction, including without limitation
00014  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00015  * and/or sell copies of the Software, and to permit persons to whom the
00016  * Software is furnished to do so, subject to the following conditions:
00017  *
00018  * The above copyright notice and this permission notice shall be included
00019  * in all copies or substantial portions of the Software.
00020  *
00021  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00022  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00023  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00024  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00025  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00026  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00027  * DEALINGS IN THE SOFTWARE.
00028  ****************************************************************************/
00029 
00030 #ifndef GDALPANSHARPEN_H_INCLUDED
00031 #define GDALPANSHARPEN_H_INCLUDED
00032 
00033 #include "gdal.h"
00034 
00035 CPL_C_START
00036 
00047 typedef enum
00048 {
00050     GDAL_PSH_WEIGHTED_BROVEY
00051 } GDALPansharpenAlg;
00052 
00055 typedef struct
00056 {
00058     GDALPansharpenAlg    ePansharpenAlg;
00059 
00061     GDALRIOResampleAlg   eResampleAlg;
00062 
00064     int                  nBitDepth;
00065 
00067     int                  nWeightCount;
00068 
00070     double              *padfWeights;
00071 
00073     GDALRasterBandH      hPanchroBand;
00074 
00076     int                  nInputSpectralBands;
00077 
00084     GDALRasterBandH     *pahInputSpectralBands;
00085 
00087     int                  nOutPansharpenedBands;
00088 
00090     int                 *panOutPansharpenedBands;
00091 
00093     int                  bHasNoData;
00094 
00097     double               dfNoData;
00098 
00101     int                  nThreads;
00102 
00104     double               dfMSShiftX;
00105 
00107     double               dfMSShiftY;
00108 
00109 } GDALPansharpenOptions;
00110 
00111 GDALPansharpenOptions CPL_DLL * GDALCreatePansharpenOptions(void);
00112 void CPL_DLL GDALDestroyPansharpenOptions( GDALPansharpenOptions * );
00113 GDALPansharpenOptions CPL_DLL * GDALClonePansharpenOptions(
00114                                         const GDALPansharpenOptions* psOptions);
00115 
00117 typedef void* GDALPansharpenOperationH;
00118 
00119 GDALPansharpenOperationH CPL_DLL GDALCreatePansharpenOperation(const GDALPansharpenOptions* );
00120 void CPL_DLL GDALDestroyPansharpenOperation( GDALPansharpenOperationH );
00121 CPLErr CPL_DLL GDALPansharpenProcessRegion( GDALPansharpenOperationH hOperation,
00122                                             int nXOff, int nYOff,
00123                                             int nXSize, int nYSize,
00124                                             void *pDataBuf,
00125                                             GDALDataType eBufDataType);
00126 
00127 CPL_C_END
00128 
00129 #ifdef __cplusplus
00130 
00131 #include <vector>
00132 #include "gdal_priv.h"
00133 #include "cpl_worker_thread_pool.h"
00134 
00135 #ifdef DEBUG_TIMING
00136 #include <sys/time.h>
00137 #endif
00138 
00139 class GDALPansharpenOperation;
00140 
00142 typedef struct
00143 {
00144     GDALPansharpenOperation* poPansharpenOperation;
00145     GDALDataType eWorkDataType;
00146     GDALDataType eBufDataType;
00147     const void* pPanBuffer;
00148     const void* pUpsampledSpectralBuffer;
00149     void* pDataBuf;
00150     int nValues;
00151     int nBandValues;
00152     GUInt32 nMaxValue;
00153 
00154 #ifdef DEBUG_TIMING
00155     struct timeval* ptv;
00156 #endif
00157 
00158     CPLErr eErr;
00159 } GDALPansharpenJob;
00160 
00161 typedef struct
00162 {
00163     GDALDataset* poMEMDS;
00164     int          nXOff;
00165     int          nYOff;
00166     int          nXSize;
00167     int          nYSize;
00168     double       dfXOff;
00169     double       dfYOff;
00170     double       dfXSize;
00171     double       dfYSize;
00172     void        *pBuffer;
00173     GDALDataType eDT;
00174     int          nBufXSize;
00175     int          nBufYSize;
00176     int          nBandCount;
00177     GDALRIOResampleAlg eResampleAlg;
00178     GSpacing     nBandSpace;
00179 
00180 #ifdef DEBUG_TIMING
00181     struct timeval* ptv;
00182 #endif
00183 } GDALPansharpenResampleJob;
00185 
00188 class GDALPansharpenOperation
00189 {
00190         GDALPansharpenOptions* psOptions;
00191         std::vector<int> anInputBands;
00192         std::vector<GDALDataset*> aVDS; // to destroy
00193         std::vector<GDALRasterBand*> aMSBands; // original multispectral bands potentially warped into a VRT
00194         int bPositiveWeights;
00195         CPLWorkerThreadPool* poThreadPool;
00196         int nKernelRadius;
00197 
00198         static void PansharpenJobThreadFunc(void* pUserData);
00199         static void PansharpenResampleJobThreadFunc(void* pUserData);
00200 
00201         template<class WorkDataType, class OutDataType> void WeightedBroveyWithNoData(
00202                                                      const WorkDataType* pPanBuffer,
00203                                                      const WorkDataType* pUpsampledSpectralBuffer,
00204                                                      OutDataType* pDataBuf,
00205                                                      int nValues,
00206                                                      int nBandValues,
00207                                                      WorkDataType nMaxValue) const;
00208         template<class WorkDataType, class OutDataType, int bHasBitDepth> void WeightedBrovey3(
00209                                                      const WorkDataType* pPanBuffer,
00210                                                      const WorkDataType* pUpsampledSpectralBuffer,
00211                                                      OutDataType* pDataBuf,
00212                                                      int nValues,
00213                                                      int nBandValues,
00214                                                      WorkDataType nMaxValue) const;
00215 
00216         // cppcheck-suppress functionStatic
00217         template<class WorkDataType, class OutDataType> void WeightedBrovey(
00218                                                      const WorkDataType* pPanBuffer,
00219                                                      const WorkDataType* pUpsampledSpectralBuffer,
00220                                                      OutDataType* pDataBuf,
00221                                                      int nValues,
00222                                                      int nBandValues,
00223                                                      WorkDataType nMaxValue) const;
00224         template<class WorkDataType> CPLErr WeightedBrovey(
00225                                                      const WorkDataType* pPanBuffer,
00226                                                      const WorkDataType* pUpsampledSpectralBuffer,
00227                                                      void *pDataBuf,
00228                                                      GDALDataType eBufDataType,
00229                                                      int nValues,
00230                                                      int nBandValues,
00231                                                      WorkDataType nMaxValue) const;
00232 
00233         // cppcheck-suppress functionStatic
00234         template<class WorkDataType> CPLErr WeightedBrovey(
00235                                                      const WorkDataType* pPanBuffer,
00236                                                      const WorkDataType* pUpsampledSpectralBuffer,
00237                                                      void *pDataBuf,
00238                                                      GDALDataType eBufDataType,
00239                                                      int nValues,
00240                                                      int nBandValues) const;
00241         void WeightedBroveyPositiveWeights(
00242                                                      const GUInt16* pPanBuffer,
00243                                                      const GUInt16* pUpsampledSpectralBuffer,
00244                                                      GUInt16* pDataBuf,
00245                                                      int nValues,
00246                                                      int nBandValues,
00247                                                      GUInt16 nMaxValue) const;
00248 
00249         template<int NINPUT, int NOUTPUT> int WeightedBroveyPositiveWeightsInternal(
00250                                                      const GUInt16* pPanBuffer,
00251                                                      const GUInt16* pUpsampledSpectralBuffer,
00252                                                      GUInt16* pDataBuf,
00253                                                      int nValues,
00254                                                      int nBandValues,
00255                                                      GUInt16 nMaxValue) const;
00256 
00257         CPLErr PansharpenChunk( GDALDataType eWorkDataType, GDALDataType eBufDataType,
00258                                                      const void* pPanBuffer,
00259                                                      const void* pUpsampledSpectralBuffer,
00260                                                      void* pDataBuf,
00261                                                      int nValues,
00262                                                      int nBandValues,
00263                                                      GUInt32 nMaxValue) const;
00264     public:
00265                              GDALPansharpenOperation();
00266                             ~GDALPansharpenOperation();
00267 
00268         CPLErr               Initialize(const GDALPansharpenOptions* psOptions);
00269         CPLErr               ProcessRegion(int nXOff, int nYOff,
00270                                            int nXSize, int nYSize,
00271                                            void *pDataBuf,
00272                                            GDALDataType eBufDataType);
00273         GDALPansharpenOptions* GetOptions();
00274 };
00275 
00276 #endif /* __cplusplus */
00277 
00278 #endif /* GDALPANSHARPEN_H_INCLUDED */

Generated for GDAL by doxygen 1.7.6.1.