SourceXtractorPlusPlus 1.0.3
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
SubImage.h
Go to the documentation of this file.
1
17
18#ifndef _SEFRAMEWORK_IMAGE_SUBIMAGE_H_
19#define _SEFRAMEWORK_IMAGE_SUBIMAGE_H_
20
21#include <memory>
22
25
26namespace SourceXtractor {
27
32
33template<typename T>
34class SubImage : public Image<T> {
35protected:
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
48public:
52 virtual ~SubImage() = default;
53
54 template<typename... Args>
55 static std::shared_ptr<SubImage<T>> create(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
75private:
79};
80
81} /* namespace SourceXtractor */
82
83#endif /* _SEFRAMEWORK_IMAGE_SUBIMAGE_H_ */
Interface representing an image.
Definition Image.h:44
SubImage(std::shared_ptr< const Image< T > > image, const PixelCoordinate &offset, int width, int height)
Definition SubImage.h:36
int getHeight() const override
Returns the height of the image in pixels.
Definition SubImage.h:67
std::shared_ptr< ImageChunk< T > > getChunk(int x, int y, int width, int height) const override
Definition SubImage.h:71
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
static std::shared_ptr< SubImage< T > > create(Args &&... args)
Definition SubImage.h:55
int getWidth() const override
Returns the width of the image in pixels.
Definition SubImage.h:63
SubImage(std::shared_ptr< const Image< T > > image, int x, int y, int width, int height)
Definition SubImage.h:42
PixelCoordinate m_offset
Definition SubImage.h:77
virtual ~SubImage()=default
Destructor.
T forward(T... args)
A pixel coordinate made of two integers m_x and m_y.
T to_string(T... args)