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, bool bIntersectOnly );
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 bool GDALTransformIsAffineNoRotation(GDALTransformerFunc pfnTransformer,
191 void *pTransformerArg);
192
193 typedef struct _CPLQuadTree CPLQuadTree;
194
195 typedef struct {
196 GDALTransformerInfo sTI;
197
198 bool bReversed;
199 double dfOversampleFactor;
200
201 // Map from target georef coordinates back to geolocation array
202 // pixel line coordinates. Built only if needed.
203 int nBackMapWidth;
204 int nBackMapHeight;
205 double adfBackMapGeoTransform[6]; // Maps georef to pixel/line.
206
207 bool bUseArray;
208 void *pAccessors;
209
210 // Geolocation bands.
211 GDALDatasetH hDS_X;
212 GDALRasterBandH hBand_X;
213 GDALDatasetH hDS_Y;
214 GDALRasterBandH hBand_Y;
215 int bSwapXY;
216
217 // Located geolocation data.
218 int nGeoLocXSize;
219 int nGeoLocYSize;
220 double dfMinX;
221 double dfYAtMinX;
222 double dfMinY;
223 double dfXAtMinY;
224 double dfMaxX;
225 double dfYAtMaxX;
226 double dfMaxY;
227 double dfXAtMaxY;
228
229 int bHasNoData;
230 double dfNoDataX;
231
232 // Geolocation <-> base image mapping.
233 double dfPIXEL_OFFSET;
234 double dfPIXEL_STEP;
235 double dfLINE_OFFSET;
236 double dfLINE_STEP;
237
238 bool bOriginIsTopLeftCorner;
239 bool bGeographicSRSWithMinus180Plus180LongRange;
240 CPLQuadTree *hQuadTree;
241
242 char ** papszGeolocationInfo;
243
244 } GDALGeoLocTransformInfo;
245
246
247 /************************************************************************/
248 /* Color table related */
249 /************************************************************************/
250
251 // Definitions exists for T = GUInt32 and T = GUIntBig.
252 template<class T> int
253 GDALComputeMedianCutPCTInternal( GDALRasterBandH hRed,
254 GDALRasterBandH hGreen,
255 GDALRasterBandH hBlue,
256 GByte* pabyRedBand,
257 GByte* pabyGreenBand,
258 GByte* pabyBlueBand,
259 int (*pfnIncludePixel)(int,int,void*),
260 int nColors,
261 int nBits,
262 T* panHistogram,
263 GDALColorTableH hColorTable,
264 GDALProgressFunc pfnProgress,
265 void * pProgressArg );
266
267 int GDALDitherRGB2PCTInternal( GDALRasterBandH hRed,
268 GDALRasterBandH hGreen,
269 GDALRasterBandH hBlue,
270 GDALRasterBandH hTarget,
271 GDALColorTableH hColorTable,
272 int nBits,
273 GInt16* pasDynamicColorMap,
274 int bDither,
275 GDALProgressFunc pfnProgress,
276 void * pProgressArg );
277
278 #define PRIME_FOR_65536 98317
279
280 // See HashHistogram structure in gdalmediancut.cpp and ColorIndex structure in
281 // gdaldither.cpp 6 * sizeof(int) should be the size of the largest of both
282 // structures.
283 #define MEDIAN_CUT_AND_DITHER_BUFFER_SIZE_65536 (6 * sizeof(int) * PRIME_FOR_65536)
284
285 /************************************************************************/
286 /* Float comparison function. */
287 /************************************************************************/
288
295 #define MAX_ULPS 10
296
297 GBool GDALFloatEquals(float A, float B);
298
299 struct FloatEqualityTest
300 {
301 bool operator()(float a, float b) { return GDALFloatEquals(a,b) == TRUE; }
302 };
303
304 bool GDALComputeAreaOfInterest(OGRSpatialReference* poSRS,
305 double adfGT[6],
306 int nXSize,
307 int nYSize,
308 double& dfWestLongitudeDeg,
309 double& dfSouthLatitudeDeg,
310 double& dfEastLongitudeDeg,
311 double& dfNorthLatitudeDeg );
312
313 bool GDALComputeAreaOfInterest(OGRSpatialReference* poSRS,
314 double dfX1,
315 double dfY1,
316 double dfX2,
317 double dfY2,
318 double& dfWestLongitudeDeg,
319 double& dfSouthLatitudeDeg,
320 double& dfEastLongitudeDeg,
321 double& dfNorthLatitudeDeg );
322
323 CPLStringList GDALCreateGeolocationMetadata( GDALDatasetH hBaseDS,
324 const char* pszGeolocationDataset,
325 bool bIsSource );
326
327 void *GDALCreateGeoLocTransformerEx( GDALDatasetH hBaseDS,
328 CSLConstList papszGeolocationInfo,
329 int bReversed,
330 const char* pszSourceDataset,
331 CSLConstList papszTransformOptions );
332
333 #endif /* #ifndef DOXYGEN_SKIP */
334
335 #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
CPLStringList
String list class designed around our use of C "char**" string lists.
Definition: cpl_string.h:429
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:304
CSLConstList
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1056
GDAL_GCP
Ground Control Point.
Definition: gdal.h:892
CPL_C_END
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:306
GSpacing
GIntBig GSpacing
Type to express pixel, line or band spacing.
Definition: gdal.h:292
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:930
GDALDatasetH
void * GDALDatasetH
Opaque type used for the C bindings of the C++ GDALDataset class.
Definition: gdal.h:269