From 892641698fbb0348afe3df85ab766af2a399ca00 Mon Sep 17 00:00:00 2001 From: Owen Arnold Date: Wed, 19 Feb 2014 13:04:46 +0000 Subject: [PATCH] refs #8992. Utilise coord trans to original. This has been prevented thus far, because use of coord transforms has been based on the presence of original workspaces. Original workspaces will not be present upon a reload. I've also exposed the new getters on MDGeometry to python. --- .../Framework/API/inc/MantidAPI/MDGeometry.h | 3 +++ Code/Mantid/Framework/API/src/MDGeometry.cpp | 18 +++++++++++++++ .../Framework/API/test/MDGeometryTest.h | 14 +++++++++++ .../MDEvents/src/QueryMDWorkspace.cpp | 2 +- .../mantid/api/src/Exports/MDGeometry.cpp | 7 ++++++ .../API/src/MantidQwtIMDWorkspaceData.cpp | 23 ++++++++++++++----- 6 files changed, 60 insertions(+), 7 deletions(-) diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/MDGeometry.h b/Code/Mantid/Framework/API/inc/MantidAPI/MDGeometry.h index 284367eb62d6..4480d541a526 100644 --- a/Code/Mantid/Framework/API/inc/MantidAPI/MDGeometry.h +++ b/Code/Mantid/Framework/API/inc/MantidAPI/MDGeometry.h @@ -92,6 +92,9 @@ namespace API void transformDimensions(std::vector & scaling, std::vector & offset); + size_t getNumberTransformsToOriginal() const; + size_t getNumberTransformsFromOriginal() const; + // -------------------------------------------------------------------------------------------- ///@return the vector of the origin (in the original workspace) that corresponds to 0,0,0... in this workspace Mantid::Kernel::VMD & getOrigin() diff --git a/Code/Mantid/Framework/API/src/MDGeometry.cpp b/Code/Mantid/Framework/API/src/MDGeometry.cpp index eb19acb52494..00056b1f3ae5 100644 --- a/Code/Mantid/Framework/API/src/MDGeometry.cpp +++ b/Code/Mantid/Framework/API/src/MDGeometry.cpp @@ -512,6 +512,24 @@ namespace API return xmlBuilder.create(); } + /** + * Get the number of transforms defined to the original coordinate system. + * @return The number of transforms. + */ + size_t MDGeometry::getNumberTransformsToOriginal() const + { + return m_transforms_ToOriginal.size(); + } + + /** + * Get the number of transforms defined from the original coordinate system. + * @return The number of transforms. + */ + size_t MDGeometry::getNumberTransformsFromOriginal() const + { + return m_transforms_FromOriginal.size(); + } + } // namespace Mantid } // namespace API diff --git a/Code/Mantid/Framework/API/test/MDGeometryTest.h b/Code/Mantid/Framework/API/test/MDGeometryTest.h index ff559c397f06..0763cb7250d5 100644 --- a/Code/Mantid/Framework/API/test/MDGeometryTest.h +++ b/Code/Mantid/Framework/API/test/MDGeometryTest.h @@ -207,8 +207,22 @@ class MDGeometryTest : public CxxTest::TestSuite AnalysisDataService::Instance().remove("MDGeometryTest_originalWS"); TSM_ASSERT("Original workspace reference was deleted.", !g.hasOriginalWorkspace()); TSM_ASSERT("Original workspace reference is cleared.", !g.getOriginalWorkspace()); + } + void test_transforms_to_original() + { + MDGeometry g; + g.setTransformFromOriginal(new NullCoordTransform, 0); + g.setTransformFromOriginal(new NullCoordTransform, 1); + TSM_ASSERT_EQUALS("Wrong number of transforms from original reported.", 2, g.getNumberTransformsFromOriginal()); + } + void test_transforms_from_original() + { + MDGeometry g; + g.setTransformToOriginal(new NullCoordTransform, 0); + g.setTransformToOriginal(new NullCoordTransform, 1); + TSM_ASSERT_EQUALS("Wrong number of transforms to original reported.", 2, g.getNumberTransformsToOriginal()); } diff --git a/Code/Mantid/Framework/MDEvents/src/QueryMDWorkspace.cpp b/Code/Mantid/Framework/MDEvents/src/QueryMDWorkspace.cpp index 604d786b71a2..991057b9849c 100644 --- a/Code/Mantid/Framework/MDEvents/src/QueryMDWorkspace.cpp +++ b/Code/Mantid/Framework/MDEvents/src/QueryMDWorkspace.cpp @@ -264,7 +264,7 @@ namespace MDEvents output->cell(rowCounter, cellIndex++) = it->getNormalizedError(); output->cell(rowCounter, cellIndex++) = int(it->getNumEvents()); VMD center = it->getCenter(); - const size_t numberOriginal = input->numOriginalWorkspaces(); + const size_t numberOriginal = input->getNumberTransformsToOriginal(); if(numberOriginal > 0) { const size_t index = numberOriginal -1; diff --git a/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/MDGeometry.cpp b/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/MDGeometry.cpp index 26c2bf40481e..2a5223040dd6 100644 --- a/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/MDGeometry.cpp +++ b/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/MDGeometry.cpp @@ -90,6 +90,13 @@ void export_MDGeometry() .def("getOrigin", (const Mantid::Kernel::VMD & (MDGeometry::*)() const)&MDGeometry::getOrigin, return_value_policy(), "Returns the vector of the origin (in the original workspace) that corresponds to 0,0,0... in this workspace") + + .def("getNumberTransformsFromOriginal", &MDGeometry::getNumberTransformsFromOriginal, + "Returns the number of transformations from original workspace coordinate systems") + + .def("getNumberTransformsToOriginal", &MDGeometry::getNumberTransformsToOriginal, + "Returns the number of transformations to original workspace coordinate systems") + ; } diff --git a/Code/Mantid/MantidQt/API/src/MantidQwtIMDWorkspaceData.cpp b/Code/Mantid/MantidQt/API/src/MantidQwtIMDWorkspaceData.cpp index 2a7c3b763b4f..a47255f1f992 100644 --- a/Code/Mantid/MantidQt/API/src/MantidQwtIMDWorkspaceData.cpp +++ b/Code/Mantid/MantidQt/API/src/MantidQwtIMDWorkspaceData.cpp @@ -325,21 +325,32 @@ void MantidQwtIMDWorkspaceData::setPreviewMode(bool preview) { m_preview = preview; // If the workspace has no original, then we MUST be in preview mode. - if (preview || (m_workspace->numOriginalWorkspaces() == 0)) + const size_t nOriginalWorkspaces = m_workspace->numOriginalWorkspaces(); + if (preview || (nOriginalWorkspaces == 0)) { // Preview mode. No transformation. m_originalWorkspace = m_workspace; - m_transform = new NullCoordTransform(m_workspace->getNumDims()); } else { // Refer to the last workspace = the intermediate in the case of MDHisto binning - size_t index = m_workspace->numOriginalWorkspaces()-1; - m_originalWorkspace = boost::dynamic_pointer_cast(m_workspace->getOriginalWorkspace(index)); - CoordTransform * temp = m_workspace->getTransformToOriginal(index); + const size_t indexOfWS = nOriginalWorkspaces-1; // Get the last workspace + m_originalWorkspace = boost::dynamic_pointer_cast(m_workspace->getOriginalWorkspace(indexOfWS)); + } + + const size_t nTransformsToOriginal = m_workspace->getNumberTransformsToOriginal(); + if (preview || (nTransformsToOriginal == 0)) + { + m_transform = new NullCoordTransform(m_workspace->getNumDims()); + } + else + { + const size_t indexOfTransform = nTransformsToOriginal-1; // Get the last transform + CoordTransform * temp = m_workspace->getTransformToOriginal(indexOfTransform); if (temp) - m_transform = temp->clone(); + m_transform = temp->clone(); } + this->choosePlotAxis(); }