GDAL
gdalwarper.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  * $Id: gdalwarper.h 17659 2009-09-20 19:02:37Z rouault $
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 GDALWarpCutlineMasker( 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 /************************************************************************/
00087 /*                           GDALWarpOptions                            */
00088 /************************************************************************/
00089 
00091 typedef struct {
00092     
00093     char              **papszWarpOptions;  
00094 
00096     double              dfWarpMemoryLimit; 
00097 
00099     GDALResampleAlg     eResampleAlg;
00100 
00103     GDALDataType        eWorkingDataType;
00104 
00106     GDALDatasetH        hSrcDS;
00107 
00109     GDALDatasetH        hDstDS;
00110 
00112     int                 nBandCount;
00113     
00115     int                *panSrcBands;
00116 
00118     int                *panDstBands;
00119 
00121     int                nSrcAlphaBand;
00122 
00124     int                nDstAlphaBand;
00125 
00127     double             *padfSrcNoDataReal;
00130     double             *padfSrcNoDataImag;
00131 
00133     double             *padfDstNoDataReal;
00136     double             *padfDstNoDataImag;
00137 
00140     GDALProgressFunc    pfnProgress;
00141 
00143     void               *pProgressArg;
00144 
00146     GDALTransformerFunc pfnTransformer;
00147 
00149     void                *pTransformerArg;
00150 
00151     GDALMaskFunc       *papfnSrcPerBandValidityMaskFunc;
00152     void              **papSrcPerBandValidityMaskFuncArg;
00153     
00154     GDALMaskFunc        pfnSrcValidityMaskFunc;
00155     void               *pSrcValidityMaskFuncArg;
00156     
00157     GDALMaskFunc        pfnSrcDensityMaskFunc;
00158     void               *pSrcDensityMaskFuncArg;
00159 
00160     GDALMaskFunc        pfnDstDensityMaskFunc;
00161     void               *pDstDensityMaskFuncArg;
00162 
00163     GDALMaskFunc        pfnDstValidityMaskFunc;
00164     void               *pDstValidityMaskFuncArg;
00165 
00166     CPLErr              (*pfnPreWarpChunkProcessor)( void *pKern, void *pArg );
00167     void               *pPreWarpProcessorArg;
00168     
00169     CPLErr              (*pfnPostWarpChunkProcessor)( void *pKern, void *pArg);
00170     void               *pPostWarpProcessorArg;
00171 
00173     void               *hCutline;
00174 
00176     double              dfCutlineBlendDist;
00177 
00178 } GDALWarpOptions;
00179 
00180 GDALWarpOptions CPL_DLL * CPL_STDCALL GDALCreateWarpOptions(void);
00181 void CPL_DLL CPL_STDCALL GDALDestroyWarpOptions( GDALWarpOptions * );
00182 GDALWarpOptions CPL_DLL * CPL_STDCALL
00183 GDALCloneWarpOptions( const GDALWarpOptions * );
00184 
00185 CPLXMLNode CPL_DLL * CPL_STDCALL
00186       GDALSerializeWarpOptions( const GDALWarpOptions * );
00187 GDALWarpOptions CPL_DLL * CPL_STDCALL
00188       GDALDeserializeWarpOptions( CPLXMLNode * );
00189 
00190 /************************************************************************/
00191 /*                         GDALReprojectImage()                         */
00192 /************************************************************************/
00193 
00194 CPLErr CPL_DLL CPL_STDCALL
00195 GDALReprojectImage( GDALDatasetH hSrcDS, const char *pszSrcWKT, 
00196                     GDALDatasetH hDstDS, const char *pszDstWKT,
00197                     GDALResampleAlg eResampleAlg, double dfWarpMemoryLimit,
00198                     double dfMaxError,
00199                     GDALProgressFunc pfnProgress, void *pProgressArg, 
00200                     GDALWarpOptions *psOptions );
00201 
00202 CPLErr CPL_DLL CPL_STDCALL
00203 GDALCreateAndReprojectImage( GDALDatasetH hSrcDS, const char *pszSrcWKT, 
00204                     const char *pszDstFilename, const char *pszDstWKT,
00205                     GDALDriverH hDstDriver, char **papszCreateOptions,
00206                     GDALResampleAlg eResampleAlg, double dfWarpMemoryLimit,
00207                     double dfMaxError,
00208                     GDALProgressFunc pfnProgress, void *pProgressArg, 
00209                     GDALWarpOptions *psOptions );
00210 
00211 /************************************************************************/
00212 /*                           VRTWarpedDataset                           */
00213 /************************************************************************/
00214 
00215 GDALDatasetH CPL_DLL CPL_STDCALL
00216 GDALAutoCreateWarpedVRT( GDALDatasetH hSrcDS, 
00217                          const char *pszSrcWKT, const char *pszDstWKT, 
00218                          GDALResampleAlg eResampleAlg, 
00219                          double dfMaxError, const GDALWarpOptions *psOptions );
00220 
00221 GDALDatasetH CPL_DLL CPL_STDCALL 
00222 GDALCreateWarpedVRT( GDALDatasetH hSrcDS, 
00223                      int nPixels, int nLines, double *padfGeoTransform,
00224                      GDALWarpOptions *psOptions );
00225 
00226 CPLErr CPL_DLL CPL_STDCALL
00227 GDALInitializeWarpedVRT( GDALDatasetH hDS, 
00228                          GDALWarpOptions *psWO );
00229 
00230 CPL_C_END
00231 
00232 #ifdef __cplusplus 
00233 
00234 /************************************************************************/
00235 /*                            GDALWarpKernel                            */
00236 /*                                                                      */
00237 /*      This class represents the lowest level of abstraction.  It      */
00238 /*      is holds the imagery for one "chunk" of a warp, and the         */
00239 /*      pre-prepared masks.  All IO is done before and after it's       */
00240 /*      operation.  This class is not normally used by the              */
00241 /*      application.                                                    */
00242 /************************************************************************/
00243 
00244 class CPL_DLL GDALWarpKernel
00245 {
00246 public:
00247     char              **papszWarpOptions;
00248 
00249     GDALResampleAlg     eResample;
00250     GDALDataType        eWorkingDataType;
00251     int                 nBands;
00252 
00253     int                 nSrcXSize;
00254     int                 nSrcYSize;
00255     GByte               **papabySrcImage;
00256 
00257     GUInt32           **papanBandSrcValid;
00258     GUInt32            *panUnifiedSrcValid;
00259     float              *pafUnifiedSrcDensity;
00260 
00261     int                 nDstXSize;
00262     int                 nDstYSize;
00263     GByte             **papabyDstImage;
00264     GUInt32            *panDstValid;
00265     float              *pafDstDensity;
00266 
00267     double              dfXScale;   // Resampling scale, i.e.
00268     double              dfYScale;   // nDstSize/nSrcSize.
00269     double              dfXFilter;  // Size of filter kernel.
00270     double              dfYFilter;
00271     int                 nXRadius;   // Size of window to filter.
00272     int                 nYRadius;
00273     int                 nFiltInitX; // Filtering offset
00274     int                 nFiltInitY;
00275     
00276     int                 nSrcXOff;
00277     int                 nSrcYOff;
00278 
00279     int                 nDstXOff;
00280     int                 nDstYOff;
00281         
00282     GDALTransformerFunc pfnTransformer;
00283     void                *pTransformerArg;
00284 
00285     GDALProgressFunc    pfnProgress;
00286     void                *pProgress;
00287 
00288     double              dfProgressBase;
00289     double              dfProgressScale;
00290     
00291     double              *padfDstNoDataReal;
00292 
00293                        GDALWarpKernel();
00294     virtual           ~GDALWarpKernel();
00295 
00296     CPLErr              Validate();
00297     CPLErr              PerformWarp();
00298 };
00299 
00300 /************************************************************************/
00301 /*                         GDALWarpOperation()                          */
00302 /*                                                                      */
00303 /*      This object is application created, or created by a higher      */
00304 /*      level convenience function.  It is responsible for              */
00305 /*      subdividing the operation into chunks, loading and saving       */
00306 /*      imagery, and establishing the varios validity and density       */
00307 /*      masks.  Actual resampling is done by the GDALWarpKernel.        */
00308 /************************************************************************/
00309 
00310 class CPL_DLL GDALWarpOperation {
00311 private:
00312     GDALWarpOptions *psOptions;
00313 
00314     double          dfProgressBase;
00315     double          dfProgressScale;
00316 
00317     void            WipeOptions();
00318     int             ValidateOptions();
00319 
00320     CPLErr          ComputeSourceWindow( int nDstXOff, int nDstYOff, 
00321                                          int nDstXSize, int nDstYSize,
00322                                          int *pnSrcXOff, int *pnSrcYOff, 
00323                                          int *pnSrcXSize, int *pnSrcYSize );
00324 
00325     CPLErr          CreateKernelMask( GDALWarpKernel *, int iBand, 
00326                                       const char *pszType );
00327 
00328     void            *hThread1Mutex;
00329     void            *hThread2Mutex;
00330     void            *hIOMutex;
00331     void            *hWarpMutex;
00332 
00333     int             nChunkListCount;
00334     int             nChunkListMax;
00335     int            *panChunkList;
00336 
00337     int             bReportTimings;
00338     unsigned long   nLastTimeReported;
00339 
00340     void            WipeChunkList();
00341     CPLErr          CollectChunkList( int nDstXOff, int nDstYOff, 
00342                                       int nDstXSize, int nDstYSize );
00343     void            ReportTiming( const char * );
00344     
00345 public:
00346                     GDALWarpOperation();
00347     virtual        ~GDALWarpOperation();
00348 
00349     CPLErr          Initialize( const GDALWarpOptions *psNewOptions );
00350 
00351     const GDALWarpOptions         *GetOptions();
00352 
00353     CPLErr          ChunkAndWarpImage( int nDstXOff, int nDstYOff, 
00354                                        int nDstXSize, int nDstYSize );
00355     CPLErr          ChunkAndWarpMulti( int nDstXOff, int nDstYOff, 
00356                                        int nDstXSize, int nDstYSize );
00357     CPLErr          WarpRegion( int nDstXOff, int nDstYOff, 
00358                                 int nDstXSize, int nDstYSize,
00359                                 int nSrcXOff=0, int nSrcYOff=0,
00360                                 int nSrcXSize=0, int nSrcYSize=0 );
00361     
00362     CPLErr          WarpRegionToBuffer( int nDstXOff, int nDstYOff, 
00363                                         int nDstXSize, int nDstYSize, 
00364                                         void *pDataBuf, 
00365                                         GDALDataType eBufDataType,
00366                                         int nSrcXOff=0, int nSrcYOff=0,
00367                                         int nSrcXSize=0, int nSrcYSize=0 );
00368 };
00369 
00370 #endif /* def __cplusplus */
00371 
00372 CPL_C_START
00373 
00374 typedef void * GDALWarpOperationH;
00375 
00376 GDALWarpOperationH CPL_DLL GDALCreateWarpOperation(const GDALWarpOptions* );
00377 void CPL_DLL GDALDestroyWarpOperation( GDALWarpOperationH );
00378 CPLErr CPL_DLL GDALChunkAndWarpImage( GDALWarpOperationH, int, int, int, int );
00379 CPLErr CPL_DLL GDALChunkAndWarpMulti( GDALWarpOperationH, int, int, int, int );
00380 CPLErr CPL_DLL GDALWarpRegion( GDALWarpOperationH,
00381                                int, int, int, int, int, int, int, int );
00382 CPLErr CPL_DLL GDALWarpRegionToBuffer( GDALWarpOperationH, int, int, int, int,
00383                                        void *, GDALDataType,
00384                                        int, int, int, int );
00385 
00386 CPL_C_END
00387 
00388 #endif /* ndef GDAL_ALG_H_INCLUDED */

Generated for GDAL by doxygen 1.7.5.