SourceXtractorPlusPlus 0.21
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
VectorImage.h
Go to the documentation of this file.
1
23#ifndef _SEFRAMEWORK_IMAGE_VECTORIMAGE_H
24#define _SEFRAMEWORK_IMAGE_VECTORIMAGE_H
25
26#include <vector>
27#include <cassert>
28
31
33
34
35namespace SourceXtractor {
36
51template <typename T>
52class VectorImage final : public WriteableImage<T> {
53protected:
54
58
60
61 VectorImage(int width, int height) : m_width(width), m_height(height),
62 m_data(std::make_shared<std::vector<T>>(width * height)) {
63 assert(width > 0 && height > 0);
64 }
65
66 VectorImage(int width, int height, std::vector<T> data) :
67 m_width(width), m_height(height), m_data(std::make_shared<std::vector<T>>(std::move(data))) {
68 assert(width > 0 && height > 0);
69 assert(m_data->size() == std::size_t(width * height));
70 }
71
72 template<typename Iter>
73 VectorImage(int width, int height, Iter data_begin, Iter data_end,
74 typename std::enable_if<
77 >::type * = 0)
78 :m_width(width), m_height(height),
80 assert(m_data->size() == std::size_t(width * height));
81 }
82
86 // FIXME: We probably could use a getChunk were we give the buffer to use
87 auto chunk = other_image.getChunk(0, 0, other_image.getWidth(), other_image.getHeight());
88 for (int y = 0; y < m_height; y++) {
89 for (int x = 0; x < m_width; x++) {
90 setValue(x, y, chunk->getValue(x, y));
91 }
92 }
93 }
94
97
98public:
99 template<typename... Args>
103
105 return "VectorImage<" + std::to_string(m_width) + "," + std::to_string(m_height) + ">";
106 }
107
109 return m_height;
110 }
111
113 return m_width;
114 }
115
116 T getValue(int x, int y) const {
117 return this->at(x, y);
118 }
119
120 T getValue(PixelCoordinate coord) const {
121 return this->at(coord.m_x, coord.m_y);
122 }
123
124 void setValue(int x, int y, T value) final {
125 at(x,y) = value;
126 }
127
128 void setValue(PixelCoordinate pc, T value) {
129 setValue(pc.m_x, pc.m_y, value);
130 }
131
132 T& at(int x, int y) {
133 assert(x >= 0 && y >=0 && x < m_width && y < m_height);
134 return (*m_data)[x + y * m_width];
135 }
136
137 const T& at(int x, int y) const {
138 assert(x >= 0 && y >=0 && x < m_width && y < m_height);
139 return (*m_data)[x + y * m_width];
140 }
141
142 void fillValue(T value) {
143 std::fill(m_data->begin(), m_data->end(), value);
144 }
145
146 const std::vector<T>& getData() const {
147 return *m_data;
148 }
149
151 return *m_data;
152 }
153
157 virtual ~VectorImage() = default;
158
159 std::shared_ptr<ImageChunk<T>> getChunk(int x, int y, int width, int height) const override {
160 return ImageChunk<T>::create(m_data, x + y * m_width, width, height, m_width);
161 }
162
163
164private:
168
169}; /* End of VectorImage class */
170
171} /* namespace SourceXtractor */
172
173
174#endif
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
static std::shared_ptr< ImageChunk< T > > create(std::shared_ptr< const std::vector< T > > data, int offset, int width, int height, int stride)
Definition ImageChunk.h:46
Interface representing an image.
Definition Image.h:44
Image implementation which keeps the pixel values in memory.
Definition VectorImage.h:52
VectorImage(int width, int height, std::vector< T > data)
Definition VectorImage.h:66
int getWidth() const final
Returns the width of the image in pixels.
void setValue(int x, int y, T value) final
T getValue(PixelCoordinate coord) const
static std::shared_ptr< VectorImage< T > > create(Args &&... args)
const T & at(int x, int y) const
std::string getRepr() const final
Get a string identifying this image in a human readable manner.
VectorImage(VectorImage< T > &&other)=default
VectorImage(const Image< T > &other_image)
Definition VectorImage.h:83
const std::vector< T > & getData() const
std::vector< T > & getData()
virtual ~VectorImage()=default
Destructor.
VectorImage(int width, int height)
Definition VectorImage.h:61
VectorImage(int width, int height, Iter data_begin, Iter data_end, typename std::enable_if< std::is_base_of< std::input_iterator_tag, typename std::iterator_traits< Iter >::iterator_category >::value and std::is_same< T, typename std::iterator_traits< Iter >::value_type >::value >::type *=0)
Definition VectorImage.h:73
VectorImage(const std::shared_ptr< const Image< T > > &other_image)
Definition VectorImage.h:95
std::shared_ptr< ImageChunk< T > > getChunk(int x, int y, int width, int height) const override
std::shared_ptr< std::vector< T > > m_data
int getHeight() const final
Returns the height of the image in pixels.
VectorImage(const VectorImage< T > &other)
Definition VectorImage.h:55
void setValue(PixelCoordinate pc, T value)
T getValue(int x, int y) const
T fill(T... args)
T make_shared(T... args)
T move(T... args)
STL namespace.
A pixel coordinate made of two integers m_x and m_y.
T to_string(T... args)