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
43
45typedef enum
46{
GBV_UserBurnValue = 0, GBV_Z = 1, GBV_M = 2
50} GDALBurnValueSrc;
51
52typedef enum
53{
54 GRMA_Replace = 0,
55 GRMA_Add = 1,
56} GDALRasterMergeAlg;
57
58typedef struct
59{
60 unsigned char *pabyChunkBuf;
61 int nXSize;
62 int nYSize;
63 int nBands;
64 GDALDataType eType;
65 int nPixelSpace;
66 GSpacing nLineSpace;
67 GSpacing nBandSpace;
68 GDALDataType eBurnValueType;
69 union
70 {
71 const std::int64_t *int64_values;
72 const double *double_values;
73 } burnValues;
74 GDALBurnValueSrc eBurnValueSource;
75 GDALRasterMergeAlg eMergeAlg;
76} GDALRasterizeInfo;
77
78typedef enum
79{
80 GRO_Raster = 0,
81 GRO_Vector = 1,
82 GRO_Auto = 2,
83} GDALRasterizeOptim;
84
85/************************************************************************/
86/* Low level rasterizer API. */
87/************************************************************************/
88
89typedef void (*llScanlineFunc)(void *, int, int, int, double);
90typedef void (*llPointFunc)(void *, int, int, double);
91
92void GDALdllImagePoint(int nRasterXSize, int nRasterYSize, int nPartCount,
93 const int *panPartSize, const double *padfX,
94 const double *padfY, const double *padfVariant,
95 llPointFunc pfnPointFunc, void *pCBData);
96
97void GDALdllImageLine(int nRasterXSize, int nRasterYSize, int nPartCount,
98 const int *panPartSize, const double *padfX,
99 const double *padfY, const double *padfVariant,
100 llPointFunc pfnPointFunc, void *pCBData);
101
102void GDALdllImageLineAllTouched(int nRasterXSize, int nRasterYSize,
103 int nPartCount, const int *panPartSize,
104 const double *padfX, const double *padfY,
105 const double *padfVariant,
106 llPointFunc pfnPointFunc, void *pCBData,
107 int bAvoidBurningSamePoints,
108 bool bIntersectOnly);
109
110void GDALdllImageFilledPolygon(int nRasterXSize, int nRasterYSize,
111 int nPartCount, const int *panPartSize,
112 const double *padfX, const double *padfY,
113 const double *padfVariant,
114 llScanlineFunc pfnScanlineFunc, void *pCBData);
115
117
118/************************************************************************/
119/* Polygon Enumerator */
120/************************************************************************/
121
122#define GP_NODATA_MARKER -51502112
123
124template <class DataType, class EqualityTest> class GDALRasterPolygonEnumeratorT
125
126{
127 private:
128 void MergePolygon(int nSrcId, int nDstId);
129 int NewPolygon(DataType nValue);
130
131 CPL_DISALLOW_COPY_ASSIGN(GDALRasterPolygonEnumeratorT)
132
133 public: // these are intended to be readonly.
134 GInt32 *panPolyIdMap = nullptr;
135 DataType *panPolyValue = nullptr;
136
137 int nNextPolygonId = 0;
138 int nPolyAlloc = 0;
139
140 int nConnectedness = 0;
141
142 public:
143 explicit GDALRasterPolygonEnumeratorT(int nConnectedness = 4);
144 ~GDALRasterPolygonEnumeratorT();
145
146 void ProcessLine(DataType *panLastLineVal, DataType *panThisLineVal,
147 GInt32 *panLastLineId, GInt32 *panThisLineId, int nXSize);
148
149 void CompleteMerges();
150
151 void Clear();
152};
153
154struct IntEqualityTest
155{
156 bool operator()(std::int64_t a, std::int64_t b) const
157 {
158 return a == b;
159 }
160};
161
162typedef GDALRasterPolygonEnumeratorT<std::int64_t, IntEqualityTest>
163 GDALRasterPolygonEnumerator;
164
165typedef void *(*GDALTransformDeserializeFunc)(CPLXMLNode *psTree);
166
167void CPL_DLL *GDALRegisterTransformDeserializer(
168 const char *pszTransformName, GDALTransformerFunc pfnTransformerFunc,
169 GDALTransformDeserializeFunc pfnDeserializeFunc);
170void CPL_DLL GDALUnregisterTransformDeserializer(void *pData);
171
172void GDALCleanupTransformDeserializerMutex();
173
174/* Transformer cloning */
175
176void *GDALCreateTPSTransformerInt(int nGCPCount, const GDAL_GCP *pasGCPList,
177 int bReversed, char **papszOptions);
178
179void CPL_DLL *GDALCloneTransformer(void *pTransformerArg);
180
181void GDALRefreshGenImgProjTransformer(void *hTransformArg);
182void GDALRefreshApproxTransformer(void *hTransformArg);
183
184int GDALTransformLonLatToDestGenImgProjTransformer(void *hTransformArg,
185 double *pdfX, double *pdfY);
186int GDALTransformLonLatToDestApproxTransformer(void *hTransformArg,
187 double *pdfX, double *pdfY);
188
189bool GDALTransformIsTranslationOnPixelBoundaries(
190 GDALTransformerFunc pfnTransformer, void *pTransformerArg);
191
192bool GDALTransformIsAffineNoRotation(GDALTransformerFunc pfnTransformer,
193 void *pTransformerArg);
194
195typedef struct _CPLQuadTree CPLQuadTree;
196
197typedef struct
198{
199 GDALTransformerInfo sTI;
200
201 bool bReversed;
202 double dfOversampleFactor;
203
204 // Map from target georef coordinates back to geolocation array
205 // pixel line coordinates. Built only if needed.
206 int nBackMapWidth;
207 int nBackMapHeight;
208 double adfBackMapGeoTransform[6]; // Maps georef to pixel/line.
209
210 bool bUseArray;
211 void *pAccessors;
212
213 // Geolocation bands.
214 GDALDatasetH hDS_X;
215 GDALRasterBandH hBand_X;
216 GDALDatasetH hDS_Y;
217 GDALRasterBandH hBand_Y;
218 int bSwapXY;
219
220 // Located geolocation data.
221 int nGeoLocXSize;
222 int nGeoLocYSize;
223 double dfMinX;
224 double dfYAtMinX;
225 double dfMinY;
226 double dfXAtMinY;
227 double dfMaxX;
228 double dfYAtMaxX;
229 double dfMaxY;
230 double dfXAtMaxY;
231
232 int bHasNoData;
233 double dfNoDataX;
234
235 // Geolocation <-> base image mapping.
236 double dfPIXEL_OFFSET;
237 double dfPIXEL_STEP;
238 double dfLINE_OFFSET;
239 double dfLINE_STEP;
240
241 bool bOriginIsTopLeftCorner;
242 bool bGeographicSRSWithMinus180Plus180LongRange;
243 CPLQuadTree *hQuadTree;
244
245 char **papszGeolocationInfo;
246
247} GDALGeoLocTransformInfo;
248
249/************************************************************************/
250/* Color table related */
251/************************************************************************/
252
253// Definitions exists for T = GUInt32 and T = GUIntBig.
254template <class T>
255int GDALComputeMedianCutPCTInternal(
257 GByte *pabyRedBand, GByte *pabyGreenBand, GByte *pabyBlueBand,
258 int (*pfnIncludePixel)(int, int, void *), int nColors, int nBits,
259 T *panHistogram, GDALColorTableH hColorTable, GDALProgressFunc pfnProgress,
260 void *pProgressArg);
261
262int GDALDitherRGB2PCTInternal(GDALRasterBandH hRed, GDALRasterBandH hGreen,
263 GDALRasterBandH hBlue, GDALRasterBandH hTarget,
264 GDALColorTableH hColorTable, int nBits,
265 GInt16 *pasDynamicColorMap, int bDither,
266 GDALProgressFunc pfnProgress, void *pProgressArg);
267
268#define PRIME_FOR_65536 98317
269
270// See HashHistogram structure in gdalmediancut.cpp and ColorIndex structure in
271// gdaldither.cpp 6 * sizeof(int) should be the size of the largest of both
272// structures.
273#define MEDIAN_CUT_AND_DITHER_BUFFER_SIZE_65536 \
274 (6 * sizeof(int) * PRIME_FOR_65536)
275
276/************************************************************************/
277/* Float comparison function. */
278/************************************************************************/
279
286#define MAX_ULPS 10
287
288GBool GDALFloatEquals(float A, float B);
289
290struct FloatEqualityTest
291{
292 bool operator()(float a, float b)
293 {
294 return GDALFloatEquals(a, b) == TRUE;
295 }
296};
297
298bool GDALComputeAreaOfInterest(OGRSpatialReference *poSRS, double adfGT[6],
299 int nXSize, int nYSize,
300 double &dfWestLongitudeDeg,
301 double &dfSouthLatitudeDeg,
302 double &dfEastLongitudeDeg,
303 double &dfNorthLatitudeDeg);
304
305bool GDALComputeAreaOfInterest(OGRSpatialReference *poSRS, double dfX1,
306 double dfY1, double dfX2, double dfY2,
307 double &dfWestLongitudeDeg,
308 double &dfSouthLatitudeDeg,
309 double &dfEastLongitudeDeg,
310 double &dfNorthLatitudeDeg);
311
312CPLStringList GDALCreateGeolocationMetadata(GDALDatasetH hBaseDS,
313 const char *pszGeolocationDataset,
314 bool bIsSource);
315
316void *GDALCreateGeoLocTransformerEx(GDALDatasetH hBaseDS,
317 CSLConstList papszGeolocationInfo,
318 int bReversed, const char *pszSourceDataset,
319 CSLConstList papszTransformOptions);
320
321#endif /* #ifndef DOXYGEN_SKIP */
322
323#endif /* ndef GDAL_ALG_PRIV_H_INCLUDED */
String list class designed around our use of C "char**" string lists.
Definition cpl_string.h:438
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition ogr_spatialref.h:167
short GInt16
Int16 type.
Definition cpl_port.h:201
#define CPL_C_END
Macro to end a block of C symbols.
Definition cpl_port.h:317
#define CPL_C_START
Macro to start a block of C symbols.
Definition cpl_port.h:313
int GBool
Type for boolean values (alias to int)
Definition cpl_port.h:214
#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:1049
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition cpl_port.h:1190
unsigned char GByte
Unsigned byte type.
Definition cpl_port.h:205
int GInt32
Int32 type.
Definition cpl_port.h:195
struct _CPLQuadTree CPLQuadTree
Opaque type for a quad tree.
Definition cpl_quad_tree.h:65
GIntBig GSpacing
Type to express pixel, line or band spacing.
Definition gdal.h:314
GDALDataType
Definition gdal.h:64
void * GDALDatasetH
Opaque type used for the C bindings of the C++ GDALDataset class.
Definition gdal.h:290
void * GDALRasterBandH
Opaque type used for the C bindings of the C++ GDALRasterBand class.
Definition gdal.h:293
void * GDALColorTableH
Opaque type used for the C bindings of the C++ GDALColorTable class.
Definition gdal.h:299
Public (C callable) GDAL algorithm entry points, and definitions.
int(* GDALTransformerFunc)(void *pTransformerArg, int bDstToSrc, int nPointCount, double *x, double *y, double *z, int *panSuccess)
Definition gdal_alg.h:95
Coordinate systems services.
Document node structure.
Definition cpl_minixml.h:70
Ground Control Point.
Definition gdal.h:959