GDAL
Classes | Public Member Functions | List of all members
GDALCachedPixelAccessor< Type, TILE_SIZE, CACHED_TILE_COUNT > Class Template Reference

Class to have reasonably fast random pixel access to a raster band, when accessing multiple pixels that are close to each other. More...

#include <gdalcachedpixelaccessor.h>

Public Member Functions

 GDALCachedPixelAccessor (GDALRasterBand *poBand)
 Constructor. More...
 
 ~GDALCachedPixelAccessor ()
 Destructor. More...
 
void SetBand (GDALRasterBand *poBand)
 Assign the raster band if not known at construction time.
 
Type Get (int nX, int nY, bool *pbSuccess=nullptr)
 Get the value of a pixel. More...
 
bool Set (int nX, int nY, Type val)
 Set the value of a pixel. More...
 
bool FlushCache ()
 Flush content of modified tiles and drop caches. More...
 
void ResetModifiedFlag ()
 Reset the modified flag for cached tiles.
 

Detailed Description

template<class Type, int TILE_SIZE, int CACHED_TILE_COUNT = 4>
class GDALCachedPixelAccessor< Type, TILE_SIZE, CACHED_TILE_COUNT >

Class to have reasonably fast random pixel access to a raster band, when accessing multiple pixels that are close to each other.

This gives faster access than using GDALRasterBand::RasterIO() with a 1x1 window.

Since
GDAL 3.5

Constructor & Destructor Documentation

◆ GDALCachedPixelAccessor()

template<class Type , int TILE_SIZE, int CACHED_TILE_COUNT>
GDALCachedPixelAccessor< Type, TILE_SIZE, CACHED_TILE_COUNT >::GDALCachedPixelAccessor ( GDALRasterBand poBand)
explicit

Constructor.

The template accepts the following parameters:

  • Type: should be one of GByte, GUInt16, GInt16, GUInt32, GInt32, GUInt64, GInt64, float or double
  • TILE_SIZE: the tile size for the cache of GDALCachedPixelAccessor. Use a power of two for faster computation. It doesn't need to be the same of the underlying raster
  • CACHED_TILE_COUNT: number of tiles to cache. Should be >= 1. Defaults to 4.
Parameters
poBandRaster band.

◆ ~GDALCachedPixelAccessor()

template<class Type , int TILE_SIZE, int CACHED_TILE_COUNT>
GDALCachedPixelAccessor< Type, TILE_SIZE, CACHED_TILE_COUNT >::~GDALCachedPixelAccessor

Destructor.

Will call FlushCache()

Member Function Documentation

◆ FlushCache()

template<class Type , int TILE_SIZE, int CACHED_TILE_COUNT>
bool GDALCachedPixelAccessor< Type, TILE_SIZE, CACHED_TILE_COUNT >::FlushCache

Flush content of modified tiles and drop caches.

Returns
true if success

◆ Get()

template<class Type , int TILE_SIZE, int CACHED_TILE_COUNT>
Type GDALCachedPixelAccessor< Type, TILE_SIZE, CACHED_TILE_COUNT >::Get ( int  nX,
int  nY,
bool *  pbSuccess = nullptr 
)
inline

Get the value of a pixel.

No bound checking of nX, nY is done.

Parameters
nXX coordinate (between 0 and GetXSize()-1)
nYY coordinate (between 0 and GetYSize()-1)
[out]pbSuccessOptional pointer to a success flag
Returns
the pixel value

◆ Set()

template<class Type , int TILE_SIZE, int CACHED_TILE_COUNT>
bool GDALCachedPixelAccessor< Type, TILE_SIZE, CACHED_TILE_COUNT >::Set ( int  nX,
int  nY,
Type  val 
)
inline

Set the value of a pixel.

The actual modification of the underlying raster is deferred until the tile is implicit flushed while loading a new tile, or an explicit call to FlushCache().

The destructor of GDALCachedPixelAccessor will take care of calling FlushCache(), if the user hasn't done it explicitly.

No bound checking of nX, nY is done.

Parameters
nXX coordinate (between 0 and GetXSize()-1)
nYY coordinate (between 0 and GetYSize()-1)
valpixel value
Returns
true if success

The documentation for this class was generated from the following file: