Skip to content

Commit

Permalink
refs #5167. Adapt to restrict to HKL only.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Nov 29, 2012
1 parent f23165b commit 9da58a5
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ namespace MantidQt
private:
QwtPlot * m_plot;
QWidget * m_parent;
PeakDimensions m_peakDims;
public:
PeakOverlayFactory(QwtPlot * plot, QWidget * parent, const FirstExperimentInfoQuery& query);
virtual ~PeakOverlayFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ namespace MantidQt
PeakOverlayFactoryBase(const FirstExperimentInfoQuery& query);
~PeakOverlayFactoryBase();
virtual boost::shared_ptr<PeakOverlayView> createView(const Mantid::API::IPeak&) const;
PeakDimensions getPeakDimensionality() const;
protected:
virtual boost::shared_ptr<PeakOverlayView> createViewAtPoint(const Mantid::Kernel::V3D& position, const double& radius, const bool hasIntensity) const = 0;
PeakDimensions m_peakDims;
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ namespace MantidQt
{
namespace SliceViewer
{
/// Enum describing types of peak dimensions.
enum PeakDimensions{LabView, SampleView, HKLView};

/** Abstract view in MVP model representing a PeakOverlay.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ namespace SliceViewer
class PeakOverlayView;

/*---------------------------------------------------------
Abstract PeaksPresenter
Abstract PeaksPresenter.
This is abstract to allow usage of the NULL object pattern. This allows the ConcreteViewPresenter to be conctructed in an atomic sense after the constrution of the owning object,
whithout having to perform fragile null checks.
----------------------------------------------------------*/
class DLLExport PeaksPresenter
{
Expand Down
29 changes: 28 additions & 1 deletion Code/Mantid/MantidQt/SliceViewer/src/ConcretePeaksPresenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,30 @@ namespace MantidQt
namespace SliceViewer
{

/**
Constructor.
1) First check that the arguments provided are valid.
2) Then iterate over the MODEL and use it to construct VIEWs via the factory.
3) A collection of views is stored internally
@param factory : View factory (THE VIEW via factory)
@param peaksWS : IPeaksWorkspace to visualise (THE MODEL)
*/
ConcretePeaksPresenter::ConcretePeaksPresenter(PeakOverlayViewFactory* factory, Mantid::API::IPeaksWorkspace_sptr peaksWS) : m_viewPeaks(peaksWS->getNumberPeaks())
{
if(factory == NULL)
{
throw std::invalid_argument("PeakOverlayViewFactory is null");
}
if(peaksWS == NULL)
{
throw std::invalid_argument("PeaksWorkspace is null");
}
if(!peaksWS->hasIntegratedPeaks())
{
throw std::invalid_argument("PeaksWorkspace does not contain integrated peaks."); // We might consider drawing these in the future anyway.
}

// Create views for every peak in the workspace.
boost::scoped_ptr<PeakOverlayViewFactory> factory_scptr(factory);
Expand All @@ -31,9 +49,11 @@ namespace SliceViewer
{
(*it)->setNormalisation(maxIntensity);
}

}

/**
Force each view to re-paint.
*/
void ConcretePeaksPresenter::update()
{
for(VecPeakOverlayView::iterator it = m_viewPeaks.begin(); it != m_viewPeaks.end(); ++it)
Expand All @@ -42,6 +62,10 @@ namespace SliceViewer
}
}

/**
Allow all view to redraw themselfs following an update to the slice point intersecting plane.
@param slicePoint : The new slice position (z) against the x-y plot of data.
*/
void ConcretePeaksPresenter::updateWithSlicePoint(const double& slicePoint)
{
for(VecPeakOverlayView::iterator it = m_viewPeaks.begin(); it != m_viewPeaks.end(); ++it)
Expand All @@ -50,6 +74,9 @@ namespace SliceViewer
}
}

/**
Destructor. Hide all owned views.
*/
ConcretePeaksPresenter::~ConcretePeaksPresenter()
{
for(VecPeakOverlayView::iterator it = m_viewPeaks.begin(); it != m_viewPeaks.end(); ++it)
Expand Down
30 changes: 3 additions & 27 deletions Code/Mantid/MantidQt/SliceViewer/src/PeakOverlayFactoryBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,19 @@ namespace MantidQt

PeakOverlayFactoryBase::PeakOverlayFactoryBase(const FirstExperimentInfoQuery& query)
{
m_peakDims = LabView;
if(query.hasRotatedGoniometer())
if(!query.hasOrientedLattice())
{
m_peakDims = SampleView;
}
if(query.hasOrientedLattice())
{
m_peakDims = HKLView;
throw std::invalid_argument("Input MDWorkspace must be in QSpace HKL and must have an oriented lattice.");
}
}

PeakOverlayFactoryBase::~PeakOverlayFactoryBase()
{
}

PeakDimensions PeakOverlayFactoryBase::getPeakDimensionality() const
{
return m_peakDims;
}

boost::shared_ptr<PeakOverlayView> PeakOverlayFactoryBase::createView(const Mantid::API::IPeak& peak) const
{
Mantid::Kernel::V3D position;
switch(m_peakDims)
{
case LabView:
position = peak.getQLabFrame();
break;
case SampleView:
position = peak.getQSampleFrame();
break;
case HKLView:
position = peak.getHKL();
break;
default:
throw std::runtime_error("Unknown PeakDimension type");
}
Mantid::Kernel::V3D position = peak.getHKL();

double intensity = peak.getIntensity();

Expand Down
25 changes: 21 additions & 4 deletions Code/Mantid/MantidQt/SliceViewer/test/ConcretePeaksPresenterTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ class ConcretePeaksPresenterTest : public CxxTest::TestSuite
MOCK_METHOD0(updateView, void());
};

/// Helper method to create a good 'Integrated' peaks workspace
Mantid::API::IPeaksWorkspace_sptr createPeaksWorkspace(const int nPeaks, const double radius=1)
{
Mantid::API::IPeaksWorkspace_sptr peaksWS = WorkspaceCreationHelper::createPeaksWorkspace(nPeaks);
peaksWS->mutableRun().addProperty("PeaksIntegrated", true);
peaksWS->mutableRun().addProperty("PeakRadius", radius);
return peaksWS;
}

public:

void test_constructor_throws_if_factory_null()
Expand All @@ -54,6 +63,14 @@ class ConcretePeaksPresenterTest : public CxxTest::TestSuite
TS_ASSERT_THROWS(ConcretePeaksPresenter(nullFactory, peaksWS), std::invalid_argument);
}

void test_constructor_throws_if_peaks_workspace_null()
{
}

void test_constructor_throws_if_peaks_workspace_not_integrated()
{
}

void test_construction()
{
// Create a widget factory mock
Expand All @@ -69,7 +86,7 @@ class ConcretePeaksPresenterTest : public CxxTest::TestSuite


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

// Construction should cause the widget factory to be used to generate peak overlay objects.
ConcretePeaksPresenter presenter(mockViewFactory, peaksWS);
Expand All @@ -92,7 +109,7 @@ class ConcretePeaksPresenterTest : public CxxTest::TestSuite
auto mockView = boost::shared_ptr<NiceMock<MockPeakOverlayView> >(pMockView);

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

// Construction should cause the widget factory to be used to generate peak overlay objects.
ConcretePeaksPresenter presenter(mockViewFactory, peaksWS);
Expand All @@ -117,7 +134,7 @@ class ConcretePeaksPresenterTest : public CxxTest::TestSuite
auto mockView = boost::shared_ptr<NiceMock<MockPeakOverlayView> >(pMockView);

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

// Construction should cause the widget factory to be used to generate peak overlay objects.
ConcretePeaksPresenter presenter(mockViewFactory, peaksWS);
Expand All @@ -141,7 +158,7 @@ class ConcretePeaksPresenterTest : public CxxTest::TestSuite
auto mockView = boost::shared_ptr<NiceMock<MockPeakOverlayView> >(pMockView);

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

{
ConcretePeaksPresenter presenter(mockViewFactory, peaksWS);
Expand Down
150 changes: 3 additions & 147 deletions Code/Mantid/MantidQt/SliceViewer/test/PeakOverlayFactoryBaseTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,159 +154,15 @@ class PeakOverlayFactoryBaseTest : public CxxTest::TestSuite

public:

void test_construction_selects_lab_view_required()
void test_throws_if_no_oriented_lattice()
{
MockFirstExperimentInfoQuery mockQuery;
EXPECT_CALL(mockQuery, hasOrientedLattice()).Times(1).WillOnce(Return(false));
EXPECT_CALL(mockQuery, hasRotatedGoniometer()).Times(1).WillOnce(Return(false));
EXPECT_CALL(mockQuery, hasOrientedLattice()).Times(1).WillOnce(Return(false)); // opps, no oriented lattice.

MockPeakOverlayFactory factory(mockQuery);
TS_ASSERT_EQUALS( LabView ,factory.getPeakDimensionality());
TS_ASSERT_THROWS(MockPeakOverlayFactory f(mockQuery), std::invalid_argument);
TS_ASSERT( Mock::VerifyAndClearExpectations(&mockQuery));
}

void test_construction_selects_sample_view_required()
{
MockFirstExperimentInfoQuery mockQuery;
EXPECT_CALL(mockQuery, hasOrientedLattice()).Times(1).WillOnce(Return(false));
EXPECT_CALL(mockQuery, hasRotatedGoniometer()).Times(1).WillOnce(Return(true));

MockPeakOverlayFactory factory(mockQuery);
TS_ASSERT_EQUALS( SampleView ,factory.getPeakDimensionality());
TS_ASSERT( Mock::VerifyAndClearExpectations(&mockQuery));
}

void test_construction_selects_HKL_view_required()
{
MockFirstExperimentInfoQuery mockQuery;
EXPECT_CALL(mockQuery, hasOrientedLattice()).Times(1).WillOnce(Return(true));
EXPECT_CALL(mockQuery, hasRotatedGoniometer()).Times(1).WillOnce(Return(false));

MockPeakOverlayFactory factory(mockQuery);
TS_ASSERT_EQUALS( HKLView ,factory.getPeakDimensionality());
TS_ASSERT( Mock::VerifyAndClearExpectations(&mockQuery));
}

void test_construction_selects_HKL_view_over_sample_view_when_both_available()
{
MockFirstExperimentInfoQuery mockQuery;
EXPECT_CALL(mockQuery, hasOrientedLattice()).Times(1).WillOnce(Return(true));
EXPECT_CALL(mockQuery, hasRotatedGoniometer()).Times(1).WillOnce(Return(true));

MockPeakOverlayFactory factory(mockQuery);
TS_ASSERT_EQUALS( HKLView ,factory.getPeakDimensionality());
TS_ASSERT( Mock::VerifyAndClearExpectations(&mockQuery));
}

void do_test_fixed_radius_calculated_from_peak_intensity(const double& peakIntensity)
{
NiceMock<MockFirstExperimentInfoQuery> mockQuery;
MockPeakOverlayFactory factory(mockQuery);

NiceMock<MockIPeak> mockPeak;
const bool hasVariableRadius = (peakIntensity != 0); // Should replicate internal logic.

EXPECT_CALL(mockPeak, getIntensity()).Times(1).WillOnce(Return(peakIntensity));
EXPECT_CALL(mockPeak, getQLabFrame()).Times(1).WillOnce(Return(Mantid::Kernel::V3D(0,0,0)));

MockPeakOverlayFactory mockFactory(mockQuery);

MockPeakOverlayView* pMockView = new MockPeakOverlayView;
PeakOverlayView_sptr mockView(pMockView);
EXPECT_CALL(mockFactory, createViewAtPoint(_,_,hasVariableRadius)).Times(1).WillOnce(Return(mockView));

mockFactory.createView(mockPeak);

TS_ASSERT( Mock::VerifyAndClearExpectations(&mockPeak));
TS_ASSERT( Mock::VerifyAndClearExpectations(&mockFactory));
}

void test_createview_specifies_fixed_radius_when_intensity_zero()
{
do_test_fixed_radius_calculated_from_peak_intensity(0);
}

void test_createview_specifies_non_fixed_radius_when_intensity_great_than_zero()
{
do_test_fixed_radius_calculated_from_peak_intensity(0.001);
}

void test_createview_specifies_non_fixed_radius_when_intensity_less_than_zero()
{
do_test_fixed_radius_calculated_from_peak_intensity(-0.001);
}

void test_createview_gets_peak_coordinates_as_lab_view_according_to_query_results()
{
NiceMock<MockFirstExperimentInfoQuery> mockQuery;
EXPECT_CALL(mockQuery, hasOrientedLattice()).Times(1).WillOnce(Return(false));
EXPECT_CALL(mockQuery, hasRotatedGoniometer()).Times(1).WillOnce(Return(false));

NiceMock<MockIPeak> mockPeak;
EXPECT_CALL(mockPeak, getQLabFrame()).Times(1).WillOnce(Return(Mantid::Kernel::V3D(0,0,0)));

MockPeakOverlayFactory mockFactory(mockQuery);

MockPeakOverlayView* pMockView = new MockPeakOverlayView;
PeakOverlayView_sptr mockView(pMockView);
EXPECT_CALL(mockFactory, createViewAtPoint(_,_,_)).Times(1).WillOnce(Return(mockView));

mockFactory.createView(mockPeak);

TS_ASSERT_EQUALS( LabView ,mockFactory.getPeakDimensionality());
TS_ASSERT( Mock::VerifyAndClearExpectations(&mockQuery));
TS_ASSERT( Mock::VerifyAndClearExpectations(&mockPeak));
TS_ASSERT( Mock::VerifyAndClearExpectations(&mockFactory));
}

void test_createview_gets_peak_coordinates_as_sample_view_according_to_query_results()
{
NiceMock<MockFirstExperimentInfoQuery> mockQuery;
EXPECT_CALL(mockQuery, hasOrientedLattice()).Times(1).WillOnce(Return(false));
EXPECT_CALL(mockQuery, hasRotatedGoniometer()).Times(1).WillOnce(Return(true));

NiceMock<MockIPeak> mockPeak;
EXPECT_CALL(mockPeak, getQSampleFrame()).Times(1).WillOnce(Return(Mantid::Kernel::V3D(0,0,0)));

MockPeakOverlayFactory mockFactory(mockQuery);

MockPeakOverlayView* pMockView = new MockPeakOverlayView;
PeakOverlayView_sptr mockView(pMockView);
EXPECT_CALL(mockFactory, createViewAtPoint(_,_,_)).Times(1).WillOnce(Return(mockView));

mockFactory.createView(mockPeak);

TS_ASSERT_EQUALS( SampleView ,mockFactory.getPeakDimensionality());
TS_ASSERT( Mock::VerifyAndClearExpectations(&mockQuery));
TS_ASSERT( Mock::VerifyAndClearExpectations(&mockPeak));
TS_ASSERT( Mock::VerifyAndClearExpectations(&mockFactory));
}

void test_createview_gets_peak_coordinates_as_HKL_view_according_to_query_results()
{
NiceMock<MockFirstExperimentInfoQuery> mockQuery;
EXPECT_CALL(mockQuery, hasOrientedLattice()).Times(1).WillOnce(Return(true));
EXPECT_CALL(mockQuery, hasRotatedGoniometer()).Times(1).WillOnce(Return(false));

NiceMock<MockIPeak> mockPeak;
EXPECT_CALL(mockPeak, getHKL()).Times(1).WillOnce(Return(Mantid::Kernel::V3D(0,0,0)));

MockPeakOverlayFactory mockFactory(mockQuery);

MockPeakOverlayView* pMockView = new MockPeakOverlayView;
PeakOverlayView_sptr mockView(pMockView);
EXPECT_CALL(mockFactory, createViewAtPoint(_,_,_)).Times(1).WillOnce(Return(mockView));

mockFactory.createView(mockPeak);

TS_ASSERT_EQUALS( HKLView ,mockFactory.getPeakDimensionality());
TS_ASSERT( Mock::VerifyAndClearExpectations(&mockQuery));
TS_ASSERT( Mock::VerifyAndClearExpectations(&mockPeak));
TS_ASSERT( Mock::VerifyAndClearExpectations(&mockFactory));
}



};


Expand Down

0 comments on commit 9da58a5

Please sign in to comment.