SourceXtractorPlusPlus  0.16
Please provide a description of the project.
SubImage.h
Go to the documentation of this file.
1 
18 #ifndef _SEFRAMEWORK_IMAGE_SUBIMAGE_H_
19 #define _SEFRAMEWORK_IMAGE_SUBIMAGE_H_
20 
21 #include <memory>
22 
25 
26 namespace SourceXtractor {
27 
33 template<typename T>
34 class SubImage : public Image<T> {
35 protected:
36  SubImage(std::shared_ptr<const Image<T>> image, const PixelCoordinate &offset, int width, int height)
37  : m_image(image), m_offset(offset), m_width(width), m_height(height) {
38  assert(offset.m_x >= 0 && offset.m_y >= 0 && width > 0 && height > 0 &&
39  offset.m_x + width <= image->getWidth() && offset.m_y + height <= image->getHeight());
40  }
41 
42  SubImage(std::shared_ptr<const Image<T>> image, int x, int y, int width, int height)
43  : m_image(image), m_offset(x, y), m_width(width), m_height(height) {
44  assert(x >= 0 && y >= 0 && width > 0 && height > 0 &&
45  x + width <= image->getWidth() && y + height <= image->getHeight());
46  }
47 
48 public:
52  virtual ~SubImage() = default;
53 
54  template<typename... Args>
55  static std::shared_ptr<SubImage<T>> create(Args &&... args) {
56  return std::shared_ptr<SubImage<T>>(new SubImage{std::forward<Args>(args)...});
57  }
58 
59  std::string getRepr() const override {
60  return "SubImage(" + m_image->getRepr() + ", " + std::to_string(m_offset.m_x) + ", " + std::to_string(m_offset.m_y) + ", " + std::to_string(m_width) + ", " + std::to_string(m_height) + ")";
61  }
62 
63  int getWidth() const override {
64  return m_width;
65  }
66 
67  int getHeight() const override {
68  return m_height;
69  }
70 
71  std::shared_ptr<ImageChunk<T>> getChunk(int x, int y, int width, int height) const override {
72  return m_image->getChunk(x + m_offset.m_x, y + m_offset.m_y, width, height);
73  }
74 
75 private:
79 };
80 
81 } /* namespace SourceXtractor */
82 
83 #endif /* _SEFRAMEWORK_IMAGE_SUBIMAGE_H_ */
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
Interface representing an image.
Definition: Image.h:43
Part of another image.
Definition: SubImage.h:34
static std::shared_ptr< SubImage< T > > create(Args &&... args)
Definition: SubImage.h:55
std::shared_ptr< ImageChunk< T > > getChunk(int x, int y, int width, int height) const override
Definition: SubImage.h:71
SubImage(std::shared_ptr< const Image< T >> image, int x, int y, int width, int height)
Definition: SubImage.h:42
int getHeight() const override
Returns the height of the image in pixels.
Definition: SubImage.h:67
SubImage(std::shared_ptr< const Image< T >> image, const PixelCoordinate &offset, int width, int height)
Definition: SubImage.h:36
std::string getRepr() const override
Get a string identifying this image in a human readable manner.
Definition: SubImage.h:59
std::shared_ptr< const Image< T > > m_image
Definition: SubImage.h:76
int getWidth() const override
Returns the width of the image in pixels.
Definition: SubImage.h:63
PixelCoordinate m_offset
Definition: SubImage.h:77
virtual ~SubImage()=default
Destructor.
A pixel coordinate made of two integers m_x and m_y.
T to_string(T... args)