SourceXtractorPlusPlus  0.13
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 
34 
35 
36 namespace SourceXtractor {
37 
52 template <typename T>
53 class VectorImage final : public ImageBase<T>, public WriteableImage<T> {
54 protected:
55 
56  VectorImage(int width, int height) : m_width(width), m_height(height), m_data(width * height) {
57  assert(width > 0 && height > 0);
58  }
59 
60  VectorImage(int width, int height, std::vector<T> data) :
61  m_width(width), m_height(height), m_data(std::move(data)) {
62  assert(width > 0 && height > 0);
63  assert(m_data.size() == std::size_t(width * height));
64  }
65 
66  template <typename Iter>
67  VectorImage(int width, int height, Iter data_begin, Iter data_end,
68  typename std::enable_if<
71  >::type* =0) :
72  m_width(width), m_height(height), m_data(data_begin, data_end) {
73  assert(m_data.size() == std::size_t(width * height));
74  }
75 
76  VectorImage(const Image<T>& other_image) :
77  m_width(other_image.getWidth()), m_height(other_image.getHeight()), m_data(m_width * m_height) {
78  for (int y = 0; y < m_height; y++) {
79  for (int x = 0; x < m_width; x++) {
80  setValue(x, y, other_image.getValue(x, y));
81  }
82  }
83  }
84 
85  VectorImage(const std::shared_ptr<const Image<T>>& other_image): VectorImage(static_cast<const Image<T>&>(*other_image)) {}
86 
87 public:
88  template<typename... Args>
89  static std::shared_ptr<VectorImage<T>> create(Args&&... args) {
90  return std::shared_ptr<VectorImage<T>>(new VectorImage<T>(std::forward<Args>(args)...));
91  }
92 
93  std::string getRepr() const final {
94  return "VectorImage<" + std::to_string(m_width) + "," + std::to_string(m_height) + ">";
95  }
96 
97  int getHeight() const final {
98  return m_height;
99  }
100 
101  int getWidth() const final {
102  return m_width;
103  }
104 
105  using Image<T>::getValue;
106  T getValue(int x, int y) const final {
107  return const_cast<VectorImage<T>*>(this)->at(x, y);
108  }
109 
110  void setValue(int x, int y, T value) final {
111  at(x,y) = value;
112  }
113 
114  void setValue(PixelCoordinate pc, T value) {
115  setValue(pc.m_x, pc.m_y, value);
116  }
117 
118  T& at(int x, int y) {
119  assert(x >= 0 && y >=0 && x < m_width && y < m_height);
120  return m_data[x + y * m_width];
121  }
122 
123  void fillValue(T value) {
124  std::fill(m_data.begin(), m_data.end(), value);
125  }
126 
127  const std::vector<T>& getData() const {
128  return m_data;
129  }
130 
132  return m_data;
133  }
134 
138  virtual ~VectorImage() = default;
139 
140  virtual std::shared_ptr<ImageChunk<T>> getChunk(int x, int y, int width, int height) const override {
141  return ImageChunk<T>::create(&m_data[x + y * m_width], width, height, m_width, this->shared_from_this());
142  }
143 
144 
145 private:
146  int m_width;
147  int m_height;
149 
150 }; /* End of VectorImage class */
151 
152 } /* namespace SourceXtractor */
153 
154 
155 #endif
SourceXtractor::VectorImage::setValue
void setValue(int x, int y, T value) final
Definition: VectorImage.h:110
ImageBase.h
std::is_same
SourceXtractor::VectorImage::VectorImage
VectorImage(const std::shared_ptr< const Image< T >> &other_image)
Definition: VectorImage.h:85
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:140
std::string
STL class.
std::shared_ptr
STL class.
SourceXtractor::VectorImage::VectorImage
VectorImage(int width, int height, std::vector< T > data)
Definition: VectorImage.h:60
std::move
T move(T... args)
SourceXtractor::VectorImage::at
T & at(int x, int y)
Definition: VectorImage.h:118
SourceXtractor::VectorImage::getData
std::vector< T > & getData()
Definition: VectorImage.h:131
ImageChunk.h
SourceXtractor::VectorImage::getRepr
std::string getRepr() const final
Get a string identifying this image in a human readable manner.
Definition: VectorImage.h:93
std::vector
STL class.
std::input_iterator_tag
SourceXtractor::VectorImage::VectorImage
VectorImage(const Image< T > &other_image)
Definition: VectorImage.h:76
SourceXtractor::VectorImage::getHeight
int getHeight() const final
Returns the height of the image in pixels.
Definition: VectorImage.h:97
SourceXtractor::VectorImage::VectorImage
VectorImage(int width, int height)
Definition: VectorImage.h:56
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:147
SourceXtractor
Definition: Aperture.h:30
std::enable_shared_from_this< ImageBase< T > >::shared_from_this
T shared_from_this(T... args)
SourceXtractor::Image::getValue
virtual T getValue(int x, int y) const =0
Returns the value of the pixel with the coordinates (x,y)
WriteableImage.h
std::enable_if
SourceXtractor::WriteableImage
Definition: WriteableImage.h:32
std::iterator_traits
std::to_string
T to_string(T... args)
SourceXtractor::VectorImage::create
static std::shared_ptr< VectorImage< T > > create(Args &&... args)
Definition: VectorImage.h:89
Image.h
SourceXtractor::VectorImage::m_width
int m_width
Definition: VectorImage.h:146
SourceXtractor::VectorImage::fillValue
void fillValue(T value)
Definition: VectorImage.h:123
SourceXtractor::VectorImage::getData
const std::vector< T > & getData() const
Definition: VectorImage.h:127
SourceXtractor::VectorImage::getWidth
int getWidth() const final
Returns the width of the image in pixels.
Definition: VectorImage.h:101
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:67
std
STL namespace.
SourceXtractor::VectorImage
Image implementation which keeps the pixel values in memory.
Definition: VectorImage.h:53
SourceXtractor::VectorImage::m_data
std::vector< T > m_data
Definition: VectorImage.h:148
SourceXtractor::VectorImage::getValue
T getValue(int x, int y) const final
Returns the value of the pixel with the coordinates (x,y)
Definition: VectorImage.h:106
std::size_t
SourceXtractor::VectorImage::~VectorImage
virtual ~VectorImage()=default
Destructor.
SourceXtractor::VectorImage::setValue
void setValue(PixelCoordinate pc, T value)
Definition: VectorImage.h:114
y
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
Definition: MoffatModelFittingTask.cpp:94
SourceXtractor::ImageBase
Definition: ImageBase.h:35
SourceXtractor::ImageChunk::create
static std::shared_ptr< ImageChunk< T > > create(const T *data, int width, int height, int stride, std::shared_ptr< const Image< T >> image=nullptr)
Definition: ImageChunk.h:44
std::is_base_of