itom 2.2.1
|
00001 /* ******************************************************************** 00002 itom software 00003 URL: http://www.uni-stuttgart.de/ito 00004 Copyright (C) 2016, Institut fuer Technische Optik (ITO), 00005 Universitaet 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 fuer 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 #include "../common/byteArray.h" 00051 00052 00053 namespace cv 00054 { 00055 template<> inline ito::float32 saturate_cast<ito::float32>( ito::float64 v) 00056 { 00057 if(cvIsInf(v)) return std::numeric_limits<ito::float32>::infinity(); 00058 if(cvIsNaN(v)) return std::numeric_limits<ito::float32>::quiet_NaN(); 00059 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() ))); 00060 } 00061 00062 template<> inline ito::float64 saturate_cast<ito::float64>( ito::float32 v) 00063 { 00064 if(cvIsInf(v)) return std::numeric_limits<ito::float64>::infinity(); 00065 if(cvIsNaN(v)) return std::numeric_limits<ito::float64>::quiet_NaN(); 00066 return static_cast<ito::float64>(v); 00067 } 00068 00069 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; } 00070 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; } 00071 00072 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; } 00073 // 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; } 00074 00075 template<> inline ito::complex64 saturate_cast(ito::uint8 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); } 00076 template<> inline ito::complex64 saturate_cast(ito::int8 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); } 00077 template<> inline ito::complex64 saturate_cast(ito::uint16 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); } 00078 template<> inline ito::complex64 saturate_cast(ito::int16 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); } 00079 template<> inline ito::complex64 saturate_cast(ito::uint32 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); } 00080 template<> inline ito::complex64 saturate_cast(ito::int32 v){ return ito::complex64(static_cast<ito::float32>(v),0.0); } 00081 template<> inline ito::complex64 saturate_cast(ito::float32 v){ return ito::complex64(v,0.0); } 00082 template<> inline ito::complex64 saturate_cast(ito::float64 v){ return ito::complex64(saturate_cast<ito::float32>(v),0.0); } 00083 template<> inline ito::complex64 saturate_cast(ito::complex64 v){ return v; } 00084 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())); } 00085 00086 template<> inline ito::complex128 saturate_cast(ito::uint8 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); } 00087 template<> inline ito::complex128 saturate_cast(ito::int8 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); } 00088 template<> inline ito::complex128 saturate_cast(ito::uint16 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); } 00089 template<> inline ito::complex128 saturate_cast(ito::int16 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); } 00090 template<> inline ito::complex128 saturate_cast(ito::uint32 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); } 00091 template<> inline ito::complex128 saturate_cast(ito::int32 v){ return ito::complex128(static_cast<ito::float64>(v),0.0); } 00092 template<> inline ito::complex128 saturate_cast(ito::float32 v){ return ito::complex128(saturate_cast<ito::float64>(v),0.0); } 00093 template<> inline ito::complex128 saturate_cast(ito::float64 v){ return ito::complex128(v,0.0); } 00094 template<> inline ito::complex128 saturate_cast(ito::complex64 v){ return ito::complex128(saturate_cast<ito::float64>(v.real()),saturate_cast<ito::float64>(v.imag())); } 00095 template<> inline ito::complex128 saturate_cast(ito::complex128 v){ return v; } 00096 00097 // template<> inline ito::Rgba32 saturate_cast(ito::int8 v) {return ito::Rgba32(saturate_cast<ito::uint8>(v));} 00098 template<> inline ito::Rgba32 saturate_cast(ito::uint8 v) {return ito::Rgba32(v);} 00099 template<> inline ito::Rgba32 saturate_cast(ito::uint16 v){return ito::Rgba32(saturate_cast<ito::uint8>(v));} 00100 // template<> inline ito::Rgba32 saturate_cast(ito::int16 v){return ito::Rgba32(saturate_cast<ito::uint8>(v));} 00101 template<> inline ito::Rgba32 saturate_cast(ito::uint32 v) 00102 { 00103 return ito::Rgba32::fromUnsignedLong(v); 00104 } 00105 template<> inline ito::Rgba32 saturate_cast(ito::int32 v) 00106 { 00107 ito::Rgba32 temp; 00108 temp.rgba = static_cast<ito::uint32>(v); 00109 return temp; 00110 } 00111 template<> inline ito::Rgba32 saturate_cast(ito::float32 v){return ito::Rgba32(saturate_cast<ito::uint8>(v));} 00112 template<> inline ito::Rgba32 saturate_cast(ito::float64 v){return ito::Rgba32(saturate_cast<ito::uint8>(v));} 00113 template<> inline ito::Rgba32 saturate_cast(ito::Rgba32 v){return v;} 00114 00115 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(); } 00116 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(); } 00117 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(); } 00118 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(); } 00119 00120 template<> inline ito::uint8 saturate_cast(ito::Rgba32 v){return saturate_cast<ito::uint8>(v.gray());}; 00121 //template<> inline ito::int16 saturate_cast(ito::Rgba32 v){return saturate_cast<ito::int16>(v.gray());}; 00122 template<> inline ito::uint16 saturate_cast(ito::Rgba32 v){return saturate_cast<ito::uint16>(v.gray());}; 00123 template<> inline ito::uint32 saturate_cast(ito::Rgba32 v){return v.argb();}; 00124 template<> inline ito::int32 saturate_cast(ito::Rgba32 v){return (ito::int32)(v.argb());}; 00125 template<> inline ito::float32 saturate_cast(ito::Rgba32 v){return v.gray();}; 00126 template<> inline ito::float64 saturate_cast(ito::Rgba32 v){return (ito::float64)v.gray();}; 00127 00128 00129 template<> class DataType<ito::Rgba32> 00130 { 00131 public: 00132 typedef ito::Rgba32 value_type; 00133 typedef ito::uint8 channel_type; 00134 typedef Vec<channel_type, 4> work_type; 00135 typedef value_type vec_type; 00136 enum 00137 { 00138 generic_type = 0, 00139 depth = cv::DataDepth<channel_type>::value, 00140 channels = 4, 00141 fmt = ((channels-1)<<8) + cv::DataDepth<channel_type>::fmt, 00142 type = CV_MAKETYPE(depth, channels) 00143 }; 00144 }; 00145 00146 template<> class DataType<ito::RedChannel> 00147 { 00148 public: 00149 typedef ito::RedChannel value_type; 00150 typedef ito::uint8 channel_type; 00151 typedef Vec<channel_type, 4> work_type; 00152 typedef value_type vec_type; 00153 enum 00154 { 00155 generic_type = 0, 00156 depth = cv::DataDepth<channel_type>::value, 00157 channels = 4, 00158 fmt = ((channels-1)<<8) + cv::DataDepth<channel_type>::fmt, 00159 type = CV_MAKETYPE(depth, channels) 00160 }; 00161 }; 00162 00163 template<> class DataType<ito::GreenChannel> 00164 { 00165 public: 00166 typedef ito::GreenChannel value_type; 00167 typedef ito::uint8 channel_type; 00168 typedef Vec<channel_type, 4> work_type; 00169 typedef value_type vec_type; 00170 enum 00171 { 00172 generic_type = 0, 00173 depth = cv::DataDepth<channel_type>::value, 00174 channels = 4, 00175 fmt = ((channels-1)<<8) + cv::DataDepth<channel_type>::fmt, 00176 type = CV_MAKETYPE(depth, channels) 00177 }; 00178 }; 00179 00180 template<> class DataType<ito::BlueChannel> 00181 { 00182 public: 00183 typedef ito::BlueChannel value_type; 00184 typedef ito::uint8 channel_type; 00185 typedef Vec<channel_type, 4> work_type; 00186 typedef value_type vec_type; 00187 enum 00188 { 00189 generic_type = 0, 00190 depth = cv::DataDepth<channel_type>::value, 00191 channels = 4, 00192 fmt = ((channels-1)<<8) + cv::DataDepth<channel_type>::fmt, 00193 type = CV_MAKETYPE(depth, channels) 00194 }; 00195 }; 00196 00197 template<> class DataType<ito::AlphaChannel> 00198 { 00199 public: 00200 typedef ito::AlphaChannel value_type; 00201 typedef ito::uint8 channel_type; 00202 typedef Vec<channel_type, 4> work_type; 00203 typedef value_type vec_type; 00204 enum 00205 { 00206 generic_type = 0, 00207 depth = cv::DataDepth<channel_type>::value, 00208 channels = 4, 00209 fmt = ((channels-1)<<8) + cv::DataDepth<channel_type>::fmt, 00210 type = CV_MAKETYPE(depth, channels) 00211 }; 00212 }; 00213 00214 00215 } // namespace cv 00216 00217 namespace ito { 00218 00219 #define __ITODEBUG 1 00220 00221 //forward declarations 00222 class DObjIterator; 00223 class DataObject; 00224 class Range; 00225 class DataObjectTags; 00226 class DataObjectTagType; 00227 class DataObjectTagsPrivate; 00228 00229 00230 //---------------------------------------------------------------------------------------------------------------------------------- 00237 class DATAOBJ_EXPORT Range 00238 { 00239 public: 00240 Range() : start(0), end(0) {} 00241 Range(int _start, int _end) { _start < _end ? (end = _end, start = _start) : (start = _end, end = _start); } 00242 inline unsigned int size() const { return end - start; } 00243 inline bool empty() const { return (start == end); } 00244 static Range all() { return Range(INT_MIN, INT_MAX); } 00246 int start; 00247 int end; 00248 }; 00249 00250 //---------------------------------------------------------------------------------------------------------------------------------- 00257 class DATAOBJ_EXPORT DataObjectTagType 00258 { 00259 public: 00260 enum tTagType 00261 { 00262 typeInvalid = 0x000000, 00263 typeDouble = 0x000008, 00264 typeString = 0x000020 00265 }; 00266 00267 private: 00268 double m_dVal; 00269 tTagType m_type; 00270 ByteArray m_strValue; 00271 00272 public: 00274 DataObjectTagType() : m_dVal(0), m_strValue(""), m_type(DataObjectTagType::typeInvalid){} 00275 DataObjectTagType(double dVal) : m_dVal(dVal), m_strValue(""), m_type(DataObjectTagType::typeDouble){} 00276 DataObjectTagType(const std::string &str) : m_dVal(std::numeric_limits<double>::quiet_NaN()), m_type(DataObjectTagType::typeString){ m_strValue = str.data(); } 00277 DataObjectTagType(const ByteArray &str) : m_dVal(std::numeric_limits<double>::quiet_NaN()), m_type(DataObjectTagType::typeString){ m_strValue = str; } 00278 DataObjectTagType(const char* cVal) : m_dVal(std::numeric_limits<double>::quiet_NaN()), m_type(DataObjectTagType::typeString){ cVal == NULL ? m_strValue = "" : m_strValue = cVal;} 00280 DataObjectTagType(const DataObjectTagType& a) : m_dVal(a.m_dVal), m_type(a.m_type), m_strValue(a.m_strValue) {} 00281 00283 DataObjectTagType & operator = (const DataObjectTagType &rhs) 00284 { 00285 this->m_dVal = rhs.m_dVal; 00286 this->m_strValue = rhs.m_strValue; 00287 this->m_type = rhs.m_type; 00288 00289 return *this; 00290 } 00291 00293 inline int getType(void) const {return m_type;} 00294 00296 inline bool isValid(void) const { return (m_type == DataObjectTagType::typeInvalid) ? false: true;} 00297 00303 inline double getVal_ToDouble(void) 00304 { 00305 if(m_type == DataObjectTagType::typeInvalid) 00306 { 00307 return std::numeric_limits<double>::quiet_NaN(); 00308 } 00309 else if(m_type == DataObjectTagType::typeDouble) 00310 { 00311 return m_dVal; 00312 } 00313 else 00314 { 00315 double dVal = std::numeric_limits<double>::quiet_NaN(); 00316 //dVal = atof(m_strValue.c_str()); //sometimes the result of that line has been arbitrary, therefore this conversion should fail. 00317 return dVal; 00318 } 00319 } 00320 00326 inline ByteArray getVal_ToString(void) 00327 { 00328 if(m_type == DataObjectTagType::typeInvalid) 00329 { 00330 return ""; 00331 } 00332 else if(m_type == DataObjectTagType::typeString) 00333 { 00334 return m_strValue; 00335 } 00336 else 00337 { 00338 if (cvIsNaN(m_dVal)) return "NaN"; 00339 if (cvIsInf(m_dVal)) return "Inf"; 00340 00341 std::ostringstream strs; 00342 strs << m_dVal; 00343 ByteArray ba(strs.str().data()); 00344 00345 return ba; 00346 } 00347 } 00348 }; 00349 00350 //---------------------------------------------------------------------------------------------------------------------------------- 00361 class DATAOBJ_EXPORT DObjConstIterator 00362 { 00363 public: 00364 00366 DObjConstIterator(); 00367 00369 DObjConstIterator(const DataObject* _dObj, int pos = 0); 00370 00372 DObjConstIterator(const DObjConstIterator& it); 00373 00375 DObjConstIterator& operator = (const DObjConstIterator& it); 00376 00378 const uchar* operator *() const; 00379 00381 const uchar* operator [](int i) const; 00382 00384 DObjConstIterator& operator += (int ofs); 00385 00387 DObjConstIterator& operator -= (int ofs); 00388 00390 DObjConstIterator& operator --(); 00391 00393 DObjConstIterator operator --(int); 00394 00396 DObjConstIterator& operator ++(); 00397 00399 DObjConstIterator operator ++(int); 00400 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 bool operator >= (const DObjConstIterator& dObjIt); 00407 00408 protected: 00410 void seekAbs(int ofs); 00411 00413 void seekRel(int ofs); 00414 00415 const DataObject* dObj; 00416 bool planeContinuous; 00417 int elemSize; 00418 uchar* ptr; 00419 uchar* sliceStart; 00420 uchar* sliceEnd; 00421 int plane; 00422 }; 00423 00424 //---------------------------------------------------------------------------------------------------------------------------------- 00433 class DATAOBJ_EXPORT DObjIterator : public DObjConstIterator 00434 { 00435 public: 00436 00438 DObjIterator(); 00439 00441 DObjIterator(DataObject* _dObj, int pos = 0); 00442 00444 DObjIterator(const DObjIterator& it); 00445 00447 DObjIterator& operator = (const DObjIterator& it); 00448 00450 uchar* operator *(); 00451 00453 uchar* operator [](int i); 00454 00456 DObjIterator& operator += (int ofs); 00457 00459 DObjIterator& operator -= (int ofs); 00460 00462 DObjIterator& operator --(); 00463 00465 DObjIterator operator --(int); 00466 00468 DObjIterator& operator ++(); 00469 00471 DObjIterator operator ++(int); 00472 }; 00473 00474 //---------------------------------------------------------------------------------------------------------------------------------- 00475 00476 // Forward declaration of friend methods 00477 #ifdef __APPLE__ 00478 template<typename _Tp> RetVal CreateFunc(DataObject *dObj, const unsigned char dimensions, const int *sizes, const unsigned char continuous, const uchar* continuousDataPtr, const int* steps); 00479 template<typename _Tp> RetVal CreateFuncWithCVPlanes(DataObject *dObj, const unsigned char dimensions, const int *sizes, const cv::Mat* planes, const unsigned int nrOfPlanes); 00480 template<typename _Tp> RetVal FreeFunc(DataObject *dObj); 00481 template<typename _Tp> RetVal SecureFreeFunc(DataObject *dObj); 00482 template<typename _Tp> RetVal CopyToFunc(const DataObject &lhs, DataObject &rhs, unsigned char regionOnly); 00483 template<typename _Tp> RetVal ConvertToFunc(const DataObject &lhs, DataObject &rhs, const int type, const double alpha, const double beta); 00484 template<typename _Tp> RetVal AdjustROIFunc(DataObject *dObj, const int *lims); 00485 template<typename _Tp> RetVal MinMaxLocFunc(const DataObject &dObj, double *minVal, double *maxVal, int *minPos, int *maxPos); 00486 template<typename _Tp> RetVal AssignScalarFunc(const DataObject *src, const ito::tDataType type, const void *scalar); 00487 template<typename _Tp> RetVal MakeContinuousFunc(const DataObject &dObj, DataObject &resDObj); 00488 template<typename _Tp> RetVal EvaluateTransposeFlagFunc(DataObject *dObj); 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]; 00535 if( d != sz.m_p[-1] ) 00536 return false; 00537 00538 return (memcmp(m_p, sz.m_p, d * sizeof(int)) == 0); //returns true if the size vector (having the same length) is equal 00539 } 00540 00541 inline bool operator != (const MSize& sz) const { return !(*this == sz); } 00542 00543 int *m_p; 00544 }; 00545 00546 00547 struct DATAOBJ_EXPORT MROI 00548 { 00549 inline MROI() : m_p(NULL) {}; 00550 inline int operator [] (const int dim) const 00551 { 00552 return m_p[dim]; //return the size value. this operator corresponds to the real data representation in memory 00553 } 00554 00555 inline bool operator == (const MROI & rroi) const 00556 { 00557 if(m_p == NULL || rroi.m_p == NULL) 00558 { 00559 return rroi.m_p == m_p; 00560 } 00561 00562 int d = m_p[-1]; 00563 if( d != rroi.m_p[-1] ) 00564 return false; 00565 00566 return (memcmp(m_p, rroi.m_p, d * sizeof(int)) == 0); //returns true if the size vector (having the same length) is equal 00567 00568 if (m_p[-1] != rroi.m_p[-1]) 00569 { 00570 return false; 00571 } 00572 } 00573 00574 int *m_p; 00575 }; 00576 00577 DataObject(const DataObject& dObj, bool transposed); 00579 char m_continuous; 00580 char m_owndata; 00581 int m_type; 00582 int *m_pRefCount; 00583 int m_dims; 00584 MSize m_osize; 00585 MROI m_roi; 00586 MSize m_size; 00587 uchar **m_data; 00588 DataObjectTagsPrivate *m_pDataObjectTags; 00589 static const int m_sizeofs; 00590 00591 int mdata_realloc(const int size); 00592 int mdata_size(void) const; 00593 int mdata_free(); 00594 00595 RetVal copyFromData2DInternal(const uchar* src, const int sizeOfElem, const int sizeX, const int sizeY); 00596 RetVal copyFromData2DInternal(const uchar* src, const int sizeOfElem, const int sizeX, const int x0, const int y0, const int width, const int height); 00597 00598 //low-level, templated methods 00599 //most low-level methods are marked "friend" such that they can access private members of their data object parameters 00600 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); 00601 template<typename _Tp> friend RetVal CreateFuncWithCVPlanes(DataObject *dObj, const unsigned char dimensions, const int *sizes, const cv::Mat* planes, const unsigned int nrOfPlanes); 00602 template<typename _Tp> friend RetVal FreeFunc(DataObject *dObj); 00603 template<typename _Tp> friend RetVal SecureFreeFunc(DataObject *dObj); 00604 template<typename _Tp> friend RetVal CopyToFunc(const DataObject &lhs, DataObject &rhs, unsigned char regionOnly); 00605 template<typename _Tp> friend RetVal ConvertToFunc(const DataObject &lhs, DataObject &rhs, const int type, const double alpha, const double beta); 00606 template<typename _Tp> friend RetVal AdjustROIFunc(DataObject *dObj, const int *lims); 00607 template<typename _Tp> friend RetVal MinMaxLocFunc(const DataObject &dObj, double *minVal, double *maxVal, int *minPos, int *maxPos); 00608 template<typename _Tp> friend RetVal AssignScalarFunc(const DataObject *src, const ito::tDataType type, const void *scalar); 00609 template<typename _Tp> friend RetVal MakeContinuousFunc(const DataObject &dObj, DataObject &resDObj); 00610 template<typename _Tp> friend RetVal EvaluateTransposeFlagFunc(DataObject *dObj); 00611 template<typename _Tp> friend std::ostream& coutFunc(std::ostream& out, const DataObject& dObj); 00612 00613 // more friends due to change of std::vector to int ** for m_data ... 00614 template<typename _Tp> friend RetVal GetRangeFunc(DataObject *dObj, const int dtop, const int dbottom, const int dleft, const int dright); 00615 template<typename _Tp> friend RetVal AdjustROIFunc(DataObject *dObj, int dtop, int dbottom, int dleft, int dright); 00616 00617 public: 00619 DataObject(void); 00620 00622 DataObject(const int size, const int type); 00623 00625 DataObject(const int sizeY, const int sizeX, const int type); 00626 00628 DataObject(const int sizeZ, const int sizeY, const int sizeX, const int type, const unsigned char continuous = 0); 00629 00631 DataObject(const int sizeZ, const int sizeY, const int sizeX, const int type, const uchar* continuousDataPtr, const int* steps = NULL); 00632 00634 DataObject(const MSize &sizes, const int type, const unsigned char continuous = 0); 00635 00637 DataObject(const unsigned char dimensions, const int *sizes, const int type, const unsigned char continuous = 0); 00638 00640 DataObject(const unsigned char dimensions, const int *sizes, const int type, const uchar* continuousDataPtr, const int* steps = NULL); 00641 00642 DataObject(const unsigned char dimensions, const int *sizes, const int type, const cv::Mat* planes, const unsigned int nrOfPlanes); 00643 00644 DataObject(const DataObject& copyConstr); 00646 00647 ~DataObject(void); 00648 00649 // TAGSPACEFUNCTIONS 00650 00652 double getValueOffset() const; 00653 00655 double getValueScale() const; 00656 00658 const std::string getValueUnit() const; 00659 00661 std::string getValueDescription() const; 00662 00664 double getAxisOffset(const int axisNum) const; 00665 00667 double getAxisScale(const int axisNum) const; 00668 00670 const std::string getAxisUnit(const int axisNum, bool &validOperation) const; 00671 00673 std::string getAxisDescription(const int axisNum, bool &validOperation) const; 00674 00675 DataObjectTagType getTag(const std::string &key, bool &validOperation) const; 00676 00677 bool getTagByIndex(const int tagNumber, std::string &key, DataObjectTagType &value) const; 00678 00680 std::string getTagKey(const int tagNumber, bool &validOperation) const; 00681 00683 int getTagListSize() const; 00684 00686 int setValueUnit(const std::string &unit); 00687 00689 int setValueDescription(const std::string &description); 00690 00692 int setAxisOffset(const unsigned int axisNum, const double offset); 00693 00695 int setAxisScale(const unsigned int axisNum, const double scale); 00696 00698 int setAxisUnit(const unsigned int axisNum, const std::string &unit); 00699 00701 int setAxisDescription(const unsigned int axisNum, const std::string &description); 00702 int setTag(const std::string &key, const DataObjectTagType &value); 00703 bool existTag(const std::string &key) const; 00704 bool deleteTag(const std::string &key); 00705 bool deleteAllTags(); 00706 int addToProtocol(const std::string &value); 00707 00708 00712 double getPhysToPix(const unsigned int dim, const double phys, bool &isInsideImage) const; 00713 00717 double getPhysToPix(const unsigned int dim, const double phys) const; 00718 00722 int getPhysToPix2D(const double physY, double &tPxY, bool &isInsideImageY, const double physX, double &tPxX, bool &isInsideImageX) const; 00723 00727 double getPixToPhys(const unsigned int dim, const double pix, bool &isInsideImage) const; 00728 00732 double getPixToPhys(const unsigned int dim, const double pix) const; 00733 00747 RetVal setXYRotationalMatrix(double r11, double r12, double r13, double r21, double r22, double r23, double r31, double r32, double r33); 00748 00762 RetVal getXYRotationalMatrix(double &r11, double &r12, double &r13, double &r21, double &r22, double &r23, double &r31, double &r32, double &r33) const; 00763 00764 RetVal copyTagMapTo(DataObject &rhs) const; 00765 RetVal copyAxisTagsTo(DataObject &rhs) const; 00767 // END TAGSPACE 00768 00770 inline int getDims(void) const { return m_dims; } 00771 00773 inline int getType(void) const { return m_type; } 00774 00776 inline char getContinuous(void) const { return m_continuous; } 00777 00779 inline char getOwnData(void) const { return m_owndata; } 00780 00782 int seekMat(const int matNum, const int numMats) const; 00783 00785 int seekMat(const int matNum) const; 00786 00788 int calcNumMats(void) const; 00789 00791 00796 inline int getNumPlanes(void) const 00797 { 00798 switch (m_dims) 00799 { 00800 case 0: 00801 return 0; 00802 case 1: 00803 case 2: 00804 return 1; 00805 case 3: 00806 return m_size[0]; 00807 case 4: 00808 return m_size[0] * m_size[1]; 00809 default: 00810 { 00811 int numMat = 1; 00812 for (int n = 0; n < m_dims - 2; n++) 00813 { 00814 numMat *= m_size[n]; 00815 } 00816 return numMat; 00817 } 00818 } 00819 } 00820 00822 cv::Mat* getCvPlaneMat(const int planeIndex); 00823 00825 const cv::Mat* getCvPlaneMat(const int planeIndex) const; 00826 00828 const cv::Mat getContinuousCvPlaneMat(const int planeIndex) const; 00829 00831 00840 inline cv::Mat** get_mdata(void) 00841 { 00842 return (cv::Mat**)m_data; 00843 } 00844 00846 00855 inline const cv::Mat** get_mdata(void) const 00856 { 00857 return (const cv::Mat**)m_data; 00858 } 00859 00861 00864 inline MSize getSize(void) { return m_size; } 00865 00867 00870 inline const MSize getSize(void) const { return m_size; } 00871 00873 00877 inline int getSize(int index) const 00878 { 00879 if(index < 0 || index >= m_dims) 00880 { 00881 return -1; 00882 } 00883 else 00884 { 00885 return m_size[index]; 00886 } 00887 } 00888 00890 00894 inline int getOriginalSize(int index) const 00895 { 00896 if(index < 0 || index >= m_dims) 00897 { 00898 return -1; 00899 } 00900 else 00901 { 00902 return m_osize[index]; 00903 } 00904 } 00905 00907 00914 int getStep(int index) const; 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 DataObject & operator += (const complex128 &value); 00998 00999 DataObject operator + (const DataObject &rhs); 01000 DataObject operator + (const float64 &value); 01001 DataObject operator + (const complex128 &value); 01002 01003 DataObject & operator -= (const DataObject &rhs); 01004 DataObject & operator -= (const float64 &value); 01005 DataObject & operator -= (const complex128 &value); 01006 01007 DataObject operator - (const DataObject &rhs); 01008 DataObject operator - (const float64 &value); 01009 DataObject operator - (const complex128 &value); 01010 01011 DataObject & operator *= (const DataObject &rhs); 01012 DataObject & operator *= (const float64 &factor); 01013 DataObject & operator *= (const complex128 &factor); 01014 01015 DataObject operator * (const DataObject &rhs); 01016 DataObject operator * (const float64 &factor); 01017 DataObject operator * (const complex128 &factor); 01018 01019 // Comparison Operators 01020 DataObject operator < (DataObject &rhs); 01021 DataObject operator > (DataObject &rhs); 01022 DataObject operator <= (DataObject &rhs); 01023 DataObject operator >= (DataObject &rhs); 01024 DataObject operator == (DataObject &rhs); 01025 DataObject operator != (DataObject &rhs); 01026 01027 DataObject operator < (const float64 &value); 01028 DataObject operator > (const float64 &value); 01029 DataObject operator <= (const float64 &value); 01030 DataObject operator >= (const float64 &value); 01031 DataObject operator == (const float64 &value); 01032 DataObject operator != (const float64 &value); 01033 01034 // bitshift operators 01035 DataObject operator << (const unsigned int shiftbit); 01036 DataObject & operator <<= (const unsigned int shiftbit); 01037 DataObject operator >> (const unsigned int shiftbit); 01038 DataObject & operator >>= (const unsigned int shiftbit); 01039 01040 // bitwise operators 01041 DataObject operator & (const DataObject & rhs); 01042 DataObject & operator &= (const DataObject & rhs); 01043 DataObject operator | (const DataObject & rhs); 01044 DataObject & operator |= (const DataObject & rhs); 01045 DataObject operator ^ (const DataObject & rhs); 01046 DataObject & operator ^= (const DataObject & rhs); 01047 DataObject bitwise_not() const; 01049 // allocates matrix with zero values 01050 RetVal zeros(const int type); 01051 RetVal zeros(const int size, const int type); 01052 RetVal zeros(const int sizeY, const int sizeX, const int type); 01053 RetVal zeros(const int sizeZ, const int sizeY, const int sizeX, const int type, const unsigned char continuous = 0); 01054 RetVal zeros(const unsigned char dimensions, const int *sizes, const int type, const unsigned char continuous = 0); 01055 01056 // allocates matrix with all values set to one 01057 RetVal ones(const int type); 01058 RetVal ones(const int size, const int type); 01059 RetVal ones(const int sizeY, const int sizeX, const int type); 01060 RetVal ones(const int sizeZ, const int sizeY, const int sizeX, const int type, const unsigned char continuous = 0); 01061 RetVal ones(const unsigned char dimensions, const int *sizes, const int type, const unsigned char continuous = 0); 01062 01063 // allocates matrix with uniform distributed noise 01064 RetVal rand(const int type, const bool randMode = false); 01065 RetVal rand(const int size, const int type, const bool randMode = false); 01066 RetVal rand(const int sizeY, const int sizeX, const int type, const bool randMode = false); 01067 RetVal rand(const int sizeZ, const int sizeY, const int sizeX, const int type, const bool randMode, const unsigned char continuous = 0); 01068 RetVal rand(const unsigned char dimensions, const int *sizes, const int type, const bool randMode, const unsigned char continuous = 0); 01069 01070 // allocates matrix with eye-matrix representation 01071 RetVal eye(const int type); 01072 RetVal eye(const int size, const int type); 01073 01074 RetVal conj(); 01075 DataObject adj() const; 01076 DataObject trans() const; 01077 01078 // element-wise multiplication 01079 DataObject mul(const DataObject &mat2, const double scale = 1.0) const; 01080 DataObject div(const DataObject &mat2, const double scale = 1.0) const; 01081 01082 // power (power of 0.5 is the square root) 01083 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) 01084 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. 01085 01086 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) 01087 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) 01088 01089 DataObject squeeze() const; 01090 DataObject reshape(int newDims, const int *newSizes) const; 01091 01092 int elemSize() const; 01094 01095 01100 template<typename _Tp> inline const _Tp& at(const unsigned int y, const unsigned int x) const 01101 { 01102 #if __ITODEBUG 01103 if (m_dims != 2) 01104 { 01105 cv::error(cv::Exception(CV_StsAssert, "Dimension mismatch while addressing data field", "", __FILE__, __LINE__)); 01106 } 01107 else if (((int)x >= m_size[1]) || ((int)y >= m_size[0]) ) 01108 { 01109 cv::error(cv::Exception(CV_StsAssert, "Index out of bounds", "", __FILE__ , __LINE__)); 01110 } 01111 #endif 01112 return (*reinterpret_cast<const cv::Mat_<_Tp>*>(m_data[0]))(y, x); 01113 } 01114 01116 01121 template<typename _Tp> inline _Tp& at(const unsigned int y, const unsigned int x) 01122 { 01123 #if __ITODEBUG 01124 if (m_dims != 2) 01125 { 01126 cv::error(cv::Exception(CV_StsAssert, "Dimension mismatch while addressing data field", "", __FILE__, __LINE__)); 01127 } 01128 else if (((int)x >= m_size[1]) || ((int)y >= m_size[0]) ) 01129 { 01130 cv::error(cv::Exception(CV_StsAssert, "Index out of bounds", "", __FILE__ , __LINE__)); 01131 } 01132 #endif 01133 return (*reinterpret_cast<cv::Mat_<_Tp>*>(m_data[0]))(y, x); 01134 } 01135 01137 01143 template<typename _Tp> inline const _Tp& at(const unsigned int z, const unsigned int y, const unsigned int x) const 01144 { 01145 #if __ITODEBUG 01146 if (m_dims != 3) 01147 { 01148 cv::error(cv::Exception(CV_StsAssert, "Dimension mismatch while addressing data field", "", __FILE__, __LINE__)); 01149 } 01150 else if (((int)x >= m_size[2]) || ((int)y >= m_size[1]) || (((int)z + m_roi[0]) >= (m_roi[0] + m_size[0]))) 01151 { 01152 cv::error(cv::Exception(CV_StsAssert, "Index out of bounds", "", __FILE__ , __LINE__)); 01153 } 01154 #endif 01155 return (*reinterpret_cast<const cv::Mat_<_Tp>*>(m_data[z + m_roi[0]]))(y, x); 01156 } 01157 01159 01165 template<typename _Tp> inline _Tp& at(const unsigned int z, const unsigned int y, const unsigned int x) 01166 { 01167 #if __ITODEBUG 01168 if (m_dims != 3) 01169 { 01170 cv::error(cv::Exception(CV_StsAssert, "Dimension mismatch while addressing data field", "", __FILE__, __LINE__)); 01171 } 01172 else if (((int)x >= m_size[2]) || ((int)y >= m_size[1]) || (((int)z + m_roi[0]) >= (m_roi[0] + m_size[0]))) 01173 { 01174 cv::error(cv::Exception(CV_StsAssert, "Index out of bounds", "", __FILE__ , __LINE__)); 01175 } 01176 #endif 01177 return (*reinterpret_cast<cv::Mat_<_Tp>*>(m_data[z + m_roi[0]]))(y, x); 01178 } 01179 01181 01186 template<typename _Tp> inline const _Tp& at(const unsigned int *idx) const //idx is in virtual order 01187 { 01188 int matNum = 0; 01189 matIdxToNum(idx, &matNum); 01190 return (*reinterpret_cast<const cv::Mat_<_Tp>*>(m_data[matNum]))(idx[m_dims - 2], idx[m_dims - 1]); 01191 } 01192 01194 01199 template<typename _Tp> inline _Tp& at(const unsigned int *idx) //idx is in virtual order 01200 { 01201 int matNum = 0; 01202 matIdxToNum(idx, &matNum); 01203 return (*reinterpret_cast<cv::Mat_<_Tp>*>(m_data[matNum]))(idx[m_dims - 2], idx[m_dims - 1]); 01204 } 01205 01206 DataObject at(const ito::Range &rowRange, const ito::Range &colRange) const; 01207 DataObject at(ito::Range *ranges) const; 01208 DataObject at(const DataObject &mask) const; 01210 01211 01217 inline uchar* rowPtr(const int matNum, const int y) 01218 { 01219 int matIndex = seekMat(matNum); 01220 return ((cv::Mat*)m_data[matIndex])->ptr(y); 01221 } 01222 01224 01230 inline const uchar* rowPtr(const int matNum, const int y) const 01231 { 01232 int matIndex = seekMat(matNum); 01233 return ((const cv::Mat*)m_data[matIndex])->ptr(y); 01234 } 01235 01237 01244 template<typename _Tp> inline _Tp* rowPtr(const int matNum, const int y) 01245 { 01246 int matIndex = seekMat(matNum); 01247 return ((cv::Mat*)m_data[matIndex])->ptr<_Tp>(y); 01248 } 01249 01251 01258 template<typename _Tp> inline const _Tp* rowPtr(const int matNum, const int y) const 01259 { 01260 int matIndex = seekMat(matNum); 01261 return ((const cv::Mat*)m_data[matIndex])->ptr<_Tp>(y); 01262 } 01263 01264 DataObject row(const int selRow) const; 01265 DataObject col(const int selCol) const; 01266 01267 DataObject toGray(const int destinationType = ito::tUInt8) const; 01268 DataObject splitColor(const char* destinationColor, const int& dtype) const; 01269 01270 // ROI 01271 DataObject & adjustROI(const int dtop, const int dbottom, const int dleft, const int dright); 01272 DataObject & adjustROI(const unsigned char dims, const int *lims); 01273 RetVal locateROI(int *wholeSizes, int *offsets) const; 01274 RetVal locateROI(int *lims) const; 01276 01277 01292 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 01293 01295 01319 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 01320 01321 template<typename T2> operator T2 (); 01323 template<typename _Tp> RetVal linspace(const _Tp start, const _Tp end, const _Tp inc, const int transposed); 01324 01325 }; 01326 01327 //template<> DATAOBJ_EXPORT RetVal ito::DataObject::linspace<ito::int8>(const ito::int8 /*start*/, const ito::int8 /*end*/, const ito::int8 /*inc*/, const int /*transposed*/); 01328 //template<> DATAOBJ_EXPORT RetVal ito::DataObject::linspace<ito::uint8>(const ito::uint8 /*start*/, const ito::uint8 /*end*/, const ito::uint8 /*inc*/, const int /*transposed*/); 01329 01330 01331 //---------------------------------------------------------------------------------------------------------------------------------- 01332 // functions for DataObject in namespace ITO, which are NOT member functions 01333 //---------------------------------------------------------------------------------------------------------------------------------- 01334 DATAOBJ_EXPORT DataObject abs(const DataObject &dObj); 01335 DATAOBJ_EXPORT DataObject arg(const DataObject &dObj); 01336 DATAOBJ_EXPORT DataObject real(const DataObject &dObj); 01337 DATAOBJ_EXPORT DataObject imag(const DataObject &dObj); 01339 DATAOBJ_EXPORT DataObject makeContinuous(const DataObject &dObj); 01341 01342 01349 template<typename _Tp> inline _Tp numberConversion(ito::tDataType fromType, const void *scalar) 01350 { 01351 _Tp retValue; 01352 01353 switch(fromType) 01354 { 01355 case ito::tUInt8: 01356 retValue = cv::saturate_cast<_Tp>(*(static_cast<const uint8*>(scalar))); 01357 break; 01358 case ito::tInt8: 01359 retValue = cv::saturate_cast<_Tp>(*(static_cast<const int8*>(scalar))); 01360 break; 01361 case ito::tUInt16: 01362 retValue = cv::saturate_cast<_Tp>(*(static_cast<const uint16*>(scalar))); 01363 break; 01364 case ito::tInt16: 01365 retValue = cv::saturate_cast<_Tp>(*(static_cast<const int16*>(scalar))); 01366 break; 01367 case ito::tUInt32: 01368 retValue = cv::saturate_cast<_Tp>(*(static_cast<const uint32*>(scalar))); 01369 break; 01370 case ito::tInt32: 01371 retValue = cv::saturate_cast<_Tp>(*(static_cast<const int32*>(scalar))); 01372 break; 01373 case ito::tFloat32: 01374 retValue = cv::saturate_cast<_Tp>(*(static_cast<const ito::float32*>(scalar))); 01375 break; 01376 case ito::tFloat64: 01377 retValue = cv::saturate_cast<_Tp>(*(static_cast<const ito::float64*>(scalar))); 01378 break; 01379 case ito::tComplex64: 01380 retValue = cv::saturate_cast<_Tp>(*(static_cast<const ito::complex64*>(scalar))); 01381 break; 01382 case ito::tComplex128: 01383 retValue = cv::saturate_cast<_Tp>(*(static_cast<const ito::complex128*>(scalar))); 01384 break; 01385 case ito::tRGBA32: 01386 retValue = cv::saturate_cast<_Tp>(*(static_cast<const ito::Rgba32*>(scalar))); 01387 break; 01388 default: 01389 cv::error(cv::Exception(CV_StsAssert, "Input value type unkown", "", __FILE__, __LINE__)); 01390 retValue = 0; 01391 } 01392 01393 return retValue; 01394 }; 01395 01397 DATAOBJ_EXPORT std::ostream& operator << (std::ostream& out, const DataObject& dObj); 01398 01400 01407 inline ito::tDataType convertCmplxTypeToRealType(ito::tDataType cmplxType) 01408 { 01409 switch(cmplxType) 01410 { 01411 case ito::tInt8: 01412 case ito::tUInt8: 01413 case ito::tInt16: 01414 case ito::tUInt16: 01415 case ito::tInt32: 01416 case ito::tUInt32: 01417 case ito::tFloat32: 01418 case ito::tFloat64: 01419 case ito::tRGBA32: 01420 return cmplxType; 01421 case ito::tComplex64: 01422 return ito::tFloat32; 01423 case ito::tComplex128: 01424 return ito::tFloat64; 01425 } 01426 01427 cv::error(cv::Exception(CV_StsAssert, "Input data type unknown", "", __FILE__, __LINE__)); 01428 return ito::tInt8; 01429 } 01430 01432 01439 inline ito::tDataType guessDataTypeFromCVMat(const cv::Mat* mat, ito::RetVal &retval) 01440 { 01441 if (mat) 01442 { 01443 switch(mat->type()) 01444 { 01445 case cv::DataType<ito::int8>::type: 01446 return ito::tInt8; 01447 case cv::DataType<ito::uint8>::type: 01448 return ito::tUInt8; 01449 case cv::DataType<ito::int16>::type: 01450 return ito::tInt16; 01451 case cv::DataType<ito::uint16>::type: 01452 return ito::tUInt16; 01453 case cv::DataType<ito::int32>::type: 01454 return ito::tInt32; 01455 case cv::DataType<ito::uint32>::type: 01456 return ito::tUInt32; 01457 case cv::DataType<ito::float32>::type: 01458 return ito::tFloat32; 01459 case cv::DataType<ito::float64>::type: 01460 return ito::tFloat64; 01461 case cv::DataType<ito::Rgba32>::type: 01462 return ito::tRGBA32; 01463 case cv::DataType<ito::complex64>::type: 01464 return ito::tComplex64; 01465 case cv::DataType<ito::complex128>::type: 01466 return ito::tComplex128; 01467 } 01468 01469 retval += ito::RetVal(ito::retError, 0, "type of cv::Mat is incompatible to ito::DataObject"); 01470 } 01471 else 01472 { 01473 retval += ito::RetVal(ito::retError, 0, "given cv::Mat is NULL."); 01474 } 01475 return ito::tInt8; 01476 } 01477 01478 01480 01488 template<typename _Tp> inline ito::tDataType getDataType(const _Tp* /*src*/) 01489 { 01490 cv::error(cv::Exception(CV_StsAssert, "Input value type unkown", "", __FILE__, __LINE__)); 01491 return ito::tInt8; 01492 } 01493 01494 template<> inline ito::tDataType getDataType(const uint8* /*src*/) { return ito::tUInt8; } 01495 template<> inline ito::tDataType getDataType(const int8* /*src*/) { return ito::tInt8; } 01496 template<> inline ito::tDataType getDataType(const uint16* /*src*/) { return ito::tUInt16; } 01497 template<> inline ito::tDataType getDataType(const int16* /*src*/) { return ito::tInt16; } 01498 template<> inline ito::tDataType getDataType(const uint32* /*src*/) { return ito::tUInt32; } 01499 template<> inline ito::tDataType getDataType(const int32* /*src*/) { return ito::tInt32; } 01500 template<> inline ito::tDataType getDataType(const float32* /*src*/) { return ito::tFloat32; } 01501 template<> inline ito::tDataType getDataType(const float64* /*src*/) { return ito::tFloat64; } 01502 template<> inline ito::tDataType getDataType(const complex64* /*src*/) { return ito::tComplex64; } 01503 template<> inline ito::tDataType getDataType(const complex128* /*src*/) { return ito::tComplex128; } 01504 template<> inline ito::tDataType getDataType(const Rgba32* /*src*/) { return ito::tRGBA32; } 01505 01506 01508 01517 template<typename _Tp> inline ito::tDataType getDataType2() 01518 { 01519 cv::error(cv::Exception(CV_StsAssert, "Input value type unkown", "", __FILE__, __LINE__)); 01520 return ito::tInt8; 01521 } 01522 01523 template<> inline ito::tDataType getDataType2<uint8*>() { return ito::tUInt8; } 01524 template<> inline ito::tDataType getDataType2<int8*>() { return ito::tInt8; } 01525 template<> inline ito::tDataType getDataType2<uint16*>() { return ito::tUInt16; } 01526 template<> inline ito::tDataType getDataType2<int16*>() { return ito::tInt16; } 01527 template<> inline ito::tDataType getDataType2<uint32*>() { return ito::tUInt32; } 01528 template<> inline ito::tDataType getDataType2<int32*>() { return ito::tInt32; } 01529 template<> inline ito::tDataType getDataType2<float32*>() { return ito::tFloat32; } 01530 template<> inline ito::tDataType getDataType2<float64*>() { return ito::tFloat64; } 01531 template<> inline ito::tDataType getDataType2<complex64*>() { return ito::tComplex64; } 01532 template<> inline ito::tDataType getDataType2<complex128*>() { return ito::tComplex128; } 01533 template<> inline ito::tDataType getDataType2<Rgba32*>() { return ito::tRGBA32; } 01534 01535 } //namespace ito 01536 01537 #endif //__DATAOBJH 01538 01539