Skip to content

Commit

Permalink
Refs #4459 choose normalization in SliceViewer
Browse files Browse the repository at this point in the history
  • Loading branch information
Janik Zikovsky committed Feb 10, 2012
1 parent 11f0755 commit 8dc49c8
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 17 deletions.
7 changes: 4 additions & 3 deletions Code/Mantid/Framework/API/inc/MantidAPI/IMDWorkspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,19 @@ namespace Mantid
virtual IMDIterator* createIterator(Mantid::Geometry::MDImplicitFunction * function = NULL) const;

/// Returns the (normalized) signal at a given coordinates
virtual signal_t getSignalAtCoord(const coord_t * coords) const
virtual signal_t getSignalAtCoord(const coord_t * coords, const Mantid::API::MDNormalization & normalization) const
{
UNUSED_ARG(coords);
UNUSED_ARG(normalization);
throw std::runtime_error("getSignalAtCoord() not implemented.");
}

//-------------------------------------------------------------------------------------------
/// Returns the signal (normalized by volume) at a given coordinates
/// @param coords :: coordinate as a VMD vector
signal_t getSignalAtCoord(const Mantid::Kernel::VMD & coords) const
signal_t getSignalAtCoord(const Mantid::Kernel::VMD & coords, const Mantid::API::MDNormalization & normalization) const
{
return this->getSignalAtCoord(coords.getBareArray());
return this->getSignalAtCoord(coords.getBareArray(), normalization);
}

/// Method to generate a line plot through a MD-workspace
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/API/inc/MantidAPI/MatrixWorkspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ namespace Mantid

virtual void getLinePlot(const Mantid::Kernel::VMD & start, const Mantid::Kernel::VMD & end,
Mantid::API::MDNormalization normalize, std::vector<coord_t> & x, std::vector<signal_t> & y, std::vector<signal_t> & e) const;
virtual signal_t getSignalAtCoord(const coord_t * coords) const;
virtual signal_t getSignalAtCoord(const coord_t * coords, const Mantid::API::MDNormalization & normalization) const;
void saveSpectraMapNexus(::NeXus::File * file, const std::vector<int>& spec,
const ::NeXus::NXcompression compression = ::NeXus::LZW) const;

Expand Down
21 changes: 18 additions & 3 deletions Code/Mantid/Framework/API/src/MatrixWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,7 @@ namespace Mantid
}

/// Returns the (normalized) signal at a given coordinates
signal_t MatrixWorkspace::getSignalAtCoord(const coord_t * coords) const
signal_t MatrixWorkspace::getSignalAtCoord(const coord_t * coords, const Mantid::API::MDNormalization & normalization) const
{
coord_t x = coords[0];
coord_t y = coords[1];
Expand All @@ -1654,15 +1654,30 @@ namespace Mantid
{
size_t i = (it - X.begin());
if (i > 0)
return this->readY(wi)[i-1];
{
double y = this->readY(wi)[i-1];
// What is our normalization factor?
switch (normalization)
{
case NoNormalization:
return y;
case VolumeNormalization:
// TODO: calculate the Y size
return y / (X[i] - X[i-1]);
case NumEventsNormalization:
return y;
}
// This won't happen
return y;
}
else
return std::numeric_limits<double>::quiet_NaN();
}

}
else
// Out of range
return std::numeric_limits<double>::quiet_NaN();

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace MDEvents
virtual Mantid::API::IMDIterator* createIterator(Mantid::Geometry::MDImplicitFunction * function = NULL) const;

/// Returns the (normalized) signal at a given coordinates
virtual signal_t getSignalAtCoord(const coord_t * coords) const;
virtual signal_t getSignalAtCoord(const coord_t * coords, const Mantid::API::MDNormalization & normalization) const;

virtual void getLinePlot(const Mantid::Kernel::VMD & start, const Mantid::Kernel::VMD & end,
MDNormalization normalize, std::vector<coord_t> & x, std::vector<signal_t> & y, std::vector<signal_t> & e) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ namespace MDEvents
Mantid::Kernel::VMD getCenter(size_t linearIndex) const;

/// Returns the (normalized) signal at a given coordinates
signal_t getSignalAtCoord(const coord_t * coords) const;
signal_t getSignalAtCoord(const coord_t * coords, const Mantid::API::MDNormalization & normalization) const;

/// Sets the signal at the specified index.
void setSignalAt(size_t index, signal_t value)
Expand Down
18 changes: 16 additions & 2 deletions Code/Mantid/Framework/MDEvents/src/MDEventWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,11 @@ namespace MDEvents
/** Returns the (normalized) signal at a given coordinates
*
* @param coords :: nd-sized array of coordinates
* @param normalization :: how to normalize the signal.
* @return the normalized signal of the box at the given coordinates. NaN if out of bounds
*/
TMDE(
signal_t MDEventWorkspace)::getSignalAtCoord(const coord_t * coords) const
signal_t MDEventWorkspace)::getSignalAtCoord(const coord_t * coords, const Mantid::API::MDNormalization & normalization) const
{
// Do an initial bounds check
for (size_t d=0; d<nd; d++)
Expand All @@ -229,7 +230,20 @@ namespace MDEvents
// If you got here, then the point is in the workspace.
const IMDBox<MDE,nd> * box = data->getBoxAtCoord(coords);
if (box)
return box->getSignalNormalized();
{
// What is our normalization factor?
switch (normalization)
{
case NoNormalization:
return box->getSignal();
case VolumeNormalization:
return box->getInverseVolume() * box->getSignal();
case NumEventsNormalization:
return double(box->getNPoints()) * box->getSignal();
}
// Should not reach here
return box->getSignal();
}
else
return std::numeric_limits<signal_t>::quiet_NaN();
}
Expand Down
19 changes: 17 additions & 2 deletions Code/Mantid/Framework/MDEvents/src/MDHistoWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "MantidGeometry/MDGeometry/MDHistoDimension.h"
#include "MantidGeometry/MDGeometry/MDDimensionExtents.h"
#include <map>
#include "MantidAPI/IMDWorkspace.h"

using namespace Mantid::Kernel;
using namespace Mantid::Geometry;
Expand Down Expand Up @@ -304,11 +305,25 @@ namespace MDEvents
* @return the (normalized) signal at a given coordinates.
* NaN if outside the range of this workspace
*/
signal_t MDHistoWorkspace::getSignalAtCoord(const coord_t * coords) const
signal_t MDHistoWorkspace::getSignalAtCoord(const coord_t * coords, const Mantid::API::MDNormalization & normalization) const
{
size_t linearIndex = this->getLinearIndexAtCoord(coords);
if (linearIndex < m_length)
return m_signals[linearIndex] * m_inverseVolume;
{
// What is our normalization factor?
switch (normalization)
{
case NoNormalization:
return m_signals[linearIndex];
case VolumeNormalization:
return m_signals[linearIndex] * m_inverseVolume;
case NumEventsNormalization:
//TOOD: track # of events
return m_signals[linearIndex] * 1;
}
// Should not reach here
return m_signals[linearIndex];
}
else
return std::numeric_limits<signal_t>::quiet_NaN();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class QWT_EXPORT QwtRasterDataMD : public QwtRasterData

void setZerosAsNan(bool val);

void setNormalization(Mantid::API::MDNormalization normalization);
Mantid::API::MDNormalization getNormalization() const;

protected:
/// Workspace being shown
Mantid::API::IMDWorkspace_sptr m_ws;
Expand Down Expand Up @@ -72,6 +75,9 @@ class QWT_EXPORT QwtRasterDataMD : public QwtRasterData

/// Convert zeroes to NAN
bool m_zerosAsNan;

/// Normalization of signals
Mantid::API::MDNormalization m_normalization;
};

} // namespace SliceViewer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public slots:
void setColorScaleAutoSlice();
void setTransparentZeros(bool transparent);
void setFastRender(bool fast);
void changeNormalization();
// Slots that will be automatically connected via QMetaObject.connectSlotsByName
void on_btnClearLine_clicked();
QPixmap getImage();
Expand Down Expand Up @@ -198,6 +199,9 @@ public slots:
QMenu *m_menuColorOptions, *m_menuView, *m_menuHelp, *m_menuLine, *m_menuFile;
QAction *m_actionFileClose;
QAction *m_actionTransparentZeros;
QAction *m_actionNormalizeNone;
QAction *m_actionNormalizeVolume;
QAction *m_actionNormalizeNumEvents;

/// Synced menu/buttons
MantidQt::API::SyncedCheckboxes *m_syncLineMode, *m_syncSnapToGrid;
Expand Down
22 changes: 20 additions & 2 deletions Code/Mantid/MantidQt/SliceViewer/src/QwtRasterDataMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <math.h>
#include "MantidGeometry/MDGeometry/MDTypes.h"
#include "MantidGeometry/MDGeometry/IMDDimension.h"
#include "MantidAPI/IMDWorkspace.h"

namespace MantidQt
{
Expand All @@ -15,7 +16,8 @@ using Mantid::Geometry::IMDDimension_const_sptr;
//-------------------------------------------------------------------------
/// Constructor
QwtRasterDataMD::QwtRasterDataMD()
: m_slicePoint(NULL), m_fast(true), m_zerosAsNan(true)
: m_slicePoint(NULL), m_fast(true), m_zerosAsNan(true),
m_normalization(Mantid::API::VolumeNormalization)
{
m_range = QwtDoubleInterval(0.0, 1.0);
m_nd = 0;
Expand Down Expand Up @@ -48,6 +50,7 @@ QwtRasterData* QwtRasterDataMD::copy() const
out->m_ws = this->m_ws;
out->m_fast = this->m_fast;
out->m_zerosAsNan = this->m_zerosAsNan;
out->m_normalization = this->m_normalization;
return out;
}

Expand Down Expand Up @@ -81,7 +84,7 @@ double QwtRasterDataMD::value(double x, double y) const
lookPoint[d] = m_slicePoint[d];
}
// Get the signal at that point
signal_t value = m_ws->getSignalAtCoord(lookPoint);
signal_t value = m_ws->getSignalAtCoord(lookPoint, m_normalization);
delete [] lookPoint;

// Special case for 0 = show as NAN
Expand Down Expand Up @@ -120,6 +123,21 @@ void QwtRasterDataMD::setZerosAsNan(bool val)
this->m_zerosAsNan = val;
}

//------------------------------------------------------------------------------------------------------
/** Set how the signal is normalized
*
* @param normalization :: option from MDNormalization enum.
*/
void QwtRasterDataMD::setNormalization(Mantid::API::MDNormalization normalization)
{
m_normalization = normalization;
}

/** @return how the signal is normalized */
Mantid::API::MDNormalization QwtRasterDataMD::getNormalization() const
{
return m_normalization;
}

//------------------------------------------------------------------------------------------------------
/** Return how many pixels this area should be rendered as
Expand Down
48 changes: 47 additions & 1 deletion Code/Mantid/MantidQt/SliceViewer/src/SliceViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,33 @@ void SliceViewer::initMenus()
connect(action, SIGNAL(toggled(bool)), this, SLOT(setFastRender(bool)));
m_menuView->addAction(action);

m_menuView->addSeparator();

QActionGroup* group = new QActionGroup( this );

action = new QAction(QPixmap(), "No Normalization", this);
connect(action, SIGNAL(triggered()), this, SLOT(changeNormalization()));
m_menuView->addAction(action);
action->setActionGroup(group);
action->setCheckable(true);
m_actionNormalizeNone = action;

action = new QAction(QPixmap(), "Volume Normalization", this);
connect(action, SIGNAL(triggered()), this, SLOT(changeNormalization()));
m_menuView->addAction(action);
action->setActionGroup(group);
action->setCheckable(true);
m_actionNormalizeVolume = action;

action = new QAction(QPixmap(), "Num. Events Normalization", this);
connect(action, SIGNAL(triggered()), this, SLOT(changeNormalization()));
m_menuView->addAction(action);
action->setActionGroup(group);
action->setCheckable(true);
m_actionNormalizeNumEvents = action;



// --------------- Color options Menu ----------------------------------------
m_menuColorOptions = new QMenu("&ColorMap", this);

Expand Down Expand Up @@ -598,6 +625,25 @@ void SliceViewer::setTransparentZeros(bool transparent)
this->updateDisplay();
}


//------------------------------------------------------------------------------------
/// Slot called when changing the normalization menu
void SliceViewer::changeNormalization()
{
Mantid::API::MDNormalization normalization;
if (m_actionNormalizeNone->isChecked())
normalization = Mantid::API::NoNormalization;
else if (m_actionNormalizeVolume->isChecked())
normalization = Mantid::API::VolumeNormalization;
else if (m_actionNormalizeNumEvents->isChecked())
normalization = Mantid::API::NumEventsNormalization;
else
normalization = Mantid::API::NoNormalization;

m_data->setNormalization(normalization);
this->updateDisplay();
}

//------------------------------------------------------------------------------------
/// Slot called when the btnDoLine button is checked/unchecked
void SliceViewer::LineMode_toggled(bool checked)
Expand Down Expand Up @@ -1001,7 +1047,7 @@ void SliceViewer::showInfoAt(double x, double y)
coords[d] = m_dimWidgets[d]->getSlicePoint();
coords[m_dimX] = x;
coords[m_dimY] = y;
signal_t signal = m_ws->getSignalAtCoord(coords);
signal_t signal = m_ws->getSignalAtCoord(coords, this->m_data->getNormalization());
ui.lblInfoX->setText(QString::number(x, 'g', 4));
ui.lblInfoY->setText(QString::number(y, 'g', 4));
ui.lblInfoSignal->setText(QString::number(signal, 'g', 4));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ int main( int argc, char ** argv )
app.setApplicationName("SliceViewerWindow demo");
IMDWorkspace_sptr mdew = makeDemoData(true);

SliceViewerWindow * mainWin = new SliceViewerWindow("workspace_2d");
//SliceViewerWindow * mainWin = new SliceViewerWindow("workspace_2d");
SliceViewerWindow * mainWin = new SliceViewerWindow("mdew");
//mainWin->getSlicer()->getLineOverlay()->setSnap(0.5);
// mainWin->getSlicer()->getLineOverlay()->setSnapLength(0.1);
mainWin->move(100, 100);
Expand Down

0 comments on commit 8dc49c8

Please sign in to comment.