Skip to content

Commit

Permalink
refs #5167. Works for default dimension mapping/
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Nov 29, 2012
1 parent 2e75431 commit 3599233
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace SliceViewer

public:
/// Constructor
PeakOverlay(QwtPlot * plot, QWidget * parent, const Mantid::Kernel::V3D& origin, const double& intensity, const bool hasIntensity);
PeakOverlay(QwtPlot * plot, QWidget * parent, const Mantid::Kernel::V3D& origin, const double& radius);
/// Destructor
virtual ~PeakOverlay();
/// Set the slice point at position.
Expand All @@ -59,8 +59,6 @@ namespace SliceViewer
/// Get the origin. md x, md y
const Mantid::Kernel::V3D & getOrigin() const;
double getRadius() const;
/// Setter for the normalisation.
void setNormalisation(const double& normalisation);

private:

Expand All @@ -76,8 +74,8 @@ namespace SliceViewer
QwtPlot * m_plot;
/// Origin md-x, md-y, and md-z
Mantid::Kernel::V3D m_origin;
/// intensity
double m_intensity;
/// actual peak radius
const double m_radius;
/// normalisation value.
double m_normalisation;
/// Max opacity
Expand All @@ -90,8 +88,6 @@ namespace SliceViewer
double m_radiusAtDistance;
/// Cached scale
double m_scale;
/// hasIntensity flag
const bool m_hasIntensity;
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace MantidQt
public:
PeakOverlayFactory(QwtPlot * plot, QWidget * parent, const FirstExperimentInfoQuery& query);
virtual ~PeakOverlayFactory();
virtual boost::shared_ptr<PeakOverlayView> createViewAtPoint(const Mantid::Kernel::V3D& position, const double& radius, const bool hasIntensity) const;
virtual boost::shared_ptr<PeakOverlayView> createViewAtPoint(const Mantid::Kernel::V3D& position, const double& radius) const;
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ namespace MantidQt
public:
PeakOverlayFactoryBase(const FirstExperimentInfoQuery& query);
~PeakOverlayFactoryBase();
void setRadius(const double& radius);
virtual boost::shared_ptr<PeakOverlayView> createView(const Mantid::API::IPeak&) const;

protected:
virtual boost::shared_ptr<PeakOverlayView> createViewAtPoint(const Mantid::Kernel::V3D& position, const double& radius, const bool hasIntensity) const = 0;
virtual boost::shared_ptr<PeakOverlayView> createViewAtPoint(const Mantid::Kernel::V3D& position, const double& radius) const = 0;

private:
/// The actual peak radius to use for all peaks created via the factory.
double m_peakRadius;
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ namespace MantidQt
virtual void updateView() = 0;
/// Hide the view.
virtual void hideView() = 0;
/// Setter for the normalisation value.
virtual void setNormalisation(const double& normalisation) = 0;
/// Destructor
virtual ~PeakOverlayView()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ namespace MantidQt
public:
/// Create a peak view from the peak object.
virtual boost::shared_ptr<PeakOverlayView> createView(const Mantid::API::IPeak&) const = 0;
/// Setter for the radius to use for all peaks.
virtual void setRadius(const double& radius) = 0;
/// Destructor
virtual ~PeakOverlayViewFactory()
{
Expand Down
12 changes: 4 additions & 8 deletions Code/Mantid/MantidQt/SliceViewer/src/ConcretePeaksPresenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,18 @@ namespace SliceViewer
{
throw std::invalid_argument("PeaksWorkspace does not contain integrated peaks."); // We might consider drawing these in the future anyway.
}
// Extract the integration radius from the workspace.
const double peakIntegrationRadius = boost::lexical_cast<double>(peaksWS->run().getProperty("PeakRadius")->value());

// Create views for every peak in the workspace.
boost::scoped_ptr<PeakOverlayViewFactory> factory_scptr(factory);
double maxIntensity = peaksWS->getPeak(0).getIntensity();
factory->setRadius(peakIntegrationRadius);

for(int i = 0; i < peaksWS->getNumberPeaks(); ++i)
{
const Mantid::API::IPeak& peak = peaksWS->getPeak(i);
maxIntensity = peak.getIntensity() > maxIntensity ? peak.getIntensity() : maxIntensity;
m_viewPeaks[i] = boost::shared_ptr<PeakOverlayView>( factory_scptr->createView(peak) );
}

// Set the normalisation. Applies to all peaks with intensity.
for(VecPeakOverlayView::iterator it = m_viewPeaks.begin(); it != m_viewPeaks.end(); ++it)
{
(*it)->setNormalisation(maxIntensity);
}
}

/**
Expand Down
36 changes: 9 additions & 27 deletions Code/Mantid/MantidQt/SliceViewer/src/PeakOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ namespace SliceViewer
//----------------------------------------------------------------------------------------------
/** Constructor
*/
PeakOverlay::PeakOverlay(QwtPlot * plot, QWidget * parent, const Mantid::Kernel::V3D& origin, const double& radius, bool hasIntensity)
PeakOverlay::PeakOverlay(QwtPlot * plot, QWidget * parent, const Mantid::Kernel::V3D& origin, const double& radius)
: QWidget( parent ),
m_plot(plot),
m_origin(origin),
m_intensity(radius),
m_normalisation(1),
m_opacityMax(0.6),
m_opacityMin(0.1),
m_hasIntensity(hasIntensity)
m_radius(radius),
m_opacityMax(0.8),
m_opacityMin(0.0)
{
setAttribute(Qt::WA_NoMousePropagation, false);
this->setVisible(true);
Expand All @@ -43,22 +41,13 @@ namespace SliceViewer
{
}

//----------------------------------------------------------------------------------------------
/** Setter for the normalisation denominator.
@param normalisation : normalisation denominator to use.
*/
void PeakOverlay::setNormalisation(const double& normalisation)
{
m_normalisation = normalisation;
}

//----------------------------------------------------------------------------------------------
/** Set the distance between the plane and the center of the peak in md coordinates
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 atPoint : distance from the peak cetner in the md coordinates of the z-axis.
@param atPoint : distance from the peak center in the md coordinates of the z-axis.
/---------\
/ \
Expand All @@ -75,8 +64,7 @@ namespace SliceViewer
{
const double distanceSQ = (z - m_origin.Z()) * (z - m_origin.Z());
const double distance = std::sqrt(distanceSQ);
const double radius = getRadius();
const double radSQ = radius * radius;
const double radSQ = m_radius * m_radius;

if(distanceSQ < radSQ)
{
Expand All @@ -93,7 +81,7 @@ namespace SliceViewer
m_scale = height()/(yMax - yMin);

// Apply a linear transform to convert from a distance to an opacity between opacityMin and opacityMax.
m_opacityAtDistance = ((m_opacityMin - m_opacityMax)/radius) * distance + 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
Expand All @@ -104,11 +92,7 @@ namespace SliceViewer

double PeakOverlay::getRadius() const
{
if(m_hasIntensity)
{
return m_intensity / m_normalisation;
}
return 1;
return m_radius;
}

//----------------------------------------------------------------------------------------------
Expand All @@ -128,8 +112,6 @@ namespace SliceViewer
int PeakOverlay::width() const
{ return m_plot->canvas()->width(); }



//----------------------------------------------------------------------------------------------
/// Paint the overlay
void PeakOverlay::paintEvent(QPaintEvent * /*event*/)
Expand All @@ -149,7 +131,7 @@ namespace SliceViewer

// Draw Outer circle
QPen pen( Qt::green );
pen.setWidth(static_cast<int>(lineWidth));
pen.setWidth(static_cast<int>(std::abs(lineWidth)));
painter.setPen( pen );
pen.setStyle(Qt::SolidLine);
painter.setOpacity(m_opacityAtDistance); //Set the pre-calculated opacity
Expand Down
5 changes: 2 additions & 3 deletions Code/Mantid/MantidQt/SliceViewer/src/PeakOverlayFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ namespace MantidQt
throw std::invalid_argument("PeakOverlayFactory parent widget is null");
}


boost::shared_ptr<PeakOverlayView> PeakOverlayFactory::createViewAtPoint(const Mantid::Kernel::V3D& position, const double& radius, const bool hasIntensity) const
boost::shared_ptr<PeakOverlayView> PeakOverlayFactory::createViewAtPoint(const Mantid::Kernel::V3D& position, const double& radius) const
{
return boost::make_shared<PeakOverlay>(m_plot, m_parent, position, radius, hasIntensity);
return boost::make_shared<PeakOverlay>(m_plot, m_parent, position, radius);
}

PeakOverlayFactory::~PeakOverlayFactory()
Expand Down
13 changes: 11 additions & 2 deletions Code/Mantid/MantidQt/SliceViewer/src/PeakOverlayFactoryBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace MantidQt
namespace SliceViewer
{

PeakOverlayFactoryBase::PeakOverlayFactoryBase(const FirstExperimentInfoQuery& query)
PeakOverlayFactoryBase::PeakOverlayFactoryBase(const FirstExperimentInfoQuery& query) : m_peakRadius(1)
{
if(!query.hasOrientedLattice())
{
Expand All @@ -19,6 +19,15 @@ namespace MantidQt
{
}

/*
Setter for the actual peak radius. The radius used for drawing will depend on the plane instesection.
@param peakRadius : Global value for the peak radius to apply to all peaks manufactured through this factory.
*/
void PeakOverlayFactoryBase::setRadius(const double& peakRadius)
{
m_peakRadius = peakRadius;
}

boost::shared_ptr<PeakOverlayView> PeakOverlayFactoryBase::createView(const Mantid::API::IPeak& peak) const
{
Mantid::Kernel::V3D position = peak.getHKL();
Expand All @@ -36,7 +45,7 @@ namespace MantidQt
3) Create the origin x, y based on these hkl values.
*/

return this->createViewAtPoint(position, intensity, intensity != 0);
return this->createViewAtPoint(position, m_peakRadius);
}

}
Expand Down
19 changes: 5 additions & 14 deletions Code/Mantid/MantidQt/SliceViewer/src/SliceViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,6 @@ SliceViewer::SliceViewer(QWidget *parent)
m_overlayWSOutline->setShowLine(false);
m_overlayWSOutline->setShown(false);

ui.btnPeakOverlay->hide();
// -------- Peak Overlay ----------------
//PeakOverlay* m_peakOverlay = new PeakOverlay(m_plot, m_plot->canvas(), QPointF(0.5,0.5), QPointF(0.1, 0.2)); //TODO use the peak overlay
//m_peakOverlay->setPlaneDistance(0);

//IPeaksWorkspace_sptr peaksWS = AnalysisDataService::Instance().retrieveWS<IPeaksWorkspace>("loadedpeaks2");
// PeakOverlayFactory* factory = new PeakOverlayFactory(m_plot, m_plot->canvas(), PeakDimensions::HKLView);
// m_peaksPresenter = boost::make_shared<PeaksPresenter>(factory, peaksWS);

ui.btnPeakOverlay->setEnabled(true);
}

Expand Down Expand Up @@ -310,12 +301,12 @@ void SliceViewer::initMenus()

m_menuView->addSeparator();

//action = new QAction(QPixmap(), "Peak Overlay", this);
//m_syncPeakOverlay = new SyncedCheckboxes(action, ui.btnPeakOverlay, false);
//connect(action, SIGNAL(toggled(bool)), this, SLOT(peakOverlay_toggled(bool)));
//m_menuView->addAction(action);
action = new QAction(QPixmap(), "Peak Overlay", this);
m_syncPeakOverlay = new SyncedCheckboxes(action, ui.btnPeakOverlay, false);
connect(action, SIGNAL(toggled(bool)), this, SLOT(peakOverlay_toggled(bool)));
m_menuView->addAction(action);

//m_menuView->addSeparator();
m_menuView->addSeparator();

QActionGroup* group = new QActionGroup( this );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class ConcretePeaksPresenterTest : public CxxTest::TestSuite
MOCK_METHOD0(updateView, void());
MOCK_METHOD1(setSlicePoint, void(const double&));
MOCK_METHOD0(hideView, void());
MOCK_METHOD1(setNormalisation, void(const double&));
~MockPeakOverlayView(){}
};

Expand All @@ -41,6 +40,7 @@ class ConcretePeaksPresenterTest : public CxxTest::TestSuite
{
public:
MOCK_CONST_METHOD1(createView, boost::shared_ptr<PeakOverlayView>(const Mantid::API::IPeak&));
MOCK_METHOD1(setRadius, void(const double&));
MOCK_METHOD0(updateView, void());
};

Expand Down Expand Up @@ -81,10 +81,9 @@ class ConcretePeaksPresenterTest : public CxxTest::TestSuite

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


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

Expand All @@ -108,6 +107,7 @@ class ConcretePeaksPresenterTest : public CxxTest::TestSuite
EXPECT_CALL(*pMockView, updateView()).Times(expectedNumberPeaks);
auto mockView = boost::shared_ptr<NiceMock<MockPeakOverlayView> >(pMockView);

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

Expand All @@ -133,6 +133,7 @@ class ConcretePeaksPresenterTest : public CxxTest::TestSuite
EXPECT_CALL(*pMockView, setSlicePoint(slicePoint)).Times(expectedNumberPeaks);
auto mockView = boost::shared_ptr<NiceMock<MockPeakOverlayView> >(pMockView);

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

Expand All @@ -157,6 +158,7 @@ class ConcretePeaksPresenterTest : public CxxTest::TestSuite
EXPECT_CALL(*pMockView, hideView()).Times(expectedNumberPeaks);
auto mockView = boost::shared_ptr<NiceMock<MockPeakOverlayView> >(pMockView);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class PeakOverlayFactoryBaseTest : public CxxTest::TestSuite
{
public:
MockPeakOverlayFactory(const FirstExperimentInfoQuery& query) : PeakOverlayFactoryBase(query){}
MOCK_CONST_METHOD3(createViewAtPoint, boost::shared_ptr<PeakOverlayView>(const Mantid::Kernel::V3D&, const double&, const bool));
MOCK_CONST_METHOD2(createViewAtPoint, boost::shared_ptr<PeakOverlayView>(const Mantid::Kernel::V3D&, const double&));
~MockPeakOverlayFactory(){}
};

Expand All @@ -48,7 +48,6 @@ class PeakOverlayFactoryBaseTest : public CxxTest::TestSuite
MOCK_METHOD0(updateView, void());
MOCK_METHOD1(setSlicePoint, void(const double&));
MOCK_METHOD0(hideView, void());
MOCK_METHOD1(setNormalisation, void(const double&));
~MockPeakOverlayView(){}
};

Expand Down

0 comments on commit 3599233

Please sign in to comment.