Mantid
Loading...
Searching...
No Matches
PeakShapeEllipsoid.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 +
8#include "MantidJson/Json.h"
10#include <json/json.h>
11
12#include <utility>
13
14namespace Mantid::DataObjects {
15
16PeakShapeEllipsoid::PeakShapeEllipsoid(const std::vector<Kernel::V3D> &directions, const std::vector<double> &abcRadii,
17 const std::vector<double> &abcRadiiBackgroundInner,
18 const std::vector<double> &abcRadiiBackgroundOuter,
19 Kernel::SpecialCoordinateSystem frame, std::string algorithmName,
20 int algorithmVersion, const Kernel::V3D &translation)
21 : PeakShapeBase(frame, std::move(algorithmName), algorithmVersion), m_directions(directions), m_abc_radii(abcRadii),
22 m_abc_radiiBackgroundInner(abcRadiiBackgroundInner), m_abc_radiiBackgroundOuter(abcRadiiBackgroundOuter),
23 m_translation(translation) {
24
25 if (directions.size() != 3) {
26 throw std::invalid_argument("directions must be of size 3");
27 }
28 if (abcRadii.size() != 3) {
29 throw std::invalid_argument("radii must be of size 3");
30 }
31 if (abcRadiiBackgroundInner.size() != 3) {
32 throw std::invalid_argument("radii inner must be of size 3");
33 }
34 if (abcRadiiBackgroundOuter.size() != 3) {
35 throw std::invalid_argument("radii outer must be of size 3");
36 }
37}
38
40 return PeakShapeBase::operator==(other) && other.directions() == this->directions() &&
41 other.abcRadii() == this->abcRadii() && other.abcRadiiBackgroundInner() == this->abcRadiiBackgroundInner() &&
43 other.translation() == this->translation();
44}
45
46const std::vector<double> &PeakShapeEllipsoid::abcRadii() const { return m_abc_radii; }
47
48const std::vector<double> &PeakShapeEllipsoid::abcRadiiBackgroundInner() const { return m_abc_radiiBackgroundInner; }
49
50const std::vector<double> &PeakShapeEllipsoid::abcRadiiBackgroundOuter() const { return m_abc_radiiBackgroundOuter; }
51
52const std::vector<Kernel::V3D> &PeakShapeEllipsoid::directions() const { return m_directions; }
53
55
56std::vector<Kernel::V3D>
58
59 if ((invertedGoniometerMatrix.numCols() != m_directions.size()) ||
60 (invertedGoniometerMatrix.numRows() != m_directions.size())) {
61 throw std::invalid_argument("The inverted goniometer matrix is not "
62 "compatible with the direction vector");
63 }
64
65 std::vector<Kernel::V3D> directionsInFrame;
66 directionsInFrame.reserve(m_directions.size());
67 std::transform(m_directions.cbegin(), m_directions.cend(), std::back_inserter(directionsInFrame),
68 [&invertedGoniometerMatrix](const auto &direction) { return invertedGoniometerMatrix * direction; });
69 return directionsInFrame;
70}
71
72std::string PeakShapeEllipsoid::toJSON() const {
73 Json::Value root;
75 root["radius0"] = Json::Value(m_abc_radii[0]);
76 root["radius1"] = Json::Value(m_abc_radii[1]);
77 root["radius2"] = Json::Value(m_abc_radii[2]);
78
79 root["background_inner_radius0"] = Json::Value(m_abc_radiiBackgroundInner[0]);
80 root["background_inner_radius1"] = Json::Value(m_abc_radiiBackgroundInner[1]);
81 root["background_inner_radius2"] = Json::Value(m_abc_radiiBackgroundInner[2]);
82
83 root["background_outer_radius0"] = Json::Value(m_abc_radiiBackgroundOuter[0]);
84 root["background_outer_radius1"] = Json::Value(m_abc_radiiBackgroundOuter[1]);
85 root["background_outer_radius2"] = Json::Value(m_abc_radiiBackgroundOuter[2]);
86
87 root["direction0"] = m_directions[0].toString();
88 root["direction1"] = m_directions[1].toString();
89 root["direction2"] = m_directions[2].toString();
90
91 root["translation0"] = Json::Value(m_translation[0]);
92 root["translation1"] = Json::Value(m_translation[1]);
93 root["translation2"] = Json::Value(m_translation[2]);
94
95 return Mantid::JsonHelpers::jsonToString(root);
96}
97
99
101
102boost::optional<double> PeakShapeEllipsoid::radius(RadiusType type) const {
103 std::vector<double>::const_iterator it;
104 switch (type) {
105 case (RadiusType::Radius):
106 it = std::max_element(m_abc_radii.cbegin(), m_abc_radii.cend());
107 break;
109 it = std::max_element(m_abc_radiiBackgroundOuter.cbegin(), m_abc_radiiBackgroundOuter.cend());
110 break;
112 it = std::max_element(m_abc_radiiBackgroundInner.cbegin(), m_abc_radiiBackgroundInner.cend());
113 break;
114 }
115 return boost::optional<double>{*it};
116}
117
118const std::string PeakShapeEllipsoid::ellipsoidShapeName() { return "ellipsoid"; }
119
120} // namespace Mantid::DataObjects
PeakShapeBase : Base class for concrete PeakShapes containing common code.
Definition: PeakShapeBase.h:26
void buildCommon(Json::Value &root) const
Build common parts of outgoing JSON serialization.
bool operator==(const PeakShapeBase &other) const
Equals operator.
PeakShapeEllipsoid : PeakShape representing a 3D ellipsoid.
std::string toJSON() const override
PeakShape interface.
Mantid::Kernel::V3D m_translation
translation of center
PeakShapeEllipsoid(const std::vector< Mantid::Kernel::V3D > &directions, const std::vector< double > &abcRadii, const std::vector< double > &abcRadiiBackgroundInner, const std::vector< double > &abcRadiiBackgroundOuter, Kernel::SpecialCoordinateSystem frame, std::string algorithmName=std::string(), int algorithmVersion=-1, const Mantid::Kernel::V3D &translation={0.0, 0.0, 0.0})
Constructor.
const Kernel::V3D & translation() const
Get translation of center.
std::vector< Mantid::Kernel::V3D > m_directions
principle axis
const std::vector< Mantid::Kernel::V3D > & directions() const
Get ellipsoid directions.
bool operator==(const PeakShapeEllipsoid &other) const
Equals operator.
std::vector< double > m_abc_radiiBackgroundInner
inner radii
static const std::string ellipsoidShapeName()
boost::optional< double > radius(RadiusType type=RadiusType::Radius) const override
PeakBase interface.
PeakShapeEllipsoid * clone() const override
Clone ellipsoid.
const std::vector< double > & abcRadiiBackgroundOuter() const
Get background outer radii.
std::vector< double > m_abc_radii
radii
const std::vector< double > & abcRadii() const
Get radii.
std::vector< double > m_abc_radiiBackgroundOuter
outer radii
std::string shapeName() const override
Get the peak shape.
const std::vector< double > & abcRadiiBackgroundInner() const
Get background inner radii.
std::vector< Kernel::V3D > getDirectionInSpecificFrame(Kernel::Matrix< double > &invertedGoniometerMatrix) const
Get ellipsoid directions in a specified frame.
RadiusType
For selecting different radius types.
Definition: PeakShape.h:35
Numerical Matrix class.
Definition: Matrix.h:42
size_t numRows() const
Return the number of rows in the matrix.
Definition: Matrix.h:144
size_t numCols() const
Return the number of columns in the matrix.
Definition: Matrix.h:147
Class for 3D vectors.
Definition: V3D.h:34
SpecialCoordinateSystem
Special coordinate systems for Q3D.
STL namespace.