Skip to content

Commit

Permalink
refs #5167. Browse peaks through slice.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Aug 28, 2012
1 parent 18caac5 commit a708692
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "DllOption.h"
#include "MantidKernel/System.h"
#include "MantidKernel/V3D.h"
#include <q3iconview.h>
#include <QtCore/QtCore>
#include <QtGui/qwidget.h>
Expand Down Expand Up @@ -46,15 +47,15 @@ namespace SliceViewer

public:
/// Constructor
PeakOverlay(QwtPlot * plot, QWidget * parent, const QPointF& origin, const double& radius);
PeakOverlay(QwtPlot * plot, QWidget * parent, const Mantid::Kernel::V3D& origin, const double& radius);
/// Destructor
virtual ~PeakOverlay();
/// Set the distance between the origin and the plane in the z-md-coordinate system.
virtual void setPlaneDistance(const double& dz);
/// Set the slice point at position.
virtual void setSlicePoint(const double& point);
/// Update the view.
virtual void updateView();
/// Get the origin. md x, md y
const QPointF & getOrigin() const;
const Mantid::Kernel::V3D & getOrigin() const;
double getRadius() const;

private:
Expand All @@ -69,8 +70,8 @@ namespace SliceViewer

/// QwtPlot containing this
QwtPlot * m_plot;
/// Origin md-x, md-y
QPointF m_origin;
/// Origin md-x, md-y, and md-z
Mantid::Kernel::V3D m_origin;
/// Radius md-x, md-y
double m_radius;
/// Max opacity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@ namespace MantidQt
class DLLExport PeakOverlayView
{
public:
/// Set the distance between the plane and the origin in md-z coordinates.
virtual void setPlaneDistance(const double& dz) = 0;
/// Get the origin. md x, md y
virtual const QPointF & getOrigin() const = 0;
/// Get the radius. md x, md y
virtual double getRadius() const = 0;
/// Set the position of the slice point.
virtual void setSlicePoint(const double&) = 0;
/// Update the view.
virtual void updateView() = 0;
/// Destructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "MantidKernel/System.h"
#include <vector>
#include <boost/shared_ptr.hpp>
#include "MantidKernel/System.h"

namespace Mantid
{
Expand All @@ -26,19 +27,25 @@ namespace SliceViewer
{
public:
virtual void update() = 0;
virtual void updateWithSlicePoint(const double& slicePoint) = 0;
};

class DLLExport NullPeaksPresenter : public PeaksPresenter
{
public:
virtual void update(){};
virtual void updateWithSlicePoint(const double& slicePoint)
{
UNUSED_ARG(slicePoint);
};
};

class DLLExport ConcretePeaksPresenter : public PeaksPresenter
{
public:
ConcretePeaksPresenter(PeakOverlayViewFactory* factory, boost::shared_ptr<Mantid::API::IPeaksWorkspace> peaksWS);
virtual void update();
virtual void updateWithSlicePoint(const double& slicePoint);
private:
typedef std::vector< boost::shared_ptr<PeakOverlayView> > VecPeakOverlayView;
/// Peak overlay views.
Expand Down
29 changes: 20 additions & 9 deletions Code/Mantid/MantidQt/SliceViewer/src/PeakOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace SliceViewer
//----------------------------------------------------------------------------------------------
/** Constructor
*/
PeakOverlay::PeakOverlay(QwtPlot * plot, QWidget * parent, const QPointF& origin, const double& radius)
PeakOverlay::PeakOverlay(QwtPlot * plot, QWidget * parent, const Mantid::Kernel::V3D& origin, const double& radius)
: QWidget( parent ),
m_plot(plot),
m_origin(origin),
Expand All @@ -47,7 +47,7 @@ namespace SliceViewer
ASCII diagram below to demonstrate how dz (distance in z) is used to determine the radius of the sphere-plane intersection at that point,
resloves both rx and ry. Also uses the distance to calculate the opacity to apply.
@param dz : distance from the peak cetner in the md coordinates of the z-axis.
@param atPoint : distance from the peak cetner in the md coordinates of the z-axis.
/---------\
/ \
Expand All @@ -60,19 +60,30 @@ namespace SliceViewer
\ /
\---------/
*/
void PeakOverlay::setPlaneDistance(const double& dz)
void PeakOverlay::setSlicePoint(const double& z)
{
const double distanceSQ = dz * dz;
m_radiusAtDistance = std::sqrt( (m_radius * m_radius) - distanceSQ );
const double distance = z - m_origin.Z();
const double distanceSQ = distance * distance;
const double radSQ = m_radius * m_radius;

if(distanceSQ < radSQ)
{
m_radiusAtDistance = std::sqrt( radSQ - distanceSQ );
}
else
{
m_radiusAtDistance = 0;
}


// Apply a linear transform to convert from a distance to an opacity between opacityMin and opacityMax.
m_opacityAtDistance = ((m_opacityMin - m_opacityMax)/m_radius) * dz + m_opacityMax;
m_opacityAtDistance = ((m_opacityMin - m_opacityMax)/m_radius) * distance + m_opacityMax;
m_opacityAtDistance = m_opacityAtDistance >= m_opacityMin ? m_opacityAtDistance : m_opacityMin;

this->update(); //repaint
}

const QPointF & PeakOverlay::getOrigin() const
const Mantid::Kernel::V3D & PeakOverlay::getOrigin() const
{ return m_origin; }

double PeakOverlay::getRadius() const
Expand Down Expand Up @@ -102,8 +113,8 @@ namespace SliceViewer
void PeakOverlay::paintEvent(QPaintEvent * /*event*/)
{
// Linear Transform from MD coordinates into Windows/Qt coordinates for ellipse rendering. TODO: This can be done outside of paintEvent.
const int xOrigin = m_plot->transform( QwtPlot::xBottom, m_origin.x() );
const int yOrigin = m_plot->transform( QwtPlot::yLeft, m_origin.y() );
const int xOrigin = m_plot->transform( QwtPlot::xBottom, m_origin.X() );
const int yOrigin = m_plot->transform( QwtPlot::yLeft, m_origin.Y() );
const QPointF originWindows(xOrigin, yOrigin);

const QwtDoubleInterval interval = m_plot->axisScaleDiv(QwtPlot::yLeft)->interval();
Expand Down
4 changes: 1 addition & 3 deletions Code/Mantid/MantidQt/SliceViewer/src/PeakOverlayFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ namespace MantidQt
3) Create the origin x, y based on these hkl values.
*/

QPointF origin(position.X(), position.Y()); // This needs to be calculated properly! See above.

return boost::make_shared<PeakOverlay>(m_plot, m_parent, origin, radius);
return boost::make_shared<PeakOverlay>(m_plot, m_parent, position, radius);
}

PeakOverlayFactory::~PeakOverlayFactory()
Expand Down
13 changes: 12 additions & 1 deletion Code/Mantid/MantidQt/SliceViewer/src/PeaksPresenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ namespace SliceViewer
const Mantid::API::IPeak& peak = peaksWS->getPeak(i);
auto view = boost::shared_ptr<PeakOverlayView>( factory_scptr->createView(peak) );
m_viewPeaks.push_back( view );
view->setPlaneDistance(0); // HACK
}
}

Expand All @@ -35,5 +34,17 @@ namespace SliceViewer
++it;
}
}

void ConcretePeaksPresenter::updateWithSlicePoint(const double& slicePoint)
{
VecPeakOverlayView::iterator it = m_viewPeaks.begin();
while(it != m_viewPeaks.end())
{
auto view = (*it);
view->setSlicePoint(slicePoint);
++it;
}

}
}
}
2 changes: 1 addition & 1 deletion Code/Mantid/MantidQt/SliceViewer/src/SliceViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,7 @@ void SliceViewer::updateDisplay(bool resetAxes)
m_spect->setData(*m_data);
m_spect->itemChanged();
m_plot->replot();
m_peaksPresenter->update();
m_peaksPresenter->updateWithSlicePoint(m_dimWidgets[2]->getSlicePoint());

// Send out a signal
emit changedSlicePoint(m_slicePoint);
Expand Down
30 changes: 26 additions & 4 deletions Code/Mantid/MantidQt/SliceViewer/test/PeaksPresenterTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ class PeaksPresenterTest : public CxxTest::TestSuite
{
public:
MOCK_METHOD1(setPlaneDistance, void(const double&));
MOCK_CONST_METHOD0(getOrigin, const QPointF&());
MOCK_CONST_METHOD0(getRadius, double());
MOCK_METHOD0(updateView, void());
MOCK_METHOD1(setSlicePoint, void(const double&));
~MockPeakOverlayView(){}
};

Expand Down Expand Up @@ -82,7 +81,7 @@ class PeaksPresenterTest : public CxxTest::TestSuite
EXPECT_CALL(*pMockView, updateView()).Times(expectedNumberPeaks);
auto mockView = boost::shared_ptr<NiceMock<MockPeakOverlayView> >(pMockView);

EXPECT_CALL(*mockViewFactory, createView(_)).Times(expectedNumberPeaks).WillRepeatedly(Return(mockView));
EXPECT_CALL(*mockViewFactory, createView(_)).WillRepeatedly(Return(mockView));
Mantid::API::IPeaksWorkspace_sptr peaksWS = WorkspaceCreationHelper::createPeaksWorkspace(expectedNumberPeaks);

// Construction should cause the widget factory to be used to generate peak overlay objects.
Expand All @@ -91,9 +90,32 @@ class PeaksPresenterTest : public CxxTest::TestSuite
// Updating should cause all of the held views to be updated too.
presenter.update();

TSM_ASSERT("MockViewFactory not used as expected.", Mock::VerifyAndClearExpectations(mockViewFactory));
TSM_ASSERT("MockView not used as expected.", Mock::VerifyAndClearExpectations(pMockView));
}

void test_set_slice_point()
{
// Create a widget factory mock
auto mockViewFactory = new MockPeakOverlayFactory;

const double slicePoint = 0.1;
const int expectedNumberPeaks = 10;

// Create a mock view object that will be returned by the mock factory.
auto pMockView = new NiceMock<MockPeakOverlayView>;
EXPECT_CALL(*pMockView, setSlicePoint(slicePoint)).Times(expectedNumberPeaks);
auto mockView = boost::shared_ptr<NiceMock<MockPeakOverlayView> >(pMockView);

EXPECT_CALL(*mockViewFactory, createView(_)).WillRepeatedly(Return(mockView));
Mantid::API::IPeaksWorkspace_sptr peaksWS = WorkspaceCreationHelper::createPeaksWorkspace(expectedNumberPeaks);

// Construction should cause the widget factory to be used to generate peak overlay objects.
ConcretePeaksPresenter presenter(mockViewFactory, peaksWS);

// Updating should cause all of the held views to be updated too.
presenter.updateWithSlicePoint(slicePoint);

TSM_ASSERT("MockView not used as expected.", Mock::VerifyAndClearExpectations(pMockView));
}

};
Expand Down

0 comments on commit a708692

Please sign in to comment.