Skip to content

Commit

Permalink
refs #6271. Ready to draw background radius.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Jan 7, 2013
1 parent aae5561 commit 4170f0a
Show file tree
Hide file tree
Showing 24 changed files with 214 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "MantidQtSliceViewer/NullPeaksPresenter.h"
#include "MantidQtSliceViewer/PeakPalette.h"
#include <vector>
#include <stdexcept>
#include <boost/shared_ptr.hpp>

namespace MantidQt
Expand All @@ -29,6 +30,7 @@ namespace MantidQt
SetPeaksWorkspaces presentedWorkspaces() const;
void setForegroundColour(const QColor){/*Do nothing*/}
void setBackgroundColour(const QColor){/*Do nothing*/}
void showBackgroundRadius(const bool show){/*Do nothing*/}
virtual std::string getTransformName() const;

/// Constructor
Expand All @@ -51,6 +53,8 @@ namespace MantidQt
QColor getBackgroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws) const;
/// Get a copy of the palette in its current state.
PeakPalette getPalette() const;
/// Setter for indicating whether the background radius will be shown.
void setBackgroundRadiusShown(const bool shown);
private:
/// Alias for container of subjects type.
typedef std::vector<PeaksPresenter_sptr> SubjectContainer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ namespace MantidQt
void hideAll();
/// Show all views
void showAll();
/// determine wheter a dimension name corresponds to the free axis for the peaks workspace.
/// Determine wheter a dimension name corresponds to the free axis for the peaks workspace.
bool isDimensionNameOfFreeAxis(const std::string& name) const;
/// Switch between showing background radius or not
void showBackgroundRadius(const bool show);
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ namespace MantidQt
void setForegroundColour(const QColor){/*Do nothing*/}
void setBackgroundColour(const QColor){/*Do nothing*/}
std::string getTransformName() const {return "";}
/*virtual QColor getForegroundColour() const{ throw std::logic_error("NullPeaksPresenter::getForegroundColour not possible.");};
virtual QColor getBackgroundColour() const{ throw std::logic_error("NullPeaksPresenter::getBackgroundColour not possible");};*/
void showBackgroundRadius(const bool){/*Do nothing*/}
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ 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 setPeakRadius(const double&, const double&, const double&)
{
//Do nothing.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace SliceViewer

public:
/// Constructor
PeakOverlaySphere(QwtPlot * plot, QWidget * parent, const Mantid::Kernel::V3D& origin, const double& radius, const QColor& peakColour);
PeakOverlaySphere(QwtPlot * plot, QWidget * parent, const Mantid::Kernel::V3D& origin, const double& peakRadius, const double& backgroundInnerRadius, const double& backgroundOuterRadius, const QColor& peakColour);
/// Destructor
virtual ~PeakOverlaySphere();
/// Set the slice point at position.
Expand All @@ -66,6 +66,8 @@ namespace SliceViewer
virtual void changeForegroundColour(const QColor);
/// Change background colour
virtual void changeBackgroundColour(const QColor);
/// Show the background radius
virtual void showBackgroundRadius(const bool show);

private:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ namespace MantidQt
{
private:
double m_peakRadius;
double m_backgroundInnerRadius;
double m_backgroundOuterRadius;
public:
PeakOverlaySphereFactory(QwtPlot * plot, QWidget * parent, const size_t colourNumber=0);
virtual ~PeakOverlaySphereFactory();
boost::shared_ptr<PeakOverlayView> createView(const Mantid::Kernel::V3D& position) const;
virtual void setRadius(const double& peakRadius);
virtual void setPeakRadius(const double& peakRadius, const double& peakInnerRadius, const double& peakOuterRadius);
virtual void setZRange(const double&, const double&)
{
// Do nothing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ namespace MantidQt
virtual void changeForegroundColour(const QColor) = 0;
/// Change background colour
virtual void changeBackgroundColour(const QColor) = 0;
/// Show the background radius
virtual void showBackgroundRadius(const bool){}
/// Destructor
virtual ~PeakOverlayView()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ namespace MantidQt
public:
/// Create a peak view from the peak object.
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 peak radius to use for all peaks.
virtual void setPeakRadius(const double& peakRadius, const double& peakInnerRadius, const double& peakOuterRadius) = 0;
/// Setter for the z range.
virtual void setZRange(const double& max, const double& min) = 0;
/// Destructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ namespace SliceViewer
virtual void setForegroundColour(const QColor) = 0;
virtual void setBackgroundColour(const QColor) = 0;
virtual std::string getTransformName() const = 0;
/*virtual QColor getForegroundColour() const = 0;
virtual QColor getBackgroundColour() const = 0;*/
virtual void showBackgroundRadius(const bool shown) = 0;
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class EXPORT_OPT_MANTIDQT_SLICEVIEWER PeaksViewer : public QWidget
public slots:
void onPeakColourChanged(Mantid::API::IPeaksWorkspace_const_sptr, QColor);
void onBackgroundColourChanged(Mantid::API::IPeaksWorkspace_const_sptr, QColor);
void onBackgroundRadiusShown(bool);
private:
boost::shared_ptr<ProxyCompositePeaksPresenter> m_presenter;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ namespace SliceViewer
{
Q_OBJECT
public:
PeaksWorkspaceWidget(Mantid::API::IPeaksWorkspace_const_sptr ws, const std::string& coordinateSystem, QWidget *parent = 0);
PeaksWorkspaceWidget(Mantid::API::IPeaksWorkspace_const_sptr ws, const std::string& coordinateSystem, const QColor& defaultForegroundColour, const QColor& defaultBackgroundColour, QWidget *parent = 0);
~PeaksWorkspaceWidget();
signals:
void peakColourChanged(Mantid::API::IPeaksWorkspace_const_sptr, QColor);
void backgroundColourChanged(Mantid::API::IPeaksWorkspace_const_sptr, QColor);
void backgroundRadiusShown(bool);
private:
/// Populate the widget with model data.
void populate();
Expand All @@ -29,10 +30,16 @@ namespace SliceViewer
Mantid::API::IPeaksWorkspace_const_sptr m_ws;
/// Coordinate system.
const std::string m_coordinateSystem;
/// Foreground colour
QColor m_foregroundColour;
/// Background colour
QColor m_backgroundColour;

private slots:
void onExpandChanged(bool);
void onBackgroundColourClicked();
void onForegroundColourClicked();
void onShowBackgroundChanged(bool);
};

} //namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace MantidQt
{
public:
/// Constructor
PhysicalSphericalPeak(const Mantid::Kernel::V3D& origin, const double& radius);
PhysicalSphericalPeak(const Mantid::Kernel::V3D& origin, const double& peakRadius, const double& backgroundInnerRadius, const double& backgroundOuterRadius);
/// Destructor
~PhysicalSphericalPeak();
/// Setter for the slice point.
Expand All @@ -47,28 +47,54 @@ namespace MantidQt
*/
inline bool isViewable() const
{
return (m_cachedOpacityAtDistance != m_opacityMin);
if(m_showBackgroundRadius)
{
return (m_backgroundOuterRadiusAtDistance <= this->m_backgroundOuterRadius);
}
else
{
return (m_peakRadiusAtDistance <= this->m_peakRadius);
}
}

/// Setter to command whether the background radius should also be shown.
void showBackgroundRadius(const bool show);

private:
/// 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
const double m_radius;
const double m_peakRadius;
/// Peak background inner radius
const double m_backgroundInnerRadius;
/// Peak background outer radius
const double m_backgroundOuterRadius;
/// Max opacity
const double m_opacityMax;
/// Min opacity
const double m_opacityMin;
/// Cached opacity at the distance z from origin
double m_cachedOpacityAtDistance;
/// Cached radius at the distance z from origin
double m_cachedRadiusAtDistance;
double m_peakRadiusAtDistance;
/// Cached opacity gradient.
const double m_cachedOpacityGradient;
/// Cached radius squared.
const double m_cachedRadiusSQ;
const double m_peakRadiusSQ;
/// Cached background inner radius sq.
const double m_backgroundInnerRadiusSQ;
/// Cached background outer radius sq.
double m_backgroundOuterRadiusSQ;
/// Flag to indicate that the background radius should be drawn.
bool m_showBackgroundRadius;
/// Inner radius at distance.
double m_backgroundInnerRadiusAtDistance;
/// Outer radius at distance.
double m_backgroundOuterRadiusAtDistance;
/// Current slicepoint.
double m_currentSlicePoint;

DISABLE_COPY_AND_ASSIGN(PhysicalSphericalPeak)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ namespace MantidQt
SetPeaksWorkspaces presentedWorkspaces() const;
/// Gets the transform name.
std::string getTransformName() const;
/// Change whether the background radius is shown.
void setBackgroundRadiusShown(const bool shown);

private:
/// Wrapped composite to delegate to.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,5 +251,10 @@ namespace MantidQt
const int pos = std::distance(m_subjects.begin(), iterator);
return m_palette.backgroundIndexToColour(pos);
}

void CompositePeaksPresenter::setBackgroundRadiusShown(const bool shown)
{

}
}
}
19 changes: 18 additions & 1 deletion Code/Mantid/MantidQt/SliceViewer/src/ConcretePeaksPresenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ namespace SliceViewer
}

double peakIntegrationRadius = 0;
double backgroundInnerRadius = 0;
double backgroundOuterRadius = 0;
double maxZ = 0;
double minZ = 0;
if(peaksWS->hasIntegratedPeaks())
{
peakIntegrationRadius = boost::lexical_cast<double>(peaksWS->run().getProperty("PeakRadius")->value());
backgroundInnerRadius = boost::lexical_cast<double>(peaksWS->run().getProperty("BackgroundInnerRadius")->value());
backgroundOuterRadius = boost::lexical_cast<double>(peaksWS->run().getProperty("BackgroundOuterRadius")->value());
}
else
{
Expand All @@ -66,7 +70,7 @@ namespace SliceViewer
}
}
}
m_viewFactory->setRadius(peakIntegrationRadius);
m_viewFactory->setPeakRadius(peakIntegrationRadius, backgroundInnerRadius, backgroundOuterRadius);
m_viewFactory->setZRange(maxZ, minZ);

const bool transformSucceeded = this->configureMappingTransform();
Expand Down Expand Up @@ -255,5 +259,18 @@ namespace SliceViewer
return m_transform->getFriendlyName();
}

void ConcretePeaksPresenter::showBackgroundRadius(const bool show)
{
// Change background colours
for(VecPeakOverlayView::iterator it = m_viewPeaks.begin(); it != m_viewPeaks.end(); ++it)
{
if((*it) != NULL)
{
(*it)->showBackgroundRadius(show);
(*it)->updateView();
}
}
}

}
}
9 changes: 7 additions & 2 deletions Code/Mantid/MantidQt/SliceViewer/src/PeakOverlaySphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ namespace SliceViewer
//----------------------------------------------------------------------------------------------
/** Constructor
*/
PeakOverlaySphere::PeakOverlaySphere(QwtPlot * plot, QWidget * parent, const Mantid::Kernel::V3D& origin, const double& radius, const QColor& peakColour)
PeakOverlaySphere::PeakOverlaySphere(QwtPlot * plot, QWidget * parent, const Mantid::Kernel::V3D& origin, const double& peakRadius, const double& backgroundInnerRadius, const double& backgroundOuterRadius, const QColor& peakColour)
: QWidget( parent ),
m_plot(plot),
m_physicalPeak(origin, radius),
m_physicalPeak(origin, peakRadius, backgroundInnerRadius, backgroundOuterRadius),
m_peakColour(peakColour)
{
setAttribute(Qt::WA_NoMousePropagation, false);
Expand Down Expand Up @@ -127,5 +127,10 @@ namespace SliceViewer
// Not being drawn at the moment, TODO.
}

void PeakOverlaySphere::showBackgroundRadius(const bool show)
{
m_physicalPeak.showBackgroundRadius(show);
}

} // namespace Mantid
} // namespace SliceViewer
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace MantidQt

boost::shared_ptr<PeakOverlayView> PeakOverlaySphereFactory::createView(const Mantid::Kernel::V3D& position) const
{
return boost::make_shared<PeakOverlaySphere>(m_plot, m_parent, position, this->m_peakRadius, this->m_peakColour);
return boost::make_shared<PeakOverlaySphere>(m_plot, m_parent, position, this->m_peakRadius, this->m_backgroundInnerRadius, this->m_backgroundOuterRadius, this->m_peakColour);
}

PeakOverlaySphereFactory::~PeakOverlaySphereFactory()
Expand All @@ -26,9 +26,11 @@ 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 PeakOverlaySphereFactory::setRadius(const double& peakRadius)
void PeakOverlaySphereFactory::setPeakRadius(const double& peakRadius, const double& backgroundInnerRadius, const double& backgroundOuterRadius)
{
m_peakRadius = peakRadius;
m_backgroundInnerRadius = backgroundInnerRadius;
m_backgroundOuterRadius = backgroundOuterRadius;
}
}
}
14 changes: 12 additions & 2 deletions Code/Mantid/MantidQt/SliceViewer/src/PeaksViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace MantidQt
this->setMinimumWidth(500);
}

void PeaksViewer::setPeaksWorkspaces(const SetPeaksWorkspaces& workspaces)
void PeaksViewer::setPeaksWorkspaces(const SetPeaksWorkspaces&)
{
}

Expand Down Expand Up @@ -47,10 +47,15 @@ namespace MantidQt
auto it = workspaces.begin();
while(it != workspaces.end())
{
auto widget = new PeaksWorkspaceWidget(*it, coordinateSystem, this);
Mantid::API::IPeaksWorkspace_const_sptr ws = *it;
auto backgroundColour = m_presenter->getBackgroundColour(ws);
auto foregroundColour = m_presenter->getForegroundColour(ws);

auto widget = new PeaksWorkspaceWidget(ws, coordinateSystem, foregroundColour, backgroundColour, this);

connect(widget, SIGNAL(peakColourChanged(Mantid::API::IPeaksWorkspace_const_sptr, QColor)), this, SLOT(onPeakColourChanged(Mantid::API::IPeaksWorkspace_const_sptr, QColor)));
connect(widget, SIGNAL(backgroundColourChanged(Mantid::API::IPeaksWorkspace_const_sptr, QColor)), this, SLOT(onBackgroundColourChanged(Mantid::API::IPeaksWorkspace_const_sptr, QColor)));
connect(widget, SIGNAL(backgroundRadiusShown(bool)), this, SLOT(onBackgroundRadiusShown(bool)));
layout()->addWidget(widget);
++it;
}
Expand Down Expand Up @@ -86,5 +91,10 @@ namespace MantidQt
m_presenter->setBackgroundColour(peaksWS, newColour);
}

void PeaksViewer::onBackgroundRadiusShown(bool show)
{
m_presenter->setBackgroundRadiusShown(show);
}

} // namespace
}

0 comments on commit 4170f0a

Please sign in to comment.