Mantid
Loading...
Searching...
No Matches
CoordTransformAffineParser.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
12
13#include <Poco/DOM/Element.h>
14#include <Poco/DOM/NodeList.h>
15
16namespace Mantid::DataObjects {
19
20//-----------------------------------------------------------------------------------------------
26Mantid::API::CoordTransform *CoordTransformAffineParser::createTransform(Poco::XML::Element *coordTransElement) const {
29 using namespace Poco::XML;
30 if ("CoordTransform" != coordTransElement->localName()) {
31 std::string message = "This is not a coordinate transform element: " + coordTransElement->localName();
32 throw std::invalid_argument(message);
33 }
34 if ("CoordTransformAffine" != coordTransElement->getChildElement("Type")->innerText()) {
35 // Delegate
36 if (!m_successor) {
37 throw std::runtime_error("CoordTransformAffineParser has no successor parser.");
38 }
39 return m_successor->createTransform(coordTransElement);
40 }
41
42 Element *paramListElement = coordTransElement->getChildElement("ParameterList");
43 Poco::AutoPtr<Poco::XML::NodeList> parameters = paramListElement->getElementsByTagName("Parameter");
44
45 // Add input dimension parameter.
46 InDimParameterParser inDimParser;
47 auto *parameter = dynamic_cast<Poco::XML::Element *>(parameters->item(0));
48 std::shared_ptr<Mantid::API::InDimParameter> inDim(inDimParser.createWithoutDelegation(parameter));
49
50 // Add output dimension parameter.
51 OutDimParameterParser outDimParser;
52 parameter = dynamic_cast<Poco::XML::Element *>(parameters->item(1));
53 std::shared_ptr<Mantid::API::OutDimParameter> outDim(outDimParser.createWithoutDelegation(parameter));
54
55 // Add affine matrix parameter.
56 AffineMatrixParameterParser affineMatrixDimParser;
57 parameter = dynamic_cast<Poco::XML::Element *>(parameters->item(2));
58 std::shared_ptr<AffineMatrixParameter> affineMatrix(affineMatrixDimParser.createParameter(parameter));
59
60 // Generate the coordinate transform with the matrix and return.
61 auto transform = new CoordTransformAffine(inDim->getValue(), outDim->getValue());
62 transform->setMatrix(affineMatrix->getAffineMatrix());
63 return transform;
64}
65
66//-----------------------------------------------------------------------------------------------
73}
74} // namespace Mantid::DataObjects
Unique SingleValueParameter Declaration for InputNDimensions.
XML Parser for single value parameter types.
Parser for a parameter of type affinematrixparameter.
AffineMatrixParameter * createParameter(Poco::XML::Element *parameterElement) override
Creates the parameter by reading the xml given.
A parser for processing coordinate transform xml.
virtual void setSuccessor(CoordTransformAffineParser *other)
Set the successor parser.
std::shared_ptr< CoordTransformAffineParser > SuccessorType_sptr
successor parser shared ptr typedef
virtual Mantid::API::CoordTransform * createTransform(Poco::XML::Element *coordTransElement) const
Create the transform object.
Generic class to transform from M input dimensions to N output dimensions.