Mantid
Loading...
Searching...
No Matches
PeakShapeEllipsoidFactory.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 +
9#include "MantidJson/Json.h"
11
12#include <json/json.h>
13#include <stdexcept>
14
15using namespace Mantid::Kernel;
16
17namespace Mantid::DataObjects {
18
25 Json::Value root;
26 Mantid::Geometry::PeakShape *product = nullptr;
27 if (Mantid::JsonHelpers::parse(source, &root)) {
28 const std::string shape = root["shape"].asString();
30
31 const std::string algorithmName(root["algorithm_name"].asString());
32 const int algorithmVersion(root["algorithm_version"].asInt());
33 const auto frame(static_cast<SpecialCoordinateSystem>(root["frame"].asInt()));
34 PeakEllipsoidExtent abcRadii{root["radius0"].asDouble(), root["radius1"].asDouble(), root["radius2"].asDouble()};
35 PeakEllipsoidExtent abcRadiiBackgroundInner{root["background_inner_radius0"].asDouble(),
36 root["background_inner_radius1"].asDouble(),
37 root["background_inner_radius2"].asDouble()};
38 PeakEllipsoidExtent abcRadiiBackgroundOuter{root["background_outer_radius0"].asDouble(),
39 root["background_outer_radius1"].asDouble(),
40 root["background_outer_radius2"].asDouble()};
41 PeakEllipsoidFrame directions;
42 directions[0].fromString(root["direction0"].asString());
43 directions[1].fromString(root["direction1"].asString());
44 directions[2].fromString(root["direction2"].asString());
45
46 product = new PeakShapeEllipsoid(directions, abcRadii, abcRadiiBackgroundInner, abcRadiiBackgroundOuter, frame,
47 algorithmName, algorithmVersion);
48
49 } else {
50 if (m_successor) {
51 product = m_successor->create(source);
52 } else {
53 throw std::invalid_argument("PeakShapeSphericalFactory:: No successor "
54 "factory able to process : " +
55 source);
56 }
57 }
58
59 } else {
60
61 throw std::invalid_argument("PeakShapeSphericalFactory:: Source JSON for "
62 "the peak shape is not valid: " +
63 source);
64 }
65 return product;
66}
67
72void PeakShapeEllipsoidFactory::setSuccessor(std::shared_ptr<const PeakShapeFactory> successorFactory) {
73 this->m_successor = successorFactory;
74}
75
76} // namespace Mantid::DataObjects
void setSuccessor(std::shared_ptr< const PeakShapeFactory > successorFactory) override
Set successor.
Mantid::Geometry::PeakShape * create(const std::string &source) const override
Create the PeakShape.
PeakShapeFactory_const_sptr m_successor
Successor factory.
PeakShapeEllipsoid : PeakShape representing a 3D ellipsoid.
PeakShape : Abstract type to describes the shape of a peak.
Definition PeakShape.h:20
std::array< Kernel::V3D, PEAK_ELLIPSOID_DIMS > PeakEllipsoidFrame
std::array< double, PEAK_ELLIPSOID_DIMS > PeakEllipsoidExtent
SpecialCoordinateSystem
Special coordinate systems for Q3D.