Skip to content

Commit

Permalink
refs #5167. Remove dead code and document.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Aug 28, 2012
1 parent 015ff3e commit 72cc121
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ namespace SliceViewer
Q_OBJECT

public:
/// Constructor
PeakOverlay(QwtPlot * plot, QWidget * parent, const QPointF& origin, const QPointF& radius);
/// Destructor
virtual ~PeakOverlay();

void setPlaneDistance(const double& distance);

/// Set the distance between the origin and the plane in the z-md-coordinate system.
void setPlaneDistance(const double& dz);
/// Get the origin. md x, md y
const QPointF & getOrigin() const;
double getRadius() const;

Expand All @@ -69,15 +71,21 @@ namespace SliceViewer

/// QwtPlot containing this
QwtPlot * m_plot;
/// Origin md-x, md-y
QPointF m_origin;
/// Radius md-x, md-y
QPointF m_radius;
/// Max opacity
const double m_opacityMax;
/// Min opacity
const double m_opacityMin;
/// Cached opacity at the distance z from origin
double m_opacityAtDistance;

/// Cached radius at the distance z from origin
double m_radiusXAtDistance;
/// Cached radius x at the distance x from origin, in md-x coordinates
double m_radiusYAtDistance;

/// Cached radius y at the distance y from origin, in md-y coordinates
};


Expand Down
38 changes: 28 additions & 10 deletions Code/Mantid/MantidQt/SliceViewer/src/PeakOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ namespace SliceViewer
m_opacityMax(1),
m_opacityMin(0.1)
{
//setAttribute(Qt::WA_TransparentForMouseEvents);
// We need mouse events all the time
setMouseTracking(true);
//setAttribute(Qt::WA_TransparentForMouseEvents);
// Make sure mouse propagates
setAttribute(Qt::WA_NoMousePropagation, false);
}

Expand All @@ -45,14 +40,37 @@ namespace SliceViewer
{
}

void PeakOverlay::setPlaneDistance(const double& distance)
//----------------------------------------------------------------------------------------------
/** 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 dz : distance from the peak cetner in the md coordinates of the z-axis.
/---------\
/ \
---/---------rx--\---------------- plane
| dz| /| peak
| | / |
| . / |
| |
\ /
\ /
\---------/
*/
void PeakOverlay::setPlaneDistance(const double& dz)
{
const double distanceSQ = distance * distance;
/*
Note that this is actually slightly wrong since the distance is in the z-axis, we must scale the distance to the x-axis and
y-axis first. However, since the same feature will be applied to each peak radius and each peak opacity, I'm leaving it for the time-being.
*/
const double distanceSQ = dz * dz;
m_radiusXAtDistance = std::sqrt( (m_radius.x() * m_radius.x()) - distanceSQ );
m_radiusYAtDistance = std::sqrt( (m_radius.y() * m_radius.y()) - distanceSQ );

// Apply a linear transform to convert from a distance to an opacity between opacityMin and opacityMax.
m_opacityAtDistance = ((m_opacityMin - m_opacityMax)/m_radius.x()) * distance + m_opacityMax;
m_opacityAtDistance = ((m_opacityMin - m_opacityMax)/m_radius.x()) * dz + m_opacityMax;
m_opacityAtDistance = m_opacityAtDistance >= m_opacityMin ? m_opacityAtDistance : m_opacityMin;

this->update(); //repaint
Expand Down Expand Up @@ -87,7 +105,7 @@ namespace SliceViewer
/// Paint the overlay
void PeakOverlay::paintEvent(QPaintEvent * /*event*/)
{
// Linear Transform from MD coordinates into Windows/Qt coordinates for ellipse rendering.
// Linear Transform from MD coordinates into Windows/Qt coordinates for ellipse rendering. TODO: This can be done outside of paintEvent.
const int xOrigin = m_plot->transform( QwtPlot::xBottom, m_origin.x() );
const int yOrigin = m_plot->transform( QwtPlot::yLeft, m_origin.y() );
const QPointF originWindows(xOrigin, yOrigin);
Expand All @@ -107,7 +125,7 @@ namespace SliceViewer
QPainter painter(this);
painter.setRenderHint( QPainter::Antialiasing );

painter.setOpacity(m_opacityAtDistance);
painter.setOpacity(m_opacityAtDistance); //Set the pre-calculated opacity
painter.setBrush(Qt::cyan);
painter.drawEllipse( originWindows, rx, ry );

Expand Down

0 comments on commit 72cc121

Please sign in to comment.