SourceXtractorPlusPlus  0.15
Please provide a description of the project.
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 
29 namespace SourceXtractor {
30 
42 template<typename T, typename I = T>
43 class FunctionalImage : public Image<T> {
44 public:
45  using FunctorType = std::function<T(int x, int y, I v)>;
46 
47 protected:
49  : m_img{std::move(img)}, m_functor{functor} {
50  }
51 
52 public:
53  virtual ~FunctionalImage() = default;
54 
55  template<typename ...Args>
56  static std::shared_ptr<FunctionalImage<T, I>> create(Args&& ... args) {
57  return std::shared_ptr<FunctionalImage<T, I>>(new FunctionalImage{std::forward<Args>(args)...});
58  }
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 
83 private:
86 };
87 
88 } // end SourceXtractor
89 
90 #endif // _SEFRAMEWORK_IMAGE_FUNCTIONALIMAGE_H
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
std::string getRepr() const final
Get a string identifying this image in a human readable manner.
std::shared_ptr< ImageChunk< T > > getChunk(int x, int y, int width, int height) const final
FunctionalImage(std::shared_ptr< const Image< I >> img, FunctorType functor)
int getHeight() const final
Returns the height of the image in pixels.
int getWidth() const final
Returns the width of the image in pixels.
static std::shared_ptr< FunctionalImage< T, I > > create(Args &&... args)
virtual ~FunctionalImage()=default
std::shared_ptr< const Image< I > > m_img
Interface representing an image.
Definition: Image.h:43
static std::shared_ptr< UniversalImageChunk< T > > create(Args &&... args)
Definition: ImageChunk.h:142
T move(T... args)
STL namespace.
T target_type(T... args)