13#include "gdalcachedpixelaccessor.h"
21class GDALGeoLocDatasetAccessors
23 typedef class GDALGeoLocDatasetAccessors AccessorType;
25 GDALGeoLocTransformInfo *m_psTransform;
31 GDALDataset *m_poBackmapWeightsTmpDataset =
nullptr;
33 GDALGeoLocDatasetAccessors(
const GDALGeoLocDatasetAccessors &) =
delete;
34 GDALGeoLocDatasetAccessors &
35 operator=(
const GDALGeoLocDatasetAccessors &) =
delete;
37 bool LoadGeoloc(
bool bIsRegularGrid);
40 static constexpr int TILE_SIZE = 256;
41 static constexpr int TILE_COUNT = 64;
49 explicit GDALGeoLocDatasetAccessors(GDALGeoLocTransformInfo *psTransform)
50 : m_psTransform(psTransform), geolocXAccessor(nullptr),
51 geolocYAccessor(nullptr), backMapXAccessor(nullptr),
52 backMapYAccessor(nullptr), backMapWeightAccessor(nullptr)
54 m_aosGTiffCreationOptions.SetNameValue(
"TILED",
"YES");
55 m_aosGTiffCreationOptions.SetNameValue(
"INTERLEAVE",
"BAND");
56 m_aosGTiffCreationOptions.SetNameValue(
"BLOCKXSIZE",
58 m_aosGTiffCreationOptions.SetNameValue(
"BLOCKYSIZE",
62 ~GDALGeoLocDatasetAccessors();
64 bool Load(
bool bIsRegularGrid,
bool bUseQuadtree);
66 bool AllocateBackMap();
69 void FlushBackmapCaches();
75 void FreeWghtsBackMap();
82GDALGeoLocDatasetAccessors::~GDALGeoLocDatasetAccessors()
91 delete m_poGeolocTmpDataset;
92 delete m_poBackmapTmpDataset;
99bool GDALGeoLocDatasetAccessors::AllocateBackMap()
102 if (poDriver ==
nullptr)
107 const std::string osBackmapTmpFilename =
109 m_poBackmapTmpDataset = poDriver->Create(
110 osBackmapTmpFilename.c_str(), m_psTransform->nBackMapWidth,
112 m_aosGTiffCreationOptions.List());
113 if (m_poBackmapTmpDataset ==
nullptr)
122 backMapXAccessor.
SetBand(poBandX);
123 backMapYAccessor.
SetBand(poBandY);
127 const std::string osBackmapWeightsTmpFilename =
129 m_poBackmapWeightsTmpDataset = poDriver->Create(
130 osBackmapWeightsTmpFilename.c_str(), m_psTransform->nBackMapWidth,
132 m_aosGTiffCreationOptions.List());
133 if (m_poBackmapWeightsTmpDataset ==
nullptr)
149void GDALGeoLocDatasetAccessors::FreeWghtsBackMap()
151 if (m_poBackmapWeightsTmpDataset)
154 delete m_poBackmapWeightsTmpDataset;
155 m_poBackmapWeightsTmpDataset =
nullptr;
163GDALDataset *GDALGeoLocDatasetAccessors::GetBackmapDataset()
168 poBandY->SetNoDataValue(INVALID_BMXY);
169 return m_poBackmapTmpDataset;
176void GDALGeoLocDatasetAccessors::FlushBackmapCaches()
186bool GDALGeoLocDatasetAccessors::Load(
bool bIsRegularGrid,
bool bUseQuadtree)
188 return LoadGeoloc(bIsRegularGrid) &&
189 ((bUseQuadtree && GDALGeoLocBuildQuadTree(m_psTransform)) ||
191 GDALGeoLoc<AccessorType>::GenerateBackMap(m_psTransform)));
198bool GDALGeoLocDatasetAccessors::LoadGeoloc(
bool bIsRegularGrid)
203 const int nXSize = m_psTransform->nGeoLocXSize;
204 const int nYSize = m_psTransform->nGeoLocYSize;
207 if (poDriver ==
nullptr)
212 const std::string osGeolocTmpFilename =
214 m_poGeolocTmpDataset =
215 poDriver->Create(osGeolocTmpFilename.c_str(), nXSize, nYSize, 2,
217 if (m_poGeolocTmpDataset ==
nullptr)
235 if (padfTempX ==
nullptr || padfTempY ==
nullptr)
246 for (
int j = 0; j < nYSize; j++)
248 if (poXBand->RasterIO(
GF_Write, 0, j, nXSize, 1, padfTempX, nXSize,
261 for (
int i = 0; i < nXSize; i++)
263 if (poYBand->RasterIO(
GF_Write, i, 0, 1, nYSize, padfTempY, 1,
279 geolocXAccessor.
SetBand(poXBand);
280 geolocYAccessor.
SetBand(poYBand);
290 GDALGeoLoc<GDALGeoLocDatasetAccessors>::LoadGeolocFinish(m_psTransform);
String list class designed around our use of C "char**" string lists.
Definition: cpl_string.h:436
Class to have reasonably fast random pixel access to a raster band, when accessing multiple pixels th...
Definition: gdalcachedpixelaccessor.h:37
bool FlushCache()
Flush content of modified tiles and drop caches.
Definition: gdalcachedpixelaccessor.h:265
void SetBand(GDALRasterBand *poBand)
Assign the raster band if not known at construction time.
Definition: gdalcachedpixelaccessor.h:68
void ResetModifiedFlag()
Reset the modified flag for cached tiles.
Definition: gdalcachedpixelaccessor.h:286
A set of associated raster bands, usually from one file.
Definition: gdal_priv.h:495
void MarkSuppressOnClose()
Set that the dataset must be deleted on close.
Definition: gdaldataset.cpp:1727
GDALRasterBand * GetRasterBand(int)
Fetch a band object for a dataset.
Definition: gdaldataset.cpp:1012
static GDALDriver * FromHandle(GDALDriverH hDriver)
Convert a GDALDriverH to a GDALDriver*.
Definition: gdal_priv.h:2348
virtual const char * GetDescription() const
Fetch object description.
Definition: gdalmajorobject.cpp:61
virtual CPLErr SetNoDataValue(double dfNoData)
Set the no data value for this band.
Definition: gdalrasterband.cpp:2500
static GDALRasterBand * FromHandle(GDALRasterBandH hBand)
Convert a GDALRasterBandH to a GDALRasterBand*.
Definition: gdal_priv.h:1890
#define CPLFree
Alias of VSIFree()
Definition: cpl_conv.h:82
const char * CPLGenerateTempFilename(const char *pszStem)
Generate temporary file name.
Definition: cpl_path.cpp:1094
const char * CPLResetExtension(const char *, const char *)
Replace the extension with the provided one.
Definition: cpl_path.cpp:450
CPLErr
Error category.
Definition: cpl_error.h:37
const char * CPLSPrintf(const char *fmt,...)
CPLSPrintf() that works with 10 static buffer.
Definition: cpl_string.cpp:967
int VSIUnlink(const char *pszFilename)
Delete a file.
Definition: cpl_vsil.cpp:434
#define VSI_MALLOC2_VERBOSE(nSize1, nSize2)
VSI_MALLOC2_VERBOSE.
Definition: cpl_vsi.h:339
@ GDT_Float64
Definition: gdal.h:59
@ GDT_Float32
Definition: gdal.h:58
@ GF_Write
Definition: gdal.h:119
@ GF_Read
Definition: gdal.h:118
GDALDriverH GDALGetDriverByName(const char *)
Fetch a driver based on the short name.
Definition: gdaldrivermanager.cpp:696
CPLErr GDALRasterIO(GDALRasterBandH hRBand, GDALRWFlag eRWFlag, int nDSXOff, int nDSYOff, int nDSXSize, int nDSYSize, void *pBuffer, int nBXSize, int nBYSize, GDALDataType eBDataType, int nPixelSpace, int nLineSpace)
Read/write a region of image data for this band.
Definition: gdalrasterband.cpp:457