Skip to content

Commit

Permalink
Refs #4244: LineViewer bins the workspace in the background
Browse files Browse the repository at this point in the history
and so remains responsive even for large workspaces
  • Loading branch information
Janik Zikovsky committed Apr 23, 2012
1 parent f54a326 commit 7195dcb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "MantidAPI/CoordTransform.h"
#include "MantidQtAPI/MantidQwtIMDWorkspaceData.h"
#include "MantidQtSliceViewer/LinePlotOptions.h"
#include "MantidQtAPI/AlgorithmRunner.h"

namespace MantidQt
{
Expand Down Expand Up @@ -75,6 +76,7 @@ public slots:
void on_radNumBins_toggled();
void textBinWidth_changed();
void refreshPlot();
void lineIntegrationComplete(bool error);

signals:
/// Signal emitted when the planar width changes
Expand Down Expand Up @@ -115,6 +117,9 @@ public slots:
/// Widget to choose X plot axis and normalization
LinePlotOptions * m_lineOptions;

/// Object for running algorithms in the background
MantidQt::API::AlgorithmRunner * m_algoRunner;

// -------------------------- Data Members ----------------------------

/// Workspace being sliced
Expand All @@ -123,6 +128,9 @@ public slots:
/// Workspace of the slice
Mantid::API::IMDWorkspace_sptr m_sliceWS;

/// Name of the workspace that was integrated (asynchronously).
std::string m_integratedWSName;

/// Start point of the line
Mantid::Kernel::VMD m_start;
/// End point of the line
Expand Down
47 changes: 32 additions & 15 deletions Code/Mantid/MantidQt/SliceViewer/src/LineViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
#include "MantidQtAPI/MantidQwtIMDWorkspaceData.h"
#include "MantidAPI/NullCoordTransform.h"
#include "MantidQtSliceViewer/LinePlotOptions.h"
#include "MantidQtAPI/AlgorithmRunner.h"
#include "MantidAPI/AlgorithmManager.h"

using namespace Mantid;
using namespace Mantid::API;
using namespace Mantid::Kernel;
using Mantid::Geometry::IMDDimension_const_sptr;
using MantidQt::API::AlgorithmRunner;

namespace MantidQt
{
Expand Down Expand Up @@ -55,6 +58,9 @@ LineViewer::LineViewer(QWidget *parent)
m_lineOptions = new LinePlotOptions(this);
m_plotLayout->addWidget(m_lineOptions, 0);

// To run BinMD in the background
m_algoRunner = new AlgorithmRunner();
QObject::connect(m_algoRunner, SIGNAL(algorithmComplete(bool)), this, SLOT(lineIntegrationComplete(bool)));

// Make the splitter use the minimum size for the controls and not stretch out
ui.splitter->setStretchFactor(0, 0);
Expand Down Expand Up @@ -256,11 +262,12 @@ void LineViewer::apply()
{
if (m_allDimsFree)
throw std::runtime_error("Not currently supported with all dimensions free!");
m_algoRunner->cancelRunningAlgorithm();

// BinMD fails on MDHisto.
IMDHistoWorkspace_sptr mdhws = boost::dynamic_pointer_cast<IMDHistoWorkspace>(m_ws);

std::string outWsName = m_ws->getName() + "_line" ;
m_integratedWSName = m_ws->getName() + "_line" ;
bool adaptive = ui.chkAdaptiveBins->isChecked();

// (half-width in the plane)
Expand All @@ -284,19 +291,19 @@ void LineViewer::apply()
// This is the origin = Translation parameter
VMD origin = m_start;

IAlgorithm * alg = NULL;
IAlgorithm_sptr alg;
size_t numBins = m_numBins;
if (adaptive)
{
alg = FrameworkManager::Instance().createAlgorithm("SliceMD");
alg = AlgorithmManager::Instance().create("SliceMD");
// "SplitInto" parameter
numBins = 2;
}
else
alg = FrameworkManager::Instance().createAlgorithm("BinMD");
alg = AlgorithmManager::Instance().create("BinMD");

alg->setProperty("InputWorkspace", m_ws);
alg->setPropertyValue("OutputWorkspace", outWsName);
alg->setPropertyValue("OutputWorkspace", m_integratedWSName);
alg->setProperty("AxisAligned", false);

std::vector<int> OutputBins;
Expand Down Expand Up @@ -346,12 +353,28 @@ void LineViewer::apply()
{
alg->setProperty("IterateEvents", true);
}
alg->execute();

if (alg->isExecuted())
// Start the algorithm asynchronously
m_algoRunner->startAlgorithm(alg);

// In the mean time, change the title
m_plot->setTitle("Integrating Line...");
}

// ==============================================================================================
// ================================== SLOTS =====================================================
// ==============================================================================================

/** Slot called when the line integration algorithm (typically BinMD)
* has completed.
*
* @param error :: true if something went wrong
*/
void LineViewer::lineIntegrationComplete(bool error)
{
if (!error)
{
//m_sliceWS = alg->getProperty("OutputWorkspace");
m_sliceWS = AnalysisDataService::Instance().retrieveWS<IMDWorkspace>(outWsName);
m_sliceWS = AnalysisDataService::Instance().retrieveWS<IMDWorkspace>(m_integratedWSName);
this->showFull();
}
else
Expand All @@ -360,14 +383,8 @@ void LineViewer::apply()
this->showPreview();
m_plot->setTitle("Error integrating workspace - see log.");
}


}

// ==============================================================================================
// ================================== SLOTS =====================================================
// ==============================================================================================

//-------------------------------------------------------------------------------------------------
/** Slot called when the start text of a non-free dimensions is changed.
* Changes the end text correspondingly
Expand Down

0 comments on commit 7195dcb

Please sign in to comment.