Image Component Library (ICL)
DataSegmentBase.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 : ICLGeom/src/ICLCore/DataSegmentBase.h **
10 ** Module : ICLGeom **
11 ** Authors: Christof Elbrechter, Patrick Nobou **
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 <ICLUtils/BasicTypes.h>
35 #include <ICLUtils/Exception.h>
36 #include <algorithm>
37 
38 namespace icl{
39  //forward declare PointCloudObjectBase to friend later
40  namespace geom {
42  }
43  namespace core{
44 
46  template<class T,int N> struct DataSegment;
49 
102 
103  protected:
105  static inline int getSizeOf(core::depth d){
106  static const int lens[] = { 1, 2, 4, 4, 8 };
107  return lens[(int)d];
108  }
109 
112 
114 
120  size_t stride;
121 
123  size_t numElements;
124 
126  icl32s organizedWidth; // -1 if unorganized
127 
130 
132  size_t elemDim; // number of elements (in Type units)
133 
134  public:
136  inline bool isOrganized() const {
137  return organizedWidth > 0;
138  }
139 
141  inline utils::Size getSize() const {
142  if(!isOrganized()) return utils::Size::null;
143  else return utils::Size(organizedWidth, numElements/organizedWidth);
144  }
145 
147  inline int getStride() const {
148  return stride;
149  }
150 
152 
153  inline int getDim() const{
154  return numElements;
155  }
156 
158  inline core::depth getDepth() const{
159  return dataDepth;
160  }
161 
163  inline int getElemDim() const{
164  return elemDim;
165  }
166 
168 
169  icl8u *getDataPointer() { return data; }
170 
172 
173  const icl8u *getDataPointer() const { return data; }
174 
176  inline DataSegmentBase(void *data=0, size_t stride=0,
177  size_t numElements=0, icl32s organizedWidth=-1,
178  core::depth dataDepth=core::depth8u, size_t elemDim=0):
179  data((icl8u*)data),stride(stride),numElements(numElements),
180  organizedWidth(organizedWidth),dataDepth(dataDepth),elemDim(elemDim){}
181 
183 
190  template<class T, int N>
191  const DataSegment<T,N> &as() const;
192 
196  int len;
197  Bytes(icl8u *data=0, int len=0):data(data),len(len){}
200  Bytes(const Bytes &other){}
201  friend struct DataSegmentBase;
202  public:
203 
205  inline int getDim() const{ return len; }
206 
208  icl8u &operator[](int idx) { return data[idx]; }
209 
211  const icl8u operator[](int idx) const { return data[idx]; }
212 
214 
215  inline Bytes &operator=(const Bytes &other) {
216  if(len != other.len){
217  throw utils::ICLException("unable to assign DataSegmentBase::Bytes: lengths differ!");
218  }
219  std::copy(other.data,other.data+len,data);
220  return *this;
221  }
222 
224  icl8u *begin() { return data; }
225 
227  icl8u *end() { return data+len; }
228 
230  const icl8u *begin() const { return data; }
231 
233  const icl8u *end() const { return data+len; }
234 
235  };
236 
238  inline Bytes operator[](int idx) {
239  return Bytes(data+idx*stride*getSizeOf(dataDepth), elemDim*getSizeOf(dataDepth));
240  }
241 
243  inline const Bytes operator[](int idx) const{
244  return const_cast<DataSegmentBase*>(this)->operator[](idx);
245  }
246 
248  inline Bytes operator()(int x, int y) {
249  return operator[](x + organizedWidth * y );
250  }
251 
253  inline const Bytes operator()(int x, int y) const{
254  return operator[](x + organizedWidth * y );
255  }
256  };
257 
258  } // namespace core
259 }
260 
261 
const icl8u * getDataPointer() const
returns the internal (strided) data pointer
Definition: DataSegmentBase.h:173
undocument this line if you encounter any issues!
Definition: Any.h:37
Bytes & operator=(const Bytes &other)
deep copy assignment operator
Definition: DataSegmentBase.h:215
const Bytes operator()(int x, int y) const
2D-index operator (only for organized data segments, const)
Definition: DataSegmentBase.h:253
static const Size null
null is w=0, h=0
Definition: Size.h:64
Ipp8u icl8u
8Bit unsigned integer type for the ICL
Definition: BasicTypes.h:64
icl32s organizedWidth
if > 0 , the data is 2D-organized
Definition: DataSegmentBase.h:126
icl8u * getDataPointer()
returns the internal (strided) data pointer
Definition: DataSegmentBase.h:169
Base class for point cloud data types.
Definition: PointCloudObjectBase.h:98
icl8u * data
data pointer (shallowly wrapped)
Definition: DataSegmentBase.h:195
core::depth dataDepth
underlying data depth
Definition: DataSegmentBase.h:129
size_t numElements
number of vector elements contained
Definition: DataSegmentBase.h:123
#define ICLGeom_API
Definition: CompatMacros.h:179
const icl8u operator[](int idx) const
index operator (const)
Definition: DataSegmentBase.h:211
const icl8u * end() const
iterator based access to the data end (const)
Definition: DataSegmentBase.h:233
Very simple Byte Vector class to provide binary access to DataSegmentBase data.
Definition: DataSegmentBase.h:194
const icl8u * begin() const
iterator based access to the data begin (const)
Definition: DataSegmentBase.h:230
Abstract data segment class.
Definition: DataSegmentBase.h:99
core::depth getDepth() const
returns the actual core::depth (data type) of the entries
Definition: DataSegmentBase.h:158
ICLQt_API ImgROI data(ImgQ &r)
creates full ROI ROI-struct
Ipp32s icl32s
32bit signed integer type for the ICL
Definition: BasicTypes.h:58
Definition: Types.h:61
static int getSizeOf(core::depth d)
associcates a core::depth values and the (byte)-size of the corresponding type
Definition: DataSegmentBase.h:105
size_t stride
stride between elements
Definition: DataSegmentBase.h:120
icl8u & operator[](int idx)
index operator
Definition: DataSegmentBase.h:208
Size class of the ICL.
Definition: Size.h:61
DataSegmentBase(void *data=0, size_t stride=0, size_t numElements=0, icl32s organizedWidth=-1, core::depth dataDepth=core::depth8u, size_t elemDim=0)
Constructor with given parameters.
Definition: DataSegmentBase.h:176
int getStride() const
returns the internal stride used
Definition: DataSegmentBase.h:147
int len
Definition: DataSegmentBase.h:196
const Bytes operator[](int idx) const
linear index operator (const)
Definition: DataSegmentBase.h:243
icl8u * begin()
iterator based access to the data begin
Definition: DataSegmentBase.h:224
utils::Size getSize() const
returns the ordred size of the segment of utils::Size::null if it's not organized
Definition: DataSegmentBase.h:141
depth
determines the pixel type of an image (8Bit-int or 32Bit-float)
Definition: Types.h:60
icl8u * end()
iterator based access to the data end
Definition: DataSegmentBase.h:227
Base class for Exception handling in the ICL.
Definition: Exception.h:42
size_t elemDim
vector element dim
Definition: DataSegmentBase.h:132
bool isOrganized() const
returns, whether the segment is 2D-organized
Definition: DataSegmentBase.h:136
Bytes operator()(int x, int y)
2D-index operator (only for organized data segments)
Definition: DataSegmentBase.h:248
ICLCore_API unsigned int getSizeOf(depth eDepth)
return sizeof value for the given depth type
int getElemDim() const
returns the dimension of the contained elements
Definition: DataSegmentBase.h:163
int getDim() const
returns the number of contained byte elements
Definition: DataSegmentBase.h:205
void copy(const T *src, const T *srcEnd, T *dst)
moves data from source to destination array (no casting possible)
Definition: CoreFunctions.h:216
icl8u * data
data pointer orign
Definition: DataSegmentBase.h:111
The DataSegment class defines a strided data segment (or 1D or 2D ordred array of vectors)
Definition: DataSegment.h:147
Bytes operator[](int idx)
linear index operator
Definition: DataSegmentBase.h:238
Bytes(const Bytes &other)
copy constructor (also provivate)
Definition: DataSegmentBase.h:200
int getDim() const
returns the number of elements
Definition: DataSegmentBase.h:153