Skip to content

Commit

Permalink
Refs #3882: Switchable log/linear color scale in SliceViewer
Browse files Browse the repository at this point in the history
  • Loading branch information
Janik Zikovsky committed Nov 1, 2011
1 parent e7417cd commit 5a3a49b
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ class ColorBarWidget : public QWidget

void setColorMap(QwtColorMap * colorMap);
void setDataRange(double min, double max);
void setDataRange(QwtDoubleInterval range);
void setViewRange(double min, double max);
void setViewRange(QwtDoubleInterval range);
void setLog(bool log);

double getMinimum() const;
double getMaximum() const;
bool getLog() const;
QwtDoubleInterval getViewRange() const;

public slots:
void changedLogState(int);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,18 @@ class QWT_EXPORT QwtRasterDataMD : public QwtRasterData
public:
QwtRasterDataMD();
virtual ~QwtRasterDataMD();
QwtRasterData* copy() const;

void setWorkspace(Mantid::API::IMDWorkspace_sptr ws);

void setRange(QwtDoubleInterval & range)
{ m_range = range; }
QwtDoubleInterval range() const;
void setRange(const QwtDoubleInterval & range);

void setLogMode(bool log);
void setSliceParams(size_t dimX, size_t dimY, std::vector<Mantid::coord_t> & slicePoint);

double value(double x, double y) const;

QwtRasterData* copy() const;

QwtDoubleInterval range() const;

QSize rasterHint(const QwtDoubleRect &) const;

mutable size_t timesRequested;
Expand All @@ -41,6 +39,9 @@ class QWT_EXPORT QwtRasterDataMD : public QwtRasterData
/// Workspace being shown
Mantid::API::IMDWorkspace_sptr m_ws;

/// Is the log10 of the data being displayed?
bool m_logMode;

/// Number of dimensions
size_t m_nd;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ public slots:
void showInfoAt(double, double);
void colorRangeFullSlot();
void colorRangeSliceSlot();
void colorRangeChanged();
void zoomInSlot();
void zoomOutSlot();


private:
void initMenus();
void initZoomer();
Expand Down
8 changes: 8 additions & 0 deletions Code/Mantid/MantidQt/SliceViewer/src/ColorBarWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ double ColorBarWidget::getMaximum() const
bool ColorBarWidget::getLog() const
{ return m_log; }

/// @return then min/max range currently viewed
QwtDoubleInterval ColorBarWidget::getViewRange() const
{ return QwtDoubleInterval(m_min, m_max); }


//-------------------------------------------------------------------------------------------------
/** Change the color map shown
Expand Down Expand Up @@ -117,6 +121,8 @@ void ColorBarWidget::setDataRange(double min, double max)
m_rangeMax = max;
setSpinBoxesSteps();
}
void ColorBarWidget::setDataRange(QwtDoubleInterval range)
{ this->setDataRange(range.minValue(), range.maxValue()); }

//-------------------------------------------------------------------------------------------------
/** Set the range of values viewed in the color bar
Expand All @@ -130,6 +136,8 @@ void ColorBarWidget::setViewRange(double min, double max)
m_max = max;
update();
}
void ColorBarWidget::setViewRange(QwtDoubleInterval range)
{ this->setViewRange(range.minValue(), range.maxValue()); }

//-------------------------------------------------------------------------------------------------
/** SLOT called when clicking the log button */
Expand Down
98 changes: 68 additions & 30 deletions Code/Mantid/MantidQt/SliceViewer/src/QwtRasterDataMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,71 @@ using namespace Mantid;
using namespace Mantid::API;
using Mantid::Geometry::IMDDimension_const_sptr;

//-------------------------------------------------------------------------
/// Constructor
QwtRasterDataMD::QwtRasterDataMD()
: m_slicePoint(NULL)
{
timesRequested = 0;
m_minVal = DBL_MAX;
m_maxVal = -DBL_MAX;
m_range = QwtDoubleInterval(0.0, 1.0);
m_logMode = true;
nan = std::numeric_limits<double>::quiet_NaN();
}


//-------------------------------------------------------------------------
/// Destructor
QwtRasterDataMD::~QwtRasterDataMD()
{
delete [] m_slicePoint;
}


//-------------------------------------------------------------------------
/** Perform a copy of this data object */
QwtRasterData* QwtRasterDataMD::copy() const
{
QwtRasterDataMD* out = new QwtRasterDataMD();
out->m_ws = this->m_ws;
out->m_logMode = this->m_logMode;
out->m_dimX = this->m_dimX;
out->m_dimY = this->m_dimY;
out->m_nd = this->m_nd;
out->m_minVal = this->m_minVal;
out->m_maxVal = this->m_maxVal;
out->m_range = this->m_range;
out->m_slicePoint = new coord_t[m_nd];
for (size_t d=0; d<m_nd; d++)
out->m_slicePoint[d] = this->m_slicePoint[d];
out->m_ws = this->m_ws;
return out;
}

//-------------------------------------------------------------------------
/** Set the data range (min/max) to display */
void QwtRasterDataMD::setRange(const QwtDoubleInterval & range)
{ m_range = range; }

//-------------------------------------------------------------------------
/** Sets whether to show the log10 of the data
* @param log :: true to use log color scaling.
*/
void QwtRasterDataMD::setLogMode(bool log)
{ m_logMode = log;
}


//-------------------------------------------------------------------------
/** Return the data value to plot at the given position
*
* @param x :: position in coordinates of the MDWorkspace
* @param y :: position in coordinates of the MDWorkspace
* @return signal to plot
*/
double QwtRasterDataMD::value(double x, double y) const
{
if (!m_ws) return 0;
// timesRequested++;
// if (timesRequested % 1000 == 0)
// std::cout << timesRequested/1000 << ", ";

// Generate the vector of coordinates, filling in X and Y
coord_t * lookPoint = new coord_t[m_nd];
Expand All @@ -46,42 +88,38 @@ double QwtRasterDataMD::value(double x, double y) const
signal_t value = m_ws->getSignalAtCoord(lookPoint);
if (value < m_minVal) m_minVal = value;
if (value > m_maxVal) m_maxVal = value;
// std::cout << x << "," << y << "=" << value << "\n";
delete [] lookPoint;

if (value <= 0.)
return nan;
if (m_logMode)
{
if (value <= 0.)
return nan;
else
return log10(value);
}
else
return log(value);
}

QwtRasterData* QwtRasterDataMD::copy() const
{
QwtRasterDataMD* out = new QwtRasterDataMD();
out->m_ws = this->m_ws;
out->m_dimX = this->m_dimX;
out->m_dimY = this->m_dimY;
out->m_nd = this->m_nd;
out->m_minVal = this->m_minVal;
out->m_maxVal = this->m_maxVal;
out->m_range = this->m_range;
out->m_slicePoint = new coord_t[m_nd];
for (size_t d=0; d<m_nd; d++)
out->m_slicePoint[d] = this->m_slicePoint[d];
out->m_ws = this->m_ws;
return out;
{
return value;
}
}


//------------------------------------------------------------------------------------------------------
/** Return the data range to show */
QwtDoubleInterval QwtRasterDataMD::range() const
{
double min = log(m_range.minValue());
double max = log(m_range.maxValue());
if (m_range.minValue() <= 0)
min = max-6;
return QwtDoubleInterval(min,max);
if (m_logMode)
{
double min = log10(m_range.minValue());
double max = log10(m_range.maxValue());
if (m_range.minValue() <= 0)
min = max-6;
return QwtDoubleInterval(min,max);
}
else
// Linear color plot
return m_range;

}


Expand Down
27 changes: 20 additions & 7 deletions Code/Mantid/MantidQt/SliceViewer/src/SliceViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ SliceViewer::SliceViewer(QWidget *parent)
{
ui.setupUi(this);


// Create the plot
m_spectLayout = new QHBoxLayout(ui.frmPlot);
m_plot = new QwtPlot();
Expand All @@ -53,20 +52,23 @@ SliceViewer::SliceViewer(QWidget *parent)
m_spect = new QwtPlotSpectrogram();
m_spect->attach(m_plot);

m_colorMap = new QwtLinearColorMap(Qt::blue, Qt::red);
QwtDoubleInterval range(0.0, 10.0);
// ---- Default Color Map ------
m_colorMap = new QwtLinearColorMap(Qt::blue, Qt::red);
QwtDoubleInterval range(0.0, 10.0);

m_data = new QwtRasterDataMD();
m_spect->setColorMap(*m_colorMap);
m_plot->autoRefresh();


// --- Create a color bar on the right axis ---------------
m_colorBar = new ColorBarWidget(this);
m_colorBar->setColorMap(m_colorMap);
m_colorBar->setDataRange( range.minValue(), range.maxValue() );
m_colorBar->setViewRange( range.minValue(), range.maxValue() );
m_colorBar->setLog(true);
m_spectLayout->addWidget(m_colorBar, 0, 0);
QObject::connect(m_colorBar, SIGNAL(changedColorRange(double,double,bool)), this, SLOT(colorRangeChanged()));

// m_colorBar = m_plot->axisWidget(QwtPlot::yRight);
// m_colorBar->setColorBarEnabled(true);
Expand Down Expand Up @@ -271,7 +273,8 @@ void SliceViewer::setWorkspace(Mantid::API::IMDWorkspace_sptr ws)
m_data->setWorkspace(ws);
// Find the full range. And use it
findRangeFull();
m_colorRange = m_colorRangeFull;
m_colorBar->setDataRange(m_colorRangeFull);
m_colorBar->setViewRange(m_colorRangeFull);
// Initial display update
this->updateDisplay(!m_firstWorkspaceOpen /*Force resetting the axes, the first time*/);

Expand All @@ -291,7 +294,8 @@ void SliceViewer::setWorkspace(Mantid::API::IMDWorkspace_sptr ws)
void SliceViewer::colorRangeFullSlot()
{
this->findRangeFull();
m_colorRange = m_colorRangeFull;
m_colorBar->setDataRange(m_colorRangeFull);
m_colorBar->setViewRange(m_colorRangeFull);
this->updateDisplay();
}

Expand All @@ -300,7 +304,14 @@ void SliceViewer::colorRangeFullSlot()
void SliceViewer::colorRangeSliceSlot()
{
this->findRangeSlice();
m_colorRange = m_colorRangeSlice;
m_colorBar->setViewRange(m_colorRangeSlice);
this->updateDisplay();
}

//------------------------------------------------------------------------------------
/// Slot called when the ColorBarWidget changes the range of colors
void SliceViewer::colorRangeChanged()
{
this->updateDisplay();
}

Expand Down Expand Up @@ -511,7 +522,9 @@ void SliceViewer::updateDisplay(bool resetAxes)
}

// Set the color range
m_data->setRange(m_colorRange);
m_data->setRange(m_colorBar->getViewRange());
m_data->setLogMode( m_colorBar->getLog() );

// m_colorBar->setColorMap(m_colorRange, m_colorMap);
// m_plot->setAxisScale(QwtPlot::yRight, m_colorRange.minValue(), m_colorRange.maxValue() );

Expand Down

0 comments on commit 5a3a49b

Please sign in to comment.