Skip to content

Commit

Permalink
refs #5167. Use PeaksTransform.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Nov 29, 2012
1 parent 3599233 commit 74ff1d7
Show file tree
Hide file tree
Showing 19 changed files with 392 additions and 58 deletions.
7 changes: 5 additions & 2 deletions Code/Mantid/MantidQt/SliceViewer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
set ( SRC_FILES
src/ColorBarWidget.cpp
src/ConcretePeaksPresenter.cpp
src/ConcretePeaksPresenter.cpp
src/CustomTools.cpp
src/DimensionSliceWidget.cpp
src/LineOverlay.cpp
src/LineViewer.cpp
src/PeakOverlay.cpp
src/PeakOverlayFactory.cpp
src/PeakOverlayFactoryBase.cpp
src/PeakTransform.cpp
src/QScienceSpinBox.cpp
src/QwtRasterDataMD.cpp
src/SliceViewer.cpp
Expand All @@ -34,7 +35,8 @@ set ( INC_FILES
inc/MantidQtSliceViewer/PeakOverlayFactory.h
inc/MantidQtSliceViewer/PeakOverlayFactoryBase.h
inc/MantidQtSliceViewer/PeaksPresenter.h
inc/MantidQtSliceViewer/QScienceSpinBox.h
inc/MantidQtSliceViewer/PeakTransform.h
inc/MantidQtSliceViewer/QScienceSpinBox.h
inc/MantidQtSliceViewer/QwtRasterDataMD.h
inc/MantidQtSliceViewer/SliceViewer.h
inc/MantidQtSliceViewer/SliceViewerWindow.h
Expand Down Expand Up @@ -70,6 +72,7 @@ set ( UI_FILES
set ( TEST_FILES
test/ConcretePeaksPresenterTest.h
test/PeakOverlayFactoryBaseTest.h
test/PeakTransformTest.h
)

# Python unit tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
#define MANTID_SLICEVIEWER_CONCRETEPEAKSPRESENTER_H_

#include "MantidQtSliceViewer/PeaksPresenter.h"
#include "MantidQtSliceViewer/PeakTransform.h"
#include "MantidKernel/V3D.h"
#include <vector>
#include <boost/shared_ptr.hpp>

namespace MantidQt
{
namespace SliceViewer
{
// Forward declaration.
class PeakOverlayViewFactory;

typedef std::vector< boost::shared_ptr<PeakOverlayView> > VecPeakOverlayView;
/*---------------------------------------------------------
ConcretePeaksPresenter
Expand All @@ -21,9 +27,16 @@ namespace MantidQt
virtual ~ConcretePeaksPresenter();
virtual void update();
virtual void updateWithSlicePoint(const double& slicePoint);
virtual void changeShownDim();
private:
/// Peak overlay views.
VecPeakOverlayView m_viewPeaks;
/// View factory
boost::shared_ptr<PeakOverlayViewFactory> m_factory;
/// Peak transformer
PeakTransform m_transform;
/// Configurre peak transformations
void configureMappingTransform();
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace MantidQt
virtual void updateWithSlicePoint(const double&)
{
}
virtual void changeShownDim(){}
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ namespace SliceViewer
virtual void updateView();
/// Get the origin. md x, md y
const Mantid::Kernel::V3D & getOrigin() const;
/// Get the radius.
double getRadius() const;
/// Move the position of the peak, by using a different configuration of the existing origin indexes.
void movePosition(const PeakTransform& peakTransform);

private:

Expand All @@ -72,6 +75,8 @@ namespace SliceViewer

/// QwtPlot containing this
QwtPlot * m_plot;
/// Original origin x=h, y=k, z=l
const Mantid::Kernel::V3D m_originalOrigin;
/// Origin md-x, md-y, and md-z
Mantid::Kernel::V3D m_origin;
/// actual peak radius
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,13 @@ namespace MantidQt
private:
QwtPlot * m_plot;
QWidget * m_parent;

public:
PeakOverlayFactory(QwtPlot * plot, QWidget * parent, const FirstExperimentInfoQuery& query);
PeakOverlayFactory(QwtPlot * plot, QWidget * parent);
virtual ~PeakOverlayFactory();
virtual boost::shared_ptr<PeakOverlayView> createViewAtPoint(const Mantid::Kernel::V3D& position, const double& radius) const;
virtual std::string getPlotXLabel() const;
virtual std::string getPlotYLabel() const;
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@ namespace MantidQt
{
namespace SliceViewer
{
class FirstExperimentInfoQuery;
class DLLExport PeakOverlayFactoryBase : public PeakOverlayViewFactory
{
public:
PeakOverlayFactoryBase(const FirstExperimentInfoQuery& query);
PeakOverlayFactoryBase();
~PeakOverlayFactoryBase();
void setRadius(const double& radius);
virtual boost::shared_ptr<PeakOverlayView> createView(const Mantid::API::IPeak&) const;

virtual boost::shared_ptr<PeakOverlayView> createView(const Mantid::Kernel::V3D&) const;
protected:
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define MANTID_SLICEVIEWER_PEAKOVERLAY_VIEW_H_

#include "MantidKernel/System.h"
#include "MantidQtSliceViewer/PeakTransform.h"
#include <QPointF>
#include <boost/shared_ptr.hpp>

Expand Down Expand Up @@ -43,6 +44,8 @@ namespace MantidQt
virtual void updateView() = 0;
/// Hide the view.
virtual void hideView() = 0;
/// Move the peak overlay to a new position.
virtual void movePosition(const PeakTransform& peakTransform) = 0;
/// Destructor
virtual ~PeakOverlayView()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define MANTID_SLICEVIEWER_PEAKOVERLAY_VIEW_FACTORY_H_

#include "MantidKernel/System.h"
#include "MantidKernel/V3D.h"
#include "MantidQtSliceViewer/PeakOverlayView.h"
#include <boost/shared_ptr.hpp>

Expand Down Expand Up @@ -46,13 +47,17 @@ namespace MantidQt
{
public:
/// Create a peak view from the peak object.
virtual boost::shared_ptr<PeakOverlayView> createView(const Mantid::API::IPeak&) const = 0;
virtual boost::shared_ptr<PeakOverlayView> createView(const Mantid::Kernel::V3D&) const = 0;
/// Setter for the radius to use for all peaks.
virtual void setRadius(const double& radius) = 0;
/// Destructor
virtual ~PeakOverlayViewFactory()
{
}
/// Get the plot x-axis label
virtual std::string getPlotXLabel() const = 0;
/// Get the plot y-axis label
virtual std::string getPlotYLabel() const = 0;
};
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef MANTID_SLICEVIEWER_PEAKTRANSFORM_H_
#define MANTID_SLICEVIEWER_PEAKTRANSFORM_H_

#include "MantidKernel/V3D.h"

namespace MantidQt
{
namespace SliceViewer
{
class DLLExport PeakTransform
{
public:
PeakTransform(const std::string& xPlotLabel, const std::string& yPlotLabel);
virtual ~PeakTransform();
PeakTransform(const PeakTransform& other);
PeakTransform & operator=(const PeakTransform & other);
Mantid::Kernel::V3D transform(const Mantid::Kernel::V3D& original) const;
private:
std::string m_xPlotLabel;
std::string m_yPlotLabel;
int m_indexOfPlotX;
int m_indexOfPlotY;
int m_indexOfPlotZ;
};

}
}

#endif /* MANTID_SLICEVIEWER_CONCRETEPEAKSPRESENTER_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace SliceViewer
public:
virtual void update() = 0;
virtual void updateWithSlicePoint(const double&) = 0;
virtual void changeShownDim() = 0;
};


Expand Down
43 changes: 38 additions & 5 deletions Code/Mantid/MantidQt/SliceViewer/src/ConcretePeaksPresenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "MantidAPI/IPeak.h"
#include "MantidQtSliceViewer/PeakOverlayViewFactory.h"
#include <boost/scoped_ptr.hpp>
#include <boost/regex.hpp>

namespace MantidQt
{
Expand All @@ -20,6 +21,7 @@ namespace SliceViewer
@param peaksWS : IPeaksWorkspace to visualise (THE MODEL)
*/
ConcretePeaksPresenter::ConcretePeaksPresenter(PeakOverlayViewFactory* factory, Mantid::API::IPeaksWorkspace_sptr peaksWS) : m_viewPeaks(peaksWS->getNumberPeaks())
, m_factory(factory), m_transform("H", "K")
{
if(factory == NULL)
{
Expand All @@ -33,17 +35,18 @@ namespace SliceViewer
{
throw std::invalid_argument("PeaksWorkspace does not contain integrated peaks."); // We might consider drawing these in the future anyway.
}

this->configureMappingTransform();
// 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);
factory->setRadius(peakIntegrationRadius);

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

PeakOverlayView_sptr view = boost::shared_ptr<PeakOverlayView>( m_factory->createView(m_transform.transform(position)) );
m_viewPeaks[i] = view;
}
}

Expand Down Expand Up @@ -80,5 +83,35 @@ namespace SliceViewer
(*it)->hideView();
}
}

/**
Respond to changes in the shown dimension.
*/
void ConcretePeaksPresenter::changeShownDim()
{
// Reconfigure the mapping tranform.
this->configureMappingTransform();
// Apply the mapping tranform to move each peak overlay object.

for(VecPeakOverlayView::iterator it = m_viewPeaks.begin(); it != m_viewPeaks.end(); ++it)
{
(*it)->movePosition(m_transform);
}
}

/**
This method looks at the plotted dimensions (XY) , and work out what indexes into the vector HKL, these XYZ dimensions correpond to.
The indexes can then be used for any future transformation, where the user changes the chosen dimensions to plot.
*/
void ConcretePeaksPresenter::configureMappingTransform()
{
std::string xLabel = m_factory->getPlotXLabel();
std::string yLabel = m_factory->getPlotYLabel();


}

}
}
7 changes: 7 additions & 0 deletions Code/Mantid/MantidQt/SliceViewer/src/PeakOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace SliceViewer
PeakOverlay::PeakOverlay(QwtPlot * plot, QWidget * parent, const Mantid::Kernel::V3D& origin, const double& radius)
: QWidget( parent ),
m_plot(plot),
m_originalOrigin(origin),
m_origin(origin),
m_radius(radius),
m_opacityMax(0.8),
Expand Down Expand Up @@ -150,5 +151,11 @@ namespace SliceViewer
this->hide();
}

void PeakOverlay::movePosition(const PeakTransform& transform)
{
// Will have the plots x, y, and z aligned to the correct h, k, l value.
m_origin = transform.transform(this->m_originalOrigin);
}

} // namespace Mantid
} // namespace SliceViewer
14 changes: 13 additions & 1 deletion Code/Mantid/MantidQt/SliceViewer/src/PeakOverlayFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace MantidQt
namespace SliceViewer
{

PeakOverlayFactory::PeakOverlayFactory(QwtPlot * plot, QWidget * parent, const FirstExperimentInfoQuery& query) : PeakOverlayFactoryBase(query), m_plot(plot), m_parent(parent)
PeakOverlayFactory::PeakOverlayFactory(QwtPlot * plot, QWidget * parent) : PeakOverlayFactoryBase(), m_plot(plot), m_parent(parent)
{
if(!plot)
throw std::invalid_argument("PeakOverlayFactory plot is null");
Expand All @@ -27,6 +27,18 @@ namespace MantidQt
return boost::make_shared<PeakOverlay>(m_plot, m_parent, position, radius);
}

std::string PeakOverlayFactory::getPlotXLabel() const
{
QwtText xDim = m_plot->axisTitle(QwtPlot::xBottom);
return xDim.text().toStdString();
}

std::string PeakOverlayFactory::getPlotYLabel() const
{
QwtText yDim = m_plot->axisTitle(QwtPlot::yLeft);
return yDim.text().toStdString();
}

PeakOverlayFactory::~PeakOverlayFactory()
{
}
Expand Down
26 changes: 4 additions & 22 deletions Code/Mantid/MantidQt/SliceViewer/src/PeakOverlayFactoryBase.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
#include "MantidQtSliceViewer/PeakOverlayFactoryBase.h"
#include "MantidQtSliceViewer/FirstExperimentInfoQuery.h"
#include "MantidAPI/IPeak.h"
#include <boost/regex.hpp>

namespace MantidQt
{
namespace SliceViewer
{

PeakOverlayFactoryBase::PeakOverlayFactoryBase(const FirstExperimentInfoQuery& query) : m_peakRadius(1)
PeakOverlayFactoryBase::PeakOverlayFactoryBase() : m_peakRadius(1)
{
if(!query.hasOrientedLattice())
{
throw std::invalid_argument("Input MDWorkspace must be in QSpace HKL and must have an oriented lattice.");
}

}

PeakOverlayFactoryBase::~PeakOverlayFactoryBase()
Expand All @@ -28,23 +25,8 @@ namespace MantidQt
m_peakRadius = peakRadius;
}

boost::shared_ptr<PeakOverlayView> PeakOverlayFactoryBase::createView(const Mantid::API::IPeak& peak) const
boost::shared_ptr<PeakOverlayView> PeakOverlayFactoryBase::createView(const Mantid::Kernel::V3D& position) const
{
Mantid::Kernel::V3D position = peak.getHKL();

double intensity = peak.getIntensity();

//QwtText xDim = m_plot->axisTitle(QwtPlot::xBottom);
//QwtText yDim = m_plot->axisTitle(QwtPlot::yLeft);

// Does the peak match the regex


/* 1) Find out which dimensions are being plotted on x and y
2) Find out what h, k, l each of these dimensions correspond to.
3) Create the origin x, y based on these hkl values.
*/

return this->createViewAtPoint(position, m_peakRadius);
}

Expand Down

0 comments on commit 74ff1d7

Please sign in to comment.