Skip to content

Commit

Permalink
Merge pull request #781 from mantidproject/feature/11814_set_recursio…
Browse files Browse the repository at this point in the history
…n_depth_for_top_level_split_to_1

Set recursion depth for top level split to 1
  • Loading branch information
OwenArnold committed Jun 1, 2015
2 parents 0a6e4bd + 5b63dd8 commit 1216797
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 4 deletions.
Expand Up @@ -10,6 +10,7 @@
#include "vtkUnstructuredGrid.h"
#include "vtkStreamingDemandDrivenPipeline.h"

#include "MantidVatesAPI/BoxInfo.h"
#include "MantidAPI/IMDWorkspace.h"
#include "MantidVatesAPI/MDEWInMemoryLoadingPresenter.h"
#include "MantidVatesAPI/MDLoadingViewAdapter.h"
Expand All @@ -20,6 +21,9 @@
#include "MantidVatesAPI/vtkMD0DFactory.h"
#include "MantidVatesAPI/FilteringUpdateProgressAction.h"
#include "MantidVatesAPI/IgnoreZerosThresholdRange.h"
#include "MantidKernel/WarningSuppressions.h"

#include <boost/optional.hpp>

using namespace Mantid::VATES;

Expand Down Expand Up @@ -231,6 +235,7 @@ int vtkMDEWSource::RequestData(vtkInformation *, vtkInformationVector **, vtkInf
return 1;
}

GCC_DIAG_OFF(strict-aliasing)
int vtkMDEWSource::RequestInformation(vtkInformation *vtkNotUsed(request), vtkInformationVector **vtkNotUsed(inputVector), vtkInformationVector *outputVector)
{
if(m_presenter == NULL && !m_wsName.empty())
Expand All @@ -242,6 +247,11 @@ int vtkMDEWSource::RequestInformation(vtkInformation *vtkNotUsed(request), vtkIn
}
else
{
// If the MDEvent workspace has had top level splitting applied to it, then use the a depth of 1
if (auto split = Mantid::VATES::findRecursionDepthForTopLevelSplitting(m_wsName)) {
SetDepth(split.get());
}

m_presenter->executeLoadMetadata();
setTimeRange(outputVector);
}
Expand Down Expand Up @@ -337,3 +347,4 @@ const char* vtkMDEWSource::GetWorkspaceName()
{
return m_wsName.c_str();
}

5 changes: 4 additions & 1 deletion Code/Mantid/Vates/VatesAPI/CMakeLists.txt
Expand Up @@ -5,6 +5,7 @@ project( VatesAPI )

set( SRC_FILES
src/ADSWorkspaceProvider.cpp
src/BoxInfo.cpp
src/Common.cpp
src/CompositePeaksPresenterVsi.cpp
src/ConcretePeaksPresenterVsi.cpp
Expand Down Expand Up @@ -62,6 +63,7 @@ src/SQWLoadingPresenter.cpp

set( INC_FILES
inc/MantidVatesAPI/ADSWorkspaceProvider.h
inc/MantidVatesAPI/BoxInfo.h
inc/MantidVatesAPI/Common.h
inc/MantidVatesAPI/CompositePeaksPresenterVsi.h
inc/MantidVatesAPI/ConcretePeaksPresenterVsi.h
Expand Down Expand Up @@ -133,6 +135,7 @@ test/vtkDataSetToImplicitFunctionTest.h
test/vtkDataSetToWsNameTest.h
test/vtkDataSetToWsLocationTest.h
test/ADSWorkspaceProviderTest.h
test/BoxInfoTest.h
test/DimensionPresenterTest.h
test/EventNexusLoadingPresenterTest.h
test/vtkDataSetFactoryTest.h
Expand Down Expand Up @@ -225,7 +228,7 @@ endif ()
if( CXXTEST_FOUND AND GMOCK_FOUND AND GTEST_FOUND )
include_directories ( SYSTEM ${CXXTEST_INCLUDE_DIR} ${GMOCK_INCLUDE_DIR} ${GTEST_INCLUDE_DIR} )

include_directories( inc ../../Framework/TestHelpers/inc ../../Framework/DataHandling/inc ../../Framework/DataObjects/inc)
include_directories( inc ../../Framework/TestHelpers/inc ../../Framework/DataHandling/inc ../../Framework/DataObjects/inc ../../Framework/MDAlgorithms/inc)
set ( TESTHELPER_SRCS ../../Framework/TestHelpers/src/ComponentCreationHelper.cpp
../../Framework/TestHelpers/src/WorkspaceCreationHelper.cpp
../../Framework/TestHelpers/src/MDEventsTestHelper.cpp
Expand Down
47 changes: 47 additions & 0 deletions Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/BoxInfo.h
@@ -0,0 +1,47 @@
#ifndef MANTID_VATESAPI_BOXINFO_H
#define MANTID_VATESAPI_BOXINFO_H

#include "MantidKernel/System.h"
#include <iostream>
#include <boost/optional.hpp>

namespace Mantid
{
namespace VATES
{
/**
Collection of functions related to box information
@date 21/05/2015
Copyright &copy; 2010 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>
*/

/**
* Function for finding an appropriate initial recursion depth.
* @param workspaceName :: name of the workspace
* @returns the appropriate recursion depth or nothing
*/
boost::optional<int> DLLExport findRecursionDepthForTopLevelSplitting(const std::string &workspaceName);
}
}

#endif
28 changes: 28 additions & 0 deletions Code/Mantid/Vates/VatesAPI/src/BoxInfo.cpp
@@ -0,0 +1,28 @@
#include "MantidVatesAPI/BoxInfo.h"
#include "MantidVatesAPI/ADSWorkspaceProvider.h"
#include "MantidAPI/IMDEventWorkspace.h"

using namespace Mantid::API;

namespace Mantid {
namespace VATES {
boost::optional<int> findRecursionDepthForTopLevelSplitting(const std::string &workspaceName) {
const int topLevelRecursionDepth = 1;
boost::optional<int> recursionDepth;
Mantid::VATES::ADSWorkspaceProvider<Mantid::API::IMDEventWorkspace>
workspaceProvider;
if (workspaceProvider.canProvideWorkspace(workspaceName)) {
auto workspace =
boost::dynamic_pointer_cast<Mantid::API::IMDEventWorkspace>(
workspaceProvider.fetchWorkspace(workspaceName));
auto boxController = workspace->getBoxController();
boost::optional<std::vector<size_t>> topLevelSplits =
boxController->getSplitTopInto();
if (boxController->getSplitTopInto()) {
recursionDepth = topLevelRecursionDepth;
}
}
return recursionDepth;
}
}
}
73 changes: 73 additions & 0 deletions Code/Mantid/Vates/VatesAPI/test/BoxInfoTest.h
@@ -0,0 +1,73 @@
#ifndef VATES_API_BOX_INFO_TEST_H_
#define VATES_API_BOX_INFO_TEST_H_



#include <cxxtest/TestSuite.h>

#include "MantidKernel/WarningSuppressions.h"
#include "MantidVatesAPI/BoxInfo.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/BoxController.h"
#include "MantidKernel/PropertyWithValue.h"
#include "MantidTestHelpers/MDEventsTestHelper.h"
#include "MantidDataObjects/MDLeanEvent.h"



using namespace Mantid::API;
using namespace Mantid::DataObjects;
using namespace Mantid::DataObjects::MDEventsTestHelper;
using namespace Mantid::Kernel;

class BoxInfoTest : public CxxTest::TestSuite {
public:
void test_initial_recursion_depth_is_empty_for_MD_Histo() {
// Arrange
const std::string wsName = "MD_HISTO_WS";
auto ws = makeFakeMDHistoWorkspace(1.0, 4, 5, 1.0, 0.1, wsName);

// Act + Assert
TSM_ASSERT("Should have no recursion depth for top level splitting.",
boost::none == Mantid::VATES::findRecursionDepthForTopLevelSplitting(wsName));

// Clean up
AnalysisDataService::Instance().remove(wsName);
}

void test_initial_recursion_depth_is_empty_for_MD_Event_wo_split() {
// Arrange
const std::string wsName = "MD_EVENT_WS";
auto ws = makeAnyMDEW<MDLeanEvent<3>, 3>(10, 0.0, 10.0, 1, wsName);

// Act + Assert
TSM_ASSERT("Should have no recursion depth for top level splitting.",
boost::none == Mantid::VATES::findRecursionDepthForTopLevelSplitting(wsName));

// Clean up
AnalysisDataService::Instance().remove(wsName);
}

GCC_DIAG_OFF(strict-aliasing)
void test_initial_recursion_depth_is_1_for_MD_Event_w_split() {
// Arrange
const std::string wsName = "MD_EVENT_WS_WITH_SPLITTING";
auto ws = makeAnyMDEW<MDLeanEvent<3>, 3>(10, 0.0, 10.0, 1, wsName);
BoxController_sptr boxController = ws->getBoxController();
boxController->setSplitTopInto(0,10);
boxController->setSplitTopInto(1, 20);
boxController->setSplitTopInto(2,30);

// Act
auto result = Mantid::VATES::findRecursionDepthForTopLevelSplitting(wsName);
// Assert

TSM_ASSERT("Should have recursion depth of 1 for top level splitting.",
result.get() == 1);

// Clean up
AnalysisDataService::Instance().remove(wsName);
}
};

#endif
19 changes: 16 additions & 3 deletions Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/ViewBase.cpp
@@ -1,7 +1,10 @@
#include "MantidVatesSimpleGuiViewWidgets/ViewBase.h"
#include "MantidVatesSimpleGuiViewWidgets/BackgroundRgbProvider.h"
#include "MantidVatesSimpleGuiViewWidgets/RebinnedSourcesManager.h"

#include "MantidVatesAPI/ADSWorkspaceProvider.h"
#include "MantidAPI/IMDEventWorkspace.h"
#include "MantidVatesAPI/BoxInfo.h"
#include "MantidKernel/WarningSuppressions.h"
#if defined(__INTEL_COMPILER)
#pragma warning disable 1170
#endif
Expand Down Expand Up @@ -37,6 +40,7 @@
#include <QPointer>
#include <QSet>

#include <boost/optional.hpp>
#include <stdexcept>

namespace Mantid
Expand Down Expand Up @@ -275,6 +279,7 @@ pqPipelineRepresentation *ViewBase::getPvActiveRep()
return qobject_cast<pqPipelineRepresentation *>(drep);
}

GCC_DIAG_OFF(strict-aliasing)
/**
* This function creates a ParaView source from a given plugin name and
* workspace name. This is used in the plugin mode of the simple interface.
Expand All @@ -292,6 +297,16 @@ pqPipelineSource* ViewBase::setPluginSource(QString pluginName, QString wsName)
vtkSMPropertyHelper(src->getProxy(),
"Mantid Workspace Name").Set(wsName.toStdString().c_str());

// WORKAROUND BEGIN
// We are setting the recursion depth to 1 when we are dealing with MDEvent workspaces
// with top level splitting, but this is not updated in the plugin line edit field.
// We do this here.
if (auto split = Mantid::VATES::findRecursionDepthForTopLevelSplitting(wsName.toStdString())) {
vtkSMPropertyHelper(src->getProxy(),
"Recursion Depth").Set(split.get());
}
// WORKAROUND END

// Update the source so that it retrieves the data from the Mantid workspace
src->getProxy()->UpdateVTKObjects(); // Updates all the proxies
src->updatePipeline(); // Updates the pipeline
Expand Down Expand Up @@ -898,8 +913,6 @@ void ViewBase::removeVisibilityListener() {
}
}



} // namespace SimpleGui
} // namespace Vates
} // namespace Mantid

0 comments on commit 1216797

Please sign in to comment.