Commit 47d5411a authored by Danny Hindson's avatar Danny Hindson
Browse files

Make LoadSampleShape algorithm work with peaks workspaces

parent 637c0509
......@@ -7,6 +7,7 @@
#pragma once
#include "MantidAPI/Algorithm.h"
#include "MantidAPI/ExperimentInfo.h"
#include "MantidDataHandling/MeshFileIO.h"
#include "MantidGeometry/Objects/MeshObject.h"
......@@ -51,7 +52,7 @@ private:
void exec() override;
};
void DLLExport rotate(Geometry::MeshObject &sampleMesh,
const API::MatrixWorkspace_const_sptr &inputWS);
const API::ExperimentInfo_const_sptr &inputWS);
} // namespace DataHandling
} // namespace Mantid
\ No newline at end of file
......@@ -13,9 +13,9 @@
#include "MantidAPI/FileProperty.h"
#include "MantidAPI/InstrumentValidator.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/Run.h"
#include "MantidAPI/Sample.h"
#include "MantidAPI/Workspace.h"
#include "MantidKernel/ArrayProperty.h"
......@@ -37,8 +37,8 @@ void LoadSampleShape::init() {
// input workspace
declareProperty(
std::make_unique<WorkspaceProperty<>>("InputWorkspace", "",
Direction::Input, wsValidator),
std::make_unique<WorkspaceProperty<Workspace>>(
"InputWorkspace", "", Direction::Input, wsValidator),
"The name of the workspace containing the instrument to add the shape");
// shape file
......@@ -51,21 +51,25 @@ void LoadSampleShape::init() {
declareProperty("Scale", "cm", "The scale of the stl: m, cm, or mm");
// Output workspace
declareProperty(std::make_unique<WorkspaceProperty<>>("OutputWorkspace", "",
Direction::Output),
declareProperty(std::make_unique<WorkspaceProperty<Workspace>>(
"OutputWorkspace", "", Direction::Output),
"The name of the workspace that will contain the loaded "
"shape of the sample");
}
void LoadSampleShape::exec() {
MatrixWorkspace_const_sptr inputWS = getProperty("InputWorkspace");
MatrixWorkspace_sptr outputWS = getProperty("OutputWorkspace");
Workspace_const_sptr inputWS = getProperty("InputWorkspace");
Workspace_sptr outputWS = getProperty("OutputWorkspace");
if (inputWS != outputWS) {
outputWS = inputWS->clone();
}
auto ei = std::dynamic_pointer_cast<ExperimentInfo>(outputWS);
if (!ei)
throw std::invalid_argument("Wrong type of input workspace");
const std::string filename = getProperty("Filename");
const std::string filetype = filename.substr(filename.size() - 3);
......@@ -83,10 +87,10 @@ void LoadSampleShape::exec() {
shape = reader->readStl();
}
// rotate shape
rotate(*shape, inputWS);
rotate(*shape, ei);
// Put shape into sample.
Sample &sample = outputWS->mutableSample();
Sample &sample = ei->mutableSample();
sample.setShape(shape);
// Set output workspace
......@@ -96,12 +100,11 @@ void LoadSampleShape::exec() {
/**
* Rotates the Shape by a provided matrix
* @param sampleMesh The Shape to rotate
* @param inputWS The workspace to get the rotation from
* @param ei The workspace to get the rotation from
* @returns a shared pointer to the newly rotated Shape
*/
void rotate(MeshObject &sampleMesh, const MatrixWorkspace_const_sptr &inputWS) {
const std::vector<double> rotationMatrix =
inputWS->run().getGoniometer().getR();
void rotate(MeshObject &sampleMesh, const ExperimentInfo_const_sptr &ei) {
const std::vector<double> rotationMatrix = ei->run().getGoniometer().getR();
sampleMesh.rotate(rotationMatrix);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment