itom
Loading...
Searching...
No Matches
dataobj.h
1/* ********************************************************************
2 itom software
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2020, Institut für Technische Optik (ITO),
5 Universität 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 für 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// see: http://social.msdn.microsoft.com/Forums/sv/vclanguage/thread/d986a370-d856-4f9e-9f14-53f3b18ab63e,
44// this is only an issue with OpenCV 2.4.3, not 2.3.x
45#define NOMINMAX
46
47#include "opencv2/opencv.hpp"
48#include "opencv2/core/core.hpp"
49#include "opencv2/core/types_c.h"
50
51#include "../common/sharedStructures.h"
52#include "../common/color.h"
53#include "../common/byteArray.h"
54
55
56namespace cv
57{
58 template<> inline ito::float32 saturate_cast<ito::float32>( ito::float64 v)
59 {
60 if(std::isinf(v))
61 return std::numeric_limits<ito::float32>::infinity();
62 if(std::isnan(v))
63 return std::numeric_limits<ito::float32>::quiet_NaN();
64 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)()) )));
65 }
66
67 template<> inline ito::float64 saturate_cast<ito::float64>( ito::float32 v)
68 {
69 if(std::isinf(v))
70 return std::numeric_limits<ito::float64>::infinity();
71 if(std::isnan(v))
72 return std::numeric_limits<ito::float64>::quiet_NaN();
73 return static_cast<ito::float64>(v);
74 }
75
76 template<typename _Tp> static inline _Tp saturate_cast(ito::complex128 /*v*/)
77 {
78 cv::error(cv::Exception(CV_StsAssert, "Not defined for input parameter type", "", __FILE__, __LINE__));
79 return 0;
80 }
81
82 template<typename _Tp> static inline _Tp saturate_cast(ito::complex64 /*v*/)
83 {
84 cv::error(cv::Exception(CV_StsAssert, "Not defined for input parameter type", "", __FILE__, __LINE__));
85 return 0;
86 }
87
88 template<typename _Tp> static inline _Tp saturate_cast(ito::Rgba32 /*v*/)
89 {
90 cv::error(cv::Exception(CV_StsAssert, "Not defined for input parameter type", "", __FILE__, __LINE__));
91 return 0;
92 }
93
94 template<typename _Tp> static inline _Tp saturate_cast(ito::DateTime /*v*/)
95 {
96 cv::error(cv::Exception(CV_StsAssert, "Not defined for input parameter type", "", __FILE__, __LINE__));
97 return 0;
98 }
99
100 template<typename _Tp> static inline _Tp saturate_cast(ito::TimeDelta /*v*/)
101 {
102 cv::error(cv::Exception(CV_StsAssert, "Not defined for input parameter type", "", __FILE__, __LINE__));
103 return 0;
104 }
105
106 template<> inline ito::Rgba32 saturate_cast(ito::DateTime /*v*/)
107 {
108 cv::error(cv::Exception(CV_StsAssert, "Not defined for input parameter type", "", __FILE__, __LINE__));
109 return ito::Rgba32::black();
110 }
111
112 template<> inline ito::Rgba32 saturate_cast(ito::TimeDelta /*v*/)
113 {
114 cv::error(cv::Exception(CV_StsAssert, "Not defined for input parameter type", "", __FILE__, __LINE__));
115 return ito::Rgba32::black();
116 }
117
118 template<> inline ito::TimeDelta saturate_cast(ito::TimeDelta v) { return v; }
119 template<> inline ito::DateTime saturate_cast(ito::DateTime v) { return v; }
120
121 template<> inline ito::complex64 saturate_cast(ito::uint8 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); }
122 template<> inline ito::complex64 saturate_cast(ito::int8 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); }
123 template<> inline ito::complex64 saturate_cast(ito::uint16 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); }
124 template<> inline ito::complex64 saturate_cast(ito::int16 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); }
125 template<> inline ito::complex64 saturate_cast(ito::uint32 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); }
126 template<> inline ito::complex64 saturate_cast(ito::int32 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); }
127 template<> inline ito::complex64 saturate_cast(ito::float32 v){ return ito::complex64(v,0.0); }
128 template<> inline ito::complex64 saturate_cast(ito::float64 v){ return ito::complex64(saturate_cast<ito::float32>(v),0.0); }
129 template<> inline ito::complex64 saturate_cast(ito::complex64 v){ return v; }
130 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())); }
131
132 template<> inline ito::complex128 saturate_cast(ito::uint8 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); }
133 template<> inline ito::complex128 saturate_cast(ito::int8 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); }
134 template<> inline ito::complex128 saturate_cast(ito::uint16 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); }
135 template<> inline ito::complex128 saturate_cast(ito::int16 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); }
136 template<> inline ito::complex128 saturate_cast(ito::uint32 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); }
137 template<> inline ito::complex128 saturate_cast(ito::int32 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); }
138 template<> inline ito::complex128 saturate_cast(ito::float32 v){ return ito::complex128(saturate_cast<ito::float64>(v),0.0); }
139 template<> inline ito::complex128 saturate_cast(ito::float64 v){ return ito::complex128(v,0.0); }
140 template<> inline ito::complex128 saturate_cast(ito::complex64 v){ return ito::complex128(saturate_cast<ito::float64>(v.real()),saturate_cast<ito::float64>(v.imag())); }
141 template<> inline ito::complex128 saturate_cast(ito::complex128 v){ return v; }
142
143 // template<> inline ito::Rgba32 saturate_cast(ito::int8 v) {return ito::Rgba32(saturate_cast<ito::uint8>(v));}
144 template<> inline ito::Rgba32 saturate_cast(ito::uint8 v) {return ito::Rgba32(v);}
145 template<> inline ito::Rgba32 saturate_cast(ito::uint16 v){return ito::Rgba32(saturate_cast<ito::uint8>(v));}
146 // template<> inline ito::Rgba32 saturate_cast(ito::int16 v){return ito::Rgba32(saturate_cast<ito::uint8>(v));}
147 template<> inline ito::Rgba32 saturate_cast(ito::uint32 v)
148 {
150 }
151 template<> inline ito::Rgba32 saturate_cast(ito::int32 v)
152 {
153 ito::Rgba32 temp;
154 temp.rgba = static_cast<ito::uint32>(v);
155 return temp;
156 }
157 template<> inline ito::Rgba32 saturate_cast(ito::float32 v){return ito::Rgba32(saturate_cast<ito::uint8>(v));}
158 template<> inline ito::Rgba32 saturate_cast(ito::float64 v){return ito::Rgba32(saturate_cast<ito::uint8>(v));}
159 template<> inline ito::Rgba32 saturate_cast(ito::Rgba32 v){return v;}
160
161 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(); }
162 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(); }
163 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(); }
164 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(); }
165
166 template<> inline ito::uint8 saturate_cast(ito::Rgba32 v){return saturate_cast<ito::uint8>(v.gray());};
167 //template<> inline ito::int16 saturate_cast(ito::Rgba32 v){return saturate_cast<ito::int16>(v.gray());};
168 template<> inline ito::uint16 saturate_cast(ito::Rgba32 v){return saturate_cast<ito::uint16>(v.gray());};
169 template<> inline ito::uint32 saturate_cast(ito::Rgba32 v){return v.argb();};
170 template<> inline ito::int32 saturate_cast(ito::Rgba32 v){return (ito::int32)(v.argb());};
171 template<> inline ito::float32 saturate_cast(ito::Rgba32 v){return v.gray();};
172 template<> inline ito::float64 saturate_cast(ito::Rgba32 v){return (ito::float64)v.gray();};
173
174#if (CV_MAJOR_VERSION > 3) || (CV_MAJOR_VERSION == 3 && CV_MINOR_VERSION >= 3)
175 //from CV 3.3.1 on, the default implementation of DataType is dropped:
176 //Original note in traits.hpp of OpenCV: Default values were dropped to stop confusing developers about using of unsupported types (see #7599)
177 template<> class DataType<ito::uint32>
178 {
179 public:
180 typedef ito::uint32 value_type;
181 typedef value_type work_type;
182 typedef value_type channel_type;
183 typedef value_type vec_type;
184 enum { generic_type = 1, depth = -1, channels = 1, fmt=0,
185 type = CV_MAKETYPE(depth, channels) };
186 };
187#endif
188
189 template<> class DataType<ito::Rgba32>
190 {
191 public:
192 typedef ito::Rgba32 value_type;
193 typedef ito::uint8 channel_type;
194 typedef Vec<channel_type, 4> work_type;
195 typedef value_type vec_type;
196 enum
197 {
198 generic_type = 0,
199 depth = cv::DataDepth<channel_type>::value,
200 channels = 4,
201 fmt = ((channels-1)<<8) + cv::DataDepth<channel_type>::fmt,
202 type = CV_MAKETYPE(depth, channels)
203 };
204 };
205
206 template<> class DataType<ito::RedChannel>
207 {
208 public:
210 typedef ito::uint8 channel_type;
211 typedef Vec<channel_type, 4> work_type;
212 typedef value_type vec_type;
213 enum
214 {
215 generic_type = 0,
216 depth = cv::DataDepth<channel_type>::value,
217 channels = 4,
218 fmt = ((channels-1)<<8) + cv::DataDepth<channel_type>::fmt,
219 type = CV_MAKETYPE(depth, channels)
220 };
221 };
222
223 template<> class DataType<ito::GreenChannel>
224 {
225 public:
227 typedef ito::uint8 channel_type;
228 typedef Vec<channel_type, 4> work_type;
229 typedef value_type vec_type;
230 enum
231 {
232 generic_type = 0,
233 depth = cv::DataDepth<channel_type>::value,
234 channels = 4,
235 fmt = ((channels-1)<<8) + cv::DataDepth<channel_type>::fmt,
236 type = CV_MAKETYPE(depth, channels)
237 };
238 };
239
240 template<> class DataType<ito::BlueChannel>
241 {
242 public:
244 typedef ito::uint8 channel_type;
245 typedef Vec<channel_type, 4> work_type;
246 typedef value_type vec_type;
247 enum
248 {
249 generic_type = 0,
250 depth = cv::DataDepth<channel_type>::value,
251 channels = 4,
252 fmt = ((channels-1)<<8) + cv::DataDepth<channel_type>::fmt,
253 type = CV_MAKETYPE(depth, channels)
254 };
255 };
256
257 template<> class DataType<ito::AlphaChannel>
258 {
259 public:
261 typedef ito::uint8 channel_type;
262 typedef Vec<channel_type, 4> work_type;
263 typedef value_type vec_type;
264 enum
265 {
266 generic_type = 0,
267 depth = cv::DataDepth<channel_type>::value,
268 channels = 4,
269 fmt = ((channels-1)<<8) + cv::DataDepth<channel_type>::fmt,
270 type = CV_MAKETYPE(depth, channels)
271 };
272 };
273
274 template<> class DataType<ito::DateTime>
275 {
276 public:
278 typedef ito::uint8 channel_type;
279 typedef ito::DateTime work_type;
280 typedef value_type vec_type;
281 enum
282 {
283 generic_type = 0,
284 depth = cv::DataDepth<channel_type>::value,
285 channels = sizeof(ito::DateTime),
286 fmt = ((channels - 1) << 8) + cv::DataDepth<channel_type>::fmt,
287 type = CV_MAKETYPE(depth, channels)
288 };
289 };
290
291 template<> class DataType<ito::TimeDelta>
292 {
293 public:
295 typedef ito::uint8 channel_type;
297 typedef value_type vec_type;
298 enum
299 {
300 generic_type = 0,
301 depth = cv::DataDepth<channel_type>::value,
302 channels = sizeof(ito::TimeDelta),
303 fmt = ((channels - 1) << 8) + cv::DataDepth<channel_type>::fmt,
304 type = CV_MAKETYPE(depth, channels)
305 };
306 };
307
308
309} // namespace cv
310
311namespace ito {
312
313#define __ITODEBUG 1
314
315 //forward declarations
316 class DObjIterator;
317 class DataObject;
318 class Range;
319 class DataObjectTags;
320 class DataObjectTagType;
321 class DataObjectTagsPrivate;
322
323
324 //----------------------------------------------------------------------------------------------------------------------------------
331 class DATAOBJ_EXPORT Range
332 {
333 public:
334 Range() : start(0), end(0) {}
335 Range(int _start, int _end) { _start < _end ? (end = _end, start = _start) : (start = _end, end = _start); }
336 inline unsigned int size() const { return end - start; }
337 inline bool empty() const { return (start == end); }
338 static Range all() { return Range(INT_MIN, INT_MAX); }
340 int start;
341 int end;
342 };
343
344 //----------------------------------------------------------------------------------------------------------------------------------
351 class DATAOBJ_EXPORT DataObjectTagType
352 {
353 public:
355 {
356 typeInvalid = 0x000000,
357 typeDouble = 0x000008,
358 typeString = 0x000020
359 };
360
361 private:
362 double m_dVal;
365
366 public:
368 DataObjectTagType() : m_dVal(0), m_strValue(""), m_type(DataObjectTagType::typeInvalid){}
369 DataObjectTagType(double dVal) : m_dVal(dVal), m_strValue(""), m_type(DataObjectTagType::typeDouble){}
370 DataObjectTagType(const std::string &str) : m_dVal(std::numeric_limits<double>::quiet_NaN()), m_type(DataObjectTagType::typeString){ m_strValue = str.data(); }
371 DataObjectTagType(const ByteArray &str) : m_dVal(std::numeric_limits<double>::quiet_NaN()), m_type(DataObjectTagType::typeString){ m_strValue = str; }
372 DataObjectTagType(const char* cVal) : m_dVal(std::numeric_limits<double>::quiet_NaN()), m_type(DataObjectTagType::typeString){ cVal == NULL ? m_strValue = "" : m_strValue = cVal;}
374 DataObjectTagType(const DataObjectTagType& a) : m_dVal(a.m_dVal), m_type(a.m_type), m_strValue(a.m_strValue) {}
375
377 DataObjectTagType & operator = (const DataObjectTagType &rhs)
378 {
379 this->m_dVal = rhs.m_dVal;
380 this->m_strValue = rhs.m_strValue;
381 this->m_type = rhs.m_type;
382
383 return *this;
384 }
385
387 inline int getType(void) const {return m_type;}
388
390 inline bool isValid(void) const { return (m_type == DataObjectTagType::typeInvalid) ? false: true;}
391
397 inline double getVal_ToDouble(void)
398 {
399 if(m_type == DataObjectTagType::typeInvalid)
400 {
401 return std::numeric_limits<double>::quiet_NaN();
402 }
403 else if(m_type == DataObjectTagType::typeDouble)
404 {
405 return m_dVal;
406 }
407 else
408 {
409 constexpr double dVal = std::numeric_limits<double>::quiet_NaN();
410 //dVal = atof(m_strValue.c_str()); //sometimes the result of that line has been arbitrary, therefore this conversion should fail.
411 return dVal;
412 }
413 }
414
421 {
422 if(m_type == DataObjectTagType::typeInvalid)
423 {
424 return "";
425 }
426 else if(m_type == DataObjectTagType::typeString)
427 {
428 return m_strValue;
429 }
430 else
431 {
432 if (std::isnan(m_dVal)) return "NaN";
433 if (std::isinf(m_dVal)) return "Inf";
434
435 std::ostringstream strs;
436 strs << m_dVal;
437 ByteArray ba(strs.str().data());
438
439 return ba;
440 }
441 }
442 };
443
444 //----------------------------------------------------------------------------------------------------------------------------------
455 class DATAOBJ_EXPORT DObjConstIterator
456 {
457 public:
458
461
463 DObjConstIterator(const DataObject* _dObj, int pos = 0);
464
467
469 DObjConstIterator& operator = (const DObjConstIterator& it);
470
472 const uchar* operator *() const;
473
475 const uchar* operator [](int i) const;
476
478 DObjConstIterator& operator += (int ofs);
479
481 DObjConstIterator& operator -= (int ofs);
482
484 DObjConstIterator& operator --();
485
487 DObjConstIterator operator --(int);
488
490 DObjConstIterator& operator ++();
491
493 DObjConstIterator operator ++(int);
494
495 bool operator == (const DObjConstIterator& dObjIt);
496 bool operator != (const DObjConstIterator& dObjIt);
497 bool operator < (const DObjConstIterator& dObjIt);
498 bool operator > (const DObjConstIterator& dObjIt);
499 bool operator <= (const DObjConstIterator& dObjIt);
500 bool operator >= (const DObjConstIterator& dObjIt);
501
502 protected:
504 void seekAbs(int ofs);
505
507 void seekRel(int ofs);
508
511 int elemSize;
512 uchar* ptr;
513 uchar* sliceStart;
514 uchar* sliceEnd;
515 int plane;
516 };
517
518 //----------------------------------------------------------------------------------------------------------------------------------
527 class DATAOBJ_EXPORT DObjIterator : public DObjConstIterator
528 {
529 public:
530
532 DObjIterator();
533
535 DObjIterator(DataObject* _dObj, int pos = 0);
536
538 DObjIterator(const DObjIterator& it);
539
541 DObjIterator& operator = (const DObjIterator& it);
542
544 uchar* operator *();
545
547 uchar* operator [](int i);
548
550 DObjIterator& operator += (int ofs);
551
553 DObjIterator& operator -= (int ofs);
554
556 DObjIterator& operator --();
557
559 DObjIterator operator --(int);
560
562 DObjIterator& operator ++();
563
565 DObjIterator operator ++(int);
566 };
567
568//----------------------------------------------------------------------------------------------------------------------------------
569
570// Forward declaration of friend methods
571#ifdef __APPLE__
572 template<typename _Tp> RetVal CreateFunc(DataObject *dObj, const unsigned char dimensions, const int *sizes, const unsigned char continuous, const uchar* continuousDataPtr, const int* steps);
573 template<typename _Tp> RetVal CreateFuncWithCVPlanes(DataObject *dObj, const unsigned char dimensions, const int *sizes, const cv::Mat* planes, const unsigned int nrOfPlanes);
574 template<typename _Tp> RetVal FreeFunc(DataObject *dObj);
575 template<typename _Tp> RetVal SecureFreeFunc(DataObject *dObj);
576 template<typename _Tp> RetVal CopyToFunc(const DataObject &lhs, DataObject &rhs, unsigned char regionOnly);
577 template<typename _Tp> RetVal ConvertToFunc(const DataObject &lhs, DataObject &rhs, const int type, const double alpha, const double beta);
578 template<typename _Tp> RetVal AdjustROIFunc(DataObject *dObj, const int *lims);
579 //template<typename _Tp> RetVal MinMaxLocFunc(const DataObject &dObj, double *minVal, double *maxVal, int *minPos, int *maxPos);
580 template<typename _Tp> RetVal AssignScalarFunc(const DataObject *src, const ito::tDataType type, const void *scalar);
581 template<typename _Tp> RetVal MakeContinuousFunc(const DataObject &dObj, DataObject &resDObj);
582 template<typename _Tp> RetVal EvaluateTransposeFlagFunc(DataObject *dObj);
583 template<typename _Tp> std::ostream& coutFunc(std::ostream& out, const DataObject& dObj);
584
585 // more friends due to change of std::vector to int ** for m_data ...
586 template<typename _Tp> RetVal GetRangeFunc(DataObject *dObj, const int dtop, const int dbottom, const int dleft, const int dright);
587 template<typename _Tp> RetVal AdjustROIFunc(DataObject *dObj, int dtop, int dbottom, int dleft, int dright);
588#endif // __APPLE__
589
590 class DATAOBJ_EXPORT DataObject
591 {
592 private:
594 void createHeader(const unsigned char dimensions, const int *sizes, const int *steps, const int elemSize);
595
597 void createHeaderWithROI(const unsigned char dimensions, const int *sizes, const int *osizes = NULL, const int *roi = NULL);
598
599 void create(const unsigned char dimensions, const int *sizes, const int type, const unsigned char continuous, const uchar* continuousDataPtr = NULL, const int* steps = NULL);
600 void create(const unsigned char dimensions, const int *sizes, const int type, const cv::Mat* planes, const unsigned int nrOfPlanes);
601
602 void freeData(void);
603 void secureFreeData(void);
606 //----------------------------------------------------------------------------------------------------------------------------------
607 ito::RetVal matNumToIdx(const int matNum, int *matIdx) const;
608
610 ito::RetVal matIdxToNum(const unsigned int *matIdx, int *matNum) const;
611
612
613 struct DATAOBJ_EXPORT MSize
614 {
615 inline MSize() : m_p(NULL) {}
616 inline int operator [] (const int dim) const
617 {
618 return m_p[dim]; //return the size value. this operator corresponds to the real data representation in memory
619 };
620 inline operator const int * () const { return m_p; }
621 inline bool operator == (const MSize& sz) const
622 {
623 if(m_p == NULL || sz.m_p == NULL)
624 {
625 return sz.m_p == m_p;
626 }
627
628 int d = m_p[-1];
629 if( d != sz.m_p[-1] )
630 return false;
631
632 return (memcmp(m_p, sz.m_p, d * sizeof(int)) == 0); //returns true if the size vector (having the same length) is equal
633 }
634
635 inline bool operator != (const MSize& sz) const { return !(*this == sz); }
636
637 int *m_p;
638 };
639
640
641 struct DATAOBJ_EXPORT MROI
642 {
643 inline MROI() : m_p(NULL) {};
644 inline int operator [] (const int dim) const
645 {
646 return m_p[dim]; //return the size value. this operator corresponds to the real data representation in memory
647 }
648
649 inline bool operator == (const MROI & rroi) const
650 {
651 if(m_p == NULL || rroi.m_p == NULL)
652 {
653 return rroi.m_p == m_p;
654 }
655
656 int d = m_p[-1];
657 if( d != rroi.m_p[-1] )
658 return false;
659
660 return (memcmp(m_p, rroi.m_p, d * sizeof(int)) == 0); //returns true if the size vector (having the same length) is equal
661
662 if (m_p[-1] != rroi.m_p[-1])
663 {
664 return false;
665 }
666 }
667
668 int *m_p;
669 };
670
671 DataObject(const DataObject& dObj, bool transposed);
675 int m_type;
677 int m_dims;
681 uchar **m_data;
683 static const int m_sizeofs;
684
685 int mdata_realloc(const int size);
686 int mdata_size(void) const;
687 int mdata_free();
688
689 RetVal copyFromData2DInternal(const uchar* src, const int sizeOfElem, const int sizeX, const int sizeY);
690 RetVal copyFromData2DInternal(const uchar* src, const int sizeOfElem, const int sizeX, const int x0, const int y0, const int width, const int height);
691
692 //low-level, templated methods
693 //most low-level methods are marked "friend" such that they can access private members of their data object parameters
694 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);
695 template<typename _Tp> friend RetVal CreateFuncWithCVPlanes(DataObject *dObj, const unsigned char dimensions, const int *sizes, const cv::Mat* planes, const unsigned int nrOfPlanes);
696 template<typename _Tp> friend RetVal FreeFunc(DataObject *dObj);
697 template<typename _Tp> friend RetVal SecureFreeFunc(DataObject *dObj);
698 template<typename _Tp> friend RetVal CopyToFunc(const DataObject &lhs, DataObject &rhs, unsigned char regionOnly);
699 template<typename _Tp> friend RetVal ConvertToFunc(const DataObject &lhs, DataObject &rhs, const int type, const double alpha, const double beta);
700 template<typename _Tp> friend RetVal AdjustROIFunc(DataObject *dObj, const int *lims);
701 //template<typename _Tp> friend RetVal MinMaxLocFunc(const DataObject &dObj, double *minVal, double *maxVal, int *minPos, int *maxPos);
702 template<typename _Tp> friend RetVal AssignScalarFunc(const DataObject *src, const ito::tDataType type, const void *scalar);
703 template<typename _Tp> friend RetVal MakeContinuousFunc(const DataObject &dObj, DataObject &resDObj);
704 template<typename _Tp> friend RetVal EvaluateTransposeFlagFunc(DataObject *dObj);
705 template<typename _Tp> friend std::ostream& coutFunc(std::ostream& out, const DataObject& dObj);
706
707 // more friends due to change of std::vector to int ** for m_data ...
708 template<typename _Tp> friend RetVal GetRangeFunc(DataObject *dObj, const int dtop, const int dbottom, const int dleft, const int dright);
709 template<typename _Tp> friend RetVal AdjustROIFunc(DataObject *dObj, int dtop, int dbottom, int dleft, int dright);
710
711 public:
713 DataObject(void);
714
716 DataObject(const int size, const int type);
717
719 DataObject(const int sizeY, const int sizeX, const int type);
720
722 DataObject(const int sizeZ, const int sizeY, const int sizeX, const int type, const unsigned char continuous = 0);
723
725 DataObject(const int sizeZ, const int sizeY, const int sizeX, const int type, const uchar* continuousDataPtr, const int* steps = NULL);
726
728 DataObject(const MSize &sizes, const int type, const unsigned char continuous = 0);
729
731 DataObject(const unsigned char dimensions, const int *sizes, const int type, const unsigned char continuous = 0);
732
734 DataObject(const unsigned char dimensions, const int *sizes, const int type, const uchar* continuousDataPtr, const int* steps = NULL);
735
737 DataObject(const unsigned char dimensions, const int *sizes, const int type, const cv::Mat* planes, const unsigned int nrOfPlanes);
738
740 DataObject(const cv::Mat &data);
741
742 DataObject(const DataObject& copyConstr);
745 ~DataObject(void);
746
747 // TAGSPACEFUNCTIONS
748
750 double getValueOffset() const;
751
753 double getValueScale() const;
754
756 const std::string getValueUnit() const;
757
759 std::string getValueDescription() const;
760
762 double getAxisOffset(const int axisNum) const;
763
765 double getAxisScale(const int axisNum) const;
766
768 const std::string getAxisUnit(const int axisNum, bool &validOperation) const;
769
771 std::string getAxisDescription(const int axisNum, bool &validOperation) const;
772
773 DataObjectTagType getTag(const std::string &key, bool &validOperation) const;
774
775 bool getTagByIndex(const int tagNumber, std::string &key, DataObjectTagType &value) const;
776
778 std::string getTagKey(const int tagNumber, bool &validOperation) const;
779
781 int getTagListSize() const;
782
784 int setValueUnit(const std::string &unit);
785
787 int setValueDescription(const std::string &description);
788
790 int setAxisOffset(const unsigned int axisNum, const double offset);
791
793 int setAxisScale(const unsigned int axisNum, const double scale);
794
796 int setAxisUnit(const unsigned int axisNum, const std::string &unit);
797
799 int setAxisDescription(const unsigned int axisNum, const std::string &description);
800 int setTag(const std::string &key, const DataObjectTagType &value);
801 bool existTag(const std::string &key) const;
802 bool deleteTag(const std::string &key);
803 bool deleteAllTags();
804 int addToProtocol(const std::string &value);
805
811 double getPhysToPix(const unsigned int dim, const double phys, bool &isInsideImage) const;
812
818 double getPhysToPix(const unsigned int dim, const double phys) const;
819
826 double getPhysToPixUnclipped(const unsigned int dim, const double phys) const;
827
831 int getPhysToPix2D(const double physY, double &tPxY, bool &isInsideImageY, const double physX, double &tPxX, bool &isInsideImageX) const;
832
836 double getPixToPhys(const unsigned int dim, const double pix, bool &isInsideImage) const;
837
841 double getPixToPhys(const unsigned int dim, const double pix) const;
842
856 RetVal setXYRotationalMatrix(double r11, double r12, double r13, double r21, double r22, double r23, double r31, double r32, double r33);
857
871 RetVal getXYRotationalMatrix(double &r11, double &r12, double &r13, double &r21, double &r22, double &r23, double &r31, double &r32, double &r33) const;
872
873 RetVal copyTagMapTo(DataObject &rhs) const;
874 RetVal copyAxisTagsTo(DataObject &rhs) const;
876 RetVal setReal(DataObject &valuesObj); /*change the real part of a complex data object*/
877 RetVal setImag(DataObject &valuesObj); /*change the imaginary part of a complex data object*/
878
879 // END TAGSPACE
880
882 inline int getDims(void) const { return m_dims; }
883
885 inline int getType(void) const { return m_type; }
886
888 inline char getContinuous(void) const { return m_continuous; }
889
891 inline char getOwnData(void) const { return m_owndata; }
892
894 int seekMat(const int matNum, const int numMats) const;
895
897 int seekMat(const int matNum) const;
898
900 int calcNumMats(void) const;
901
903
908 inline int getNumPlanes(void) const
909 {
910 switch (m_dims)
911 {
912 case 0:
913 return 0;
914 case 1:
915 case 2:
916 return 1;
917 case 3:
918 return m_size[0];
919 case 4:
920 return m_size[0] * m_size[1];
921 default:
922 {
923 int numMat = 1;
924 for (int n = 0; n < m_dims - 2; n++)
925 {
926 numMat *= m_size[n];
927 }
928 return numMat;
929 }
930 }
931 }
932
934 cv::Mat* getCvPlaneMat(const int planeIndex);
935
937 const cv::Mat* getCvPlaneMat(const int planeIndex) const;
938
940 const cv::Mat getContinuousCvPlaneMat(const int planeIndex) const;
941
943
952 inline cv::Mat** get_mdata(void)
953 {
954 return (cv::Mat**)m_data;
955 }
956
958
967 inline const cv::Mat** get_mdata(void) const
968 {
969 return (const cv::Mat**)m_data;
970 }
971
973
976 inline MSize getSize(void) { return m_size; }
977
979
982 inline const MSize getSize(void) const { return m_size; }
983
985
989 inline int getSize(int index) const
990 {
991 if(index < 0 || index >= m_dims)
992 {
993 return -1;
994 }
995 else
996 {
997 return m_size[index];
998 }
999 }
1000
1002
1005 inline MSize getOriginalSize(void) { return m_osize; }
1006
1008
1011 inline const MSize getOriginalSize(void) const { return m_osize; }
1012
1014
1018 inline int getOriginalSize(int index) const
1019 {
1020 if(index < 0 || index >= m_dims)
1021 {
1022 return -1;
1023 }
1024 else
1025 {
1026 return m_osize[index];
1027 }
1028 }
1029
1031
1038 int getStep(int index) const;
1039
1040
1042
1046 inline int getTotal() const
1047 {
1048 int dims = getDims();
1049 int total = dims > 0 ? 1 : 0;
1050 for(int i = 0 ; i < dims ; i++)
1051 {
1052 total *= m_size[i];
1053 }
1054 return total;
1055
1056 }
1057
1059
1063 inline int getOriginalTotal() const
1064 {
1065 int dims = getDims();
1066 int total = dims > 0 ? 1 : 0;
1067 for(int i = 0 ; i<dims ; i++)
1068 {
1069 total *= m_osize[i];
1070 }
1071 return total;
1072 }
1073
1074 RetVal copyTo(DataObject &rhs, unsigned char regionOnly = 0) const;
1075 RetVal convertTo(DataObject &rhs, const int type, const double alpha=1, const double beta=0 ) const;
1077 RetVal setTo(const int8 &value, const DataObject &mask = DataObject());
1078 RetVal setTo(const uint8 &value, const DataObject &mask = DataObject());
1079 RetVal setTo(const int16 &value, const DataObject &mask = DataObject());
1080 RetVal setTo(const uint16 &value, const DataObject &mask = DataObject());
1081 RetVal setTo(const int32 &value, const DataObject &mask = DataObject());
1082 RetVal setTo(const uint32 &value, const DataObject &mask = DataObject());
1083 RetVal setTo(const float32 &value, const DataObject &mask = DataObject());
1084 RetVal setTo(const float64 &value, const DataObject &mask = DataObject());
1085 RetVal setTo(const complex64 &value, const DataObject &mask = DataObject());
1086 RetVal setTo(const complex128 &value, const DataObject &mask = DataObject());
1087 RetVal setTo(const ito::Rgba32 &value, const DataObject &mask = DataObject());
1088 RetVal setTo(const ito::DateTime &value, const DataObject &mask = DataObject());
1089 RetVal setTo(const ito::TimeDelta &value, const DataObject &mask = DataObject());
1092 RetVal deepCopyPartial(DataObject &copyTo);
1093
1095 DObjIterator begin();
1097 DObjIterator end();
1098
1100 DObjConstIterator constBegin() const;
1101
1103 DObjConstIterator constEnd() const;
1104
1106 DataObject & operator = (const cv::Mat &rhs);
1107 DataObject & operator = (const DataObject &rhs);
1108 DataObject & operator = (const int8 &value);
1109 DataObject & operator = (const uint8 &value);
1110 DataObject & operator = (const int16 &value);
1111 DataObject & operator = (const uint16 &value);
1112 DataObject & operator = (const int32 &value);
1113 DataObject & operator = (const uint32 &value);
1114 DataObject & operator = (const float32 &value);
1115 DataObject & operator = (const float64 &value);
1116 DataObject & operator = (const complex64 &value);
1117 DataObject & operator = (const complex128 &value);
1118 DataObject & operator = (const ito::Rgba32 &value);
1119 DataObject & operator = (const ito::DateTime &value);
1120 DataObject & operator = (const ito::TimeDelta &value);
1123 DataObject & operator += (const DataObject &rhs);
1124 DataObject & operator += (const float64 &value);
1125 DataObject & operator += (const complex128 &value);
1126 DataObject & operator += (const TimeDelta &value);
1127
1128 DataObject operator + (const DataObject &rhs);
1129 DataObject operator + (const float64 &value);
1130 DataObject operator + (const complex128 &value);
1131 DataObject operator + (const TimeDelta &value);
1132
1133 DataObject & operator -= (const DataObject &rhs);
1134 DataObject & operator -= (const float64 &value);
1135 DataObject & operator -= (const complex128 &value);
1136 DataObject & operator -= (const TimeDelta &value);
1137
1138 DataObject operator - (const DataObject &rhs);
1139 DataObject operator - (const float64 &value);
1140 DataObject operator - (const complex128 &value);
1141 DataObject operator - (const TimeDelta &value);
1142
1143 DataObject & operator *= (const DataObject &rhs);
1144 DataObject & operator *= (const float64 &factor);
1145 DataObject & operator *= (const complex128 &factor);
1146
1147 DataObject operator * (const DataObject &rhs);
1148 DataObject operator * (const float64 &factor);
1149 DataObject operator * (const complex128 &factor);
1150
1151 // Comparison Operators
1152 DataObject operator < (DataObject &rhs);
1153 DataObject operator > (DataObject &rhs);
1154 DataObject operator <= (DataObject &rhs);
1155 DataObject operator >= (DataObject &rhs);
1156 DataObject operator == (DataObject &rhs);
1157 DataObject operator != (DataObject &rhs);
1158
1159 DataObject operator < (const float64 &value);
1160 DataObject operator > (const float64 &value);
1161 DataObject operator <= (const float64 &value);
1162 DataObject operator >= (const float64 &value);
1163 DataObject operator == (const float64 &value);
1164 DataObject operator != (const float64 &value);
1165
1166 DataObject operator == (const ito::complex64 &value);
1167 DataObject operator != (const ito::complex64 &value);
1168
1169 DataObject operator == (const ito::complex128 &value);
1170 DataObject operator != (const ito::complex128 &value);
1171
1172 DataObject operator == (const ito::Rgba32 &value);
1173 DataObject operator != (const ito::Rgba32 &value);
1174
1175 DataObject operator < (const ito::DateTime &value);
1176 DataObject operator > (const ito::DateTime &value);
1177 DataObject operator <= (const ito::DateTime &value);
1178 DataObject operator >= (const ito::DateTime &value);
1179 DataObject operator == (const ito::DateTime &value);
1180 DataObject operator != (const ito::DateTime &value);
1181
1182 DataObject operator < (const ito::TimeDelta &value);
1183 DataObject operator > (const ito::TimeDelta &value);
1184 DataObject operator <= (const ito::TimeDelta &value);
1185 DataObject operator >= (const ito::TimeDelta &value);
1186 DataObject operator == (const ito::TimeDelta &value);
1187 DataObject operator != (const ito::TimeDelta &value);
1188
1189 // bitshift operators
1190 DataObject operator << (const unsigned int shiftbit);
1191 DataObject & operator <<= (const unsigned int shiftbit);
1192 DataObject operator >> (const unsigned int shiftbit);
1193 DataObject & operator >>= (const unsigned int shiftbit);
1194
1195 // bitwise operators
1196 DataObject operator & (const DataObject & rhs);
1197 DataObject & operator &= (const DataObject & rhs);
1198 DataObject operator | (const DataObject & rhs);
1199 DataObject & operator |= (const DataObject & rhs);
1200 DataObject operator ^ (const DataObject & rhs);
1201 DataObject & operator ^= (const DataObject & rhs);
1202 DataObject bitwise_not() const;
1204 // allocates matrix with zero values
1205 RetVal zeros(const int type);
1206 RetVal zeros(const int size, const int type);
1207 RetVal zeros(const int sizeY, const int sizeX, const int type);
1208 RetVal zeros(const int sizeZ, const int sizeY, const int sizeX, const int type, const unsigned char continuous = 0);
1209 RetVal zeros(const unsigned char dimensions, const int *sizes, const int type, const unsigned char continuous = 0);
1210
1211 // allocates matrix with all values set to one
1212 RetVal ones(const int type);
1213 RetVal ones(const int size, const int type);
1214 RetVal ones(const int sizeY, const int sizeX, const int type);
1215 RetVal ones(const int sizeZ, const int sizeY, const int sizeX, const int type, const unsigned char continuous = 0);
1216 RetVal ones(const unsigned char dimensions, const int *sizes, const int type, const unsigned char continuous = 0);
1217
1218 // allocates matrix with all values set to one
1219 RetVal nans(const int type);
1220 RetVal nans(const int size, const int type);
1221 RetVal nans(const int sizeY, const int sizeX, const int type);
1222 RetVal nans(const int sizeZ, const int sizeY, const int sizeX, const int type, const unsigned char continuous = 0);
1223 RetVal nans(const unsigned char dimensions, const int *sizes, const int type, const unsigned char continuous = 0);
1224
1225 // allocates matrix with uniform distributed noise
1226 RetVal rand(const int type, const bool randMode = false);
1227 RetVal rand(const int size, const int type, const bool randMode = false);
1228 RetVal rand(const int sizeY, const int sizeX, const int type, const bool randMode = false);
1229 RetVal rand(const int sizeZ, const int sizeY, const int sizeX, const int type, const bool randMode, const unsigned char continuous = 0);
1230 RetVal rand(const unsigned char dimensions, const int *sizes, const int type, const bool randMode, const unsigned char continuous = 0);
1231
1232 // allocates matrix with eye-matrix representation
1233 RetVal eye(const int type);
1234 RetVal eye(const int size, const int type);
1235
1236 RetVal conj();
1237 DataObject adj() const;
1238 DataObject trans() const;
1239
1240 // element-wise multiplication
1241 DataObject mul(const DataObject &mat2, const double scale = 1.0) const;
1242 DataObject div(const DataObject &mat2, const double scale = 1.0) const;
1243
1244
1245
1246 // power (power of 0.5 is the square root)
1247 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)
1248 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.
1249
1250 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)
1251 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)
1252
1253 DataObject squeeze() const;
1254 DataObject reshape(int newDims, const int *newSizes) const;
1255
1256 int elemSize() const;
1259
1264 template<typename _Tp> inline const _Tp& at(const unsigned int y, const unsigned int x) const
1265 {
1266#if __ITODEBUG
1267 if (m_dims != 2)
1268 {
1269 cv::error(cv::Exception(CV_StsAssert, "Dimension mismatch while addressing data field", "", __FILE__, __LINE__));
1270 }
1271 else if (((int)x >= m_size[1]) || ((int)y >= m_size[0]) )
1272 {
1273 cv::error(cv::Exception(CV_StsAssert, "Index out of bounds", "", __FILE__ , __LINE__));
1274 }
1275#endif
1276 return (*reinterpret_cast<const cv::Mat_<_Tp>*>(m_data[0]))(y, x);
1277 }
1278
1280
1285 template<typename _Tp> inline _Tp& at(const unsigned int y, const unsigned int x)
1286 {
1287#if __ITODEBUG
1288 if (m_dims != 2)
1289 {
1290 cv::error(cv::Exception(CV_StsAssert, "Dimension mismatch while addressing data field", "", __FILE__, __LINE__));
1291 }
1292 else if (((int)x >= m_size[1]) || ((int)y >= m_size[0]) )
1293 {
1294 cv::error(cv::Exception(CV_StsAssert, "Index out of bounds", "", __FILE__ , __LINE__));
1295 }
1296#endif
1297 return (*reinterpret_cast<cv::Mat_<_Tp>*>(m_data[0]))(y, x);
1298 }
1299
1301
1307 template<typename _Tp> inline const _Tp& at(const unsigned int z, const unsigned int y, const unsigned int x) const
1308 {
1309#if __ITODEBUG
1310 if (m_dims != 3)
1311 {
1312 cv::error(cv::Exception(CV_StsAssert, "Dimension mismatch while addressing data field", "", __FILE__, __LINE__));
1313 }
1314 else if (((int)x >= m_size[2]) || ((int)y >= m_size[1]) || (((int)z + m_roi[0]) >= (m_roi[0] + m_size[0])))
1315 {
1316 cv::error(cv::Exception(CV_StsAssert, "Index out of bounds", "", __FILE__ , __LINE__));
1317 }
1318#endif
1319 return (*reinterpret_cast<const cv::Mat_<_Tp>*>(m_data[z + m_roi[0]]))(y, x);
1320 }
1321
1323
1329 template<typename _Tp> inline _Tp& at(const unsigned int z, const unsigned int y, const unsigned int x)
1330 {
1331#if __ITODEBUG
1332 if (m_dims != 3)
1333 {
1334 cv::error(cv::Exception(CV_StsAssert, "Dimension mismatch while addressing data field", "", __FILE__, __LINE__));
1335 }
1336 else if (((int)x >= m_size[2]) || ((int)y >= m_size[1]) || (((int)z + m_roi[0]) >= (m_roi[0] + m_size[0])))
1337 {
1338 cv::error(cv::Exception(CV_StsAssert, "Index out of bounds", "", __FILE__ , __LINE__));
1339 }
1340#endif
1341 return (*reinterpret_cast<cv::Mat_<_Tp>*>(m_data[z + m_roi[0]]))(y, x);
1342 }
1343
1345
1350 template<typename _Tp> inline const _Tp& at(const unsigned int *idx) const //idx is in virtual order
1351 {
1352 int matNum = 0;
1353 matIdxToNum(idx, &matNum);
1354 return (*reinterpret_cast<const cv::Mat_<_Tp>*>(m_data[matNum]))(idx[m_dims - 2], idx[m_dims - 1]);
1355 }
1356
1358
1363 template<typename _Tp> inline _Tp& at(const unsigned int *idx) //idx is in virtual order
1364 {
1365 int matNum = 0;
1366 matIdxToNum(idx, &matNum);
1367 return (*reinterpret_cast<cv::Mat_<_Tp>*>(m_data[matNum]))(idx[m_dims - 2], idx[m_dims - 1]);
1368 }
1369
1370 DataObject at(const ito::Range &rowRange, const ito::Range &colRange) const;
1371 DataObject at(ito::Range *ranges) const;
1372 DataObject at(const DataObject &mask) const;
1375
1381 inline uchar* rowPtr(const int matNum, const int y)
1382 {
1383 int matIndex = seekMat(matNum);
1384 return ((cv::Mat*)m_data[matIndex])->ptr(y);
1385 }
1386
1388
1394 inline const uchar* rowPtr(const int matNum, const int y) const
1395 {
1396 int matIndex = seekMat(matNum);
1397 return ((const cv::Mat*)m_data[matIndex])->ptr(y);
1398 }
1399
1401
1408 template<typename _Tp> inline _Tp* rowPtr(const int matNum, const int y)
1409 {
1410 int matIndex = seekMat(matNum);
1411 return ((cv::Mat*)m_data[matIndex])->ptr<_Tp>(y);
1412 }
1413
1415
1422 template<typename _Tp> inline const _Tp* rowPtr(const int matNum, const int y) const
1423 {
1424 int matIndex = seekMat(matNum);
1425 return ((const cv::Mat*)m_data[matIndex])->ptr<_Tp>(y);
1426 }
1427
1428 DataObject row(const int selRow) const;
1429 DataObject col(const int selCol) const;
1430
1431 DataObject toGray(const int destinationType = ito::tUInt8) const;
1432 DataObject splitColor(const char* destinationColor, const int& dtype) const;
1433 DataObject lineCut(const double* coordinates, const int& len) const;
1434
1435 // ROI
1436 DataObject & adjustROI(const int dtop, const int dbottom, const int dleft, const int dright);
1437 DataObject & adjustROI(const unsigned char dims, const int *lims);
1438 RetVal locateROI(int *wholeSizes, int *offsets) const;
1439 RetVal locateROI(int *lims) const;
1442
1457 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
1458
1460
1484 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
1485
1486 template<typename T2> operator T2 ();
1488 template<typename _Tp> RetVal linspace(const _Tp start, const _Tp end, const _Tp inc, const int transposed);
1489
1491
1495 static DataObject stack(const DataObject *mats, int num, unsigned int axis = 0);
1496
1497 };
1498
1499 //template<> DATAOBJ_EXPORT RetVal ito::DataObject::linspace<ito::int8>(const ito::int8 /*start*/, const ito::int8 /*end*/, const ito::int8 /*inc*/, const int /*transposed*/);
1500 //template<> DATAOBJ_EXPORT RetVal ito::DataObject::linspace<ito::uint8>(const ito::uint8 /*start*/, const ito::uint8 /*end*/, const ito::uint8 /*inc*/, const int /*transposed*/);
1501
1502
1503 //----------------------------------------------------------------------------------------------------------------------------------
1504 // functions for DataObject in namespace ITO, which are NOT member functions
1505 //----------------------------------------------------------------------------------------------------------------------------------
1506 DATAOBJ_EXPORT DataObject abs(const DataObject &dObj);
1507 DATAOBJ_EXPORT DataObject arg(const DataObject &dObj);
1508 DATAOBJ_EXPORT DataObject real(const DataObject &dObj);
1509 DATAOBJ_EXPORT DataObject imag(const DataObject &dObj);
1511 DATAOBJ_EXPORT DataObject makeContinuous(const DataObject &dObj);
1514
1521 template<typename _Tp> inline _Tp numberConversion(ito::tDataType fromType, const void *scalar)
1522 {
1523 _Tp retValue;
1524
1525 switch(fromType)
1526 {
1527 case ito::tUInt8:
1528 retValue = cv::saturate_cast<_Tp>(*(static_cast<const uint8*>(scalar)));
1529 break;
1530 case ito::tInt8:
1531 retValue = cv::saturate_cast<_Tp>(*(static_cast<const int8*>(scalar)));
1532 break;
1533 case ito::tUInt16:
1534 retValue = cv::saturate_cast<_Tp>(*(static_cast<const uint16*>(scalar)));
1535 break;
1536 case ito::tInt16:
1537 retValue = cv::saturate_cast<_Tp>(*(static_cast<const int16*>(scalar)));
1538 break;
1539 case ito::tUInt32:
1540 retValue = cv::saturate_cast<_Tp>(*(static_cast<const uint32*>(scalar)));
1541 break;
1542 case ito::tInt32:
1543 retValue = cv::saturate_cast<_Tp>(*(static_cast<const int32*>(scalar)));
1544 break;
1545 case ito::tFloat32:
1546 retValue = cv::saturate_cast<_Tp>(*(static_cast<const ito::float32*>(scalar)));
1547 break;
1548 case ito::tFloat64:
1549 retValue = cv::saturate_cast<_Tp>(*(static_cast<const ito::float64*>(scalar)));
1550 break;
1551 case ito::tComplex64:
1552 retValue = cv::saturate_cast<_Tp>(*(static_cast<const ito::complex64*>(scalar)));
1553 break;
1554 case ito::tComplex128:
1555 retValue = cv::saturate_cast<_Tp>(*(static_cast<const ito::complex128*>(scalar)));
1556 break;
1557 case ito::tRGBA32:
1558 retValue = cv::saturate_cast<_Tp>(*(static_cast<const ito::Rgba32*>(scalar)));
1559 break;
1560 case ito::tDateTime:
1561 retValue = cv::saturate_cast<_Tp>(*(static_cast<const ito::DateTime*>(scalar)));
1562 break;
1563 case ito::tTimeDelta:
1564 retValue = cv::saturate_cast<_Tp>(*(static_cast<const ito::TimeDelta*>(scalar)));
1565 break;
1566 default:
1567 cv::error(cv::Exception(CV_StsAssert, "Input value type unknown", "", __FILE__, __LINE__));
1568 retValue = 0;
1569 }
1570
1571 return retValue;
1572 };
1573
1575 DATAOBJ_EXPORT std::ostream& operator << (std::ostream& out, const DataObject& dObj);
1576
1578
1586 {
1587 switch(cmplxType)
1588 {
1589 case ito::tInt8:
1590 case ito::tUInt8:
1591 case ito::tInt16:
1592 case ito::tUInt16:
1593 case ito::tInt32:
1594 case ito::tUInt32:
1595 case ito::tFloat32:
1596 case ito::tFloat64:
1597 case ito::tRGBA32:
1598 case ito::tDateTime:
1599 case ito::tTimeDelta:
1600 return cmplxType;
1601 case ito::tComplex64:
1602 return ito::tFloat32;
1603 case ito::tComplex128:
1604 return ito::tFloat64;
1605 }
1606
1607 cv::error(cv::Exception(CV_StsAssert, "Input data type unknown", "", __FILE__, __LINE__));
1608 return ito::tInt8;
1609 }
1610
1612
1619 inline ito::tDataType guessDataTypeFromCVMat(const cv::Mat* mat, ito::RetVal &retval)
1620 {
1621 if (mat)
1622 {
1623 switch(mat->type())
1624 {
1625 case cv::DataType<ito::int8>::type:
1626 return ito::tInt8;
1627 case cv::DataType<ito::uint8>::type:
1628 return ito::tUInt8;
1629 case cv::DataType<ito::int16>::type:
1630 return ito::tInt16;
1631 case cv::DataType<ito::uint16>::type:
1632 return ito::tUInt16;
1633 case cv::DataType<ito::int32>::type:
1634 return ito::tInt32;
1635 case cv::DataType<ito::uint32>::type:
1636 return ito::tUInt32;
1637 case cv::DataType<ito::float32>::type:
1638 return ito::tFloat32;
1639 case cv::DataType<ito::float64>::type:
1640 return ito::tFloat64;
1641 case cv::DataType<ito::Rgba32>::type:
1642 return ito::tRGBA32;
1643 case cv::DataType<ito::complex64>::type:
1644 return ito::tComplex64;
1645 case cv::DataType<ito::complex128>::type:
1646 return ito::tComplex128;
1647 case cv::DataType<ito::DateTime>::type:
1648 return ito::tDateTime;
1649 case cv::DataType<ito::TimeDelta>::type:
1650 return ito::tTimeDelta;
1651 }
1652
1653 retval += ito::RetVal(ito::retError, 0, "type of cv::Mat is incompatible to ito::DataObject");
1654 }
1655 else
1656 {
1657 retval += ito::RetVal(ito::retError, 0, "given cv::Mat is NULL.");
1658 }
1659 return ito::tInt8;
1660 }
1661
1662
1664
1672 template<typename _Tp> inline ito::tDataType getDataType(const _Tp* /*src*/)
1673 {
1674 cv::error(cv::Exception(CV_StsAssert, "Input value type unknown", "", __FILE__, __LINE__));
1675 return ito::tInt8;
1676 }
1677
1678 template<> inline ito::tDataType getDataType(const uint8* /*src*/) { return ito::tUInt8; }
1679 template<> inline ito::tDataType getDataType(const int8* /*src*/) { return ito::tInt8; }
1680 template<> inline ito::tDataType getDataType(const uint16* /*src*/) { return ito::tUInt16; }
1681 template<> inline ito::tDataType getDataType(const int16* /*src*/) { return ito::tInt16; }
1682 template<> inline ito::tDataType getDataType(const uint32* /*src*/) { return ito::tUInt32; }
1683 template<> inline ito::tDataType getDataType(const int32* /*src*/) { return ito::tInt32; }
1684 template<> inline ito::tDataType getDataType(const float32* /*src*/) { return ito::tFloat32; }
1685 template<> inline ito::tDataType getDataType(const float64* /*src*/) { return ito::tFloat64; }
1686 template<> inline ito::tDataType getDataType(const complex64* /*src*/) { return ito::tComplex64; }
1687 template<> inline ito::tDataType getDataType(const complex128* /*src*/) { return ito::tComplex128; }
1688 template<> inline ito::tDataType getDataType(const Rgba32* /*src*/) { return ito::tRGBA32; }
1689 template<> inline ito::tDataType getDataType(const DateTime* /*src*/) { return ito::tDateTime; }
1690 template<> inline ito::tDataType getDataType(const TimeDelta* /*src*/) { return ito::tTimeDelta; }
1691
1692
1694
1703 template<typename _Tp> inline ito::tDataType getDataType2()
1704 {
1705 cv::error(cv::Exception(CV_StsAssert, "Input value type unknown", "", __FILE__, __LINE__));
1706 return ito::tInt8;
1707 }
1708
1709 template<> inline ito::tDataType getDataType2<uint8*>() { return ito::tUInt8; }
1710 template<> inline ito::tDataType getDataType2<int8*>() { return ito::tInt8; }
1711 template<> inline ito::tDataType getDataType2<uint16*>() { return ito::tUInt16; }
1712 template<> inline ito::tDataType getDataType2<int16*>() { return ito::tInt16; }
1713 template<> inline ito::tDataType getDataType2<uint32*>() { return ito::tUInt32; }
1714 template<> inline ito::tDataType getDataType2<int32*>() { return ito::tInt32; }
1715 template<> inline ito::tDataType getDataType2<float32*>() { return ito::tFloat32; }
1716 template<> inline ito::tDataType getDataType2<float64*>() { return ito::tFloat64; }
1717 template<> inline ito::tDataType getDataType2<complex64*>() { return ito::tComplex64; }
1718 template<> inline ito::tDataType getDataType2<complex128*>() { return ito::tComplex128; }
1719 template<> inline ito::tDataType getDataType2<Rgba32*>() { return ito::tRGBA32; }
1720 template<> inline ito::tDataType getDataType2<DateTime*>() { return ito::tDateTime; }
1721 template<> inline ito::tDataType getDataType2<TimeDelta*>() { return ito::tTimeDelta; }
1722
1723} //namespace ito
1724
1725#endif //__DATAOBJH
This is a Qt-free class for byte arrays (strings) without specific encoding information.
Definition byteArray.h:65
const char * data() const
return the pointer to the internal character array. If it is empty, the returned pointer still points...
Definition byteArray.h:144
constant iterator through data object
Definition dataobj.h:456
const DataObject * dObj
reference to the related data object
Definition dataobj.h:509
uchar * sliceStart
pointer to the first item within the current continuous slice
Definition dataobj.h:513
uchar * ptr
pointer to the current value of the iterator
Definition dataobj.h:512
bool planeContinuous
indicates whether dObj is continuously organized in each plane for faster seek operations
Definition dataobj.h:510
uchar * sliceEnd
pointer to the last item within the current continuous slice
Definition dataobj.h:514
int plane
plane index where the iterator is currently positioned
Definition dataobj.h:515
iterator through data object
Definition dataobj.h:528
dataObject contains a n-dimensional matrix
Definition dataobj.h:591
int * m_pRefCount
Definition dataobj.h:676
int getTotal() const
gets total number of elements within the data object's ROI
Definition dataobj.h:1046
int getDims(void) const
Definition dataobj.h:882
MROI m_roi
Definition dataobj.h:679
MSize getOriginalSize(void)
returns the original size-member. This is equal to getSize() if no roi is set to the dataObject.
Definition dataobj.h:1005
const cv::Mat ** get_mdata(void) const
returns constant array of pointers to cv::_Mat-matrices (planes) of the data object
Definition dataobj.h:967
char m_continuous
Definition dataobj.h:673
MSize m_size
Definition dataobj.h:680
_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:1408
int getSize(int index) const
gets the size of the given dimension (this is the size within the ROI)
Definition dataobj.h:989
MSize getSize(void)
returns the size-member. m_size fits to the physical organization of data in memory.
Definition dataobj.h:976
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:1422
uchar ** m_data
Definition dataobj.h:681
char m_owndata
Definition dataobj.h:674
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:1307
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:1011
MSize m_osize
Definition dataobj.h:678
int getNumPlanes(void) const
calculates numbers of single opencv matrices which are part of the ROI which has previously been set.
Definition dataobj.h:908
char getOwnData(void) const
Definition dataobj.h:891
const _Tp & at(const unsigned int *idx) const
addressing method for n-dimensional data object.
Definition dataobj.h:1350
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:982
cv::Mat ** get_mdata(void)
returns array of pointers to cv::_Mat-matrices (planes) of the data object.
Definition dataobj.h:952
_Tp & at(const unsigned int z, const unsigned int y, const unsigned int x)
addressing method for three-dimensional data object.
Definition dataobj.h:1329
int getType(void) const
Definition dataobj.h:885
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:1484
int getOriginalSize(int index) const
gets the original size of the given dimension (this is the size without considering any ROI)
Definition dataobj.h:1018
_Tp & at(const unsigned int y, const unsigned int x)
addressing method for two-dimensional data object.
Definition dataobj.h:1285
char getContinuous(void) const
Definition dataobj.h:888
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:1381
_Tp & at(const unsigned int *idx)
addressing method for n-dimensional data object.
Definition dataobj.h:1363
DataObjectTagsPrivate * m_pDataObjectTags
Definition dataobj.h:682
int m_type
Definition dataobj.h:675
int getOriginalTotal() const
gets total number of elements of the whole data object
Definition dataobj.h:1063
int m_dims
Definition dataobj.h:677
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:1394
RetVal copyFromData2D(const _Tp *src, const int sizeX, const int sizeY)
copies the externally given source data inside this data object
Definition dataobj.h:1457
const _Tp & at(const unsigned int y, const unsigned int x) const
addressing method for two-dimensional data object.
Definition dataobj.h:1264
Variant storage class for either a double or a string value.
Definition dataobj.h:352
tTagType m_type
type indicator of this class (invalid, double or string)
Definition dataobj.h:363
DataObjectTagType(const char *cVal)
Copy Constructor.
Definition dataobj.h:372
int getType(void) const
returns type of tag (
Definition dataobj.h:387
DataObjectTagType()
< Constructor
Definition dataobj.h:368
ByteArray getVal_ToString(void)
Definition dataobj.h:420
ByteArray m_strValue
if the tag type is string, the string data is stored in this ByteArray variable.
Definition dataobj.h:364
tTagType
Definition dataobj.h:355
double getVal_ToDouble(void)
Definition dataobj.h:397
double m_dVal
if the tag type is double, the real double value is stored here
Definition dataobj.h:362
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:390
Definition dataobj.cpp:59
Definition typeDefs.h:161
Definition color.h:259
each range value has a start and end point. Optionally range can be marked as Range::all(),...
Definition dataobj.h:332
int start
Definition dataobj.h:340
bool empty() const
Definition dataobj.h:337
int end
Definition dataobj.h:341
Range()
Definition dataobj.h:334
unsigned int size() const
Definition dataobj.h:336
static Range all()
Definition dataobj.h:338
Range(int _start, int _end)
Definition dataobj.h:335
Class for managing status values (like errors or warning)
Definition retVal.h:54
This class implements basic functionality for color handling in itom. \detail This class implements A...
Definition color.h:47
uint32 & argb()
Definition color.h:250
float32 gray() const
Definition color.h:235
static Rgba32 fromUnsignedLong(const uint32 val)
static constructor to create Rgba32 from uint32 containing the values argb
Definition color.h:82
Definition typeDefs.h:218
Definition apiFunctionsGraph.cpp:40
ito::tDataType getDataType2()
method which returns the value of enumeration ito::tDataType, which corresponds to the template param...
Definition dataobj.h:1703
DataObject arg(const DataObject &dObj)
Definition dataobj.cpp:12926
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:2905
RetVal GetRangeFunc(DataObject *dObj, const int dtop, const int dbottom, const int dleft, const int dright)
Definition dataobj.cpp:9093
ito::tDataType guessDataTypeFromCVMat(const cv::Mat *mat, ito::RetVal &retval)
method which guesses the dataObject type from a given cv::Mat*
Definition dataobj.h:1619
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:1879
_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:1521
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:1672
DataObject imag(const DataObject &dObj)
Definition dataobj.cpp:13456
RetVal AssignScalarFunc(DataObject *src, const ito::tDataType type, const void *scalar)
Definition dataobj.cpp:4524
RetVal FreeFunc(DataObject *dObj)
low-level, templated method for freeing allocated data blocks
Definition dataobj.cpp:828
ito::tDataType convertCmplxTypeToRealType(ito::tDataType cmplxType)
method which returns the real data type of any given data type
Definition dataobj.h:1585
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:12120
RetVal AdjustROIFunc(DataObject *dObj, int dtop, int dbottom, int dleft, int dright)
Definition dataobj.cpp:9262
RetVal MakeContinuousFunc(const DataObject &dObj, DataObject &resDObj)
Definition dataobj.cpp:13492
tDataType
Definition typeDefs.h:88
@ tTimeDelta
Definition typeDefs.h:101
@ tInt16
Definition typeDefs.h:91
@ tFloat32
Definition typeDefs.h:95
@ tInt8
Definition typeDefs.h:89
@ tComplex128
Definition typeDefs.h:98
@ tInt32
Definition typeDefs.h:93
@ tUInt16
Definition typeDefs.h:92
@ tFloat64
Definition typeDefs.h:96
@ tComplex64
Definition typeDefs.h:97
@ tRGBA32
Definition typeDefs.h:99
@ tDateTime
Definition typeDefs.h:100
@ tUInt8
Definition typeDefs.h:90
@ tUInt32
Definition typeDefs.h:94
DataObject real(const DataObject &dObj)
Definition dataobj.cpp:13020
DataObject makeContinuous(const DataObject &dObj)
Definition dataobj.cpp:13623
@ retError
Definition typeDefs.h:60
DataObject abs(const DataObject &dObj)
Definition dataobj.cpp:12796
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:2152
Definition dataobj.h:642
Definition dataobj.h:614