Skip to content

Commit

Permalink
refs #7282. Modify in place and fix warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Jun 11, 2013
1 parent 827251f commit 3767e38
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
32 changes: 19 additions & 13 deletions Code/Mantid/Framework/MDAlgorithms/src/ThresholdMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ namespace Mantid
propOptions.push_back(GreaterThan());

declareProperty("Condition", LessThan(), boost::make_shared<StringListValidator>(propOptions),
"Selected threshold condition?");
"Selected threshold condition. Any value which does meet this condition with respect to the ReferenceValue will be overwritten.");

declareProperty("CurrentValue", 0.0, "Comparator value used by the Condition.");
declareProperty("ReferenceValue", 0.0, "Comparator value used by the Condition.");

declareProperty("OverwriteWithZero", true,
"Flag for enabling overwriting with a custom value. Defaults to overwrite signals with zeros.");
Expand All @@ -112,37 +112,43 @@ namespace Mantid
{
IMDHistoWorkspace_sptr inputWS = getProperty("InputWorkspace");
const std::string condition = getProperty("Condition");
const double currentValue = getProperty("CurrentValue");
const double referenceValue = getProperty("ReferenceValue");
const bool doOverwriteWithZero = getProperty("OverwriteWithZero");
double customOverwriteValue = getProperty("CustomOverwriteValue");
const std::string outWSName = getPropertyValue("OutputWorkspace");
if(doOverwriteWithZero)
{
customOverwriteValue = 0;
}

IAlgorithm_sptr alg = createChildAlgorithm("CloneMDWorkspace");
alg->setProperty("InputWorkspace", inputWS);
alg->executeAsChildAlg();
IMDWorkspace_sptr temp = alg->getProperty("OutputWorkspace");
auto outWS = boost::dynamic_pointer_cast<IMDHistoWorkspace>(temp);
IMDHistoWorkspace_sptr outWS = inputWS; // Shallow copy
if (outWSName != inputWS->getName())
{
g_log.debug("Deep copy input workspace as output workspace.");
IAlgorithm_sptr alg = createChildAlgorithm("CloneMDWorkspace");
alg->setProperty("InputWorkspace", inputWS);
alg->executeAsChildAlg();
IMDWorkspace_sptr temp = alg->getProperty("OutputWorkspace");
outWS = boost::dynamic_pointer_cast<IMDHistoWorkspace>(temp);
}

const int nPoints = inputWS->getNPoints();
const uint64_t nPoints = inputWS->getNPoints();

boost::function<bool(double)> comparitor = boost::bind(std::less<double>(),_1, currentValue);
boost::function<bool(double)> comparitor = boost::bind(std::less<double>(),_1, referenceValue);
if(condition == GreaterThan())
{
comparitor = boost::bind(std::greater<double>(),_1, currentValue);
comparitor = boost::bind(std::greater<double>(),_1, referenceValue);
}

Progress prog(this, 0, 1, 100);
int frequency = nPoints;
uint64_t frequency = nPoints;
if(nPoints > 100)
{
frequency = nPoints/100;
}

PARALLEL_FOR2(inputWS, outWS)
for(int i = 0; i < nPoints; ++i)
for(uint64_t i = 0; i < nPoints; ++i)
{
PARALLEL_START_INTERUPT_REGION
const double signalAt = inputWS->getSignalAt(i);
Expand Down
6 changes: 3 additions & 3 deletions Code/Mantid/Framework/MDAlgorithms/test/ThresholdMDTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ class ThresholdMDTest : public CxxTest::TestSuite
TS_ASSERT( alg.isInitialized() )
}

IMDHistoWorkspace_sptr doExecute(IMDHistoWorkspace_sptr inWS, const std::string& condition, const double& currentValue)
IMDHistoWorkspace_sptr doExecute(IMDHistoWorkspace_sptr inWS, const std::string& condition, const double& referenceValue)
{
const std::string outWSName = "OutWS";
ThresholdMD alg;
alg.setRethrows(true);
alg.initialize();
alg.setProperty("InputWorkspace", inWS);
alg.setProperty("Condition", condition);
alg.setProperty("CurrentValue", currentValue);
alg.setProperty("ReferenceValue", referenceValue);
alg.setPropertyValue("OutputWorkspace", outWSName);
alg.execute();

Expand Down Expand Up @@ -101,7 +101,7 @@ class ThresholdMDTest : public CxxTest::TestSuite
alg.initialize();
alg.setProperty("InputWorkspace", inWS);
alg.setProperty("Condition", "Less Than");
alg.setProperty("CurrentValue", 3.0);
alg.setProperty("ReferenceValue", 3.0);
alg.setProperty("OverwriteWithZero", false);
alg.setProperty("CustomOverwriteValue", 9.0);
alg.setPropertyValue("OutputWorkspace", outWSName);
Expand Down

0 comments on commit 3767e38

Please sign in to comment.