forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CoordTransformAffineParser.cpp
74 lines (65 loc) · 3.32 KB
/
CoordTransformAffineParser.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
// 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/CoordTransformAffineParser.h"
#include "MantidAPI/CoordTransform.h"
#include "MantidAPI/SingleValueParameterParser.h"
#include "MantidDataObjects/AffineMatrixParameterParser.h"
#include "MantidDataObjects/CoordTransformAffine.h"
#include <Poco/DOM/Element.h>
#include <Poco/DOM/NodeList.h>
namespace Mantid::DataObjects {
/// Constructor
CoordTransformAffineParser::CoordTransformAffineParser() = default;
//-----------------------------------------------------------------------------------------------
/**
Create the transform object.
@param coordTransElement : xml coordinate transform element
@return a fully constructed coordinate transform object.
*/
Mantid::API::CoordTransform *CoordTransformAffineParser::createTransform(Poco::XML::Element *coordTransElement) const {
using InDimParameterParser = Mantid::API::SingleValueParameterParser<Mantid::API::InDimParameter>;
using OutDimParameterParser = Mantid::API::SingleValueParameterParser<Mantid::API::OutDimParameter>;
using namespace Poco::XML;
if ("CoordTransform" != coordTransElement->localName()) {
std::string message = "This is not a coordinate transform element: " + coordTransElement->localName();
throw std::invalid_argument(message);
}
if ("CoordTransformAffine" != coordTransElement->getChildElement("Type")->innerText()) {
// Delegate
if (!m_successor) {
throw std::runtime_error("CoordTransformAffineParser has no successor parser.");
}
return m_successor->createTransform(coordTransElement);
}
Element *paramListElement = coordTransElement->getChildElement("ParameterList");
Poco::AutoPtr<Poco::XML::NodeList> parameters = paramListElement->getElementsByTagName("Parameter");
// Add input dimension parameter.
InDimParameterParser inDimParser;
auto *parameter = dynamic_cast<Poco::XML::Element *>(parameters->item(0));
std::shared_ptr<Mantid::API::InDimParameter> inDim(inDimParser.createWithoutDelegation(parameter));
// Add output dimension parameter.
OutDimParameterParser outDimParser;
parameter = dynamic_cast<Poco::XML::Element *>(parameters->item(1));
std::shared_ptr<Mantid::API::OutDimParameter> outDim(outDimParser.createWithoutDelegation(parameter));
// Add affine matrix parameter.
AffineMatrixParameterParser affineMatrixDimParser;
parameter = dynamic_cast<Poco::XML::Element *>(parameters->item(2));
std::shared_ptr<AffineMatrixParameter> affineMatrix(affineMatrixDimParser.createParameter(parameter));
// Generate the coordinate transform with the matrix and return.
auto transform = new CoordTransformAffine(inDim->getValue(), outDim->getValue());
transform->setMatrix(affineMatrix->getAffineMatrix());
return transform;
}
//-----------------------------------------------------------------------------------------------
/**
Set the successor parser.
@param other : another parser to use if this one fails.
*/
void CoordTransformAffineParser::setSuccessor(CoordTransformAffineParser *other) {
m_successor = SuccessorType_sptr(other);
}
} // namespace Mantid::DataObjects