Skip to content

Commit

Permalink
Add a specialised QwtRasterData for views with only 2 dimensions
Browse files Browse the repository at this point in the history
It also doesn't use any overlays.
Refs #9319
  • Loading branch information
martyngigg committed Apr 23, 2014
1 parent 3e57ec1 commit cf192e7
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 8 deletions.
18 changes: 10 additions & 8 deletions Code/Mantid/MantidPlot/src/Spectrogram.cpp
Expand Up @@ -72,15 +72,17 @@ Spectrogram::Spectrogram(const Mantid::API::IMDWorkspace_const_sptr &workspace)
color_axis(QwtPlot::yRight),
color_map_policy(Default),mColorMap()
{
d_wsData = new MantidQt::API::QwtRasterDataMD;
d_wsData = new MantidQt::API::NoOverlayRaster2D;
d_wsData->setWorkspace(workspace);
d_wsData->setFastMode(false);
d_wsData->setNormalization(Mantid::API::NoNormalization);
d_wsData->setZerosAsNan(false);

// colour range
QwtDoubleInterval fullRange = MantidQt::API::SignalRange(*workspace).interval();
d_wsData->setRange(fullRange);

// X/Y axis ranges
auto dim0 = workspace->getDimension(0);
auto dim1 = workspace->getDimension(1);
Mantid::coord_t minX(dim0->getMinimum()), minY(dim1->getMinimum());
Expand Down Expand Up @@ -927,19 +929,19 @@ bool Spectrogram::isIntensityChanged()

/**
* Override QwtPlotSpectrogram::renderImage to draw ragged spectrograms. It is almost
* a copy of QwtPlotSpectrogram::renderImage except that pixels of the image that are
* a copy of QwtPlotSpectrogram::renderImage except that pixels of the image that are
* outside the boundaries of the histograms are set to a special colour (white).
*/
QImage Spectrogram::renderImage(
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
const QwtDoubleRect &area) const
{
// Mantid workspace handled in QwtRasterDataMD
if(d_wsData) return QwtPlotSpectrogram::renderImage(xMap,yMap,area);

MantidMatrixFunction* mantidFun = dynamic_cast<MantidMatrixFunction*>(d_funct);
if (!mantidFun)
{
return QwtPlotSpectrogram::renderImage(xMap,yMap,area);
}
// Not Mantid function so just use base class
auto *mantidFun = dynamic_cast<MantidMatrixFunction*>(d_funct);
if (!mantidFun) return QwtPlotSpectrogram::renderImage(xMap,yMap,area);

if ( area.isEmpty() )
return QImage();
Expand Down
10 changes: 10 additions & 0 deletions Code/Mantid/MantidQt/API/inc/MantidQtAPI/QwtRasterDataMD.h
Expand Up @@ -104,6 +104,16 @@ class QWT_EXPORT QwtRasterDataMD : public QwtRasterData
Mantid::API::MDNormalization m_normalization;
};

//-----------------------------------------------------------------
// Specialised class for 2D data with no overlays
//-----------------------------------------------------------------
class QWT_EXPORT NoOverlayRaster2D : public QwtRasterDataMD
{
public:
NoOverlayRaster2D* copy() const;
double value(double x, double y) const;
};

} // namespace SliceViewer
} // namespace Mantid

Expand Down
58 changes: 58 additions & 0 deletions Code/Mantid/MantidQt/API/src/QwtRasterDataMD.cpp
Expand Up @@ -3,6 +3,7 @@
#include "MantidGeometry/MDGeometry/MDTypes.h"
#include "MantidGeometry/MDGeometry/IMDDimension.h"
#include "MantidAPI/IMDWorkspace.h"
#include "MantidAPI/MatrixWorkspace.h"

namespace MantidQt
{
Expand Down Expand Up @@ -279,5 +280,62 @@ void QwtRasterDataMD::setSliceParams(size_t dimX, size_t dimY,
}
}

//===================================================================================
// NoOverlayRaster2D
//===================================================================================

/**
* Create a new object with the same state as this
* @return A pointer to a new object
*/
NoOverlayRaster2D *NoOverlayRaster2D::copy() const
{
auto* out = new NoOverlayRaster2D();
//base bounding box
out->setBoundingRect(this->boundingRect());

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_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;
out->m_fast = this->m_fast;
out->m_zerosAsNan = this->m_zerosAsNan;
out->m_normalization = this->m_normalization;

out->m_overlayWS = this->m_overlayWS;
out->m_overlayXMin = this->m_overlayXMin;
out->m_overlayXMax = this->m_overlayXMax;
out->m_overlayYMin = this->m_overlayYMin;
out->m_overlayYMax = this->m_overlayYMax;
out->m_overlayInSlice = this->m_overlayInSlice;
return out;

}

/**
* Return the data value to plot at the given position specialized
* for a matrix workspace. There is no consideration for a
* slicing point. It simply plots the signal from the given
* coordinates
* @param x :: position in coordinates of the MDWorkspace
* @param y :: position in coordinates of the MDWorkspace
* @return signal to plot
*/
double NoOverlayRaster2D::value(double x, double y) const
{
coord_t lookPoint[2] = {static_cast<coord_t>(x), static_cast<coord_t>(y)};
signal_t value = m_ws->getSignalAtCoord(lookPoint, m_normalization);
if(value != value) // out of range
{
value = m_range.maxValue()*1.1;
}
return value;
}

} //namespace
} //namespace

0 comments on commit cf192e7

Please sign in to comment.