SourceXtractorPlusPlus 1.0.3
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
FunctionalImage.h
Go to the documentation of this file.
1
17/*
18 * @file SEFramework/Image/FunctionalImage.h
19 * @date 27/03/19
20 * @author Alejandro Alvarez Ayllon
21 */
22
23#ifndef _SEFRAMEWORK_IMAGE_FUNCTIONALIMAGE_H
24#define _SEFRAMEWORK_IMAGE_FUNCTIONALIMAGE_H
25
28
29namespace SourceXtractor {
30
42template<typename T, typename I = T>
43class FunctionalImage : public Image<T> {
44public:
45 using FunctorType = std::function<T(int x, int y, I v)>;
46
47protected:
49 : m_img{std::move(img)}, m_functor{functor} {
50 }
51
52public:
53 virtual ~FunctionalImage() = default;
54
55 template<typename ...Args>
59
60 std::string getRepr() const final {
61 return "FunctionalImage<" + std::string(m_functor.target_type().name()) + ">";
62 }
63
64 int getWidth() const final {
65 return m_img->getWidth();
66 }
67
68 int getHeight() const final {
69 return m_img->getHeight();
70 }
71
72 std::shared_ptr<ImageChunk<T>> getChunk(int x, int y, int width, int height) const final {
73 auto in_chunk = m_img->getChunk(x, y, width, height);
74 auto chunk = UniversalImageChunk<T>::create(width, height);
75 for (int iy = 0; iy < height; ++iy) {
76 for (int ix = 0; ix < width; ++ix) {
77 chunk->at(ix, iy) = m_functor(ix + x, iy + y, in_chunk->getValue(ix, iy));
78 }
79 }
80 return chunk;
81 }
82
83private:
86};
87
88} // end SourceXtractor
89
90#endif // _SEFRAMEWORK_IMAGE_FUNCTIONALIMAGE_H
std::string getRepr() const final
Get a string identifying this image in a human readable manner.
static std::shared_ptr< FunctionalImage< T, I > > create(Args &&... args)
std::shared_ptr< ImageChunk< T > > getChunk(int x, int y, int width, int height) const final
std::function< T(int x, int y, I v)> FunctorType
int getHeight() const final
Returns the height of the image in pixels.
int getWidth() const final
Returns the width of the image in pixels.
FunctionalImage(std::shared_ptr< const Image< I > > img, FunctorType functor)
virtual ~FunctionalImage()=default
std::shared_ptr< const Image< I > > m_img
Interface representing an image.
Definition Image.h:44
static std::shared_ptr< UniversalImageChunk< T > > create(Args &&... args)
Definition ImageChunk.h:144
T forward(T... args)
T move(T... args)
STL namespace.