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 = 256;
57 static constexpr int TILE_COUNT = 64;
65 explicit GDALGeoLocDatasetAccessors(GDALGeoLocTransformInfo *psTransform)
66 : m_psTransform(psTransform), geolocXAccessor(nullptr),
67 geolocYAccessor(nullptr), backMapXAccessor(nullptr),
68 backMapYAccessor(nullptr), backMapWeightAccessor(nullptr)
70 m_aosGTiffCreationOptions.SetNameValue(
"TILED",
"YES");
71 m_aosGTiffCreationOptions.SetNameValue(
"INTERLEAVE",
"BAND");
72 m_aosGTiffCreationOptions.SetNameValue(
"BLOCKXSIZE",
73 CPLSPrintf(
"%d", TILE_SIZE));
74 m_aosGTiffCreationOptions.SetNameValue(
"BLOCKYSIZE",
75 CPLSPrintf(
"%d", TILE_SIZE));
78 ~GDALGeoLocDatasetAccessors();
80 bool Load(
bool bIsRegularGrid,
bool bUseQuadtree);
82 bool AllocateBackMap();
85 void FlushBackmapCaches();
91 void FreeWghtsBackMap();
98GDALGeoLocDatasetAccessors::~GDALGeoLocDatasetAccessors()
107 delete m_poGeolocTmpDataset;
108 delete m_poBackmapTmpDataset;
115bool GDALGeoLocDatasetAccessors::AllocateBackMap()
118 if (poDriver ==
nullptr)
123 const std::string osBackmapTmpFilename =
125 m_poBackmapTmpDataset = poDriver->Create(
126 osBackmapTmpFilename.c_str(), m_psTransform->nBackMapWidth,
128 m_aosGTiffCreationOptions.List());
129 if (m_poBackmapTmpDataset ==
nullptr)
138 backMapXAccessor.
SetBand(poBandX);
139 backMapYAccessor.
SetBand(poBandY);
143 const std::string osBackmapWeightsTmpFilename =
145 m_poBackmapWeightsTmpDataset = poDriver->Create(
146 osBackmapWeightsTmpFilename.c_str(), m_psTransform->nBackMapWidth,
148 m_aosGTiffCreationOptions.List());
149 if (m_poBackmapWeightsTmpDataset ==
nullptr)
165void GDALGeoLocDatasetAccessors::FreeWghtsBackMap()
167 if (m_poBackmapWeightsTmpDataset)
170 delete m_poBackmapWeightsTmpDataset;
171 m_poBackmapWeightsTmpDataset =
nullptr;
179GDALDataset *GDALGeoLocDatasetAccessors::GetBackmapDataset()
184 poBandY->SetNoDataValue(INVALID_BMXY);
185 return m_poBackmapTmpDataset;
192void GDALGeoLocDatasetAccessors::FlushBackmapCaches()
202bool GDALGeoLocDatasetAccessors::Load(
bool bIsRegularGrid,
bool bUseQuadtree)
204 return LoadGeoloc(bIsRegularGrid) &&
205 ((bUseQuadtree && GDALGeoLocBuildQuadTree(m_psTransform)) ||
207 GDALGeoLoc<AccessorType>::GenerateBackMap(m_psTransform)));
214bool GDALGeoLocDatasetAccessors::LoadGeoloc(
bool bIsRegularGrid)
219 const int nXSize = m_psTransform->nGeoLocXSize;
220 const int nYSize = m_psTransform->nGeoLocYSize;
223 if (poDriver ==
nullptr)
228 const std::string osGeolocTmpFilename =
230 m_poGeolocTmpDataset =
231 poDriver->Create(osGeolocTmpFilename.c_str(), nXSize, nYSize, 2,
233 if (m_poGeolocTmpDataset ==
nullptr)
251 if (padfTempX ==
nullptr || padfTempY ==
nullptr)
262 for (
int j = 0; j < nYSize; j++)
264 if (poXBand->RasterIO(
GF_Write, 0, j, nXSize, 1, padfTempX, nXSize,
277 for (
int i = 0; i < nXSize; i++)
279 if (poYBand->RasterIO(
GF_Write, i, 0, 1, nYSize, padfTempY, 1,
295 geolocXAccessor.
SetBand(poXBand);
296 geolocYAccessor.
SetBand(poYBand);
306 GDALGeoLoc<GDALGeoLocDatasetAccessors>::LoadGeolocFinish(m_psTransform);
String list class designed around our use of C "char**" string lists.
Definition cpl_string.h:449
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:490
void MarkSuppressOnClose()
Set that the dataset must be deleted on close.
Definition gdaldataset.cpp:1723
GDALRasterBand * GetRasterBand(int)
Fetch a band object for a dataset.
Definition gdaldataset.cpp:1013
static GDALDriver * FromHandle(GDALDriverH hDriver)
Convert a GDALDriverH to a GDALDriver*.
Definition gdal_priv.h:2173
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:1995
static GDALRasterBand * FromHandle(GDALRasterBandH hBand)
Convert a GDALRasterBandH to a GDALRasterBand*.
Definition gdal_priv.h:1764
#define CPLFree
Alias of VSIFree()
Definition cpl_conv.h:98
const char * CPLGenerateTempFilename(const char *pszStem)
Generate temporary file name.
Definition cpl_path.cpp:1110
const char * CPLResetExtension(const char *, const char *)
Replace the extension with the provided one.
Definition cpl_path.cpp:466
CPLErr
Error category.
Definition cpl_error.h:53
int VSIUnlink(const char *pszFilename)
Delete a file.
Definition cpl_vsil.cpp:450
#define VSI_MALLOC2_VERBOSE(nSize1, nSize2)
VSI_MALLOC2_VERBOSE.
Definition cpl_vsi.h:353
@ GDT_Float64
Definition gdal.h:75
@ GDT_Float32
Definition gdal.h:74
@ GF_Write
Definition gdal.h:134
@ GF_Read
Definition gdal.h:133
GDALDriverH GDALGetDriverByName(const char *)
Fetch a driver based on the short name.
Definition gdaldrivermanager.cpp:691
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:448