Skip to content

Commit

Permalink
Refs #5085: python interface to dynamic rebinning crashes
Browse files Browse the repository at this point in the history
I suspect it has to do with the threading going on when calling BinMD. Disabled for now
  • Loading branch information
Janik Zikovsky committed Apr 11, 2012
1 parent aaa5c36 commit 9db217e
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 3 deletions.
1 change: 1 addition & 0 deletions Code/Mantid/MantidPlot/mantidplotpy/proxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ class SliceViewerProxy(QtProxyObject):
"""Proxy for a C++ SliceViewer widget.
"""
# These are the exposed python method names
#slicer_methods = ["setWorkspace", "getWorkspaceName", "showControls", "openFromXML", "getImage", "saveImage", "copyImageToClipboard", "setFastRender", "getFastRender", "toggleLineMode", "setXYDim", "setXYDim", "getDimX", "getDimY", "setSlicePoint", "setSlicePoint", "getSlicePoint", "getSlicePoint", "setXYLimits", "getXLimits", "getYLimits", "zoomBy", "setXYCenter", "resetZoom", "loadColorMap", "setColorScale", "setColorScaleMin", "setColorScaleMax", "setColorScaleLog", "getColorScaleMin", "getColorScaleMax", "getColorScaleLog", "setColorScaleAutoFull", "setColorScaleAutoSlice", "setColorMapBackground", "setTransparentZeros", "setNormalization", "getNormalization", "setRebinThickness", "setRebinNumBins", "setRebinMode", "refreshRebin"]
slicer_methods = ["setWorkspace", "getWorkspaceName", "showControls", "openFromXML", "getImage", "saveImage", "copyImageToClipboard", "setFastRender", "getFastRender", "toggleLineMode", "setXYDim", "setXYDim", "getDimX", "getDimY", "setSlicePoint", "setSlicePoint", "getSlicePoint", "getSlicePoint", "setXYLimits", "getXLimits", "getYLimits", "zoomBy", "setXYCenter", "resetZoom", "loadColorMap", "setColorScale", "setColorScaleMin", "setColorScaleMax", "setColorScaleLog", "getColorScaleMin", "getColorScaleMax", "getColorScaleLog", "setColorScaleAutoFull", "setColorScaleAutoSlice", "setColorMapBackground", "setTransparentZeros", "setNormalization", "getNormalization"]

def __init__(self, toproxy):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ class EXPORT_OPT_MANTIDQT_SLICEVIEWER SliceViewer : public QWidget
void setNormalization(Mantid::API::MDNormalization norm);
Mantid::API::MDNormalization getNormalization() const;

/// Dynamic Rebinning-related Python bindings
void setRebinThickness(int dim, double thickness);
void setRebinNumBins(int xBins, int yBins);
void setRebinMode(bool mode, bool locked);
void refreshRebin();

signals:
/// Signal emitted when the X/Y index of the shown dimensions is changed
void changedShownDim(size_t dimX, size_t dimY);
Expand Down
60 changes: 60 additions & 0 deletions Code/Mantid/MantidQt/SliceViewer/src/SliceViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,66 @@ Mantid::API::MDNormalization SliceViewer::getNormalization() const
return m_data->getNormalization();
}


//------------------------------------------------------------------------------------
/** Set the thickness (above and below the plane) for dynamic rebinning.
*
* @param dim :: index of the dimension to adjust
* @param thickness :: thickness to set, in units of the dimension.
* @throw runtime_error if the dimension index is invalid or the thickness is <= 0.0.
*/
void SliceViewer::setRebinThickness(int dim, double thickness)
{
if (dim < 0 || dim >= static_cast<int>(m_dimWidgets.size()))
throw std::runtime_error("SliceViewer::setRebinThickness(): Invalid dimension index");
if (thickness <= 0.0)
throw std::runtime_error("SliceViewer::setRebinThickness(): Thickness must be > 0.0");
m_dimWidgets[dim]->setThickness(thickness);
}

//------------------------------------------------------------------------------------
/** Set the number of bins for dynamic rebinning.
*
* @param xBins :: number of bins in the viewed X direction
* @param yBins :: number of bins in the viewed Y direction
* @throw runtime_error if the number of bins is < 1
*/
void SliceViewer::setRebinNumBins(int xBins, int yBins)
{
if (xBins < 1 || yBins < 1)
throw std::runtime_error("SliceViewer::setRebinNumBins(): Number of bins must be >= 1");
m_dimWidgets[m_dimX]->setNumBins(xBins);
m_dimWidgets[m_dimY]->setNumBins(yBins);
}

//------------------------------------------------------------------------------------
/** Sets the SliceViewer in dynamic rebin mode.
* In this mode, the current view area (see setXYLimits()) is used as the
* limits to rebin.
* See setRebinNumBins() to adjust the number of bins in the X/Y dimensions.
* See setRebinThickness() to adjust the thickness in other dimensions.
*
* @param mode :: true for rebinning mode
* @param locked :: if true, then the rebinned area is only refreshed manually
* or when changing rebinning parameters.
*/
void SliceViewer::setRebinMode(bool mode, bool locked)
{
// The events associated with these controls will trigger a re-draw
m_syncRebinMode->toggle(mode);
m_syncRebinLock->toggle(locked);
}

//------------------------------------------------------------------------------------
/** When in dynamic rebinning mode, this refreshes the rebinned area to be the
* currently viewed area. See setXYLimits(), setRebinNumBins(), setRebinThickness()
*/
void SliceViewer::refreshRebin()
{
this->rebinParamsChanged();
}


//------------------------------------------------------------------------------------
/// Slot called when the btnDoLine button is checked/unchecked
void SliceViewer::LineMode_toggled(bool checked)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,18 @@ def test_fixedBinWidth(self):
self.assertEqual(liner.getNumBins(), 200)
self.assertAlmostEqual(liner.getBinWidth(), 0.025, 3)

#==========================================================================
#======================= Dynamic Rebinning ================================
#==========================================================================
# FIXME: Figure out why this fails
def xtest_DynamicRebinning(self):
sv = self.sv
sv.setRebinThickness(2, 1.0)
sv.setRebinNumBins(50, 200)
sv.refreshRebin()
sv.setRebinMode(True, True)
time.sleep(1)
self.assertTrue(mtd.workspaceExists('uniform_binned'), 'Dynamically rebinned workspace was created.')



Expand Down
6 changes: 5 additions & 1 deletion Code/Mantid/MantidQt/mantidqt.in.sip
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,11 @@ public:
void setNormalization(Mantid::API::MDNormalization norm);
Mantid::API::MDNormalization getNormalization() const;


// //*WIKI* ==== Dynamic Rebinning ====
// void setRebinThickness(int dim, double thickness) throw (std::runtime_error);
// void setRebinNumBins(int xBins, int yBins) throw (std::runtime_error);
// void setRebinMode(bool mode, bool locked) throw (std::runtime_error);
// void refreshRebin() throw (std::runtime_error);
};


Expand Down
6 changes: 5 additions & 1 deletion Code/Mantid/MantidQt/mantidqt.rhel5.sip
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,11 @@ public:
Mantid::API::MDNormalization getNormalization() const;



// //*WIKI* ==== Dynamic Rebinning ====
// void setRebinThickness(int dim, double thickness) throw (std::runtime_error);
// void setRebinNumBins(int xBins, int yBins) throw (std::runtime_error);
// void setRebinMode(bool mode, bool locked) throw (std::runtime_error);
// void refreshRebin() throw (std::runtime_error);
};


Expand Down
6 changes: 5 additions & 1 deletion Code/Mantid/MantidQt/mantidqt.sip
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,11 @@ Mantid::API::MDNormalization SliceViewer::getNormalization()
%End



// //*WIKI* ==== Dynamic Rebinning ====
// void setRebinThickness(int dim, double thickness) throw (std::runtime_error);
// void setRebinNumBins(int xBins, int yBins) throw (std::runtime_error);
// void setRebinMode(bool mode, bool locked) throw (std::runtime_error);
// void refreshRebin() throw (std::runtime_error);
};


Expand Down

0 comments on commit 9db217e

Please sign in to comment.