forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AffineMatrixParameterParser.cpp
76 lines (61 loc) · 2.69 KB
/
AffineMatrixParameterParser.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#include "MantidDataObjects/AffineMatrixParameterParser.h"
#include <boost/algorithm/string.hpp>
namespace Mantid::DataObjects {
AffineMatrixParameterParser::AffineMatrixParameterParser() {}
//----------------------------------------------------------------------------------------------
AffineMatrixParameter *AffineMatrixParameterParser::createParameter(Poco::XML::Element *parameterElement) {
std::string typeName = parameterElement->getChildElement("Type")->innerText();
if (AffineMatrixParameter::parameterName() != typeName) {
throw std::runtime_error(std::string("AffineMatrixParameterParser cannot parse parameter of type: " + typeName));
} else {
// Convenience typedefs
using VecStrings = std::vector<std::string>;
using VecDoubles = std::vector<coord_t>;
std::string sParameterValue = parameterElement->getChildElement("Value")->innerText();
VecStrings vecStrRows;
VecStrings vecStrCols;
boost::split(vecStrRows, sParameterValue, boost::is_any_of(";"));
size_t nRows = vecStrRows.size();
auto row_it = vecStrRows.begin();
VecStrings::iterator col_it;
size_t nCols = 0;
VecDoubles elements;
// Process each row and column and extract each element as a double.
while (row_it != vecStrRows.end()) {
boost::split(vecStrCols, *row_it, boost::is_any_of(","));
nCols = vecStrCols.size();
col_it = vecStrCols.begin();
while (col_it != vecStrCols.end()) {
coord_t val = static_cast<coord_t>(std::stof(col_it->c_str()));
elements.emplace_back(val);
++col_it;
}
++row_it;
}
// Create the Matrix.
AffineMatrixType m(nRows, nCols);
size_t count = 0;
for (size_t i = 0; i < nRows; i++) {
for (size_t j = 0; j < nCols; j++) {
m[i][j] = elements[count];
count++;
}
}
// Create the parameter and set the matrix.
auto parameter = new AffineMatrixParameter(nRows - 1, nCols - 1);
parameter->setMatrix(m);
// Now return the fully constructed parameter.
return parameter;
}
}
//----------------------------------------------------------------------------------------------
void AffineMatrixParameterParser::setSuccessorParser(Mantid::API::ImplicitFunctionParameterParser * /*paramParser*/) {
throw std::runtime_error("Cannot set a successor parser on a AffineMatrixParameterParser");
}
} // namespace Mantid::DataObjects