GDAL
gdal_alg_priv.h
1 /******************************************************************************
2  * $Id: gdal_alg_priv.h f0602c2d27b51faf8f846e4601b018865a902e83 2021-07-05 20:28:39 +0200 Even Rouault $
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 "gdal_alg.h"
38 #include "ogr_spatialref.h"
39 
41 
43 typedef enum { GBV_UserBurnValue = 0, GBV_Z = 1, GBV_M = 2
47 } GDALBurnValueSrc;
48 
49 typedef enum {
50  GRMA_Replace = 0,
51  GRMA_Add = 1,
52 } GDALRasterMergeAlg;
53 
54 typedef struct {
55  unsigned char * pabyChunkBuf;
56  int nXSize;
57  int nYSize;
58  int nBands;
59  GDALDataType eType;
60  int nPixelSpace;
61  GSpacing nLineSpace;
62  GSpacing nBandSpace;
63  const double *padfBurnValue;
64  GDALBurnValueSrc eBurnValueSource;
65  GDALRasterMergeAlg eMergeAlg;
66 } GDALRasterizeInfo;
67 
68 typedef enum {
69  GRO_Raster = 0,
70  GRO_Vector = 1,
71  GRO_Auto = 2,
72 } GDALRasterizeOptim;
73 
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,
83  int nPartCount, const int *panPartSize,
84  const double *padfX, const double *padfY,
85  const double *padfVariant,
86  llPointFunc pfnPointFunc, void *pCBData );
87 
88 void GDALdllImageLine( int nRasterXSize, int nRasterYSize,
89  int nPartCount, const int *panPartSize,
90  const double *padfX, const double *padfY,
91  const double *padfVariant,
92  llPointFunc pfnPointFunc, void *pCBData );
93 
94 void GDALdllImageLineAllTouched( int nRasterXSize, int nRasterYSize,
95  int nPartCount, const int *panPartSize,
96  const double *padfX, const double *padfY,
97  const double *padfVariant,
98  llPointFunc pfnPointFunc, void *pCBData,
99  int bAvoidBurningSamePoints );
100 
101 void GDALdllImageFilledPolygon( int nRasterXSize, int nRasterYSize,
102  int nPartCount, const int *panPartSize,
103  const double *padfX, const double *padfY,
104  const double *padfVariant,
105  llScanlineFunc pfnScanlineFunc, void *pCBData );
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 
126  GInt32 *panPolyIdMap = nullptr;
127  DataType *panPolyValue = nullptr;
128 
129  int nNextPolygonId = 0;
130  int nPolyAlloc = 0;
131 
132  int nConnectedness = 0;
133 
134 public:
135  explicit GDALRasterPolygonEnumeratorT( int nConnectedness=4 );
136  ~GDALRasterPolygonEnumeratorT();
137 
138  void ProcessLine( DataType *panLastLineVal, DataType *panThisLineVal,
139  GInt32 *panLastLineId, GInt32 *panThisLineId,
140  int nXSize );
141 
142  void CompleteMerges();
143 
144  void Clear();
145 };
146 
147 struct IntEqualityTest
148 {
149  bool operator()(GInt32 a, GInt32 b) const { return a == b; }
150 };
151 
152 typedef GDALRasterPolygonEnumeratorT<GInt32, IntEqualityTest> GDALRasterPolygonEnumerator;
153 
154 typedef void* (*GDALTransformDeserializeFunc)( CPLXMLNode *psTree );
155 
156 void CPL_DLL *GDALRegisterTransformDeserializer(const char* pszTransformName,
157  GDALTransformerFunc pfnTransformerFunc,
158  GDALTransformDeserializeFunc pfnDeserializeFunc);
159 void CPL_DLL GDALUnregisterTransformDeserializer(void* pData);
160 
161 void GDALCleanupTransformDeserializerMutex();
162 
163 /* Transformer cloning */
164 
165 void* GDALCreateTPSTransformerInt( int nGCPCount, const GDAL_GCP *pasGCPList,
166  int bReversed, char** papszOptions );
167 
168 void CPL_DLL * GDALCloneTransformer( void *pTransformerArg );
169 
170 void GDALRefreshGenImgProjTransformer(void* hTransformArg);
171 void GDALRefreshApproxTransformer(void* hTransformArg);
172 
173 int GDALTransformLonLatToDestGenImgProjTransformer(void* hTransformArg,
174  double* pdfX,
175  double* pdfY);
176 int GDALTransformLonLatToDestApproxTransformer(void* hTransformArg,
177  double* pdfX,
178  double* pdfY);
179 
180 typedef struct {
181  GDALTransformerInfo sTI;
182 
183  bool bReversed;
184 
185  // Map from target georef coordinates back to geolocation array
186  // pixel line coordinates. Built only if needed.
187  size_t nBackMapWidth;
188  size_t nBackMapHeight;
189  double adfBackMapGeoTransform[6]; // Maps georef to pixel/line.
190  float *pafBackMapX;
191  float *pafBackMapY;
192 
193  // Geolocation bands.
194  GDALDatasetH hDS_X;
195  GDALRasterBandH hBand_X;
196  GDALDatasetH hDS_Y;
197  GDALRasterBandH hBand_Y;
198  int bSwapXY;
199 
200  // Located geolocation data.
201  size_t nGeoLocXSize;
202  size_t nGeoLocYSize;
203  double *padfGeoLocX;
204  double *padfGeoLocY;
205  double dfMinX;
206  double dfYAtMinX;
207  double dfMinY;
208  double dfXAtMinY;
209  double dfMaxX;
210  double dfYAtMaxX;
211  double dfMaxY;
212  double dfXAtMaxY;
213 
214  int bHasNoData;
215  double dfNoDataX;
216 
217  // Geolocation <-> base image mapping.
218  double dfPIXEL_OFFSET;
219  double dfPIXEL_STEP;
220  double dfLINE_OFFSET;
221  double dfLINE_STEP;
222 
223  char ** papszGeolocationInfo;
224 
225 } GDALGeoLocTransformInfo;
226 
227 
228 /************************************************************************/
229 /* Color table related */
230 /************************************************************************/
231 
232 // Definitions exists for T = GUInt32 and T = GUIntBig.
233 template<class T> int
234 GDALComputeMedianCutPCTInternal( GDALRasterBandH hRed,
235  GDALRasterBandH hGreen,
236  GDALRasterBandH hBlue,
237  GByte* pabyRedBand,
238  GByte* pabyGreenBand,
239  GByte* pabyBlueBand,
240  int (*pfnIncludePixel)(int,int,void*),
241  int nColors,
242  int nBits,
243  T* panHistogram,
244  GDALColorTableH hColorTable,
245  GDALProgressFunc pfnProgress,
246  void * pProgressArg );
247 
248 int GDALDitherRGB2PCTInternal( GDALRasterBandH hRed,
249  GDALRasterBandH hGreen,
250  GDALRasterBandH hBlue,
251  GDALRasterBandH hTarget,
252  GDALColorTableH hColorTable,
253  int nBits,
254  GInt16* pasDynamicColorMap,
255  int bDither,
256  GDALProgressFunc pfnProgress,
257  void * pProgressArg );
258 
259 #define PRIME_FOR_65536 98317
260 
261 // See HashHistogram structure in gdalmediancut.cpp and ColorIndex structure in
262 // gdaldither.cpp 6 * sizeof(int) should be the size of the largest of both
263 // structures.
264 #define MEDIAN_CUT_AND_DITHER_BUFFER_SIZE_65536 (6 * sizeof(int) * PRIME_FOR_65536)
265 
266 /************************************************************************/
267 /* Float comparison function. */
268 /************************************************************************/
269 
276 #define MAX_ULPS 10
277 
278 GBool GDALFloatEquals(float A, float B);
279 
280 struct FloatEqualityTest
281 {
282  bool operator()(float a, float b) { return GDALFloatEquals(a,b) == TRUE; }
283 };
284 
285 bool GDALComputeAreaOfInterest(OGRSpatialReference* poSRS,
286  double adfGT[6],
287  int nXSize,
288  int nYSize,
289  double& dfWestLongitudeDeg,
290  double& dfSouthLatitudeDeg,
291  double& dfEastLongitudeDeg,
292  double& dfNorthLatitudeDeg );
293 
294 bool GDALComputeAreaOfInterest(OGRSpatialReference* poSRS,
295  double dfX1,
296  double dfY1,
297  double dfX2,
298  double dfY2,
299  double& dfWestLongitudeDeg,
300  double& dfSouthLatitudeDeg,
301  double& dfEastLongitudeDeg,
302  double& dfNorthLatitudeDeg );
303 
304 
305 #endif /* #ifndef DOXYGEN_SKIP */
306 
307 #endif /* ndef GDAL_ALG_PRIV_H_INCLUDED */
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition: ogr_spatialref.h:158
short GInt16
Int16 type.
Definition: cpl_port.h:211
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:331
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:329
int GBool
Type for boolean values (alias to int)
Definition: cpl_port.h:223
#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:955
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:215
int GInt32
Int32 type.
Definition: cpl_port.h:205
GIntBig GSpacing
Type to express pixel, line or band spacing.
Definition: gdal.h:286
GDALDataType
Definition: gdal.h:62
void * GDALDatasetH
Opaque type used for the C bindings of the C++ GDALDataset class.
Definition: gdal.h:268
void * GDALRasterBandH
Opaque type used for the C bindings of the C++ GDALRasterBand class.
Definition: gdal.h:271
void * GDALColorTableH
Opaque type used for the C bindings of the C++ GDALColorTable class.
Definition: gdal.h:277
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:114
Coordinate systems services.
Document node structure.
Definition: cpl_minixml.h:70
Ground Control Point.
Definition: gdal.h:711