itom  4.1.0
dataobj.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2020, 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 "opencv2/opencv.hpp"
46 #include "opencv2/core/core.hpp"
47 #include "opencv2/core/types_c.h"
48 
49 #include "../common/sharedStructures.h"
50 #include "../common/color.h"
51 #include "../common/byteArray.h"
52 
53 
54 namespace cv
55 {
56  template<> inline ito::float32 saturate_cast<ito::float32>( ito::float64 v)
57  {
58  if(cvIsInf(v)) return std::numeric_limits<ito::float32>::infinity();
59  if(cvIsNaN(v)) return std::numeric_limits<ito::float32>::quiet_NaN();
60  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)()) )));
61  }
62 
63  template<> inline ito::float64 saturate_cast<ito::float64>( ito::float32 v)
64  {
65  if(cvIsInf(v)) return std::numeric_limits<ito::float64>::infinity();
66  if(cvIsNaN(v)) return std::numeric_limits<ito::float64>::quiet_NaN();
67  return static_cast<ito::float64>(v);
68  }
69 
70  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; }
71  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; }
72 
73  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; }
74  // 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; }
75 
76  template<> inline ito::complex64 saturate_cast(ito::uint8 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); }
77  template<> inline ito::complex64 saturate_cast(ito::int8 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); }
78  template<> inline ito::complex64 saturate_cast(ito::uint16 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); }
79  template<> inline ito::complex64 saturate_cast(ito::int16 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); }
80  template<> inline ito::complex64 saturate_cast(ito::uint32 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); }
81  template<> inline ito::complex64 saturate_cast(ito::int32 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); }
82  template<> inline ito::complex64 saturate_cast(ito::float32 v){ return ito::complex64(v,0.0); }
83  template<> inline ito::complex64 saturate_cast(ito::float64 v){ return ito::complex64(saturate_cast<ito::float32>(v),0.0); }
84  template<> inline ito::complex64 saturate_cast(ito::complex64 v){ return v; }
85  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())); }
86 
87  template<> inline ito::complex128 saturate_cast(ito::uint8 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); }
88  template<> inline ito::complex128 saturate_cast(ito::int8 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); }
89  template<> inline ito::complex128 saturate_cast(ito::uint16 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); }
90  template<> inline ito::complex128 saturate_cast(ito::int16 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); }
91  template<> inline ito::complex128 saturate_cast(ito::uint32 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); }
92  template<> inline ito::complex128 saturate_cast(ito::int32 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); }
93  template<> inline ito::complex128 saturate_cast(ito::float32 v){ return ito::complex128(saturate_cast<ito::float64>(v),0.0); }
94  template<> inline ito::complex128 saturate_cast(ito::float64 v){ return ito::complex128(v,0.0); }
95  template<> inline ito::complex128 saturate_cast(ito::complex64 v){ return ito::complex128(saturate_cast<ito::float64>(v.real()),saturate_cast<ito::float64>(v.imag())); }
96  template<> inline ito::complex128 saturate_cast(ito::complex128 v){ return v; }
97 
98  // template<> inline ito::Rgba32 saturate_cast(ito::int8 v) {return ito::Rgba32(saturate_cast<ito::uint8>(v));}
99  template<> inline ito::Rgba32 saturate_cast(ito::uint8 v) {return ito::Rgba32(v);}
100  template<> inline ito::Rgba32 saturate_cast(ito::uint16 v){return ito::Rgba32(saturate_cast<ito::uint8>(v));}
101  // template<> inline ito::Rgba32 saturate_cast(ito::int16 v){return ito::Rgba32(saturate_cast<ito::uint8>(v));}
102  template<> inline ito::Rgba32 saturate_cast(ito::uint32 v)
103  {
105  }
106  template<> inline ito::Rgba32 saturate_cast(ito::int32 v)
107  {
108  ito::Rgba32 temp;
109  temp.rgba = static_cast<ito::uint32>(v);
110  return temp;
111  }
112  template<> inline ito::Rgba32 saturate_cast(ito::float32 v){return ito::Rgba32(saturate_cast<ito::uint8>(v));}
113  template<> inline ito::Rgba32 saturate_cast(ito::float64 v){return ito::Rgba32(saturate_cast<ito::uint8>(v));}
114  template<> inline ito::Rgba32 saturate_cast(ito::Rgba32 v){return v;}
115 
116  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(); }
117  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(); }
118  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(); }
119  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(); }
120 
121  template<> inline ito::uint8 saturate_cast(ito::Rgba32 v){return saturate_cast<ito::uint8>(v.gray());};
122  //template<> inline ito::int16 saturate_cast(ito::Rgba32 v){return saturate_cast<ito::int16>(v.gray());};
123  template<> inline ito::uint16 saturate_cast(ito::Rgba32 v){return saturate_cast<ito::uint16>(v.gray());};
124  template<> inline ito::uint32 saturate_cast(ito::Rgba32 v){return v.argb();};
125  template<> inline ito::int32 saturate_cast(ito::Rgba32 v){return (ito::int32)(v.argb());};
126  template<> inline ito::float32 saturate_cast(ito::Rgba32 v){return v.gray();};
127  template<> inline ito::float64 saturate_cast(ito::Rgba32 v){return (ito::float64)v.gray();};
128 
129 #if (CV_MAJOR_VERSION > 3) || (CV_MAJOR_VERSION == 3 && CV_MINOR_VERSION >= 3)
130  //from CV 3.3.1 on, the default implementation of DataType is dropped:
131  //Original note in traits.hpp of OpenCV: Default values were dropped to stop confusing developers about using of unsupported types (see #7599)
132  template<> class DataType<ito::uint32>
133  {
134  public:
135  typedef ito::uint32 value_type;
136  typedef value_type work_type;
137  typedef value_type channel_type;
138  typedef value_type vec_type;
139  enum { generic_type = 1, depth = -1, channels = 1, fmt=0,
140  type = CV_MAKETYPE(depth, channels) };
141  };
142 #endif
143 
144  template<> class DataType<ito::Rgba32>
145  {
146  public:
147  typedef ito::Rgba32 value_type;
148  typedef ito::uint8 channel_type;
149  typedef Vec<channel_type, 4> work_type;
150  typedef value_type vec_type;
151  enum
152  {
153  generic_type = 0,
154  depth = cv::DataDepth<channel_type>::value,
155  channels = 4,
156  fmt = ((channels-1)<<8) + cv::DataDepth<channel_type>::fmt,
157  type = CV_MAKETYPE(depth, channels)
158  };
159  };
160 
161  template<> class DataType<ito::RedChannel>
162  {
163  public:
164  typedef ito::RedChannel value_type;
165  typedef ito::uint8 channel_type;
166  typedef Vec<channel_type, 4> work_type;
167  typedef value_type vec_type;
168  enum
169  {
170  generic_type = 0,
171  depth = cv::DataDepth<channel_type>::value,
172  channels = 4,
173  fmt = ((channels-1)<<8) + cv::DataDepth<channel_type>::fmt,
174  type = CV_MAKETYPE(depth, channels)
175  };
176  };
177 
178  template<> class DataType<ito::GreenChannel>
179  {
180  public:
182  typedef ito::uint8 channel_type;
183  typedef Vec<channel_type, 4> work_type;
184  typedef value_type vec_type;
185  enum
186  {
187  generic_type = 0,
188  depth = cv::DataDepth<channel_type>::value,
189  channels = 4,
190  fmt = ((channels-1)<<8) + cv::DataDepth<channel_type>::fmt,
191  type = CV_MAKETYPE(depth, channels)
192  };
193  };
194 
195  template<> class DataType<ito::BlueChannel>
196  {
197  public:
199  typedef ito::uint8 channel_type;
200  typedef Vec<channel_type, 4> work_type;
201  typedef value_type vec_type;
202  enum
203  {
204  generic_type = 0,
205  depth = cv::DataDepth<channel_type>::value,
206  channels = 4,
207  fmt = ((channels-1)<<8) + cv::DataDepth<channel_type>::fmt,
208  type = CV_MAKETYPE(depth, channels)
209  };
210  };
211 
212  template<> class DataType<ito::AlphaChannel>
213  {
214  public:
216  typedef ito::uint8 channel_type;
217  typedef Vec<channel_type, 4> work_type;
218  typedef value_type vec_type;
219  enum
220  {
221  generic_type = 0,
222  depth = cv::DataDepth<channel_type>::value,
223  channels = 4,
224  fmt = ((channels-1)<<8) + cv::DataDepth<channel_type>::fmt,
225  type = CV_MAKETYPE(depth, channels)
226  };
227  };
228 
229 
230 } // namespace cv
231 
232 namespace ito {
233 
234 #define __ITODEBUG 1
235 
236  //forward declarations
237  class DObjIterator;
238  class DataObject;
239  class Range;
240  class DataObjectTags;
241  class DataObjectTagType;
242  class DataObjectTagsPrivate;
243 
244 
245  //----------------------------------------------------------------------------------------------------------------------------------
252  class DATAOBJ_EXPORT Range
253  {
254  public:
255  Range() : start(0), end(0) {}
256  Range(int _start, int _end) { _start < _end ? (end = _end, start = _start) : (start = _end, end = _start); }
257  inline unsigned int size() const { return end - start; }
258  inline bool empty() const { return (start == end); }
259  static Range all() { return Range(INT_MIN, INT_MAX); }
261  int start;
262  int end;
263  };
264 
265  //----------------------------------------------------------------------------------------------------------------------------------
272  class DATAOBJ_EXPORT DataObjectTagType
273  {
274  public:
275  enum tTagType
276  {
277  typeInvalid = 0x000000,
278  typeDouble = 0x000008,
279  typeString = 0x000020
280  };
281 
282  private:
283  double m_dVal;
286 
287  public:
289  DataObjectTagType() : m_dVal(0), m_strValue(""), m_type(DataObjectTagType::typeInvalid){}
290  DataObjectTagType(double dVal) : m_dVal(dVal), m_strValue(""), m_type(DataObjectTagType::typeDouble){}
291  DataObjectTagType(const std::string &str) : m_dVal(std::numeric_limits<double>::quiet_NaN()), m_type(DataObjectTagType::typeString){ m_strValue = str.data(); }
292  DataObjectTagType(const ByteArray &str) : m_dVal(std::numeric_limits<double>::quiet_NaN()), m_type(DataObjectTagType::typeString){ m_strValue = str; }
293  DataObjectTagType(const char* cVal) : m_dVal(std::numeric_limits<double>::quiet_NaN()), m_type(DataObjectTagType::typeString){ cVal == NULL ? m_strValue = "" : m_strValue = cVal;}
295  DataObjectTagType(const DataObjectTagType& a) : m_dVal(a.m_dVal), m_type(a.m_type), m_strValue(a.m_strValue) {}
296 
298  DataObjectTagType & operator = (const DataObjectTagType &rhs)
299  {
300  this->m_dVal = rhs.m_dVal;
301  this->m_strValue = rhs.m_strValue;
302  this->m_type = rhs.m_type;
303 
304  return *this;
305  }
306 
308  inline int getType(void) const {return m_type;}
309 
311  inline bool isValid(void) const { return (m_type == DataObjectTagType::typeInvalid) ? false: true;}
312 
318  inline double getVal_ToDouble(void)
319  {
320  if(m_type == DataObjectTagType::typeInvalid)
321  {
322  return std::numeric_limits<double>::quiet_NaN();
323  }
324  else if(m_type == DataObjectTagType::typeDouble)
325  {
326  return m_dVal;
327  }
328  else
329  {
330  double dVal = std::numeric_limits<double>::quiet_NaN();
331  //dVal = atof(m_strValue.c_str()); //sometimes the result of that line has been arbitrary, therefore this conversion should fail.
332  return dVal;
333  }
334  }
335 
342  {
343  if(m_type == DataObjectTagType::typeInvalid)
344  {
345  return "";
346  }
347  else if(m_type == DataObjectTagType::typeString)
348  {
349  return m_strValue;
350  }
351  else
352  {
353  if (cvIsNaN(m_dVal)) return "NaN";
354  if (cvIsInf(m_dVal)) return "Inf";
355 
356  std::ostringstream strs;
357  strs << m_dVal;
358  ByteArray ba(strs.str().data());
359 
360  return ba;
361  }
362  }
363  };
364 
365  //----------------------------------------------------------------------------------------------------------------------------------
376  class DATAOBJ_EXPORT DObjConstIterator
377  {
378  public:
379 
382 
384  DObjConstIterator(const DataObject* _dObj, int pos = 0);
385 
388 
390  DObjConstIterator& operator = (const DObjConstIterator& it);
391 
393  const uchar* operator *() const;
394 
396  const uchar* operator [](int i) const;
397 
399  DObjConstIterator& operator += (int ofs);
400 
402  DObjConstIterator& operator -= (int ofs);
403 
405  DObjConstIterator& operator --();
406 
408  DObjConstIterator operator --(int);
409 
411  DObjConstIterator& operator ++();
412 
414  DObjConstIterator operator ++(int);
415 
416  bool operator == (const DObjConstIterator& dObjIt);
417  bool operator != (const DObjConstIterator& dObjIt);
418  bool operator < (const DObjConstIterator& dObjIt);
419  bool operator > (const DObjConstIterator& dObjIt);
420  bool operator <= (const DObjConstIterator& dObjIt);
421  bool operator >= (const DObjConstIterator& dObjIt);
422 
423  protected:
425  void seekAbs(int ofs);
426 
428  void seekRel(int ofs);
429 
430  const DataObject* dObj;
432  int elemSize;
433  uchar* ptr;
434  uchar* sliceStart;
435  uchar* sliceEnd;
436  int plane;
437  };
438 
439  //----------------------------------------------------------------------------------------------------------------------------------
448  class DATAOBJ_EXPORT DObjIterator : public DObjConstIterator
449  {
450  public:
451 
453  DObjIterator();
454 
456  DObjIterator(DataObject* _dObj, int pos = 0);
457 
459  DObjIterator(const DObjIterator& it);
460 
462  DObjIterator& operator = (const DObjIterator& it);
463 
465  uchar* operator *();
466 
468  uchar* operator [](int i);
469 
471  DObjIterator& operator += (int ofs);
472 
474  DObjIterator& operator -= (int ofs);
475 
477  DObjIterator& operator --();
478 
480  DObjIterator operator --(int);
481 
483  DObjIterator& operator ++();
484 
486  DObjIterator operator ++(int);
487  };
488 
489 //----------------------------------------------------------------------------------------------------------------------------------
490 
491 // Forward declaration of friend methods
492 #ifdef __APPLE__
493  template<typename _Tp> RetVal CreateFunc(DataObject *dObj, const unsigned char dimensions, const int *sizes, const unsigned char continuous, const uchar* continuousDataPtr, const int* steps);
494  template<typename _Tp> RetVal CreateFuncWithCVPlanes(DataObject *dObj, const unsigned char dimensions, const int *sizes, const cv::Mat* planes, const unsigned int nrOfPlanes);
495  template<typename _Tp> RetVal FreeFunc(DataObject *dObj);
496  template<typename _Tp> RetVal SecureFreeFunc(DataObject *dObj);
497  template<typename _Tp> RetVal CopyToFunc(const DataObject &lhs, DataObject &rhs, unsigned char regionOnly);
498  template<typename _Tp> RetVal ConvertToFunc(const DataObject &lhs, DataObject &rhs, const int type, const double alpha, const double beta);
499  template<typename _Tp> RetVal AdjustROIFunc(DataObject *dObj, const int *lims);
500  //template<typename _Tp> RetVal MinMaxLocFunc(const DataObject &dObj, double *minVal, double *maxVal, int *minPos, int *maxPos);
501  template<typename _Tp> RetVal AssignScalarFunc(const DataObject *src, const ito::tDataType type, const void *scalar);
502  template<typename _Tp> RetVal MakeContinuousFunc(const DataObject &dObj, DataObject &resDObj);
503  template<typename _Tp> RetVal EvaluateTransposeFlagFunc(DataObject *dObj);
504  template<typename _Tp> std::ostream& coutFunc(std::ostream& out, const DataObject& dObj);
505 
506  // more friends due to change of std::vector to int ** for m_data ...
507  template<typename _Tp> RetVal GetRangeFunc(DataObject *dObj, const int dtop, const int dbottom, const int dleft, const int dright);
508  template<typename _Tp> RetVal AdjustROIFunc(DataObject *dObj, int dtop, int dbottom, int dleft, int dright);
509 #endif // __APPLE__
510 
511  class DATAOBJ_EXPORT DataObject
512  {
513  private:
515  void createHeader(const unsigned char dimensions, const int *sizes, const int *steps, const int elemSize);
516 
518  void createHeaderWithROI(const unsigned char dimensions, const int *sizes, const int *osizes = NULL, const int *roi = NULL);
519 
520  void create(const unsigned char dimensions, const int *sizes, const int type, const unsigned char continuous, const uchar* continuousDataPtr = NULL, const int* steps = NULL);
521  void create(const unsigned char dimensions, const int *sizes, const int type, const cv::Mat* planes, const unsigned int nrOfPlanes);
522 
523  void freeData(void);
524  void secureFreeData(void);
527  //----------------------------------------------------------------------------------------------------------------------------------
528  ito::RetVal matNumToIdx(const int matNum, int *matIdx) const;
529 
531  ito::RetVal matIdxToNum(const unsigned int *matIdx, int *matNum) const;
532 
533 
534  struct DATAOBJ_EXPORT MSize
535  {
536  inline MSize() : m_p(NULL) {}
537  inline int operator [] (const int dim) const
538  {
539  return m_p[dim]; //return the size value. this operator corresponds to the real data representation in memory
540  };
541  inline operator const int * () const { return m_p; }
542  inline bool operator == (const MSize& sz) const
543  {
544  if(m_p == NULL || sz.m_p == NULL)
545  {
546  return sz.m_p == m_p;
547  }
548 
549  int d = m_p[-1];
550  if( d != sz.m_p[-1] )
551  return false;
552 
553  return (memcmp(m_p, sz.m_p, d * sizeof(int)) == 0); //returns true if the size vector (having the same length) is equal
554  }
555 
556  inline bool operator != (const MSize& sz) const { return !(*this == sz); }
557 
558  int *m_p;
559  };
560 
561 
562  struct DATAOBJ_EXPORT MROI
563  {
564  inline MROI() : m_p(NULL) {};
565  inline int operator [] (const int dim) const
566  {
567  return m_p[dim]; //return the size value. this operator corresponds to the real data representation in memory
568  }
569 
570  inline bool operator == (const MROI & rroi) const
571  {
572  if(m_p == NULL || rroi.m_p == NULL)
573  {
574  return rroi.m_p == m_p;
575  }
576 
577  int d = m_p[-1];
578  if( d != rroi.m_p[-1] )
579  return false;
580 
581  return (memcmp(m_p, rroi.m_p, d * sizeof(int)) == 0); //returns true if the size vector (having the same length) is equal
582 
583  if (m_p[-1] != rroi.m_p[-1])
584  {
585  return false;
586  }
587  }
588 
589  int *m_p;
590  };
591 
592  DataObject(const DataObject& dObj, bool transposed);
595  char m_owndata;
596  int m_type;
597  int *m_pRefCount;
598  int m_dims;
602  uchar **m_data;
604  static const int m_sizeofs;
605 
606  int mdata_realloc(const int size);
607  int mdata_size(void) const;
608  int mdata_free();
609 
610  RetVal copyFromData2DInternal(const uchar* src, const int sizeOfElem, const int sizeX, const int sizeY);
611  RetVal copyFromData2DInternal(const uchar* src, const int sizeOfElem, const int sizeX, const int x0, const int y0, const int width, const int height);
612 
613  //low-level, templated methods
614  //most low-level methods are marked "friend" such that they can access private members of their data object parameters
615  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);
616  template<typename _Tp> friend RetVal CreateFuncWithCVPlanes(DataObject *dObj, const unsigned char dimensions, const int *sizes, const cv::Mat* planes, const unsigned int nrOfPlanes);
617  template<typename _Tp> friend RetVal FreeFunc(DataObject *dObj);
618  template<typename _Tp> friend RetVal SecureFreeFunc(DataObject *dObj);
619  template<typename _Tp> friend RetVal CopyToFunc(const DataObject &lhs, DataObject &rhs, unsigned char regionOnly);
620  template<typename _Tp> friend RetVal ConvertToFunc(const DataObject &lhs, DataObject &rhs, const int type, const double alpha, const double beta);
621  template<typename _Tp> friend RetVal AdjustROIFunc(DataObject *dObj, const int *lims);
622  //template<typename _Tp> friend RetVal MinMaxLocFunc(const DataObject &dObj, double *minVal, double *maxVal, int *minPos, int *maxPos);
623  template<typename _Tp> friend RetVal AssignScalarFunc(const DataObject *src, const ito::tDataType type, const void *scalar);
624  template<typename _Tp> friend RetVal MakeContinuousFunc(const DataObject &dObj, DataObject &resDObj);
625  template<typename _Tp> friend RetVal EvaluateTransposeFlagFunc(DataObject *dObj);
626  template<typename _Tp> friend std::ostream& coutFunc(std::ostream& out, const DataObject& dObj);
627 
628  // more friends due to change of std::vector to int ** for m_data ...
629  template<typename _Tp> friend RetVal GetRangeFunc(DataObject *dObj, const int dtop, const int dbottom, const int dleft, const int dright);
630  template<typename _Tp> friend RetVal AdjustROIFunc(DataObject *dObj, int dtop, int dbottom, int dleft, int dright);
631 
632  public:
634  DataObject(void);
635 
637  DataObject(const int size, const int type);
638 
640  DataObject(const int sizeY, const int sizeX, const int type);
641 
643  DataObject(const int sizeZ, const int sizeY, const int sizeX, const int type, const unsigned char continuous = 0);
644 
646  DataObject(const int sizeZ, const int sizeY, const int sizeX, const int type, const uchar* continuousDataPtr, const int* steps = NULL);
647 
649  DataObject(const MSize &sizes, const int type, const unsigned char continuous = 0);
650 
652  DataObject(const unsigned char dimensions, const int *sizes, const int type, const unsigned char continuous = 0);
653 
655  DataObject(const unsigned char dimensions, const int *sizes, const int type, const uchar* continuousDataPtr, const int* steps = NULL);
656 
658  DataObject(const unsigned char dimensions, const int *sizes, const int type, const cv::Mat* planes, const unsigned int nrOfPlanes);
659 
661  DataObject(const cv::Mat &data);
662 
663  DataObject(const DataObject& copyConstr);
665  ~DataObject(void);
667 
668  // TAGSPACEFUNCTIONS
669 
671  double getValueOffset() const;
672 
674  double getValueScale() const;
675 
677  const std::string getValueUnit() const;
678 
680  std::string getValueDescription() const;
681 
683  double getAxisOffset(const int axisNum) const;
684 
686  double getAxisScale(const int axisNum) const;
687 
689  const std::string getAxisUnit(const int axisNum, bool &validOperation) const;
690 
692  std::string getAxisDescription(const int axisNum, bool &validOperation) const;
693 
694  DataObjectTagType getTag(const std::string &key, bool &validOperation) const;
695 
696  bool getTagByIndex(const int tagNumber, std::string &key, DataObjectTagType &value) const;
697 
699  std::string getTagKey(const int tagNumber, bool &validOperation) const;
700 
702  int getTagListSize() const;
703 
705  int setValueUnit(const std::string &unit);
706 
708  int setValueDescription(const std::string &description);
709 
711  int setAxisOffset(const unsigned int axisNum, const double offset);
712 
714  int setAxisScale(const unsigned int axisNum, const double scale);
715 
717  int setAxisUnit(const unsigned int axisNum, const std::string &unit);
718 
720  int setAxisDescription(const unsigned int axisNum, const std::string &description);
721  int setTag(const std::string &key, const DataObjectTagType &value);
722  bool existTag(const std::string &key) const;
723  bool deleteTag(const std::string &key);
724  bool deleteAllTags();
725  int addToProtocol(const std::string &value);
726 
730  double getPhysToPix(const unsigned int dim, const double phys, bool &isInsideImage) const;
731 
735  double getPhysToPix(const unsigned int dim, const double phys) const;
736 
740  int getPhysToPix2D(const double physY, double &tPxY, bool &isInsideImageY, const double physX, double &tPxX, bool &isInsideImageX) const;
741 
745  double getPixToPhys(const unsigned int dim, const double pix, bool &isInsideImage) const;
746 
750  double getPixToPhys(const unsigned int dim, const double pix) const;
751 
765  RetVal setXYRotationalMatrix(double r11, double r12, double r13, double r21, double r22, double r23, double r31, double r32, double r33);
766 
780  RetVal getXYRotationalMatrix(double &r11, double &r12, double &r13, double &r21, double &r22, double &r23, double &r31, double &r32, double &r33) const;
781 
782  RetVal copyTagMapTo(DataObject &rhs) const;
783  RetVal copyAxisTagsTo(DataObject &rhs) const;
785  RetVal setReal(DataObject &valuesObj); /*change the real part of a complex data object*/
786  RetVal setImag(DataObject &valuesObj); /*change the imaginary part of a complex data object*/
787 
788  // END TAGSPACE
789 
791  inline int getDims(void) const { return m_dims; }
792 
794  inline int getType(void) const { return m_type; }
795 
797  inline char getContinuous(void) const { return m_continuous; }
798 
800  inline char getOwnData(void) const { return m_owndata; }
801 
803  int seekMat(const int matNum, const int numMats) const;
804 
806  int seekMat(const int matNum) const;
807 
809  int calcNumMats(void) const;
810 
812 
817  inline int getNumPlanes(void) const
818  {
819  switch (m_dims)
820  {
821  case 0:
822  return 0;
823  case 1:
824  case 2:
825  return 1;
826  case 3:
827  return m_size[0];
828  case 4:
829  return m_size[0] * m_size[1];
830  default:
831  {
832  int numMat = 1;
833  for (int n = 0; n < m_dims - 2; n++)
834  {
835  numMat *= m_size[n];
836  }
837  return numMat;
838  }
839  }
840  }
841 
843  cv::Mat* getCvPlaneMat(const int planeIndex);
844 
846  const cv::Mat* getCvPlaneMat(const int planeIndex) const;
847 
849  const cv::Mat getContinuousCvPlaneMat(const int planeIndex) const;
850 
852 
861  inline cv::Mat** get_mdata(void)
862  {
863  return (cv::Mat**)m_data;
864  }
865 
867 
876  inline const cv::Mat** get_mdata(void) const
877  {
878  return (const cv::Mat**)m_data;
879  }
880 
882 
885  inline MSize getSize(void) { return m_size; }
886 
888 
891  inline const MSize getSize(void) const { return m_size; }
892 
894 
898  inline int getSize(int index) const
899  {
900  if(index < 0 || index >= m_dims)
901  {
902  return -1;
903  }
904  else
905  {
906  return m_size[index];
907  }
908  }
909 
911 
914  inline MSize getOriginalSize(void) { return m_osize; }
915 
917 
920  inline const MSize getOriginalSize(void) const { return m_osize; }
921 
923 
927  inline int getOriginalSize(int index) const
928  {
929  if(index < 0 || index >= m_dims)
930  {
931  return -1;
932  }
933  else
934  {
935  return m_osize[index];
936  }
937  }
938 
940 
947  int getStep(int index) const;
948 
949 
951 
955  inline int getTotal() 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_size[i];
962  }
963  return total;
964 
965  }
966 
968 
972  inline int getOriginalTotal() const
973  {
974  int dims = getDims();
975  int total = dims > 0 ? 1 : 0;
976  for(int i = 0 ; i<dims ; i++)
977  {
978  total *= m_osize[i];
979  }
980  return total;
981  }
982 
983  RetVal copyTo(DataObject &rhs, unsigned char regionOnly = 0) const;
984  RetVal convertTo(DataObject &rhs, const int type, const double alpha=1, const double beta=0 ) const;
986  RetVal setTo(const int8 &value, const DataObject &mask = DataObject());
987  RetVal setTo(const uint8 &value, const DataObject &mask = DataObject());
988  RetVal setTo(const int16 &value, const DataObject &mask = DataObject());
989  RetVal setTo(const uint16 &value, const DataObject &mask = DataObject());
990  RetVal setTo(const int32 &value, const DataObject &mask = DataObject());
991  RetVal setTo(const uint32 &value, const DataObject &mask = DataObject());
992  RetVal setTo(const float32 &value, const DataObject &mask = DataObject());
993  RetVal setTo(const float64 &value, const DataObject &mask = DataObject());
994  RetVal setTo(const complex64 &value, const DataObject &mask = DataObject());
995  RetVal setTo(const complex128 &value, const DataObject &mask = DataObject());
996  RetVal setTo(const ito::Rgba32 &value, const DataObject &mask = DataObject());
998  RetVal deepCopyPartial(DataObject &copyTo);
1000 
1002  DObjIterator begin();
1004  DObjIterator end();
1005 
1007  DObjConstIterator constBegin() const;
1008 
1010  DObjConstIterator constEnd() const;
1011 
1013  DataObject & operator = (const cv::Mat &rhs);
1014  DataObject & operator = (const DataObject &rhs);
1015  DataObject & operator = (const int8 &value);
1016  DataObject & operator = (const uint8 &value);
1017  DataObject & operator = (const int16 &value);
1018  DataObject & operator = (const uint16 &value);
1019  DataObject & operator = (const int32 &value);
1020  DataObject & operator = (const uint32 &value);
1021  DataObject & operator = (const float32 &value);
1022  DataObject & operator = (const float64 &value);
1023  DataObject & operator = (const complex64 &value);
1024  DataObject & operator = (const complex128 &value);
1025  DataObject & operator = (const ito::Rgba32 &value);
1028  DataObject & operator += (const DataObject &rhs);
1029  DataObject & operator += (const float64 &value);
1030  DataObject & operator += (const complex128 &value);
1031 
1032  DataObject operator + (const DataObject &rhs);
1033  DataObject operator + (const float64 &value);
1034  DataObject operator + (const complex128 &value);
1035 
1036  DataObject & operator -= (const DataObject &rhs);
1037  DataObject & operator -= (const float64 &value);
1038  DataObject & operator -= (const complex128 &value);
1039 
1040  DataObject operator - (const DataObject &rhs);
1041  DataObject operator - (const float64 &value);
1042  DataObject operator - (const complex128 &value);
1043 
1044  DataObject & operator *= (const DataObject &rhs);
1045  DataObject & operator *= (const float64 &factor);
1046  DataObject & operator *= (const complex128 &factor);
1047 
1048  DataObject operator * (const DataObject &rhs);
1049  DataObject operator * (const float64 &factor);
1050  DataObject operator * (const complex128 &factor);
1051 
1052  // Comparison Operators
1053  DataObject operator < (DataObject &rhs);
1054  DataObject operator > (DataObject &rhs);
1055  DataObject operator <= (DataObject &rhs);
1056  DataObject operator >= (DataObject &rhs);
1059 
1060  DataObject operator < (const float64 &value);
1061  DataObject operator > (const float64 &value);
1062  DataObject operator <= (const float64 &value);
1063  DataObject operator >= (const float64 &value);
1064  DataObject operator == (const float64 &value);
1065  DataObject operator != (const float64 &value);
1066 
1067  DataObject operator == (const ito::complex64 &value);
1068  DataObject operator != (const ito::complex64 &value);
1069  DataObject operator == (const ito::complex128 &value);
1070  DataObject operator != (const ito::complex128 &value);
1071 
1072  // bitshift operators
1073  DataObject operator << (const unsigned int shiftbit);
1074  DataObject & operator <<= (const unsigned int shiftbit);
1075  DataObject operator >> (const unsigned int shiftbit);
1076  DataObject & operator >>= (const unsigned int shiftbit);
1077 
1078  // bitwise operators
1079  DataObject operator & (const DataObject & rhs);
1080  DataObject & operator &= (const DataObject & rhs);
1081  DataObject operator | (const DataObject & rhs);
1082  DataObject & operator |= (const DataObject & rhs);
1083  DataObject operator ^ (const DataObject & rhs);
1084  DataObject & operator ^= (const DataObject & rhs);
1085  DataObject bitwise_not() const;
1087  // allocates matrix with zero values
1088  RetVal zeros(const int type);
1089  RetVal zeros(const int size, const int type);
1090  RetVal zeros(const int sizeY, const int sizeX, const int type);
1091  RetVal zeros(const int sizeZ, const int sizeY, const int sizeX, const int type, const unsigned char continuous = 0);
1092  RetVal zeros(const unsigned char dimensions, const int *sizes, const int type, const unsigned char continuous = 0);
1093 
1094  // allocates matrix with all values set to one
1095  RetVal ones(const int type);
1096  RetVal ones(const int size, const int type);
1097  RetVal ones(const int sizeY, const int sizeX, const int type);
1098  RetVal ones(const int sizeZ, const int sizeY, const int sizeX, const int type, const unsigned char continuous = 0);
1099  RetVal ones(const unsigned char dimensions, const int *sizes, const int type, const unsigned char continuous = 0);
1100 
1101  // allocates matrix with all values set to one
1102  RetVal nans(const int type);
1103  RetVal nans(const int size, const int type);
1104  RetVal nans(const int sizeY, const int sizeX, const int type);
1105  RetVal nans(const int sizeZ, const int sizeY, const int sizeX, const int type, const unsigned char continuous = 0);
1106  RetVal nans(const unsigned char dimensions, const int *sizes, const int type, const unsigned char continuous = 0);
1107 
1108  // allocates matrix with uniform distributed noise
1109  RetVal rand(const int type, const bool randMode = false);
1110  RetVal rand(const int size, const int type, const bool randMode = false);
1111  RetVal rand(const int sizeY, const int sizeX, const int type, const bool randMode = false);
1112  RetVal rand(const int sizeZ, const int sizeY, const int sizeX, const int type, const bool randMode, const unsigned char continuous = 0);
1113  RetVal rand(const unsigned char dimensions, const int *sizes, const int type, const bool randMode, const unsigned char continuous = 0);
1114 
1115  // allocates matrix with eye-matrix representation
1116  RetVal eye(const int type);
1117  RetVal eye(const int size, const int type);
1118 
1119  RetVal conj();
1120  DataObject adj() const;
1121  DataObject trans() const;
1122 
1123  // element-wise multiplication
1124  DataObject mul(const DataObject &mat2, const double scale = 1.0) const;
1125  DataObject div(const DataObject &mat2, const double scale = 1.0) const;
1126 
1127 
1128 
1129  // power (power of 0.5 is the square root)
1130  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)
1131  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.
1132 
1133  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)
1134  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)
1135 
1136  DataObject squeeze() const;
1137  DataObject reshape(int newDims, const int *newSizes) const;
1138 
1139  int elemSize() const;
1141 
1147  template<typename _Tp> inline const _Tp& at(const unsigned int y, const unsigned int x) const
1148  {
1149 #if __ITODEBUG
1150  if (m_dims != 2)
1151  {
1152  cv::error(cv::Exception(CV_StsAssert, "Dimension mismatch while addressing data field", "", __FILE__, __LINE__));
1153  }
1154  else if (((int)x >= m_size[1]) || ((int)y >= m_size[0]) )
1155  {
1156  cv::error(cv::Exception(CV_StsAssert, "Index out of bounds", "", __FILE__ , __LINE__));
1157  }
1158 #endif
1159  return (*reinterpret_cast<const cv::Mat_<_Tp>*>(m_data[0]))(y, x);
1160  }
1161 
1163 
1168  template<typename _Tp> inline _Tp& at(const unsigned int y, const unsigned int x)
1169  {
1170 #if __ITODEBUG
1171  if (m_dims != 2)
1172  {
1173  cv::error(cv::Exception(CV_StsAssert, "Dimension mismatch while addressing data field", "", __FILE__, __LINE__));
1174  }
1175  else if (((int)x >= m_size[1]) || ((int)y >= m_size[0]) )
1176  {
1177  cv::error(cv::Exception(CV_StsAssert, "Index out of bounds", "", __FILE__ , __LINE__));
1178  }
1179 #endif
1180  return (*reinterpret_cast<cv::Mat_<_Tp>*>(m_data[0]))(y, x);
1181  }
1182 
1184 
1190  template<typename _Tp> inline const _Tp& at(const unsigned int z, const unsigned int y, const unsigned int x) const
1191  {
1192 #if __ITODEBUG
1193  if (m_dims != 3)
1194  {
1195  cv::error(cv::Exception(CV_StsAssert, "Dimension mismatch while addressing data field", "", __FILE__, __LINE__));
1196  }
1197  else if (((int)x >= m_size[2]) || ((int)y >= m_size[1]) || (((int)z + m_roi[0]) >= (m_roi[0] + m_size[0])))
1198  {
1199  cv::error(cv::Exception(CV_StsAssert, "Index out of bounds", "", __FILE__ , __LINE__));
1200  }
1201 #endif
1202  return (*reinterpret_cast<const cv::Mat_<_Tp>*>(m_data[z + m_roi[0]]))(y, x);
1203  }
1204 
1206 
1212  template<typename _Tp> inline _Tp& at(const unsigned int z, const unsigned int y, const unsigned int x)
1213  {
1214 #if __ITODEBUG
1215  if (m_dims != 3)
1216  {
1217  cv::error(cv::Exception(CV_StsAssert, "Dimension mismatch while addressing data field", "", __FILE__, __LINE__));
1218  }
1219  else if (((int)x >= m_size[2]) || ((int)y >= m_size[1]) || (((int)z + m_roi[0]) >= (m_roi[0] + m_size[0])))
1220  {
1221  cv::error(cv::Exception(CV_StsAssert, "Index out of bounds", "", __FILE__ , __LINE__));
1222  }
1223 #endif
1224  return (*reinterpret_cast<cv::Mat_<_Tp>*>(m_data[z + m_roi[0]]))(y, x);
1225  }
1226 
1228 
1233  template<typename _Tp> inline const _Tp& at(const unsigned int *idx) const //idx is in virtual order
1234  {
1235  int matNum = 0;
1236  matIdxToNum(idx, &matNum);
1237  return (*reinterpret_cast<const cv::Mat_<_Tp>*>(m_data[matNum]))(idx[m_dims - 2], idx[m_dims - 1]);
1238  }
1239 
1241 
1246  template<typename _Tp> inline _Tp& at(const unsigned int *idx) //idx is in virtual order
1247  {
1248  int matNum = 0;
1249  matIdxToNum(idx, &matNum);
1250  return (*reinterpret_cast<cv::Mat_<_Tp>*>(m_data[matNum]))(idx[m_dims - 2], idx[m_dims - 1]);
1251  }
1252 
1253  DataObject at(const ito::Range &rowRange, const ito::Range &colRange) const;
1254  DataObject at(ito::Range *ranges) const;
1255  DataObject at(const DataObject &mask) const;
1257 
1264  inline uchar* rowPtr(const int matNum, const int y)
1265  {
1266  int matIndex = seekMat(matNum);
1267  return ((cv::Mat*)m_data[matIndex])->ptr(y);
1268  }
1269 
1271 
1277  inline const uchar* rowPtr(const int matNum, const int y) const
1278  {
1279  int matIndex = seekMat(matNum);
1280  return ((const cv::Mat*)m_data[matIndex])->ptr(y);
1281  }
1282 
1284 
1291  template<typename _Tp> inline _Tp* rowPtr(const int matNum, const int y)
1292  {
1293  int matIndex = seekMat(matNum);
1294  return ((cv::Mat*)m_data[matIndex])->ptr<_Tp>(y);
1295  }
1296 
1298 
1305  template<typename _Tp> inline const _Tp* rowPtr(const int matNum, const int y) const
1306  {
1307  int matIndex = seekMat(matNum);
1308  return ((const cv::Mat*)m_data[matIndex])->ptr<_Tp>(y);
1309  }
1310 
1311  DataObject row(const int selRow) const;
1312  DataObject col(const int selCol) const;
1313 
1314  DataObject toGray(const int destinationType = ito::tUInt8) const;
1315  DataObject splitColor(const char* destinationColor, const int& dtype) const;
1316  DataObject lineCut(const double* coordinates, const int& len) const;
1317 
1318  // ROI
1319  DataObject & adjustROI(const int dtop, const int dbottom, const int dleft, const int dright);
1320  DataObject & adjustROI(const unsigned char dims, const int *lims);
1321  RetVal locateROI(int *wholeSizes, int *offsets) const;
1322  RetVal locateROI(int *lims) const;
1324 
1340  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
1341 
1343 
1367  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
1368 
1369  template<typename T2> operator T2 ();
1371  template<typename _Tp> RetVal linspace(const _Tp start, const _Tp end, const _Tp inc, const int transposed);
1372 
1374 
1378  static DataObject stack(const DataObject *mats, int num, unsigned int axis = 0);
1379 
1380  };
1381 
1382  //template<> DATAOBJ_EXPORT RetVal ito::DataObject::linspace<ito::int8>(const ito::int8 /*start*/, const ito::int8 /*end*/, const ito::int8 /*inc*/, const int /*transposed*/);
1383  //template<> DATAOBJ_EXPORT RetVal ito::DataObject::linspace<ito::uint8>(const ito::uint8 /*start*/, const ito::uint8 /*end*/, const ito::uint8 /*inc*/, const int /*transposed*/);
1384 
1385 
1386  //----------------------------------------------------------------------------------------------------------------------------------
1387  // functions for DataObject in namespace ITO, which are NOT member functions
1388  //----------------------------------------------------------------------------------------------------------------------------------
1389  DATAOBJ_EXPORT DataObject abs(const DataObject &dObj);
1390  DATAOBJ_EXPORT DataObject arg(const DataObject &dObj);
1391  DATAOBJ_EXPORT DataObject real(const DataObject &dObj);
1392  DATAOBJ_EXPORT DataObject imag(const DataObject &dObj);
1394  DATAOBJ_EXPORT DataObject makeContinuous(const DataObject &dObj);
1396 
1404  template<typename _Tp> inline _Tp numberConversion(ito::tDataType fromType, const void *scalar)
1405  {
1406  _Tp retValue;
1407 
1408  switch(fromType)
1409  {
1410  case ito::tUInt8:
1411  retValue = cv::saturate_cast<_Tp>(*(static_cast<const uint8*>(scalar)));
1412  break;
1413  case ito::tInt8:
1414  retValue = cv::saturate_cast<_Tp>(*(static_cast<const int8*>(scalar)));
1415  break;
1416  case ito::tUInt16:
1417  retValue = cv::saturate_cast<_Tp>(*(static_cast<const uint16*>(scalar)));
1418  break;
1419  case ito::tInt16:
1420  retValue = cv::saturate_cast<_Tp>(*(static_cast<const int16*>(scalar)));
1421  break;
1422  case ito::tUInt32:
1423  retValue = cv::saturate_cast<_Tp>(*(static_cast<const uint32*>(scalar)));
1424  break;
1425  case ito::tInt32:
1426  retValue = cv::saturate_cast<_Tp>(*(static_cast<const int32*>(scalar)));
1427  break;
1428  case ito::tFloat32:
1429  retValue = cv::saturate_cast<_Tp>(*(static_cast<const ito::float32*>(scalar)));
1430  break;
1431  case ito::tFloat64:
1432  retValue = cv::saturate_cast<_Tp>(*(static_cast<const ito::float64*>(scalar)));
1433  break;
1434  case ito::tComplex64:
1435  retValue = cv::saturate_cast<_Tp>(*(static_cast<const ito::complex64*>(scalar)));
1436  break;
1437  case ito::tComplex128:
1438  retValue = cv::saturate_cast<_Tp>(*(static_cast<const ito::complex128*>(scalar)));
1439  break;
1440  case ito::tRGBA32:
1441  retValue = cv::saturate_cast<_Tp>(*(static_cast<const ito::Rgba32*>(scalar)));
1442  break;
1443  default:
1444  cv::error(cv::Exception(CV_StsAssert, "Input value type unkown", "", __FILE__, __LINE__));
1445  retValue = 0;
1446  }
1447 
1448  return retValue;
1449  };
1450 
1452  DATAOBJ_EXPORT std::ostream& operator << (std::ostream& out, const DataObject& dObj);
1453 
1455 
1463  {
1464  switch(cmplxType)
1465  {
1466  case ito::tInt8:
1467  case ito::tUInt8:
1468  case ito::tInt16:
1469  case ito::tUInt16:
1470  case ito::tInt32:
1471  case ito::tUInt32:
1472  case ito::tFloat32:
1473  case ito::tFloat64:
1474  case ito::tRGBA32:
1475  return cmplxType;
1476  case ito::tComplex64:
1477  return ito::tFloat32;
1478  case ito::tComplex128:
1479  return ito::tFloat64;
1480  }
1481 
1482  cv::error(cv::Exception(CV_StsAssert, "Input data type unknown", "", __FILE__, __LINE__));
1483  return ito::tInt8;
1484  }
1485 
1487 
1494  inline ito::tDataType guessDataTypeFromCVMat(const cv::Mat* mat, ito::RetVal &retval)
1495  {
1496  if (mat)
1497  {
1498  switch(mat->type())
1499  {
1500  case cv::DataType<ito::int8>::type:
1501  return ito::tInt8;
1502  case cv::DataType<ito::uint8>::type:
1503  return ito::tUInt8;
1504  case cv::DataType<ito::int16>::type:
1505  return ito::tInt16;
1506  case cv::DataType<ito::uint16>::type:
1507  return ito::tUInt16;
1508  case cv::DataType<ito::int32>::type:
1509  return ito::tInt32;
1510  case cv::DataType<ito::uint32>::type:
1511  return ito::tUInt32;
1512  case cv::DataType<ito::float32>::type:
1513  return ito::tFloat32;
1514  case cv::DataType<ito::float64>::type:
1515  return ito::tFloat64;
1516  case cv::DataType<ito::Rgba32>::type:
1517  return ito::tRGBA32;
1518  case cv::DataType<ito::complex64>::type:
1519  return ito::tComplex64;
1520  case cv::DataType<ito::complex128>::type:
1521  return ito::tComplex128;
1522  }
1523 
1524  retval += ito::RetVal(ito::retError, 0, "type of cv::Mat is incompatible to ito::DataObject");
1525  }
1526  else
1527  {
1528  retval += ito::RetVal(ito::retError, 0, "given cv::Mat is NULL.");
1529  }
1530  return ito::tInt8;
1531  }
1532 
1533 
1535 
1543  template<typename _Tp> inline ito::tDataType getDataType(const _Tp* /*src*/)
1544  {
1545  cv::error(cv::Exception(CV_StsAssert, "Input value type unkown", "", __FILE__, __LINE__));
1546  return ito::tInt8;
1547  }
1548 
1549  template<> inline ito::tDataType getDataType(const uint8* /*src*/) { return ito::tUInt8; }
1550  template<> inline ito::tDataType getDataType(const int8* /*src*/) { return ito::tInt8; }
1551  template<> inline ito::tDataType getDataType(const uint16* /*src*/) { return ito::tUInt16; }
1552  template<> inline ito::tDataType getDataType(const int16* /*src*/) { return ito::tInt16; }
1553  template<> inline ito::tDataType getDataType(const uint32* /*src*/) { return ito::tUInt32; }
1554  template<> inline ito::tDataType getDataType(const int32* /*src*/) { return ito::tInt32; }
1555  template<> inline ito::tDataType getDataType(const float32* /*src*/) { return ito::tFloat32; }
1556  template<> inline ito::tDataType getDataType(const float64* /*src*/) { return ito::tFloat64; }
1557  template<> inline ito::tDataType getDataType(const complex64* /*src*/) { return ito::tComplex64; }
1558  template<> inline ito::tDataType getDataType(const complex128* /*src*/) { return ito::tComplex128; }
1559  template<> inline ito::tDataType getDataType(const Rgba32* /*src*/) { return ito::tRGBA32; }
1560 
1561 
1563 
1572  template<typename _Tp> inline ito::tDataType getDataType2()
1573  {
1574  cv::error(cv::Exception(CV_StsAssert, "Input value type unkown", "", __FILE__, __LINE__));
1575  return ito::tInt8;
1576  }
1577 
1578  template<> inline ito::tDataType getDataType2<uint8*>() { return ito::tUInt8; }
1579  template<> inline ito::tDataType getDataType2<int8*>() { return ito::tInt8; }
1580  template<> inline ito::tDataType getDataType2<uint16*>() { return ito::tUInt16; }
1581  template<> inline ito::tDataType getDataType2<int16*>() { return ito::tInt16; }
1582  template<> inline ito::tDataType getDataType2<uint32*>() { return ito::tUInt32; }
1583  template<> inline ito::tDataType getDataType2<int32*>() { return ito::tInt32; }
1584  template<> inline ito::tDataType getDataType2<float32*>() { return ito::tFloat32; }
1585  template<> inline ito::tDataType getDataType2<float64*>() { return ito::tFloat64; }
1586  template<> inline ito::tDataType getDataType2<complex64*>() { return ito::tComplex64; }
1587  template<> inline ito::tDataType getDataType2<complex128*>() { return ito::tComplex128; }
1588  template<> inline ito::tDataType getDataType2<Rgba32*>() { return ito::tRGBA32; }
1589 
1590 } //namespace ito
1591 
1592 #endif //__DATAOBJH
1593 
1594 
int getType(void) const
returns type of tag (
Definition: dataobj.h:308
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:311
double m_dVal
if the tag type is double, the real double value is stored here
Definition: dataobj.h:283
_Tp & at(const unsigned int z, const unsigned int y, const unsigned int x)
addressing method for three-dimensional data object.
Definition: dataobj.h:1212
iterator through data object
Definition: dataobj.h:448
dataObject contains a n-dimensional matrix
Definition: dataobj.h:511
Range(int _start, int _end)
Definition: dataobj.h:256
Definition: typeDefs.h:99
MSize getSize(void)
returns the size-member. m_size fits to the physical organization of data in memory.
Definition: dataobj.h:885
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:10131
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:2447
MSize m_osize
Definition: dataobj.h:599
int start
Definition: dataobj.h:261
ByteArray m_strValue
if the tag type is string, the string data is stored in this ByteArray variable.
Definition: dataobj.h:285
_Tp & at(const unsigned int y, const unsigned int x)
addressing method for two-dimensional data object.
Definition: dataobj.h:1168
tTagType
Definition: dataobj.h:275
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:3815
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:1543
Definition: dataobj.h:534
Definition: typeDefs.h:91
Definition: typeDefs.h:60
const DataObject * dObj
reference to the related data object
Definition: dataobj.h:430
Definition: typeDefs.h:96
MROI m_roi
Definition: dataobj.h:600
uchar * ptr
pointer to the current value of the iterator
Definition: dataobj.h:433
Class for managing status values (like errors or warning)
Definition: retVal.h:54
unsigned int size() const
Definition: dataobj.h:257
Definition: color.h:258
Definition: typeDefs.h:98
Definition: typeDefs.h:97
DataObjectTagsPrivate * m_pDataObjectTags
Definition: dataobj.h:603
_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:1291
int getType(void) const
Definition: dataobj.h:794
const _Tp & at(const unsigned int y, const unsigned int x) const
addressing method for two-dimensional data object.
Definition: dataobj.h:1147
uchar * sliceEnd
pointer to the last item within the current continuous slice
Definition: dataobj.h:435
Definition: typeDefs.h:94
uint32 & argb()
Definition: color.h:250
Definition: dataobj.h:54
const cv::Mat ** get_mdata(void) const
returns constant array of pointers to cv::_Mat-matrices (planes) of the data object ...
Definition: dataobj.h:876
bool empty() const
Definition: dataobj.h:258
This is a Qt-free class for byte arrays (strings) without specific encoding information.
Definition: byteArray.h:64
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:1190
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:10648
Definition: typeDefs.h:89
DataObjectTagType(const char *cVal)
Copy Constructor.
Definition: dataobj.h:293
_Tp & at(const unsigned int *idx)
addressing method for n-dimensional data object.
Definition: dataobj.h:1246
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:10622
ito::tDataType guessDataTypeFromCVMat(const cv::Mat *mat, ito::RetVal &retval)
method which guesses the dataObject type from a given cv::Mat*
Definition: dataobj.h:1494
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:1726
ByteArray getVal_ToString(void)
Definition: dataobj.h:341
char getOwnData(void) const
Definition: dataobj.h:800
RetVal copyFromData2D(const _Tp *src, const int sizeX, const int sizeY)
copies the externally given source data inside this data object
Definition: dataobj.h:1340
_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:1404
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:920
int * m_pRefCount
Definition: dataobj.h:597
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:10012
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:1277
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:252
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:927
ito::tDataType convertCmplxTypeToRealType(ito::tDataType cmplxType)
method which returns the real data type of any given data type
Definition: dataobj.h:1462
int getDims(void) const
Definition: dataobj.h:791
Definition: typeDefs.h:93
int plane
plane index where the iterator is currently positioned
Definition: dataobj.h:436
tag type double
Definition: dataobj.h:278
RetVal FreeFunc(DataObject *dObj)
low-level, templated method for freeing allocated data blocks
Definition: dataobj.cpp:781
int getTotal() const
gets total number of elements within the data object's ROI
Definition: dataobj.h:955
Variant storage class for either a double or a string value.
Definition: dataobj.h:272
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:1367
Definition: typeDefs.h:95
int m_type
Definition: dataobj.h:596
uchar ** m_data
Definition: dataobj.h:602
int m_dims
Definition: dataobj.h:598
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:6961
char m_continuous
Definition: dataobj.h:594
Definition: dataobj.h:562
bool operator==(const ByteArray &a1, const char *a2)
comparison operator that returns true if the content of a1 is equal to the given zero-terminated stri...
Definition: byteArray.h:185
const _Tp & at(const unsigned int *idx) const
addressing method for n-dimensional data object.
Definition: dataobj.h:1233
MSize getOriginalSize(void)
returns the original size-member. This is equal to getSize() if no roi is set to the dataObject...
Definition: dataobj.h:914
int getSize(int index) const
gets the size of the given dimension (this is the size within the ROI)
Definition: dataobj.h:898
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:1305
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:891
Definition: typeDefs.h:92
bool planeContinuous
indicates whether dObj is continuously organized in each plane for faster seek operations ...
Definition: dataobj.h:431
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:10774
int end
Definition: dataobj.h:262
constant iterator through data object
Definition: dataobj.h:376
cv::Mat ** get_mdata(void)
returns array of pointers to cv::_Mat-matrices (planes) of the data object.
Definition: dataobj.h:861
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:6817
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:1939
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:10215
tag type string (
Definition: dataobj.h:279
bool operator!=(const ByteArray &a1, const char *a2)
comparison operator that returns true if the content of a1 is not equal to the given zero-terminated ...
Definition: byteArray.h:197
char getContinuous(void) const
Definition: dataobj.h:797
char m_owndata
Definition: dataobj.h:595
DataObjectTagType()
< Constructor
Definition: dataobj.h:289
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:255
tDataType
Definition: typeDefs.h:87
int getNumPlanes(void) const
calculates numbers of single opencv matrices which are part of the ROI which has previously been set...
Definition: dataobj.h:817
ito::tDataType getDataType2()
method which returns the value of enumeration ito::tDataType, which corresponds to the template param...
Definition: dataobj.h:1572
Definition: typeDefs.h:90
tTagType m_type
type indicator of this class (invalid, double or string)
Definition: dataobj.h:284
int getOriginalTotal() const
gets total number of elements of the whole data object
Definition: dataobj.h:972
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:1264
const char * data() const
return the pointer to the internal character array. If it is empty, the returned pointer still points...
Definition: byteArray.h:131
static Range all()
Definition: dataobj.h:259
double getVal_ToDouble(void)
Definition: dataobj.h:318
MSize m_size
Definition: dataobj.h:601
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:9509
invalid tag type
Definition: dataobj.h:277
uchar * sliceStart
pointer to the first item within the current continuous slice
Definition: dataobj.h:434