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 PCLFUNCTIONS_IMPL_H 00029 #define PCLFUNCTIONS_IMPL_H 00030 00031 #include "../../common/sharedStructures.h" 00032 00033 #include "../../common/typeDefs.h" 00034 #include "../../DataObject/dataobj.h" 00035 00036 namespace ito 00037 { 00038 00039 class DataObject; //forward declaration 00040 00041 namespace pclHelper 00042 { 00043 template<typename _Tp, int _Rows, int _Cols> ito::RetVal eigenMatrixToDataObj(const Eigen::Matrix<_Tp,_Rows,_Cols> &mat, DataObject &out) 00044 { 00045 ito::RetVal retval; 00046 ito::tDataType type; 00047 00048 try 00049 { 00050 type = ito::getDataType2<_Tp*>(); 00051 } 00052 catch(...) 00053 { 00054 retval += ito::RetVal(ito::retError, 0, "eigen matrix type cannot be converted to dataObject"); 00055 } 00056 00057 if(!retval.containsError()) 00058 { 00059 const _Tp *data = mat.data(); 00060 _Tp *rowPtr = NULL; 00061 size_t c = 0; 00062 size_t rows = mat.rows(); 00063 size_t cols = mat.cols(); 00064 out = ito::DataObject(rows, cols, type); 00065 00066 if(mat.Options & Eigen::RowMajor) 00067 { 00068 for(size_t m = 0 ; m < rows ; m++) 00069 { 00070 rowPtr = (_Tp*)out.rowPtr(0,m); 00071 for(size_t n = 0 ; n < cols ; n++) 00072 { 00073 rowPtr[n] = data[c++]; 00074 } 00075 } 00076 } 00077 else 00078 { 00079 for(size_t m = 0 ; m < rows ; m++) 00080 { 00081 rowPtr = (_Tp*)out.rowPtr(0,m); 00082 for(size_t n = 0 ; n < cols ; n++) 00083 { 00084 rowPtr[n] = data[m + n * rows]; 00085 } 00086 } 00087 } 00088 00089 } 00090 00091 return retval; 00092 } 00093 00094 00095 template<typename _Tp, int _Rows, int _Cols> ito::RetVal dataObjToEigenMatrix(const DataObject &dataobj, Eigen::Matrix<_Tp,_Rows,_Cols> &mat) 00096 { 00097 ito::RetVal retval; 00098 ito::tDataType type; 00099 00100 try 00101 { 00102 type = ito::getDataType2<_Tp*>(); 00103 } 00104 catch(...) 00105 { 00106 retval += ito::RetVal(ito::retError, 0, "eigen matrix type is unknown for dataObject"); 00107 } 00108 00109 if(!retval.containsError()) 00110 { 00111 ito::DataObject dobj; 00112 retval += dataobj.convertTo(dobj, type); 00113 } 00114 00115 if (dataobj.getDims() != 2 || dataobj.getSize(0) != _Rows || dataobj.getSize(1) != _Cols) 00116 { 00117 retval += ito::RetVal(ito::retError, 0, "size of dataobj does not fit to requested Eigen::Matrix size"); 00118 } 00119 00120 if (!retval.containsError()) 00121 { 00122 _Tp *data = mat.data(); 00123 const _Tp *rowPtr = NULL; 00124 size_t c = 0; 00125 size_t rows = mat.rows(); 00126 size_t cols = mat.cols(); 00127 00128 if(mat.Options & Eigen::RowMajor) 00129 { 00130 for(size_t m = 0 ; m < rows ; m++) 00131 { 00132 rowPtr = (_Tp*)dataobj.rowPtr(0,m); 00133 for(size_t n = 0 ; n < cols ; n++) 00134 { 00135 data[c++] = rowPtr[n]; 00136 } 00137 } 00138 } 00139 else 00140 { 00141 for(size_t m = 0 ; m < rows ; m++) 00142 { 00143 rowPtr = (_Tp*)dataobj.rowPtr(0,m); 00144 for(size_t n = 0 ; n < cols ; n++) 00145 { 00146 data[m + n * rows] = rowPtr[n]; 00147 } 00148 } 00149 } 00150 00151 } 00152 00153 return retval; 00154 } 00155 00156 } //end namespace pclHelper 00157 00158 } //end namespace ito 00159 00160 #endif