Skip to content

Commit

Permalink
Allow SignalRange to work with MDImplicitFunction
Browse files Browse the repository at this point in the history
Refs #9319
  • Loading branch information
martyngigg committed Apr 23, 2014
1 parent e3c38e0 commit 9f4e8bf
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
25 changes: 22 additions & 3 deletions Code/Mantid/MantidQt/API/src/SignalRange.cpp
Expand Up @@ -20,7 +20,23 @@ namespace MantidQt
const Mantid::API::MDNormalization normalization)
: m_interval(), m_normalization(normalization)
{
findFullRange(workspace);
findFullRange(workspace, NULL);
}

/**
* Find the signal range that region defined by the function gives on the workspace
* using the given normalization
* @param workspace A reference to a workspace object
* @param function A reference to an MDImplicitFunction object that defines a region
* of the workspace
* @param normalization The type of normalization
*/
SignalRange::SignalRange(const Mantid::API::IMDWorkspace &workspace,
Mantid::Geometry::MDImplicitFunction &function,
const Mantid::API::MDNormalization normalization)
:m_interval(), m_normalization(normalization)
{
findFullRange(workspace, &function);
}

/**
Expand All @@ -36,10 +52,13 @@ namespace MantidQt
//-------------------------------------------------------------------------
/**
* @param workspace A reference to the workspace the explore
* @param function A pointer to an MDImplicitFunction object that defines a region
* of the workspace. NULL indicates use whole workspace
*/
void SignalRange::findFullRange(const Mantid::API::IMDWorkspace &workspace)
void SignalRange::findFullRange(const Mantid::API::IMDWorkspace &workspace,
Mantid::Geometry::MDImplicitFunction *function)
{
auto iterators = workspace.createIterators(PARALLEL_GET_MAX_THREADS);
auto iterators = workspace.createIterators(PARALLEL_GET_MAX_THREADS, function);
m_interval = getRange(iterators);
}

Expand Down
38 changes: 37 additions & 1 deletion Code/Mantid/MantidQt/API/test/SignalRangeTest.h
Expand Up @@ -106,7 +106,7 @@ class SignalRangeTest : public CxxTest::TestSuite
TS_ASSERT_DELTA(10.0, range.maxValue(), 1e-10);
}

void test_IMDWorkspace_Without_Function_Uses_Specified_Normalization()
void test_IMDWorkspace_Uses_Specified_Normalization()
{
using namespace ::testing;

Expand Down Expand Up @@ -136,6 +136,42 @@ class SignalRangeTest : public CxxTest::TestSuite
TS_ASSERT_DELTA(5.0, range.maxValue(), 1e-10);
}

void test_IMDWorkspace_With_Function_()
{
using namespace ::testing;

int nthreads = PARALLEL_GET_MAX_THREADS;
std::vector<Mantid::API::IMDIterator*> iterators(nthreads);
for(int i = 0;i < nthreads; ++i)
{
auto * iterator = new NormalizableMockIterator;
EXPECT_CALL(*iterator, getNumEvents()).Times(Exactly(2)).WillRepeatedly(Return(2));
EXPECT_CALL(*iterator, valid()).WillRepeatedly(Return(true));
EXPECT_CALL(*iterator, next()).WillOnce(Return(true)).WillRepeatedly(Return(false));
EXPECT_CALL(*iterator, getSignal()).WillOnce(Return(1.5)).WillRepeatedly(Return(10.0));
iterators[i] = iterator;
}

MockMDWorkspace data;
Mantid::Geometry::MDImplicitFunction function;
Mantid::coord_t normal[3] = {1234, 456, 678};
Mantid::coord_t point[3] = {1,2,3};
function.addPlane(Mantid::Geometry::MDPlane(3, normal, point));

EXPECT_CALL(data, createIterators(nthreads, &function))
.Times(Exactly(1))
.WillOnce(Return(iterators));


MantidQt::API::SignalRange sr(data, function, Mantid::API::NoNormalization);
QwtDoubleInterval range = sr.interval();

TS_ASSERT(Mock::VerifyAndClearExpectations(&data));

TS_ASSERT_DELTA(0.75, range.minValue(), 1e-10);
TS_ASSERT_DELTA(5.0, range.maxValue(), 1e-10);
}

};


Expand Down

0 comments on commit 9f4e8bf

Please sign in to comment.