Skip to content

Commit

Permalink
refs #6279. Can now visualise non-integrated peaks wokspaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Dec 11, 2012
1 parent cf27410 commit b40403d
Show file tree
Hide file tree
Showing 15 changed files with 414 additions and 36 deletions.
5 changes: 4 additions & 1 deletion Code/Mantid/MantidQt/SliceViewer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set ( SRC_FILES
src/LineOverlay.cpp
src/LineViewer.cpp
src/PeakOverlaySphere.cpp
src/PeakOverlayCross.cpp
src/PeakOverlaySphereFactory.cpp
src/PeakOverlayCrossFactory.cpp
src/PeakOverlayViewFactoryBase.cpp
Expand Down Expand Up @@ -38,6 +39,7 @@ set ( INC_FILES
inc/MantidQtSliceViewer/LineViewer.h
inc/MantidQtSliceViewer/NullPeaksPresenter.h
inc/MantidQtSliceViewer/PeakOverlaySphere.h
inc/MantidQtSliceViewer/PeakOverlayCross.h
inc/MantidQtSliceViewer/PeakOverlayView.h
inc/MantidQtSliceViewer/PeakOverlayViewFactory.h
inc/MantidQtSliceViewer/PeakOverlayViewFactoryBase.h
Expand All @@ -64,6 +66,7 @@ set ( MOC_FILES
inc/MantidQtSliceViewer/LineOverlay.h
inc/MantidQtSliceViewer/LineViewer.h
inc/MantidQtSliceViewer/LinePlotOptions.h
inc/MantidQtSliceViewer/PeakOverlayCross.h
inc/MantidQtSliceViewer/PeakOverlaySphere.h
inc/MantidQtSliceViewer/SliceViewer.h
inc/MantidQtSliceViewer/SliceViewerWindow.h
Expand Down Expand Up @@ -140,7 +143,7 @@ if ( CXXTEST_FOUND )
include_directories( ../../Framework/TestHelpers/inc ../../Framework/DataObjects/inc ../../Framework/Crystal/inc )

set ( TESTHELPER_SRCS ../../Framework/TestHelpers/src/WorkspaceCreationHelper.cpp
../../Framework/TestHelpers/src/ComponentCreationHelper.cpp
../../Framework/TestHelpers/src/ComponentCreationHelper.cpp
)

if ( GMOCK_FOUND AND GTEST_FOUND )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "MantidQtSliceViewer/PeaksPresenter.h"
#include "MantidQtSliceViewer/PeakTransform.h"
#include "MantidAPI/MDGeometry.h"
#include "MantidAPI/IPeaksWorkspace.h"
#include "MantidKernel/V3D.h"
#include <vector>
#include <boost/shared_ptr.hpp>
Expand All @@ -11,11 +13,13 @@ namespace MantidQt
{
namespace SliceViewer
{
// Forward declaration.
// Forward declarations.
class PeakOverlayViewFactory;
class PeakTransformFactory;

/// Alias for Vector of Peak Overlay Views
typedef std::vector< boost::shared_ptr<PeakOverlayView> > VecPeakOverlayView;

/*---------------------------------------------------------
ConcretePeaksPresenter
Expand All @@ -24,7 +28,7 @@ namespace MantidQt
class DLLExport ConcretePeaksPresenter : public PeaksPresenter
{
public:
ConcretePeaksPresenter(boost::shared_ptr<PeakOverlayViewFactory> nonIntegratedViewFactory, boost::shared_ptr<PeakOverlayViewFactory> integratedViewFactory, boost::shared_ptr<Mantid::API::IPeaksWorkspace> peaksWS, boost::shared_ptr<PeakTransformFactory> transformFactory);
ConcretePeaksPresenter(boost::shared_ptr<PeakOverlayViewFactory> nonIntegratedViewFactory, boost::shared_ptr<PeakOverlayViewFactory> integratedViewFactory, boost::shared_ptr<Mantid::API::IPeaksWorkspace> peaksWS, boost::shared_ptr<Mantid::API::MDGeometry> mdWS, boost::shared_ptr<PeakTransformFactory> transformFactory);
virtual ~ConcretePeaksPresenter();
virtual void update();
virtual void updateWithSlicePoint(const double& slicePoint);
Expand All @@ -47,6 +51,8 @@ namespace MantidQt
void hideAll();
/// Show all views
void showAll();
/// determine wheter a dimension name corresponds to the free axis for the peaks workspace.
bool isDimensionNameOfFreeAxis(const std::string& name) const;
};

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#ifndef MANTID_SLICEVIEWER_PEAKOVERLAYCROSS_H_
#define MANTID_SLICEVIEWER_PEAKOVERLAYCROSS_H_

#include "DllOption.h"
#include "MantidKernel/System.h"
#include "MantidKernel/V3D.h"
#include <q3iconview.h>
#include <QtCore/QtCore>
#include <QtGui/qwidget.h>
#include <qwt_plot.h>
#include <qpainter.h>
#include <qcolor.h>
#include "MantidQtSliceViewer/PeakOverlayView.h"


namespace MantidQt
{
namespace SliceViewer
{

/** Widget representing a peak sphere on the plot. Used for representing spherically integrated peaks.
@date 2012-08-22
Copyright &copy; 2011 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class EXPORT_OPT_MANTIDQT_SLICEVIEWER PeakOverlayCross : public QWidget, public PeakOverlayView
{
Q_OBJECT

public:
/// Constructor
PeakOverlayCross(QwtPlot * plot, QWidget * parent, const Mantid::Kernel::V3D& origin, const double& maxZ, const double& minZ, const QColor& peakColour);
/// Destructor
virtual ~PeakOverlayCross();
/// Set the slice point at position.
virtual void setSlicePoint(const double& point);
/// Hide the view.
virtual void hideView();
/// Show the view.
virtual void showView();
/// Update the view.
virtual void updateView();
/// Get the origin. md x, md y
const Mantid::Kernel::V3D & getOrigin() const;
/// Move the position of the peak, by using a different configuration of the existing origin indexes.
void movePosition(PeakTransform_sptr peakTransform);

private:

//QRect drawHandle(QPainter & painter, QPointF coords, QColor brush);
void paintEvent(QPaintEvent *event);

QSize sizeHint() const;
QSize size() const;
int height() const;
int width() const;

/// 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;
/// Effective radius of the widget. This is so that the widget can be effectively brought in and out of focus as a result of slicing.
const double m_effectiveRadius;
/// normalisation value.
double m_normalisation;
/// Max opacity
const double m_opacityMax;
/// Min opacity
const double m_opacityMin;
/// Cross size percentage in y a fraction of the current screen height.
const double m_crossViewFraction;
/// Peak colour
QColor m_peakColour;
/// Cached opacity at the distance z from origin
double m_opacityAtDistance;
};


} // namespace SliceViewer
} // namespace Mantid

#endif /* MANTID_SLICEVIEWER_PEAKOVERLAYCROSS_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ namespace MantidQt
PeakOverlayCrossFactory(QwtPlot * plot, QWidget * parent, const size_t colourNumber=0);
virtual ~PeakOverlayCrossFactory();
boost::shared_ptr<PeakOverlayView> createView(const Mantid::Kernel::V3D& position) const;
virtual void setRadius(const double&)
virtual void setRadius(const double& radius)
{
// Do nothing.
//Do nothing.
}
virtual void setZRange(const double& max, const double& min);
private:
double m_zMax;
double m_zMin;
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ namespace MantidQt
virtual ~PeakOverlaySphereFactory();
boost::shared_ptr<PeakOverlayView> createView(const Mantid::Kernel::V3D& position) const;
virtual void setRadius(const double& peakRadius);
virtual void setZRange(const double& max, const double& min)
{
// Do nothing.
}
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ namespace MantidQt
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;
/// Setter for the z range.
virtual void setZRange(const double& max, const double& min) = 0;
/// Destructor
virtual ~PeakOverlayViewFactory()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@
#include <boost/shared_ptr.hpp>
#include "MantidKernel/System.h"

namespace Mantid
{
namespace API
{
// Forward dec.
class IPeaksWorkspace;
}
}

namespace MantidQt
{
namespace SliceViewer
Expand Down
35 changes: 32 additions & 3 deletions Code/Mantid/MantidQt/SliceViewer/src/ConcretePeaksPresenter.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#include "MantidQtSliceViewer/ConcretePeaksPresenter.h"
#include "MantidAPI/IPeaksWorkspace.h"
#include "MantidAPI/IPeak.h"
#include "MantidAPI/IMDWorkspace.h"
#include "MantidGeometry/MDGeometry/IMDDimension.h"
#include "MantidQtSliceViewer/PeakOverlayViewFactory.h"
#include "MantidQtSliceViewer/PeakTransformFactory.h"
#include <boost/scoped_ptr.hpp>
#include <boost/regex.hpp>

using namespace Mantid::API;
using Mantid::Geometry::IMDDimension_const_sptr;

namespace MantidQt
{
namespace SliceViewer
Expand All @@ -20,9 +25,10 @@ namespace SliceViewer
@param nonIntegratedViewFactory : View Factory (THE VIEW via factory)
@param integratedViewFactory : View Factory (THE VIEW via factory)
@param peaksWS : IPeaksWorkspace to visualise (THE MODEL)
@param mdWS : IMDWorkspace also being visualised (THE MODEL)
@param peaksTransform : Peak Transformation Factory. This is about interpreting the MODEL.
*/
ConcretePeaksPresenter::ConcretePeaksPresenter(PeakOverlayViewFactory_sptr nonIntegratedViewFactory, PeakOverlayViewFactory_sptr integratedViewFactory, Mantid::API::IPeaksWorkspace_sptr peaksWS, PeakTransformFactory_sptr transformFactory) : m_viewPeaks(peaksWS->getNumberPeaks())
ConcretePeaksPresenter::ConcretePeaksPresenter(PeakOverlayViewFactory_sptr nonIntegratedViewFactory, PeakOverlayViewFactory_sptr integratedViewFactory, IPeaksWorkspace_sptr peaksWS, boost::shared_ptr<MDGeometry> mdWS, PeakTransformFactory_sptr transformFactory) : m_viewPeaks(peaksWS->getNumberPeaks())
, m_viewFactory(integratedViewFactory), m_transformFactory(transformFactory), m_transform(transformFactory->createDefaultTransform()), m_slicePoint(0)
{
if(integratedViewFactory == NULL)
Expand All @@ -39,6 +45,8 @@ namespace SliceViewer
}

double peakIntegrationRadius = 0;
double maxZ = 0;
double minZ = 0;
if(peaksWS->hasIntegratedPeaks())
{
peakIntegrationRadius = boost::lexical_cast<double>(peaksWS->run().getProperty("PeakRadius")->value());
Expand All @@ -47,15 +55,26 @@ namespace SliceViewer
{
// Swap the view factory. We are not plotting integrated peaks now.
m_viewFactory.swap(nonIntegratedViewFactory);
// Find the range for the z slider axis.
for(size_t dimIndex = 0; dimIndex < mdWS->getNumDims(); ++dimIndex)
{
IMDDimension_const_sptr dimensionMappedToZ = mdWS->getDimension(dimIndex);
if(this->isDimensionNameOfFreeAxis(dimensionMappedToZ->getName()))
{
maxZ = dimensionMappedToZ->getMaximum();
minZ = dimensionMappedToZ->getMinimum();
}
}
}
m_viewFactory->setRadius(peakIntegrationRadius);
m_viewFactory->setZRange(maxZ, minZ);

const bool transformSucceeded = this->configureMappingTransform();

// Make and register each peak widget.
for(int i = 0; i < peaksWS->getNumberPeaks(); ++i)
{
const Mantid::API::IPeak& peak = peaksWS->getPeak(i);
const IPeak& peak = peaksWS->getPeak(i);
PeakOverlayView_sptr view = boost::shared_ptr<PeakOverlayView>( m_viewFactory->createView(m_transform->transformPeak(peak)) );
m_viewPeaks[i] = view;
}
Expand Down Expand Up @@ -150,7 +169,17 @@ namespace SliceViewer
*/
bool ConcretePeaksPresenter::isLabelOfFreeAxis(const std::string& label) const
{
return boost::regex_match(label, m_transform->getFreePeakAxisRegex());
return isDimensionNameOfFreeAxis(label);
}

/**
Determine whether the candidate dimension name is the name of the free axis.
@param name: The candidate dimension name to consider.
@return True if it matches the label of the free axis accoring to the current peaks transform.
*/
bool ConcretePeaksPresenter::isDimensionNameOfFreeAxis(const std::string& name) const
{
return boost::regex_match(name, m_transform->getFreePeakAxisRegex());
}

/**
Expand Down

0 comments on commit b40403d

Please sign in to comment.