diff --git a/Vates/VatesAPI/inc/MantidVatesAPI/MDLoadingPresenter.h b/Vates/VatesAPI/inc/MantidVatesAPI/MDLoadingPresenter.h index eaf0abd5f3810b78ba81d1c80b8d8dcc7b352cfa..5fafd8b5a6130a982af54b753a38faa953d352b3 100644 --- a/Vates/VatesAPI/inc/MantidVatesAPI/MDLoadingPresenter.h +++ b/Vates/VatesAPI/inc/MantidVatesAPI/MDLoadingPresenter.h @@ -11,10 +11,6 @@ #include <string> #include <vector> -namespace { -Mantid::Kernel::Logger g_log("MDLoadingPresenter"); -} - class vtkUnstructuredGrid; namespace Mantid { namespace VATES { diff --git a/Vates/VatesAPI/inc/MantidVatesAPI/SaveMDWorkspaceToVTKImpl.h b/Vates/VatesAPI/inc/MantidVatesAPI/SaveMDWorkspaceToVTKImpl.h index d9e18957c9ea73a649af33f48c0d2bc74b2a0720..2a9210ac47a8c5c3e22adeb83159ec90315f2818 100644 --- a/Vates/VatesAPI/inc/MantidVatesAPI/SaveMDWorkspaceToVTKImpl.h +++ b/Vates/VatesAPI/inc/MantidVatesAPI/SaveMDWorkspaceToVTKImpl.h @@ -47,9 +47,10 @@ public: SaveMDWorkspaceToVTKImpl(); ~SaveMDWorkspaceToVTKImpl() {} void saveMDWorkspace(Mantid::API::IMDWorkspace_sptr workspace, - std::string filename, VisualNormalization normalization, - ThresholdRange_scptr thresholdRange, - int recursionDepth) const; + const std::string &filename, + VisualNormalization normalization, + ThresholdRange_scptr thresholdRange, int recursionDepth, + const std::string &compressorType) const; const static std::string structuredGridExtension; const static std::string unstructuredGridExtension; @@ -71,7 +72,8 @@ private: void setupMembers(); bool is4DWorkspace(Mantid::API::IMDWorkspace_sptr workspace) const; int writeDataSetToVTKFile(vtkXMLWriter *writer, vtkDataSet *dataSet, - std::string filename) const; + const std::string &filename, + vtkXMLWriter::CompressorType compressor) const; double selectTimeSliceValue(Mantid::API::IMDWorkspace_sptr workspace) const; std::string getFullFilename(std::string filename, bool isHistoWorkspace) const; diff --git a/Vates/VatesAPI/src/MDEWLoadingPresenter.cpp b/Vates/VatesAPI/src/MDEWLoadingPresenter.cpp index 274a550cff7d00fee74c7ddcfe9cc0acdc370ff7..33b1f390a9659dd4416b84f22628a1348fb44185 100644 --- a/Vates/VatesAPI/src/MDEWLoadingPresenter.cpp +++ b/Vates/VatesAPI/src/MDEWLoadingPresenter.cpp @@ -17,6 +17,10 @@ #include <vtkFieldData.h> #include <vtkDataSet.h> +namespace { +Mantid::Kernel::Logger g_log("MDEWLoadingPresenter"); +} + namespace Mantid { namespace VATES { /// Constructor diff --git a/Vates/VatesAPI/src/MDHWLoadingPresenter.cpp b/Vates/VatesAPI/src/MDHWLoadingPresenter.cpp index 6c09e52e1b9a05b27e2a4a0e76b69e916c7b3877..0439d1c6c0641478762ae3852f4d4c5d7ce0f437 100644 --- a/Vates/VatesAPI/src/MDHWLoadingPresenter.cpp +++ b/Vates/VatesAPI/src/MDHWLoadingPresenter.cpp @@ -23,6 +23,10 @@ #include <vtkFieldData.h> #include <vtkDataSet.h> +namespace { +Mantid::Kernel::Logger g_log("MDHWLoadingPresenter"); +} + namespace Mantid { namespace VATES { diff --git a/Vates/VatesAPI/src/MDLoadingPresenter.cpp b/Vates/VatesAPI/src/MDLoadingPresenter.cpp index 739284872fe6dcf55bab9487f3be3bc41f33f621..90e45ff14b3a846e25eee66afa68eaae5b192171 100644 --- a/Vates/VatesAPI/src/MDLoadingPresenter.cpp +++ b/Vates/VatesAPI/src/MDLoadingPresenter.cpp @@ -1,5 +1,9 @@ #include "MantidVatesAPI/MDLoadingPresenter.h" +namespace { +Mantid::Kernel::Logger g_log("MDLoadingPresenter"); +} + namespace Mantid { namespace VATES { /** diff --git a/Vates/VatesAPI/src/SaveMDWorkspaceToVTK.cpp b/Vates/VatesAPI/src/SaveMDWorkspaceToVTK.cpp index 13cbff86b1fc40d616334217c6ba70b3f033e960..e7b77406bbe7a8aaf374806215c5010f57cbbee7 100644 --- a/Vates/VatesAPI/src/SaveMDWorkspaceToVTK.cpp +++ b/Vates/VatesAPI/src/SaveMDWorkspaceToVTK.cpp @@ -73,6 +73,11 @@ void SaveMDWorkspaceToVTK::init() { declareProperty("RecursionDepth", 5, mustBePositive, "The recursion depth is only required for MDEvent workspaces " "and determines to which level data should be displayed."); + + declareProperty("CompressorType", "NONE", + boost::make_shared<Mantid::Kernel::StringListValidator>( + std::vector<std::string>{"NONE", "ZLIB"}), + "Select which compression library to use"); } void SaveMDWorkspaceToVTK::exec() { @@ -92,9 +97,11 @@ void SaveMDWorkspaceToVTK::exec() { int recursionDepth = this->getProperty("RecursionDepth"); + std::string compressorType = this->getProperty("CompressorType"); + // Save workspace into file saver->saveMDWorkspace(inputWS, filename, normalization, thresholdRange, - recursionDepth); + recursionDepth, compressorType); } std::map<std::string, std::string> SaveMDWorkspaceToVTK::validateInputs() { diff --git a/Vates/VatesAPI/src/SaveMDWorkspaceToVTKImpl.cpp b/Vates/VatesAPI/src/SaveMDWorkspaceToVTKImpl.cpp index 4f33bb074d3d43c19377c75c3b747e241b9783c7..1d7440130c49f53cd459f63e419a020fca5c623e 100644 --- a/Vates/VatesAPI/src/SaveMDWorkspaceToVTKImpl.cpp +++ b/Vates/VatesAPI/src/SaveMDWorkspaceToVTKImpl.cpp @@ -1,13 +1,13 @@ -#include "MantidVatesAPI/Normalization.h" #include "MantidVatesAPI/SaveMDWorkspaceToVTKImpl.h" +#include "MantidVatesAPI/Normalization.h" #include "MantidVatesAPI/IgnoreZerosThresholdRange.h" #include "MantidVatesAPI/NoThresholdRange.h" +#include "MantidVatesAPI/FactoryChains.h" #include "MantidVatesAPI/MDEWInMemoryLoadingPresenter.h" #include "MantidVatesAPI/MDHWInMemoryLoadingPresenter.h" #include "MantidVatesAPI/MDLoadingViewSimple.h" -#include "MantidVatesAPI/FactoryChains.h" #include "MantidVatesAPI/PresenterFactories.h" #include "MantidVatesAPI/ProgressAction.h" #include "MantidVatesAPI/SingleWorkspaceProvider.h" @@ -15,6 +15,7 @@ #include "MantidAPI/IMDHistoWorkspace.h" #include "MantidGeometry/MDGeometry/IMDDimension.h" +#include "MantidKernel/Logger.h" #include "MantidKernel/make_unique.h" #include "vtkFloatArray.h" @@ -68,17 +69,31 @@ SaveMDWorkspaceToVTKImpl::SaveMDWorkspaceToVTKImpl() { setupMembers(); } * @param normalization: the visual normalization option * @param thresholdRange: a plolicy for the threshold range * @param recursionDepth: the recursion depth for MDEvent Workspaces determines + * @param compressorType: the compression type used by VTK * from which level data should be displayed */ void SaveMDWorkspaceToVTKImpl::saveMDWorkspace( - Mantid::API::IMDWorkspace_sptr workspace, std::string filename, + Mantid::API::IMDWorkspace_sptr workspace, const std::string &filename, VisualNormalization normalization, ThresholdRange_scptr thresholdRange, - int recursionDepth) const { + int recursionDepth, const std::string &compressorType) const { auto isHistoWorkspace = boost::dynamic_pointer_cast<Mantid::API::IMDHistoWorkspace>(workspace) != nullptr; auto fullFilename = getFullFilename(filename, isHistoWorkspace); + const vtkXMLWriter::CompressorType compressor = [&compressorType] { + if (compressorType == "NONE") { + return vtkXMLWriter::NONE; + } else if (compressorType == "ZLIB") { + return vtkXMLWriter::ZLIB; + } else { + // This should never happen. + Mantid::Kernel::Logger g_log("SaveMDWorkspaceToVTK"); + g_log.warning("Incorrect CompressorType: " + compressorType + + ". Using CompressorType=NONE."); + return vtkXMLWriter::NONE; + } + }(); // Define a time slice. auto time = selectTimeSliceValue(workspace); @@ -119,7 +134,8 @@ void SaveMDWorkspaceToVTKImpl::saveMDWorkspace( // Write the data to the file vtkSmartPointer<vtkXMLWriter> writer = getXMLWriter(isHistoWorkspace); - auto writeSuccessFlag = writeDataSetToVTKFile(writer, dataSet, fullFilename); + auto writeSuccessFlag = + writeDataSetToVTKFile(writer, dataSet, fullFilename, compressor); if (!writeSuccessFlag) { throw std::runtime_error("SaveMDWorkspaceToVTK: VTK could not write " "your data set to a file."); @@ -184,12 +200,17 @@ SaveMDWorkspaceToVTKImpl::getPresenter(bool isHistoWorkspace, * @param writer: a vtk xml writer * @param dataSet: the data set which is to be saved out * @param filename: the file name + * @param compressor: the compression type used by VTK * @returns a vtk error flag */ int SaveMDWorkspaceToVTKImpl::writeDataSetToVTKFile( - vtkXMLWriter *writer, vtkDataSet *dataSet, std::string filename) const { + vtkXMLWriter *writer, vtkDataSet *dataSet, const std::string &filename, + vtkXMLWriter::CompressorType compressor) const { writer->SetFileName(filename.c_str()); writer->SetInputData(dataSet); + writer->SetCompressorType(compressor); + // Required for large (>4GB?) files. + writer->SetHeaderTypeToUInt64(); return writer->Write(); } diff --git a/Vates/VatesAPI/test/SaveMDWorkspaceToVTKImplTest.h b/Vates/VatesAPI/test/SaveMDWorkspaceToVTKImplTest.h index 604d1b272630acb66aacc47b4fc0ce1346faafb7..3a06c37bdcac214ca4d278462587f52c2c419c55 100644 --- a/Vates/VatesAPI/test/SaveMDWorkspaceToVTKImplTest.h +++ b/Vates/VatesAPI/test/SaveMDWorkspaceToVTKImplTest.h @@ -215,7 +215,7 @@ private: saveMDToVTK.translateStringToThresholdRange(thresholds[0]); saveMDToVTK.saveMDWorkspace(workspace, filename, normalization, threshold, - recursionDepth); + recursionDepth, "NONE"); } Mantid::API::IMDWorkspace_sptr getTestWorkspace(std::string workspaceType) { diff --git a/Vates/VatesAPI/test/SaveMDWorkspaceToVTKTest.h b/Vates/VatesAPI/test/SaveMDWorkspaceToVTKTest.h index 27a929c189084260c3ad6ce9004f71b2f819aa38..46027ce611af122974485747c97a51fd71abd045 100644 --- a/Vates/VatesAPI/test/SaveMDWorkspaceToVTKTest.h +++ b/Vates/VatesAPI/test/SaveMDWorkspaceToVTKTest.h @@ -22,10 +22,11 @@ public: alg.setProperty("Normalization", "AutoSelect"); alg.setProperty("ThresholdRange", "IgnoreZerosThresholdRange"); alg.setProperty("RecursionDepth", 5); + alg.setProperty("CompressorType", "NONE"); // Act + Assert TSM_ASSERT_THROWS_ANYTHING( - "Wrong workspae type should cause the algorithm to throw", + "Wrong workspace type should cause the algorithm to throw", alg.execute()); } @@ -46,6 +47,7 @@ public: alg.setProperty("Normalization", "AutoSelect"); alg.setProperty("ThresholdRange", "IgnoreZerosThresholdRange"); alg.setProperty("RecursionDepth", 5); + alg.setProperty("CompressorType", "NONE"); // Act + Assert TSM_ASSERT_THROWS_ANYTHING( @@ -75,6 +77,7 @@ public: alg.setProperty("Normalization", "AutoSelect"); alg.setProperty("ThresholdRange", "IgnoreZerosThresholdRange"); alg.setProperty("RecursionDepth", 5); + alg.setProperty("CompressorType", "NONE"); // Act and Assert TSM_ASSERT_THROWS_NOTHING("Should save without any issues.", alg.execute()); diff --git a/docs/source/release/v3.9.0/ui.rst b/docs/source/release/v3.9.0/ui.rst index a146d75183a8f5ad60eff69b5acbed7cf208a6c3..bf0f32531016b4ab6b1ed84b73ac4bd09d8d1e99 100644 --- a/docs/source/release/v3.9.0/ui.rst +++ b/docs/source/release/v3.9.0/ui.rst @@ -27,6 +27,8 @@ Plotting Improvements Algorithm Toolbox ################# + - Add compressorType option to SaveMDWorkspaceToVTK. + Scripting Window ################