diff --git a/Code/Mantid/Framework/MDAlgorithms/src/SmoothMD.cpp b/Code/Mantid/Framework/MDAlgorithms/src/SmoothMD.cpp index d6cf1048fa05c3a0fed87094c6289430853adcb4..c23fd72af6bccbd28bb901a74077d4f0b60428fb 100644 --- a/Code/Mantid/Framework/MDAlgorithms/src/SmoothMD.cpp +++ b/Code/Mantid/Framework/MDAlgorithms/src/SmoothMD.cpp @@ -7,6 +7,7 @@ #include "MantidKernel/ListValidator.h" #include "MantidKernel/MandatoryValidator.h" #include "MantidKernel/PropertyWithValue.h" +#include "MantidMDEvents/MDHistoWorkspaceIterator.h" #include <boost/make_shared.hpp> #include <vector> #include <map> @@ -19,6 +20,7 @@ using namespace Mantid::Kernel; using namespace Mantid::API; +using namespace Mantid::MDEvents; typedef std::vector<int> WidthVector; typedef boost::function<IMDHistoWorkspace_sptr(IMDHistoWorkspace_const_sptr, const WidthVector&)> SmoothFunction; @@ -40,11 +42,12 @@ std::vector<std::string> functions() { IMDHistoWorkspace_sptr hatSmooth(IMDHistoWorkspace_const_sptr toSmooth, const WidthVector& widthVector) { IMDHistoWorkspace_sptr outWS = toSmooth->clone(); - boost::scoped_ptr<IMDIterator> iterator(toSmooth->createIterator(NULL)); // TODO should be multi-threaded + boost::scoped_ptr<MDHistoWorkspaceIterator> iterator(dynamic_cast<MDHistoWorkspaceIterator*>(toSmooth->createIterator(NULL))); // TODO should be multi-threaded do { // Gets all vertex-touching neighbours - std::vector<size_t> neighbourIndexes = iterator->findNeighbourIndexes(); + + std::vector<size_t> neighbourIndexes = iterator->findNeighbourIndexesByWidth(widthVector.front()); // TODO we should use the whole width vector not just the first element. const size_t nNeighbours = neighbourIndexes.size(); double sumSignal = iterator->getSignal(); double sumSqError = iterator->getError(); diff --git a/Code/Mantid/Framework/MDAlgorithms/test/SmoothMDTest.h b/Code/Mantid/Framework/MDAlgorithms/test/SmoothMDTest.h index 48d1ac79320a4d20d62cb2f07a5906c7f59da016..8a571715eefd020b9e7be36f8acf51bd2eaaee83 100644 --- a/Code/Mantid/Framework/MDAlgorithms/test/SmoothMDTest.h +++ b/Code/Mantid/Framework/MDAlgorithms/test/SmoothMDTest.h @@ -82,7 +82,7 @@ public: } - void test_smooth_hat_function() + void test_smooth_hat_function_3_pix_width() { auto toSmooth = MDEventsTestHelper::makeFakeMDHistoWorkspace(1 /*signal*/, 2 /*numDims*/, 3 /*numBins in each dimension*/); toSmooth->setSignalAt(4, 2.0); @@ -116,8 +116,67 @@ public: TS_ASSERT_EQUALS(5.0/4, out->getSignalAt(0)); TS_ASSERT_EQUALS(7.0/6, out->getSignalAt(1)); TS_ASSERT_EQUALS(10.0/9, out->getSignalAt(4)); + } + + void test_smooth_hat_function_5_pix_width() + { + auto toSmooth = MDEventsTestHelper::makeFakeMDHistoWorkspace(1 /*signal*/, 2 /*numDims*/, 5 /*numBins in each dimension*/); + toSmooth->setSignalAt(12, 4.0); + + /* + 2D MDHistoWorkspace Input + + 1 - 1 - 1 - 1 - 1 + 1 - 1 - 1 - 1 - 1 + 1 - 1 - 4 - 1 - 1 + 1 - 1 - 1 - 1 - 1 + 1 - 1 - 1 - 1 - 1 + + */ + + SmoothMD alg; + alg.setChild(true); + alg.initialize(); + std::vector<int> widthVector(1, 5); // Smooth with width == 5 + alg.setProperty("WidthVector", widthVector); + alg.setProperty("InputWorkspace", toSmooth); + alg.setPropertyValue("OutputWorkspace", "dummy"); + alg.execute(); + IMDHistoWorkspace_sptr out = alg.getProperty("OutputWorkspace"); + /* + 2D MDHistoWorkspace Expected + + key: + x = 12/9 + y = 18/15 + z = 28/25 + ` = ignore + + x - ` - y - ` - x + ` - ` - ` - ` - ` + y - ` - z - ` - y + ` - ` - ` - ` - ` + x - ` - y - ` - x + */ + // Check vertexes + double x = 12.0/9; + TS_ASSERT_EQUALS(x, out->getSignalAt(0)); + TS_ASSERT_EQUALS(x, out->getSignalAt(4)); + TS_ASSERT_EQUALS(x, out->getSignalAt(20)); + TS_ASSERT_EQUALS(x, out->getSignalAt(24)); + + // Check edges + double y = 18.0/15; + TS_ASSERT_EQUALS(y, out->getSignalAt(2)); + TS_ASSERT_EQUALS(y, out->getSignalAt(10)); + TS_ASSERT_EQUALS(y, out->getSignalAt(14)); + TS_ASSERT_EQUALS(y, out->getSignalAt(22)); + + // Check centre + double z = 28.0/25; + TS_ASSERT_EQUALS(z, out->getSignalAt(12)); } diff --git a/Code/Mantid/docs/source/algorithms/SmoothMD-v1.rst b/Code/Mantid/docs/source/algorithms/SmoothMD-v1.rst index 6f4ad1d1f5b5dd1a03f30fc63e03297661150d9e..f0f805e3fc302f399ec58637aac330b5d648fafc 100644 --- a/Code/Mantid/docs/source/algorithms/SmoothMD-v1.rst +++ b/Code/Mantid/docs/source/algorithms/SmoothMD-v1.rst @@ -10,7 +10,7 @@ Description ----------- -TODO: Enter a full rst-markup description of your algorithm here. +Provides smoothing of :ref:`MDHistoWorkspaces <MDHistoWorkspace>`__ in n-dimensions. The WidthVector relates to the number of pixels to include in the width for each dimension. *WidthVector* **must contain entries that are odd numbers**. Usage