Image Component Library (ICL)
Channel.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLCore/src/ICLCore/Channel.h **
10 ** Module : ICLCore **
11 ** Authors: Christof Elbrechter **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 #pragma once
32 
33 #include <ICLUtils/CompatMacros.h>
34 #include <ICLCore/Types.h>
35 #include <ICLCore/CoreFunctions.h>
36 #include <ICLUtils/Size.h>
37 #include <ICLUtils/Point.h>
38 #include <ICLUtils/Rect.h>
39 #include <ICLCore/ImgIterator.h>
40 
41 namespace icl{
42  namespace core{
43 
44 
46 
144  template<class T>
145  class Channel{
146  mutable T *m_data;
149 
150  public:
152 
155 
157  inline Channel(const Channel &other){
158  *this = other;
159  }
160 
163  m_data = other.m_data;
164  m_size = other.m_size;
165  m_roi = other.m_roi;
166  return *this;
167  }
168 
170 
173  const Channel<T> &operator=(const Channel<T> &other) const{
174  return *const_cast<Channel*>(this) = const_cast<Channel<T>&>(other);
175  }
176 
178 
183  inline T &operator()(int x, int y){
184  return m_data[x+m_size.width*y];
185  }
186 
188 
189  inline T &operator()(const utils::Point &p){
190  return operator()(p.x,p.y);
191  }
192 
194 
195  inline const T &operator()(const utils::Point &p) const{
196  return operator()(p.x,p.y);
197  }
198 
200 
205  inline const T &operator()(int x, int y) const{
206  return m_data[x+m_size.width*y];
207  }
208 
210 
213  inline T &operator[](int idx) {
214  return m_data[idx];
215  }
216 
218 
221  inline const T &operator[](int idx) const {
222  return m_data[idx];
223  }
224 
226 
231  template<class Vec2D>
232  inline T operator()(const Vec2D &p) const{
233  float fX0 = p[0] - floor(p[0]), fX1 = 1.0 - fX0;
234  float fY0 = p[1] - floor(p[1]), fY1 = 1.0 - fY0;
235  const T* pLL = &operator()((int)p[0],(int)p[1]);
236  float a = *pLL; // a b
237  float b = *(++pLL); // c d
238  pLL += getWidth();
239  float d = *pLL;
240  float c = *(--pLL);
241  return fX1 * (fY1*a + fY0*c) + fX0 * (fY1*b + fY0*d);
242  }
243 
245  typedef T* iterator;
246 
248  typedef const T* const_iterator;
249 
252 
255 
258  return m_data;
259  }
260 
263  return m_data;
264  }
265 
268  return m_data+getDim();
269  }
270 
273  return m_data+getDim();
274  }
275 
278  return roi_iterator(m_data,getWidth(),getROI());
279  }
280 
282  inline const_roi_iterator beginROI() const{
283  return const_cast<Channel<T>*>(this)->beginROI();
284  }
285 
287 
288  inline roi_iterator endROI() {
290  }
291 
293  inline const_roi_iterator endROI() const{
295  }
296 
297  bool isNull() const { return !m_data; }
298 
300 
301  inline int getWidth() const { return m_size.width; }
302 
304 
305  inline int getHeight() const { return m_size.height; }
306 
308  inline const utils::Size& getSize() const { return m_size; }
309 
311 
312  inline int getDim() const { return m_size.getDim(); }
313 
315  inline const utils::Rect &getROI() const { return m_roi; }
316 
318  inline utils::Point getROIOffset() const { return m_roi.ul(); }
319 
321  inline utils::Size getROISize() const { return m_roi.getSize(); }
322 
324  inline int getROIWidth() const { return m_roi.width; }
325 
327  inline int getROIHeight() const { return m_roi.height; }
328 
330  inline int getROIXOffset() const { return m_roi.x; }
331 
333  inline int getROIYOffset() const { return m_roi.y; }
334 
336 
337  void redefineROI(const utils::Rect &newROI) const{
338  m_roi = newROI;
339  }
340 
342  void deepCopy(Channel<T> &other) const {
343  if(m_size != other.m_size){
344  throw utils::ICLException("Channel::deepCopy: sizes differ!");
345  }
347  }
348 
350  template<class OtherT>
351  void convert(Channel<OtherT> &other) const {
352  if(m_size != other.m_size){
353  throw utils::ICLException("Channel::convert: sizes differ!");
354  }
356  }
357 
358 
360  friend class Img<T>;
361 
362  private:
364 
367  inline Channel(const T *data, const utils::Size &size, const utils::Rect &roi):
368  m_data(data),m_size(size),m_roi(roi){}
369 
370  inline Channel(T *data, const utils::Size &size, const utils::Rect &roi):
371  m_data(data),m_size(size),m_roi(roi){}
372 
373  };
374 
376  #define ICL_INSTANTIATE_DEPTH(D) typedef Channel<icl##D> Channel##D;
378  #undef ICL_INSTANTIATE_DEPTH
379 
380  } // namespace core
381 }
const utils::Rect & getROI() const
returns the channel ROI
Definition: Channel.h:315
undocument this line if you encounter any issues!
Definition: Any.h:37
utils::Size m_size
Definition: Channel.h:147
utils::Point getROIOffset() const
returns the channel ROI offset
Definition: Channel.h:318
T & operator[](int idx)
working function for linear pixel array access ( not const version)
Definition: Channel.h:213
void convert(Channel< OtherT > &other) const
deeply converts the channel data (no roi support here)
Definition: Channel.h:351
#define ICL_INSTANTIATE_ALL_DEPTHS
Definition: Macros.h:175
int getROIYOffset() const
returns the channel ROI Y-Offset
Definition: Channel.h:333
int getDim() const
returns the wrapped images dim = width*height
Definition: Channel.h:312
T & operator()(int x, int y)
main working function: returns a reference to the pixel at position (x,y)
Definition: Channel.h:183
const T * const_iterator
const iterator type (just a const pointer)
Definition: Channel.h:248
ICLQt_API ImgROI roi(ImgQ &r)
creates a ROI-struct from an image
Channel(const T *data, const utils::Size &size, const utils::Rect &roi)
private constructor
Definition: Channel.h:367
const utils::Size & getSize() const
retusn the wrapped images size
Definition: Channel.h:308
T * m_data
Definition: Channel.h:146
Channel()
Empty constructor (create an invalid Channel object)
Definition: Channel.h:154
void deepCopy(Channel< T > &other) const
deeply copies the channel data (no roi support here)
Definition: Channel.h:342
const Channel< T > & operator=(const Channel< T > &other) const
assign operator (also for const channels)
Definition: Channel.h:173
Channel(T *data, const utils::Size &size, const utils::Rect &roi)
Definition: Channel.h:370
int getHeight() const
returns the wrapped images height
Definition: Channel.h:305
ICLQt_API ImgROI data(ImgQ &r)
creates full ROI ROI-struct
utils::Rect m_roi
Definition: Channel.h:148
int getROIHeight() const
returns the channel ROI height
Definition: Channel.h:327
Point ul() const
returns upper left point of the rect
Definition: Rect.h:290
roi_iterator endROI()
returns the end-iterator for an images ROI
Definition: Channel.h:288
const_roi_iterator beginROI() const
returns the iterator for an images ROI (const)
Definition: Channel.h:282
Iterator class used to iterate through an Images ROI-pixels.
Definition: ImgIterator.h:242
void redefineROI(const utils::Rect &newROI) const
Sets a new ROI to this image channel (this does not affect the underlying images ROI)
Definition: Channel.h:337
Size getSize() const
returns the size of the rect
Definition: Rect.h:324
Size class of the ICL.
Definition: Size.h:61
Utility helper class for faster and more convenient access to single channel image data.
Definition: Channel.h:145
const_roi_iterator endROI() const
returns the end-iterator for an images ROI (const)
Definition: Channel.h:293
iterator end()
returns the image end-iterator (equal to getData(channel)+getDim())
Definition: Channel.h:267
int getWidth() const
returns the wrapped images width
Definition: Channel.h:301
int getROIWidth() const
returns the channel ROI width
Definition: Channel.h:324
T & operator()(const utils::Point &p)
convenience function for point-based index access
Definition: Channel.h:189
ImgIterator< T > roi_iterator
type definition for ROI iterator
Definition: Channel.h:251
Point class of the ICL used e.g. for the Images ROI offset.
Definition: Point.h:58
const ImgIterator< T > const_roi_iterator
type definition for a const ROI iterator
Definition: Channel.h:254
const_iterator begin() const
returns the image iterator (equal to getData(channel)) (const)
Definition: Channel.h:262
Channel< T > & operator=(Channel< T > &other)
assignmet operator
Definition: Channel.h:162
const_iterator end() const
returns the image end-iterator (const)
Definition: Channel.h:272
const T & operator()(int x, int y) const
main working function: returns const a reference to the pixel at position (x,y)
Definition: Channel.h:205
Base class for Exception handling in the ICL.
Definition: Exception.h:42
iterator begin()
returns the image iterator (equal to getData(channel))
Definition: Channel.h:257
void convert(const srcT *poSrcStart, const srcT *poSrcEnd, dstT *poDst)
moves value from source to destination array (with casting on demand)
Definition: CoreFunctions.h:252
const T & operator[](int idx) const
working function for linear pixel array access (const version)
Definition: Channel.h:221
Channel(const Channel &other)
Copy an image channel (this could be exploited to violate const concept)
Definition: Channel.h:157
int getDim() const
reutrns width*height
Definition: Size.h:211
void copy(const T *src, const T *srcEnd, T *dst)
moves data from source to destination array (no casting possible)
Definition: CoreFunctions.h:216
utils::Size getROISize() const
returns the channel ROI size
Definition: Channel.h:321
Rectangle class of the ICL used e.g. for the Images ROI-rect.
Definition: Rect.h:95
const T & operator()(const utils::Point &p) const
convenience function for point-based index access (const)
Definition: Channel.h:195
int getROIXOffset() const
returns the channel ROI X-Offset
Definition: Channel.h:330
The Img class implements the ImgBase Image interface with type specific functionalities .
Definition: Img.h:49
bool isNull() const
Definition: Channel.h:297
static const ImgIterator< Type > create_end_roi_iterator(const Type *data, int width, const utils::Rect &roi)
Definition: ImgIterator.h:245
roi_iterator beginROI()
returns the iterator for an images ROI
Definition: Channel.h:277
T operator()(const Vec2D &p) const
index operator with linear interpolation
Definition: Channel.h:232
T * iterator
typedef for a normal iterator (just a pointer)
Definition: Channel.h:245