From 9f4e8bfc6b2628d01b9fa5ca5fa56d846b105c86 Mon Sep 17 00:00:00 2001 From: Martyn Gigg Date: Fri, 11 Apr 2014 11:50:49 +0100 Subject: [PATCH] Allow SignalRange to work with MDImplicitFunction Refs #9319 --- Code/Mantid/MantidQt/API/src/SignalRange.cpp | 25 ++++++++++-- .../MantidQt/API/test/SignalRangeTest.h | 38 ++++++++++++++++++- 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/Code/Mantid/MantidQt/API/src/SignalRange.cpp b/Code/Mantid/MantidQt/API/src/SignalRange.cpp index 9cf35bb8ab7c..3099212a14ed 100644 --- a/Code/Mantid/MantidQt/API/src/SignalRange.cpp +++ b/Code/Mantid/MantidQt/API/src/SignalRange.cpp @@ -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); } /** @@ -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); } diff --git a/Code/Mantid/MantidQt/API/test/SignalRangeTest.h b/Code/Mantid/MantidQt/API/test/SignalRangeTest.h index 56d7dd4a8309..a2026ee44ea8 100644 --- a/Code/Mantid/MantidQt/API/test/SignalRangeTest.h +++ b/Code/Mantid/MantidQt/API/test/SignalRangeTest.h @@ -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; @@ -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 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); + } + };