Skip to content

Commit

Permalink
Use SignalRange class in SliceViewer.
Browse files Browse the repository at this point in the history
Refs #9319
  • Loading branch information
martyngigg committed Apr 23, 2014
1 parent 9f4e8bf commit e2bfea4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 96 deletions.
7 changes: 5 additions & 2 deletions Code/Mantid/MantidQt/API/inc/MantidQtAPI/SignalRange.h
Expand Up @@ -37,9 +37,11 @@ namespace MantidQt
class EXPORT_OPT_MANTIDQT_API SignalRange
{
public:
/// Create a full range from the given workspace and normalization
SignalRange(const Mantid::API::IMDWorkspace & workspace,
const Mantid::API::MDNormalization normalization = Mantid::API::NoNormalization);
SignalRange(const Mantid::API::IMDWorkspace & workspace,
Mantid::Geometry::MDImplicitFunction &function,
const Mantid::API::MDNormalization normalization = Mantid::API::NoNormalization);

/// Returns the range of the workspace signal values
QwtDoubleInterval interval() const;
Expand All @@ -48,7 +50,8 @@ namespace MantidQt
DISABLE_DEFAULT_CONSTRUCT(SignalRange);

/// Find the min/max signal values in the entire workspace
void findFullRange(const Mantid::API::IMDWorkspace & workspace);
void findFullRange(const Mantid::API::IMDWorkspace & workspace,
Mantid::Geometry::MDImplicitFunction *function);
/// Get the range of signal, in parallel, given an iterator
QwtDoubleInterval getRange(const std::vector<Mantid::API::IMDIterator *> & iterators);
///Get the range of signal given an iterator
Expand Down
Expand Up @@ -178,8 +178,6 @@ public slots:
void updateDisplay(bool resetAxes = false);
void updateDimensionSliceWidgets();
void resetAxis(int axis, const Mantid::Geometry::IMDDimension_const_sptr & dim);
QwtDoubleInterval getRange(Mantid::API::IMDIterator * it);
QwtDoubleInterval getRange(std::vector<Mantid::API::IMDIterator *> iterators);

void findRangeFull();
void findRangeSlice();
Expand Down
96 changes: 4 additions & 92 deletions Code/Mantid/MantidQt/SliceViewer/src/SliceViewer.cpp
Expand Up @@ -16,10 +16,11 @@
#include "MantidKernel/DataService.h"
#include "MantidKernel/Strings.h"
#include "MantidKernel/VMD.h"
#include "MantidQtAPI/QwtRasterDataMD.h"
#include "MantidQtAPI/SignalRange.h"
#include "MantidQtSliceViewer/CustomTools.h"
#include "MantidQtSliceViewer/DimensionSliceWidget.h"
#include "MantidQtSliceViewer/LineOverlay.h"
#include "MantidQtAPI/QwtRasterDataMD.h"
#include "MantidQtSliceViewer/SliceViewer.h"
#include "MantidQtSliceViewer/SnapToGridDialog.h"
#include "MantidQtSliceViewer/XYLimitsDialog.h"
Expand Down Expand Up @@ -1199,93 +1200,6 @@ void SliceViewer::resetAxis(int axis, const IMDDimension_const_sptr &dim)
m_plot->setAxisTitle( axis, API::PlotAxis(*dim).title());
}

//------------------------------------------------------------------------------------
/** Get the range of signal given an iterator
*
* @param it :: IMDIterator of what to find
* @return the min/max range, or INFINITY if not found
*/
QwtDoubleInterval SliceViewer::getRange(IMDIterator * it)
{
if (!it)
return QwtDoubleInterval(0., 1.0);
if (!it->valid())
return QwtDoubleInterval(0., 1.0);
// Use the current normalization
it->setNormalization(m_data->getNormalization());

double minSignal = DBL_MAX;
double maxSignal = -DBL_MAX;
do
{
double signal = it->getNormalizedSignal();
// Skip any 'infs' as it screws up the color scale
if (signal != m_inf)
{
if (signal > 0 && signal < minSignal) minSignal = signal;
if (signal > maxSignal) maxSignal = signal;
}
} while (it->next());


if (minSignal == DBL_MAX)
{
minSignal = m_inf;
maxSignal = m_inf;
}
return QwtDoubleInterval(minSignal, maxSignal);
}

//------------------------------------------------------------------------------------
/** Get the range of signal, in parallel, given an iterator
*
* @param iterators :: vector of IMDIterator of what to find
* @return the min/max range, or 0-1.0 if not found
*/
QwtDoubleInterval SliceViewer::getRange(std::vector<IMDIterator *> iterators)
{
std::vector<QwtDoubleInterval> intervals(iterators.size());
// cppcheck-suppress syntaxError
PRAGMA_OMP( parallel for schedule(dynamic, 1))
for (int i=0; i < int(iterators.size()); i++)
{
IMDIterator * it = iterators[i];
QwtDoubleInterval range = this->getRange(it);
intervals[i] = range;
delete it;
}

// Combine the overall min/max
double minSignal = DBL_MAX;
double maxSignal = -DBL_MAX;
for (size_t i=0; i < iterators.size(); i++)
{
double signal;
signal = intervals[i].minValue();
if (signal != m_inf && signal > 0 && signal < minSignal) minSignal = signal;

signal = intervals[i].maxValue();
if (signal != m_inf && signal > maxSignal) maxSignal = signal;
}

if (minSignal == DBL_MAX)
{
minSignal = 0.0;
maxSignal = 1.0;
}
if (minSignal < maxSignal)
return QwtDoubleInterval(minSignal, maxSignal);
else
{
if (minSignal != 0)
// Possibly only one value in range
return QwtDoubleInterval(minSignal*0.5, minSignal*1.5);
else
// Other default value
return QwtDoubleInterval(0., 1.0);
}
}

//------------------------------------------------------------------------------------
/// Find the full range of values in the workspace
void SliceViewer::findRangeFull()
Expand All @@ -1303,8 +1217,7 @@ void SliceViewer::findRangeFull()
ReadLock lock(*workspace_used);

// Iterate through the entire workspace
std::vector<IMDIterator *> iterators = workspace_used->createIterators(PARALLEL_GET_MAX_THREADS);
m_colorRangeFull = getRange(iterators);
m_colorRangeFull = API::SignalRange(*workspace_used, this->getNormalization()).interval();
}


Expand Down Expand Up @@ -1358,8 +1271,7 @@ void SliceViewer::findRangeSlice()
MDBoxImplicitFunction * function = new MDBoxImplicitFunction(min, max);

// Iterate through the slice
std::vector<IMDIterator *> iterators = m_ws->createIterators(PARALLEL_GET_MAX_THREADS, function);
m_colorRangeSlice = getRange(iterators);
m_colorRangeSlice = API::SignalRange(*workspace_used, *function, this->getNormalization()).interval();
delete function;
// In case of failure, use the full range instead
if (m_colorRangeSlice == QwtDoubleInterval(0.0, 1.0))
Expand Down

0 comments on commit e2bfea4

Please sign in to comment.