itom  3.0.0
dataobj.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2016, Institut fuer Technische Optik (ITO),
5  Universitaet Stuttgart, Germany
6 
7  This file is part of itom and its software development toolkit (SDK).
8 
9  itom is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public Licence as published by
11  the Free Software Foundation; either version 2 of the Licence, or (at
12  your option) any later version.
13 
14  In addition, as a special exception, the Institut fuer Technische
15  Optik (ITO) gives you certain additional rights.
16  These rights are described in the ITO LGPL Exception version 1.0,
17  which can be found in the file LGPL_EXCEPTION.txt in this package.
18 
19  itom is distributed in the hope that it will be useful, but
20  WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
22  General Public Licence for more details.
23 
24  You should have received a copy of the GNU Library General Public License
25  along with itom. If not, see <http://www.gnu.org/licenses/>.
26  *********************************************************************** */
27 
28 #ifndef __DATAOBJH
29 #define __DATAOBJH
30 
31 #include "defines.h"
32 
33 #include <cstdlib>
34 #include <iostream>
35 #include <complex>
36 #include <limits>
37 #include <string>
38 
39 #ifdef WIN32
40  #pragma warning(disable:4996)
41 #endif
42 
43 #define NOMINMAX //see: http://social.msdn.microsoft.com/Forums/sv/vclanguage/thread/d986a370-d856-4f9e-9f14-53f3b18ab63e, this is only an issue with OpenCV 2.4.3, not 2.3.x
44 
45 #include "opencv/cv.h"
46 #include "opencv2/core/core.hpp"
47 
48 #include "../common/sharedStructures.h"
49 #include "../common/color.h"
50 #include "../common/byteArray.h"
51 
52 
53 namespace cv
54 {
55  template<> inline ito::float32 saturate_cast<ito::float32>( ito::float64 v)
56  {
57  if(cvIsInf(v)) return std::numeric_limits<ito::float32>::infinity();
58  if(cvIsNaN(v)) return std::numeric_limits<ito::float32>::quiet_NaN();
59  return static_cast<ito::float32>(std::max ( (ito::float64)(- std::numeric_limits<ito::float32>::max()) , std::min ( v , (ito::float64) std::numeric_limits<ito::float32>::max() )));
60  }
61 
62  template<> inline ito::float64 saturate_cast<ito::float64>( ito::float32 v)
63  {
64  if(cvIsInf(v)) return std::numeric_limits<ito::float64>::infinity();
65  if(cvIsNaN(v)) return std::numeric_limits<ito::float64>::quiet_NaN();
66  return static_cast<ito::float64>(v);
67  }
68 
69  template<typename _Tp> static inline _Tp saturate_cast(ito::complex128 /*v*/) { cv::error(cv::Exception(CV_StsAssert, "Not defined for input parameter type", "", __FILE__, __LINE__)); return 0; }
70  template<typename _Tp> static inline _Tp saturate_cast(ito::complex64 /*v*/) { cv::error(cv::Exception(CV_StsAssert, "Not defined for input parameter type", "", __FILE__, __LINE__)); return 0; }
71 
72  template<typename _Tp> static inline _Tp saturate_cast(ito::Rgba32 /*v*/) { cv::error(cv::Exception(CV_StsAssert, "Not defined for input parameter type", "", __FILE__, __LINE__)); return 0; }
73  // template<typename _Tp> static inline ito::Rgba32 saturate_cast(_Tp /*v*/) { cv::error(cv::Exception(CV_StsAssert, "Not defined for input parameter type", "", __FILE__, __LINE__)); return 0; }
74 
75  template<> inline ito::complex64 saturate_cast(ito::uint8 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); }
76  template<> inline ito::complex64 saturate_cast(ito::int8 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); }
77  template<> inline ito::complex64 saturate_cast(ito::uint16 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); }
78  template<> inline ito::complex64 saturate_cast(ito::int16 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); }
79  template<> inline ito::complex64 saturate_cast(ito::uint32 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); }
80  template<> inline ito::complex64 saturate_cast(ito::int32 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); }
81  template<> inline ito::complex64 saturate_cast(ito::float32 v){ return ito::complex64(v,0.0); }
82  template<> inline ito::complex64 saturate_cast(ito::float64 v){ return ito::complex64(saturate_cast<ito::float32>(v),0.0); }
83  template<> inline ito::complex64 saturate_cast(ito::complex64 v){ return v; }
84  template<> inline ito::complex64 saturate_cast(ito::complex128 v){ return std::complex<ito::float32>(saturate_cast<ito::float32>(v.real()),saturate_cast<ito::float32>(v.imag())); }
85 
86  template<> inline ito::complex128 saturate_cast(ito::uint8 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); }
87  template<> inline ito::complex128 saturate_cast(ito::int8 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); }
88  template<> inline ito::complex128 saturate_cast(ito::uint16 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); }
89  template<> inline ito::complex128 saturate_cast(ito::int16 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); }
90  template<> inline ito::complex128 saturate_cast(ito::uint32 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); }
91  template<> inline ito::complex128 saturate_cast(ito::int32 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); }
92  template<> inline ito::complex128 saturate_cast(ito::float32 v){ return ito::complex128(saturate_cast<ito::float64>(v),0.0); }
93  template<> inline ito::complex128 saturate_cast(ito::float64 v){ return ito::complex128(v,0.0); }
94  template<> inline ito::complex128 saturate_cast(ito::complex64 v){ return ito::complex128(saturate_cast<ito::float64>(v.real()),saturate_cast<ito::float64>(v.imag())); }
95  template<> inline ito::complex128 saturate_cast(ito::complex128 v){ return v; }
96 
97  // template<> inline ito::Rgba32 saturate_cast(ito::int8 v) {return ito::Rgba32(saturate_cast<ito::uint8>(v));}
98  template<> inline ito::Rgba32 saturate_cast(ito::uint8 v) {return ito::Rgba32(v);}
99  template<> inline ito::Rgba32 saturate_cast(ito::uint16 v){return ito::Rgba32(saturate_cast<ito::uint8>(v));}
100  // template<> inline ito::Rgba32 saturate_cast(ito::int16 v){return ito::Rgba32(saturate_cast<ito::uint8>(v));}
101  template<> inline ito::Rgba32 saturate_cast(ito::uint32 v)
102  {
104  }
105  template<> inline ito::Rgba32 saturate_cast(ito::int32 v)
106  {
107  ito::Rgba32 temp;
108  temp.rgba = static_cast<ito::uint32>(v);
109  return temp;
110  }
111  template<> inline ito::Rgba32 saturate_cast(ito::float32 v){return ito::Rgba32(saturate_cast<ito::uint8>(v));}
112  template<> inline ito::Rgba32 saturate_cast(ito::float64 v){return ito::Rgba32(saturate_cast<ito::uint8>(v));}
113  template<> inline ito::Rgba32 saturate_cast(ito::Rgba32 v){return v;}
114 
115  template<> inline ito::Rgba32 saturate_cast(ito::int8 /*v*/) { cv::error(cv::Exception(CV_StsAssert, "Cast from int8 to rgba32 not defined.", "", __FILE__, __LINE__)); return ito::Rgba32(); }
116  template<> inline ito::Rgba32 saturate_cast(ito::int16 /*v*/) { cv::error(cv::Exception(CV_StsAssert, "Cast from int16 to rgba32 not defined.", "", __FILE__, __LINE__)); return ito::Rgba32(); }
117  template<> inline ito::Rgba32 saturate_cast(ito::complex128 /*v*/) { cv::error(cv::Exception(CV_StsAssert, "Cast from complex128 to rgba32 not defined.", "", __FILE__, __LINE__)); return ito::Rgba32(); }
118  template<> inline ito::Rgba32 saturate_cast(ito::complex64 /*v*/) { cv::error(cv::Exception(CV_StsAssert, "Cast from complex64 to rgba32 not defined.", "", __FILE__, __LINE__)); return ito::Rgba32(); }
119 
120  template<> inline ito::uint8 saturate_cast(ito::Rgba32 v){return saturate_cast<ito::uint8>(v.gray());};
121  //template<> inline ito::int16 saturate_cast(ito::Rgba32 v){return saturate_cast<ito::int16>(v.gray());};
122  template<> inline ito::uint16 saturate_cast(ito::Rgba32 v){return saturate_cast<ito::uint16>(v.gray());};
123  template<> inline ito::uint32 saturate_cast(ito::Rgba32 v){return v.argb();};
124  template<> inline ito::int32 saturate_cast(ito::Rgba32 v){return (ito::int32)(v.argb());};
125  template<> inline ito::float32 saturate_cast(ito::Rgba32 v){return v.gray();};
126  template<> inline ito::float64 saturate_cast(ito::Rgba32 v){return (ito::float64)v.gray();};
127 
128 
129  template<> class DataType<ito::Rgba32>
130  {
131  public:
132  typedef ito::Rgba32 value_type;
133  typedef ito::uint8 channel_type;
134  typedef Vec<channel_type, 4> work_type;
135  typedef value_type vec_type;
136  enum
137  {
138  generic_type = 0,
139  depth = cv::DataDepth<channel_type>::value,
140  channels = 4,
141  fmt = ((channels-1)<<8) + cv::DataDepth<channel_type>::fmt,
142  type = CV_MAKETYPE(depth, channels)
143  };
144  };
145 
146  template<> class DataType<ito::RedChannel>
147  {
148  public:
149  typedef ito::RedChannel value_type;
150  typedef ito::uint8 channel_type;
151  typedef Vec<channel_type, 4> work_type;
152  typedef value_type vec_type;
153  enum
154  {
155  generic_type = 0,
156  depth = cv::DataDepth<channel_type>::value,
157  channels = 4,
158  fmt = ((channels-1)<<8) + cv::DataDepth<channel_type>::fmt,
159  type = CV_MAKETYPE(depth, channels)
160  };
161  };
162 
163  template<> class DataType<ito::GreenChannel>
164  {
165  public:
167  typedef ito::uint8 channel_type;
168  typedef Vec<channel_type, 4> work_type;
169  typedef value_type vec_type;
170  enum
171  {
172  generic_type = 0,
173  depth = cv::DataDepth<channel_type>::value,
174  channels = 4,
175  fmt = ((channels-1)<<8) + cv::DataDepth<channel_type>::fmt,
176  type = CV_MAKETYPE(depth, channels)
177  };
178  };
179 
180  template<> class DataType<ito::BlueChannel>
181  {
182  public:
184  typedef ito::uint8 channel_type;
185  typedef Vec<channel_type, 4> work_type;
186  typedef value_type vec_type;
187  enum
188  {
189  generic_type = 0,
190  depth = cv::DataDepth<channel_type>::value,
191  channels = 4,
192  fmt = ((channels-1)<<8) + cv::DataDepth<channel_type>::fmt,
193  type = CV_MAKETYPE(depth, channels)
194  };
195  };
196 
197  template<> class DataType<ito::AlphaChannel>
198  {
199  public:
201  typedef ito::uint8 channel_type;
202  typedef Vec<channel_type, 4> work_type;
203  typedef value_type vec_type;
204  enum
205  {
206  generic_type = 0,
207  depth = cv::DataDepth<channel_type>::value,
208  channels = 4,
209  fmt = ((channels-1)<<8) + cv::DataDepth<channel_type>::fmt,
210  type = CV_MAKETYPE(depth, channels)
211  };
212  };
213 
214 
215 } // namespace cv
216 
217 namespace ito {
218 
219 #define __ITODEBUG 1
220 
221  //forward declarations
222  class DObjIterator;
223  class DataObject;
224  class Range;
225  class DataObjectTags;
226  class DataObjectTagType;
227  class DataObjectTagsPrivate;
228 
229 
230  //----------------------------------------------------------------------------------------------------------------------------------
237  class DATAOBJ_EXPORT Range
238  {
239  public:
240  Range() : start(0), end(0) {}
241  Range(int _start, int _end) { _start < _end ? (end = _end, start = _start) : (start = _end, end = _start); }
242  inline unsigned int size() const { return end - start; }
243  inline bool empty() const { return (start == end); }
244  static Range all() { return Range(INT_MIN, INT_MAX); }
246  int start;
247  int end;
248  };
249 
250  //----------------------------------------------------------------------------------------------------------------------------------
257  class DATAOBJ_EXPORT DataObjectTagType
258  {
259  public:
260  enum tTagType
261  {
262  typeInvalid = 0x000000,
263  typeDouble = 0x000008,
264  typeString = 0x000020
265  };
266 
267  private:
268  double m_dVal;
271 
272  public:
274  DataObjectTagType() : m_dVal(0), m_strValue(""), m_type(DataObjectTagType::typeInvalid){}
275  DataObjectTagType(double dVal) : m_dVal(dVal), m_strValue(""), m_type(DataObjectTagType::typeDouble){}
276  DataObjectTagType(const std::string &str) : m_dVal(std::numeric_limits<double>::quiet_NaN()), m_type(DataObjectTagType::typeString){ m_strValue = str.data(); }
277  DataObjectTagType(const ByteArray &str) : m_dVal(std::numeric_limits<double>::quiet_NaN()), m_type(DataObjectTagType::typeString){ m_strValue = str; }
278  DataObjectTagType(const char* cVal) : m_dVal(std::numeric_limits<double>::quiet_NaN()), m_type(DataObjectTagType::typeString){ cVal == NULL ? m_strValue = "" : m_strValue = cVal;}
280  DataObjectTagType(const DataObjectTagType& a) : m_dVal(a.m_dVal), m_type(a.m_type), m_strValue(a.m_strValue) {}
281 
283  DataObjectTagType & operator = (const DataObjectTagType &rhs)
284  {
285  this->m_dVal = rhs.m_dVal;
286  this->m_strValue = rhs.m_strValue;
287  this->m_type = rhs.m_type;
288 
289  return *this;
290  }
291 
293  inline int getType(void) const {return m_type;}
294 
296  inline bool isValid(void) const { return (m_type == DataObjectTagType::typeInvalid) ? false: true;}
297 
303  inline double getVal_ToDouble(void)
304  {
305  if(m_type == DataObjectTagType::typeInvalid)
306  {
307  return std::numeric_limits<double>::quiet_NaN();
308  }
309  else if(m_type == DataObjectTagType::typeDouble)
310  {
311  return m_dVal;
312  }
313  else
314  {
315  double dVal = std::numeric_limits<double>::quiet_NaN();
316  //dVal = atof(m_strValue.c_str()); //sometimes the result of that line has been arbitrary, therefore this conversion should fail.
317  return dVal;
318  }
319  }
320 
327  {
328  if(m_type == DataObjectTagType::typeInvalid)
329  {
330  return "";
331  }
332  else if(m_type == DataObjectTagType::typeString)
333  {
334  return m_strValue;
335  }
336  else
337  {
338  if (cvIsNaN(m_dVal)) return "NaN";
339  if (cvIsInf(m_dVal)) return "Inf";
340 
341  std::ostringstream strs;
342  strs << m_dVal;
343  ByteArray ba(strs.str().data());
344 
345  return ba;
346  }
347  }
348  };
349 
350  //----------------------------------------------------------------------------------------------------------------------------------
361  class DATAOBJ_EXPORT DObjConstIterator
362  {
363  public:
364 
367 
369  DObjConstIterator(const DataObject* _dObj, int pos = 0);
370 
373 
375  DObjConstIterator& operator = (const DObjConstIterator& it);
376 
378  const uchar* operator *() const;
379 
381  const uchar* operator [](int i) const;
382 
384  DObjConstIterator& operator += (int ofs);
385 
387  DObjConstIterator& operator -= (int ofs);
388 
390  DObjConstIterator& operator --();
391 
393  DObjConstIterator operator --(int);
394 
396  DObjConstIterator& operator ++();
397 
399  DObjConstIterator operator ++(int);
400 
401  bool operator == (const DObjConstIterator& dObjIt);
402  bool operator != (const DObjConstIterator& dObjIt);
403  bool operator < (const DObjConstIterator& dObjIt);
404  bool operator > (const DObjConstIterator& dObjIt);
405  bool operator <= (const DObjConstIterator& dObjIt);
406  bool operator >= (const DObjConstIterator& dObjIt);
407 
408  protected:
410  void seekAbs(int ofs);
411 
413  void seekRel(int ofs);
414 
415  const DataObject* dObj;
417  int elemSize;
418  uchar* ptr;
419  uchar* sliceStart;
420  uchar* sliceEnd;
421  int plane;
422  };
423 
424  //----------------------------------------------------------------------------------------------------------------------------------
433  class DATAOBJ_EXPORT DObjIterator : public DObjConstIterator
434  {
435  public:
436 
438  DObjIterator();
439 
441  DObjIterator(DataObject* _dObj, int pos = 0);
442 
444  DObjIterator(const DObjIterator& it);
445 
447  DObjIterator& operator = (const DObjIterator& it);
448 
450  uchar* operator *();
451 
453  uchar* operator [](int i);
454 
456  DObjIterator& operator += (int ofs);
457 
459  DObjIterator& operator -= (int ofs);
460 
462  DObjIterator& operator --();
463 
465  DObjIterator operator --(int);
466 
468  DObjIterator& operator ++();
469 
471  DObjIterator operator ++(int);
472  };
473 
474 //----------------------------------------------------------------------------------------------------------------------------------
475 
476 // Forward declaration of friend methods
477 #ifdef __APPLE__
478  template<typename _Tp> RetVal CreateFunc(DataObject *dObj, const unsigned char dimensions, const int *sizes, const unsigned char continuous, const uchar* continuousDataPtr, const int* steps);
479  template<typename _Tp> RetVal CreateFuncWithCVPlanes(DataObject *dObj, const unsigned char dimensions, const int *sizes, const cv::Mat* planes, const unsigned int nrOfPlanes);
480  template<typename _Tp> RetVal FreeFunc(DataObject *dObj);
481  template<typename _Tp> RetVal SecureFreeFunc(DataObject *dObj);
482  template<typename _Tp> RetVal CopyToFunc(const DataObject &lhs, DataObject &rhs, unsigned char regionOnly);
483  template<typename _Tp> RetVal ConvertToFunc(const DataObject &lhs, DataObject &rhs, const int type, const double alpha, const double beta);
484  template<typename _Tp> RetVal AdjustROIFunc(DataObject *dObj, const int *lims);
485  template<typename _Tp> RetVal MinMaxLocFunc(const DataObject &dObj, double *minVal, double *maxVal, int *minPos, int *maxPos);
486  template<typename _Tp> RetVal AssignScalarFunc(const DataObject *src, const ito::tDataType type, const void *scalar);
487  template<typename _Tp> RetVal MakeContinuousFunc(const DataObject &dObj, DataObject &resDObj);
488  template<typename _Tp> RetVal EvaluateTransposeFlagFunc(DataObject *dObj);
489  template<typename _Tp> std::ostream& coutFunc(std::ostream& out, const DataObject& dObj);
490 
491  // more friends due to change of std::vector to int ** for m_data ...
492  template<typename _Tp> RetVal GetRangeFunc(DataObject *dObj, const int dtop, const int dbottom, const int dleft, const int dright);
493  template<typename _Tp> RetVal AdjustROIFunc(DataObject *dObj, int dtop, int dbottom, int dleft, int dright);
494 #endif // __APPLE__
495 
496  class DATAOBJ_EXPORT DataObject
497  {
498  private:
500  void createHeader(const unsigned char dimensions, const int *sizes, const int *steps, const int elemSize);
501 
503  void createHeaderWithROI(const unsigned char dimensions, const int *sizes, const int *osizes = NULL, const int *roi = NULL);
504 
505  void create(const unsigned char dimensions, const int *sizes, const int type, const unsigned char continuous, const uchar* continuousDataPtr = NULL, const int* steps = NULL);
506  void create(const unsigned char dimensions, const int *sizes, const int type, const cv::Mat* planes, const unsigned int nrOfPlanes);
507 
508  void freeData(void);
509  void secureFreeData(void);
512  //----------------------------------------------------------------------------------------------------------------------------------
513  ito::RetVal matNumToIdx(const int matNum, int *matIdx) const;
514 
516  ito::RetVal matIdxToNum(const unsigned int *matIdx, int *matNum) const;
517 
518 
519  struct DATAOBJ_EXPORT MSize
520  {
521  inline MSize() : m_p(NULL) {}
522  inline int operator [] (const int dim) const
523  {
524  return m_p[dim]; //return the size value. this operator corresponds to the real data representation in memory
525  };
526  inline operator const int * () const { return m_p; }
527  inline bool operator == (const MSize& sz) const
528  {
529  if(m_p == NULL || sz.m_p == NULL)
530  {
531  return sz.m_p == m_p;
532  }
533 
534  int d = m_p[-1];
535  if( d != sz.m_p[-1] )
536  return false;
537 
538  return (memcmp(m_p, sz.m_p, d * sizeof(int)) == 0); //returns true if the size vector (having the same length) is equal
539  }
540 
541  inline bool operator != (const MSize& sz) const { return !(*this == sz); }
542 
543  int *m_p;
544  };
545 
546 
547  struct DATAOBJ_EXPORT MROI
548  {
549  inline MROI() : m_p(NULL) {};
550  inline int operator [] (const int dim) const
551  {
552  return m_p[dim]; //return the size value. this operator corresponds to the real data representation in memory
553  }
554 
555  inline bool operator == (const MROI & rroi) const
556  {
557  if(m_p == NULL || rroi.m_p == NULL)
558  {
559  return rroi.m_p == m_p;
560  }
561 
562  int d = m_p[-1];
563  if( d != rroi.m_p[-1] )
564  return false;
565 
566  return (memcmp(m_p, rroi.m_p, d * sizeof(int)) == 0); //returns true if the size vector (having the same length) is equal
567 
568  if (m_p[-1] != rroi.m_p[-1])
569  {
570  return false;
571  }
572  }
573 
574  int *m_p;
575  };
576 
577  DataObject(const DataObject& dObj, bool transposed);
580  char m_owndata;
581  int m_type;
582  int *m_pRefCount;
583  int m_dims;
587  uchar **m_data;
589  static const int m_sizeofs;
590 
591  int mdata_realloc(const int size);
592  int mdata_size(void) const;
593  int mdata_free();
594 
595  RetVal copyFromData2DInternal(const uchar* src, const int sizeOfElem, const int sizeX, const int sizeY);
596  RetVal copyFromData2DInternal(const uchar* src, const int sizeOfElem, const int sizeX, const int x0, const int y0, const int width, const int height);
597 
598  //low-level, templated methods
599  //most low-level methods are marked "friend" such that they can access private members of their data object parameters
600  template<typename _Tp> friend RetVal CreateFunc(DataObject *dObj, const unsigned char dimensions, const int *sizes, const unsigned char continuous, const uchar* continuousDataPtr, const int* steps);
601  template<typename _Tp> friend RetVal CreateFuncWithCVPlanes(DataObject *dObj, const unsigned char dimensions, const int *sizes, const cv::Mat* planes, const unsigned int nrOfPlanes);
602  template<typename _Tp> friend RetVal FreeFunc(DataObject *dObj);
603  template<typename _Tp> friend RetVal SecureFreeFunc(DataObject *dObj);
604  template<typename _Tp> friend RetVal CopyToFunc(const DataObject &lhs, DataObject &rhs, unsigned char regionOnly);
605  template<typename _Tp> friend RetVal ConvertToFunc(const DataObject &lhs, DataObject &rhs, const int type, const double alpha, const double beta);
606  template<typename _Tp> friend RetVal AdjustROIFunc(DataObject *dObj, const int *lims);
607  template<typename _Tp> friend RetVal MinMaxLocFunc(const DataObject &dObj, double *minVal, double *maxVal, int *minPos, int *maxPos);
608  template<typename _Tp> friend RetVal AssignScalarFunc(const DataObject *src, const ito::tDataType type, const void *scalar);
609  template<typename _Tp> friend RetVal MakeContinuousFunc(const DataObject &dObj, DataObject &resDObj);
610  template<typename _Tp> friend RetVal EvaluateTransposeFlagFunc(DataObject *dObj);
611  template<typename _Tp> friend std::ostream& coutFunc(std::ostream& out, const DataObject& dObj);
612 
613  // more friends due to change of std::vector to int ** for m_data ...
614  template<typename _Tp> friend RetVal GetRangeFunc(DataObject *dObj, const int dtop, const int dbottom, const int dleft, const int dright);
615  template<typename _Tp> friend RetVal AdjustROIFunc(DataObject *dObj, int dtop, int dbottom, int dleft, int dright);
616 
617  public:
619  DataObject(void);
620 
622  DataObject(const int size, const int type);
623 
625  DataObject(const int sizeY, const int sizeX, const int type);
626 
628  DataObject(const int sizeZ, const int sizeY, const int sizeX, const int type, const unsigned char continuous = 0);
629 
631  DataObject(const int sizeZ, const int sizeY, const int sizeX, const int type, const uchar* continuousDataPtr, const int* steps = NULL);
632 
634  DataObject(const MSize &sizes, const int type, const unsigned char continuous = 0);
635 
637  DataObject(const unsigned char dimensions, const int *sizes, const int type, const unsigned char continuous = 0);
638 
640  DataObject(const unsigned char dimensions, const int *sizes, const int type, const uchar* continuousDataPtr, const int* steps = NULL);
641 
643  DataObject(const unsigned char dimensions, const int *sizes, const int type, const cv::Mat* planes, const unsigned int nrOfPlanes);
644 
646  DataObject(const cv::Mat &data);
647 
648  DataObject(const DataObject& copyConstr);
650  ~DataObject(void);
652 
653  // TAGSPACEFUNCTIONS
654 
656  double getValueOffset() const;
657 
659  double getValueScale() const;
660 
662  const std::string getValueUnit() const;
663 
665  std::string getValueDescription() const;
666 
668  double getAxisOffset(const int axisNum) const;
669 
671  double getAxisScale(const int axisNum) const;
672 
674  const std::string getAxisUnit(const int axisNum, bool &validOperation) const;
675 
677  std::string getAxisDescription(const int axisNum, bool &validOperation) const;
678 
679  DataObjectTagType getTag(const std::string &key, bool &validOperation) const;
680 
681  bool getTagByIndex(const int tagNumber, std::string &key, DataObjectTagType &value) const;
682 
684  std::string getTagKey(const int tagNumber, bool &validOperation) const;
685 
687  int getTagListSize() const;
688 
690  int setValueUnit(const std::string &unit);
691 
693  int setValueDescription(const std::string &description);
694 
696  int setAxisOffset(const unsigned int axisNum, const double offset);
697 
699  int setAxisScale(const unsigned int axisNum, const double scale);
700 
702  int setAxisUnit(const unsigned int axisNum, const std::string &unit);
703 
705  int setAxisDescription(const unsigned int axisNum, const std::string &description);
706  int setTag(const std::string &key, const DataObjectTagType &value);
707  bool existTag(const std::string &key) const;
708  bool deleteTag(const std::string &key);
709  bool deleteAllTags();
710  int addToProtocol(const std::string &value);
711 
712 
716  double getPhysToPix(const unsigned int dim, const double phys, bool &isInsideImage) const;
717 
721  double getPhysToPix(const unsigned int dim, const double phys) const;
722 
726  int getPhysToPix2D(const double physY, double &tPxY, bool &isInsideImageY, const double physX, double &tPxX, bool &isInsideImageX) const;
727 
731  double getPixToPhys(const unsigned int dim, const double pix, bool &isInsideImage) const;
732 
736  double getPixToPhys(const unsigned int dim, const double pix) const;
737 
751  RetVal setXYRotationalMatrix(double r11, double r12, double r13, double r21, double r22, double r23, double r31, double r32, double r33);
752 
766  RetVal getXYRotationalMatrix(double &r11, double &r12, double &r13, double &r21, double &r22, double &r23, double &r31, double &r32, double &r33) const;
767 
768  RetVal copyTagMapTo(DataObject &rhs) const;
769  RetVal copyAxisTagsTo(DataObject &rhs) const;
771  // END TAGSPACE
772 
774  inline int getDims(void) const { return m_dims; }
775 
777  inline int getType(void) const { return m_type; }
778 
780  inline char getContinuous(void) const { return m_continuous; }
781 
783  inline char getOwnData(void) const { return m_owndata; }
784 
786  int seekMat(const int matNum, const int numMats) const;
787 
789  int seekMat(const int matNum) const;
790 
792  int calcNumMats(void) const;
793 
795 
800  inline int getNumPlanes(void) const
801  {
802  switch (m_dims)
803  {
804  case 0:
805  return 0;
806  case 1:
807  case 2:
808  return 1;
809  case 3:
810  return m_size[0];
811  case 4:
812  return m_size[0] * m_size[1];
813  default:
814  {
815  int numMat = 1;
816  for (int n = 0; n < m_dims - 2; n++)
817  {
818  numMat *= m_size[n];
819  }
820  return numMat;
821  }
822  }
823  }
824 
826  cv::Mat* getCvPlaneMat(const int planeIndex);
827 
829  const cv::Mat* getCvPlaneMat(const int planeIndex) const;
830 
832  const cv::Mat getContinuousCvPlaneMat(const int planeIndex) const;
833 
835 
844  inline cv::Mat** get_mdata(void)
845  {
846  return (cv::Mat**)m_data;
847  }
848 
850 
859  inline const cv::Mat** get_mdata(void) const
860  {
861  return (const cv::Mat**)m_data;
862  }
863 
865 
868  inline MSize getSize(void) { return m_size; }
869 
871 
874  inline const MSize getSize(void) const { return m_size; }
875 
877 
881  inline int getSize(int index) const
882  {
883  if(index < 0 || index >= m_dims)
884  {
885  return -1;
886  }
887  else
888  {
889  return m_size[index];
890  }
891  }
892 
894 
897  inline MSize getOriginalSize(void) { return m_osize; }
898 
900 
903  inline const MSize getOriginalSize(void) const { return m_osize; }
904 
906 
910  inline int getOriginalSize(int index) const
911  {
912  if(index < 0 || index >= m_dims)
913  {
914  return -1;
915  }
916  else
917  {
918  return m_osize[index];
919  }
920  }
921 
923 
930  int getStep(int index) const;
931 
932 
934 
938  inline int getTotal() const
939  {
940  int dims = getDims();
941  int total = dims > 0 ? 1 : 0;
942  for(int i = 0 ; i < dims ; i++)
943  {
944  total *= m_size[i];
945  }
946  return total;
947 
948  }
949 
951 
955  inline int getOriginalTotal() const
956  {
957  int dims = getDims();
958  int total = dims > 0 ? 1 : 0;
959  for(int i = 0 ; i<dims ; i++)
960  {
961  total *= m_osize[i];
962  }
963  return total;
964  }
965 
966  RetVal copyTo(DataObject &rhs, unsigned char regionOnly = 0) const;
967  RetVal convertTo(DataObject &rhs, const int type, const double alpha=1, const double beta=0 ) const;
969  RetVal setTo(const int8 &value, const DataObject &mask = DataObject());
970  RetVal setTo(const uint8 &value, const DataObject &mask = DataObject());
971  RetVal setTo(const int16 &value, const DataObject &mask = DataObject());
972  RetVal setTo(const uint16 &value, const DataObject &mask = DataObject());
973  RetVal setTo(const int32 &value, const DataObject &mask = DataObject());
974  RetVal setTo(const uint32 &value, const DataObject &mask = DataObject());
975  RetVal setTo(const float32 &value, const DataObject &mask = DataObject());
976  RetVal setTo(const float64 &value, const DataObject &mask = DataObject());
977  RetVal setTo(const complex64 &value, const DataObject &mask = DataObject());
978  RetVal setTo(const complex128 &value, const DataObject &mask = DataObject());
979  RetVal setTo(const ito::Rgba32 &value, const DataObject &mask = DataObject());
981  RetVal deepCopyPartial(DataObject &copyTo);
983 
985  DObjIterator begin();
987  DObjIterator end();
988 
990  DObjConstIterator constBegin() const;
991 
993  DObjConstIterator constEnd() const;
994 
996  DataObject & operator = (const cv::Mat &rhs);
997  DataObject & operator = (const DataObject &rhs);
998  DataObject & operator = (const int8 &value);
999  DataObject & operator = (const uint8 &value);
1000  DataObject & operator = (const int16 &value);
1001  DataObject & operator = (const uint16 &value);
1002  DataObject & operator = (const int32 &value);
1003  DataObject & operator = (const uint32 &value);
1004  DataObject & operator = (const float32 &value);
1005  DataObject & operator = (const float64 &value);
1006  DataObject & operator = (const complex64 &value);
1007  DataObject & operator = (const complex128 &value);
1008  DataObject & operator = (const ito::Rgba32 &value);
1011  DataObject & operator += (const DataObject &rhs);
1012  DataObject & operator += (const float64 &value);
1013  DataObject & operator += (const complex128 &value);
1014 
1015  DataObject operator + (const DataObject &rhs);
1016  DataObject operator + (const float64 &value);
1017  DataObject operator + (const complex128 &value);
1018 
1019  DataObject & operator -= (const DataObject &rhs);
1020  DataObject & operator -= (const float64 &value);
1021  DataObject & operator -= (const complex128 &value);
1022 
1023  DataObject operator - (const DataObject &rhs);
1024  DataObject operator - (const float64 &value);
1025  DataObject operator - (const complex128 &value);
1026 
1027  DataObject & operator *= (const DataObject &rhs);
1028  DataObject & operator *= (const float64 &factor);
1029  DataObject & operator *= (const complex128 &factor);
1030 
1031  DataObject operator * (const DataObject &rhs);
1032  DataObject operator * (const float64 &factor);
1033  DataObject operator * (const complex128 &factor);
1034 
1035  // Comparison Operators
1036  DataObject operator < (DataObject &rhs);
1037  DataObject operator > (DataObject &rhs);
1038  DataObject operator <= (DataObject &rhs);
1039  DataObject operator >= (DataObject &rhs);
1040  DataObject operator == (DataObject &rhs);
1041  DataObject operator != (DataObject &rhs);
1042 
1043  DataObject operator < (const float64 &value);
1044  DataObject operator > (const float64 &value);
1045  DataObject operator <= (const float64 &value);
1046  DataObject operator >= (const float64 &value);
1047  DataObject operator == (const float64 &value);
1048  DataObject operator != (const float64 &value);
1049 
1050  // bitshift operators
1051  DataObject operator << (const unsigned int shiftbit);
1052  DataObject & operator <<= (const unsigned int shiftbit);
1053  DataObject operator >> (const unsigned int shiftbit);
1054  DataObject & operator >>= (const unsigned int shiftbit);
1055 
1056  // bitwise operators
1057  DataObject operator & (const DataObject & rhs);
1058  DataObject & operator &= (const DataObject & rhs);
1059  DataObject operator | (const DataObject & rhs);
1060  DataObject & operator |= (const DataObject & rhs);
1061  DataObject operator ^ (const DataObject & rhs);
1062  DataObject & operator ^= (const DataObject & rhs);
1063  DataObject bitwise_not() const;
1065  // allocates matrix with zero values
1066  RetVal zeros(const int type);
1067  RetVal zeros(const int size, const int type);
1068  RetVal zeros(const int sizeY, const int sizeX, const int type);
1069  RetVal zeros(const int sizeZ, const int sizeY, const int sizeX, const int type, const unsigned char continuous = 0);
1070  RetVal zeros(const unsigned char dimensions, const int *sizes, const int type, const unsigned char continuous = 0);
1071 
1072  // allocates matrix with all values set to one
1073  RetVal ones(const int type);
1074  RetVal ones(const int size, const int type);
1075  RetVal ones(const int sizeY, const int sizeX, const int type);
1076  RetVal ones(const int sizeZ, const int sizeY, const int sizeX, const int type, const unsigned char continuous = 0);
1077  RetVal ones(const unsigned char dimensions, const int *sizes, const int type, const unsigned char continuous = 0);
1078 
1079  // allocates matrix with uniform distributed noise
1080  RetVal rand(const int type, const bool randMode = false);
1081  RetVal rand(const int size, const int type, const bool randMode = false);
1082  RetVal rand(const int sizeY, const int sizeX, const int type, const bool randMode = false);
1083  RetVal rand(const int sizeZ, const int sizeY, const int sizeX, const int type, const bool randMode, const unsigned char continuous = 0);
1084  RetVal rand(const unsigned char dimensions, const int *sizes, const int type, const bool randMode, const unsigned char continuous = 0);
1085 
1086  // allocates matrix with eye-matrix representation
1087  RetVal eye(const int type);
1088  RetVal eye(const int size, const int type);
1089 
1090  RetVal conj();
1091  DataObject adj() const;
1092  DataObject trans() const;
1093 
1094  // element-wise multiplication
1095  DataObject mul(const DataObject &mat2, const double scale = 1.0) const;
1096  DataObject div(const DataObject &mat2, const double scale = 1.0) const;
1097 
1098 
1099 
1100  // power (power of 0.5 is the square root)
1101  DataObject pow(const ito::float64 &power); // returns a new data object with the same size and type than this data object and calculates src**power if power is an integer, else |src|**power (only for float32 and float64 data objects)
1102  void pow(const ito::float64 &power, DataObject &dst); // this function raises every element of this data object to *power* and saves the result in dst. Dst must be of the same size and type than this data object or empty. In the latter case, it is reassigned to the right size and type.
1103 
1104  DataObject sqrt(); // returns a new data object of the same size and type than this data object where the square root of every element is calculated. Is the same than pow(0.5)
1105  void sqrt(DataObject &dst); // this function calculates the square root of every element and saves the result in dst. Dst must be of the same size and type than this data object or empty. In the latter case, it is reassigned to the right size and type.. Is the same than pow(0.5, dst)
1106 
1107  DataObject squeeze() const;
1108  DataObject reshape(int newDims, const int *newSizes) const;
1109 
1110  int elemSize() const;
1112 
1118  template<typename _Tp> inline const _Tp& at(const unsigned int y, const unsigned int x) const
1119  {
1120 #if __ITODEBUG
1121  if (m_dims != 2)
1122  {
1123  cv::error(cv::Exception(CV_StsAssert, "Dimension mismatch while addressing data field", "", __FILE__, __LINE__));
1124  }
1125  else if (((int)x >= m_size[1]) || ((int)y >= m_size[0]) )
1126  {
1127  cv::error(cv::Exception(CV_StsAssert, "Index out of bounds", "", __FILE__ , __LINE__));
1128  }
1129 #endif
1130  return (*reinterpret_cast<const cv::Mat_<_Tp>*>(m_data[0]))(y, x);
1131  }
1132 
1134 
1139  template<typename _Tp> inline _Tp& at(const unsigned int y, const unsigned int x)
1140  {
1141 #if __ITODEBUG
1142  if (m_dims != 2)
1143  {
1144  cv::error(cv::Exception(CV_StsAssert, "Dimension mismatch while addressing data field", "", __FILE__, __LINE__));
1145  }
1146  else if (((int)x >= m_size[1]) || ((int)y >= m_size[0]) )
1147  {
1148  cv::error(cv::Exception(CV_StsAssert, "Index out of bounds", "", __FILE__ , __LINE__));
1149  }
1150 #endif
1151  return (*reinterpret_cast<cv::Mat_<_Tp>*>(m_data[0]))(y, x);
1152  }
1153 
1155 
1161  template<typename _Tp> inline const _Tp& at(const unsigned int z, const unsigned int y, const unsigned int x) const
1162  {
1163 #if __ITODEBUG
1164  if (m_dims != 3)
1165  {
1166  cv::error(cv::Exception(CV_StsAssert, "Dimension mismatch while addressing data field", "", __FILE__, __LINE__));
1167  }
1168  else if (((int)x >= m_size[2]) || ((int)y >= m_size[1]) || (((int)z + m_roi[0]) >= (m_roi[0] + m_size[0])))
1169  {
1170  cv::error(cv::Exception(CV_StsAssert, "Index out of bounds", "", __FILE__ , __LINE__));
1171  }
1172 #endif
1173  return (*reinterpret_cast<const cv::Mat_<_Tp>*>(m_data[z + m_roi[0]]))(y, x);
1174  }
1175 
1177 
1183  template<typename _Tp> inline _Tp& at(const unsigned int z, const unsigned int y, const unsigned int x)
1184  {
1185 #if __ITODEBUG
1186  if (m_dims != 3)
1187  {
1188  cv::error(cv::Exception(CV_StsAssert, "Dimension mismatch while addressing data field", "", __FILE__, __LINE__));
1189  }
1190  else if (((int)x >= m_size[2]) || ((int)y >= m_size[1]) || (((int)z + m_roi[0]) >= (m_roi[0] + m_size[0])))
1191  {
1192  cv::error(cv::Exception(CV_StsAssert, "Index out of bounds", "", __FILE__ , __LINE__));
1193  }
1194 #endif
1195  return (*reinterpret_cast<cv::Mat_<_Tp>*>(m_data[z + m_roi[0]]))(y, x);
1196  }
1197 
1199 
1204  template<typename _Tp> inline const _Tp& at(const unsigned int *idx) const //idx is in virtual order
1205  {
1206  int matNum = 0;
1207  matIdxToNum(idx, &matNum);
1208  return (*reinterpret_cast<const cv::Mat_<_Tp>*>(m_data[matNum]))(idx[m_dims - 2], idx[m_dims - 1]);
1209  }
1210 
1212 
1217  template<typename _Tp> inline _Tp& at(const unsigned int *idx) //idx is in virtual order
1218  {
1219  int matNum = 0;
1220  matIdxToNum(idx, &matNum);
1221  return (*reinterpret_cast<cv::Mat_<_Tp>*>(m_data[matNum]))(idx[m_dims - 2], idx[m_dims - 1]);
1222  }
1223 
1224  DataObject at(const ito::Range &rowRange, const ito::Range &colRange) const;
1225  DataObject at(ito::Range *ranges) const;
1226  DataObject at(const DataObject &mask) const;
1228 
1235  inline uchar* rowPtr(const int matNum, const int y)
1236  {
1237  int matIndex = seekMat(matNum);
1238  return ((cv::Mat*)m_data[matIndex])->ptr(y);
1239  }
1240 
1242 
1248  inline const uchar* rowPtr(const int matNum, const int y) const
1249  {
1250  int matIndex = seekMat(matNum);
1251  return ((const cv::Mat*)m_data[matIndex])->ptr(y);
1252  }
1253 
1255 
1262  template<typename _Tp> inline _Tp* rowPtr(const int matNum, const int y)
1263  {
1264  int matIndex = seekMat(matNum);
1265  return ((cv::Mat*)m_data[matIndex])->ptr<_Tp>(y);
1266  }
1267 
1269 
1276  template<typename _Tp> inline const _Tp* rowPtr(const int matNum, const int y) const
1277  {
1278  int matIndex = seekMat(matNum);
1279  return ((const cv::Mat*)m_data[matIndex])->ptr<_Tp>(y);
1280  }
1281 
1282  DataObject row(const int selRow) const;
1283  DataObject col(const int selCol) const;
1284 
1285  DataObject toGray(const int destinationType = ito::tUInt8) const;
1286  DataObject splitColor(const char* destinationColor, const int& dtype) const;
1287 
1288  // ROI
1289  DataObject & adjustROI(const int dtop, const int dbottom, const int dleft, const int dright);
1290  DataObject & adjustROI(const unsigned char dims, const int *lims);
1291  RetVal locateROI(int *wholeSizes, int *offsets) const;
1292  RetVal locateROI(int *lims) const;
1294 
1310  template<typename _Tp> RetVal copyFromData2D(const _Tp* src, const int sizeX, const int sizeY) { return copyFromData2DInternal((const uchar*)src, sizeof(_Tp), sizeX, sizeY); } // copies 2D continuous data into data object, data object must have correct size and type, otherwise an error is returned
1311 
1313 
1337  template<typename _Tp> RetVal copyFromData2D(const _Tp *src, const int sizeX, const int sizeY, const int x0, const int y0, const int width, const int height) { return copyFromData2DInternal((const uchar*)src, sizeof(_Tp), sizeX, x0, y0, width, height); } // copies 2D continuous data into data object, data object must have correct size and type, otherwise an error is returned
1338 
1339  template<typename T2> operator T2 ();
1341  template<typename _Tp> RetVal linspace(const _Tp start, const _Tp end, const _Tp inc, const int transposed);
1342 
1344 
1348  static DataObject stack(const DataObject *mats, int num, unsigned int axis = 0);
1349 
1350  };
1351 
1352  //template<> DATAOBJ_EXPORT RetVal ito::DataObject::linspace<ito::int8>(const ito::int8 /*start*/, const ito::int8 /*end*/, const ito::int8 /*inc*/, const int /*transposed*/);
1353  //template<> DATAOBJ_EXPORT RetVal ito::DataObject::linspace<ito::uint8>(const ito::uint8 /*start*/, const ito::uint8 /*end*/, const ito::uint8 /*inc*/, const int /*transposed*/);
1354 
1355 
1356  //----------------------------------------------------------------------------------------------------------------------------------
1357  // functions for DataObject in namespace ITO, which are NOT member functions
1358  //----------------------------------------------------------------------------------------------------------------------------------
1359  DATAOBJ_EXPORT DataObject abs(const DataObject &dObj);
1360  DATAOBJ_EXPORT DataObject arg(const DataObject &dObj);
1361  DATAOBJ_EXPORT DataObject real(const DataObject &dObj);
1362  DATAOBJ_EXPORT DataObject imag(const DataObject &dObj);
1364  DATAOBJ_EXPORT DataObject makeContinuous(const DataObject &dObj);
1366 
1374  template<typename _Tp> inline _Tp numberConversion(ito::tDataType fromType, const void *scalar)
1375  {
1376  _Tp retValue;
1377 
1378  switch(fromType)
1379  {
1380  case ito::tUInt8:
1381  retValue = cv::saturate_cast<_Tp>(*(static_cast<const uint8*>(scalar)));
1382  break;
1383  case ito::tInt8:
1384  retValue = cv::saturate_cast<_Tp>(*(static_cast<const int8*>(scalar)));
1385  break;
1386  case ito::tUInt16:
1387  retValue = cv::saturate_cast<_Tp>(*(static_cast<const uint16*>(scalar)));
1388  break;
1389  case ito::tInt16:
1390  retValue = cv::saturate_cast<_Tp>(*(static_cast<const int16*>(scalar)));
1391  break;
1392  case ito::tUInt32:
1393  retValue = cv::saturate_cast<_Tp>(*(static_cast<const uint32*>(scalar)));
1394  break;
1395  case ito::tInt32:
1396  retValue = cv::saturate_cast<_Tp>(*(static_cast<const int32*>(scalar)));
1397  break;
1398  case ito::tFloat32:
1399  retValue = cv::saturate_cast<_Tp>(*(static_cast<const ito::float32*>(scalar)));
1400  break;
1401  case ito::tFloat64:
1402  retValue = cv::saturate_cast<_Tp>(*(static_cast<const ito::float64*>(scalar)));
1403  break;
1404  case ito::tComplex64:
1405  retValue = cv::saturate_cast<_Tp>(*(static_cast<const ito::complex64*>(scalar)));
1406  break;
1407  case ito::tComplex128:
1408  retValue = cv::saturate_cast<_Tp>(*(static_cast<const ito::complex128*>(scalar)));
1409  break;
1410  case ito::tRGBA32:
1411  retValue = cv::saturate_cast<_Tp>(*(static_cast<const ito::Rgba32*>(scalar)));
1412  break;
1413  default:
1414  cv::error(cv::Exception(CV_StsAssert, "Input value type unkown", "", __FILE__, __LINE__));
1415  retValue = 0;
1416  }
1417 
1418  return retValue;
1419  };
1420 
1422  DATAOBJ_EXPORT std::ostream& operator << (std::ostream& out, const DataObject& dObj);
1423 
1425 
1433  {
1434  switch(cmplxType)
1435  {
1436  case ito::tInt8:
1437  case ito::tUInt8:
1438  case ito::tInt16:
1439  case ito::tUInt16:
1440  case ito::tInt32:
1441  case ito::tUInt32:
1442  case ito::tFloat32:
1443  case ito::tFloat64:
1444  case ito::tRGBA32:
1445  return cmplxType;
1446  case ito::tComplex64:
1447  return ito::tFloat32;
1448  case ito::tComplex128:
1449  return ito::tFloat64;
1450  }
1451 
1452  cv::error(cv::Exception(CV_StsAssert, "Input data type unknown", "", __FILE__, __LINE__));
1453  return ito::tInt8;
1454  }
1455 
1457 
1464  inline ito::tDataType guessDataTypeFromCVMat(const cv::Mat* mat, ito::RetVal &retval)
1465  {
1466  if (mat)
1467  {
1468  switch(mat->type())
1469  {
1470  case cv::DataType<ito::int8>::type:
1471  return ito::tInt8;
1472  case cv::DataType<ito::uint8>::type:
1473  return ito::tUInt8;
1474  case cv::DataType<ito::int16>::type:
1475  return ito::tInt16;
1476  case cv::DataType<ito::uint16>::type:
1477  return ito::tUInt16;
1478  case cv::DataType<ito::int32>::type:
1479  return ito::tInt32;
1480  case cv::DataType<ito::uint32>::type:
1481  return ito::tUInt32;
1482  case cv::DataType<ito::float32>::type:
1483  return ito::tFloat32;
1484  case cv::DataType<ito::float64>::type:
1485  return ito::tFloat64;
1486  case cv::DataType<ito::Rgba32>::type:
1487  return ito::tRGBA32;
1488  case cv::DataType<ito::complex64>::type:
1489  return ito::tComplex64;
1490  case cv::DataType<ito::complex128>::type:
1491  return ito::tComplex128;
1492  }
1493 
1494  retval += ito::RetVal(ito::retError, 0, "type of cv::Mat is incompatible to ito::DataObject");
1495  }
1496  else
1497  {
1498  retval += ito::RetVal(ito::retError, 0, "given cv::Mat is NULL.");
1499  }
1500  return ito::tInt8;
1501  }
1502 
1503 
1505 
1513  template<typename _Tp> inline ito::tDataType getDataType(const _Tp* /*src*/)
1514  {
1515  cv::error(cv::Exception(CV_StsAssert, "Input value type unkown", "", __FILE__, __LINE__));
1516  return ito::tInt8;
1517  }
1518 
1519  template<> inline ito::tDataType getDataType(const uint8* /*src*/) { return ito::tUInt8; }
1520  template<> inline ito::tDataType getDataType(const int8* /*src*/) { return ito::tInt8; }
1521  template<> inline ito::tDataType getDataType(const uint16* /*src*/) { return ito::tUInt16; }
1522  template<> inline ito::tDataType getDataType(const int16* /*src*/) { return ito::tInt16; }
1523  template<> inline ito::tDataType getDataType(const uint32* /*src*/) { return ito::tUInt32; }
1524  template<> inline ito::tDataType getDataType(const int32* /*src*/) { return ito::tInt32; }
1525  template<> inline ito::tDataType getDataType(const float32* /*src*/) { return ito::tFloat32; }
1526  template<> inline ito::tDataType getDataType(const float64* /*src*/) { return ito::tFloat64; }
1527  template<> inline ito::tDataType getDataType(const complex64* /*src*/) { return ito::tComplex64; }
1528  template<> inline ito::tDataType getDataType(const complex128* /*src*/) { return ito::tComplex128; }
1529  template<> inline ito::tDataType getDataType(const Rgba32* /*src*/) { return ito::tRGBA32; }
1530 
1531 
1533 
1542  template<typename _Tp> inline ito::tDataType getDataType2()
1543  {
1544  cv::error(cv::Exception(CV_StsAssert, "Input value type unkown", "", __FILE__, __LINE__));
1545  return ito::tInt8;
1546  }
1547 
1548  template<> inline ito::tDataType getDataType2<uint8*>() { return ito::tUInt8; }
1549  template<> inline ito::tDataType getDataType2<int8*>() { return ito::tInt8; }
1550  template<> inline ito::tDataType getDataType2<uint16*>() { return ito::tUInt16; }
1551  template<> inline ito::tDataType getDataType2<int16*>() { return ito::tInt16; }
1552  template<> inline ito::tDataType getDataType2<uint32*>() { return ito::tUInt32; }
1553  template<> inline ito::tDataType getDataType2<int32*>() { return ito::tInt32; }
1554  template<> inline ito::tDataType getDataType2<float32*>() { return ito::tFloat32; }
1555  template<> inline ito::tDataType getDataType2<float64*>() { return ito::tFloat64; }
1556  template<> inline ito::tDataType getDataType2<complex64*>() { return ito::tComplex64; }
1557  template<> inline ito::tDataType getDataType2<complex128*>() { return ito::tComplex128; }
1558  template<> inline ito::tDataType getDataType2<Rgba32*>() { return ito::tRGBA32; }
1559 
1560 } //namespace ito
1561 
1562 #endif //__DATAOBJH
1563 
1564 
int getType(void) const
returns type of tag (
Definition: dataobj.h:293
bool isValid(void) const
returns if tag is valid (double or string) or invalid (e.g. due to use of default constructor) ...
Definition: dataobj.h:296
double m_dVal
if the tag type is double, the real double value is stored here
Definition: dataobj.h:268
_Tp & at(const unsigned int z, const unsigned int y, const unsigned int x)
addressing method for three-dimensional data object.
Definition: dataobj.h:1183
iterator through data object
Definition: dataobj.h:433
dataObject contains a n-dimensional matrix
Definition: dataobj.h:496
Range(int _start, int _end)
Definition: dataobj.h:241
Definition: typeDefs.h:89
MSize getSize(void)
returns the size-member. m_size fits to the physical organization of data in memory.
Definition: dataobj.h:868
DataObject arg(const DataObject &dObj)
high-level value which calculates the argument value of each element of the input source data object ...
Definition: dataobj.cpp:8901
RetVal CopyToFunc(const DataObject &lhs, DataObject &rhs, unsigned char regionOnly)
low-level, templated method for deeply copying the data of one matrix to another given matrix ...
Definition: dataobj.cpp:2377
MSize m_osize
Definition: dataobj.h:584
int start
Definition: dataobj.h:246
ByteArray m_strValue
if the tag type is string, the string data is stored in this ByteArray variable.
Definition: dataobj.h:270
_Tp & at(const unsigned int y, const unsigned int x)
addressing method for two-dimensional data object.
Definition: dataobj.h:1139
tTagType
Definition: dataobj.h:260
RetVal AssignScalarFunc(DataObject *src, const ito::tDataType type, const void *scalar)
low-level, templated helper method to assign the given scalar to every element within its ROI in Data...
Definition: dataobj.cpp:3556
ito::tDataType getDataType(const _Tp *)
method which returns the value of enumeration ito::tDataType, which corresponds to the type of the gi...
Definition: dataobj.h:1513
Definition: dataobj.h:519
Definition: typeDefs.h:81
Definition: typeDefs.h:60
const DataObject * dObj
reference to the related data object
Definition: dataobj.h:415
Definition: typeDefs.h:86
MROI m_roi
Definition: dataobj.h:585
uchar * ptr
pointer to the current value of the iterator
Definition: dataobj.h:418
Class for managing status values (like errors or warning)
Definition: retVal.h:54
unsigned int size() const
Definition: dataobj.h:242
Definition: color.h:258
Definition: typeDefs.h:88
Definition: typeDefs.h:87
DataObjectTagsPrivate * m_pDataObjectTags
Definition: dataobj.h:588
_Tp * rowPtr(const int matNum, const int y)
returns pointer to the data in the y-th row in the 2d-matrix plane matNum
Definition: dataobj.h:1262
int getType(void) const
Definition: dataobj.h:777
const _Tp & at(const unsigned int y, const unsigned int x) const
addressing method for two-dimensional data object.
Definition: dataobj.h:1118
uchar * sliceEnd
pointer to the last item within the current continuous slice
Definition: dataobj.h:420
Definition: typeDefs.h:84
uint32 & argb()
Definition: color.h:250
Definition: dataobj.h:53
const cv::Mat ** get_mdata(void) const
returns constant array of pointers to cv::_Mat-matrices (planes) of the data object ...
Definition: dataobj.h:859
bool empty() const
Definition: dataobj.h:243
This is a Qt-free class for byte arrays (strings) without specific encoding information.
Definition: byteArray.h:69
const _Tp & at(const unsigned int z, const unsigned int y, const unsigned int x) const
addressing method for three-dimensional data object.
Definition: dataobj.h:1161
RetVal MakeContinuousFunc(const DataObject &dObj, DataObject &resDObj)
low-level, templated method which copies an incontinuously organized data object to a continuously or...
Definition: dataobj.cpp:9095
Definition: typeDefs.h:79
DataObjectTagType(const char *cVal)
Copy Constructor.
Definition: dataobj.h:278
_Tp & at(const unsigned int *idx)
addressing method for n-dimensional data object.
Definition: dataobj.h:1217
DataObject imag(const DataObject &dObj)
high-level value which calculates the imaginary value of each element of the input source data object...
Definition: dataobj.cpp:9069
ito::tDataType guessDataTypeFromCVMat(const cv::Mat *mat, ito::RetVal &retval)
method which guesses the dataObject type from a given cv::Mat*
Definition: dataobj.h:1464
RetVal CreateFunc(DataObject *dObj, const unsigned char dimensions, const int *sizes, const unsigned char continuous, const uchar *continuousDataPtr, const int *steps)
templated method for create
Definition: dataobj.cpp:1692
ByteArray getVal_ToString(void)
Definition: dataobj.h:326
char getOwnData(void) const
Definition: dataobj.h:783
RetVal copyFromData2D(const _Tp *src, const int sizeX, const int sizeY)
copies the externally given source data inside this data object
Definition: dataobj.h:1310
_Tp numberConversion(ito::tDataType fromType, const void *scalar)
templated method for converting a given scalar value to the data type, indicated by the template para...
Definition: dataobj.h:1374
const MSize getOriginalSize(void) const
returns the original size-member. This is equal to getSize() if no roi is set to the dataObject...
Definition: dataobj.h:903
int * m_pRefCount
Definition: dataobj.h:582
DataObject abs(const DataObject &dObj)
high-level value which calculates the absolute value of each element of the input source data object ...
Definition: dataobj.cpp:8782
const uchar * rowPtr(const int matNum, const int y) const
returns pointer to the data in the y-th row in the 2d-matrix plane matNum
Definition: dataobj.h:1248
each range value has a start and end point. Optionally range can be marked as Range::all(), which indicates a full range
Definition: dataobj.h:237
Definition: dataobj.cpp:54
Definition: apiFunctionsGraph.cpp:39
int getOriginalSize(int index) const
gets the original size of the given dimension (this is the size without considering any ROI) ...
Definition: dataobj.h:910
ito::tDataType convertCmplxTypeToRealType(ito::tDataType cmplxType)
method which returns the real data type of any given data type
Definition: dataobj.h:1432
int getDims(void) const
Definition: dataobj.h:774
Definition: typeDefs.h:83
int plane
plane index where the iterator is currently positioned
Definition: dataobj.h:421
RetVal FreeFunc(DataObject *dObj)
low-level, templated method for freeing allocated data blocks
Definition: dataobj.cpp:759
int getTotal() const
gets total number of elements within the data object&#39;s ROI
Definition: dataobj.h:938
Variant storage class for either a double or a string value.
Definition: dataobj.h:257
RetVal copyFromData2D(const _Tp *src, const int sizeX, const int sizeY, const int x0, const int y0, const int width, const int height)
copies the externally given source data inside this data object
Definition: dataobj.h:1337
Definition: typeDefs.h:85
int m_type
Definition: dataobj.h:581
uchar ** m_data
Definition: dataobj.h:587
int m_dims
Definition: dataobj.h:583
RetVal AdjustROIFunc(DataObject *dObj, int dtop, int dbottom, int dleft, int dright)
low-level, templated method for adjusting the ROI of a data object by the given incremental values ...
Definition: dataobj.cpp:6191
char m_continuous
Definition: dataobj.h:579
Definition: dataobj.h:547
const _Tp & at(const unsigned int *idx) const
addressing method for n-dimensional data object.
Definition: dataobj.h:1204
MSize getOriginalSize(void)
returns the original size-member. This is equal to getSize() if no roi is set to the dataObject...
Definition: dataobj.h:897
int getSize(int index) const
gets the size of the given dimension (this is the size within the ROI)
Definition: dataobj.h:881
const _Tp * rowPtr(const int matNum, const int y) const
returns pointer to the data in the y-th row in the 2d-matrix plane matNum
Definition: dataobj.h:1276
const MSize getSize(void) const
returns the size-member. This member does not consider the transpose flag, hence, m_size fits to the ...
Definition: dataobj.h:874
Definition: typeDefs.h:82
bool planeContinuous
indicates whether dObj is continuously organized in each plane for faster seek operations ...
Definition: dataobj.h:416
static Rgba32 fromUnsignedLong(const uint32 val)
static constructor to create Rgba32 from uint32 containing the values argb
Definition: color.h:82
DataObject makeContinuous(const DataObject &dObj)
high-level method which copies an incontinuously organized data object to a continuously organized re...
Definition: dataobj.cpp:9221
int end
Definition: dataobj.h:247
constant iterator through data object
Definition: dataobj.h:361
cv::Mat ** get_mdata(void)
returns array of pointers to cv::_Mat-matrices (planes) of the data object.
Definition: dataobj.h:844
RetVal GetRangeFunc(DataObject *dObj, const int dtop, const int dbottom, const int dleft, const int dright)
low-level, templated method for saving a shallow copy of a source cv::Mat_ to a destination cv::Mat_ ...
Definition: dataobj.cpp:6047
RetVal CreateFuncWithCVPlanes(DataObject *dObj, const unsigned char dimensions, const int *sizes, const cv::Mat *planes, const unsigned int nrOfPlanes)
templated method for creation with given vector of cv::Mat-planes
Definition: dataobj.cpp:1893
DataObject real(const DataObject &dObj)
high-level value which calculates the real value of each element of the input source data object and ...
Definition: dataobj.cpp:8985
char getContinuous(void) const
Definition: dataobj.h:780
char m_owndata
Definition: dataobj.h:580
DataObjectTagType()
< Constructor
Definition: dataobj.h:274
This class implements basic functionality for color handling in itom. This class implements ARGB32 i...
Definition: color.h:46
float32 gray() const
Definition: color.h:235
Range()
Definition: dataobj.h:240
tDataType
Definition: typeDefs.h:77
int getNumPlanes(void) const
calculates numbers of single opencv matrices which are part of the ROI which has previously been set...
Definition: dataobj.h:800
ito::tDataType getDataType2()
method which returns the value of enumeration ito::tDataType, which corresponds to the template param...
Definition: dataobj.h:1542
Definition: typeDefs.h:80
tTagType m_type
type indicator of this class (invalid, double or string)
Definition: dataobj.h:269
int getOriginalTotal() const
gets total number of elements of the whole data object
Definition: dataobj.h:955
uchar * rowPtr(const int matNum, const int y)
returns pointer to the data in the y-th row in the 2d-matrix plane matNum
Definition: dataobj.h:1235
const char * data() const
return the pointer to the internal character array. If it is empty, the returned pointer still points...
Definition: byteArray.h:136
static Range all()
Definition: dataobj.h:244
double getVal_ToDouble(void)
Definition: dataobj.h:303
MSize m_size
Definition: dataobj.h:586
RetVal ConvertToFunc(const DataObject &lhs, DataObject &rhs, const int dest_type, const double alpha, const double beta)
converts data in DataObject lhs to DataObject rhs with a given type
Definition: dataobj.cpp:8279
uchar * sliceStart
pointer to the first item within the current continuous slice
Definition: dataobj.h:419