SourceXtractorPlusPlus  0.13
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImageTile.h
Go to the documentation of this file.
1 
17 /*
18  * ImageTile.hm
19  *
20  * Created on: Feb 20, 2018
21  * Author: mschefer
22  */
23 
24 #ifndef _SEFRAMEWORK_IMAGE_IMAGETILE_H_
25 #define _SEFRAMEWORK_IMAGE_IMAGETILE_H_
26 #include <iostream>
29 
30 namespace SourceXtractor {
31 
32 class ImageSource;
33 
34 class ImageTile {
35 public:
36 
37  enum ImageType {
44  };
45 
46  static std::shared_ptr<ImageTile> create(ImageType image_type, int x, int y, int width, int height, std::shared_ptr<ImageSource> source=nullptr);
47 
48  virtual ~ImageTile() {
50  }
51 
52  bool isPixelInTile(int x, int y) const {
53  return x >= m_x && y >= m_y && x < m_max_x && y < m_max_y;
54  }
55 
56  int getPosX() const {
57  return m_x;
58  }
59 
60  int getPosY() const {
61  return m_y;
62  }
63 
64  virtual int getTileMemorySize() const = 0;
65 
66  int getWidth() const {
67  return m_max_x - m_x;
68  }
69 
70  int getHeight() const {
71  return m_max_y - m_y;
72  }
73 
74  template<typename T>
75  T getValue(int x, int y) const {
76  T value;
77  getValue(x, y, value);
78  return value;
79  }
80 
81  virtual void setValue(int x, int y, float value) = 0;
82  virtual void setValue(int x, int y, double value) = 0;
83  virtual void setValue(int x, int y, int value) = 0;
84  virtual void setValue(int x, int y, unsigned int value) = 0;
85  virtual void setValue(int x, int y, std::int64_t value) = 0;
86 
87  template<typename T>
89  if (m_image_type == getTypeValue(T())) {
91  } else {
92  //FIXME implement type conversion !!!!!!!!!!!!!!!!
93  return nullptr;
94  }
95  }
96 
97  virtual void* getDataPtr()=0;
98 
99  void setModified(bool modified) {
100  m_modified = modified;
101  }
102 
103  bool isModified() const {
104  return m_modified;
105  }
106 
107  virtual void saveIfModified();
108 
109  static ImageType getTypeValue(float) {
110  return FloatImage;
111  }
112 
113  static ImageType getTypeValue(double) {
114  return DoubleImage;
115  }
116 
117  static ImageType getTypeValue(int) {
118  return IntImage;
119  }
120 
121  static ImageType getTypeValue(unsigned int) {
122  return UIntImage;
123  }
124 
126  return LongLongImage;
127  }
128 
129  static size_t getTypeSize(ImageType image_type) {
130  switch (image_type) {
131  default:
133  case ImageTile::IntImage:
135  return 4;
138  return 8;
139  }
140  }
141 
142  ImageType getType() const {
143  return m_image_type;
144  }
145 
146 protected:
147  virtual void getValue(int x, int y, float& value) const = 0;
148  virtual void getValue(int x, int y, double& value) const = 0;
149  virtual void getValue(int x, int y, int& value) const = 0;
150  virtual void getValue(int x, int y, unsigned int& value) const = 0;
151  virtual void getValue(int x, int y, std::int64_t& value) const = 0;
152 
153 
154  ImageTile(ImageType image_type, int x, int y, int width, int height, std::shared_ptr<ImageSource> source=nullptr)
155  : m_modified(false), m_image_type(image_type), m_source(source), m_x(x), m_y(y), m_max_x(x+width), m_max_y(y+height) {
156  createImage(image_type, width, height);
157  }
158 
159  void createImage(ImageType image_type, int width, int height) {
160  //std::cout << "create tile type " << image_type << "\n";
161  switch (image_type) {
162  default:
163  case FloatImage:
164  m_tile_image = VectorImage<float>::create(width, height);
165  break;
166  case DoubleImage:
167  m_tile_image = VectorImage<double>::create(width, height);
168  break;
169  case IntImage:
170  m_tile_image = VectorImage<int>::create(width, height);
171  break;
172  case UIntImage:
174  break;
175  case LongLongImage:
177  break;
178  }
179  }
180 
182 
184 
186  int m_x, m_y;
188 
190 };
191 
192 
193 }
194 
195 
196 #endif /* _SEFRAMEWORK_IMAGE_IMAGETILE_H_ */
std::shared_ptr< VectorImage< T > > getImage() const
Definition: ImageTile.h:88
ImageType getType() const
Definition: ImageTile.h:142
std::shared_ptr< void > m_tile_image
Definition: ImageTile.h:189
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
static std::shared_ptr< VectorImage< T > > create(Args &&...args)
Definition: VectorImage.h:89
ImageTile(ImageType image_type, int x, int y, int width, int height, std::shared_ptr< ImageSource > source=nullptr)
Definition: ImageTile.h:154
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
void setModified(bool modified)
Definition: ImageTile.h:99
static ImageType getTypeValue(unsigned int)
Definition: ImageTile.h:121
int getPosX() const
Definition: ImageTile.h:56
Image implementation which keeps the pixel values in memory.
Definition: VectorImage.h:53
virtual void setValue(int x, int y, float value)=0
virtual void saveIfModified()
Definition: ImageTile.cpp:112
static size_t getTypeSize(ImageType image_type)
Definition: ImageTile.h:129
virtual int getTileMemorySize() const =0
std::shared_ptr< ImageSource > m_source
Definition: ImageTile.h:185
T static_pointer_cast(T...args)
bool isModified() const
Definition: ImageTile.h:103
int getWidth() const
Definition: ImageTile.h:66
bool isPixelInTile(int x, int y) const
Definition: ImageTile.h:52
static ImageType getTypeValue(int)
Definition: ImageTile.h:117
T getValue(int x, int y) const
Definition: ImageTile.h:75
static ImageType getTypeValue(double)
Definition: ImageTile.h:113
static std::shared_ptr< ImageTile > create(ImageType image_type, int x, int y, int width, int height, std::shared_ptr< ImageSource > source=nullptr)
Definition: ImageTile.cpp:96
int getHeight() const
Definition: ImageTile.h:70
void createImage(ImageType image_type, int width, int height)
Definition: ImageTile.h:159
static ImageType getTypeValue(std::int64_t)
Definition: ImageTile.h:125
int getPosY() const
Definition: ImageTile.h:60
static ImageType getTypeValue(float)
Definition: ImageTile.h:109
virtual void * getDataPtr()=0