Mantid
Loading...
Searching...
No Matches
Projection.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 +
9
10namespace Mantid::API {
11
13
15 m_dimensions[0][0] = 1.0;
16 m_dimensions[1][1] = 1.0;
17 m_dimensions[2][2] = 1.0;
18 m_offsets[0] = 0.0;
19 m_offsets[1] = 0.0;
20 m_offsets[2] = 0.0;
21 m_units[0] = RLU;
22 m_units[1] = RLU;
23 m_units[2] = RLU;
24}
25
26Projection::Projection(const V3D &u, const V3D &v) {
27 m_dimensions[0] = u;
28 m_dimensions[1] = v;
29 m_dimensions[2] = u.cross_prod(v);
30 for (size_t i = 0; i < 3; ++i) {
31 m_offsets[i] = 0.0;
32 m_units[i] = RLU;
33 }
34}
35
36Projection::Projection(const V3D &u, const V3D &v, const V3D &w) {
37 if (fabs(w.scalar_prod(u.cross_prod(v))) <= 0.00001)
38 throw std::runtime_error("u, v, and w must not be coplanar!");
39
40 m_dimensions[0] = u;
41 m_dimensions[1] = v;
42 m_dimensions[2] = w;
43 for (size_t i = 0; i < 3; ++i) {
44 m_offsets[i] = 0.0;
45 m_units[i] = RLU;
46 }
47}
48
50 if (ws.columnCount() != 4)
51 throw std::runtime_error("4 columns must be provided to create a projection");
52
53 const size_t numRows = ws.rowCount();
54 if (numRows != 3)
55 throw std::runtime_error("3 rows must be provided to create a projection");
56
57 Column_const_sptr nameCol = ws.getColumn("name");
58 Column_const_sptr valueCol = ws.getColumn("value");
59 Column_const_sptr offsetCol = ws.getColumn("offset");
60 Column_const_sptr unitCol = ws.getColumn("type");
61
62 for (size_t i = 0; i < numRows; i++) {
63 const std::string name = nameCol->cell<std::string>(i);
64 const V3D value = valueCol->cell<V3D>(i);
65 const double offset = offsetCol->cell<double>(i);
66 const std::string unitStr = unitCol->cell<std::string>(i);
67
68 // Check the name
69 size_t index;
70 if (name == "u") {
71 index = 0;
72 } else if (name == "v") {
73 index = 1;
74 } else if (name == "w") {
75 index = 2;
76 } else {
77 throw std::runtime_error("Invalid dimension name: " + name);
78 }
79
80 // Check the unit
81 ProjectionUnit unit;
82 if (unitStr == "r") {
83 unit = RLU;
84 } else if (unitStr == "a") {
85 unit = INV_ANG;
86 } else {
87 throw std::runtime_error("Unknown type: " + unitStr);
88 }
89
90 // Apply the data
92 m_offsets[index] = offset;
93 m_units[index] = unit;
94 }
95}
96
97double Projection::getOffset(size_t nd) {
98 if (nd >= 3)
99 throw std::invalid_argument("given axis out of range");
100 else
101 return m_offsets[nd];
102}
103
105 if (nd >= 3)
106 throw std::invalid_argument("given axis out of range");
107 else
108 return m_dimensions[nd];
109}
110
112 if (nd >= 3)
113 throw std::invalid_argument("given axis out of range");
114 else
115 return m_units[nd];
116}
117
118void Projection::setOffset(size_t nd, double offset) {
119 if (nd >= 3)
120 throw std::invalid_argument("given axis out of range");
121 else
122 m_offsets[nd] = offset;
123}
124
125void Projection::setAxis(size_t nd, const V3D &axis) {
126 if (nd >= 3)
127 throw std::invalid_argument("given axis out of range");
128 else
129 m_dimensions[nd] = axis;
130}
131
132void Projection::setUnit(size_t nd, ProjectionUnit unit) {
133 if (nd >= 3)
134 throw std::invalid_argument("given axis out of range");
135 else
136 m_units[nd] = unit;
137}
138
139} // namespace Mantid::API
double value
The value of the point.
Definition: FitMW.cpp:51
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
#define fabs(x)
Definition: Matrix.cpp:22
ITableWorkspace is an implementation of Workspace in which the data are organised in columns of same ...
virtual Column_sptr getColumn(const std::string &name)=0
Gets the shared pointer to a column by name.
virtual size_t columnCount() const =0
Number of columns in the workspace.
virtual size_t rowCount() const =0
Number of rows in the workspace.
double m_offsets[3]
The offsets for each dimension.
Definition: Projection.h:65
Kernel::V3D getAxis(size_t nd)
Retrieves the axis vector for the given dimension.
Definition: Projection.cpp:104
Projection()
Default constructor builds identity projection.
Definition: Projection.cpp:14
void setOffset(size_t nd, double offset)
Set the offset for a given dimension.
Definition: Projection.cpp:118
ProjectionUnit getUnit(size_t nd)
Retrives the unit of the given dimension.
Definition: Projection.cpp:111
Kernel::V3D m_dimensions[3]
The dimensions.
Definition: Projection.h:63
void setUnit(size_t nd, ProjectionUnit unit)
Set the unit for a given dimension.
Definition: Projection.cpp:132
ProjectionUnit m_units[3]
The units for each dimension.
Definition: Projection.h:67
void setAxis(size_t nd, const Kernel::V3D &axis)
Set the axis vector for a given dimension.
Definition: Projection.cpp:125
double getOffset(size_t nd)
Retrieves the offset for the given dimension.
Definition: Projection.cpp:97
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
constexpr V3D cross_prod(const V3D &v) const noexcept
Cross product (this * argument)
Definition: V3D.h:278
std::shared_ptr< const Column > Column_const_sptr
Definition: Column.h:229
ProjectionUnit
Represents 3 dimensional projections.
Definition: Projection.h:27