GDAL
gdalwarper.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  * $Id: gdalwarper.h 20819 2010-10-13 15:59:44Z warmerdam $
00003  *
00004  * Project:  GDAL High Performance Warper
00005  * Purpose:  Prototypes, and definitions for warping related work.
00006  * Author:   Frank Warmerdam, warmerdam@pobox.com
00007  *
00008  ******************************************************************************
00009  * Copyright (c) 2003, Frank Warmerdam
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 GDALWARPER_H_INCLUDED
00031 #define GDALWARPER_H_INCLUDED
00032 
00041 #include "gdal_alg.h"
00042 #include "cpl_minixml.h"
00043 
00044 CPL_C_START
00045 
00047 typedef enum { GRA_NearestNeighbour=0,                         GRA_Bilinear=1,  GRA_Cubic=2,     GRA_CubicSpline=3, GRA_Lanczos=4
00053 } GDALResampleAlg;
00054 
00055 typedef int 
00056 (*GDALMaskFunc)( void *pMaskFuncArg,
00057                  int nBandCount, GDALDataType eType, 
00058                  int nXOff, int nYOff, 
00059                  int nXSize, int nYSize,
00060                  GByte **papabyImageData, 
00061                  int bMaskIsFloat, void *pMask );
00062 
00063 CPLErr CPL_DLL 
00064 GDALWarpNoDataMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
00065                       int nXOff, int nYOff, int nXSize, int nYSize,
00066                       GByte **papabyImageData, int bMaskIsFloat,
00067                       void *pValidityMask );
00068 
00069 CPLErr CPL_DLL 
00070 GDALWarpDstAlphaMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
00071                         int nXOff, int nYOff, int nXSize, int nYSize,
00072                         GByte ** /*ppImageData */,
00073                         int bMaskIsFloat, void *pValidityMask );
00074 CPLErr CPL_DLL 
00075 GDALWarpSrcAlphaMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
00076                         int nXOff, int nYOff, int nXSize, int nYSize,
00077                         GByte ** /*ppImageData */,
00078                         int bMaskIsFloat, void *pValidityMask );
00079 
00080 CPLErr CPL_DLL 
00081 GDALWarpSrcMaskMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
00082                        int nXOff, int nYOff, int nXSize, int nYSize,
00083                        GByte ** /*ppImageData */,
00084                        int bMaskIsFloat, void *pValidityMask );
00085 
00086 CPLErr CPL_DLL 
00087 GDALWarpCutlineMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
00088                        int nXOff, int nYOff, int nXSize, int nYSize,
00089                        GByte ** /* ppImageData */,
00090                        int bMaskIsFloat, void *pValidityMask );
00091 
00092 /************************************************************************/
00093 /*                           GDALWarpOptions                            */
00094 /************************************************************************/
00095 
00097 typedef struct {
00098     
00099     char              **papszWarpOptions;  
00100 
00102     double              dfWarpMemoryLimit; 
00103 
00105     GDALResampleAlg     eResampleAlg;
00106 
00109     GDALDataType        eWorkingDataType;
00110 
00112     GDALDatasetH        hSrcDS;
00113 
00115     GDALDatasetH        hDstDS;
00116 
00118     int                 nBandCount;
00119     
00121     int                *panSrcBands;
00122 
00124     int                *panDstBands;
00125 
00127     int                nSrcAlphaBand;
00128 
00130     int                nDstAlphaBand;
00131 
00133     double             *padfSrcNoDataReal;
00136     double             *padfSrcNoDataImag;
00137 
00139     double             *padfDstNoDataReal;
00142     double             *padfDstNoDataImag;
00143 
00146     GDALProgressFunc    pfnProgress;
00147 
00149     void               *pProgressArg;
00150 
00152     GDALTransformerFunc pfnTransformer;
00153 
00155     void                *pTransformerArg;
00156 
00157     GDALMaskFunc       *papfnSrcPerBandValidityMaskFunc;
00158     void              **papSrcPerBandValidityMaskFuncArg;
00159     
00160     GDALMaskFunc        pfnSrcValidityMaskFunc;
00161     void               *pSrcValidityMaskFuncArg;
00162     
00163     GDALMaskFunc        pfnSrcDensityMaskFunc;
00164     void               *pSrcDensityMaskFuncArg;
00165 
00166     GDALMaskFunc        pfnDstDensityMaskFunc;
00167     void               *pDstDensityMaskFuncArg;
00168 
00169     GDALMaskFunc        pfnDstValidityMaskFunc;
00170     void               *pDstValidityMaskFuncArg;
00171 
00172     CPLErr              (*pfnPreWarpChunkProcessor)( void *pKern, void *pArg );
00173     void               *pPreWarpProcessorArg;
00174     
00175     CPLErr              (*pfnPostWarpChunkProcessor)( void *pKern, void *pArg);
00176     void               *pPostWarpProcessorArg;
00177 
00179     void               *hCutline;
00180 
00182     double              dfCutlineBlendDist;
00183 
00184 } GDALWarpOptions;
00185 
00186 GDALWarpOptions CPL_DLL * CPL_STDCALL GDALCreateWarpOptions(void);
00187 void CPL_DLL CPL_STDCALL GDALDestroyWarpOptions( GDALWarpOptions * );
00188 GDALWarpOptions CPL_DLL * CPL_STDCALL
00189 GDALCloneWarpOptions( const GDALWarpOptions * );
00190 
00191 CPLXMLNode CPL_DLL * CPL_STDCALL
00192       GDALSerializeWarpOptions( const GDALWarpOptions * );
00193 GDALWarpOptions CPL_DLL * CPL_STDCALL
00194       GDALDeserializeWarpOptions( CPLXMLNode * );
00195 
00196 /************************************************************************/
00197 /*                         GDALReprojectImage()                         */
00198 /************************************************************************/
00199 
00200 CPLErr CPL_DLL CPL_STDCALL
00201 GDALReprojectImage( GDALDatasetH hSrcDS, const char *pszSrcWKT, 
00202                     GDALDatasetH hDstDS, const char *pszDstWKT,
00203                     GDALResampleAlg eResampleAlg, double dfWarpMemoryLimit,
00204                     double dfMaxError,
00205                     GDALProgressFunc pfnProgress, void *pProgressArg, 
00206                     GDALWarpOptions *psOptions );
00207 
00208 CPLErr CPL_DLL CPL_STDCALL
00209 GDALCreateAndReprojectImage( GDALDatasetH hSrcDS, const char *pszSrcWKT, 
00210                     const char *pszDstFilename, const char *pszDstWKT,
00211                     GDALDriverH hDstDriver, char **papszCreateOptions,
00212                     GDALResampleAlg eResampleAlg, double dfWarpMemoryLimit,
00213                     double dfMaxError,
00214                     GDALProgressFunc pfnProgress, void *pProgressArg, 
00215                     GDALWarpOptions *psOptions );
00216 
00217 /************************************************************************/
00218 /*                           VRTWarpedDataset                           */
00219 /************************************************************************/
00220 
00221 GDALDatasetH CPL_DLL CPL_STDCALL
00222 GDALAutoCreateWarpedVRT( GDALDatasetH hSrcDS, 
00223                          const char *pszSrcWKT, const char *pszDstWKT, 
00224                          GDALResampleAlg eResampleAlg, 
00225                          double dfMaxError, const GDALWarpOptions *psOptions );
00226 
00227 GDALDatasetH CPL_DLL CPL_STDCALL 
00228 GDALCreateWarpedVRT( GDALDatasetH hSrcDS, 
00229                      int nPixels, int nLines, double *padfGeoTransform,
00230                      GDALWarpOptions *psOptions );
00231 
00232 CPLErr CPL_DLL CPL_STDCALL
00233 GDALInitializeWarpedVRT( GDALDatasetH hDS, 
00234                          GDALWarpOptions *psWO );
00235 
00236 CPL_C_END
00237 
00238 #ifdef __cplusplus 
00239 
00240 /************************************************************************/
00241 /*                            GDALWarpKernel                            */
00242 /*                                                                      */
00243 /*      This class represents the lowest level of abstraction.  It      */
00244 /*      is holds the imagery for one "chunk" of a warp, and the         */
00245 /*      pre-prepared masks.  All IO is done before and after it's       */
00246 /*      operation.  This class is not normally used by the              */
00247 /*      application.                                                    */
00248 /************************************************************************/
00249 
00250 class CPL_DLL GDALWarpKernel
00251 {
00252 public:
00253     char              **papszWarpOptions;
00254 
00255     GDALResampleAlg     eResample;
00256     GDALDataType        eWorkingDataType;
00257     int                 nBands;
00258 
00259     int                 nSrcXSize;
00260     int                 nSrcYSize;
00261     GByte               **papabySrcImage;
00262 
00263     GUInt32           **papanBandSrcValid;
00264     GUInt32            *panUnifiedSrcValid;
00265     float              *pafUnifiedSrcDensity;
00266 
00267     int                 nDstXSize;
00268     int                 nDstYSize;
00269     GByte             **papabyDstImage;
00270     GUInt32            *panDstValid;
00271     float              *pafDstDensity;
00272 
00273     double              dfXScale;   // Resampling scale, i.e.
00274     double              dfYScale;   // nDstSize/nSrcSize.
00275     double              dfXFilter;  // Size of filter kernel.
00276     double              dfYFilter;
00277     int                 nXRadius;   // Size of window to filter.
00278     int                 nYRadius;
00279     int                 nFiltInitX; // Filtering offset
00280     int                 nFiltInitY;
00281     
00282     int                 nSrcXOff;
00283     int                 nSrcYOff;
00284 
00285     int                 nDstXOff;
00286     int                 nDstYOff;
00287         
00288     GDALTransformerFunc pfnTransformer;
00289     void                *pTransformerArg;
00290 
00291     GDALProgressFunc    pfnProgress;
00292     void                *pProgress;
00293 
00294     double              dfProgressBase;
00295     double              dfProgressScale;
00296     
00297     double              *padfDstNoDataReal;
00298 
00299                        GDALWarpKernel();
00300     virtual           ~GDALWarpKernel();
00301 
00302     CPLErr              Validate();
00303     CPLErr              PerformWarp();
00304 };
00305 
00306 /************************************************************************/
00307 /*                         GDALWarpOperation()                          */
00308 /*                                                                      */
00309 /*      This object is application created, or created by a higher      */
00310 /*      level convenience function.  It is responsible for              */
00311 /*      subdividing the operation into chunks, loading and saving       */
00312 /*      imagery, and establishing the varios validity and density       */
00313 /*      masks.  Actual resampling is done by the GDALWarpKernel.        */
00314 /************************************************************************/
00315 
00316 class CPL_DLL GDALWarpOperation {
00317 private:
00318     GDALWarpOptions *psOptions;
00319 
00320     void            WipeOptions();
00321     int             ValidateOptions();
00322 
00323     CPLErr          ComputeSourceWindow( int nDstXOff, int nDstYOff, 
00324                                          int nDstXSize, int nDstYSize,
00325                                          int *pnSrcXOff, int *pnSrcYOff, 
00326                                          int *pnSrcXSize, int *pnSrcYSize );
00327 
00328     CPLErr          CreateKernelMask( GDALWarpKernel *, int iBand, 
00329                                       const char *pszType );
00330 
00331     void            *hThread1Mutex;
00332     void            *hThread2Mutex;
00333     void            *hIOMutex;
00334     void            *hWarpMutex;
00335 
00336     int             nChunkListCount;
00337     int             nChunkListMax;
00338     int            *panChunkList;
00339 
00340     int             bReportTimings;
00341     unsigned long   nLastTimeReported;
00342 
00343     void            WipeChunkList();
00344     CPLErr          CollectChunkList( int nDstXOff, int nDstYOff, 
00345                                       int nDstXSize, int nDstYSize );
00346     void            ReportTiming( const char * );
00347     
00348 public:
00349                     GDALWarpOperation();
00350     virtual        ~GDALWarpOperation();
00351 
00352     CPLErr          Initialize( const GDALWarpOptions *psNewOptions );
00353 
00354     const GDALWarpOptions         *GetOptions();
00355 
00356     CPLErr          ChunkAndWarpImage( int nDstXOff, int nDstYOff, 
00357                                        int nDstXSize, int nDstYSize );
00358     CPLErr          ChunkAndWarpMulti( int nDstXOff, int nDstYOff, 
00359                                        int nDstXSize, int nDstYSize );
00360     CPLErr          WarpRegion( int nDstXOff, int nDstYOff, 
00361                                 int nDstXSize, int nDstYSize,
00362                                 int nSrcXOff=0, int nSrcYOff=0,
00363                                 int nSrcXSize=0, int nSrcYSize=0,
00364                                 double dfProgressBase=0.0, double dfProgressScale=1.0);
00365     
00366     CPLErr          WarpRegionToBuffer( int nDstXOff, int nDstYOff, 
00367                                         int nDstXSize, int nDstYSize, 
00368                                         void *pDataBuf, 
00369                                         GDALDataType eBufDataType,
00370                                         int nSrcXOff=0, int nSrcYOff=0,
00371                                         int nSrcXSize=0, int nSrcYSize=0,
00372                                         double dfProgressBase=0.0, double dfProgressScale=1.0);
00373 };
00374 
00375 #endif /* def __cplusplus */
00376 
00377 CPL_C_START
00378 
00379 typedef void * GDALWarpOperationH;
00380 
00381 GDALWarpOperationH CPL_DLL GDALCreateWarpOperation(const GDALWarpOptions* );
00382 void CPL_DLL GDALDestroyWarpOperation( GDALWarpOperationH );
00383 CPLErr CPL_DLL GDALChunkAndWarpImage( GDALWarpOperationH, int, int, int, int );
00384 CPLErr CPL_DLL GDALChunkAndWarpMulti( GDALWarpOperationH, int, int, int, int );
00385 CPLErr CPL_DLL GDALWarpRegion( GDALWarpOperationH,
00386                                int, int, int, int, int, int, int, int );
00387 CPLErr CPL_DLL GDALWarpRegionToBuffer( GDALWarpOperationH, int, int, int, int,
00388                                        void *, GDALDataType,
00389                                        int, int, int, int );
00390 
00391 CPL_C_END
00392 
00393 #endif /* ndef GDAL_ALG_H_INCLUDED */

Generated for GDAL by doxygen 1.7.6.1.