Mantid
Loading...
Searching...
No Matches
PeakTransform.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 +
7#include <utility>
8
10
11namespace Mantid::Geometry {
12PeakTransform::PeakTransform(std::string xPlotLabel, std::string yPlotLabel, const boost::regex &regexOne,
13 const boost::regex &regexTwo, const boost::regex &regexThree)
14 : m_xPlotLabel(std::move(xPlotLabel)), m_yPlotLabel(std::move(yPlotLabel)), m_indexOfPlotX(0), m_indexOfPlotY(1),
15 m_indexOfPlotZ(2), m_indexOfPeakX(0), m_indexOfPeakY(1), m_indexOfPeakZ(2), m_FirstRegex(regexOne),
16 m_SecondRegex(regexTwo), m_ThirdRegex(regexThree) {
17 const std::string &xLabel = m_xPlotLabel;
18 const std::string &yLabel = m_yPlotLabel;
19
20 const int FirstIndex = 0; // Maybe more appropriate to call this IndexZero etc.
21 const int SecondIndex = 1;
22 const int ThirdIndex = 2;
23
24 if (boost::regex_match(xLabel, m_FirstRegex) && boost::regex_match(yLabel, m_SecondRegex)) // HKL
25 {
26 m_indexOfPlotX = FirstIndex;
27 m_indexOfPlotY = SecondIndex;
28 m_indexOfPlotZ = ThirdIndex;
29
30 m_indexOfPeakX = FirstIndex;
31 m_indexOfPeakY = SecondIndex;
32 m_indexOfPeakZ = ThirdIndex;
33 } else if (boost::regex_match(xLabel, m_FirstRegex) && boost::regex_match(yLabel, m_ThirdRegex)) // HLK
34 {
35 m_indexOfPlotX = FirstIndex;
36 m_indexOfPlotY = ThirdIndex;
37 m_indexOfPlotZ = SecondIndex;
38
39 m_indexOfPeakX = FirstIndex;
40 m_indexOfPeakY = ThirdIndex;
41 m_indexOfPeakZ = SecondIndex;
42 } else if (boost::regex_match(xLabel, m_ThirdRegex) && boost::regex_match(yLabel, m_FirstRegex)) // LHK
43 {
44 m_indexOfPlotX = ThirdIndex;
45 m_indexOfPlotY = FirstIndex;
46 m_indexOfPlotZ = SecondIndex;
47
48 m_indexOfPeakX = SecondIndex;
49 m_indexOfPeakY = ThirdIndex;
50 m_indexOfPeakZ = FirstIndex;
51 } else if (boost::regex_match(xLabel, m_ThirdRegex) && boost::regex_match(yLabel, m_SecondRegex)) // LKH
52 {
53 m_indexOfPlotX = ThirdIndex;
54 m_indexOfPlotY = SecondIndex;
55 m_indexOfPlotZ = FirstIndex;
56
57 m_indexOfPeakX = ThirdIndex;
58 m_indexOfPeakY = SecondIndex;
59 m_indexOfPeakZ = FirstIndex;
60 } else if (boost::regex_match(xLabel, m_SecondRegex) && boost::regex_match(yLabel, m_ThirdRegex)) // KLH
61 {
62 m_indexOfPlotX = SecondIndex;
63 m_indexOfPlotY = ThirdIndex;
64 m_indexOfPlotZ = FirstIndex;
65
66 m_indexOfPeakX = ThirdIndex;
67 m_indexOfPeakY = FirstIndex;
68 m_indexOfPeakZ = SecondIndex;
69 } else if (boost::regex_match(xLabel, m_SecondRegex) && boost::regex_match(yLabel, m_FirstRegex)) // KHL
70 {
71 m_indexOfPlotX = SecondIndex;
72 m_indexOfPlotY = FirstIndex;
73 m_indexOfPlotZ = ThirdIndex;
74
75 m_indexOfPeakX = SecondIndex;
76 m_indexOfPeakY = FirstIndex;
77 m_indexOfPeakZ = ThirdIndex;
78 } else {
80 }
81}
82
84 switch (m_indexOfPlotZ) {
85 case 0:
86 return m_FirstRegex;
87 case 1:
88 return m_SecondRegex;
89 default:
90 return m_ThirdRegex;
91 }
92}
93
95 // Will have the plots x, y, and z aligned to the correct h, k, l value.
96 Mantid::Kernel::V3D transformedPeakPosition;
97 transformedPeakPosition.setX(original[m_indexOfPlotX]);
98 transformedPeakPosition.setY(original[m_indexOfPlotY]);
99 transformedPeakPosition.setZ(original[m_indexOfPlotZ]);
100 return transformedPeakPosition;
101}
102
104 // Will have the plots x, y, and z aligned to the correct h, k, l value.
105 Mantid::Kernel::V3D originalPeakPosition;
106 originalPeakPosition.setX(transformed[m_indexOfPeakX]);
107 originalPeakPosition.setY(transformed[m_indexOfPeakY]);
108 originalPeakPosition.setZ(transformed[m_indexOfPeakZ]);
109 return originalPeakPosition;
110}
111} // namespace Mantid::Geometry
Exceptions occuring when PeakTransformations cannot be formed.
Definition: PeakTransform.h:66
virtual Mantid::Kernel::V3D transform(const Mantid::Kernel::V3D &original) const
Perform Transform.
Mantid::Kernel::V3D transformBack(const Mantid::Kernel::V3D &transformed) const
Perform reverse transform.
boost::regex getFreePeakAxisRegex() const
Get a regex to find the axis of the free peak.
PeakTransform(std::string xPlotLabel, std::string yPlotLabel, const boost::regex &regexOne, const boost::regex &regexTwo, const boost::regex &regexThree)
Class for 3D vectors.
Definition: V3D.h:34
void setZ(const double zz) noexcept
Set is z position.
Definition: V3D.h:230
void setX(const double xx) noexcept
Set is x position.
Definition: V3D.h:218
void setY(const double yy) noexcept
Set is y position.
Definition: V3D.h:224
STL namespace.