itom
Loading...
Searching...
No Matches
pclFunctionsImpl.h
1/* ********************************************************************
2 itom software
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2020, Institut für Technische Optik (ITO),
5 Universität Stuttgart, Germany
6
7 This file is part of itom and its software development toolkit (SDK).
8
9 itom is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Library General Public Licence as published by
11 the Free Software Foundation; either version 2 of the Licence, or (at
12 your option) any later version.
13
14 In addition, as a special exception, the Institut für Technische
15 Optik (ITO) gives you certain additional rights.
16 These rights are described in the ITO LGPL Exception version 1.0,
17 which can be found in the file LGPL_EXCEPTION.txt in this package.
18
19 itom is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
22 General Public Licence for more details.
23
24 You should have received a copy of the GNU Library General Public License
25 along with itom. If not, see <http://www.gnu.org/licenses/>.
26*********************************************************************** */
27
28#ifndef PCLFUNCTIONS_IMPL_H
29#define PCLFUNCTIONS_IMPL_H
30
31#include "../../common/sharedStructures.h"
32
33#include "../../common/typeDefs.h"
34#include "../../DataObject/dataobj.h"
35
36namespace ito
37{
38
39class DataObject; //forward declaration
40
41namespace pclHelper
42{
43 template<typename _Tp, int _Rows, int _Cols> ito::RetVal eigenMatrixToDataObj(const Eigen::Matrix<_Tp,_Rows,_Cols> &mat, DataObject &out)
44 {
45 ito::RetVal retval;
46 ito::tDataType type;
47
48 try
49 {
51 }
52 catch(...)
53 {
54 retval += ito::RetVal(ito::retError, 0, "eigen matrix type cannot be converted to dataObject");
55 }
56
57 if(!retval.containsError())
58 {
59 const _Tp *data = mat.data();
60 _Tp *rowPtr = NULL;
61 size_t c = 0;
62 size_t rows = mat.rows();
63 size_t cols = mat.cols();
64 out = ito::DataObject(rows, cols, type);
65
66 if(mat.Options & Eigen::RowMajor)
67 {
68 for(size_t m = 0 ; m < rows ; m++)
69 {
70 rowPtr = (_Tp*)out.rowPtr(0,m);
71 for(size_t n = 0 ; n < cols ; n++)
72 {
73 rowPtr[n] = data[c++];
74 }
75 }
76 }
77 else
78 {
79 for(size_t m = 0 ; m < rows ; m++)
80 {
81 rowPtr = (_Tp*)out.rowPtr(0,m);
82 for(size_t n = 0 ; n < cols ; n++)
83 {
84 rowPtr[n] = data[m + n * rows];
85 }
86 }
87 }
88
89 }
90
91 return retval;
92 }
93
94
95 template<typename _Tp, int _Rows, int _Cols> ito::RetVal dataObjToEigenMatrix(const DataObject &dataobj, Eigen::Matrix<_Tp,_Rows,_Cols> &mat)
96 {
97 ito::RetVal retval;
98 ito::tDataType type;
99
100 try
101 {
103 }
104 catch(...)
105 {
106 retval += ito::RetVal(ito::retError, 0, "eigen matrix type is unknown for dataObject");
107 }
108
109 if(!retval.containsError())
110 {
111 ito::DataObject dobj;
112 retval += dataobj.convertTo(dobj, type);
113 }
114
115 if (dataobj.getDims() != 2 || dataobj.getSize(0) != _Rows || dataobj.getSize(1) != _Cols)
116 {
117 retval += ito::RetVal(ito::retError, 0, "size of dataobj does not fit to requested Eigen::Matrix size");
118 }
119
120 if (!retval.containsError())
121 {
122 _Tp *data = mat.data();
123 const _Tp *rowPtr = NULL;
124 size_t c = 0;
125 size_t rows = mat.rows();
126 size_t cols = mat.cols();
127
128 if(mat.Options & Eigen::RowMajor)
129 {
130 for(size_t m = 0 ; m < rows ; m++)
131 {
132 rowPtr = (_Tp*)dataobj.rowPtr(0,m);
133 for(size_t n = 0 ; n < cols ; n++)
134 {
135 data[c++] = rowPtr[n];
136 }
137 }
138 }
139 else
140 {
141 for(size_t m = 0 ; m < rows ; m++)
142 {
143 rowPtr = (_Tp*)dataobj.rowPtr(0,m);
144 for(size_t n = 0 ; n < cols ; n++)
145 {
146 data[m + n * rows] = rowPtr[n];
147 }
148 }
149 }
150
151 }
152
153 return retval;
154 }
155
156} //end namespace pclHelper
157
158} //end namespace ito
159
160#endif
dataObject contains a n-dimensional matrix
Definition dataobj.h:591
Class for managing status values (like errors or warning)
Definition retVal.h:54
int containsError() const
Definition retVal.h:166
Definition apiFunctionsGraph.cpp:40
ito::tDataType getDataType2()
method which returns the value of enumeration ito::tDataType, which corresponds to the template param...
Definition dataobj.h:1703
tDataType
Definition typeDefs.h:88
@ retError
Definition typeDefs.h:60