diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewFilters/RebinningCutterOperator/RebinningCutter.xml b/Code/Mantid/Vates/ParaviewPlugins/ParaViewFilters/RebinningCutterOperator/RebinningCutter.xml index b1cf1cbc2b075521cc75b7dc725fa2cc2c676aad..1eb5822a8c1cd6ddb7602e043176f7b6c40d7a87 100755 --- a/Code/Mantid/Vates/ParaviewPlugins/ParaViewFilters/RebinningCutterOperator/RebinningCutter.xml +++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewFilters/RebinningCutterOperator/RebinningCutter.xml @@ -76,19 +76,18 @@ information_only="1"> <SimpleStringInformationHelper /> </StringVectorProperty> + <StringVectorProperty + name="ThresholdRangeStrategyIndex" + command="SetThresholdRangeStrategyIndex" + number_of_elements="1" + default_values="0"> + </StringVectorProperty> <StringVectorProperty name="AppliedGeometryXML" command="SetAppliedGeometryXML" number_of_elements="1" default_values="--"> </StringVectorProperty> - <IntVectorProperty - name="User Defined Range" - command="SetUserDefinedRange" - number_of_elements="1" - default_values="0"> - <BooleanDomain name="bool"/> - </IntVectorProperty> </SourceProxy> </ProxyGroup> <!-- End RebinningCutter --> diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewFilters/RebinningCutterOperator/vtkRebinningCutter.cxx b/Code/Mantid/Vates/ParaviewPlugins/ParaViewFilters/RebinningCutterOperator/vtkRebinningCutter.cxx index d7b5686155688a08046e309922baf66d7cd062c3..117fd916e4f10542215b2be74c6431b226a75577 100755 --- a/Code/Mantid/Vates/ParaviewPlugins/ParaViewFilters/RebinningCutterOperator/vtkRebinningCutter.cxx +++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewFilters/RebinningCutterOperator/vtkRebinningCutter.cxx @@ -33,6 +33,9 @@ #include "MantidVatesAPI/vtkDataSetToGeometry.h" #include "MantidVatesAPI/GaussianThresholdRange.h" #include "MantidVatesAPI/UserDefinedThresholdRange.h" +#include "MantidVatesAPI/NoThresholdRange.h" +#include "MantidVatesAPI/IgnoreZerosThresholdRange.h" +#include "MantidVatesAPI/MedianAndBelowThresholdRange.h" #include "MantidGeometry/MDGeometry/MDGeometryXMLParser.h" #include "MantidGeometry/MDGeometry/MDGeometryXMLBuilder.h" @@ -138,7 +141,8 @@ m_presenter(new NullRebinningPresenter()), m_setup(Pending), m_timestep(0), m_thresholdMax(1e9), - m_thresholdMin(0) + m_thresholdMin(0), + m_thresholdMethodIndex(0) { this->SetNumberOfInputPorts(1); this->SetNumberOfOutputPorts(1); @@ -150,6 +154,34 @@ vtkRebinningCutter::~vtkRebinningCutter() delete m_presenter; } +void vtkRebinningCutter::configureThresholdRangeMethod() +{ + switch(m_thresholdMethodIndex) + { + case 0: + m_ThresholdRange = ThresholdRange_scptr(new IgnoreZerosThresholdRange()); + break; + case 1: + m_ThresholdRange = ThresholdRange_scptr(new NoThresholdRange()); + break; + case 2: + m_ThresholdRange = ThresholdRange_scptr(new MedianAndBelowThresholdRange()); + break; + case 3: + m_ThresholdRange = ThresholdRange_scptr(new UserDefinedThresholdRange(m_thresholdMin, m_thresholdMax)); + break; + } +} + +void vtkRebinningCutter::SetThresholdRangeStrategyIndex(std::string selectedStrategyIndex) +{ + int index = atoi(selectedStrategyIndex.c_str()); + if(index != m_thresholdMethodIndex) + { + m_thresholdMethodIndex = index; + this->Modified(); + } +} int vtkRebinningCutter::RequestData(vtkInformation* vtkNotUsed(request), vtkInformationVector**, vtkInformationVector *outputVector) @@ -159,14 +191,8 @@ int vtkRebinningCutter::RequestData(vtkInformation* vtkNotUsed(request), vtkInfo //Setup is not complete until metadata has been correctly provided. if(SetupDone == m_setup) { - if(true == m_userDefinedRange) - { - m_ThresholdRange = ThresholdRange_scptr(new UserDefinedThresholdRange(m_thresholdMin, m_thresholdMax)); - } - else - { - m_ThresholdRange = ThresholdRange_scptr(new GaussianThresholdRange(2, 10000)); //2 sigma, 10000 attempted samples - } + configureThresholdRangeMethod(); + //Updating again at this point is the only way to pick-up changes to clipping. m_presenter->updateModel(); @@ -276,9 +302,10 @@ void vtkRebinningCutter::SetApplyClip(int applyClip) void vtkRebinningCutter::SetUserDefinedRange(int userDefinedRange) { - if(m_userDefinedRange != userDefinedRange) + bool b_userDefinedRange = userDefinedRange == 1 ? true : false; + if(m_userDefinedRange != b_userDefinedRange) { - m_userDefinedRange = userDefinedRange; + m_userDefinedRange = b_userDefinedRange; this->Modified(); } } diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewFilters/RebinningCutterOperator/vtkRebinningCutter.h b/Code/Mantid/Vates/ParaviewPlugins/ParaViewFilters/RebinningCutterOperator/vtkRebinningCutter.h index a4906a61be49f114923fafaed034a21eee1e309a..2b9a1b82657e5814b0ba7441e3b03c73ee09a2b7 100755 --- a/Code/Mantid/Vates/ParaviewPlugins/ParaViewFilters/RebinningCutterOperator/vtkRebinningCutter.h +++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewFilters/RebinningCutterOperator/vtkRebinningCutter.h @@ -72,6 +72,7 @@ public: void SetApplyClip(int applyClip); const char* GetInputGeometryXML(); void SetUserDefinedRange(int userDefinedRange); + void SetThresholdRangeStrategyIndex(std::string selectedStrategyIndex); /// Paraview Related Commands. See *.xml proxy/property file -------------------------------- /// Called by presenter to force progress information updating. @@ -121,6 +122,8 @@ private: vtkRebinningCutter(const vtkRebinningCutter&); void operator = (const vtkRebinningCutter&); + void configureThresholdRangeMethod(); + /// handles overwriting of time ranges. void setTimeRange(vtkInformationVector* outputVector); @@ -141,6 +144,8 @@ private: bool m_userDefinedRange; /// Threshold range calculator. Mantid::VATES::ThresholdRange_scptr m_ThresholdRange; + + int m_thresholdMethodIndex; }; #endif diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/DimensionWidget.cpp b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/DimensionWidget.cpp index 454eed0e258ee66b266330d64e3e0279e983d456..0f7eac8f975441e7d685d6ab183fc5eab7b1489a 100644 --- a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/DimensionWidget.cpp +++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/DimensionWidget.cpp @@ -19,12 +19,20 @@ DimensionWidget::DimensionWidget(bool readOnlyLimits) using namespace Mantid::Geometry; QGridLayout* m_layout = new QGridLayout(); - QLabel* integratedLabel = new QLabel("Integrated"); + QLabel* integratedLabel = new QLabel("Int"); + integratedLabel->setToolTip("Collapse/Expand dimension"); m_layout->addWidget(integratedLabel, 0, 0, Qt::AlignLeft); m_ckIntegrated = new QCheckBox(); + m_ckIntegrated->setToolTip("Collapse/Expand dimension"); connect(m_ckIntegrated, SIGNAL(clicked(bool)), this, SLOT(integratedChanged(bool))); m_layout->addWidget(m_ckIntegrated, 0, 1, Qt::AlignLeft); + + m_nBinsLabel = new QLabel("Bins"); + m_layout->addWidget(m_nBinsLabel, 0, 2, Qt::AlignLeft); + m_nBinsBox = new QLineEdit(); + connect(m_nBinsBox, SIGNAL(editingFinished()), this, SLOT(nBinsListener())); + m_layout->addWidget(m_nBinsBox, 0, 3, Qt::AlignLeft); m_dimensionLabel = new QLabel(); m_layout->addWidget(m_dimensionLabel, 1, 0, Qt::AlignLeft); @@ -33,28 +41,18 @@ DimensionWidget::DimensionWidget(bool readOnlyLimits) connect(m_dimensionCombo,SIGNAL(activated(int)),this ,SLOT(dimensionSelectedListener())); m_layout->addWidget(m_dimensionCombo, 1, 1, Qt::AlignLeft); - m_nBinsLabel = new QLabel("Number of Bins"); - m_layout->addWidget(m_nBinsLabel, 2, 0, Qt::AlignLeft); - m_nBinsBox = new QLineEdit(); - connect(m_nBinsBox, SIGNAL(editingFinished()), this, SLOT(nBinsListener())); - m_layout->addWidget(m_nBinsBox, 2, 1, Qt::AlignLeft); + m_layout->addWidget(new QLabel("Min"), 1, 2, Qt::AlignLeft); + m_minBox = new QLineEdit(); + + connect(m_minBox, SIGNAL(editingFinished()), this, SLOT(minBoxListener())); + m_layout->addWidget(m_minBox, 1, 3, Qt::AlignLeft); - QLabel* maxLabel = new QLabel("Maximum"); - maxLabel->setText("Maximum"); - m_layout->addWidget(maxLabel, 3, 0, Qt::AlignLeft); + m_layout->addWidget(new QLabel("Max"), 1, 4, Qt::AlignLeft); m_maxBox = new QLineEdit(); - + connect(m_maxBox, SIGNAL(editingFinished()), this, SLOT(maxBoxListener())); - m_layout->addWidget(m_maxBox, 3, 1, Qt::AlignLeft); - - QLabel* minLabel = new QLabel(); - minLabel->setText("Minimum"); - m_layout->addWidget(minLabel, 4, 0, Qt::AlignLeft); - m_minBox = new QLineEdit(); + m_layout->addWidget(m_maxBox, 1, 5, Qt::AlignLeft); - connect(m_minBox, SIGNAL(editingFinished()), this, SLOT(minBoxListener())); - m_layout->addWidget(m_minBox, 4, 1, Qt::AlignLeft); - m_maxBox->setEnabled(!readOnlyLimits); m_minBox->setEnabled(!readOnlyLimits); diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/ThresholdRangeWidget.cpp b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/ThresholdRangeWidget.cpp index ededa9edf914b233c96b9f57dfd1ce143425a2e1..86780fac971b371090478444901bc3c2932c7713 100644 --- a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/ThresholdRangeWidget.cpp +++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/ThresholdRangeWidget.cpp @@ -2,8 +2,7 @@ #include <QLabel> #include <QLineEdit> #include <QGridLayout> -//#include <QBoxLayout> -#include <QCheckBox> +#include <QComboBox> #include <QPalette> #include <QFont> #include <boost/algorithm/string.hpp> @@ -11,37 +10,53 @@ ThresholdRangeWidget::ThresholdRangeWidget(double min, double max) { + QGridLayout* headerLayout = new QGridLayout(); + headerLayout->addWidget(new QLabel("Thresholds"), 0, 0, 1, 2, Qt::AlignCenter); + + QGridLayout* layout = new QGridLayout; + layout->addLayout(headerLayout, 0, 1); - QGridLayout* layout = new QGridLayout(); - layout->addWidget(new QLabel("Threshold Ranges"), 0 , 0 , 1, 2, Qt::AlignCenter); - QLabel* thresholdMethodLabel = new QLabel("User Defined"); - layout->addWidget(thresholdMethodLabel, 1, 0, Qt::AlignLeft); - m_ckUserDefined = new QCheckBox(); - m_ckUserDefined->setChecked(false); //Automatic selection by default. - connect(m_ckUserDefined, SIGNAL(clicked(bool)), this, SLOT(methodChanged(bool))); - layout->addWidget(m_ckUserDefined, 1, 1, Qt::AlignLeft); + m_thresholdStrategyComboBox = new QComboBox; + m_thresholdStrategyComboBox->addItem("Ignore Zeros"); + m_thresholdStrategyComboBox->addItem("No Threshold Range"); + m_thresholdStrategyComboBox->addItem("Median and Below"); + m_thresholdStrategyComboBox->addItem("User Defined"); + + connect(m_thresholdStrategyComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(strategySelectedListener(const QString &))); + layout->addWidget(m_thresholdStrategyComboBox, 1, 0, Qt::AlignLeft); - m_minLabel = new QLabel("Min signal"); m_minEditBox = new QLineEdit(); std::string minValueString = boost::str(boost::format("%0.2f") % min); m_minEditBox->setText(minValueString.c_str()); - layout->addWidget(m_minLabel, 2, 0, Qt::AlignLeft); - layout->addWidget(m_minEditBox, 2, 1, Qt::AlignLeft); + layout->addWidget(new QLabel("Min"), 1, 1, Qt::AlignLeft); + layout->addWidget(m_minEditBox, 1, 2, Qt::AlignLeft); m_minEditBox->setDisabled(true); //Disabled by default. connect(m_minEditBox, SIGNAL(textEdited(const QString &)), this, SLOT(minThresholdListener(const QString &))); - - m_maxLabel = new QLabel("Max signal"); + m_maxEditBox = new QLineEdit(); std::string maxValueString = boost::str(boost::format("%0.2f") % max); m_maxEditBox->setText(maxValueString.c_str()); m_maxEditBox->setDisabled(true); //Disabled by default - layout->addWidget(m_maxLabel, 3, 0, Qt::AlignLeft); - layout->addWidget(m_maxEditBox, 3, 1, Qt::AlignLeft); + layout->addWidget(new QLabel("Max"), 1, 3, Qt::AlignLeft); + layout->addWidget(m_maxEditBox, 1, 4, Qt::AlignLeft); connect(m_maxEditBox, SIGNAL(textEdited(const QString &)), this, SLOT(maxThresholdListener(const QString &))); this->setLayout(layout); } +void ThresholdRangeWidget::strategySelectedListener(const QString&) +{ + bool disableUserControls = true; + if(m_thresholdStrategyComboBox->currentText() == "User Defined") + { + disableUserControls = false; + } + m_maxEditBox->setDisabled(disableUserControls); + m_minEditBox->setDisabled(disableUserControls); + + emit chosenStrategyChanged(); +} + void ThresholdRangeWidget::maxThresholdListener(const QString &) { emit maxChanged(); @@ -78,23 +93,9 @@ QString ThresholdRangeWidget::getMinSignal() const return m_minEditBox->text(); } -bool ThresholdRangeWidget::getUserDefinedRange() const +QString ThresholdRangeWidget::getChosenStrategy() const { - return m_ckUserDefined->isChecked(); + std::string minValueString = boost::str(boost::format("%i") % m_thresholdStrategyComboBox->currentIndex()); + return QString(minValueString.c_str()); } -void ThresholdRangeWidget::methodChanged(bool) -{ - bool disableUserControls; - if(m_ckUserDefined->isChecked()) - { - disableUserControls = false; - } - else - { - disableUserControls = true; - } - m_maxEditBox->setDisabled(disableUserControls); - m_minEditBox->setDisabled(disableUserControls); - emit userDefinedChanged(true); -} diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/ThresholdRangeWidget.h b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/ThresholdRangeWidget.h index cf80cb870bfebb2b1fa31254bf8026aaae774008..2cfa3c6b0059276de1e12a26e59abbaae9cb0cd8 100644 --- a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/ThresholdRangeWidget.h +++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/ThresholdRangeWidget.h @@ -36,7 +36,7 @@ class QLabel; class QLayout; class QLineEdit; -class QCheckBox; +class QComboBox; class EXPORT_OPT_MANTIDPARVIEW ThresholdRangeWidget: public QWidget { @@ -45,7 +45,7 @@ Q_OBJECT public: Q_PROPERTY(QString MinSignal READ getMinSignal WRITE setMinSignal NOTIFY minChanged) Q_PROPERTY(QString MaxSignal READ getMaxSignal WRITE setMaxSignal NOTIFY maxChanged) -Q_PROPERTY(bool UserDefinedRange READ getUserDefinedRange WRITE setUserDefinedRange NOTIFY userDefinedChanged USER true) +Q_PROPERTY(QString ChosenStrategy READ getChosenStrategy WRITE setChosenStrategy NOTIFY chosenStrategyChanged) ThresholdRangeWidget(double min, double max); @@ -53,7 +53,7 @@ ThresholdRangeWidget(double min, double max); QString getMaxSignal() const; QString getMinSignal() const; -bool getUserDefinedRange() const; +QString getChosenStrategy() const; void setMaximum(double value); void setMinimum(double value); @@ -70,31 +70,30 @@ void setMaxSignal(QString value) UNUSED_ARG(value); } -void setUserDefinedRange(bool value) +void setChosenStrategy(QString value) { //Do nothing. UNUSED_ARG(value); } + Q_SIGNALS: void minChanged(); void maxChanged(); - void userDefinedChanged(bool checked); + void chosenStrategyChanged(); - private: +private: - QLabel* m_minLabel; - QLabel* m_maxLabel; QLineEdit* m_maxEditBox; QLineEdit* m_minEditBox; - QCheckBox* m_ckUserDefined; + QComboBox* m_thresholdStrategyComboBox; private slots: void maxThresholdListener(const QString &); void minThresholdListener(const QString &); - void methodChanged(bool); + void strategySelectedListener(const QString &); }; #endif \ No newline at end of file diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/RebinningCutterObjectPanel/RebinningCutterObjectPanel.cxx b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/RebinningCutterObjectPanel/RebinningCutterObjectPanel.cxx index 1a59b51c952cf7222103c4d8b582880d746e5a9e..4f7fefbdea8d8f7a9d2e3301211de3a2d6b98198 100644 --- a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/RebinningCutterObjectPanel/RebinningCutterObjectPanel.cxx +++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/RebinningCutterObjectPanel/RebinningCutterObjectPanel.cxx @@ -112,7 +112,7 @@ void RebinningCutterObjectPanel::constructThresholdRanges(QGridLayout* gLayout) vtkSMProperty * maxThreshold = this->proxy()->GetProperty("MaxThreshold"); // Property used as setter - vtkSMProperty * userDefinedRange = this->proxy()->GetProperty("User Defined Range"); + vtkSMProperty * rangeStrategy = this->proxy()->GetProperty("ThresholdRangeStrategyIndex"); // Hook-up events to PV properties. this->propertyManager()->registerLink(m_thresholdWidget, "MinSignal", @@ -123,8 +123,8 @@ void RebinningCutterObjectPanel::constructThresholdRanges(QGridLayout* gLayout) SIGNAL(maxChanged()), this->proxy(), maxThreshold); // Hook-up events to PV properties. - this->propertyManager()->registerLink(m_thresholdWidget, "UserDefinedRange", - SIGNAL(userDefinedChanged(bool)), this->proxy(), userDefinedRange); + this->propertyManager()->registerLink(m_thresholdWidget, "ChosenStrategy", + SIGNAL(chosenStrategyChanged()), this->proxy(), rangeStrategy); m_cachedMaxThreshold = inputMaxThreshold; m_cachedMinThreshold = inputMinThreshold; @@ -140,7 +140,8 @@ void RebinningCutterObjectPanel::removeAutoGeneratedWidgets() popWidget(); // Autogenerated Max threshold QLabel popWidget(); // Autogenerated Min threshold QLineEdit popWidget(); // Autogenerated Min threshold QLabel - popWidget(); // Autogenerated User defined CheckBox. + popWidget(); // Autogenerated User defined ComboBox. + popWidget(); // Autogenerated User defined ComboBox. } /// Pop widgets off the layout and hide them. diff --git a/Code/Mantid/Vates/VatesAPI/src/IgnoreZerosThresholdRange.cpp b/Code/Mantid/Vates/VatesAPI/src/IgnoreZerosThresholdRange.cpp index 934a3d8af1f7dc1107b23251faa92781972bcea5..4ed1eef88546e23881afff8b2c4ab1de8443eee0 100644 --- a/Code/Mantid/Vates/VatesAPI/src/IgnoreZerosThresholdRange.cpp +++ b/Code/Mantid/Vates/VatesAPI/src/IgnoreZerosThresholdRange.cpp @@ -9,7 +9,7 @@ namespace Mantid /** Constructor. */ - IgnoreZerosThresholdRange::IgnoreZerosThresholdRange() : m_min(0), m_max(0) + IgnoreZerosThresholdRange::IgnoreZerosThresholdRange() : m_min(1), m_max(1) { } @@ -79,7 +79,10 @@ namespace Mantid bool IgnoreZerosThresholdRange::inRange(const signal_t& signal) { m_max = signal > m_max ? signal : m_max; //cache min and max values. - m_min = signal < m_min ? signal : m_min; + if(signal < m_min && 0 != signal) + { + m_min = signal < m_min ? signal : m_min; + } return signal != 0; } } diff --git a/Code/Mantid/Vates/VatesAPI/test/IgnoreZerosThresholdRangeTest.h b/Code/Mantid/Vates/VatesAPI/test/IgnoreZerosThresholdRangeTest.h index a0be190611a47501882814a27f9b4c2966bbc66f..7e6caab24ba2b449b649025f3a80431d3510bb77 100644 --- a/Code/Mantid/Vates/VatesAPI/test/IgnoreZerosThresholdRangeTest.h +++ b/Code/Mantid/Vates/VatesAPI/test/IgnoreZerosThresholdRangeTest.h @@ -37,6 +37,16 @@ public : TSM_ASSERT_EQUALS("Wrong min found", -2, range.getMinimum()); } + void testMinIsNeverZero() + { + IgnoreZerosThresholdRange range; + + range.inRange(0); + range.inRange(0.5); + range.inRange(2); + TSM_ASSERT_EQUALS("Wrong min found", 0.5, range.getMinimum()); + } + }; #endif \ No newline at end of file