GDAL

gdalwarper.h

Go to the documentation of this file.
00001 /******************************************************************************
00002  * $Id: gdalwarper.h 15291 2008-09-02 14:06:14Z dron $
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 
00172     void               *hCutline;           /* OGRPolygonH in src pixels */
00173     double              dfCutlineBlendDist; /* distance in src pixels */
00174 
00175 } GDALWarpOptions;
00176 
00177 GDALWarpOptions CPL_DLL * CPL_STDCALL GDALCreateWarpOptions(void);
00178 void CPL_DLL CPL_STDCALL GDALDestroyWarpOptions( GDALWarpOptions * );
00179 GDALWarpOptions CPL_DLL * CPL_STDCALL
00180 GDALCloneWarpOptions( const GDALWarpOptions * );
00181 
00182 CPLXMLNode CPL_DLL * CPL_STDCALL
00183       GDALSerializeWarpOptions( const GDALWarpOptions * );
00184 GDALWarpOptions CPL_DLL * CPL_STDCALL
00185       GDALDeserializeWarpOptions( CPLXMLNode * );
00186 
00187 /************************************************************************/
00188 /*                         GDALReprojectImage()                         */
00189 /************************************************************************/
00190 
00191 CPLErr CPL_DLL CPL_STDCALL
00192 GDALReprojectImage( GDALDatasetH hSrcDS, const char *pszSrcWKT, 
00193                     GDALDatasetH hDstDS, const char *pszDstWKT,
00194                     GDALResampleAlg eResampleAlg, double dfWarpMemoryLimit,
00195                     double dfMaxError,
00196                     GDALProgressFunc pfnProgress, void *pProgressArg, 
00197                     GDALWarpOptions *psOptions );
00198 
00199 CPLErr CPL_DLL CPL_STDCALL
00200 GDALCreateAndReprojectImage( GDALDatasetH hSrcDS, const char *pszSrcWKT, 
00201                     const char *pszDstFilename, const char *pszDstWKT,
00202                     GDALDriverH hDstDriver, char **papszCreateOptions,
00203                     GDALResampleAlg eResampleAlg, double dfWarpMemoryLimit,
00204                     double dfMaxError,
00205                     GDALProgressFunc pfnProgress, void *pProgressArg, 
00206                     GDALWarpOptions *psOptions );
00207 
00208 /************************************************************************/
00209 /*                           VRTWarpedDataset                           */
00210 /************************************************************************/
00211 
00212 GDALDatasetH CPL_DLL CPL_STDCALL
00213 GDALAutoCreateWarpedVRT( GDALDatasetH hSrcDS, 
00214                          const char *pszSrcWKT, const char *pszDstWKT, 
00215                          GDALResampleAlg eResampleAlg, 
00216                          double dfMaxError, const GDALWarpOptions *psOptions );
00217 
00218 GDALDatasetH CPL_DLL CPL_STDCALL 
00219 GDALCreateWarpedVRT( GDALDatasetH hSrcDS, 
00220                      int nPixels, int nLines, double *padfGeoTransform,
00221                      GDALWarpOptions *psOptions );
00222 
00223 CPLErr CPL_DLL CPL_STDCALL
00224 GDALInitializeWarpedVRT( GDALDatasetH hDS, 
00225                          GDALWarpOptions *psWO );
00226 
00227 CPL_C_END
00228 
00229 #ifdef __cplusplus 
00230 
00231 /************************************************************************/
00232 /*                            GDALWarpKernel                            */
00233 /*                                                                      */
00234 /*      This class represents the lowest level of abstraction.  It      */
00235 /*      is holds the imagery for one "chunk" of a warp, and the         */
00236 /*      pre-prepared masks.  All IO is done before and after it's       */
00237 /*      operation.  This class is not normally used by the              */
00238 /*      application.                                                    */
00239 /************************************************************************/
00240 
00241 class CPL_DLL GDALWarpKernel
00242 {
00243 public:
00244     char              **papszWarpOptions;
00245 
00246     GDALResampleAlg     eResample;
00247     GDALDataType        eWorkingDataType;
00248     int                 nBands;
00249 
00250     int                 nSrcXSize;
00251     int                 nSrcYSize;
00252     GByte               **papabySrcImage;
00253 
00254     GUInt32           **papanBandSrcValid;
00255     GUInt32            *panUnifiedSrcValid;
00256     float              *pafUnifiedSrcDensity;
00257 
00258     int                 nDstXSize;
00259     int                 nDstYSize;
00260     GByte             **papabyDstImage;
00261     GUInt32            *panDstValid;
00262     float              *pafDstDensity;
00263 
00264     double              dfXScale;   // Resampling scale, i.e.
00265     double              dfYScale;   // nDstSize/nSrcSize.
00266     double              dfXFilter;  // Size of filter kernel.
00267     double              dfYFilter;
00268     int                 nXRadius;   // Size of window to filter.
00269     int                 nYRadius;
00270     int                 nFiltInitX; // Filtering offset
00271     int                 nFiltInitY;
00272     
00273     int                 nSrcXOff;
00274     int                 nSrcYOff;
00275 
00276     int                 nDstXOff;
00277     int                 nDstYOff;
00278         
00279     GDALTransformerFunc pfnTransformer;
00280     void                *pTransformerArg;
00281 
00282     GDALProgressFunc    pfnProgress;
00283     void                *pProgress;
00284 
00285     double              dfProgressBase;
00286     double              dfProgressScale;
00287 
00288                        GDALWarpKernel();
00289     virtual           ~GDALWarpKernel();
00290 
00291     CPLErr              Validate();
00292     CPLErr              PerformWarp();
00293 };
00294 
00295 /************************************************************************/
00296 /*                         GDALWarpOperation()                          */
00297 /*                                                                      */
00298 /*      This object is application created, or created by a higher      */
00299 /*      level convenience function.  It is responsible for              */
00300 /*      subdividing the operation into chunks, loading and saving       */
00301 /*      imagery, and establishing the varios validity and density       */
00302 /*      masks.  Actual resampling is done by the GDALWarpKernel.        */
00303 /************************************************************************/
00304 
00305 class CPL_DLL GDALWarpOperation {
00306 private:
00307     GDALWarpOptions *psOptions;
00308 
00309     double          dfProgressBase;
00310     double          dfProgressScale;
00311 
00312     void            WipeOptions();
00313     int             ValidateOptions();
00314 
00315     CPLErr          ComputeSourceWindow( int nDstXOff, int nDstYOff, 
00316                                          int nDstXSize, int nDstYSize,
00317                                          int *pnSrcXOff, int *pnSrcYOff, 
00318                                          int *pnSrcXSize, int *pnSrcYSize );
00319 
00320     CPLErr          CreateKernelMask( GDALWarpKernel *, int iBand, 
00321                                       const char *pszType );
00322 
00323     void            *hThread1Mutex;
00324     void            *hThread2Mutex;
00325     void            *hIOMutex;
00326     void            *hWarpMutex;
00327 
00328     int             nChunkListCount;
00329     int             nChunkListMax;
00330     int            *panChunkList;
00331 
00332     int             bReportTimings;
00333     unsigned long   nLastTimeReported;
00334 
00335     void            WipeChunkList();
00336     CPLErr          CollectChunkList( int nDstXOff, int nDstYOff, 
00337                                       int nDstXSize, int nDstYSize );
00338     void            ReportTiming( const char * );
00339     
00340 public:
00341                     GDALWarpOperation();
00342     virtual        ~GDALWarpOperation();
00343 
00344     CPLErr          Initialize( const GDALWarpOptions *psNewOptions );
00345 
00346     const GDALWarpOptions         *GetOptions();
00347 
00348     CPLErr          ChunkAndWarpImage( int nDstXOff, int nDstYOff, 
00349                                        int nDstXSize, int nDstYSize );
00350     CPLErr          ChunkAndWarpMulti( int nDstXOff, int nDstYOff, 
00351                                        int nDstXSize, int nDstYSize );
00352     CPLErr          WarpRegion( int nDstXOff, int nDstYOff, 
00353                                 int nDstXSize, int nDstYSize,
00354                                 int nSrcXOff=0, int nSrcYOff=0,
00355                                 int nSrcXSize=0, int nSrcYSize=0 );
00356     
00357     CPLErr          WarpRegionToBuffer( int nDstXOff, int nDstYOff, 
00358                                         int nDstXSize, int nDstYSize, 
00359                                         void *pDataBuf, 
00360                                         GDALDataType eBufDataType,
00361                                         int nSrcXOff=0, int nSrcYOff=0,
00362                                         int nSrcXSize=0, int nSrcYSize=0 );
00363 };
00364 
00365 #endif /* def __cplusplus */
00366 
00367 CPL_C_START
00368 
00369 typedef void * GDALWarpOperationH;
00370 
00371 GDALWarpOperationH CPL_DLL GDALCreateWarpOperation(const GDALWarpOptions* );
00372 void CPL_DLL GDALDestroyWarpOperation( GDALWarpOperationH );
00373 CPLErr CPL_DLL GDALChunkAndWarpImage( GDALWarpOperationH, int, int, int, int );
00374 CPLErr CPL_DLL GDALChunkAndWarpMulti( GDALWarpOperationH, int, int, int, int );
00375 CPLErr CPL_DLL GDALWarpRegion( GDALWarpOperationH,
00376                                int, int, int, int, int, int, int, int );
00377 CPLErr CPL_DLL GDALWarpRegionToBuffer( GDALWarpOperationH, int, int, int, int,
00378                                        void *, GDALDataType,
00379                                        int, int, int, int );
00380 
00381 CPL_C_END
00382 
00383 #endif /* ndef GDAL_ALG_H_INCLUDED */

Generated for GDAL by doxygen 1.7.3.