SourceXtractorPlusPlus  0.15
Please provide a description of the project.
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 
35 namespace SourceXtractor {
36 
51 template <typename T>
52 class VectorImage final : public WriteableImage<T> {
53 protected:
54 
55  VectorImage(const VectorImage<T>& other) : m_width(other.m_width), m_height(other.m_height),
56  m_data(std::make_shared<std::vector<T>>(*other.m_data)) {
57  }
58 
59  VectorImage(VectorImage<T>&& other) = default;
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),
79  m_data(std::make_shared<std::vector<T>>(data_begin, data_end)) {
80  assert(m_data->size() == std::size_t(width * height));
81  }
82 
83  VectorImage(const Image <T>& other_image)
84  : m_width(other_image.getWidth()), m_height(other_image.getHeight()),
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 
95  VectorImage(const std::shared_ptr<const Image <T>>& other_image) : VectorImage(
96  static_cast<const Image <T>&>(*other_image)) {}
97 
98 public:
99  template<typename... Args>
100  static std::shared_ptr<VectorImage<T>> create(Args&&... args) {
101  return std::shared_ptr<VectorImage<T>>(new VectorImage<T>(std::forward<Args>(args)...));
102  }
103 
104  std::string getRepr() const final {
105  return "VectorImage<" + std::to_string(m_width) + "," + std::to_string(m_height) + ">";
106  }
107 
108  int getHeight() const final {
109  return m_height;
110  }
111 
112  int getWidth() const final {
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  virtual 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 
164 private:
165  int m_width;
166  int m_height;
168 
169 }; /* End of VectorImage class */
170 
171 } /* namespace SourceXtractor */
172 
173 
174 #endif
SourceXtractor::VectorImage::setValue
void setValue(int x, int y, T value) final
Definition: VectorImage.h:124
std::is_same
SourceXtractor::VectorImage::VectorImage
VectorImage(const std::shared_ptr< const Image< T >> &other_image)
Definition: VectorImage.h:95
SourceXtractor::PixelCoordinate
A pixel coordinate made of two integers m_x and m_y.
Definition: PixelCoordinate.h:37
SourceXtractor::VectorImage::getChunk
virtual std::shared_ptr< ImageChunk< T > > getChunk(int x, int y, int width, int height) const override
Definition: VectorImage.h:159
std::string
STL class.
std::shared_ptr
STL class.
SourceXtractor::VectorImage::VectorImage
VectorImage(int width, int height, std::vector< T > data)
Definition: VectorImage.h:66
SourceXtractor::Image::getWidth
virtual int getWidth() const =0
Returns the width of the image in pixels.
std::move
T move(T... args)
SourceXtractor::VectorImage::at
T & at(int x, int y)
Definition: VectorImage.h:132
SourceXtractor::VectorImage::getData
std::vector< T > & getData()
Definition: VectorImage.h:150
ImageChunk.h
std::make_shared
T make_shared(T... args)
SourceXtractor::VectorImage::getRepr
std::string getRepr() const final
Get a string identifying this image in a human readable manner.
Definition: VectorImage.h:104
std::vector
STL class.
std::input_iterator_tag
SourceXtractor::VectorImage::VectorImage
VectorImage(const Image< T > &other_image)
Definition: VectorImage.h:83
SourceXtractor::VectorImage::m_data
std::shared_ptr< std::vector< T > > m_data
Definition: VectorImage.h:167
SourceXtractor::Image::getHeight
virtual int getHeight() const =0
Returns the height of the image in pixels.
SourceXtractor::VectorImage::getHeight
int getHeight() const final
Returns the height of the image in pixels.
Definition: VectorImage.h:108
SourceXtractor::VectorImage::VectorImage
VectorImage(int width, int height)
Definition: VectorImage.h:61
SourceXtractor::VectorImage::VectorImage
VectorImage(VectorImage< T > &&other)=default
SourceXtractor::Image
Interface representing an image.
Definition: Image.h:43
std::fill
T fill(T... args)
pc
constexpr double pc
SourceXtractor::VectorImage::m_height
int m_height
Definition: VectorImage.h:166
SourceXtractor
Definition: Aperture.h:30
SourceXtractor::PixelCoordinate::m_x
int m_x
Definition: PixelCoordinate.h:38
WriteableImage.h
std::enable_if
SourceXtractor::WriteableImage
Definition: WriteableImage.h:33
SourceXtractor::PixelCoordinate::m_y
int m_y
Definition: PixelCoordinate.h:38
std::iterator_traits
SourceXtractor::Image::getChunk
virtual std::shared_ptr< ImageChunk< T > > getChunk(int x, int y, int width, int height) const =0
std::to_string
T to_string(T... args)
SourceXtractor::VectorImage::create
static std::shared_ptr< VectorImage< T > > create(Args &&... args)
Definition: VectorImage.h:100
Image.h
SourceXtractor::VectorImage::m_width
int m_width
Definition: VectorImage.h:165
SourceXtractor::VectorImage::fillValue
void fillValue(T value)
Definition: VectorImage.h:142
SourceXtractor::VectorImage::getData
const std::vector< T > & getData() const
Definition: VectorImage.h:146
SourceXtractor::VectorImage::getWidth
int getWidth() const final
Returns the width of the image in pixels.
Definition: VectorImage.h:112
SourceXtractor::VectorImage::getValue
T getValue(PixelCoordinate coord) const
Definition: VectorImage.h:120
SourceXtractor::VectorImage::at
const T & at(int x, int y) const
Definition: VectorImage.h:137
x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
Definition: MoffatModelFittingTask.cpp:94
SourceXtractor::VectorImage::VectorImage
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
std
STL namespace.
SourceXtractor::VectorImage
Image implementation which keeps the pixel values in memory.
Definition: VectorImage.h:52
std::size_t
SourceXtractor::VectorImage::~VectorImage
virtual ~VectorImage()=default
Destructor.
SourceXtractor::VectorImage::getValue
T getValue(int x, int y) const
Definition: VectorImage.h:116
SourceXtractor::VectorImage::setValue
void setValue(PixelCoordinate pc, T value)
Definition: VectorImage.h:128
SourceXtractor::ImageChunk::create
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:44
y
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
Definition: MoffatModelFittingTask.cpp:94
SourceXtractor::VectorImage::VectorImage
VectorImage(const VectorImage< T > &other)
Definition: VectorImage.h:55
std::is_base_of