SourceXtractorPlusPlus 1.0.3
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
SourceXtractor::ImageAccessor< T > Class Template Reference

#include <ImageAccessor.h>

Inheritance diagram for SourceXtractor::ImageAccessor< T >:
Collaboration diagram for SourceXtractor::ImageAccessor< T >:

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.
int getWidth () const override
 Returns the width of the image in pixels.
int getHeight () const override
 Returns the height of the image in pixels.
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.
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.

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 )
inlineexplicit

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.

References m_hint, m_image, m_keep_alive, m_read_height, m_read_width, std::move(), and TOP_LEFT.

Referenced by ImageAccessor(), ImageAccessor(), and operator=().

Here is the call graph for this function:

◆ ImageAccessor() [2/4]

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

Definition at line 75 of file ImageAccessor.h.

References m_hint, m_image, m_read_height, m_read_width, and TOP_LEFT.

◆ ImageAccessor() [3/4]

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

Can not be copied!

References ImageAccessor().

Here is the call graph for this function:

◆ ImageAccessor() [4/4]

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

But it can be moved

References ImageAccessor().

Here is the call graph for this function:

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 127 of file ImageAccessor.h.

References m_image.

◆ 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 115 of file ImageAccessor.h.

References m_image.

◆ getValue() [1/2]

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

Definition at line 106 of file ImageAccessor.h.

References m_chunk, m_chunk_min, and selectChunk().

Here is the call graph for this function:

◆ getValue() [2/2]

◆ 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 154 of file ImageAccessor.h.

References BOTTOM_RIGHT, CENTERED, firstCoordinates(), m_chunk, m_chunk_max, m_chunk_min, m_hint, m_image, m_read_height, m_read_width, SourceXtractor::PixelCoordinate::m_x, SourceXtractor::PixelCoordinate::m_y, and TOP_LEFT.

Referenced by selectChunk().

Here is the call graph for this function:

◆ operator=()

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

Can not be assigned either

References ImageAccessor().

Here is the call graph for this function:

◆ 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 143 of file ImageAccessor.h.

References m_chunk, m_chunk_max, m_chunk_min, m_image, and nextCoordinates().

Referenced by getValue(), and getValue().

Here is the call graph for this function:

Member Data Documentation

◆ m_chunk

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

Definition at line 134 of file ImageAccessor.h.

Referenced by getValue(), getValue(), nextCoordinates(), and selectChunk().

◆ m_chunk_max

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

Definition at line 135 of file ImageAccessor.h.

Referenced by nextCoordinates(), and selectChunk().

◆ m_chunk_min

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

Definition at line 135 of file ImageAccessor.h.

Referenced by getValue(), getValue(), nextCoordinates(), and selectChunk().

◆ m_hint

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

Definition at line 136 of file ImageAccessor.h.

Referenced by firstCoordinates(), ImageAccessor(), ImageAccessor(), and nextCoordinates().

◆ 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 133 of file ImageAccessor.h.

Referenced by ImageAccessor().

◆ m_read_height

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

Definition at line 137 of file ImageAccessor.h.

Referenced by firstCoordinates(), ImageAccessor(), ImageAccessor(), and nextCoordinates().

◆ m_read_width

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

Definition at line 137 of file ImageAccessor.h.

Referenced by firstCoordinates(), ImageAccessor(), ImageAccessor(), and nextCoordinates().


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