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 std::vector<double> abcRadii, abcRadiiBackgroundInner, abcRadiiBackgroundOuter;
35 abcRadii.emplace_back(root["radius0"].asDouble());
36 abcRadii.emplace_back(root["radius1"].asDouble());
37 abcRadii.emplace_back(root["radius2"].asDouble());
38 abcRadiiBackgroundInner.emplace_back(root["background_inner_radius0"].asDouble());
39 abcRadiiBackgroundInner.emplace_back(root["background_inner_radius1"].asDouble());
40 abcRadiiBackgroundInner.emplace_back(root["background_inner_radius2"].asDouble());
41 abcRadiiBackgroundOuter.emplace_back(root["background_outer_radius0"].asDouble());
42 abcRadiiBackgroundOuter.emplace_back(root["background_outer_radius1"].asDouble());
43 abcRadiiBackgroundOuter.emplace_back(root["background_outer_radius2"].asDouble());
44
45 std::vector<V3D> directions(3);
46 directions[0].fromString(root["direction0"].asString());
47 directions[1].fromString(root["direction1"].asString());
48 directions[2].fromString(root["direction2"].asString());
49
50 product = new PeakShapeEllipsoid(directions, abcRadii, abcRadiiBackgroundInner, abcRadiiBackgroundOuter, frame,
51 algorithmName, algorithmVersion);
52
53 } else {
54 if (m_successor) {
55 product = m_successor->create(source);
56 } else {
57 throw std::invalid_argument("PeakShapeSphericalFactory:: No successor "
58 "factory able to process : " +
59 source);
60 }
61 }
62
63 } else {
64
65 throw std::invalid_argument("PeakShapeSphericalFactory:: Source JSON for "
66 "the peak shape is not valid: " +
67 source);
68 }
69 return product;
70}
71
76void PeakShapeEllipsoidFactory::setSuccessor(std::shared_ptr<const PeakShapeFactory> successorFactory) {
77 this->m_successor = successorFactory;
78}
79
80} // 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.
static const std::string ellipsoidShapeName()
PeakShape : Abstract type to describes the shape of a peak.
Definition: PeakShape.h:20
SpecialCoordinateSystem
Special coordinate systems for Q3D.