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 * SPDX-License-Identifier: MIT
14 ****************************************************************************/
15
16#ifndef GDAL_ALG_PRIV_H_INCLUDED
17#define GDAL_ALG_PRIV_H_INCLUDED
18
19#ifndef DOXYGEN_SKIP
20
21#include <cstdint>
22
23#include <set>
24
25#include "gdal_alg.h"
26#include "ogr_spatialref.h"
27
28 CPL_C_START
29
31 typedef enum
32{
GBV_UserBurnValue = 0, GBV_Z = 1, GBV_M = 2
36} GDALBurnValueSrc;
37
38 typedef enum
39{
40 GRMA_Replace = 0,
41 GRMA_Add = 1,
42} GDALRasterMergeAlg;
43
44 typedef struct
45{
46 unsigned char *pabyChunkBuf;
47 int nXSize;
48 int nYSize;
49 int nBands;
50 GDALDataType eType;
51 int nPixelSpace;
52 GSpacing nLineSpace;
53 GSpacing nBandSpace;
54 GDALDataType eBurnValueType;
55
56 union
57 {
58 const std::int64_t *int64_values;
59 const double *double_values;
60 } burnValues;
61
62 GDALBurnValueSrc eBurnValueSource;
63 GDALRasterMergeAlg eMergeAlg;
64 bool bFillSetVisitedPoints;
65 std::set<uint64_t> *poSetVisitedPoints;
66} GDALRasterizeInfo;
67
68 typedef enum
69{
70 GRO_Raster = 0,
71 GRO_Vector = 1,
72 GRO_Auto = 2,
73} GDALRasterizeOptim;
74
75/************************************************************************/
76/* Low level rasterizer API. */
77/************************************************************************/
78
79 typedef void (*llScanlineFunc)(void *, int, int, int, double);
80 typedef void (*llPointFunc)(void *, int, int, double);
81
82 void GDALdllImagePoint(int nRasterXSize, int nRasterYSize, int nPartCount,
83 const int *panPartSize, const double *padfX,
84 const double *padfY, const double *padfVariant,
85 llPointFunc pfnPointFunc, void *pCBData);
86
87 void GDALdllImageLine(int nRasterXSize, int nRasterYSize, int nPartCount,
88 const int *panPartSize, const double *padfX,
89 const double *padfY, const double *padfVariant,
90 llPointFunc pfnPointFunc, void *pCBData);
91
92 void GDALdllImageLineAllTouched(int nRasterXSize, int nRasterYSize,
93 int nPartCount, const int *panPartSize,
94 const double *padfX, const double *padfY,
95 const double *padfVariant,
96 llPointFunc pfnPointFunc, void *pCBData,
97 bool bAvoidBurningSamePoints,
98 bool bIntersectOnly);
99
100 void GDALdllImageFilledPolygon(int nRasterXSize, int nRasterYSize,
101 int nPartCount, const int *panPartSize,
102 const double *padfX, const double *padfY,
103 const double *padfVariant,
104 llScanlineFunc pfnScanlineFunc, void *pCBData,
105 bool bAvoidBurningSamePoints);
106
107 CPL_C_END
108
109/************************************************************************/
110/* Polygon Enumerator */
111/************************************************************************/
112
113#define GP_NODATA_MARKER -51502112
114
115 template <class DataType, class EqualityTest> class GDALRasterPolygonEnumeratorT
116
117{
118 private:
119 void MergePolygon(int nSrcId, int nDstId);
120 int NewPolygon(DataType nValue);
121
122 CPL_DISALLOW_COPY_ASSIGN(GDALRasterPolygonEnumeratorT)
123
124 public: // these are intended to be readonly.
125 GInt32 *panPolyIdMap = nullptr;
126 DataType *panPolyValue = nullptr;
127
128 int nNextPolygonId = 0;
129 int nPolyAlloc = 0;
130
131 int nConnectedness = 0;
132
133 public:
134 explicit GDALRasterPolygonEnumeratorT(int nConnectedness = 4);
135 ~GDALRasterPolygonEnumeratorT();
136
137 bool ProcessLine(DataType *panLastLineVal, DataType *panThisLineVal,
138 GInt32 *panLastLineId, GInt32 *panThisLineId, int nXSize);
139
140 void CompleteMerges();
141
142 void Clear();
143};
144
145 struct IntEqualityTest
146{
147 bool operator()(std::int64_t a, std::int64_t b) const
148 {
149 return a == b;
150 }
151};
152
153 typedef GDALRasterPolygonEnumeratorT<std::int64_t, IntEqualityTest>
154 GDALRasterPolygonEnumerator;
155
156 constexpr const char *GDAL_APPROX_TRANSFORMER_CLASS_NAME =
157 "GDALApproxTransformer";
158 constexpr const char *GDAL_GEN_IMG_TRANSFORMER_CLASS_NAME =
159 "GDALGenImgProjTransformer";
160 constexpr const char *GDAL_RPC_TRANSFORMER_CLASS_NAME = "GDALRPCTransformer";
161
162 bool GDALIsTransformer(void *hTransformerArg, const char *pszClassName);
163
164 typedef void *(*GDALTransformDeserializeFunc)(CPLXMLNode *psTree);
165
166 void CPL_DLL *GDALRegisterTransformDeserializer(
167 const char *pszTransformName, GDALTransformerFunc pfnTransformerFunc,
168 GDALTransformDeserializeFunc pfnDeserializeFunc);
169 void CPL_DLL GDALUnregisterTransformDeserializer(void *pData);
170
171 void GDALCleanupTransformDeserializerMutex();
172
173/* Transformer cloning */
174
175 void *GDALCreateTPSTransformerInt(int nGCPCount, const GDAL_GCP *pasGCPList,
176 int bReversed, char **papszOptions);
177
178 void CPL_DLL *GDALCloneTransformer(void *pTransformerArg);
179
180 void GDALRefreshGenImgProjTransformer(void *hTransformArg);
181 void GDALRefreshApproxTransformer(void *hTransformArg);
182
183 int GDALTransformLonLatToDestGenImgProjTransformer(void *hTransformArg,
184 double *pdfX, double *pdfY);
185 int GDALTransformLonLatToDestApproxTransformer(void *hTransformArg,
186 double *pdfX, double *pdfY);
187
188 bool GDALTransformIsTranslationOnPixelBoundaries(
189 GDALTransformerFunc pfnTransformer, void *pTransformerArg);
190
191 bool GDALTransformIsAffineNoRotation(GDALTransformerFunc pfnTransformer,
192 void *pTransformerArg);
193
194 bool GDALTransformHasFastClone(void *pTransformerArg);
195
196 typedef struct _CPLQuadTree CPLQuadTree;
197
198 typedef struct
199{
200 GDALTransformerInfo sTI;
201
202 bool bReversed;
203 double dfOversampleFactor;
204
205 // Map from target georef coordinates back to geolocation array
206 // pixel line coordinates. Built only if needed.
207 int nBackMapWidth;
208 int nBackMapHeight;
209 double adfBackMapGeoTransform[6]; // Maps georef to pixel/line.
210
211 bool bUseArray;
212 void *pAccessors;
213
214 // Geolocation bands.
215 GDALDatasetH hDS_X;
216 GDALRasterBandH hBand_X;
217 GDALDatasetH hDS_Y;
218 GDALRasterBandH hBand_Y;
219 int bSwapXY;
220
221 // Located geolocation data.
222 int nGeoLocXSize;
223 int nGeoLocYSize;
224 double dfMinX;
225 double dfYAtMinX;
226 double dfMinY;
227 double dfXAtMinY;
228 double dfMaxX;
229 double dfYAtMaxX;
230 double dfMaxY;
231 double dfXAtMaxY;
232
233 int bHasNoData;
234 double dfNoDataX;
235
236 // Geolocation <-> base image mapping.
237 double dfPIXEL_OFFSET;
238 double dfPIXEL_STEP;
239 double dfLINE_OFFSET;
240 double dfLINE_STEP;
241
242 bool bOriginIsTopLeftCorner;
243 bool bGeographicSRSWithMinus180Plus180LongRange;
244 CPLQuadTree *hQuadTree;
245
246 char **papszGeolocationInfo;
247
248} GDALGeoLocTransformInfo;
249
250/************************************************************************/
251/* ==================================================================== */
252/* GDALReprojectionTransformer */
253/* ==================================================================== */
254/************************************************************************/
255
256 struct GDALReprojectionTransformInfo
257{
258 GDALTransformerInfo sTI;
259 char **papszOptions = nullptr;
260 double dfTime = 0.0;
261
262 OGRCoordinateTransformation *poForwardTransform = nullptr;
263 OGRCoordinateTransformation *poReverseTransform = nullptr;
264
265 GDALReprojectionTransformInfo() : sTI()
266 {
267 memset(&sTI, 0, sizeof(sTI));
268 }
269
270 GDALReprojectionTransformInfo(const GDALReprojectionTransformInfo &) =
271 delete;
272 GDALReprojectionTransformInfo &
273 operator=(const GDALReprojectionTransformInfo &) = delete;
274};
275
276/************************************************************************/
277/* ==================================================================== */
278/* GDALGenImgProjTransformer */
279/* ==================================================================== */
280/************************************************************************/
281
282 typedef struct
283{
284
285 GDALTransformerInfo sTI;
286
287 double adfSrcGeoTransform[6];
288 double adfSrcInvGeoTransform[6];
289
290 void *pSrcTransformArg;
291 GDALTransformerFunc pSrcTransformer;
292
293 void *pReprojectArg;
294 GDALTransformerFunc pReproject;
295
296 double adfDstGeoTransform[6];
297 double adfDstInvGeoTransform[6];
298
299 void *pDstTransformArg;
300 GDALTransformerFunc pDstTransformer;
301
302 // Memorize the value of the CHECK_WITH_INVERT_PROJ at the time we
303 // instantiated the object, to be able to decide if
304 // GDALRefreshGenImgProjTransformer() must do something or not.
305 bool bCheckWithInvertPROJ;
306
307 // Set to TRUE when the transformation pipline is a custom one.
308 bool bHasCustomTransformationPipeline;
309
310} GDALGenImgProjTransformInfo;
311
312/************************************************************************/
313/* Color table related */
314/************************************************************************/
315
316// Definitions exists for T = GUInt32 and T = GUIntBig.
317 template <class T>
318 int GDALComputeMedianCutPCTInternal(
319 GDALRasterBandH hRed, GDALRasterBandH hGreen, GDALRasterBandH hBlue,
320 GByte *pabyRedBand, GByte *pabyGreenBand, GByte *pabyBlueBand,
321 int (*pfnIncludePixel)(int, int, void *), int nColors, int nBits,
322 T *panHistogram, GDALColorTableH hColorTable, GDALProgressFunc pfnProgress,
323 void *pProgressArg);
324
325 int GDALDitherRGB2PCTInternal(GDALRasterBandH hRed, GDALRasterBandH hGreen,
326 GDALRasterBandH hBlue, GDALRasterBandH hTarget,
327 GDALColorTableH hColorTable, int nBits,
328 GInt16 *pasDynamicColorMap, int bDither,
329 GDALProgressFunc pfnProgress, void *pProgressArg);
330
331#define PRIME_FOR_65536 98317
332
333// See HashHistogram structure in gdalmediancut.cpp and ColorIndex structure in
334// gdaldither.cpp 6 * sizeof(int) should be the size of the largest of both
335// structures.
336#define MEDIAN_CUT_AND_DITHER_BUFFER_SIZE_65536 \
337 (6 * sizeof(int) * PRIME_FOR_65536)
338
339/************************************************************************/
340/* Float comparison function. */
341/************************************************************************/
342
349#define MAX_ULPS 10
350
351 GBool GDALFloatEquals(float A, float B);
352
353 struct FloatEqualityTest
354{
355 bool operator()(float a, float b)
356 {
357 return GDALFloatEquals(a, b) == TRUE;
358 }
359};
360
361 bool GDALComputeAreaOfInterest(OGRSpatialReference *poSRS, double adfGT[6],
362 int nXSize, int nYSize,
363 double &dfWestLongitudeDeg,
364 double &dfSouthLatitudeDeg,
365 double &dfEastLongitudeDeg,
366 double &dfNorthLatitudeDeg);
367
368 bool GDALComputeAreaOfInterest(OGRSpatialReference *poSRS, double dfX1,
369 double dfY1, double dfX2, double dfY2,
370 double &dfWestLongitudeDeg,
371 double &dfSouthLatitudeDeg,
372 double &dfEastLongitudeDeg,
373 double &dfNorthLatitudeDeg);
374
375 CPLStringList GDALCreateGeolocationMetadata(GDALDatasetH hBaseDS,
376 const char *pszGeolocationDataset,
377 bool bIsSource);
378
379 void *GDALCreateGeoLocTransformerEx(GDALDatasetH hBaseDS,
380 CSLConstList papszGeolocationInfo,
381 int bReversed, const char *pszSourceDataset,
382 CSLConstList papszTransformOptions);
383
384#endif /* #ifndef DOXYGEN_SKIP */
385
386#endif /* ndef GDAL_ALG_PRIV_H_INCLUDED */
CPLStringList
String list class designed around our use of C "char**" string lists.
Definition cpl_string.h:436
OGRCoordinateTransformation
Interface for transforming between coordinate systems.
Definition ogr_spatialref.h:773
OGRSpatialReference
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition ogr_spatialref.h:153
GInt16
short GInt16
Int16 type.
Definition cpl_port.h:165
CPL_C_END
#define CPL_C_END
Macro to end a block of C symbols.
Definition cpl_port.h:283
CPL_C_START
#define CPL_C_START
Macro to start a block of C symbols.
Definition cpl_port.h:279
GBool
int GBool
Type for boolean values (alias to int)
Definition cpl_port.h:180
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:1030
CSLConstList
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition cpl_port.h:1179
GByte
unsigned char GByte
Unsigned byte type.
Definition cpl_port.h:169
GInt32
int GInt32
Int32 type.
Definition cpl_port.h:159
CPLQuadTree
struct _CPLQuadTree CPLQuadTree
Opaque type for a quad tree.
Definition cpl_quad_tree.h:49
GSpacing
GIntBig GSpacing
Type to express pixel, line or band spacing.
Definition gdal.h:400
GDALDataType
GDALDataType
Definition gdal.h:48
GDALDatasetH
void * GDALDatasetH
Opaque type used for the C bindings of the C++ GDALDataset class.
Definition gdal.h:376
GDALRasterBandH
void * GDALRasterBandH
Opaque type used for the C bindings of the C++ GDALRasterBand class.
Definition gdal.h:379
GDALColorTableH
void * GDALColorTableH
Opaque type used for the C bindings of the C++ GDALColorTable class.
Definition gdal.h:385
gdal_alg.h
Public (C callable) GDAL algorithm entry points, and definitions.
GDALTransformerFunc
int(* GDALTransformerFunc)(void *pTransformerArg, int bDstToSrc, int nPointCount, double *x, double *y, double *z, int *panSuccess)
Definition gdal_alg.h:79
ogr_spatialref.h
Coordinate systems services.
CPLXMLNode
Document node structure.
Definition cpl_minixml.h:55
GDAL_GCP
Ground Control Point.
Definition gdal.h:1168