-
Notifications
You must be signed in to change notification settings - Fork 122
/
PeakShapeSpherical.cpp
142 lines (127 loc) · 4.62 KB
/
PeakShapeSpherical.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include "MantidDataObjects/PeakShapeSpherical.h"
#include <stdexcept>
#include <jsoncpp/json/json.h>
namespace Mantid {
namespace DataObjects {
/**
* @brief Constructor
* @param peakRadius : Peak radius
* @param frame : Coordinate frame used for the integration
* @param algorithmName : Algorithm name used for the integration
* @param algorithmVersion : Algorithm version used for the integration
*/
PeakShapeSpherical::PeakShapeSpherical(const double &peakRadius,
API::SpecialCoordinateSystem frame,
std::string algorithmName,
int algorithmVersion)
: PeakShapeBase(frame, algorithmName, algorithmVersion),
m_radius(peakRadius) {}
/**
* @brief PeakShapeSpherical::PeakShapeSpherical
* @param peakRadius : Peak radius
* @param peakInnerRadius : Peak inner radius
* @param peakOuterRadius : Peak outer radius
* @param frame : Coordinate frame used for the integration
* @param algorithmName : Algorithm name
* @param algorithmVersion : Algorithm version
*/
PeakShapeSpherical::PeakShapeSpherical(const double &peakRadius,
const double &peakInnerRadius,
const double &peakOuterRadius,
API::SpecialCoordinateSystem frame,
std::string algorithmName,
int algorithmVersion)
: PeakShapeBase(frame, algorithmName, algorithmVersion),
m_radius(peakRadius), m_backgroundInnerRadius(peakInnerRadius),
m_backgroundOuterRadius(peakOuterRadius) {
if (peakRadius == m_backgroundInnerRadius) {
m_backgroundInnerRadius.reset();
}
if (peakRadius == m_backgroundOuterRadius) {
m_backgroundOuterRadius.reset();
}
}
//----------------------------------------------------------------------------------------------
/** Destructor
*/
PeakShapeSpherical::~PeakShapeSpherical() {}
/**
* @brief Copy constructor
* @param other : source of the copy
*/
PeakShapeSpherical::PeakShapeSpherical(const PeakShapeSpherical &other)
: PeakShapeBase(other), m_radius(other.radius()),
m_backgroundOuterRadius(other.backgroundOuterRadius()),
m_backgroundInnerRadius(other.backgroundInnerRadius()) {}
/**
* @brief Assignment operator
* @param other : source of the assignment
* @return Ref to assigned object.
*/
PeakShapeSpherical &PeakShapeSpherical::
operator=(const PeakShapeSpherical &other) {
if (this != &other) {
PeakShapeBase::operator=(other);
m_radius = other.radius();
m_backgroundOuterRadius = other.backgroundOuterRadius();
m_backgroundInnerRadius = other.backgroundInnerRadius();
}
return *this;
}
/**
* @brief Serialize to JSON object
* @return JSON object as std::string
*/
std::string PeakShapeSpherical::toJSON() const {
Json::Value root;
PeakShapeBase::buildCommon(root);
root["radius"] = Json::Value(m_radius);
// Check that there is an inner radius before writing
if (m_backgroundInnerRadius.is_initialized()) {
root["background_outer_radius"] =
Json::Value(m_backgroundOuterRadius.get());
}
// Check that there is an outer radius before writing
if (m_backgroundOuterRadius.is_initialized()) {
root["background_inner_radius"] =
Json::Value(m_backgroundInnerRadius.get());
}
Json::StyledWriter writer;
return writer.write(root);
}
/**
* @brief Clone object as deep copy
* @return pointer to new object
*/
PeakShapeSpherical *PeakShapeSpherical::clone() const {
return new PeakShapeSpherical(*this);
}
std::string PeakShapeSpherical::shapeName() const { return "spherical"; }
bool PeakShapeSpherical::operator==(const PeakShapeSpherical &other) const {
return PeakShapeBase::operator==(other) && other.radius() == this->radius() &&
other.backgroundInnerRadius() == this->backgroundInnerRadius() &&
other.backgroundOuterRadius() == this->backgroundOuterRadius();
}
/**
* @brief Get radius of sphere
* @return radius
*/
double PeakShapeSpherical::radius() const { return m_radius; }
/**
* @brief Get the background outer radius. The outer radius may not be set, so
* this is optional.
* @return boost optional outer radius
*/
boost::optional<double> PeakShapeSpherical::backgroundOuterRadius() const {
return m_backgroundOuterRadius;
}
/**
* @brief Get the background inner radius. The inner radius may not be set, so
* this is optional.
* @return boost optional inner radius.
*/
boost::optional<double> PeakShapeSpherical::backgroundInnerRadius() const {
return m_backgroundInnerRadius;
}
} // namespace DataObjects
} // namespace Mantid