29#include "gdalcachedpixelaccessor.h"
37class GDALGeoLocDatasetAccessors
39 typedef class GDALGeoLocDatasetAccessors AccessorType;
41 GDALGeoLocTransformInfo *m_psTransform;
47 GDALDataset *m_poBackmapWeightsTmpDataset =
nullptr;
49 GDALGeoLocDatasetAccessors(
const GDALGeoLocDatasetAccessors &) =
delete;
50 GDALGeoLocDatasetAccessors &
51 operator=(
const GDALGeoLocDatasetAccessors &) =
delete;
53 bool LoadGeoloc(
bool bIsRegularGrid);
56 static constexpr int TILE_SIZE = 1024;
64 explicit GDALGeoLocDatasetAccessors(GDALGeoLocTransformInfo *psTransform)
65 : m_psTransform(psTransform), geolocXAccessor(nullptr),
66 geolocYAccessor(nullptr), backMapXAccessor(nullptr),
67 backMapYAccessor(nullptr), backMapWeightAccessor(nullptr)
69 m_aosGTiffCreationOptions.SetNameValue(
"TILED",
"YES");
70 m_aosGTiffCreationOptions.SetNameValue(
"INTERLEAVE",
"BAND");
71 m_aosGTiffCreationOptions.SetNameValue(
"BLOCKXSIZE",
72 CPLSPrintf(
"%d", TILE_SIZE));
73 m_aosGTiffCreationOptions.SetNameValue(
"BLOCKYSIZE",
74 CPLSPrintf(
"%d", TILE_SIZE));
77 ~GDALGeoLocDatasetAccessors();
79 bool Load(
bool bIsRegularGrid,
bool bUseQuadtree);
81 bool AllocateBackMap();
84 void FlushBackmapCaches();
89 void FreeWghtsBackMap();
96GDALGeoLocDatasetAccessors::~GDALGeoLocDatasetAccessors()
105 delete m_poGeolocTmpDataset;
106 delete m_poBackmapTmpDataset;
113bool GDALGeoLocDatasetAccessors::AllocateBackMap()
116 if (poDriver ==
nullptr)
119 m_poBackmapTmpDataset = poDriver->Create(
121 m_psTransform->nBackMapWidth, m_psTransform->nBackMapHeight, 2,
123 if (m_poBackmapTmpDataset ==
nullptr)
132 backMapXAccessor.
SetBand(poBandX);
133 backMapYAccessor.
SetBand(poBandY);
135 m_poBackmapWeightsTmpDataset = poDriver->Create(
137 m_psTransform->nBackMapWidth, m_psTransform->nBackMapHeight, 1,
139 if (m_poBackmapWeightsTmpDataset ==
nullptr)
155void GDALGeoLocDatasetAccessors::FreeWghtsBackMap()
157 if (m_poBackmapWeightsTmpDataset)
160 delete m_poBackmapWeightsTmpDataset;
161 m_poBackmapWeightsTmpDataset =
nullptr;
169GDALDataset *GDALGeoLocDatasetAccessors::GetBackmapDataset()
174 poBandY->SetNoDataValue(INVALID_BMXY);
175 return m_poBackmapTmpDataset;
182void GDALGeoLocDatasetAccessors::FlushBackmapCaches()
192bool GDALGeoLocDatasetAccessors::Load(
bool bIsRegularGrid,
bool bUseQuadtree)
194 return LoadGeoloc(bIsRegularGrid) &&
195 ((bUseQuadtree && GDALGeoLocBuildQuadTree(m_psTransform)) ||
197 GDALGeoLoc<AccessorType>::GenerateBackMap(m_psTransform)));
204bool GDALGeoLocDatasetAccessors::LoadGeoloc(
bool bIsRegularGrid)
209 const int nXSize = m_psTransform->nGeoLocXSize;
210 const int nYSize = m_psTransform->nGeoLocYSize;
213 if (poDriver ==
nullptr)
216 m_poGeolocTmpDataset = poDriver->Create(
218 nYSize, 2,
GDT_Float64, m_aosGTiffCreationOptions.List());
219 if (m_poGeolocTmpDataset ==
nullptr)
237 if (padfTempX ==
nullptr || padfTempY ==
nullptr)
248 for (
int j = 0; j < nYSize; j++)
250 if (poXBand->RasterIO(
GF_Write, 0, j, nXSize, 1, padfTempX, nXSize,
263 for (
int i = 0; i < nXSize; i++)
265 if (poYBand->RasterIO(
GF_Write, i, 0, 1, nYSize, padfTempY, 1,
281 geolocXAccessor.
SetBand(poXBand);
282 geolocYAccessor.
SetBand(poYBand);
292 return GDALGeoLoc<GDALGeoLocDatasetAccessors>::LoadGeolocFinish(
String list class designed around our use of C "char**" string lists.
Definition cpl_string.h:438
Class to have reasonably fast random pixel access to a raster band, when accessing multiple pixels th...
Definition gdalcachedpixelaccessor.h:53
bool FlushCache()
Flush content of modified tiles and drop caches.
Definition gdalcachedpixelaccessor.h:281
void SetBand(GDALRasterBand *poBand)
Assign the raster band if not known at construction time.
Definition gdalcachedpixelaccessor.h:84
void ResetModifiedFlag()
Reset the modified flag for cached tiles.
Definition gdalcachedpixelaccessor.h:302
A set of associated raster bands, usually from one file.
Definition gdal_priv.h:348
void MarkSuppressOnClose()
Set that the dataset must be deleted on close.
Definition gdaldataset.cpp:1449
GDALRasterBand * GetRasterBand(int)
Fetch a band object for a dataset.
Definition gdaldataset.cpp:779
static GDALDriver * FromHandle(GDALDriverH hDriver)
Convert a GDALDriverH to a GDALDriver*.
Definition gdal_priv.h:1764
virtual const char * GetDescription() const
Fetch object description.
Definition gdalmajorobject.cpp:77
virtual CPLErr SetNoDataValue(double dfNoData)
Set the no data value for this band.
Definition gdalrasterband.cpp:1877
static GDALRasterBand * FromHandle(GDALRasterBandH hBand)
Convert a GDALRasterBandH to a GDALRasterBand*.
Definition gdal_priv.h:1472
#define CPLFree
Alias of VSIFree()
Definition cpl_conv.h:86
const char * CPLGenerateTempFilename(const char *pszStem)
Generate temporary file name.
Definition cpl_path.cpp:1109
const char * CPLResetExtension(const char *, const char *)
Replace the extension with the provided one.
Definition cpl_path.cpp:442
CPLErr
Error category.
Definition cpl_error.h:53
int VSIUnlink(const char *pszFilename)
Delete a file.
Definition cpl_vsil.cpp:416
#define VSI_MALLOC2_VERBOSE(nSize1, nSize2)
VSI_MALLOC2_VERBOSE.
Definition cpl_vsi.h:347
@ GDT_Float64
Definition gdal.h:74
@ GDT_Float32
Definition gdal.h:73
@ GF_Write
Definition gdal.h:133
@ GF_Read
Definition gdal.h:132
GDALDriverH GDALGetDriverByName(const char *)
Fetch a driver based on the short name.
Definition gdaldrivermanager.cpp:622
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:403