gdalwarper.h

Go to the documentation of this file.
00001 /******************************************************************************
00002  * $Id: gdalwarper.h 10646 2007-01-18 02:38:10Z 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,
00052 } GDALResampleAlg;
00053 
00054 typedef int 
00055 (*GDALMaskFunc)( void *pMaskFuncArg,
00056                  int nBandCount, GDALDataType eType, 
00057                  int nXOff, int nYOff, 
00058                  int nXSize, int nYSize,
00059                  GByte **papabyImageData, 
00060                  int bMaskIsFloat, void *pMask );
00061 
00062 CPLErr CPL_DLL 
00063 GDALWarpNoDataMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
00064                       int nXOff, int nYOff, int nXSize, int nYSize,
00065                       GByte **papabyImageData, int bMaskIsFloat,
00066                       void *pValidityMask );
00067 
00068 CPLErr CPL_DLL 
00069 GDALWarpDstAlphaMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
00070                         int nXOff, int nYOff, int nXSize, int nYSize,
00071                         GByte ** /*ppImageData */,
00072                         int bMaskIsFloat, void *pValidityMask );
00073 CPLErr CPL_DLL 
00074 GDALWarpSrcAlphaMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
00075                         int nXOff, int nYOff, int nXSize, int nYSize,
00076                         GByte ** /*ppImageData */,
00077                         int bMaskIsFloat, void *pValidityMask );
00078 
00079 /************************************************************************/
00080 /*                           GDALWarpOptions                            */
00081 /************************************************************************/
00082 
00084 typedef struct {
00085     
00086     char              **papszWarpOptions;  
00087 
00089     double              dfWarpMemoryLimit; 
00090 
00092     GDALResampleAlg     eResampleAlg;
00093 
00096     GDALDataType        eWorkingDataType;
00097 
00099     GDALDatasetH        hSrcDS;
00100 
00102     GDALDatasetH        hDstDS;
00103 
00105     int                 nBandCount;
00106     
00108     int                *panSrcBands;
00109 
00111     int                *panDstBands;
00112 
00114     int                nSrcAlphaBand;
00115 
00117     int                nDstAlphaBand;
00118 
00120     double             *padfSrcNoDataReal;
00123     double             *padfSrcNoDataImag;
00124 
00126     double             *padfDstNoDataReal;
00129     double             *padfDstNoDataImag;
00130 
00133     GDALProgressFunc    pfnProgress;
00134 
00136     void               *pProgressArg;
00137 
00139     GDALTransformerFunc pfnTransformer;
00140 
00142     void                *pTransformerArg;
00143 
00144     GDALMaskFunc       *papfnSrcPerBandValidityMaskFunc;
00145     void              **papSrcPerBandValidityMaskFuncArg;
00146     
00147     GDALMaskFunc        pfnSrcValidityMaskFunc;
00148     void               *pSrcValidityMaskFuncArg;
00149     
00150     GDALMaskFunc        pfnSrcDensityMaskFunc;
00151     void               *pSrcDensityMaskFuncArg;
00152 
00153     GDALMaskFunc        pfnDstDensityMaskFunc;
00154     void               *pDstDensityMaskFuncArg;
00155 
00156     GDALMaskFunc        pfnDstValidityMaskFunc;
00157     void               *pDstValidityMaskFuncArg;
00158 
00159     CPLErr              (*pfnPreWarpChunkProcessor)( void *pKern, void *pArg );
00160     void               *pPreWarpProcessorArg;
00161     
00162     CPLErr              (*pfnPostWarpChunkProcessor)( void *pKern, void *pArg);
00163     void               *pPostWarpProcessorArg;
00164 
00165 } GDALWarpOptions;
00166 
00167 GDALWarpOptions CPL_DLL * CPL_STDCALL GDALCreateWarpOptions(void);
00168 void CPL_DLL CPL_STDCALL GDALDestroyWarpOptions( GDALWarpOptions * );
00169 GDALWarpOptions CPL_DLL * CPL_STDCALL
00170 GDALCloneWarpOptions( const GDALWarpOptions * );
00171 
00172 CPLXMLNode CPL_DLL * CPL_STDCALL
00173       GDALSerializeWarpOptions( const GDALWarpOptions * );
00174 GDALWarpOptions CPL_DLL * CPL_STDCALL
00175       GDALDeserializeWarpOptions( CPLXMLNode * );
00176 
00177 /************************************************************************/
00178 /*                         GDALReprojectImage()                         */
00179 /************************************************************************/
00180 
00181 CPLErr CPL_DLL CPL_STDCALL
00182 GDALReprojectImage( GDALDatasetH hSrcDS, const char *pszSrcWKT, 
00183                     GDALDatasetH hDstDS, const char *pszDstWKT,
00184                     GDALResampleAlg eResampleAlg, double dfWarpMemoryLimit,
00185                     double dfMaxError,
00186                     GDALProgressFunc pfnProgress, void *pProgressArg, 
00187                     GDALWarpOptions *psOptions );
00188 
00189 CPLErr CPL_DLL CPL_STDCALL
00190 GDALCreateAndReprojectImage( GDALDatasetH hSrcDS, const char *pszSrcWKT, 
00191                     const char *pszDstFilename, const char *pszDstWKT,
00192                     GDALDriverH hDstDriver, char **papszCreateOptions,
00193                     GDALResampleAlg eResampleAlg, double dfWarpMemoryLimit,
00194                     double dfMaxError,
00195                     GDALProgressFunc pfnProgress, void *pProgressArg, 
00196                     GDALWarpOptions *psOptions );
00197 
00198 /************************************************************************/
00199 /*                           VRTWarpedDataset                           */
00200 /************************************************************************/
00201 
00202 GDALDatasetH CPL_DLL CPL_STDCALL
00203 GDALAutoCreateWarpedVRT( GDALDatasetH hSrcDS, 
00204                          const char *pszSrcWKT, const char *pszDstWKT, 
00205                          GDALResampleAlg eResampleAlg, 
00206                          double dfMaxError, const GDALWarpOptions *psOptions );
00207 
00208 GDALDatasetH CPL_DLL CPL_STDCALL 
00209 GDALCreateWarpedVRT( GDALDatasetH hSrcDS, 
00210                      int nPixels, int nLines, double *padfGeoTransform,
00211                      GDALWarpOptions *psOptions );
00212 
00213 CPLErr CPL_DLL CPL_STDCALL
00214 GDALInitializeWarpedVRT( GDALDatasetH hDS, 
00215                          GDALWarpOptions *psWO );
00216 
00217 CPL_C_END
00218 
00219 #ifdef __cplusplus 
00220 
00221 /************************************************************************/
00222 /*                            GDALWarpKernel                            */
00223 /*                                                                      */
00224 /*      This class represents the lowest level of abstraction.  It      */
00225 /*      is holds the imagery for one "chunk" of a warp, and the         */
00226 /*      pre-prepared masks.  All IO is done before and after it's       */
00227 /*      operation.  This class is not normally used by the              */
00228 /*      application.                                                    */
00229 /************************************************************************/
00230 
00231 class CPL_DLL GDALWarpKernel
00232 {
00233 public:
00234                        GDALWarpKernel();
00235     virtual           ~GDALWarpKernel();
00236 
00237     char              **papszWarpOptions;
00238 
00239     GDALResampleAlg     eResample;
00240     GDALDataType        eWorkingDataType;
00241     int                 nBands;
00242 
00243     int                 nSrcXSize;
00244     int                 nSrcYSize;
00245     GByte               **papabySrcImage;
00246 
00247     GUInt32           **papanBandSrcValid;
00248     GUInt32            *panUnifiedSrcValid;
00249     float              *pafUnifiedSrcDensity;
00250 
00251     int                 nDstXSize;
00252     int                 nDstYSize;
00253     GByte             **papabyDstImage;
00254     GUInt32            *panDstValid;
00255     float              *pafDstDensity;
00256     
00257     int                 nSrcXOff;
00258     int                 nSrcYOff;
00259 
00260     int                 nDstXOff;
00261     int                 nDstYOff;
00262         
00263     GDALTransformerFunc pfnTransformer;
00264     void                *pTransformerArg;
00265 
00266     GDALProgressFunc    pfnProgress;
00267     void                *pProgress;
00268 
00269     double              dfProgressBase;
00270     double              dfProgressScale;
00271 
00272     CPLErr              Validate();
00273     CPLErr              PerformWarp();
00274 };
00275 
00276 /************************************************************************/
00277 /*                         GDALWarpOperation()                          */
00278 /*                                                                      */
00279 /*      This object is application created, or created by a higher      */
00280 /*      level convenience function.  It is responsible for              */
00281 /*      subdividing the operation into chunks, loading and saving       */
00282 /*      imagery, and establishing the varios validity and density       */
00283 /*      masks.  Actual resampling is done by the GDALWarpKernel.        */
00284 /************************************************************************/
00285 
00286 class CPL_DLL GDALWarpOperation {
00287 private:
00288     GDALWarpOptions *psOptions;
00289 
00290     double          dfProgressBase;
00291     double          dfProgressScale;
00292 
00293     void            WipeOptions();
00294     int             ValidateOptions();
00295 
00296     CPLErr          ComputeSourceWindow( int nDstXOff, int nDstYOff, 
00297                                          int nDstXSize, int nDstYSize,
00298                                          int *pnSrcXOff, int *pnSrcYOff, 
00299                                          int *pnSrcXSize, int *pnSrcYSize );
00300 
00301     CPLErr          CreateKernelMask( GDALWarpKernel *, int iBand, 
00302                                       const char *pszType );
00303 
00304     void            *hThread1Mutex;
00305     void            *hThread2Mutex;
00306     void            *hIOMutex;
00307     void            *hWarpMutex;
00308 
00309     int             nChunkListCount;
00310     int             nChunkListMax;
00311     int            *panChunkList;
00312 
00313     int             bReportTimings;
00314     unsigned long   nLastTimeReported;
00315 
00316     void            WipeChunkList();
00317     CPLErr          CollectChunkList( int nDstXOff, int nDstYOff, 
00318                                       int nDstXSize, int nDstYSize );
00319     void            ReportTiming( const char * );
00320     
00321 public:
00322                     GDALWarpOperation();
00323     virtual        ~GDALWarpOperation();
00324 
00325     CPLErr          Initialize( const GDALWarpOptions *psNewOptions );
00326 
00327     const GDALWarpOptions         *GetOptions();
00328 
00329     CPLErr          ChunkAndWarpImage( int nDstXOff, int nDstYOff, 
00330                                        int nDstXSize, int nDstYSize );
00331     CPLErr          ChunkAndWarpMulti( int nDstXOff, int nDstYOff, 
00332                                        int nDstXSize, int nDstYSize );
00333     CPLErr          WarpRegion( int nDstXOff, int nDstYOff, 
00334                                 int nDstXSize, int nDstYSize,
00335                                 int nSrcXOff=0, int nSrcYOff=0,
00336                                 int nSrcXSize=0, int nSrcYSize=0 );
00337     
00338     CPLErr          WarpRegionToBuffer( int nDstXOff, int nDstYOff, 
00339                                         int nDstXSize, int nDstYSize, 
00340                                         void *pDataBuf, 
00341                                         GDALDataType eBufDataType,
00342                                         int nSrcXOff=0, int nSrcYOff=0,
00343                                         int nSrcXSize=0, int nSrcYSize=0 );
00344 };
00345 
00346 #endif /* def __cplusplus */
00347 
00348 CPL_C_START
00349 
00350 typedef void * GDALWarpOperationH;
00351 
00352 GDALWarpOperationH CPL_DLL GDALCreateWarpOperation(const GDALWarpOptions* );
00353 void CPL_DLL GDALDestroyWarpOperation( GDALWarpOperationH );
00354 CPLErr CPL_DLL GDALChunkAndWarpImage( GDALWarpOperationH, int, int, int, int );
00355 CPLErr CPL_DLL GDALChunkAndWarpMulti( GDALWarpOperationH, int, int, int, int );
00356 CPLErr CPL_DLL GDALWarpRegion( GDALWarpOperationH,
00357                                int, int, int, int, int, int, int, int );
00358 CPLErr CPL_DLL GDALWarpRegionToBuffer( GDALWarpOperationH, int, int, int, int,
00359                                        void *, GDALDataType,
00360                                        int, int, int, int );
00361 
00362 CPL_C_END
00363 
00364 #endif /* ndef GDAL_ALG_H_INCLUDED */

Generated for GDAL by doxygen 1.5.2.