Skip to content
Snippets Groups Projects
Commit 4267def9 authored by Jose Borreguero's avatar Jose Borreguero
Browse files

Refs #14936 Minimally working matrix viewer

parent 34dc4ddd
No related merge requests found
......@@ -6,12 +6,12 @@
<rect>
<x>0</x>
<y>0</y>
<width>535</width>
<height>654</height>
<width>613</width>
<height>850</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
......@@ -29,18 +29,24 @@
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupLoadSlices">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Loads Slices</string>
<string>Input</string>
</property>
<layout class="QGridLayout" name="loRangeBinning">
<property name="topMargin">
<number>0</number>
<number>9</number>
</property>
<property name="bottomMargin">
<number>0</number>
<number>9</number>
</property>
<item row="0" column="0">
<widget class="MantidQt::MantidWidgets::DataSelector" name="dataSelector"/>
<widget class="MantidQt::MantidWidgets::DataSelector" name="dataSelector" native="true"/>
</item>
</layout>
</widget>
......@@ -89,13 +95,26 @@
<layout class="QHBoxLayout" name="layout2Dview">
<item>
<widget class="QSlider" name="sliderSelectSlice">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="MantidQt::MantidWidgets::MWView" name="slices2DPlot"/>
<widget class="MantidQt::MantidWidgets::MWView" name="slices2DPlot" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
......@@ -108,7 +127,7 @@
<item>
<widget class="MantidQt::MantidWidgets::PreviewPlot" name="previewPlotSelectedSlice" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
......@@ -187,17 +206,6 @@
</widget>
</widget>
<customwidgets>
<customwidget>
<class>QwtPlot</class>
<extends>QFrame</extends>
<header>qwt_plot.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>MantidQt::MantidWidgets::MWView</class>
<extends>Qwidget</extends>
<header>MantidQtMantidWidgets/MWView.h</header>
</customwidget>
<customwidget>
<class>MantidQt::MantidWidgets::DataSelector</class>
<extends>QWidget</extends>
......@@ -209,6 +217,11 @@
<header>MantidQtMantidWidgets/PreviewPlot.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>MantidQt::MantidWidgets::MWView</class>
<extends>QWidget</extends>
<header>MantidQtMantidWidgets/MWView.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>spinboxSliceSelector</tabstop>
......
......@@ -84,7 +84,8 @@ void SliceSelector::loadSlices(const QString &workspaceName) {
m_uiForm.spinboxSliceSelector->setValue(0);
/// initialize the 2D view of the slices;
m_uiForm.slices2DPlot->setWorkspace(m_loadedWorkspace->m_ws);
m_uiForm.slices2DPlot->updateDisplay();
/// initialize the preview plot
updatePlotSelectedSlice();
......
......@@ -10,6 +10,7 @@
// includes for workspace handling
#include "MantidAPI/MatrixWorkspace_fwd.h"
#include "MantidAPI/IMDWorkspace.h"
#include "MantidGeometry/MDGeometry/MDHistoDimension.h"
namespace Mantid{
namespace API{
......@@ -27,6 +28,9 @@ class MdSettings;
namespace MantidWidgets {
class ColorBarWidget;
using MWDimension_sptr = boost::shared_ptr<Mantid::API::MWDimension>;
using MWDimension_const_sptr = boost::shared_ptr<const Mantid::API::MWDimension>;
/** A viewer for a Matrix Workspace.
*
* Before drawing, it acquires a ReadLock to prevent
......@@ -66,6 +70,7 @@ public:
~MWView();
void loadColorMap(QString filename = QString() );
void setWorkspace(Mantid::API::MatrixWorkspace_sptr ws);
void updateDisplay();
signals:
/// Signal emitted when someone uses setWorkspace() on MWView
......@@ -80,8 +85,9 @@ private:
void initLayout();
void loadSettings();
void saveSettings();
void updateDisplay();
void checkRangeLimits();
void findRangeFull();
void setVectorDimensions();
Ui::MWView m_uiForm;
/// Spectrogram plot of MWView
......@@ -94,9 +100,14 @@ private:
boost::shared_ptr<MantidQt::API::MdSettings> m_mdSettings;
/// Workspace being shown
Mantid::API::MatrixWorkspace_sptr m_workspace;
/// The calculated range of values in the FULL data set
QwtDoubleInterval m_colorRangeFull;
Mantid::API::MDNormalization m_normalization;
/// Vector of the dimensions to show.
std::vector<Mantid::Geometry::MDHistoDimension_sptr> m_dimensions;
};
} // namespace MantidWidgets
} // namespace MantidQt
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>941</width>
<height>718</height>
<width>706</width>
<height>462</height>
</rect>
</property>
<property name="windowTitle">
......@@ -18,16 +18,30 @@
<rect>
<x>19</x>
<y>19</y>
<width>911</width>
<height>691</height>
<width>681</width>
<height>441</height>
</rect>
</property>
<layout class="QHBoxLayout" name="viewer">
<item>
<widget class="MantidQt::MantidWidgets::SafeQwtPlot" name="plot2D"/>
<widget class="MantidQt::MantidWidgets::SafeQwtPlot" name="plot2D">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="MantidQt::MantidWidgets::ColorBarWidget" name="colorBar" native="true"/>
<widget class="MantidQt::MantidWidgets::ColorBarWidget" name="colorBar" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
......
......@@ -2,10 +2,17 @@
// includes for workspace handling
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidGeometry/MDGeometry/MDTypes.h"
#include "MantidKernel/ReadLock.h"
#include "MantidQtAPI/SignalRange.h"
#include "MantidGeometry/MDGeometry/IMDDimension.h"
#include "MantidGeometry/MDGeometry/MDHistoDimension.h"
#include <boost/pointer_cast.hpp>
#include <boost/shared_ptr.hpp>
// includes for interface development
#include "MantidQtAPI/QwtRasterDataMD.h"
#include "MantidQtAPI/MantidColorMap.h"
#include <qwt_color_map.h>
#include <qwt_double_rect.h>
namespace {
Mantid::Kernel::Logger g_log("MWView");
......@@ -19,9 +26,11 @@ namespace MantidWidgets {
// ++++++++++++++++++++++++++++++++
MWView::MWView(QWidget *parent)
: QWidget(parent), m_mdSettings{nullptr}, m_workspace{nullptr} {
: QWidget(parent), m_mdSettings{nullptr}, m_workspace{nullptr},
m_dimensions() {
m_spect = new QwtPlotSpectrogram();
m_data = new MantidQt::API::QwtRasterDataMD();
m_normalization = Mantid::API::NoNormalization;
this->initLayout();
this->loadSettings();
this->updateDisplay();
......@@ -55,11 +64,39 @@ void MWView::loadColorMap(QString filename) {
void MWView::setWorkspace(Mantid::API::MatrixWorkspace_sptr ws) {
m_workspace = ws;
this->checkRangeLimits();
this->setVectorDimensions();
findRangeFull(); // minimum and maximum intensities in ws
m_uiForm.colorBar->setViewRange(m_colorRangeFull);
m_uiForm.colorBar->updateColorMap();
m_data->setWorkspace(ws);
m_normalization = ws->displayNormalization();
m_data->setNormalization(m_normalization);
m_uiForm.plot2D->setWorkspace(ws);
m_spect->setColorMap(m_uiForm.colorBar->getColorMap());
emit workspaceChanged();
}
void MWView::updateDisplay() {
if (!m_workspace)
return;
m_data->setRange(m_uiForm.colorBar->getViewRange());
std::vector<Mantid::coord_t> slicePoint{0,0};
size_t dimX{0};
size_t dimY{1};
Mantid::Geometry::IMDDimension_const_sptr X = m_dimensions[dimX];
Mantid::Geometry::IMDDimension_const_sptr Y = m_dimensions[dimY];
m_data->setSliceParams(dimX, dimY, X, Y, slicePoint);
double left{X->getMinimum()};
double top{Y->getMinimum()};
double width{X->getMaximum()-X->getMinimum()};
double height{Y->getMaximum()-Y->getMinimum()};
QwtDoubleRect bounds{left,top,width, height};
m_data->setBoundingRect(bounds.normalized());
m_spect->setColorMap(m_uiForm.colorBar->getColorMap());
m_spect->setData(*m_data);
m_spect->itemChanged();
m_uiForm.plot2D->replot();
}
// ++++++++++++++++++++++++++++++++
// ++++++++ Public slots ++++++++
......@@ -141,17 +178,8 @@ void MWView::saveSettings() {
settings.setValue("TransparentZeros", (m_data->isZerosAsNan() ? 1 : 0));
}
void MWView::updateDisplay() {
if (!m_workspace)
return;
m_data->setRange(m_uiForm.colorBar->getViewRange());
m_spect->setData(*m_data);
m_spect->itemChanged();
m_uiForm.plot2D->replot();
}
// Verify workspace limits
void MWView::checkRangeLimits(){
void MWView::checkRangeLimits() {
std::ostringstream mess;
for (size_t d = 0; d < m_workspace->getNumDims(); d++) {
Mantid::coord_t min = m_workspace->getDimension(d)->getMinimum();
......@@ -171,11 +199,45 @@ void MWView::checkRangeLimits(){
if (!mess.str().empty()) {
mess << "Bad ranges could cause memory allocation errors. Please fix the "
"workspace.";
mess << std::endl
<< "You can continue using Mantid.";
mess << std::endl << "You can continue using Mantid.";
throw std::out_of_range(mess.str());
}
}
/// Find the full range of values in the workspace
void MWView::findRangeFull() {
if (!m_workspace)
return;
Mantid::API::MatrixWorkspace_sptr workspace_used = m_workspace;
// Acquire a scoped read-only lock on the workspace, preventing it from being
// written
// while we iterate through.
Mantid::Kernel::ReadLock lock(*workspace_used);
// Iterate through the entire workspace
m_colorRangeFull =
API::SignalRange(*workspace_used, m_normalization).interval();
double minR = m_colorRangeFull.minValue();
if (minR <= 0 && m_uiForm.colorBar->getScale() == 1) {
double maxR = m_colorRangeFull.maxValue();
minR = pow(10., log10(maxR) - 10.);
m_colorRangeFull = QwtDoubleInterval(minR, maxR);
}
}
/// Update m_dimensions with the loaded workspace
void MWView::setVectorDimensions() {
if (!m_workspace) {
return;
}
m_dimensions.clear();
for (size_t d = 0; d < m_workspace->getNumDims(); d++) {
Mantid::Geometry::MDHistoDimension_sptr dimension(
new Mantid::Geometry::MDHistoDimension(m_workspace->getDimension(d).get()));
m_dimensions.push_back(dimension);
}
}
} // namespace MantidQt
} // namespace MantidWidgets
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment