From 1349be01e6e78d1f3ca446dfedd41a85e4908cf6 Mon Sep 17 00:00:00 2001 From: Owen Arnold <owen.arnold@stfc.ac.uk> Date: Tue, 1 Sep 2015 12:01:20 +0100 Subject: [PATCH] refs #13517. Add unit tests for new transpose behaviour. --- .../MDHWInMemoryLoadingPresenter.h | 135 ++--- .../inc/MantidVatesAPI/MDHWLoadingPresenter.h | 155 +++--- .../src/MDHWInMemoryLoadingPresenter.cpp | 79 +-- .../VatesAPI/src/MDHWLoadingPresenter.cpp | 513 ++++++++++-------- .../src/MDHWNexusLoadingPresenter.cpp | 6 +- .../VatesAPI/test/MDHWLoadingPresenterTest.h | 92 +++- .../test/MDHWNexusLoadingPresenterTest.h | 3 + Code/Mantid/Vates/VatesAPI/test/MockObjects.h | 17 +- 8 files changed, 541 insertions(+), 459 deletions(-) diff --git a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/MDHWInMemoryLoadingPresenter.h b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/MDHWInMemoryLoadingPresenter.h index c56d65686d8..892ee4a8815 100644 --- a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/MDHWInMemoryLoadingPresenter.h +++ b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/MDHWInMemoryLoadingPresenter.h @@ -7,70 +7,77 @@ #include <vector> class vtkDataSet; -namespace Mantid -{ - namespace API{ - class IMDHistoWorkspace; - } - namespace VATES - { - /** - @class MDHWInMemoryLoadingPresenter - Presenter for loading MDHWs directly from the ADS, does not touch the disk. - @date 02/12/2011 - - Copyright © 2011 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source - - This file is part of Mantid. - - Mantid is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - Mantid is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - File change history is stored at: <https://github.com/mantidproject/mantid> - Code Documentation is available at: <http://doxygen.mantidproject.org> - */ - - class MDLoadingView; - class WorkspaceProvider; - class MetaDataExtractorUtils; - class vtkDataSetFactory; - - class DLLExport MDHWInMemoryLoadingPresenter : public MDHWLoadingPresenter - { - public: - MDHWInMemoryLoadingPresenter(MDLoadingView* view, WorkspaceProvider* repository, std::string wsName); - virtual vtkDataSet* execute(vtkDataSetFactory* factory, ProgressAction& rebinningProgressUpdate, ProgressAction& drawingProgressUpdate); - virtual void executeLoadMetadata(); - virtual ~MDHWInMemoryLoadingPresenter(); - virtual bool canReadFile() const; - virtual std::string getWorkspaceTypeName(); - virtual int getSpecialCoordinates(); - std::vector<int> getExtents(); - private: - /// Transpose a workspace to push integrated dimensions to the last - boost::shared_ptr<Mantid::API::IMDHistoWorkspace> transposeWs(boost::shared_ptr<Mantid::API::IMDHistoWorkspace>& histoWs); - /// Repository for accessing workspaces. At this level, does not specify how or where from. - boost::scoped_ptr<WorkspaceProvider> m_repository; - /// The name of the workspace. - const std::string m_wsName; - /// The type name of the workspace - std::string m_wsTypeName; - /// The workspace special coordinate system - int m_specialCoords; - /// Cached visual histogram workspace. Post transpose. Avoids repeating transpose. - boost::shared_ptr<Mantid::API::IMDHistoWorkspace> m_cachedVisualHistoWs; - }; - } +namespace Mantid { +namespace API { +class IMDHistoWorkspace; +} +namespace VATES { +/** +@class MDHWInMemoryLoadingPresenter +Presenter for loading MDHWs directly from the ADS, does not touch the disk. +@date 02/12/2011 + +Copyright © 2011 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +National Laboratory & European Spallation Source + +This file is part of Mantid. + +Mantid is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Mantid is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +File change history is stored at: <https://github.com/mantidproject/mantid> +Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ + +class MDLoadingView; +class WorkspaceProvider; +class MetaDataExtractorUtils; +class vtkDataSetFactory; + +class DLLExport MDHWInMemoryLoadingPresenter : public MDHWLoadingPresenter { +public: + MDHWInMemoryLoadingPresenter(MDLoadingView *view, + WorkspaceProvider *repository, + std::string wsName); + virtual vtkDataSet *execute(vtkDataSetFactory *factory, + ProgressAction &rebinningProgressUpdate, + ProgressAction &drawingProgressUpdate); + virtual void executeLoadMetadata(); + virtual ~MDHWInMemoryLoadingPresenter(); + virtual bool canReadFile() const; + virtual std::string getWorkspaceTypeName(); + virtual int getSpecialCoordinates(); + std::vector<int> getExtents(); + +private: + + + /// Repository for accessing workspaces. At this level, does not specify how + /// or where from. + boost::scoped_ptr<WorkspaceProvider> m_repository; + /// The name of the workspace. + const std::string m_wsName; + /// The type name of the workspace + std::string m_wsTypeName; + /// The workspace special coordinate system + int m_specialCoords; + /// Cached visual histogram workspace. Post transpose. Avoids repeating + /// transpose. + boost::shared_ptr<Mantid::API::IMDHistoWorkspace> m_cachedVisualHistoWs; +}; + + +} } #endif diff --git a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/MDHWLoadingPresenter.h b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/MDHWLoadingPresenter.h index 51cc1ff323b..c6e023f131f 100644 --- a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/MDHWLoadingPresenter.h +++ b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/MDHWLoadingPresenter.h @@ -11,80 +11,87 @@ #include <boost/scoped_ptr.hpp> -namespace Mantid -{ - namespace VATES - { - - /** - @class MDHWLoadingPresenter - Abstract presenter encapsulating common operations used by all MDHW type loading. Reduces template bloat. - @author Owen Arnold, Tessella plc - @date 16/08/2011 - - Copyright © 2011 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source - - This file is part of Mantid. - - Mantid is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - Mantid is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - File change history is stored at: <https://github.com/mantidproject/mantid> - Code Documentation is available at: <http://doxygen.mantidproject.org> - */ - class MDLoadingView; - class DLLExport MDHWLoadingPresenter : public MDLoadingPresenter - { - public: - MDHWLoadingPresenter(MDLoadingView* view); - const std::string& getGeometryXML() const; - virtual bool hasTDimensionAvailable() const; - virtual std::vector<double> getTimeStepValues() const; - virtual std::string getTimeStepLabel() const; - virtual void setAxisLabels(vtkDataSet* visualDataSet); - virtual void makeNonOrthogonal(vtkDataSet* visualDataSet); - virtual ~MDHWLoadingPresenter(); - virtual const std::string& getInstrument(); - virtual double getMinValue(); - virtual double getMaxValue(); - - protected: - /*--------------------------------------------------------------------------- - Common/shared operations and members for all MDHW file-type loading. - ---------------------------------------------------------------------------*/ - MDLoadingView* m_view; - - Mantid::Geometry::MDGeometryBuilderXML<Mantid::Geometry::NoDimensionPolicy> xmlBuilder; - - Mantid::Geometry::IMDDimension_sptr tDimension; - std::vector<std::string> axisLabels; - virtual void appendMetadata(vtkDataSet* visualDataSet, - const std::string& wsName) ; - virtual void extractMetadata(Mantid::API::IMDHistoWorkspace_sptr histoWs); - virtual bool canLoadFileBasedOnExtension(const std::string& filename, - const std::string& expectedExtension) const; - virtual bool shouldLoad(); - bool m_isSetup; - double m_time; - bool m_loadInMemory; - bool m_firstLoad; - - boost::scoped_ptr<MetadataJsonManager> m_metadataJsonManager; - boost::scoped_ptr<MetaDataExtractorUtils> m_metaDataExtractor; - boost::scoped_ptr<VatesConfigurations> m_vatesConfigurations; - - }; - } +namespace Mantid { +namespace VATES { + +/** +@class MDHWLoadingPresenter +Abstract presenter encapsulating common operations used by all MDHW type +loading. Reduces template bloat. +@author Owen Arnold, Tessella plc +@date 16/08/2011 + +Copyright © 2011 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +National Laboratory & European Spallation Source + +This file is part of Mantid. + +Mantid is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Mantid is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +File change history is stored at: <https://github.com/mantidproject/mantid> +Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ +class MDLoadingView; +class DLLExport MDHWLoadingPresenter : public MDLoadingPresenter { +public: + MDHWLoadingPresenter(MDLoadingView *view); + const std::string &getGeometryXML() const; + virtual bool hasTDimensionAvailable() const; + virtual std::vector<double> getTimeStepValues() const; + virtual std::string getTimeStepLabel() const; + virtual void setAxisLabels(vtkDataSet *visualDataSet); + virtual void makeNonOrthogonal(vtkDataSet *visualDataSet); + virtual ~MDHWLoadingPresenter(); + virtual const std::string &getInstrument(); + virtual double getMinValue(); + virtual double getMaxValue(); + + /// Transpose a workspace to push integrated dimensions to the last + static void transposeWs( + Mantid::API::IMDHistoWorkspace_sptr &inHistoWs, + Mantid::API::IMDHistoWorkspace_sptr &outCachedHistoWs); + +protected: + /*--------------------------------------------------------------------------- + Common/shared operations and members for all MDHW file-type loading. + ---------------------------------------------------------------------------*/ + MDLoadingView *m_view; + + Mantid::Geometry::MDGeometryBuilderXML<Mantid::Geometry::NoDimensionPolicy> + xmlBuilder; + + Mantid::Geometry::IMDDimension_sptr tDimension; + std::vector<std::string> axisLabels; + virtual void appendMetadata(vtkDataSet *visualDataSet, + const std::string &wsName); + virtual void extractMetadata(Mantid::API::IMDHistoWorkspace_sptr histoWs); + virtual bool + canLoadFileBasedOnExtension(const std::string &filename, + const std::string &expectedExtension) const; + virtual bool shouldLoad(); + bool m_isSetup; + double m_time; + bool m_loadInMemory; + bool m_firstLoad; + + boost::scoped_ptr<MetadataJsonManager> m_metadataJsonManager; + boost::scoped_ptr<MetaDataExtractorUtils> m_metaDataExtractor; + boost::scoped_ptr<VatesConfigurations> m_vatesConfigurations; +}; + + +} } #endif diff --git a/Code/Mantid/Vates/VatesAPI/src/MDHWInMemoryLoadingPresenter.cpp b/Code/Mantid/Vates/VatesAPI/src/MDHWInMemoryLoadingPresenter.cpp index f438c62ee1b..cd33892016a 100644 --- a/Code/Mantid/Vates/VatesAPI/src/MDHWInMemoryLoadingPresenter.cpp +++ b/Code/Mantid/Vates/VatesAPI/src/MDHWInMemoryLoadingPresenter.cpp @@ -1,6 +1,5 @@ #include "MantidVatesAPI/MDHWInMemoryLoadingPresenter.h" #include "MantidAPI/AlgorithmManager.h" -#include "MantidAPI/IAlgorithm.h" #include "MantidAPI/IMDHistoWorkspace.h" #include "MantidVatesAPI/MDLoadingView.h" #include "MantidVatesAPI/MetaDataExtractorUtils.h" @@ -60,63 +59,6 @@ bool MDHWInMemoryLoadingPresenter::canReadFile() const { return bCanReadIt; } -/** - * @brief MDHWInMemoryLoadingPresenter::transposeWs - * - * vtkDataSets are usually provided in 3D, trying to create these where one of those dimensions - * might be integrated out leads to empty datasets. To avoid this we reorder the dimensions in our workspace - * prior to visualisation by transposing if if needed. - * - * @param histoWs : An input workspace that may integrated dimensions anywhere. - * @return A workspace that can be directly rendered from. Integrated dimensions are always last. - */ -Mantid::API::IMDHistoWorkspace_sptr MDHWInMemoryLoadingPresenter::transposeWs( - Mantid::API::IMDHistoWorkspace_sptr &histoWs) { - using namespace Mantid::API; - - if (!m_cachedVisualHistoWs) { - /* - Construct dimension indexes list for transpose. We do this by forcing - integrated - dimensions to be the last in the list. All other orderings are kept. - */ - std::vector<int> integratedDims; - std::vector<int> nonIntegratedDims; - for (int i = 0; i < int(histoWs->getNumDims()); ++i) { - auto dim = histoWs->getDimension(i); - if (dim->getIsIntegrated()) { - integratedDims.push_back(i); - } else { - nonIntegratedDims.push_back(i); - } - } - std::vector<int> orderedDims; - orderedDims = nonIntegratedDims; - orderedDims.insert(orderedDims.end(), integratedDims.begin(), - integratedDims.end()); - - /* - If there has been any reordering above, then the dimension indexes will - no longer be sorted. We use that to determine if we can avoid transposing the workspace. - */ - if (!std::is_sorted(orderedDims.begin(), orderedDims.end())) { - IAlgorithm_sptr alg = AlgorithmManager::Instance().create("TransposeMD"); - alg->setChild(true); - alg->initialize(); - alg->setProperty("InputWorkspace", histoWs); - alg->setPropertyValue("OutputWorkspace", "dummy"); - alg->setProperty("Axes", orderedDims); - alg->execute(); - IMDHistoWorkspace_sptr visualHistoWs = - alg->getProperty("OutputWorkspace"); - m_cachedVisualHistoWs = visualHistoWs; - } else { - // No need to transpose anything. - m_cachedVisualHistoWs = histoWs; - } - } - return m_cachedVisualHistoWs; -} /* Executes the underlying algorithm to create the MVP model. @@ -136,11 +78,11 @@ MDHWInMemoryLoadingPresenter::execute(vtkDataSetFactory *factory, IMDHistoWorkspace_sptr histoWs = boost::dynamic_pointer_cast<Mantid::API::IMDHistoWorkspace>(ws); - auto visualHistoWs = transposeWs(histoWs); + MDHWLoadingPresenter::transposeWs(histoWs, m_cachedVisualHistoWs); // factory->setRecursionDepth(this->m_view->getRecursionDepth()); vtkDataSet *visualDataSet = factory->oneStepCreate( - visualHistoWs, drawingProgressUpdate); // HACK: progressUpdate should be + m_cachedVisualHistoWs, drawingProgressUpdate); // HACK: progressUpdate should be // argument for drawing! /*extractMetaData needs to be re-run here because the first execution of this @@ -157,8 +99,9 @@ MDHWInMemoryLoadingPresenter::execute(vtkDataSetFactory *factory, this->m_metadataJsonManager->setMaxValue(range[1]); } - this->extractMetadata(visualHistoWs); + this->extractMetadata(m_cachedVisualHistoWs); + // Transposed workpace is temporary, outside the ADS, and does not have a name. so get it from pre-transposed. this->appendMetadata(visualDataSet, histoWs->getName()); return visualDataSet; } @@ -175,7 +118,7 @@ void MDHWInMemoryLoadingPresenter::executeLoadMetadata() { m_wsTypeName = histoWs->id(); m_specialCoords = histoWs->getSpecialCoordinateSystem(); - histoWs = transposeWs(histoWs); + MDHWLoadingPresenter::transposeWs(histoWs, m_cachedVisualHistoWs); // Set the minimum and maximum of the workspace data. QwtDoubleInterval minMaxContainer = @@ -185,13 +128,13 @@ void MDHWInMemoryLoadingPresenter::executeLoadMetadata() { // Set the instrument which is associated with the workspace. m_metadataJsonManager->setInstrument( - m_metaDataExtractor->extractInstrument(histoWs)); + m_metaDataExtractor->extractInstrument(m_cachedVisualHistoWs)); // Set the special coordinates m_metadataJsonManager->setSpecialCoordinates(m_specialCoords); // Call base-class extraction method. - this->extractMetadata(histoWs); + this->extractMetadata(m_cachedVisualHistoWs); } /// Destructor @@ -218,11 +161,11 @@ std::vector<int> MDHWInMemoryLoadingPresenter::getExtents() { Workspace_sptr ws = m_repository->fetchWorkspace(m_wsName); IMDHistoWorkspace_sptr histoWs = boost::dynamic_pointer_cast<Mantid::API::IMDHistoWorkspace>(ws); - histoWs = transposeWs(histoWs); + MDHWLoadingPresenter::transposeWs(histoWs, m_cachedVisualHistoWs); std::vector<int> extents(6, 0); - extents[1] = static_cast<int>(histoWs->getXDimension()->getNBins()); - extents[3] = static_cast<int>(histoWs->getYDimension()->getNBins()); - extents[5] = static_cast<int>(histoWs->getZDimension()->getNBins()); + extents[1] = static_cast<int>(m_cachedVisualHistoWs->getXDimension()->getNBins()); + extents[3] = static_cast<int>(m_cachedVisualHistoWs->getYDimension()->getNBins()); + extents[5] = static_cast<int>(m_cachedVisualHistoWs->getZDimension()->getNBins()); return extents; } } diff --git a/Code/Mantid/Vates/VatesAPI/src/MDHWLoadingPresenter.cpp b/Code/Mantid/Vates/VatesAPI/src/MDHWLoadingPresenter.cpp index 319edd9f331..94604ad1e37 100644 --- a/Code/Mantid/Vates/VatesAPI/src/MDHWLoadingPresenter.cpp +++ b/Code/Mantid/Vates/VatesAPI/src/MDHWLoadingPresenter.cpp @@ -1,6 +1,8 @@ #include "MantidVatesAPI/MDHWLoadingPresenter.h" #include "MantidVatesAPI/MDLoadingView.h" +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/FrameworkManager.h" +#include "MantidAPI/IAlgorithm.h" #include "MantidAPI/IMDHistoWorkspace.h" #include "MantidGeometry/MDGeometry/MDHistoDimension.h" @@ -26,263 +28,300 @@ namespace { Mantid::Kernel::Logger g_log("MDHWLoadingPresenter"); } -namespace Mantid -{ - namespace VATES - { - /// Constructor - MDHWLoadingPresenter::MDHWLoadingPresenter(MDLoadingView* view) : - m_view(view), - m_isSetup(false), - m_time(-1), - m_loadInMemory(false), - m_firstLoad(true), - m_metadataJsonManager(new MetadataJsonManager()), - m_metaDataExtractor(new MetaDataExtractorUtils()), - m_vatesConfigurations(new VatesConfigurations()) - { - Mantid::API::FrameworkManager::Instance(); - } +namespace Mantid { +namespace VATES { - /// Destructor - MDHWLoadingPresenter::~MDHWLoadingPresenter() - { - } +/** + * @brief MDHWInMemoryLoadingPresenter::transposeWs + * + * vtkDataSets are usually provided in 3D, trying to create these where one of + *those dimensions + * might be integrated out leads to empty datasets. To avoid this we reorder the + *dimensions in our workspace + * prior to visualisation by transposing if if needed. + * + * @param inHistoWs : An input workspace that may integrated dimensions + *anywhere. + * @param outCachedHistoWs : Cached histo workspace. To write to if needed. + * @return A workspace that can be directly rendered from. Integrated dimensions + *are always last. + */ +void MDHWLoadingPresenter::transposeWs(Mantid::API::IMDHistoWorkspace_sptr &inHistoWs, + Mantid::API::IMDHistoWorkspace_sptr &outCachedHistoWs) { + using namespace Mantid::API; - /* - Extract the geometry and function information - @param histoWs : histogram workspace to get the information from. - */ - void MDHWLoadingPresenter::extractMetadata(Mantid::API::IMDHistoWorkspace_sptr histoWs) - { - using namespace Mantid::Geometry; - MDGeometryBuilderXML<NoDimensionPolicy> refresh; - xmlBuilder= refresh; //Reassign. - std::vector<IMDDimension_sptr> dimensions; - size_t nDimensions = histoWs->getNumDims(); - for (size_t d=0; d<nDimensions; d++) - { - IMDDimension_const_sptr inDim = histoWs->getDimension(d); - coord_t min = inDim->getMinimum(); - coord_t max = inDim->getMaximum(); - if (min > max) - { - min = 0.0; - max = 1.0; - } - //std::cout << "dim " << d << min << " to " << max << std::endl; - axisLabels.push_back(makeAxisTitle(inDim)); - MDHistoDimension_sptr dim(new MDHistoDimension(inDim->getName(), inDim->getName(), inDim->getUnits(), min, max, inDim->getNBins())); - dimensions.push_back(dim); + if (!outCachedHistoWs) { + /* + Construct dimension indexes list for transpose. We do this by forcing + integrated + dimensions to be the last in the list. All other orderings are kept. + */ + std::vector<int> integratedDims; + std::vector<int> nonIntegratedDims; + for (int i = 0; i < int(inHistoWs->getNumDims()); ++i) { + auto dim = inHistoWs->getDimension(i); + if (dim->getIsIntegrated()) { + integratedDims.push_back(i); + } else { + nonIntegratedDims.push_back(i); } + } + std::vector<int> orderedDims; + orderedDims = nonIntegratedDims; + orderedDims.insert(orderedDims.end(), integratedDims.begin(), + integratedDims.end()); - //Configuring the geometry xml builder allows the object panel associated with this reader to later - //determine how to display all geometry related properties. - if(nDimensions > 0) - { - xmlBuilder.addXDimension( dimensions[0] ); - } - if(nDimensions > 1) - { - xmlBuilder.addYDimension( dimensions[1] ); - } - if(nDimensions > 2) - { - xmlBuilder.addZDimension( dimensions[2] ); - } - if(nDimensions > 3) - { - tDimension = dimensions[3]; - xmlBuilder.addTDimension(tDimension); - } - m_isSetup = true; + /* + If there has been any reordering above, then the dimension indexes will + no longer be sorted. We use that to determine if we can avoid transposing + the workspace. + */ + if (!std::is_sorted(orderedDims.begin(), orderedDims.end())) { + IAlgorithm_sptr alg = AlgorithmManager::Instance().create("TransposeMD"); + alg->setChild(true); + alg->initialize(); + alg->setProperty("InputWorkspace", inHistoWs); + alg->setPropertyValue("OutputWorkspace", "dummy"); + alg->setProperty("Axes", orderedDims); + alg->execute(); + IMDHistoWorkspace_sptr visualHistoWs = + alg->getProperty("OutputWorkspace"); + outCachedHistoWs = visualHistoWs; + } else { + // No need to transpose anything. + outCachedHistoWs = inHistoWs; } + } +} - /** - Method determines whether loading/re-loading is necessary. - */ - bool MDHWLoadingPresenter::shouldLoad() - { - double viewTime = m_view->getTime(); - bool viewLoadInMemory = m_view->getLoadInMemory(); +/// Constructor +MDHWLoadingPresenter::MDHWLoadingPresenter(MDLoadingView *view) + : m_view(view), m_isSetup(false), m_time(-1), m_loadInMemory(false), + m_firstLoad(true), m_metadataJsonManager(new MetadataJsonManager()), + m_metaDataExtractor(new MetaDataExtractorUtils()), + m_vatesConfigurations(new VatesConfigurations()) { + Mantid::API::FrameworkManager::Instance(); +} - bool bExecute = false; - if(m_time != viewTime) - { - bExecute = false; //Time has changed. This DOES NOT require reloading. - } - if(m_loadInMemory != viewLoadInMemory) - { - bExecute = true; //Must reload with memory/file option. - } - if(m_firstLoad) - { - bExecute = true; //First time round. should execute underlying algorithm. - } +/// Destructor +MDHWLoadingPresenter::~MDHWLoadingPresenter() {} - // Save state. - m_time = viewTime; - m_loadInMemory = viewLoadInMemory; - m_firstLoad = false; - //Return decision. - return bExecute; - } - - /** - Determines wheter the file can be loaded based on it's extension. - @param filename containing the extension - @param expectedExtension expected extension for the file to have - @return TRUE, only if the extension is approved. - */ - bool MDHWLoadingPresenter::canLoadFileBasedOnExtension(const std::string& filename, const std::string& expectedExtension) const - { - // Quick check based on extension. - const size_t startExtension = filename.find_last_of('.'); - const size_t endExtension = filename.length(); - std::string extension = filename.substr(startExtension, endExtension - startExtension); - boost::algorithm::to_lower(extension); - boost::algorithm::trim(extension); - return extension == expectedExtension; +/* +Extract the geometry and function information +@param histoWs : histogram workspace to get the information from. +*/ +void MDHWLoadingPresenter::extractMetadata( + Mantid::API::IMDHistoWorkspace_sptr histoWs) { + using namespace Mantid::Geometry; + MDGeometryBuilderXML<NoDimensionPolicy> refresh; + xmlBuilder = refresh; // Reassign. + std::vector<IMDDimension_sptr> dimensions; + size_t nDimensions = histoWs->getNumDims(); + for (size_t d = 0; d < nDimensions; d++) { + IMDDimension_const_sptr inDim = histoWs->getDimension(d); + coord_t min = inDim->getMinimum(); + coord_t max = inDim->getMaximum(); + if (min > max) { + min = 0.0; + max = 1.0; } + // std::cout << "dim " << d << min << " to " << max << std::endl; + axisLabels.push_back(makeAxisTitle(inDim)); + MDHistoDimension_sptr dim( + new MDHistoDimension(inDim->getName(), inDim->getName(), + inDim->getUnits(), min, max, inDim->getNBins())); + dimensions.push_back(dim); + } - /* - Append the geometry and function information onto the outgoing vtkDataSet. - @param visualDataSet : outgoing dataset on which to append metadata. - @param wsName : name of the workspace. - */ - void MDHWLoadingPresenter::appendMetadata(vtkDataSet* visualDataSet, const std::string& wsName) - { - using namespace Mantid::API; + // Configuring the geometry xml builder allows the object panel associated + // with this reader to later + // determine how to display all geometry related properties. + if (nDimensions > 0) { + xmlBuilder.addXDimension(dimensions[0]); + } + if (nDimensions > 1) { + xmlBuilder.addYDimension(dimensions[1]); + } + if (nDimensions > 2) { + xmlBuilder.addZDimension(dimensions[2]); + } + if (nDimensions > 3) { + tDimension = dimensions[3]; + xmlBuilder.addTDimension(tDimension); + } + m_isSetup = true; +} - vtkFieldData* outputFD = vtkFieldData::New(); - - //Serialize metadata - VatesKnowledgeSerializer serializer; - serializer.setWorkspaceName(wsName); - serializer.setGeometryXML(xmlBuilder.create()); - serializer.setImplicitFunction( Mantid::Geometry::MDImplicitFunction_sptr(new Mantid::Geometry::NullImplicitFunction())); - std::string xmlString = serializer.createXMLString(); - - // Serialize Json metadata - std::string jsonString = m_metadataJsonManager->getSerializedJson(); +/** +Method determines whether loading/re-loading is necessary. +*/ +bool MDHWLoadingPresenter::shouldLoad() { + double viewTime = m_view->getTime(); + bool viewLoadInMemory = m_view->getLoadInMemory(); - //Add metadata to dataset. - MetadataToFieldData convert; - convert(outputFD, xmlString, XMLDefinitions::metaDataId().c_str()); - convert(outputFD, jsonString, m_vatesConfigurations->getMetadataIdJson().c_str()); - visualDataSet->SetFieldData(outputFD); - outputFD->Delete(); - } + bool bExecute = false; + if (m_time != viewTime) { + bExecute = false; // Time has changed. This DOES NOT require reloading. + } + if (m_loadInMemory != viewLoadInMemory) { + bExecute = true; // Must reload with memory/file option. + } + if (m_firstLoad) { + bExecute = true; // First time round. should execute underlying algorithm. + } - /** - * Change the data based on non-orthogonal axis information - * @param visualDataSet : The VTK dataset to modify - */ - void MDHWLoadingPresenter::makeNonOrthogonal(vtkDataSet *visualDataSet) - { - std::string wsName = vtkDataSetToWsName::exec(visualDataSet); - vtkDataSetToNonOrthogonalDataSet converter(visualDataSet, wsName); - converter.execute(); - } + // Save state. + m_time = viewTime; + m_loadInMemory = viewLoadInMemory; + m_firstLoad = false; + // Return decision. + return bExecute; +} - /** - * Set the axis labels from the current dimensions - * @param visualDataSet: The VTK dataset to update - */ - void MDHWLoadingPresenter::setAxisLabels(vtkDataSet *visualDataSet) - { - if (!vtkPVChangeOfBasisHelper::AddBasisNames( - visualDataSet, axisLabels[0].c_str(), axisLabels[1].c_str(), - axisLabels[2].c_str())) { - g_log.warning("The basis names could not be added to the field data of " - "the data set.\n"); - } - } +/** +Determines wheter the file can be loaded based on it's extension. +@param filename containing the extension +@param expectedExtension expected extension for the file to have +@return TRUE, only if the extension is approved. +*/ +bool MDHWLoadingPresenter::canLoadFileBasedOnExtension( + const std::string &filename, const std::string &expectedExtension) const { + // Quick check based on extension. + const size_t startExtension = filename.find_last_of('.'); + const size_t endExtension = filename.length(); + std::string extension = + filename.substr(startExtension, endExtension - startExtension); + boost::algorithm::to_lower(extension); + boost::algorithm::trim(extension); + return extension == expectedExtension; +} - /** - Gets the geometry in a string format. - @return geometry string ref. - @throw runtime_error if execute has not been run first. - */ - const std::string& MDHWLoadingPresenter::getGeometryXML() const - { - if(!m_isSetup) - { - throw std::runtime_error("Have not yet run extractMetaData!"); - } - return xmlBuilder.create(); - } +/* +Append the geometry and function information onto the outgoing vtkDataSet. +@param visualDataSet : outgoing dataset on which to append metadata. +@param wsName : name of the workspace. +*/ +void MDHWLoadingPresenter::appendMetadata(vtkDataSet *visualDataSet, + const std::string &wsName) { + using namespace Mantid::API; - /** - @return boolean indicating whether the T dimension is available. - @throw runtime_error if execute has not been run first. - */ - bool MDHWLoadingPresenter::hasTDimensionAvailable() const - { - if(!m_isSetup) - { - throw std::runtime_error("Have not yet run ::extractMetaData!"); - } - return xmlBuilder.hasTDimension() && !xmlBuilder.hasIntegratedTDimension(); - } + vtkFieldData *outputFD = vtkFieldData::New(); - /* - @return timestep values. - @throw runtime_error if execute has not been run first. - */ - std::vector<double> MDHWLoadingPresenter::getTimeStepValues() const - { - if(!m_isSetup) - { - throw std::runtime_error("Have not yet run ::extractMetaData!"); - } - std::vector<double> result; - for(size_t i = 0; i < tDimension->getNBins(); i++) - { - result.push_back(tDimension->getX(i)); - } - return result; - } + // Serialize metadata + VatesKnowledgeSerializer serializer; + serializer.setWorkspaceName(wsName); + serializer.setGeometryXML(xmlBuilder.create()); + serializer.setImplicitFunction(Mantid::Geometry::MDImplicitFunction_sptr( + new Mantid::Geometry::NullImplicitFunction())); + std::string xmlString = serializer.createXMLString(); - /** - * Create a label for the "time" coordinate - * @return the "time" coordinate label - * @throw runtime_error if execute has not been run first. - */ - std::string MDHWLoadingPresenter::getTimeStepLabel() const - { - if (!m_isSetup) - { - throw std::runtime_error("Have not yet run ::extractMetaData!"); - } - return tDimension->getName() + " (" + tDimension->getUnits().ascii() + ")"; - } + // Serialize Json metadata + std::string jsonString = m_metadataJsonManager->getSerializedJson(); - /** - * Getter for the instrument. - * @returns The name of the instrument which is associated with the workspace. - */ - const std::string& MDHWLoadingPresenter::getInstrument() - { - return m_metadataJsonManager->getInstrument(); - } + // Add metadata to dataset. + MetadataToFieldData convert; + convert(outputFD, xmlString, XMLDefinitions::metaDataId().c_str()); + convert(outputFD, jsonString, + m_vatesConfigurations->getMetadataIdJson().c_str()); + visualDataSet->SetFieldData(outputFD); + outputFD->Delete(); +} - /** - * Getter for the minimum value; - * @return The minimum value of the data set. - */ - double MDHWLoadingPresenter::getMinValue() - { - return m_metadataJsonManager->getMinValue(); - } +/** + * Change the data based on non-orthogonal axis information + * @param visualDataSet : The VTK dataset to modify + */ +void MDHWLoadingPresenter::makeNonOrthogonal(vtkDataSet *visualDataSet) { + std::string wsName = vtkDataSetToWsName::exec(visualDataSet); + vtkDataSetToNonOrthogonalDataSet converter(visualDataSet, wsName); + converter.execute(); +} - /** - * Getter for the maximum value; - * @return The maximum value of the data set. - */ - double MDHWLoadingPresenter::getMaxValue() - { - return m_metadataJsonManager->getMaxValue(); - } +/** + * Set the axis labels from the current dimensions + * @param visualDataSet: The VTK dataset to update + */ +void MDHWLoadingPresenter::setAxisLabels(vtkDataSet *visualDataSet) { + if (!vtkPVChangeOfBasisHelper::AddBasisNames( + visualDataSet, axisLabels[0].c_str(), axisLabels[1].c_str(), + axisLabels[2].c_str())) { + g_log.warning("The basis names could not be added to the field data of " + "the data set.\n"); + } +} + +/** +Gets the geometry in a string format. +@return geometry string ref. +@throw runtime_error if execute has not been run first. +*/ +const std::string &MDHWLoadingPresenter::getGeometryXML() const { + if (!m_isSetup) { + throw std::runtime_error("Have not yet run extractMetaData!"); } + return xmlBuilder.create(); +} + +/** +@return boolean indicating whether the T dimension is available. +@throw runtime_error if execute has not been run first. +*/ +bool MDHWLoadingPresenter::hasTDimensionAvailable() const { + if (!m_isSetup) { + throw std::runtime_error("Have not yet run ::extractMetaData!"); + } + return xmlBuilder.hasTDimension() && !xmlBuilder.hasIntegratedTDimension(); +} + +/* +@return timestep values. +@throw runtime_error if execute has not been run first. +*/ +std::vector<double> MDHWLoadingPresenter::getTimeStepValues() const { + if (!m_isSetup) { + throw std::runtime_error("Have not yet run ::extractMetaData!"); + } + std::vector<double> result; + for (size_t i = 0; i < tDimension->getNBins(); i++) { + result.push_back(tDimension->getX(i)); + } + return result; +} + +/** + * Create a label for the "time" coordinate + * @return the "time" coordinate label + * @throw runtime_error if execute has not been run first. + */ +std::string MDHWLoadingPresenter::getTimeStepLabel() const { + if (!m_isSetup) { + throw std::runtime_error("Have not yet run ::extractMetaData!"); + } + return tDimension->getName() + " (" + tDimension->getUnits().ascii() + ")"; +} + +/** + * Getter for the instrument. + * @returns The name of the instrument which is associated with the workspace. + */ +const std::string &MDHWLoadingPresenter::getInstrument() { + return m_metadataJsonManager->getInstrument(); +} + +/** + * Getter for the minimum value; + * @return The minimum value of the data set. + */ +double MDHWLoadingPresenter::getMinValue() { + return m_metadataJsonManager->getMinValue(); +} + +/** + * Getter for the maximum value; + * @return The maximum value of the data set. + */ +double MDHWLoadingPresenter::getMaxValue() { + return m_metadataJsonManager->getMaxValue(); +} +} } diff --git a/Code/Mantid/Vates/VatesAPI/src/MDHWNexusLoadingPresenter.cpp b/Code/Mantid/Vates/VatesAPI/src/MDHWNexusLoadingPresenter.cpp index 2081e450c33..eec4a5a3b10 100644 --- a/Code/Mantid/Vates/VatesAPI/src/MDHWNexusLoadingPresenter.cpp +++ b/Code/Mantid/Vates/VatesAPI/src/MDHWNexusLoadingPresenter.cpp @@ -158,7 +158,11 @@ void MDHWNexusLoadingPresenter::loadWorkspace() alg->setProperty("FileBackEnd", !this->m_view->getLoadInMemory()); //Load from file by default. alg->execute(); Workspace_sptr result = AnalysisDataService::Instance().retrieve("MD_HISTO_WS_ID"); - m_histoWs = boost::dynamic_pointer_cast<Mantid::API::IMDHistoWorkspace>(result); + auto preTranspose = boost::dynamic_pointer_cast<Mantid::API::IMDHistoWorkspace>(result); + // Perform any necessary transpose. + MDHWLoadingPresenter::transposeWs(preTranspose, m_histoWs); + + } void MDHWNexusLoadingPresenter::loadWorkspace( ProgressAction& loadingProgressUpdate) diff --git a/Code/Mantid/Vates/VatesAPI/test/MDHWLoadingPresenterTest.h b/Code/Mantid/Vates/VatesAPI/test/MDHWLoadingPresenterTest.h index 6a23deae546..693e1e895c9 100644 --- a/Code/Mantid/Vates/VatesAPI/test/MDHWLoadingPresenterTest.h +++ b/Code/Mantid/Vates/VatesAPI/test/MDHWLoadingPresenterTest.h @@ -9,11 +9,13 @@ #include "MantidVatesAPI/MDHWLoadingPresenter.h" #include "MantidVatesAPI/MDLoadingView.h" +#include "MantidDataObjects/MDHistoWorkspace.h" #include "MockObjects.h" using namespace testing; using namespace Mantid::VATES; +using namespace Mantid::API; //===================================================================================== // Functional tests @@ -72,7 +74,7 @@ void testShouldLoadFirstTimeRound() MockMDLoadingView view; EXPECT_CALL(view, getRecursionDepth()).Times(0); EXPECT_CALL(view, getLoadInMemory()).Times(2); - EXPECT_CALL(view, getTime()).Times(2); + EXPECT_CALL(view, getTime()).Times(2).WillRepeatedly(Return(0)); EXPECT_CALL(view, updateAlgorithmProgress(_,_)).Times(0); ConcreteMDHWLoadingPresenter presenter(&view); @@ -106,7 +108,7 @@ void testLoadInMemoryChanged() EXPECT_CALL(view, getLoadInMemory()).Times(2) .WillOnce(Return(true)) .WillOnce(Return(false)); // Load in memory changed - EXPECT_CALL(view, getTime()).Times(2); + EXPECT_CALL(view, getTime()).Times(2).WillRepeatedly(Return(0)); EXPECT_CALL(view, updateAlgorithmProgress(_,_)).Times(0); ConcreteMDHWLoadingPresenter presenter(&view); @@ -119,7 +121,7 @@ void testLoadInMemoryChanged() void testhasTDimensionWhenIntegrated() { //Setup view - MockMDLoadingView* view = new MockMDLoadingView; + auto * view = new NiceMock<MockMDLoadingView>(); ConcreteMDHWLoadingPresenter presenter(view); @@ -128,12 +130,13 @@ void testhasTDimensionWhenIntegrated() presenter.extractMetadata(boost::dynamic_pointer_cast<Mantid::API::IMDHistoWorkspace>(ws)); TSM_ASSERT("This is a 4D workspace with an integrated T dimension", !presenter.hasTDimensionAvailable()); + delete view; } void testHasTDimensionWhenNotIntegrated() { //Setup view - MockMDLoadingView* view = new MockMDLoadingView; + auto * view = new NiceMock<MockMDLoadingView>(); ConcreteMDHWLoadingPresenter presenter(view); @@ -142,12 +145,13 @@ void testHasTDimensionWhenNotIntegrated() presenter.extractMetadata(boost::dynamic_pointer_cast<Mantid::API::IMDHistoWorkspace>(ws)); TSM_ASSERT("This is a 4D workspace with an integrated T dimension", presenter.hasTDimensionAvailable()); + delete view; } void testHasTimeLabelWithTDimension() { //Setup view - MockMDLoadingView* view = new MockMDLoadingView; + auto * view = new NiceMock<MockMDLoadingView>(); ConcreteMDHWLoadingPresenter presenter(view); @@ -156,12 +160,13 @@ void testHasTimeLabelWithTDimension() presenter.extractMetadata(boost::dynamic_pointer_cast<Mantid::API::IMDHistoWorkspace>(ws)); TSM_ASSERT_EQUALS("This is a 4D workspace with a T dimension", "D (A)", presenter.getTimeStepLabel()); + delete view; } void testCanSetAxisLabelsFrom3DData() { //Setup view - MockMDLoadingView* view = new MockMDLoadingView; + auto * view = new NiceMock<MockMDLoadingView>(); ConcreteMDHWLoadingPresenter presenter(view); @@ -176,12 +181,13 @@ void testCanSetAxisLabelsFrom3DData() getStringFieldDataValue(ds, "AxisTitleForY"), "B (A)"); TSM_ASSERT_EQUALS("Z Label should match exactly", getStringFieldDataValue(ds, "AxisTitleForZ"), "C (A)"); + delete view; } void testCanSetAxisLabelsFrom4DData() { //Setup view - MockMDLoadingView* view = new MockMDLoadingView; + auto * view = new NiceMock<MockMDLoadingView>(); ConcreteMDHWLoadingPresenter presenter(view); @@ -196,6 +202,78 @@ void testCanSetAxisLabelsFrom4DData() getStringFieldDataValue(ds, "AxisTitleForY"), "B (A)"); TSM_ASSERT_EQUALS("Z Label should match exactly", getStringFieldDataValue(ds, "AxisTitleForZ"), "C (A)"); + + delete view; +} + +Mantid::API::IMDHistoWorkspace_sptr makeHistoWorkspace(const std::vector<int> &shape){ + + IAlgorithm* create = FrameworkManager::Instance().createAlgorithm("CreateMDHistoWorkspace"); + create->setChild(true); + create->initialize(); + + const std::string allNames[5] = {"A", "B", "C", "D", "E"}; + const std::string allUnits[5] = {"AU", "BU", "CU", "DU", "EU"}; + + std::vector<std::string> names; + std::vector<std::string> units; + size_t flatSize = 1; + std::vector<double> extents; + for(size_t i = 0; i < shape.size(); ++i){ + flatSize *= shape[i]; + names.push_back(allNames[i]); + units.push_back(allUnits[i]); + extents.push_back(-10); + extents.push_back(10); + } + + create->setProperty("SignalInput", std::vector<double>(flatSize, 1)); + create->setProperty("ErrorInput", std::vector<double>(flatSize, 1)); + + create->setProperty("Dimensionality", int(shape.size())); + create->setProperty("Extents",extents); + create->setProperty("NumberOfBins", shape); + create->setProperty("Names", names); + create->setProperty("Units", units); + create->setPropertyValue("OutputWorkspace", "dummy"); + create->execute(); + IMDHistoWorkspace_sptr outWs = create->getProperty("OutputWorkspace"); + return outWs; +} + +void test_transpose_not_needed(){ + + //return outWs; + int shape[4] = {10, 10, 1}; // Well behaved input workspace. Integrated dim at end. + std::vector<int> shapeVec(shape, shape+3); + auto inWs = makeHistoWorkspace(shapeVec); + + IMDHistoWorkspace_sptr targetWs; + MDHWLoadingPresenter::transposeWs(inWs, targetWs); + + TS_ASSERT_EQUALS(targetWs->getNumDims(), inWs->getNumDims()); + TS_ASSERT_EQUALS(targetWs->getNPoints(), inWs->getNPoints()) + TS_ASSERT_EQUALS(targetWs->getDimension(0)->getName(), inWs->getDimension(0)->getName()); + TS_ASSERT_EQUALS(targetWs->getDimension(1)->getName(), inWs->getDimension(1)->getName()); + TS_ASSERT_EQUALS(targetWs->getDimension(2)->getName(), inWs->getDimension(2)->getName()); +} + +void test_transpose_rules_applied(){ + + //return outWs; + int shape[4] = {10, 10, 1, 10}; // Inproper input workspace. Needs transpose! + std::vector<int> shapeVec(shape, shape+4); + auto inWs = makeHistoWorkspace(shapeVec); + + IMDHistoWorkspace_sptr targetWs; + MDHWLoadingPresenter::transposeWs(inWs, targetWs); + + TS_ASSERT_EQUALS(targetWs->getNumDims(), inWs->getNumDims()); + TS_ASSERT_EQUALS(targetWs->getNPoints(), inWs->getNPoints()) + TS_ASSERT_EQUALS(targetWs->getDimension(0)->getName(), inWs->getDimension(0)->getName()); + TS_ASSERT_EQUALS(targetWs->getDimension(1)->getName(), inWs->getDimension(1)->getName()); + TSM_ASSERT_EQUALS("Integrated dims should be shifted to end", targetWs->getDimension(2)->getName(), inWs->getDimension(3)->getName()); + TSM_ASSERT_EQUALS("Integrated dims on the end", targetWs->getDimension(3)->getName(), inWs->getDimension(2)->getName()); } }; diff --git a/Code/Mantid/Vates/VatesAPI/test/MDHWNexusLoadingPresenterTest.h b/Code/Mantid/Vates/VatesAPI/test/MDHWNexusLoadingPresenterTest.h index 83063f3b3a4..9eee4ef3773 100644 --- a/Code/Mantid/Vates/VatesAPI/test/MDHWNexusLoadingPresenterTest.h +++ b/Code/Mantid/Vates/VatesAPI/test/MDHWNexusLoadingPresenterTest.h @@ -65,6 +65,7 @@ void testExecution() { //Setup view MockMDLoadingView* view = new MockMDLoadingView; + EXPECT_CALL(*view, getTime()).WillRepeatedly(Return(0)); EXPECT_CALL(*view, getRecursionDepth()).Times(AtLeast(0)); EXPECT_CALL(*view, getLoadInMemory()).Times(AtLeast(1)).WillRepeatedly(testing::Return(true)); EXPECT_CALL(*view, updateAlgorithmProgress(_,_)).Times(AnyNumber()); @@ -125,6 +126,7 @@ void testTimeLabel() { // Setup view MockMDLoadingView* view = new MockMDLoadingView; + EXPECT_CALL(*view, getTime()).WillRepeatedly(Return(0)); EXPECT_CALL(*view, getRecursionDepth()).Times(AtLeast(0)); EXPECT_CALL(*view, getLoadInMemory()).Times(AtLeast(1)).WillRepeatedly(testing::Return(true)); EXPECT_CALL(*view, updateAlgorithmProgress(_,_)).Times(AnyNumber()); @@ -155,6 +157,7 @@ void testAxisLabels() { //Setup view MockMDLoadingView* view = new MockMDLoadingView; + EXPECT_CALL(*view, getTime()).WillRepeatedly(Return(0)); EXPECT_CALL(*view, getRecursionDepth()).Times(AtLeast(0)); EXPECT_CALL(*view, getLoadInMemory()).Times(AtLeast(1)).WillRepeatedly(testing::Return(true)); EXPECT_CALL(*view, updateAlgorithmProgress(_,_)).Times(AnyNumber()); diff --git a/Code/Mantid/Vates/VatesAPI/test/MockObjects.h b/Code/Mantid/Vates/VatesAPI/test/MockObjects.h index 6527be6e5f5..ee3ae349b2a 100644 --- a/Code/Mantid/Vates/VatesAPI/test/MockObjects.h +++ b/Code/Mantid/Vates/VatesAPI/test/MockObjects.h @@ -425,17 +425,18 @@ Create a field data entry containing (as contents) the argument text. Mantid::API::Workspace_sptr createSimple3DWorkspace() { using namespace Mantid::API; - AnalysisDataService::Instance().remove("3D_Workspace"); - IAlgorithm* create = FrameworkManager::Instance().createAlgorithm("CreateMDWorkspace"); + IAlgorithm* create = FrameworkManager::Instance().createAlgorithm("CreateMDWorkspace"); + create->setChild(true); create->initialize(); create->setProperty("Dimensions", 4); create->setPropertyValue("Extents","0,5,0,5,0,5,0,5"); create->setPropertyValue("Names","A,B,C,D"); create->setPropertyValue("Units","A,A,A,A"); - create->setPropertyValue("OutputWorkspace", "3D_Workspace"); + create->setPropertyValue("OutputWorkspace", "dummy"); create->execute(); - return AnalysisDataService::Instance().retrieve("3D_Workspace"); + Workspace_sptr outWs = create->getProperty("OutputWorkspace"); + return outWs; } Mantid::API::Workspace_sptr get3DWorkspace(bool integratedTDimension, bool sliceMD) @@ -445,7 +446,6 @@ Create a field data entry containing (as contents) the argument text. Mantid::API::Workspace_sptr inputWs = createSimple3DWorkspace(); - AnalysisDataService::Instance().remove("binned"); std::string binningAlgName; if(sliceMD) { @@ -456,6 +456,7 @@ Create a field data entry containing (as contents) the argument text. binningAlgName = "BinMD"; } IAlgorithm_sptr binningAlg = AlgorithmManager::Instance().createUnmanaged(binningAlgName); + binningAlg->setChild(true); binningAlg->initialize(); binningAlg->setProperty("InputWorkspace", inputWs); binningAlg->setPropertyValue("AlignedDim0","A,0,5,2"); @@ -470,10 +471,10 @@ Create a field data entry containing (as contents) the argument text. { binningAlg->setPropertyValue("AlignedDim3","D,0,5,2"); } - binningAlg->setPropertyValue("OutputWorkspace", "binned"); + binningAlg->setPropertyValue("OutputWorkspace", "dummy"); binningAlg->execute(); - - return AnalysisDataService::Instance().retrieve("binned"); + Workspace_sptr outWs = binningAlg->getProperty("OutputWorkspace"); + return outWs; } /** -- GitLab