29 #include "gdalcachedpixelaccessor.h"
37 class 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",
73 m_aosGTiffCreationOptions.SetNameValue(
"BLOCKYSIZE",
77 ~GDALGeoLocDatasetAccessors();
79 bool Load(
bool bIsRegularGrid,
bool bUseQuadtree);
81 bool AllocateBackMap();
84 void FlushBackmapCaches();
90 void FreeWghtsBackMap();
97 GDALGeoLocDatasetAccessors::~GDALGeoLocDatasetAccessors()
106 delete m_poGeolocTmpDataset;
107 delete m_poBackmapTmpDataset;
114 bool GDALGeoLocDatasetAccessors::AllocateBackMap()
117 if (poDriver ==
nullptr)
120 m_poBackmapTmpDataset = poDriver->Create(
122 m_psTransform->nBackMapWidth, m_psTransform->nBackMapHeight, 2,
124 if (m_poBackmapTmpDataset ==
nullptr)
133 backMapXAccessor.
SetBand(poBandX);
134 backMapYAccessor.
SetBand(poBandY);
136 m_poBackmapWeightsTmpDataset = poDriver->Create(
138 m_psTransform->nBackMapWidth, m_psTransform->nBackMapHeight, 1,
140 if (m_poBackmapWeightsTmpDataset ==
nullptr)
156 void GDALGeoLocDatasetAccessors::FreeWghtsBackMap()
158 if (m_poBackmapWeightsTmpDataset)
161 delete m_poBackmapWeightsTmpDataset;
162 m_poBackmapWeightsTmpDataset =
nullptr;
170 GDALDataset *GDALGeoLocDatasetAccessors::GetBackmapDataset()
175 poBandY->SetNoDataValue(INVALID_BMXY);
176 return m_poBackmapTmpDataset;
183 void GDALGeoLocDatasetAccessors::FlushBackmapCaches()
193 bool GDALGeoLocDatasetAccessors::Load(
bool bIsRegularGrid,
bool bUseQuadtree)
195 return LoadGeoloc(bIsRegularGrid) &&
196 ((bUseQuadtree && GDALGeoLocBuildQuadTree(m_psTransform)) ||
198 GDALGeoLoc<AccessorType>::GenerateBackMap(m_psTransform)));
205 bool GDALGeoLocDatasetAccessors::LoadGeoloc(
bool bIsRegularGrid)
210 const int nXSize = m_psTransform->nGeoLocXSize;
211 const int nYSize = m_psTransform->nGeoLocYSize;
214 if (poDriver ==
nullptr)
217 m_poGeolocTmpDataset = poDriver->Create(
219 nYSize, 2,
GDT_Float64, m_aosGTiffCreationOptions.List());
220 if (m_poGeolocTmpDataset ==
nullptr)
238 if (padfTempX ==
nullptr || padfTempY ==
nullptr)
249 for (
int j = 0; j < nYSize; j++)
251 if (poXBand->RasterIO(
GF_Write, 0, j, nXSize, 1, padfTempX, nXSize,
264 for (
int i = 0; i < nXSize; i++)
266 if (poYBand->RasterIO(
GF_Write, i, 0, 1, nYSize, padfTempY, 1,
282 geolocXAccessor.
SetBand(poXBand);
283 geolocYAccessor.
SetBand(poYBand);
293 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:503
void MarkSuppressOnClose()
Set that the dataset must be deleted on close.
Definition: gdaldataset.cpp:1726
GDALRasterBand * GetRasterBand(int)
Fetch a band object for a dataset.
Definition: gdaldataset.cpp:1016
static GDALDriver * FromHandle(GDALDriverH hDriver)
Convert a GDALDriverH to a GDALDriver*.
Definition: gdal_priv.h:2225
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:1996
static GDALRasterBand * FromHandle(GDALRasterBandH hBand)
Convert a GDALRasterBandH to a GDALRasterBand*.
Definition: gdal_priv.h:1816
#define CPLFree
Alias of VSIFree()
Definition: cpl_conv.h:98
const char * CPLResetExtension(const char *, const char *)
Replace the extension with the provided one.
Definition: cpl_path.cpp:436
const char * CPLGenerateTempFilename(const char *pszStem)
Generate temporary file name.
Definition: cpl_path.cpp:1056
CPLErr
Error category.
Definition: cpl_error.h:53
const char * CPLSPrintf(const char *fmt,...)
CPLSPrintf() that works with 10 static buffer.
Definition: cpl_string.cpp:982
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:355
@ 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:449