Newer
Older

Zhou, Wenduo
committed
#include "MantidAlgorithms/BinaryOperateMasks.h"
#include "MantidKernel/System.h"
#include "MantidDataObjects/MaskWorkspace.h"

Zhou, Wenduo
committed
#include "MantidAPI/WorkspaceValidators.h"
#include "MantidKernel/ListValidator.h"
using namespace Mantid::Kernel;
using namespace Mantid::API;
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
namespace Mantid {
namespace Algorithms {
DECLARE_ALGORITHM(BinaryOperateMasks)
// enum BinaryOperator{AND, OR, XOR, NOT};
//----------------------------------------------------------------------------------------------
/** Constructor
*/
BinaryOperateMasks::BinaryOperateMasks() {
// TODO Auto-generated constructor stub
}
//----------------------------------------------------------------------------------------------
/** Destructor
*/
BinaryOperateMasks::~BinaryOperateMasks() {
// TODO Auto-generated destructor stub
}
void BinaryOperateMasks::init() {
std::vector<std::string> operators;
operators.push_back("AND");
operators.push_back("OR");
operators.push_back("XOR");
operators.push_back("NOT");
declareProperty(new WorkspaceProperty<DataObjects::MaskWorkspace>(
"InputWorkspace1", "", Direction::Input),
"MaskWorkspace 1 for binary operation");
declareProperty(
new WorkspaceProperty<DataObjects::MaskWorkspace>(
"InputWorkspace2", "", Direction::Input, PropertyMode::Optional),
"Optional MaskWorkspace 2 for binary operation");
declareProperty("OperationType", "AND",
boost::make_shared<StringListValidator>(operators),
"Operator for Workspace1 and Workspace2");
declareProperty(new WorkspaceProperty<DataObjects::MaskWorkspace>(
"OutputWorkspace", "", Direction::Output),
"Output MaskWorkspace as result of binary operation");
return;
}
//----------------------------------------------------------------------------------------------
/** Main execution body
*/
void BinaryOperateMasks::exec() {
// 1. Read input
DataObjects::MaskWorkspace_const_sptr inputws1 =
getProperty("InputWorkspace1");
std::string op = getProperty("OperationType");
// 2. Output
DataObjects::MaskWorkspace_sptr outputws = getProperty("OutputWorkspace");
if (outputws != inputws1) {
// if the input and output are not the same, then create a new workspace for
// the output.
outputws = boost::make_shared<DataObjects::MaskWorkspace>(
inputws1->getInstrument());

Zhou, Wenduo
committed
}
// 3. Call Child Algorithm
if (op == "NOT") {
// Unary operation
outputws->binaryOperation(Mantid::DataObjects::BinaryOperator::NOT);
} else {
// Binary operation
// a. 2nd Input
DataObjects::MaskWorkspace_const_sptr inputws2 =
getProperty("InputWorkspace2");
DataObjects::SpecialWorkspace2D_const_sptr inputws2_special(inputws2);
unsigned int binop;
if (op == "AND") {
binop = (unsigned int)Mantid::DataObjects::BinaryOperator::AND;
} else if (op == "OR") {
binop = (unsigned int)Mantid::DataObjects::BinaryOperator::OR;
} else if (op == "XOR") {
binop = (unsigned int)Mantid::DataObjects::BinaryOperator::XOR;
} else {
binop = 1000;

Zhou, Wenduo
committed
}
outputws->binaryOperation(inputws2_special, binop);
}

Zhou, Wenduo
committed
// 4. Output
this->setProperty("OutputWorkspace", outputws);

Zhou, Wenduo
committed

Zhou, Wenduo
committed
} // namespace Mantid
} // namespace Algorithms