GDAL
gdal_alg_priv.h
1 /******************************************************************************
2  * $Id: gdal_alg_priv.h db9ea60631eda5ef881ae75dc3355f42734fb38c 2022-02-22 16:16:41 +0100 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 bool GDALTransformIsTranslationOnPixelBoundaries(GDALTransformerFunc pfnTransformer,
181  void *pTransformerArg);
182 
183 typedef struct {
184  GDALTransformerInfo sTI;
185 
186  bool bReversed;
187 
188  // Map from target georef coordinates back to geolocation array
189  // pixel line coordinates. Built only if needed.
190  size_t nBackMapWidth;
191  size_t nBackMapHeight;
192  double adfBackMapGeoTransform[6]; // Maps georef to pixel/line.
193  float *pafBackMapX;
194  float *pafBackMapY;
195 
196  // Geolocation bands.
197  GDALDatasetH hDS_X;
198  GDALRasterBandH hBand_X;
199  GDALDatasetH hDS_Y;
200  GDALRasterBandH hBand_Y;
201  int bSwapXY;
202 
203  // Located geolocation data.
204  size_t nGeoLocXSize;
205  size_t nGeoLocYSize;
206  double *padfGeoLocX;
207  double *padfGeoLocY;
208  double dfMinX;
209  double dfYAtMinX;
210  double dfMinY;
211  double dfXAtMinY;
212  double dfMaxX;
213  double dfYAtMaxX;
214  double dfMaxY;
215  double dfXAtMaxY;
216 
217  int bHasNoData;
218  double dfNoDataX;
219 
220  // Geolocation <-> base image mapping.
221  double dfPIXEL_OFFSET;
222  double dfPIXEL_STEP;
223  double dfLINE_OFFSET;
224  double dfLINE_STEP;
225 
226  char ** papszGeolocationInfo;
227 
228 } GDALGeoLocTransformInfo;
229 
230 
231 /************************************************************************/
232 /* Color table related */
233 /************************************************************************/
234 
235 // Definitions exists for T = GUInt32 and T = GUIntBig.
236 template<class T> int
237 GDALComputeMedianCutPCTInternal( GDALRasterBandH hRed,
238  GDALRasterBandH hGreen,
239  GDALRasterBandH hBlue,
240  GByte* pabyRedBand,
241  GByte* pabyGreenBand,
242  GByte* pabyBlueBand,
243  int (*pfnIncludePixel)(int,int,void*),
244  int nColors,
245  int nBits,
246  T* panHistogram,
247  GDALColorTableH hColorTable,
248  GDALProgressFunc pfnProgress,
249  void * pProgressArg );
250 
251 int GDALDitherRGB2PCTInternal( GDALRasterBandH hRed,
252  GDALRasterBandH hGreen,
253  GDALRasterBandH hBlue,
254  GDALRasterBandH hTarget,
255  GDALColorTableH hColorTable,
256  int nBits,
257  GInt16* pasDynamicColorMap,
258  int bDither,
259  GDALProgressFunc pfnProgress,
260  void * pProgressArg );
261 
262 #define PRIME_FOR_65536 98317
263 
264 // See HashHistogram structure in gdalmediancut.cpp and ColorIndex structure in
265 // gdaldither.cpp 6 * sizeof(int) should be the size of the largest of both
266 // structures.
267 #define MEDIAN_CUT_AND_DITHER_BUFFER_SIZE_65536 (6 * sizeof(int) * PRIME_FOR_65536)
268 
269 /************************************************************************/
270 /* Float comparison function. */
271 /************************************************************************/
272 
279 #define MAX_ULPS 10
280 
281 GBool GDALFloatEquals(float A, float B);
282 
283 struct FloatEqualityTest
284 {
285  bool operator()(float a, float b) { return GDALFloatEquals(a,b) == TRUE; }
286 };
287 
288 bool GDALComputeAreaOfInterest(OGRSpatialReference* poSRS,
289  double adfGT[6],
290  int nXSize,
291  int nYSize,
292  double& dfWestLongitudeDeg,
293  double& dfSouthLatitudeDeg,
294  double& dfEastLongitudeDeg,
295  double& dfNorthLatitudeDeg );
296 
297 bool GDALComputeAreaOfInterest(OGRSpatialReference* poSRS,
298  double dfX1,
299  double dfY1,
300  double dfX2,
301  double dfY2,
302  double& dfWestLongitudeDeg,
303  double& dfSouthLatitudeDeg,
304  double& dfEastLongitudeDeg,
305  double& dfNorthLatitudeDeg );
306 
307 
308 #endif /* #ifndef DOXYGEN_SKIP */
309 
310 #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