itom 2.0.0
|
00001 /* ******************************************************************** 00002 itom software 00003 URL: http://www.uni-stuttgart.de/ito 00004 Copyright (C) 2013, Institut für Technische Optik (ITO), 00005 Universität Stuttgart, Germany 00006 00007 This file is part of itom and its software development toolkit (SDK). 00008 00009 itom is free software; you can redistribute it and/or modify it 00010 under the terms of the GNU Library General Public Licence as published by 00011 the Free Software Foundation; either version 2 of the Licence, or (at 00012 your option) any later version. 00013 00014 In addition, as a special exception, the Institut für Technische 00015 Optik (ITO) gives you certain additional rights. 00016 These rights are described in the ITO LGPL Exception version 1.0, 00017 which can be found in the file LGPL_EXCEPTION.txt in this package. 00018 00019 itom is distributed in the hope that it will be useful, but 00020 WITHOUT ANY WARRANTY; without even the implied warranty of 00021 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library 00022 General Public Licence for more details. 00023 00024 You should have received a copy of the GNU Library General Public License 00025 along with itom. If not, see <http://www.gnu.org/licenses/>. 00026 *********************************************************************** */ 00027 00028 #ifndef __DATAOBJH 00029 #define __DATAOBJH 00030 00031 #include "defines.h" 00032 00033 #include <cstdlib> 00034 #include <iostream> 00035 #include <complex> 00036 #include <limits> 00037 #include <string> 00038 00039 #ifdef WIN32 00040 #pragma warning(disable:4996) 00041 #endif 00042 00043 #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 00044 00045 #include "opencv/cv.h" 00046 #include "opencv2/core/core.hpp" 00047 00048 #include "../common/sharedStructures.h" 00049 #include "../common/color.h" 00050 00051 00052 namespace cv 00053 { 00054 template<> inline ito::float32 saturate_cast<ito::float32>( ito::float64 v) 00055 { 00056 if(cvIsInf(v)) return std::numeric_limits<ito::float32>::infinity(); 00057 if(cvIsNaN(v)) return std::numeric_limits<ito::float32>::quiet_NaN(); 00058 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() ))); 00059 } 00060 00061 template<> inline ito::float64 saturate_cast<ito::float64>( ito::float32 v) 00062 { 00063 if(cvIsInf(v)) return std::numeric_limits<ito::float64>::infinity(); 00064 if(cvIsNaN(v)) return std::numeric_limits<ito::float64>::quiet_NaN(); 00065 return static_cast<ito::float64>(v); 00066 } 00067 00068 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; } 00069 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; } 00070 00071 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; } 00072 // 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; } 00073 00074 template<> inline ito::complex64 saturate_cast(ito::uint8 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); } 00075 template<> inline ito::complex64 saturate_cast(ito::int8 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); } 00076 template<> inline ito::complex64 saturate_cast(ito::uint16 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); } 00077 template<> inline ito::complex64 saturate_cast(ito::int16 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); } 00078 template<> inline ito::complex64 saturate_cast(ito::uint32 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); } 00079 template<> inline ito::complex64 saturate_cast(ito::int32 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); } 00080 template<> inline ito::complex64 saturate_cast(ito::float32 v){ return ito::complex64(v,0.0); } 00081 template<> inline ito::complex64 saturate_cast(ito::float64 v){ return ito::complex64(saturate_cast<ito::float32>(v),0.0); } 00082 template<> inline ito::complex64 saturate_cast(ito::complex64 v){ return v; } 00083 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())); } 00084 00085 template<> inline ito::complex128 saturate_cast(ito::uint8 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); } 00086 template<> inline ito::complex128 saturate_cast(ito::int8 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); } 00087 template<> inline ito::complex128 saturate_cast(ito::uint16 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); } 00088 template<> inline ito::complex128 saturate_cast(ito::int16 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); } 00089 template<> inline ito::complex128 saturate_cast(ito::uint32 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); } 00090 template<> inline ito::complex128 saturate_cast(ito::int32 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); } 00091 template<> inline ito::complex128 saturate_cast(ito::float32 v){ return ito::complex128(saturate_cast<ito::float64>(v),0.0); } 00092 template<> inline ito::complex128 saturate_cast(ito::float64 v){ return ito::complex128(v,0.0); } 00093 template<> inline ito::complex128 saturate_cast(ito::complex64 v){ return ito::complex128(saturate_cast<ito::float64>(v.real()),saturate_cast<ito::float64>(v.imag())); } 00094 template<> inline ito::complex128 saturate_cast(ito::complex128 v){ return v; } 00095 00096 // template<> inline ito::Rgba32 saturate_cast(ito::int8 v) {return ito::Rgba32(saturate_cast<ito::uint8>(v));} 00097 template<> inline ito::Rgba32 saturate_cast(ito::uint8 v) {return ito::Rgba32(v);} 00098 template<> inline ito::Rgba32 saturate_cast(ito::uint16 v){return ito::Rgba32(saturate_cast<ito::uint8>(v));} 00099 // template<> inline ito::Rgba32 saturate_cast(ito::int16 v){return ito::Rgba32(saturate_cast<ito::uint8>(v));} 00100 template<> inline ito::Rgba32 saturate_cast(ito::uint32 v) 00101 { 00102 return ito::Rgba32::fromUnsignedLong(v); 00103 } 00104 template<> inline ito::Rgba32 saturate_cast(ito::int32 v) 00105 { 00106 ito::Rgba32 temp; 00107 temp.rgba = static_cast<ito::uint32>(v); 00108 return temp; 00109 } 00110 template<> inline ito::Rgba32 saturate_cast(ito::float32 v){return ito::Rgba32(saturate_cast<ito::uint8>(v));} 00111 template<> inline ito::Rgba32 saturate_cast(ito::float64 v){return ito::Rgba32(saturate_cast<ito::uint8>(v));} 00112 template<> inline ito::Rgba32 saturate_cast(ito::Rgba32 v){return v;} 00113 00114 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(); } 00115 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(); } 00116 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(); } 00117 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(); } 00118 00119 template<> inline ito::uint8 saturate_cast(ito::Rgba32 v){return saturate_cast<ito::uint8>(v.gray());}; 00120 //template<> inline ito::int16 saturate_cast(ito::Rgba32 v){return saturate_cast<ito::int16>(v.gray());}; 00121 template<> inline ito::uint16 saturate_cast(ito::Rgba32 v){return saturate_cast<ito::uint16>(v.gray());}; 00122 template<> inline ito::uint32 saturate_cast(ito::Rgba32 v){return v.argb();}; 00123 template<> inline ito::int32 saturate_cast(ito::Rgba32 v){return (ito::int32)(v.argb());}; 00124 template<> inline ito::float32 saturate_cast(ito::Rgba32 v){return v.gray();}; 00125 template<> inline ito::float64 saturate_cast(ito::Rgba32 v){return (ito::float64)v.gray();}; 00126 00127 00128 template<> class DataType<ito::Rgba32> 00129 { 00130 public: 00131 typedef ito::Rgba32 value_type; 00132 typedef ito::uint8 channel_type; 00133 typedef Vec<channel_type, 4> work_type; 00134 typedef value_type vec_type; 00135 enum 00136 { 00137 generic_type = 0, 00138 depth = cv::DataDepth<channel_type>::value, 00139 channels = 4, 00140 fmt = ((channels-1)<<8) + cv::DataDepth<channel_type>::fmt, 00141 type = CV_MAKETYPE(depth, channels) 00142 }; 00143 }; 00144 00145 template<> class DataType<ito::RedChannel> 00146 { 00147 public: 00148 typedef ito::RedChannel value_type; 00149 typedef ito::uint8 channel_type; 00150 typedef Vec<channel_type, 4> work_type; 00151 typedef value_type vec_type; 00152 enum 00153 { 00154 generic_type = 0, 00155 depth = cv::DataDepth<channel_type>::value, 00156 channels = 4, 00157 fmt = ((channels-1)<<8) + cv::DataDepth<channel_type>::fmt, 00158 type = CV_MAKETYPE(depth, channels) 00159 }; 00160 }; 00161 00162 template<> class DataType<ito::GreenChannel> 00163 { 00164 public: 00165 typedef ito::GreenChannel value_type; 00166 typedef ito::uint8 channel_type; 00167 typedef Vec<channel_type, 4> work_type; 00168 typedef value_type vec_type; 00169 enum 00170 { 00171 generic_type = 0, 00172 depth = cv::DataDepth<channel_type>::value, 00173 channels = 4, 00174 fmt = ((channels-1)<<8) + cv::DataDepth<channel_type>::fmt, 00175 type = CV_MAKETYPE(depth, channels) 00176 }; 00177 }; 00178 00179 template<> class DataType<ito::BlueChannel> 00180 { 00181 public: 00182 typedef ito::BlueChannel value_type; 00183 typedef ito::uint8 channel_type; 00184 typedef Vec<channel_type, 4> work_type; 00185 typedef value_type vec_type; 00186 enum 00187 { 00188 generic_type = 0, 00189 depth = cv::DataDepth<channel_type>::value, 00190 channels = 4, 00191 fmt = ((channels-1)<<8) + cv::DataDepth<channel_type>::fmt, 00192 type = CV_MAKETYPE(depth, channels) 00193 }; 00194 }; 00195 00196 template<> class DataType<ito::AlphaChannel> 00197 { 00198 public: 00199 typedef ito::AlphaChannel value_type; 00200 typedef ito::uint8 channel_type; 00201 typedef Vec<channel_type, 4> work_type; 00202 typedef value_type vec_type; 00203 enum 00204 { 00205 generic_type = 0, 00206 depth = cv::DataDepth<channel_type>::value, 00207 channels = 4, 00208 fmt = ((channels-1)<<8) + cv::DataDepth<channel_type>::fmt, 00209 type = CV_MAKETYPE(depth, channels) 00210 }; 00211 }; 00212 00213 00214 } // namespace cv 00215 00216 namespace ito { 00217 00218 #define __ITODEBUG 1 00219 00220 //forward declarations 00221 class DObjIterator; 00222 class DataObject; 00223 class Range; 00224 class DataObjectTags; 00225 class DataObjectTagType; 00226 class DataObjectTagsPrivate; 00227 00228 00229 //---------------------------------------------------------------------------------------------------------------------------------- 00236 class DATAOBJ_EXPORT Range 00237 { 00238 public: 00239 Range() : start(0), end(0) {} 00240 Range(int _start, int _end) { _start < _end ? (end = _end, start = _start) : (start = _end, end = _start); } 00241 inline unsigned int size() const { return end - start; } 00242 inline bool empty() const { return (start == end); } 00243 static Range all() { return Range(INT_MIN, INT_MAX); } 00245 int start; 00246 int end; 00247 }; 00248 00249 //---------------------------------------------------------------------------------------------------------------------------------- 00256 class DATAOBJ_EXPORT DataObjectTagType 00257 { 00258 public: 00259 enum tTagType 00260 { 00261 typeInvalid = 0x000000, 00262 typeDouble = 0x000008, 00263 typeString = 0x000020 00264 }; 00265 00266 private: 00267 double m_dVal; 00268 tTagType m_type; 00269 ByteArray m_strValue; 00270 00271 public: 00273 DataObjectTagType() : m_dVal(0), m_strValue(""), m_type(DataObjectTagType::typeInvalid){} 00274 DataObjectTagType(double dVal) : m_dVal(dVal), m_strValue(""), m_type(DataObjectTagType::typeDouble){} 00275 DataObjectTagType(const std::string &str) : m_dVal(std::numeric_limits<double>::quiet_NaN()), m_type(DataObjectTagType::typeString){ m_strValue = str.data(); } 00276 DataObjectTagType(const ByteArray &str) : m_dVal(std::numeric_limits<double>::quiet_NaN()), m_type(DataObjectTagType::typeString){ m_strValue = str; } 00277 DataObjectTagType(const char* cVal) : m_dVal(std::numeric_limits<double>::quiet_NaN()), m_type(DataObjectTagType::typeString){ cVal == NULL ? m_strValue = "" : m_strValue = cVal;} 00279 DataObjectTagType(const DataObjectTagType& a) : m_dVal(a.m_dVal), m_type(a.m_type), m_strValue(a.m_strValue) {} 00280 00282 DataObjectTagType & operator = (const DataObjectTagType &rhs) 00283 { 00284 this->m_dVal = rhs.m_dVal; 00285 this->m_strValue = rhs.m_strValue; 00286 this->m_type = rhs.m_type; 00287 00288 return *this; 00289 } 00290 00292 inline int getType(void) const {return m_type;} 00293 00295 inline bool isValid(void) const { return (m_type == DataObjectTagType::typeInvalid) ? false: true;} 00296 00302 inline double getVal_ToDouble(void) 00303 { 00304 if(m_type == DataObjectTagType::typeInvalid) 00305 { 00306 return std::numeric_limits<double>::quiet_NaN(); 00307 } 00308 else if(m_type == DataObjectTagType::typeDouble) 00309 { 00310 return m_dVal; 00311 } 00312 else 00313 { 00314 double dVal = std::numeric_limits<double>::quiet_NaN(); 00315 //dVal = atof(m_strValue.c_str()); //sometimes the result of that line has been arbitrary, therefore this conversion should fail. 00316 return dVal; 00317 } 00318 } 00319 00325 inline ByteArray getVal_ToString(void) 00326 { 00327 if(m_type == DataObjectTagType::typeInvalid) 00328 { 00329 return ""; 00330 } 00331 else if(m_type == DataObjectTagType::typeString) 00332 { 00333 return m_strValue; 00334 } 00335 else 00336 { 00337 if (cvIsNaN(m_dVal)) return "NaN"; 00338 if (cvIsInf(m_dVal)) return "Inf"; 00339 00340 std::ostringstream strs; 00341 strs << m_dVal; 00342 ByteArray ba(strs.str().data()); 00343 00344 return ba; 00345 } 00346 } 00347 }; 00348 00349 //---------------------------------------------------------------------------------------------------------------------------------- 00360 class DATAOBJ_EXPORT DObjConstIterator 00361 { 00362 public: 00363 00365 DObjConstIterator(); 00366 00368 DObjConstIterator(const DataObject* _dObj, int pos = 0); 00369 00371 DObjConstIterator(const DObjConstIterator& it); 00372 00374 DObjConstIterator& operator = (const DObjConstIterator& it); 00375 00377 const uchar* operator *() const; 00378 00380 const uchar* operator [](int i) const; 00381 00383 DObjConstIterator& operator += (int ofs); 00384 00386 DObjConstIterator& operator -= (int ofs); 00387 00389 DObjConstIterator& operator --(); 00390 00392 DObjConstIterator operator --(int); 00393 00395 DObjConstIterator& operator ++(); 00396 00398 DObjConstIterator operator ++(int); 00399 00400 bool operator == (const DObjConstIterator& dObjIt); 00401 bool operator != (const DObjConstIterator& dObjIt); 00402 bool operator < (const DObjConstIterator& dObjIt); 00403 bool operator > (const DObjConstIterator& dObjIt); 00404 bool operator <= (const DObjConstIterator& dObjIt); 00405 bool operator >= (const DObjConstIterator& dObjIt); 00406 00407 protected: 00409 void seekAbs(int ofs); 00410 00412 void seekRel(int ofs); 00413 00414 const DataObject* dObj; 00415 bool planeContinuous; 00416 int elemSize; 00417 uchar* ptr; 00418 uchar* sliceStart; 00419 uchar* sliceEnd; 00420 int plane; 00421 }; 00422 00423 //---------------------------------------------------------------------------------------------------------------------------------- 00432 class DATAOBJ_EXPORT DObjIterator : public DObjConstIterator 00433 { 00434 public: 00435 00437 DObjIterator(); 00438 00440 DObjIterator(DataObject* _dObj, int pos = 0); 00441 00443 DObjIterator(const DObjIterator& it); 00444 00446 DObjIterator& operator = (const DObjIterator& it); 00447 00449 uchar* operator *(); 00450 00452 uchar* operator [](int i); 00453 00455 DObjIterator& operator += (int ofs); 00456 00458 DObjIterator& operator -= (int ofs); 00459 00461 DObjIterator& operator --(); 00462 00464 DObjIterator operator --(int); 00465 00467 DObjIterator& operator ++(); 00468 00470 DObjIterator operator ++(int); 00471 }; 00472 00473 //---------------------------------------------------------------------------------------------------------------------------------- 00474 00475 // Forward declaration of friend methods 00476 #ifdef __APPLE__ 00477 template<typename _Tp> RetVal CreateFunc(DataObject *dObj, const unsigned char dimensions, const int *sizes, const unsigned char continuous, const uchar* continuousDataPtr, const int* steps); 00478 template<typename _Tp> RetVal CreateFuncWithCVPlanes(DataObject *dObj, const unsigned char dimensions, const int *sizes, const cv::Mat* planes, const unsigned int nrOfPlanes); 00479 template<typename _Tp> RetVal FreeFunc(DataObject *dObj); 00480 template<typename _Tp> RetVal SecureFreeFunc(DataObject *dObj); 00481 template<typename _Tp> RetVal CopyToFunc(const DataObject &lhs, DataObject &rhs, unsigned char regionOnly); 00482 template<typename _Tp> RetVal ConvertToFunc(const DataObject &lhs, DataObject &rhs, const int type, const double alpha, const double beta); 00483 template<typename _Tp> RetVal AdjustROIFunc(DataObject *dObj, const int *lims); 00484 template<typename _Tp> RetVal MinMaxLocFunc(const DataObject &dObj, double *minVal, double *maxVal, int *minPos, int *maxPos); 00485 template<typename _Tp> RetVal AssignScalarFunc(const DataObject *src, const ito::tDataType type, const void *scalar); 00486 template<typename _Tp> RetVal MakeContinuousFunc(const DataObject &dObj, DataObject &resDObj); 00487 template<typename _Tp> RetVal EvaluateTransposeFlagFunc(DataObject *dObj); 00488 //template<typename _Tp> RetVal CalcMinMaxValues(DataObject *lhs, double &result_min, double &result_max, const int cmplxSel); 00489 template<typename _Tp> std::ostream& coutFunc(std::ostream& out, const DataObject& dObj); 00490 00491 // more friends due to change of std::vector to int ** for m_data ... 00492 template<typename _Tp> RetVal GetRangeFunc(DataObject *dObj, const int dtop, const int dbottom, const int dleft, const int dright); 00493 template<typename _Tp> RetVal AdjustROIFunc(DataObject *dObj, int dtop, int dbottom, int dleft, int dright); 00494 #endif // __APPLE__ 00495 00496 class DATAOBJ_EXPORT DataObject 00497 { 00498 private: 00500 void createHeader(const unsigned char dimensions, const int *sizes, const int *steps, const int elemSize); 00501 00503 void createHeaderWithROI(const unsigned char dimensions, const int *sizes, const int *osizes = NULL, const int *roi = NULL); 00504 00505 void create(const unsigned char dimensions, const int *sizes, const int type, const unsigned char continuous, const uchar* continuousDataPtr = NULL, const int* steps = NULL); 00506 void create(const unsigned char dimensions, const int *sizes, const int type, const cv::Mat* planes, const unsigned int nrOfPlanes); 00507 00508 void freeData(void); 00509 void secureFreeData(void); 00512 //---------------------------------------------------------------------------------------------------------------------------------- 00513 ito::RetVal matNumToIdx(const int matNum, int *matIdx) const; 00514 00516 ito::RetVal matIdxToNum(const unsigned int *matIdx, int *matNum) const; 00517 00518 00519 struct DATAOBJ_EXPORT MSize 00520 { 00521 inline MSize() : m_p(NULL) {} 00522 inline int operator [] (const int dim) const 00523 { 00524 return m_p[dim]; //return the size value. this operator corresponds to the real data representation in memory 00525 }; 00526 inline operator const int * () const { return m_p; } 00527 inline bool operator == (const MSize& sz) const 00528 { 00529 if(m_p == NULL || sz.m_p == NULL) 00530 { 00531 return sz.m_p == m_p; 00532 } 00533 00534 int d = m_p[-1], dsz = sz.m_p[-1]; 00535 if( d != dsz ) 00536 return false; 00537 if( d == 2 ) 00538 { 00539 return m_p[0] == sz.m_p[0] && m_p[1] == sz.m_p[1]; 00540 } 00541 00542 for( int i = 0; i < d - 2; i++ ) 00543 { 00544 if( m_p[i] != sz.m_p[i] ) 00545 { 00546 return false; 00547 } 00548 } 00549 return (m_p[d - 2] == sz.m_p[d - 2]) && (m_p[d - 1] == sz.m_p[d - 1]); 00550 } 00551 00552 inline bool operator != (const MSize& sz) const { return !(*this == sz); } 00553 00554 int *m_p; 00555 }; 00556 00557 00558 struct DATAOBJ_EXPORT MROI 00559 { 00560 inline MROI() : m_p(NULL) {}; 00561 inline int operator [] (const int dim) const 00562 { 00563 return m_p[dim]; //return the size value. this operator corresponds to the real data representation in memory 00564 } 00565 00566 inline bool operator == (const MROI & rroi) const 00567 { 00568 if(m_p == NULL || rroi.m_p == NULL) 00569 { 00570 return rroi.m_p == m_p; 00571 } 00572 00573 if (m_p[-1] != rroi.m_p[-1]) 00574 { 00575 return false; 00576 } 00577 00578 int d = m_p[-1]; 00579 for (int n = 0; n < d - 2; n++) 00580 { 00581 if (m_p[n] != rroi.m_p[n]) 00582 { 00583 return false; 00584 } 00585 } 00586 00587 return m_p[d - 2] == rroi.m_p[d - 2] && m_p[d - 1] == rroi.m_p[d - 1]; 00588 } 00589 00590 int *m_p; 00591 }; 00592 00593 DataObject(const DataObject& dObj, bool transposed); 00595 char m_continuous; 00596 char m_owndata; 00597 int m_type; 00598 int *m_pRefCount; 00599 int m_dims; 00600 MSize m_osize; 00601 MROI m_roi; 00602 MSize m_size; 00603 uchar **m_data; 00604 DataObjectTagsPrivate *m_pDataObjectTags; 00605 static const int m_sizeofs; 00606 00607 int mdata_realloc(const int size); 00608 int mdata_size(void) const; 00609 int mdata_free(); 00610 00611 RetVal copyFromData2DInternal(const uchar* src, const int sizeOfElem, const int sizeX, const int sizeY); 00612 RetVal copyFromData2DInternal(const uchar* src, const int sizeOfElem, const int sizeX, const int x0, const int y0, const int width, const int height); 00613 00615 //template<typename _Tp> RetVal CalcMinMaxValues(DataObject *lhs, double &result_min, double &result_max, const int cmplxSel = 0); 00616 00617 //low-level, templated methods 00618 //most low-level methods are marked "friend" such that they can access private members of their data object parameters 00619 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); 00620 template<typename _Tp> friend RetVal CreateFuncWithCVPlanes(DataObject *dObj, const unsigned char dimensions, const int *sizes, const cv::Mat* planes, const unsigned int nrOfPlanes); 00621 template<typename _Tp> friend RetVal FreeFunc(DataObject *dObj); 00622 template<typename _Tp> friend RetVal SecureFreeFunc(DataObject *dObj); 00623 template<typename _Tp> friend RetVal CopyToFunc(const DataObject &lhs, DataObject &rhs, unsigned char regionOnly); 00624 template<typename _Tp> friend RetVal ConvertToFunc(const DataObject &lhs, DataObject &rhs, const int type, const double alpha, const double beta); 00625 template<typename _Tp> friend RetVal AdjustROIFunc(DataObject *dObj, const int *lims); 00626 template<typename _Tp> friend RetVal MinMaxLocFunc(const DataObject &dObj, double *minVal, double *maxVal, int *minPos, int *maxPos); 00627 template<typename _Tp> friend RetVal AssignScalarFunc(const DataObject *src, const ito::tDataType type, const void *scalar); 00628 template<typename _Tp> friend RetVal MakeContinuousFunc(const DataObject &dObj, DataObject &resDObj); 00629 template<typename _Tp> friend RetVal EvaluateTransposeFlagFunc(DataObject *dObj); 00630 //template<typename _Tp> friend RetVal CalcMinMaxValues(DataObject *lhs, double &result_min, double &result_max, const int cmplxSel); //!< \deprecated Will be deleted once the interface number is incremented due to further changes 00631 template<typename _Tp> friend std::ostream& coutFunc(std::ostream& out, const DataObject& dObj); 00632 00633 // more friends due to change of std::vector to int ** for m_data ... 00634 template<typename _Tp> friend RetVal GetRangeFunc(DataObject *dObj, const int dtop, const int dbottom, const int dleft, const int dright); 00635 template<typename _Tp> friend RetVal AdjustROIFunc(DataObject *dObj, int dtop, int dbottom, int dleft, int dright); 00636 00637 public: 00639 DataObject(void); 00640 00642 DataObject(const int size, const int type); 00643 00645 DataObject(const int sizeY, const int sizeX, const int type); 00646 00648 DataObject(const int sizeZ, const int sizeY, const int sizeX, const int type, const unsigned char continuous = 0); 00649 00651 DataObject(const int sizeZ, const int sizeY, const int sizeX, const int type, const uchar* continuousDataPtr, const int* steps = NULL); 00652 00654 DataObject(const MSize &sizes, const int type, const unsigned char continuous = 0); 00655 00657 DataObject(const unsigned char dimensions, const int *sizes, const int type, const unsigned char continuous = 0); 00658 00660 DataObject(const unsigned char dimensions, const int *sizes, const int type, const uchar* continuousDataPtr, const int* steps = NULL); 00661 00662 DataObject(const unsigned char dimensions, const int *sizes, const int type, const cv::Mat* planes, const unsigned int nrOfPlanes); 00663 00664 DataObject(const DataObject& copyConstr); 00666 00667 ~DataObject(void); 00668 00669 // TAGSPACEFUNCTIONS 00670 00672 double getValueOffset() const; 00673 00675 double getValueScale() const; 00676 00678 const std::string getValueUnit() const; 00679 00681 std::string getValueDescription() const; 00682 00684 double getAxisOffset(const int axisNum) const; 00685 00687 double getAxisScale(const int axisNum) const; 00688 00690 const std::string getAxisUnit(const int axisNum, bool &validOperation) const; 00691 00693 std::string getAxisDescription(const int axisNum, bool &validOperation) const; 00694 00695 DataObjectTagType getTag(const std::string &key, bool &validOperation) const; 00696 00697 bool getTagByIndex(const int tagNumber, std::string &key, DataObjectTagType &value) const; 00698 00700 std::string getTagKey(const int tagNumber, bool &validOperation) const; 00701 00703 int getTagListSize() const; 00704 00706 int setValueUnit(const std::string &unit); 00707 00709 int setValueDescription(const std::string &description); 00710 00711 int setAxisOffset(const unsigned int axisNum, const double offset); 00712 int setAxisScale(const unsigned int axisNum, const double scale); 00713 int setAxisUnit(const unsigned int axisNum, const std::string &unit); //unit must be latin1 encoded 00714 int setAxisDescription(const unsigned int axisNum, const std::string &description); //description must be latin1 encoded 00715 int setTag(const std::string &key, const DataObjectTagType &value); 00716 bool existTag(const std::string &key) const; 00717 bool deleteTag(const std::string &key); 00718 bool deleteAllTags(); 00719 int addToProtocol(const std::string &value); 00720 00721 00725 double getPhysToPix(const unsigned int dim, const double phys, bool &isInsideImage) const; 00726 00730 double getPhysToPix(const unsigned int dim, const double phys) const; 00731 00735 int getPhysToPix2D(const double physY, double &tPxY, bool &isInsideImageY, const double physX, double &tPxX, bool &isInsideImageX) const; 00736 00740 double getPixToPhys(const unsigned int dim, const double pix, bool &isInsideImage) const; 00741 00745 double getPixToPhys(const unsigned int dim, const double pix) const; 00746 00760 RetVal setXYRotationalMatrix(double r11, double r12, double r13, double r21, double r22, double r23, double r31, double r32, double r33); 00761 00775 RetVal getXYRotationalMatrix(double &r11, double &r12, double &r13, double &r21, double &r22, double &r23, double &r31, double &r32, double &r33) const; 00776 00777 RetVal copyTagMapTo(DataObject &rhs) const; 00778 RetVal copyAxisTagsTo(DataObject &rhs) const; 00780 // END TAGSPACE 00781 00783 inline int getDims(void) const { return m_dims; } 00784 00786 inline int getType(void) const { return m_type; } 00787 00789 inline char getContinuous(void) const { return m_continuous; } 00790 00792 inline char getOwnData(void) const { return m_owndata; } 00793 00795 int seekMat(const int matNum, const int numMats) const; 00796 00798 int seekMat(const int matNum) const; 00799 00801 int calcNumMats(void) const; 00802 00804 00809 inline int getNumPlanes(void) const 00810 { 00811 switch (m_dims) 00812 { 00813 case 0: 00814 return 0; 00815 case 1: 00816 case 2: 00817 return 1; 00818 case 3: 00819 return m_size[0]; 00820 default: 00821 { 00822 int numMat = 1; 00823 for (int n = 0; n < m_dims - 2; n++) 00824 { 00825 numMat *= m_size[n]; 00826 } 00827 return numMat; 00828 } 00829 } 00830 } 00831 00833 cv::Mat* getCvPlaneMat(const int planeIndex); 00834 00836 const cv::Mat* getCvPlaneMat(const int planeIndex) const; 00837 00839 const cv::Mat getContinuousCvPlaneMat(const int planeIndex) const; 00840 00842 00851 inline cv::Mat** get_mdata(void) 00852 { 00853 return (cv::Mat**)m_data; 00854 } 00855 00857 00866 inline const cv::Mat** get_mdata(void) const 00867 { 00868 return (const cv::Mat**)m_data; 00869 } 00870 00872 00875 inline MSize getSize(void) { return m_size; } 00876 00878 00881 inline const MSize getSize(void) const { return m_size; } 00882 00884 00888 inline int getSize(int index) const 00889 { 00890 if(index < 0 || index >= m_dims) 00891 { 00892 return -1; 00893 } 00894 else 00895 { 00896 return m_size[index]; 00897 } 00898 } 00899 00901 00905 inline int getOriginalSize(int index) const 00906 { 00907 if(index < 0 || index >= m_dims) 00908 { 00909 return -1; 00910 } 00911 else 00912 { 00913 return m_osize[index]; 00914 } 00915 } 00916 00918 00922 inline int getTotal() const 00923 { 00924 int dims = getDims(); 00925 int total = dims > 0 ? 1 : 0; 00926 for(int i = 0 ; i < dims ; i++) 00927 { 00928 total *= m_size[i]; 00929 } 00930 return total; 00931 00932 } 00933 00935 00939 inline int getOriginalTotal() const 00940 { 00941 int dims = getDims(); 00942 int total = dims > 0 ? 1 : 0; 00943 for(int i = 0 ; i<dims ; i++) 00944 { 00945 total *= m_osize[i]; 00946 } 00947 return total; 00948 } 00949 00950 RetVal copyTo(DataObject &rhs, unsigned char regionOnly = 0) const; 00951 RetVal convertTo(DataObject &rhs, const int type, const double alpha=1, const double beta=0 ) const; 00953 RetVal setTo(const int8 &value, const DataObject &mask = DataObject()); 00954 RetVal setTo(const uint8 &value, const DataObject &mask = DataObject()); 00955 RetVal setTo(const int16 &value, const DataObject &mask = DataObject()); 00956 RetVal setTo(const uint16 &value, const DataObject &mask = DataObject()); 00957 RetVal setTo(const int32 &value, const DataObject &mask = DataObject()); 00958 RetVal setTo(const uint32 &value, const DataObject &mask = DataObject()); 00959 RetVal setTo(const float32 &value, const DataObject &mask = DataObject()); 00960 RetVal setTo(const float64 &value, const DataObject &mask = DataObject()); 00961 RetVal setTo(const complex64 &value, const DataObject &mask = DataObject()); 00962 RetVal setTo(const complex128 &value, const DataObject &mask = DataObject()); 00963 RetVal setTo(const ito::Rgba32 &value, const DataObject &mask = DataObject()); 00965 00966 RetVal deepCopyPartial(DataObject ©To); 00967 00969 DObjIterator begin(); 00971 DObjIterator end(); 00972 00974 DObjConstIterator constBegin() const; 00975 00977 DObjConstIterator constEnd() const; 00978 00980 DataObject & operator = (const cv::Mat &rhs); 00981 DataObject & operator = (const DataObject &rhs); 00982 DataObject & operator = (const int8 &value); 00983 DataObject & operator = (const uint8 &value); 00984 DataObject & operator = (const int16 &value); 00985 DataObject & operator = (const uint16 &value); 00986 DataObject & operator = (const int32 &value); 00987 DataObject & operator = (const uint32 &value); 00988 DataObject & operator = (const float32 &value); 00989 DataObject & operator = (const float64 &value); 00990 DataObject & operator = (const complex64 &value); 00991 DataObject & operator = (const complex128 &value); 00992 DataObject & operator = (const ito::Rgba32 &value); 00995 DataObject & operator += (const DataObject &rhs); 00996 DataObject & operator += (const float64 &value); 00997 00998 DataObject operator + (const DataObject &rhs); 00999 DataObject operator + (const float64 &value); 01000 01001 DataObject & operator -= (const DataObject &rhs); 01002 DataObject & operator -= (const float64 &value); 01003 01004 DataObject operator - (const DataObject &rhs); 01005 DataObject operator - (const float64 &value); 01006 01007 DataObject & operator *= (const DataObject &rhs); 01008 DataObject & operator *= (const float64 &factor); 01009 01010 DataObject operator * (const DataObject &rhs); 01011 DataObject operator * (const float64 &factor); 01012 01013 // Comparison Operators 01014 DataObject operator < (DataObject &rhs); 01015 DataObject operator > (DataObject &rhs); 01016 DataObject operator <= (DataObject &rhs); 01017 DataObject operator >= (DataObject &rhs); 01018 DataObject operator == (DataObject &rhs); 01019 DataObject operator != (DataObject &rhs); 01020 01021 DataObject operator < (const float64 &value); 01022 DataObject operator > (const float64 &value); 01023 DataObject operator <= (const float64 &value); 01024 DataObject operator >= (const float64 &value); 01025 DataObject operator == (const float64 &value); 01026 DataObject operator != (const float64 &value); 01027 01028 // bitshift operators 01029 DataObject operator << (const unsigned int shiftbit); 01030 DataObject & operator <<= (const unsigned int shiftbit); 01031 DataObject operator >> (const unsigned int shiftbit); 01032 DataObject & operator >>= (const unsigned int shiftbit); 01033 01034 // bitwise operators 01035 DataObject operator & (const DataObject & rhs); 01036 DataObject & operator &= (const DataObject & rhs); 01037 DataObject operator | (const DataObject & rhs); 01038 DataObject & operator |= (const DataObject & rhs); 01039 DataObject operator ^ (const DataObject & rhs); 01040 DataObject & operator ^= (const DataObject & rhs); 01041 01042 // allocates matrix with zero values 01043 RetVal zeros(const int type); 01044 RetVal zeros(const int size, const int type); 01045 RetVal zeros(const int sizeY, const int sizeX, const int type); 01046 RetVal zeros(const int sizeZ, const int sizeY, const int sizeX, const int type, const unsigned char continuous = 0); 01047 RetVal zeros(const unsigned char dimensions, const int *sizes, const int type, const unsigned char continuous = 0); 01048 01049 // allocates matrix with all values set to one 01050 RetVal ones(const int type); 01051 RetVal ones(const int size, const int type); 01052 RetVal ones(const int sizeY, const int sizeX, const int type); 01053 RetVal ones(const int sizeZ, const int sizeY, const int sizeX, const int type, const unsigned char continuous = 0); 01054 RetVal ones(const unsigned char dimensions, const int *sizes, const int type, const unsigned char continuous = 0); 01055 01056 // allocates matrix with uniform distributed noise 01057 RetVal rand(const int type, const bool randMode = false); 01058 RetVal rand(const int size, const int type, const bool randMode = false); 01059 RetVal rand(const int sizeY, const int sizeX, const int type, const bool randMode = false); 01060 RetVal rand(const int sizeZ, const int sizeY, const int sizeX, const int type, const bool randMode, const unsigned char continuous = 0); 01061 RetVal rand(const unsigned char dimensions, const int *sizes, const int type, const bool randMode, const unsigned char continuous = 0); 01062 01063 // allocates matrix with eye-matrix representation 01064 RetVal eye(const int type); 01065 RetVal eye(const int size, const int type); 01066 01067 RetVal conj(); 01068 DataObject adj() const; 01069 DataObject trans() const; 01070 01071 // element-wise multiplication 01072 DataObject mul(const DataObject &mat2, const double scale = 1.0) const; 01073 DataObject div(const DataObject &mat2, const double scale = 1.0) const; 01074 DataObject squeeze() const; 01075 int elemSize() const; 01077 01078 01083 template<typename _Tp> inline const _Tp& at(const unsigned int y, const unsigned int x) const 01084 { 01085 #if __ITODEBUG 01086 if (m_dims != 2) 01087 { 01088 cv::error(cv::Exception(CV_StsAssert, "Dimension mismatch while addressing data field", "", __FILE__, __LINE__)); 01089 } 01090 else if (((int)x >= m_size[1]) || ((int)y >= m_size[0]) ) 01091 { 01092 cv::error(cv::Exception(CV_StsAssert, "Index out of bounds", "", __FILE__ , __LINE__)); 01093 } 01094 #endif 01095 return (*reinterpret_cast<const cv::Mat_<_Tp>*>(m_data[0]))(y, x); 01096 } 01097 01099 01104 template<typename _Tp> inline _Tp& at(const unsigned int y, const unsigned int x) 01105 { 01106 #if __ITODEBUG 01107 if (m_dims != 2) 01108 { 01109 cv::error(cv::Exception(CV_StsAssert, "Dimension mismatch while addressing data field", "", __FILE__, __LINE__)); 01110 } 01111 else if (((int)x >= m_size[1]) || ((int)y >= m_size[0]) ) 01112 { 01113 cv::error(cv::Exception(CV_StsAssert, "Index out of bounds", "", __FILE__ , __LINE__)); 01114 } 01115 #endif 01116 return (*reinterpret_cast<cv::Mat_<_Tp>*>(m_data[0]))(y, x); 01117 } 01118 01120 01126 template<typename _Tp> inline const _Tp& at(const unsigned int z, const unsigned int y, const unsigned int x) const 01127 { 01128 #if __ITODEBUG 01129 if (m_dims != 3) 01130 { 01131 cv::error(cv::Exception(CV_StsAssert, "Dimension mismatch while addressing data field", "", __FILE__, __LINE__)); 01132 } 01133 else if (((int)x >= m_size[2]) || ((int)y >= m_size[1]) || (((int)z + m_roi[0]) >= (m_roi[0] + m_size[0]))) 01134 { 01135 cv::error(cv::Exception(CV_StsAssert, "Index out of bounds", "", __FILE__ , __LINE__)); 01136 } 01137 #endif 01138 return (*reinterpret_cast<const cv::Mat_<_Tp>*>(m_data[z + m_roi[0]]))(y, x); 01139 } 01140 01142 01148 template<typename _Tp> inline _Tp& at(const unsigned int z, const unsigned int y, const unsigned int x) 01149 { 01150 #if __ITODEBUG 01151 if (m_dims != 3) 01152 { 01153 cv::error(cv::Exception(CV_StsAssert, "Dimension mismatch while addressing data field", "", __FILE__, __LINE__)); 01154 } 01155 else if (((int)x >= m_size[2]) || ((int)y >= m_size[1]) || (((int)z + m_roi[0]) >= (m_roi[0] + m_size[0]))) 01156 { 01157 cv::error(cv::Exception(CV_StsAssert, "Index out of bounds", "", __FILE__ , __LINE__)); 01158 } 01159 #endif 01160 return (*reinterpret_cast<cv::Mat_<_Tp>*>(m_data[z + m_roi[0]]))(y, x); 01161 } 01162 01164 01169 template<typename _Tp> inline const _Tp& at(const unsigned int *idx) const //idx is in virtual order 01170 { 01171 int matNum = 0; 01172 matIdxToNum(idx, &matNum); 01173 return (*reinterpret_cast<const cv::Mat_<_Tp>*>(m_data[matNum]))(idx[m_dims - 2], idx[m_dims - 1]); 01174 } 01175 01177 01182 template<typename _Tp> inline _Tp& at(const unsigned int *idx) //idx is in virtual order 01183 { 01184 int matNum = 0; 01185 matIdxToNum(idx, &matNum); 01186 return (*reinterpret_cast<cv::Mat_<_Tp>*>(m_data[matNum]))(idx[m_dims - 2], idx[m_dims - 1]); 01187 } 01188 01189 DataObject at(const ito::Range &rowRange, const ito::Range &colRange) const; 01190 DataObject at(ito::Range *ranges) const; 01191 DataObject at(const DataObject &mask) const; 01193 01194 01200 inline uchar* rowPtr(const int matNum, const int y) 01201 { 01202 int matIndex = seekMat(matNum); 01203 return ((cv::Mat*)m_data[matIndex])->ptr(y); 01204 } 01205 01207 01213 inline const uchar* rowPtr(const int matNum, const int y) const 01214 { 01215 int matIndex = seekMat(matNum); 01216 return ((const cv::Mat*)m_data[matIndex])->ptr(y); 01217 } 01218 01219 DataObject row(const int selRow) const; 01220 DataObject col(const int selCol) const; 01221 01222 DataObject toGray(const int destinationType = ito::tUInt8) const; 01223 01224 // ROI 01225 DataObject & adjustROI(const int dtop, const int dbottom, const int dleft, const int dright); 01226 DataObject & adjustROI(const unsigned char dims, const int *lims); 01227 RetVal locateROI(int *wholeSizes, int *offsets) const; 01228 RetVal locateROI(int *lims) const; 01230 01231 01246 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 01247 01249 01273 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 01274 01275 template<typename T2> operator T2 (); 01277 template<typename _Tp> RetVal linspace(const _Tp start, const _Tp end, const _Tp inc, const int transposed); 01278 01279 }; 01280 01281 //template<> DATAOBJ_EXPORT RetVal ito::DataObject::linspace<ito::int8>(const ito::int8 /*start*/, const ito::int8 /*end*/, const ito::int8 /*inc*/, const int /*transposed*/); 01282 //template<> DATAOBJ_EXPORT RetVal ito::DataObject::linspace<ito::uint8>(const ito::uint8 /*start*/, const ito::uint8 /*end*/, const ito::uint8 /*inc*/, const int /*transposed*/); 01283 01284 01285 //---------------------------------------------------------------------------------------------------------------------------------- 01286 // functions for DataObject in namespace ITO, which are NOT member functions 01287 //---------------------------------------------------------------------------------------------------------------------------------- 01288 DATAOBJ_EXPORT DataObject abs(const DataObject &dObj); 01289 DATAOBJ_EXPORT DataObject arg(const DataObject &dObj); 01290 DATAOBJ_EXPORT DataObject real(const DataObject &dObj); 01291 DATAOBJ_EXPORT DataObject imag(const DataObject &dObj); 01293 DATAOBJ_EXPORT DataObject makeContinuous(const DataObject &dObj); 01295 01296 01303 template<typename _Tp> inline _Tp numberConversion(ito::tDataType fromType, const void *scalar) 01304 { 01305 _Tp retValue; 01306 01307 switch(fromType) 01308 { 01309 case ito::tUInt8: 01310 retValue = cv::saturate_cast<_Tp>(*(static_cast<const uint8*>(scalar))); 01311 break; 01312 case ito::tInt8: 01313 retValue = cv::saturate_cast<_Tp>(*(static_cast<const int8*>(scalar))); 01314 break; 01315 case ito::tUInt16: 01316 retValue = cv::saturate_cast<_Tp>(*(static_cast<const uint16*>(scalar))); 01317 break; 01318 case ito::tInt16: 01319 retValue = cv::saturate_cast<_Tp>(*(static_cast<const int16*>(scalar))); 01320 break; 01321 case ito::tUInt32: 01322 retValue = cv::saturate_cast<_Tp>(*(static_cast<const uint32*>(scalar))); 01323 break; 01324 case ito::tInt32: 01325 retValue = cv::saturate_cast<_Tp>(*(static_cast<const int32*>(scalar))); 01326 break; 01327 case ito::tFloat32: 01328 retValue = cv::saturate_cast<_Tp>(*(static_cast<const ito::float32*>(scalar))); 01329 break; 01330 case ito::tFloat64: 01331 retValue = cv::saturate_cast<_Tp>(*(static_cast<const ito::float64*>(scalar))); 01332 break; 01333 case ito::tComplex64: 01334 retValue = cv::saturate_cast<_Tp>(*(static_cast<const ito::complex64*>(scalar))); 01335 break; 01336 case ito::tComplex128: 01337 retValue = cv::saturate_cast<_Tp>(*(static_cast<const ito::complex128*>(scalar))); 01338 break; 01339 case ito::tRGBA32: 01340 retValue = cv::saturate_cast<_Tp>(*(static_cast<const ito::Rgba32*>(scalar))); 01341 break; 01342 default: 01343 cv::error(cv::Exception(CV_StsAssert, "Input value type unkown", "", __FILE__, __LINE__)); 01344 retValue = 0; 01345 } 01346 01347 return retValue; 01348 }; 01349 01350 //deprecated 01351 template<typename _Tp> inline _Tp numberConversion(ito::tDataType fromType, void *scalar) 01352 { 01353 return numberConversion<_Tp>(fromType, const_cast<const void*>(scalar)); 01354 }; 01355 01356 01358 DATAOBJ_EXPORT std::ostream& operator << (std::ostream& out, const DataObject& dObj); 01359 01361 01368 inline ito::tDataType convertCmplxTypeToRealType(ito::tDataType cmplxType) 01369 { 01370 switch(cmplxType) 01371 { 01372 case ito::tInt8: 01373 case ito::tUInt8: 01374 case ito::tInt16: 01375 case ito::tUInt16: 01376 case ito::tInt32: 01377 case ito::tUInt32: 01378 case ito::tFloat32: 01379 case ito::tFloat64: 01380 case ito::tRGBA32: 01381 return cmplxType; 01382 case ito::tComplex64: 01383 return ito::tFloat32; 01384 case ito::tComplex128: 01385 return ito::tFloat64; 01386 } 01387 01388 cv::error(cv::Exception(CV_StsAssert, "Input data type unknown", "", __FILE__, __LINE__)); 01389 return ito::tInt8; 01390 } 01391 01393 01400 inline ito::tDataType guessDataTypeFromCVMat(const cv::Mat* mat, ito::RetVal &retval) 01401 { 01402 if (mat) 01403 { 01404 switch(mat->type()) 01405 { 01406 case cv::DataType<ito::int8>::type: 01407 return ito::tInt8; 01408 case cv::DataType<ito::uint8>::type: 01409 return ito::tUInt8; 01410 case cv::DataType<ito::int16>::type: 01411 return ito::tInt16; 01412 case cv::DataType<ito::uint16>::type: 01413 return ito::tUInt16; 01414 case cv::DataType<ito::int32>::type: 01415 return ito::tInt32; 01416 case cv::DataType<ito::uint32>::type: 01417 return ito::tUInt32; 01418 case cv::DataType<ito::float32>::type: 01419 return ito::tFloat32; 01420 case cv::DataType<ito::float64>::type: 01421 return ito::tFloat64; 01422 case cv::DataType<ito::Rgba32>::type: 01423 return ito::tRGBA32; 01424 case cv::DataType<ito::complex64>::type: 01425 return ito::tComplex64; 01426 case cv::DataType<ito::complex128>::type: 01427 return ito::tComplex128; 01428 } 01429 01430 retval += ito::RetVal(ito::retError, 0, "type of cv::Mat is incompatible to ito::DataObject"); 01431 } 01432 else 01433 { 01434 retval += ito::RetVal(ito::retError, 0, "given cv::Mat is NULL."); 01435 } 01436 return ito::tInt8; 01437 } 01438 01439 01441 01449 template<typename _Tp> inline ito::tDataType getDataType(const _Tp* /*src*/) 01450 { 01451 cv::error(cv::Exception(CV_StsAssert, "Input value type unkown", "", __FILE__, __LINE__)); 01452 return ito::tInt8; 01453 } 01454 01455 template<> inline ito::tDataType getDataType(const uint8* /*src*/) { return ito::tUInt8; } 01456 template<> inline ito::tDataType getDataType(const int8* /*src*/) { return ito::tInt8; } 01457 template<> inline ito::tDataType getDataType(const uint16* /*src*/) { return ito::tUInt16; } 01458 template<> inline ito::tDataType getDataType(const int16* /*src*/) { return ito::tInt16; } 01459 template<> inline ito::tDataType getDataType(const uint32* /*src*/) { return ito::tUInt32; } 01460 template<> inline ito::tDataType getDataType(const int32* /*src*/) { return ito::tInt32; } 01461 template<> inline ito::tDataType getDataType(const float32* /*src*/) { return ito::tFloat32; } 01462 template<> inline ito::tDataType getDataType(const float64* /*src*/) { return ito::tFloat64; } 01463 template<> inline ito::tDataType getDataType(const complex64* /*src*/) { return ito::tComplex64; } 01464 template<> inline ito::tDataType getDataType(const complex128* /*src*/) { return ito::tComplex128; } 01465 template<> inline ito::tDataType getDataType(const Rgba32* /*src*/) { return ito::tRGBA32; } 01466 01467 01469 01478 template<typename _Tp> inline ito::tDataType getDataType2() 01479 { 01480 cv::error(cv::Exception(CV_StsAssert, "Input value type unkown", "", __FILE__, __LINE__)); 01481 return ito::tInt8; 01482 } 01483 01484 template<> inline ito::tDataType getDataType2<uint8*>() { return ito::tUInt8; } 01485 template<> inline ito::tDataType getDataType2<int8*>() { return ito::tInt8; } 01486 template<> inline ito::tDataType getDataType2<uint16*>() { return ito::tUInt16; } 01487 template<> inline ito::tDataType getDataType2<int16*>() { return ito::tInt16; } 01488 template<> inline ito::tDataType getDataType2<uint32*>() { return ito::tUInt32; } 01489 template<> inline ito::tDataType getDataType2<int32*>() { return ito::tInt32; } 01490 template<> inline ito::tDataType getDataType2<float32*>() { return ito::tFloat32; } 01491 template<> inline ito::tDataType getDataType2<float64*>() { return ito::tFloat64; } 01492 template<> inline ito::tDataType getDataType2<complex64*>() { return ito::tComplex64; } 01493 template<> inline ito::tDataType getDataType2<complex128*>() { return ito::tComplex128; } 01494 template<> inline ito::tDataType getDataType2<Rgba32*>() { return ito::tRGBA32; } 01495 01497 01507 template<typename _Tp> inline bool isZeroValue(_Tp v, _Tp /*epsilon*/) 01508 { 01509 return v == 0; 01510 } 01511 01512 template<> inline bool isZeroValue(Rgba32 v, Rgba32 /*epsilon*/) 01513 { 01514 return v == Rgba32::zeros(); 01515 } 01516 01517 template<> inline bool isZeroValue(float32 v, float32 epsilon) 01518 { 01519 return v >= epsilon ? false : (v <= -epsilon ? false : true); 01520 } 01521 01522 template<> inline bool isZeroValue(float64 v, float64 epsilon) 01523 { 01524 return v >= epsilon ? false : (v <= -epsilon ? false : true); 01525 } 01526 01527 template<> inline bool isZeroValue(std::complex<ito::float32> v, std::complex<ito::float32> epsilon) 01528 { 01529 return isZeroValue<ito::float32>(v.real(),epsilon.real()) && isZeroValue<ito::float32>(v.imag(),epsilon.real()); 01530 } 01531 01532 template<> inline bool isZeroValue(std::complex<ito::float64> v, std::complex<ito::float64> epsilon) 01533 { 01534 return isZeroValue<ito::float64>(v.real(),epsilon.real()) && isZeroValue<ito::float64>(v.imag(),epsilon.real()); 01535 } 01536 01537 01538 } //namespace ito 01539 01540 #endif //__DATAOBJH 01541 01542