Mantid
Loading...
Searching...
No Matches
AffineMatrixParameter.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
9namespace Mantid::DataObjects {
10
11//----------------------------------------------------------------------------------------------
17AffineMatrixParameter::AffineMatrixParameter(size_t outD, size_t inD) : m_affineMatrix(outD + 1, inD + 1) {
18 m_isValid = false;
20 size_t nx = m_affineMatrix.numRows();
21 size_t ny = m_affineMatrix.numCols();
22 // big chunk of memory holding the whole matrix
23 m_rawMem = new coord_t[nx * ny];
24 // array of pointers (one per column)
25 m_rawMatrix = new coord_t *[nx];
26 for (size_t i = 0; i < nx; i++)
27 m_rawMatrix[i] = m_rawMem + (i * ny);
28 // Copy into the raw matrix (for speed)
30}
31
32//----------------------------------------------------------------------------------------------
35 // delete array of pointers to rows
36 delete[] m_rawMatrix;
37 m_rawMatrix = nullptr;
38
39 // delete large mem block holding the matrix
40 delete[] m_rawMem;
41 m_rawMem = nullptr;
42}
43
44//----------------------------------------------------------------------------------------------
47 for (size_t x = 0; x < m_affineMatrix.numRows(); ++x)
48 for (size_t y = 0; y < m_affineMatrix.numCols(); ++y)
50}
51
52//----------------------------------------------------------------------------------------------
58
59//----------------------------------------------------------------------------------------------
65
66//----------------------------------------------------------------------------------------------
72
73//----------------------------------------------------------------------------------------------
79 std::vector<coord_t> elements = this->m_affineMatrix.getVector();
80 const size_t size = elements.size();
81 std::string parameterValue;
82
83 for (size_t i = 1; i <= size; i++) {
84 std::stringstream sstream;
85 sstream << elements[i - 1];
86 parameterValue.append(sstream.str());
87 sstream.clear();
88 if (i % m_affineMatrix.numCols() == 0) {
89 if (i != size) {
90 parameterValue.append(";");
91 }
92 } else {
93 parameterValue.append(",");
94 }
95 }
96
97 return parameterXMLTemplate(parameterValue);
98}
99
100//----------------------------------------------------------------------------------------------
107}
108
109//----------------------------------------------------------------------------------------------
115
116//----------------------------------------------------------------------------------------------
121// cppcheck-suppress operatorEqVarError
123 if ((other.m_affineMatrix.numCols() != this->m_affineMatrix.numCols()) ||
124 (other.m_affineMatrix.numRows() != this->m_affineMatrix.numRows())) {
125 throw std::runtime_error("Cannot make assignemnts between "
126 "AffineMatrixParameter when the matrixes are of "
127 "different sizes.");
128 }
129 if (this != &other) {
130 this->m_affineMatrix = other.m_affineMatrix;
131 this->m_isValid = other.m_isValid;
133 }
134 return *this;
135}
136
137//----------------------------------------------------------------------------------------------
142 : m_affineMatrix(other.m_affineMatrix) {
143 m_isValid = other.m_isValid;
144 size_t nx = m_affineMatrix.numRows();
145 size_t ny = m_affineMatrix.numCols();
146 m_rawMem = new coord_t[nx * ny];
147 m_rawMatrix = new coord_t *[nx];
148 for (size_t i = 0; i < nx; i++)
149 m_rawMatrix[i] = m_rawMem + (i * ny);
151}
152
153//----------------------------------------------------------------------------------------------
159 if (newMatrix.numRows() != this->m_affineMatrix.numRows())
160 throw std::runtime_error("setMatrix(): Number of rows must match!");
161 if (newMatrix.numCols() != this->m_affineMatrix.numCols())
162 throw std::runtime_error("setMatrix(): Number of columns must match!");
163 m_affineMatrix = newMatrix;
164 // Copy into the raw matrix (for speed)
166 this->m_isValid = true;
167}
168} // namespace Mantid::DataObjects
std::string parameterXMLTemplate(const std::string &valueXMLtext) const
Type to wrap an affine matrix and allow serialization via xml.
AffineMatrixParameter & operator=(const AffineMatrixParameter &other)
Assignment operator.
std::string getName() const override
Get the name of the parameter.
bool isValid() const override
Getter for the valid status.
void copyRawMatrix()
Copy elements from affinematrix into raw array.
coord_t ** m_rawMatrix
Raw matrix used for speed (array of pointers to columns).
coord_t * m_rawMem
pointer to large memory block (matrix)
AffineMatrixType m_affineMatrix
Affine matrix.
AffineMatrixType getAffineMatrix() const
Gets copy of internal affine matrix.
std::string toXMLString() const override
Serialize the Affine Matrix Parameter.
static std::string parameterName()
Gets the type parameter name.
AffineMatrixParameter * clone() const override
Clone the parameter.
coord_t ** getRawMatrix()
Get the matrix in its raw array form.
AffineMatrixParameter(size_t outD, size_t inD)
Constructor.
void setMatrix(const AffineMatrixType &newMatrix)
Setter for the internal affine matrix.
void identityMatrix()
Makes the matrix an idenity matrix.
Definition: Matrix.cpp:661
std::vector< T > getVector() const
Definition: Matrix.cpp:77
size_t numRows() const
Return the number of rows in the matrix.
Definition: Matrix.h:144
size_t numCols() const
Return the number of columns in the matrix.
Definition: Matrix.h:147
float coord_t
Typedef for the data type to use for coordinate axes in MD objects such as MDBox, MDEventWorkspace,...
Definition: MDTypes.h:27