Mantid
Loading...
Searching...
No Matches
MDTransfAxisNames.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 <boost/format.hpp>
9
10namespace Mantid::MDAlgorithms {
11using namespace Mantid::Kernel;
12
13MDTransfAxisNames::MDTransfAxisNames() : m_DefaultDimID(CnvrtToMD::nDefaultID) {
14 // this defines default dimension ID-s which are used to indentify dimensions
15 // when using the target MD workspace later
16 // for ModQ transformation:
18 // for Q3D transformation
23}
24
25//
26std::vector<std::string> MDTransfAxisNames::getDefaultDimIDQ3D(DeltaEMode::Type dEMode) const {
27 std::vector<std::string> rez;
28 if (dEMode == DeltaEMode::Elastic) {
29 rez.resize(3);
30 } else {
31
32 if (dEMode == DeltaEMode::Direct || dEMode == DeltaEMode::Indirect) {
33 rez.resize(4);
35 } else {
36 throw(std::invalid_argument("Unknown dE mode provided"));
37 }
38 }
42 return rez;
43}
44
45std::vector<std::string> MDTransfAxisNames::getDefaultDimIDModQ(DeltaEMode::Type dEMode) const {
46 std::vector<std::string> rez;
47
48 if (dEMode == DeltaEMode::Elastic) {
49 rez.resize(1);
50 } else {
51 if (dEMode == DeltaEMode::Direct || dEMode == DeltaEMode::Indirect) {
52 rez.resize(2);
54 } else {
55 throw(std::invalid_argument("Unknown dE mode provided"));
56 }
57 }
59 return rez;
60}
61
62std::string makeAxisName(const Kernel::V3D &Dir, const std::vector<std::string> &QNames) {
63 double eps(1.e-3);
64 Kernel::V3D absDir(fabs(Dir.X()), fabs(Dir.Y()), fabs(Dir.Z()));
65 std::string mainName;
66
67 if ((absDir[0] >= absDir[1]) && (absDir[0] >= absDir[2])) {
68 mainName = QNames[0];
69 } else if (absDir[1] >= absDir[2]) {
70 mainName = QNames[1];
71 } else {
72 mainName = QNames[2];
73 }
74
75 std::string name("["), separator = ",";
76 for (size_t i = 0; i < 3; i++) {
77
78 if (i == 2)
79 separator = "]";
80 if (absDir[i] < eps) {
81 name += "0" + separator;
82 continue;
83 }
84 if (Dir[i] < 0) {
85 name += "-";
86 }
87 if (std::fabs(absDir[i] - 1) < eps) {
88 name.append(mainName).append(separator);
89 continue;
90 }
91 name.append(sprintfd(absDir[i], eps)).append(mainName).append(separator);
92 }
93
94 return name;
95}
96std::string DLLExport sprintfd(const double data, const double eps) {
97 // truncate to eps decimal points
98 double dist = std::round(data / eps) * eps;
99 return boost::str(boost::format("%d") % dist);
100}
101
102} // namespace Mantid::MDAlgorithms
#define fabs(x)
Definition: Matrix.cpp:22
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
Definition: System.h:53
Class for 3D vectors.
Definition: V3D.h:34
constexpr double X() const noexcept
Get x.
Definition: V3D.h:232
constexpr double Y() const noexcept
Get y.
Definition: V3D.h:233
constexpr double Z() const noexcept
Get z.
Definition: V3D.h:234
std::vector< std::string > getDefaultDimIDModQ(Kernel::DeltaEMode::Type dEMode) const
std::vector< std::string > getDefaultDimIDQ3D(Kernel::DeltaEMode::Type dEMode) const
function returns default dimension id-s for different Q and dE modes, defined by this class
std::vector< std::string > m_DefaultDimID
the vector describes default dimension names, specified along the axis if no names are explicitly req...
std::string DLLExport sprintfd(const double data, const double eps)
creates string representation of the number with accuracy, cpecified by eps
std::string DLLExport makeAxisName(const Kernel::V3D &Dir, const std::vector< std::string > &QNames)
function to build mslice-like axis name from the vector, which describes crystallographic direction a...
Type
Define the available energy transfer modes It is important to assign enums proper numbers,...
Definition: DeltaEMode.h:29