Skip to content

Commit

Permalink
refs #5167. Transformations performed correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Aug 28, 2012
1 parent 7e8b78b commit 015ff3e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
#include <QtCore/QtCore>
#include <QtGui/qwidget.h>
#include <qwt_plot.h>
#include <qwt_plot_spectrogram.h>
#include <qpainter.h>



namespace MantidQt
{
namespace SliceViewer
{

/** GUI for overlaying a peak circle on the plot.
/** GUI for overlaying a peak ellipse on the plot.
@date 2012-08-22
Expand Down Expand Up @@ -43,25 +45,11 @@ namespace SliceViewer
{
Q_OBJECT

/// Enum giving IDs to the 4 handles on the widget
enum eHandleID
{
HandleNone = -1,
HandleA = 0,
HandleB = 1,
HandleWidthTop = 2,
HandleWidthBottom = 3,
HandleCenter = 4 // Anywhere inside the center
};

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

void reset();

void setOrigin(QPointF origin);
void setRadius(double radius);
void setPlaneDistance(const double& distance);

const QPointF & getOrigin() const;
double getRadius() const;
Expand All @@ -74,26 +62,21 @@ namespace SliceViewer
//QRect drawHandle(QPainter & painter, QPointF coords, QColor brush);
void paintEvent(QPaintEvent *event);

//eHandleID mouseOverHandle(QPoint pos);
//bool mouseOverCenter(QPoint pos);
//void handleDrag(QMouseEvent * event);
//void mouseMoveEvent(QMouseEvent * event);
//void mousePressEvent(QMouseEvent * event);
//void mouseReleaseEvent(QMouseEvent * event);

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

protected:

/// QwtPlot containing this
QwtPlot * m_plot;

QPointF m_origin;
QPointF m_radius;
const double m_opacityMax;
const double m_opacityMin;
double m_opacityAtDistance;

double m_radius;
double m_radiusXAtDistance;
double m_radiusYAtDistance;

};

Expand Down
68 changes: 41 additions & 27 deletions Code/Mantid/MantidQt/SliceViewer/src/PeakOverlay.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#include "MantidQtSliceViewer/PeakOverlay.h"
#include <qwt_plot.h>
#include <qwt_plot_canvas.h>
#include <qwt_scale_div.h>
#include <iostream>
#include <qpainter.h>
#include <QRect>
#include <QPen>
#include <QBrush>
#include <QShowEvent>
#include "MantidKernel/Utils.h"

Expand All @@ -19,12 +22,14 @@ namespace SliceViewer
//----------------------------------------------------------------------------------------------
/** Constructor
*/
PeakOverlay::PeakOverlay(QwtPlot * plot, QWidget * parent)
PeakOverlay::PeakOverlay(QwtPlot * plot, QWidget * parent, const QPointF& origin, const QPointF& radius)
: QWidget( parent ),
m_plot(plot)
m_plot(plot),
m_origin(origin),
m_radius(radius),
m_opacityMax(1),
m_opacityMin(0.1)
{
m_origin = QPointF(0.0, 0.0);
m_radius = 0.1;
//setAttribute(Qt::WA_TransparentForMouseEvents);
// We need mouse events all the time
setMouseTracking(true);
Expand All @@ -39,28 +44,17 @@ namespace SliceViewer
PeakOverlay::~PeakOverlay()
{
}

////----------------------------------------------------------------------------------------------
///** Reset the line. User will have to click to create it */
//void PeakOverlay::reset()
//{
// m_creation = true; // Will create with the mouse
// m_rightButton = false;
// m_dragHandle = HandleNone;
// this->update();
//}



void PeakOverlay::setOrigin(QPointF origin)
void PeakOverlay::setPlaneDistance(const double& distance)
{
m_origin = origin;
this->update(); //repaint
}
const double distanceSQ = distance * distance;
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_opacityAtDistance >= m_opacityMin ? m_opacityAtDistance : m_opacityMin;

void PeakOverlay::setRadius(double radius)
{
m_radius = radius;
this->update(); //repaint
}

Expand Down Expand Up @@ -89,18 +83,38 @@ namespace SliceViewer




//----------------------------------------------------------------------------------------------
/// Paint the overlay
void PeakOverlay::paintEvent(QPaintEvent * /*event*/)
{
// Linear Transform from MD coordinates into Windows/Qt coordinates for ellipse rendering.
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);

const double xMin = m_plot->axisScaleDiv(QwtPlot::xBottom)->lowerBound();
const double xMax = m_plot->axisScaleDiv(QwtPlot::xBottom)->upperBound();
const double scaleX = width()/(xMax - xMin);

const double yMin = m_plot->axisScaleDiv(QwtPlot::yLeft)->lowerBound();
const double yMax = m_plot->axisScaleDiv(QwtPlot::yLeft)->upperBound();
const double scaleY = height()/(yMax - yMin);

int rx = scaleX * m_radiusXAtDistance;
int ry = scaleY * m_radiusYAtDistance;

// Draw circle and inner circle.
QPainter painter(this);
painter.setRenderHint( QPainter::Antialiasing );

//painter.setPen( Qt::black );
painter.setBrush(Qt::red);
painter.drawEllipse( m_origin, width()/2, height()/2 );
painter.setOpacity(m_opacityAtDistance);
painter.setBrush(Qt::cyan);
painter.drawEllipse( originWindows, rx, ry );

QPen pen( Qt::green );
pen.setWidth(2);
painter.setPen( pen );
painter.drawEllipse( originWindows, rx, ry );

}

Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/MantidQt/SliceViewer/src/SliceViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ SliceViewer::SliceViewer(QWidget *parent)
m_overlayWSOutline->setShowHandles(false);
m_overlayWSOutline->setShowLine(false);
m_overlayWSOutline->setShown(false);

// -------- Peak Overlay ----------------
//m_peakOverlay = new PeakOverlay(m_plot, m_plot->canvas()); //TODO use the peak overlay
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);
ui.btnPeakOverlay->setEnabled(true);
}

Expand Down

0 comments on commit 015ff3e

Please sign in to comment.