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