Main Page | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

gdalwarper.h

Go to the documentation of this file.
00001 /******************************************************************************
00002  * $Id: gdalwarper.h,v 1.10 2003/07/04 11:50:57 dron Exp $
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  * $Log: gdalwarper.h,v $
00031  * Revision 1.10  2003/07/04 11:50:57  dron
00032  * GRA_CubicSpline added to the list of resampling algorithms.
00033  *
00034  * Revision 1.9  2003/06/12 11:21:33  dron
00035  * Few additional comments.
00036  *
00037  * Revision 1.8  2003/05/27 20:49:25  warmerda
00038  * added REPORT_TIMINGS support
00039  *
00040  * Revision 1.7  2003/05/07 19:13:06  warmerda
00041  * added pre and post warp chunk processor
00042  *
00043  * Revision 1.6  2003/04/23 05:18:57  warmerda
00044  * added multithread support
00045  *
00046  * Revision 1.5  2003/03/02 05:25:59  warmerda
00047  * added some source nodata support
00048  *
00049  * Revision 1.4  2003/02/22 02:04:11  warmerda
00050  * added dfMaxError to reproject function
00051  *
00052  * Revision 1.3  2003/02/21 15:41:37  warmerda
00053  * added progressbase/scale for operation
00054  *
00055  * Revision 1.2  2003/02/20 21:53:06  warmerda
00056  * partial implementation
00057  *
00058  * Revision 1.1  2003/02/18 17:25:50  warmerda
00059  * New
00060  *
00061  */
00062 
00063 #ifndef GDALWARPER_H_INCLUDED
00064 #define GDALWARPER_H_INCLUDED
00065 
00074 #include "gdal_alg.h"
00075 
00076 CPL_C_START
00077 
00079 typedef enum { GRA_NearestNeighbour=0,                         GRA_Bilinear=1,  GRA_Cubic=2,     GRA_CubicSpline=3,
00084 } GDALResampleAlg;
00085 
00086 typedef int 
00087 (*GDALMaskFunc)( void *pMaskFuncArg,
00088                  int nBandCount, GDALDataType eType, 
00089                  int nXOff, int nYOff, 
00090                  int nXSize, int nYSize,
00091                  GByte **papabyImageData, 
00092                  int bMaskIsFloat, void *pMask );
00093 
00094 CPLErr GDALWarpNoDataMasker( void *pMaskFuncArg, int nBandCount, 
00095                              GDALDataType eType,
00096                              int nXOff, int nYOff, int nXSize, int nYSize,
00097                              GByte **papabyImageData, int bMaskIsFloat,
00098                              void *pValidityMask );
00099 
00100 /************************************************************************/
00101 /*                           GDALWarpOptions                            */
00102 /************************************************************************/
00103 
00105 typedef struct {
00106     
00107     char              **papszWarpOptions;  
00108 
00110     double              dfWarpMemoryLimit; 
00111 
00113     GDALResampleAlg     eResampleAlg;
00114 
00117     GDALDataType        eWorkingDataType;
00118 
00120     GDALDatasetH        hSrcDS;
00121 
00123     GDALDatasetH        hDstDS;
00124 
00126     int                 nBandCount;
00127     
00129     int                *panSrcBands;
00130 
00132     int                *panDstBands;
00133 
00135     double             *padfSrcNoDataReal;
00138     double             *padfSrcNoDataImag;
00139 
00141     double             *padfDstNoDataReal;
00144     double             *padfDstNoDataImag;
00145 
00148     GDALProgressFunc    pfnProgress;
00149 
00151     void               *pProgressArg;
00152 
00154     GDALTransformerFunc pfnTransformer;
00155 
00157     void                *pTransformerArg;
00158 
00159     GDALMaskFunc       *papfnSrcPerBandValidityMaskFunc;
00160     void              **papSrcPerBandValidityMaskFuncArg;
00161     
00162     GDALMaskFunc        pfnSrcValidityMaskFunc;
00163     void               *pSrcValidityMaskFuncArg;
00164     
00165     GDALMaskFunc        pfnSrcDensityMaskFunc;
00166     void               *pSrcDensityMaskFuncArg;
00167 
00168     GDALMaskFunc        pfnDstDensityMaskFunc;
00169     void               *pDstDensityMaskFuncArg;
00170 
00171     GDALMaskFunc        pfnDstValidityMaskFunc;
00172     void               *pDstValidityMaskFuncArg;
00173 
00174     CPLErr              (*pfnPreWarpChunkProcessor)( void *pKern, void *pArg );
00175     void               *pPreWarpProcessorArg;
00176     
00177     CPLErr              (*pfnPostWarpChunkProcessor)( void *pKern, void *pArg);
00178     void               *pPostWarpProcessorArg;
00179 
00180 } GDALWarpOptions;
00181 
00182 GDALWarpOptions CPL_DLL *GDALCreateWarpOptions();
00183 void CPL_DLL GDALDestroyWarpOptions( GDALWarpOptions * );
00184 GDALWarpOptions CPL_DLL *GDALCloneWarpOptions( const GDALWarpOptions * );
00185 
00186 /************************************************************************/
00187 /*                         GDALReprojectImage()                         */
00188 /************************************************************************/
00189 
00190 CPLErr CPL_DLL 
00191 GDALReprojectImage( GDALDatasetH hSrcDS, const char *pszSrcWKT, 
00192                     GDALDatasetH hDstDS, const char *pszDstWKT,
00193                     GDALResampleAlg eResampleAlg, double dfWarpMemoryLimit,
00194                     double dfMaxError,
00195                     GDALProgressFunc pfnProgress, void *pProgressArg, 
00196                     GDALWarpOptions *psOptions );
00197 
00198 CPLErr CPL_DLL 
00199 GDALCreateAndReprojectImage( GDALDatasetH hSrcDS, const char *pszSrcWKT, 
00200                     const char *pszDstFilename, const char *pszDstWKT,
00201                     GDALDriverH hDstDriver, char **papszCreateOptions,
00202                     GDALResampleAlg eResampleAlg, double dfWarpMemoryLimit,
00203                     double dfMaxError,
00204                     GDALProgressFunc pfnProgress, void *pProgressArg, 
00205                     GDALWarpOptions *psOptions );
00206 
00207 CPL_C_END
00208 
00209 #ifdef __cplusplus 
00210 
00211 /************************************************************************/
00212 /*                            GDALWarpKernel                            */
00213 /*                                                                      */
00214 /*      This class represents the lowest level of abstraction.  It      */
00215 /*      is holds the imagery for one "chunk" of a warp, and the         */
00216 /*      pre-prepared masks.  All IO is done before and after it's       */
00217 /*      operation.  This class is not normally used by the              */
00218 /*      application.                                                    */
00219 /************************************************************************/
00220 
00221 class CPL_DLL GDALWarpKernel
00222 {
00223 public:
00224                        GDALWarpKernel();
00225     virtual           ~GDALWarpKernel();
00226 
00227     char              **papszWarpOptions;
00228 
00229     GDALResampleAlg     eResample;
00230     GDALDataType        eWorkingDataType;
00231     int                 nBands;
00232 
00233     int                 nSrcXSize;
00234     int                 nSrcYSize;
00235     GByte               **papabySrcImage;
00236 
00237     GUInt32           **papanBandSrcValid;
00238     GUInt32            *panUnifiedSrcValid;
00239     float              *pafUnifiedSrcDensity;
00240 
00241     int                 nDstXSize;
00242     int                 nDstYSize;
00243     GByte             **papabyDstImage;
00244     GUInt32            *panDstValid;
00245     float              *pafDstDensity;
00246     
00247     int                 nSrcXOff;
00248     int                 nSrcYOff;
00249 
00250     int                 nDstXOff;
00251     int                 nDstYOff;
00252         
00253     GDALTransformerFunc pfnTransformer;
00254     void                *pTransformerArg;
00255 
00256     GDALProgressFunc    pfnProgress;
00257     void                *pProgress;
00258 
00259     double              dfProgressBase;
00260     double              dfProgressScale;
00261 
00262     CPLErr              Validate();
00263     CPLErr              PerformWarp();
00264 };
00265 
00266 /************************************************************************/
00267 /*                         GDALWarpOperation()                          */
00268 /*                                                                      */
00269 /*      This object is application created, or created by a higher      */
00270 /*      level convenience function.  It is responsible for              */
00271 /*      subdividing the operation into chunks, loading and saving       */
00272 /*      imagery, and establishing the varios validity and density       */
00273 /*      masks.  Actual resampling is done by the GDALWarpKernel.        */
00274 /************************************************************************/
00275 
00276 class CPL_DLL GDALWarpOperation {
00277 private:
00278     GDALWarpOptions *psOptions;
00279 
00280     double          dfProgressBase;
00281     double          dfProgressScale;
00282 
00283     void            WipeOptions();
00284     int             ValidateOptions();
00285 
00286     CPLErr          ComputeSourceWindow( int nDstXOff, int nDstYOff, 
00287                                          int nDstXSize, int nDstYSize,
00288                                          int *pnSrcXOff, int *pnSrcYOff, 
00289                                          int *pnSrcXSize, int *pnSrcYSize );
00290 
00291     CPLErr          CreateKernelMask( GDALWarpKernel *, int iBand, 
00292                                       const char *pszType );
00293 
00294     void            *hThread1Mutex;
00295     void            *hThread2Mutex;
00296     void            *hIOMutex;
00297     void            *hWarpMutex;
00298 
00299     int             nChunkListCount;
00300     int             nChunkListMax;
00301     int            *panChunkList;
00302 
00303     int             bReportTimings;
00304     unsigned long   nLastTimeReported;
00305 
00306     void            WipeChunkList();
00307     CPLErr          CollectChunkList( int nDstXOff, int nDstYOff, 
00308                                       int nDstXSize, int nDstYSize );
00309     void            ReportTiming( const char * );
00310     
00311 public:
00312                     GDALWarpOperation();
00313     virtual        ~GDALWarpOperation();
00314 
00315     CPLErr          Initialize( const GDALWarpOptions *psNewOptions );
00316 
00317     const GDALWarpOptions         *GetOptions();
00318 
00319     CPLErr          ChunkAndWarpImage( int nDstXOff, int nDstYOff, 
00320                                        int nDstXSize, int nDstYSize );
00321     CPLErr          ChunkAndWarpMulti( int nDstXOff, int nDstYOff, 
00322                                        int nDstXSize, int nDstYSize );
00323     CPLErr          WarpRegion( int nDstXOff, int nDstYOff, 
00324                                 int nDstXSize, int nDstYSize,
00325                                 int nSrcXOff=0, int nSrcYOff=0,
00326                                 int nSrcXSize=0, int nSrcYSize=0 );
00327     
00328     CPLErr          WarpRegionToBuffer( int nDstXOff, int nDstYOff, 
00329                                         int nDstXSize, int nDstYSize, 
00330                                         void *pDataBuf, 
00331                                         GDALDataType eBufDataType,
00332                                         int nSrcXOff=0, int nSrcYOff=0,
00333                                         int nSrcXSize=0, int nSrcYSize=0 );
00334 };
00335 
00336 #endif /* def __cplusplus */
00337 
00338 #endif /* ndef GDAL_ALG_H_INCLUDED */

Generated on Thu Nov 13 00:08:23 2003 for GDAL by doxygen 1.3.4