SourceXtractorPlusPlus  0.15
Please provide a description of the project.
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
SourceXtractor::ImageAccessor< T > Class Template Reference

#include <ImageAccessor.h>

Inheritance diagram for SourceXtractor::ImageAccessor< T >:
[legend]
Collaboration diagram for SourceXtractor::ImageAccessor< T >:
[legend]

Public Types

enum  AccessHint { TOP_LEFT, CENTERED, BOTTOM_RIGHT }
 
- Public Types inherited from SourceXtractor::Image< T >
using PixelType = T
 

Public Member Functions

 ~ImageAccessor ()=default
 
 ImageAccessor (std::shared_ptr< const Image< T >> img, AccessHint hint=TOP_LEFT, int w=64, int h=1)
 
 ImageAccessor (const Image< T > &img, AccessHint hint=TOP_LEFT, int w=64, int h=64)
 
 ImageAccessor (const ImageAccessor< T > &)=delete
 
 ImageAccessor (ImageAccessor< T > &&)=default
 
ImageAccessor< T > & operator= (const ImageAccessor< T > &)=delete
 
getValue (int x, int y)
 
getValue (const PixelCoordinate &coord)
 
std::string getRepr () const override
 Get a string identifying this image in a human readable manner. More...
 
int getWidth () const override
 Returns the width of the image in pixels. More...
 
int getHeight () const override
 Returns the height of the image in pixels. More...
 
std::shared_ptr< ImageChunk< T > > getChunk (int x, int y, int width, int height) const override
 
- Public Member Functions inherited from SourceXtractor::Image< T >
virtual ~Image ()=default
 Destructor. More...
 
std::shared_ptr< ImageChunk< T > > getChunk (const PixelCoordinate &start, const PixelCoordinate &end) const
 
bool isInside (int x, int y) const
 Returns true if the given coordinates are inside the image bounds. More...
 

Private Member Functions

void selectChunk (const PixelCoordinate &coord)
 
void nextCoordinates (const PixelCoordinate &coord)
 
PixelCoordinate firstCoordinates (const PixelCoordinate &coord)
 

Private Attributes

const Image< T > * m_image
 
std::shared_ptr< const Image< T > > m_keep_alive
 
std::shared_ptr< const ImageChunk< T > > m_chunk
 
PixelCoordinate m_chunk_min
 
PixelCoordinate m_chunk_max
 
AccessHint m_hint
 
int m_read_width
 
int m_read_height
 

Detailed Description

template<typename T>
class SourceXtractor::ImageAccessor< T >

The Image interface used to have a getValue(x, y) method, but this was suboptimal when using image types that need to keep state and be thread safe (i.e. BufferedImage) It was dropped, and this accessor is intended to provide an easy alternative. Unlike the images, the accessor is explicitly not thread safe and not intended to be passed around or copied. To reduce performance penalties, it can be hinted about the chunk size and the access pattern. For instance, if you know the access is away from the first coordinate in a circular fashion, the first chunk will be centered on your first read to reduce requests.

Template Parameters
TPixel type

Definition at line 41 of file ImageAccessor.h.

Member Enumeration Documentation

◆ AccessHint

template<typename T >
enum SourceXtractor::ImageAccessor::AccessHint

Hints about the access pattern Even if you don't honor the hint, it will still work!

Enumerator
TOP_LEFT 
CENTERED 
BOTTOM_RIGHT 

Definition at line 48 of file ImageAccessor.h.

Constructor & Destructor Documentation

◆ ~ImageAccessor()

template<typename T >
SourceXtractor::ImageAccessor< T >::~ImageAccessor ( )
default

Destructor

◆ ImageAccessor() [1/4]

template<typename T >
SourceXtractor::ImageAccessor< T >::ImageAccessor ( std::shared_ptr< const Image< T >>  img,
AccessHint  hint = TOP_LEFT,
int  w = 64,
int  h = 1 
)
inline

Constructor

Parameters
imgImage to be accessed
hintHint about the access pattern
wWidth of the chunk size
hHeight of the chunk size
Note
Don't be greedy over the chunk size, but not too conservative either. Of course, if you know beforehand the exact chunk that will be needed, better use getChunk directly!

Definition at line 72 of file ImageAccessor.h.

◆ ImageAccessor() [2/4]

template<typename T >
SourceXtractor::ImageAccessor< T >::ImageAccessor ( const Image< T > &  img,
AccessHint  hint = TOP_LEFT,
int  w = 64,
int  h = 64 
)
inline

Definition at line 76 of file ImageAccessor.h.

◆ ImageAccessor() [3/4]

template<typename T >
SourceXtractor::ImageAccessor< T >::ImageAccessor ( const ImageAccessor< T > &  )
delete

Can not be copied!

◆ ImageAccessor() [4/4]

template<typename T >
SourceXtractor::ImageAccessor< T >::ImageAccessor ( ImageAccessor< T > &&  )
default

But it can be moved

Member Function Documentation

◆ firstCoordinates()

template<typename T >
PixelCoordinate SourceXtractor::ImageAccessor< T >::firstCoordinates ( const PixelCoordinate coord)
inlineprivate

◆ getChunk()

template<typename T >
std::shared_ptr<ImageChunk<T> > SourceXtractor::ImageAccessor< T >::getChunk ( int  x,
int  y,
int  width,
int  height 
) const
inlineoverridevirtual

Implements SourceXtractor::Image< T >.

Definition at line 128 of file ImageAccessor.h.

◆ getHeight()

template<typename T >
int SourceXtractor::ImageAccessor< T >::getHeight ( ) const
inlineoverridevirtual

◆ getRepr()

template<typename T >
std::string SourceXtractor::ImageAccessor< T >::getRepr ( ) const
inlineoverridevirtual

Get a string identifying this image in a human readable manner.

Implements SourceXtractor::Image< T >.

Definition at line 116 of file ImageAccessor.h.

◆ getValue() [1/2]

template<typename T >
T SourceXtractor::ImageAccessor< T >::getValue ( const PixelCoordinate coord)
inline

Definition at line 107 of file ImageAccessor.h.

◆ getValue() [2/2]

template<typename T >
T SourceXtractor::ImageAccessor< T >::getValue ( int  x,
int  y 
)
inline

◆ getWidth()

template<typename T >
int SourceXtractor::ImageAccessor< T >::getWidth ( ) const
inlineoverridevirtual

◆ nextCoordinates()

template<typename T >
void SourceXtractor::ImageAccessor< T >::nextCoordinates ( const PixelCoordinate coord)
inlineprivate

Try to guess what's coming next. It just uses some rudimentary heuristics.

Definition at line 155 of file ImageAccessor.h.

Referenced by SourceXtractor::ImageAccessor< WriteableInterfaceType::PixelType >::selectChunk().

◆ operator=()

template<typename T >
ImageAccessor<T>& SourceXtractor::ImageAccessor< T >::operator= ( const ImageAccessor< T > &  )
delete

Can not be assigned either

◆ selectChunk()

template<typename T >
void SourceXtractor::ImageAccessor< T >::selectChunk ( const PixelCoordinate coord)
inlineprivate

Verify if the requested coordinates can be satisfied, and asks for the next chunk otherwise

Definition at line 144 of file ImageAccessor.h.

Referenced by SourceXtractor::ImageAccessor< WriteableInterfaceType::PixelType >::getValue().

Member Data Documentation

◆ m_chunk

template<typename T >
std::shared_ptr<const ImageChunk<T> > SourceXtractor::ImageAccessor< T >::m_chunk
private

◆ m_chunk_max

template<typename T >
PixelCoordinate SourceXtractor::ImageAccessor< T >::m_chunk_max
private

◆ m_chunk_min

template<typename T >
PixelCoordinate SourceXtractor::ImageAccessor< T >::m_chunk_min
private

◆ m_hint

template<typename T >
AccessHint SourceXtractor::ImageAccessor< T >::m_hint
private

◆ m_image

template<typename T >
const Image<T>* SourceXtractor::ImageAccessor< T >::m_image
private

◆ m_keep_alive

template<typename T >
std::shared_ptr<const Image<T> > SourceXtractor::ImageAccessor< T >::m_keep_alive
private

Definition at line 134 of file ImageAccessor.h.

◆ m_read_height

template<typename T >
int SourceXtractor::ImageAccessor< T >::m_read_height
private

◆ m_read_width

template<typename T >
int SourceXtractor::ImageAccessor< T >::m_read_width
private

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