Skip to content
Snippets Groups Projects
Commit f7b27ccc authored by Harry Jeffery's avatar Harry Jeffery
Browse files

Refs #11355 Port matrixFromProjection

parent 8167eb86
No related branches found
No related tags found
No related merge requests found
#include "MantidMDAlgorithms/CutMD.h"
#include "MantidAPI/IMDEventWorkspace.h"
#include "MantidKernel/ArrayProperty.h"
#include "MantidKernel/Matrix.h"
#include "MantidKernel/System.h"
using namespace Mantid::API;
......@@ -15,6 +16,35 @@ std::pair<double, double> getDimensionExtents(IMDEventWorkspace_sptr ws,
auto dim = ws->getDimension(index);
return std::make_pair(dim->getMinimum(), dim->getMaximum());
}
Matrix<double> matrixFromProjection(ITableWorkspace_sptr projection) {
if (!projection) {
return Matrix<double>(3, 3, true /* makeIdentity */);
}
const size_t numDims = projection->rowCount();
Matrix<double> ret(3, 3);
for (size_t i = 0; i < numDims; i++) {
const std::string name =
projection->getColumn("name")->cell<std::string>(i);
const std::string valueStr =
projection->getColumn("value")->cell<std::string>(i);
std::vector<std::string> valueStrVec;
boost::split(valueStrVec, valueStr, boost::is_any_of(","));
std::vector<double> valueDblVec;
for (auto it = valueStrVec.begin(); it != valueStrVec.end(); ++it)
valueDblVec.push_back(boost::lexical_cast<double>(*it));
if (name == "u")
ret.setRow(0, valueDblVec);
else if (name == "v")
ret.setRow(1, valueDblVec);
else if (name == "w")
ret.setRow(2, valueDblVec);
}
return ret;
}
} // anonymous namespace
namespace Mantid {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment