Mantid
Loading...
Searching...
No Matches
PeaksInRegion.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 +
11
12using namespace Mantid::Kernel;
13using namespace Mantid::API;
14
15namespace Mantid::Crystal {
16
17// Register the algorithm into the AlgorithmFactory
18DECLARE_ALGORITHM(PeaksInRegion)
19
20//----------------------------------------------------------------------------------------------
22const std::string PeaksInRegion::name() const { return "PeaksInRegion"; }
23
25int PeaksInRegion::version() const { return 1; }
26
28const std::string PeaksInRegion::category() const { return "Crystal\\Peaks"; }
29
30//----------------------------------------------------------------------------------------------
31
32//----------------------------------------------------------------------------------------------
36 declareProperty(std::make_unique<PropertyWithValue<bool>>("CheckPeakExtents", false),
37 "Include any peak in the region that has a shape extent "
38 "extending into that region.");
39
40 this->initBaseProperties();
41
42 auto mandatoryExtents = std::make_shared<Mantid::Kernel::MandatoryValidator<std::vector<double>>>();
43
44 std::vector<double> extents(2, 0);
45 extents[0] = -50;
46 extents[1] = +50;
47 declareProperty(std::make_unique<ArrayProperty<double>>("Extents", std::move(extents), std::move(mandatoryExtents)),
48 "A comma separated list of min, max for each dimension,\n"
49 "specifying the extents of each dimension. Optional, default +-50 in "
50 "each dimension.");
51
52 setPropertySettings("PeakRadius", std::make_unique<EnabledWhenProperty>("CheckPeakExtents", IS_NOT_DEFAULT));
53}
54
56 const size_t numberOfFaces = this->numberOfFaces();
57 std::stringstream outbuff;
58 if (m_extents.size() != numberOfFaces) {
59 throw std::invalid_argument("Six commma separated entries for the extents expected");
60 }
61 if (m_extents[0] > m_extents[1]) {
62 outbuff << "xmin > xmax " << m_extents[0] << " > " << m_extents[1];
63 throw std::invalid_argument(outbuff.str());
64 }
65 if (m_extents[2] > m_extents[3]) {
66 outbuff << "ymin > ymax " << m_extents[2] << " > " << m_extents[3];
67 throw std::invalid_argument(outbuff.str());
68 }
69 if (m_extents[4] > m_extents[5]) {
70 outbuff << "zmin > zmax " << m_extents[2] << " > " << m_extents[3];
71 throw std::invalid_argument(outbuff.str());
72 }
73}
74
75bool PeaksInRegion::pointOutsideAnyExtents(const V3D &testPoint) const {
76 return testPoint[0] < m_extents[0] || testPoint[0] > m_extents[1] || testPoint[1] < m_extents[2] ||
77 testPoint[1] > m_extents[3] || testPoint[2] < m_extents[4] || testPoint[2] > m_extents[5];
78}
79
80bool PeaksInRegion::pointInsideAllExtents(const V3D &testPoint, const Mantid::Kernel::V3D & /*peakCenter*/) const {
81 return testPoint[0] >= m_extents[0] && testPoint[0] <= m_extents[1] && testPoint[1] >= m_extents[2] &&
82 testPoint[1] <= m_extents[3] && testPoint[2] >= m_extents[4] && testPoint[2] <= m_extents[5];
83}
84
85void PeaksInRegion::checkTouchPoint(const V3D &touchPoint, const V3D &normal, const V3D &faceVertex) const {
86 if (normal.scalar_prod(touchPoint - faceVertex) != 0) {
87 throw std::runtime_error("Debugging. Calculation is wrong. touch point should always be on the "
88 "plane!"); // Remove this line later. Check that geometry is setup
89 // properly.
90 }
91}
92
97int PeaksInRegion::numberOfFaces() const { return 6; }
98
104 const int minXIndex = 0;
105 const int maxXIndex = 1;
106 const int minYIndex = 2;
107 const int maxYIndex = 3;
108 const int minZIndex = 4;
109 const int maxZIndex = 5;
110
111 // Clockwise ordering of points around the extents box
112 /*
113
114 on front face. Positive z extends into plane.
115
116 p2|---|p3
117 | |
118 p1|---|p4
119 */
120 V3D point1(m_extents[minXIndex], m_extents[minYIndex], m_extents[minZIndex]);
121 V3D point2(m_extents[minXIndex], m_extents[maxYIndex], m_extents[minZIndex]);
122 V3D point3(m_extents[maxXIndex], m_extents[maxYIndex], m_extents[minZIndex]);
123 V3D point4(m_extents[maxXIndex], m_extents[minYIndex], m_extents[minZIndex]);
124 V3D point5(m_extents[minXIndex], m_extents[minYIndex], m_extents[maxZIndex]);
125 V3D point6(m_extents[minXIndex], m_extents[maxYIndex], m_extents[maxZIndex]);
126 V3D point7(m_extents[maxXIndex], m_extents[maxYIndex], m_extents[maxZIndex]);
127 V3D point8(m_extents[maxXIndex], m_extents[minYIndex], m_extents[maxZIndex]);
128
129 const int numberOfFaces = this->numberOfFaces();
131 int faceIndex = 0;
132 faces[faceIndex++] = {point1, point5, point6}; // These define a
133 // face normal to x
134 // at xmin.
135
136 faces[faceIndex++] = {point4, point7, point8}; // These define a
137 // face normal to x
138 // at xmax.
139
140 faces[faceIndex++] = {point1, point4, point8}; // These define a
141 // face normal to y
142 // at ymin.
143
144 faces[faceIndex++] = {point2, point3, point7}; // These define a
145 // face normal to y
146 // at ymax.
147
148 faces[faceIndex++] = {point1, point2, point3}; // These define a
149 // face normal to z
150 // at zmin.
151
152 faces[faceIndex++] = {point5, point6, point7}; // These define a
153 // face normal to z
154 // at zmax.
155 return faces;
156}
157
158//----------------------------------------------------------------------------------------------
162 m_extents = this->getProperty("Extents");
163 const bool checkPeakExtents = this->getProperty("CheckPeakExtents");
164
166
167 executePeaksIntersection(checkPeakExtents);
168}
169
170} // namespace Mantid::Crystal
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
Definition: Algorithm.cpp:1913
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
PeaksInRegion : Find peaks that are either inside a box region, or that have a radius of sufficent si...
Definition: PeaksInRegion.h:17
void exec() override
Execute the algorithm.
void init() override
Initialize the algorithm's properties.
std::vector< double > m_extents
Extents.
Definition: PeaksInRegion.h:42
void validateExtentsInput() const override
Validate the input extents.
VecVecV3D createFaces() const override
Create the faces associated with this shape.
int numberOfFaces() const override
Implementation of pure virtual method on PeaksIntersection.
bool pointInsideAllExtents(const Mantid::Kernel::V3D &testPoint, const Mantid::Kernel::V3D &peakCenter) const override
Check that a point is inside ALL of the extents.
void checkTouchPoint(const Mantid::Kernel::V3D &touchPoint, const Mantid::Kernel::V3D &normal, const Mantid::Kernel::V3D &faceVertex) const override
Verfifies that the normals have been set up correctly such that the touch point falls onto the plane.
bool pointOutsideAnyExtents(const Mantid::Kernel::V3D &testPoint) const override
Check that a point is outside any of the extents.
const std::string category() const override
Algorithm's category for identification.
int version() const override
Algorithm's version for identification.
void executePeaksIntersection(const bool checkPeakExtents=true)
Run the algorithm.
void initBaseProperties()
Initalize the common properties.
Support for a property that holds an array of values.
Definition: ArrayProperty.h:28
void setPropertySettings(const std::string &name, std::unique_ptr< IPropertySettings > settings)
The concrete, templated class for properties.
Class for 3D vectors.
Definition: V3D.h:34
constexpr double scalar_prod(const V3D &v) const noexcept
Calculates the cross product.
Definition: V3D.h:274
std::vector< VecV3D > VecVecV3D
STL namespace.