GDAL

gdal_alg_priv.h
1 /******************************************************************************
2 * $Id$
3 *
4 * Project: GDAL Image Processing Algorithms
5 * Purpose: Prototypes and definitions for various GDAL based algorithms:
6 * private declarations.
7 * Author: Andrey Kiselev, dron@ak4719.spb.edu
8 *
9 ******************************************************************************
10 * Copyright (c) 2008, Andrey Kiselev <dron@ak4719.spb.edu>
11 * Copyright (c) 2010-2013, Even Rouault <even dot rouault at spatialys.com>
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining a
14 * copy of this software and associated documentation files (the "Software"),
15 * to deal in the Software without restriction, including without limitation
16 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 * and/or sell copies of the Software, and to permit persons to whom the
18 * Software is furnished to do so, subject to the following conditions:
19 *
20 * The above copyright notice and this permission notice shall be included
21 * in all copies or substantial portions of the Software.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 * DEALINGS IN THE SOFTWARE.
30 ****************************************************************************/
31
32 #ifndef GDAL_ALG_PRIV_H_INCLUDED
33 #define GDAL_ALG_PRIV_H_INCLUDED
34
35 #ifndef DOXYGEN_SKIP
36
37 #include <cstdint>
38
39 #include "gdal_alg.h"
40 #include "ogr_spatialref.h"
41
42 CPL_C_START
43
45 typedef enum { GBV_UserBurnValue = 0, GBV_Z = 1, GBV_M = 2
49 } GDALBurnValueSrc;
50
51 typedef enum {
52 GRMA_Replace = 0,
53 GRMA_Add = 1,
54 } GDALRasterMergeAlg;
55
56 typedef struct {
57 unsigned char * pabyChunkBuf;
58 int nXSize;
59 int nYSize;
60 int nBands;
61 GDALDataType eType;
62 int nPixelSpace;
63 GSpacing nLineSpace;
64 GSpacing nBandSpace;
65 GDALDataType eBurnValueType;
66 union
67 {
68 const std::int64_t* int64_values;
69 const double *double_values;
70 } burnValues;
71 GDALBurnValueSrc eBurnValueSource;
72 GDALRasterMergeAlg eMergeAlg;
73 } GDALRasterizeInfo;
74
75 typedef enum {
76 GRO_Raster = 0,
77 GRO_Vector = 1,
78 GRO_Auto = 2,
79 } GDALRasterizeOptim;
80
81
82 /************************************************************************/
83 /* Low level rasterizer API. */
84 /************************************************************************/
85
86 typedef void (*llScanlineFunc)( void *, int, int, int, double );
87 typedef void (*llPointFunc)( void *, int, int, double );
88
89 void GDALdllImagePoint( int nRasterXSize, int nRasterYSize,
90 int nPartCount, const int *panPartSize,
91 const double *padfX, const double *padfY,
92 const double *padfVariant,
93 llPointFunc pfnPointFunc, void *pCBData );
94
95 void GDALdllImageLine( int nRasterXSize, int nRasterYSize,
96 int nPartCount, const int *panPartSize,
97 const double *padfX, const double *padfY,
98 const double *padfVariant,
99 llPointFunc pfnPointFunc, void *pCBData );
100
101 void GDALdllImageLineAllTouched( int nRasterXSize, int nRasterYSize,
102 int nPartCount, const int *panPartSize,
103 const double *padfX, const double *padfY,
104 const double *padfVariant,
105 llPointFunc pfnPointFunc, void *pCBData,
106 int bAvoidBurningSamePoints );
107
108 void GDALdllImageFilledPolygon( int nRasterXSize, int nRasterYSize,
109 int nPartCount, const int *panPartSize,
110 const double *padfX, const double *padfY,
111 const double *padfVariant,
112 llScanlineFunc pfnScanlineFunc, void *pCBData );
113
114 CPL_C_END
115
116 /************************************************************************/
117 /* Polygon Enumerator */
118 /************************************************************************/
119
120 #define GP_NODATA_MARKER -51502112
121
122 template<class DataType, class EqualityTest> class GDALRasterPolygonEnumeratorT
123
124 {
125 private:
126 void MergePolygon( int nSrcId, int nDstId );
127 int NewPolygon( DataType nValue );
128
129 CPL_DISALLOW_COPY_ASSIGN(GDALRasterPolygonEnumeratorT)
130
131 public: // these are intended to be readonly.
132
133 GInt32 *panPolyIdMap = nullptr;
134 DataType *panPolyValue = nullptr;
135
136 int nNextPolygonId = 0;
137 int nPolyAlloc = 0;
138
139 int nConnectedness = 0;
140
141 public:
142 explicit GDALRasterPolygonEnumeratorT( int nConnectedness=4 );
143 ~GDALRasterPolygonEnumeratorT();
144
145 void ProcessLine( DataType *panLastLineVal, DataType *panThisLineVal,
146 GInt32 *panLastLineId, GInt32 *panThisLineId,
147 int nXSize );
148
149 void CompleteMerges();
150
151 void Clear();
152 };
153
154 struct IntEqualityTest
155 {
156 bool operator()(std::int64_t a, std::int64_t b) const { return a == b; }
157 };
158
159 typedef GDALRasterPolygonEnumeratorT<std::int64_t, IntEqualityTest> GDALRasterPolygonEnumerator;
160
161 typedef void* (*GDALTransformDeserializeFunc)( CPLXMLNode *psTree );
162
163 void CPL_DLL *GDALRegisterTransformDeserializer(const char* pszTransformName,
164 GDALTransformerFunc pfnTransformerFunc,
165 GDALTransformDeserializeFunc pfnDeserializeFunc);
166 void CPL_DLL GDALUnregisterTransformDeserializer(void* pData);
167
168 void GDALCleanupTransformDeserializerMutex();
169
170 /* Transformer cloning */
171
172 void* GDALCreateTPSTransformerInt( int nGCPCount, const GDAL_GCP *pasGCPList,
173 int bReversed, char** papszOptions );
174
175 void CPL_DLL * GDALCloneTransformer( void *pTransformerArg );
176
177 void GDALRefreshGenImgProjTransformer(void* hTransformArg);
178 void GDALRefreshApproxTransformer(void* hTransformArg);
179
180 int GDALTransformLonLatToDestGenImgProjTransformer(void* hTransformArg,
181 double* pdfX,
182 double* pdfY);
183 int GDALTransformLonLatToDestApproxTransformer(void* hTransformArg,
184 double* pdfX,
185 double* pdfY);
186
187 bool GDALTransformIsTranslationOnPixelBoundaries(GDALTransformerFunc pfnTransformer,
188 void *pTransformerArg);
189
190 typedef struct _CPLQuadTree CPLQuadTree;
191
192 typedef struct {
193 GDALTransformerInfo sTI;
194
195 bool bReversed;
196 double dfOversampleFactor;
197
198 // Map from target georef coordinates back to geolocation array
199 // pixel line coordinates. Built only if needed.
200 int nBackMapWidth;
201 int nBackMapHeight;
202 double adfBackMapGeoTransform[6]; // Maps georef to pixel/line.
203
204 bool bUseArray;
205 void *pAccessors;
206
207 // Geolocation bands.
208 GDALDatasetH hDS_X;
209 GDALRasterBandH hBand_X;
210 GDALDatasetH hDS_Y;
211 GDALRasterBandH hBand_Y;
212 int bSwapXY;
213
214 // Located geolocation data.
215 int nGeoLocXSize;
216 int nGeoLocYSize;
217 double dfMinX;
218 double dfYAtMinX;
219 double dfMinY;
220 double dfXAtMinY;
221 double dfMaxX;
222 double dfYAtMaxX;
223 double dfMaxY;
224 double dfXAtMaxY;
225
226 int bHasNoData;
227 double dfNoDataX;
228
229 // Geolocation <-> base image mapping.
230 double dfPIXEL_OFFSET;
231 double dfPIXEL_STEP;
232 double dfLINE_OFFSET;
233 double dfLINE_STEP;
234
235 bool bOriginIsTopLeftCorner;
236 bool bGeographicSRSWithMinus180Plus180LongRange;
237 CPLQuadTree *hQuadTree;
238
239 char ** papszGeolocationInfo;
240
241 } GDALGeoLocTransformInfo;
242
243
244 /************************************************************************/
245 /* Color table related */
246 /************************************************************************/
247
248 // Definitions exists for T = GUInt32 and T = GUIntBig.
249 template<class T> int
250 GDALComputeMedianCutPCTInternal( GDALRasterBandH hRed,
251 GDALRasterBandH hGreen,
252 GDALRasterBandH hBlue,
253 GByte* pabyRedBand,
254 GByte* pabyGreenBand,
255 GByte* pabyBlueBand,
256 int (*pfnIncludePixel)(int,int,void*),
257 int nColors,
258 int nBits,
259 T* panHistogram,
260 GDALColorTableH hColorTable,
261 GDALProgressFunc pfnProgress,
262 void * pProgressArg );
263
264 int GDALDitherRGB2PCTInternal( GDALRasterBandH hRed,
265 GDALRasterBandH hGreen,
266 GDALRasterBandH hBlue,
267 GDALRasterBandH hTarget,
268 GDALColorTableH hColorTable,
269 int nBits,
270 GInt16* pasDynamicColorMap,
271 int bDither,
272 GDALProgressFunc pfnProgress,
273 void * pProgressArg );
274
275 #define PRIME_FOR_65536 98317
276
277 // See HashHistogram structure in gdalmediancut.cpp and ColorIndex structure in
278 // gdaldither.cpp 6 * sizeof(int) should be the size of the largest of both
279 // structures.
280 #define MEDIAN_CUT_AND_DITHER_BUFFER_SIZE_65536 (6 * sizeof(int) * PRIME_FOR_65536)
281
282 /************************************************************************/
283 /* Float comparison function. */
284 /************************************************************************/
285
292 #define MAX_ULPS 10
293
294 GBool GDALFloatEquals(float A, float B);
295
296 struct FloatEqualityTest
297 {
298 bool operator()(float a, float b) { return GDALFloatEquals(a,b) == TRUE; }
299 };
300
301 bool GDALComputeAreaOfInterest(OGRSpatialReference* poSRS,
302 double adfGT[6],
303 int nXSize,
304 int nYSize,
305 double& dfWestLongitudeDeg,
306 double& dfSouthLatitudeDeg,
307 double& dfEastLongitudeDeg,
308 double& dfNorthLatitudeDeg );
309
310 bool GDALComputeAreaOfInterest(OGRSpatialReference* poSRS,
311 double dfX1,
312 double dfY1,
313 double dfX2,
314 double dfY2,
315 double& dfWestLongitudeDeg,
316 double& dfSouthLatitudeDeg,
317 double& dfEastLongitudeDeg,
318 double& dfNorthLatitudeDeg );
319
320 void *GDALCreateGeoLocTransformerEx( GDALDatasetH hBaseDS,
321 char **papszGeolocationInfo,
322 int bReversed,
323 const char* pszSourceDataset,
324 CSLConstList papszTransformOptions );
325
326 #endif /* #ifndef DOXYGEN_SKIP */
327
328 #endif /* ndef GDAL_ALG_PRIV_H_INCLUDED */
ogr_spatialref.h
GByte
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:203
GInt16
short GInt16
Int16 type.
Definition: cpl_port.h:199
GDALTransformerFunc
int(* GDALTransformerFunc)(void *pTransformerArg, int bDstToSrc, int nPointCount, double *x, double *y, double *z, int *panSuccess)
Definition: gdal_alg.h:115
OGRSpatialReference
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition: ogr_spatialref.h:157
GDALColorTableH
void * GDALColorTableH
Opaque type used for the C bindings of the C++ GDALColorTable class.
Definition: gdal.h:278
GDALDataType
GDALDataType
Definition: gdal.h:63
CPLXMLNode
Document node structure.
Definition: cpl_minixml.h:69
CPLQuadTree
struct _CPLQuadTree CPLQuadTree
Opaque type for a quad tree.
Definition: cpl_quad_tree.h:64
CPL_C_START
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:301
CSLConstList
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1053
GDAL_GCP
Ground Control Point.
Definition: gdal.h:732
CPL_C_END
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:303
GSpacing
GIntBig GSpacing
Type to express pixel, line or band spacing.
Definition: gdal.h:287
gdal_alg.h
GBool
int GBool
Type for boolean values (alias to int)
Definition: cpl_port.h:211
GDALRasterBandH
void * GDALRasterBandH
Opaque type used for the C bindings of the C++ GDALRasterBand class.
Definition: gdal.h:272
GInt32
int GInt32
Int32 type.
Definition: cpl_port.h:193
CPL_DISALLOW_COPY_ASSIGN
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition: cpl_port.h:927
GDALDatasetH
void * GDALDatasetH
Opaque type used for the C bindings of the C++ GDALDataset class.
Definition: gdal.h:269