forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PeakShapeEllipsoidFactory.cpp
80 lines (68 loc) · 3.23 KB
/
PeakShapeEllipsoidFactory.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
77
78
79
80
// 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/PeakShapeEllipsoidFactory.h"
#include "MantidDataObjects/PeakShapeEllipsoid.h"
#include "MantidJson/Json.h"
#include "MantidKernel/SpecialCoordinateSystem.h"
#include <json/json.h>
#include <stdexcept>
using namespace Mantid::Kernel;
namespace Mantid::DataObjects {
/**
* @brief Create the PeakShape
* @param source : source JSON
* @return PeakShape via this factory or it's successors
*/
Mantid::Geometry::PeakShape *PeakShapeEllipsoidFactory::create(const std::string &source) const {
Json::Value root;
Mantid::Geometry::PeakShape *product = nullptr;
if (Mantid::JsonHelpers::parse(source, &root)) {
const std::string shape = root["shape"].asString();
if (shape == PeakShapeEllipsoid::ellipsoidShapeName()) {
const std::string algorithmName(root["algorithm_name"].asString());
const int algorithmVersion(root["algorithm_version"].asInt());
const auto frame(static_cast<SpecialCoordinateSystem>(root["frame"].asInt()));
std::vector<double> abcRadii, abcRadiiBackgroundInner, abcRadiiBackgroundOuter;
abcRadii.emplace_back(root["radius0"].asDouble());
abcRadii.emplace_back(root["radius1"].asDouble());
abcRadii.emplace_back(root["radius2"].asDouble());
abcRadiiBackgroundInner.emplace_back(root["background_inner_radius0"].asDouble());
abcRadiiBackgroundInner.emplace_back(root["background_inner_radius1"].asDouble());
abcRadiiBackgroundInner.emplace_back(root["background_inner_radius2"].asDouble());
abcRadiiBackgroundOuter.emplace_back(root["background_outer_radius0"].asDouble());
abcRadiiBackgroundOuter.emplace_back(root["background_outer_radius1"].asDouble());
abcRadiiBackgroundOuter.emplace_back(root["background_outer_radius2"].asDouble());
std::vector<V3D> directions(3);
directions[0].fromString(root["direction0"].asString());
directions[1].fromString(root["direction1"].asString());
directions[2].fromString(root["direction2"].asString());
product = new PeakShapeEllipsoid(directions, abcRadii, abcRadiiBackgroundInner, abcRadiiBackgroundOuter, frame,
algorithmName, algorithmVersion);
} else {
if (m_successor) {
product = m_successor->create(source);
} else {
throw std::invalid_argument("PeakShapeSphericalFactory:: No successor "
"factory able to process : " +
source);
}
}
} else {
throw std::invalid_argument("PeakShapeSphericalFactory:: Source JSON for "
"the peak shape is not valid: " +
source);
}
return product;
}
/**
* @brief Set successor
* @param successorFactory : successor
*/
void PeakShapeEllipsoidFactory::setSuccessor(std::shared_ptr<const PeakShapeFactory> successorFactory) {
this->m_successor = successorFactory;
}
} // namespace Mantid::DataObjects