Skip to content

Commit

Permalink
refs #5167. Fix display update issues.
Browse files Browse the repository at this point in the history
Fix issue where peaks dont display until slider is moved.
Fix issue where the correct slider to use is unknown.
Fix issue where the peakstransform is not getting updated with the new plot axis
Fix issue where the peak shape is fixed circular based on one axis range.
  • Loading branch information
OwenArnold committed Nov 29, 2012
1 parent 74ff1d7 commit a7866b4
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace MantidQt
virtual void update();
virtual void updateWithSlicePoint(const double& slicePoint);
virtual void changeShownDim();
virtual bool isLabelOfFreeAxis(const std::string& label) const;
private:
/// Peak overlay views.
VecPeakOverlayView m_viewPeaks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class EXPORT_OPT_MANTIDQT_SLICEVIEWER DimensionSliceWidget : public QWidget
double getSlicePoint() const
{ return m_slicePoint; }

std::string getDimName() const
{ return m_dim->getName(); }

/// @return the shown dimension, 0=X, 1=Y, -1=None
int getShownDim() const
{ return m_shownDim; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ namespace MantidQt
{
public:
virtual void update(){}
virtual void updateWithSlicePoint(const double&)
{
}
virtual void updateWithSlicePoint(const double&){}
virtual void changeShownDim(){}
virtual bool isLabelOfFreeAxis(const std::string&) const {return false;}
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define MANTID_SLICEVIEWER_PEAKTRANSFORM_H_

#include "MantidKernel/V3D.h"
#include <boost/regex.hpp>

namespace MantidQt
{
Expand All @@ -15,12 +16,16 @@ namespace MantidQt
PeakTransform(const PeakTransform& other);
PeakTransform & operator=(const PeakTransform & other);
Mantid::Kernel::V3D transform(const Mantid::Kernel::V3D& original) const;
boost::regex getFreePeakAxisRegex() const;
private:
std::string m_xPlotLabel;
std::string m_yPlotLabel;
int m_indexOfPlotX;
int m_indexOfPlotY;
int m_indexOfPlotZ;
boost::regex m_HRegex;
boost::regex m_KRegex;
boost::regex m_LRegex;
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace SliceViewer
virtual void update() = 0;
virtual void updateWithSlicePoint(const double&) = 0;
virtual void changeShownDim() = 0;
virtual bool isLabelOfFreeAxis(const std::string& label) const = 0;
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public slots:

void findRangeFull();
void findRangeSlice();
void updatePeaksWithSlicePoint();


private:
Expand Down
12 changes: 10 additions & 2 deletions Code/Mantid/MantidQt/SliceViewer/src/ConcretePeaksPresenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ namespace SliceViewer
}

/**
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.
Expand All @@ -109,8 +108,17 @@ namespace SliceViewer
{
std::string xLabel = m_factory->getPlotXLabel();
std::string yLabel = m_factory->getPlotYLabel();
m_transform = PeakTransform(xLabel, yLabel);
}


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

}
Expand Down
37 changes: 24 additions & 13 deletions Code/Mantid/MantidQt/SliceViewer/src/PeakOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace SliceViewer
{
setAttribute(Qt::WA_NoMousePropagation, false);
this->setVisible(true);
setUpdatesEnabled(true);
}

//----------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -75,11 +76,6 @@ namespace SliceViewer
{
m_radiusAtDistance = 0;
}

const QwtDoubleInterval interval = m_plot->axisScaleDiv(QwtPlot::yLeft)->interval();
const double yMin = interval.minValue();
const double yMax = interval.maxValue();
m_scale = height()/(yMax - yMin);

// Apply a linear transform to convert from a distance to an opacity between opacityMin and opacityMax.
m_opacityAtDistance = ((m_opacityMin - m_opacityMax)/m_radius) * distance + m_opacityMax;
Expand Down Expand Up @@ -122,28 +118,43 @@ namespace SliceViewer
const int yOrigin = m_plot->transform( QwtPlot::yLeft, m_origin.Y() );
const QPointF originWindows(xOrigin, yOrigin);

const double innerRadius = m_scale * m_radiusAtDistance;
double outerRadius = m_scale * getRadius();
double lineWidth = outerRadius - innerRadius;
outerRadius -= lineWidth/2;
const QwtDoubleInterval intervalY = m_plot->axisScaleDiv(QwtPlot::yLeft)->interval();
const QwtDoubleInterval intervalX = m_plot->axisScaleDiv(QwtPlot::xBottom)->interval();

const double scaleY = height()/(intervalY.width());
const double scaleX = width()/(intervalX.width());

const double innerRadiusX = scaleX * m_radiusAtDistance;
const double innerRadiusY = scaleY * m_radiusAtDistance;

double outerRadiusX = scaleX * getRadius();
double outerRadiusY = scaleY * getRadius();

const double lineWidthX = outerRadiusX - innerRadiusX;
const double lineWidthY = outerRadiusY - innerRadiusY;
outerRadiusX -= lineWidthX/2;
outerRadiusY -= lineWidthY/2;

QPainter painter(this);
painter.setRenderHint( QPainter::Antialiasing );

// Draw Outer circle
QPen pen( Qt::green );
pen.setWidth(static_cast<int>(std::abs(lineWidth)));
painter.setPen( pen );
/* Note we are creating an ellipse here and generating a filled effect by controlling the line thickness.
Since the linewidth takes a single scalar value, we choose to use x as the scale value.
*/
pen.setWidth(static_cast<int>(std::abs(lineWidthX)));
painter.setPen( pen );

pen.setStyle(Qt::SolidLine);
painter.setOpacity(m_opacityAtDistance); //Set the pre-calculated opacity
painter.drawEllipse( originWindows, outerRadius, outerRadius );
painter.drawEllipse( originWindows, outerRadiusX, outerRadiusY );

}

void PeakOverlay::updateView()
{
this->update();
this->repaint();
}

void PeakOverlay::hideView()
Expand Down
49 changes: 33 additions & 16 deletions Code/Mantid/MantidQt/SliceViewer/src/PeakTransform.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "MantidQtSliceViewer/PeakTransform.h"
#include <boost/regex.hpp>

namespace MantidQt
{
Expand All @@ -11,51 +10,50 @@ namespace MantidQt
m_yPlotLabel(yPlotLabel),
m_indexOfPlotX(0),
m_indexOfPlotY(1),
m_indexOfPlotZ(2)
m_indexOfPlotZ(2),
m_HRegex("^H.*$"),
m_KRegex("^K.*$"),
m_LRegex("^L.*$")
{
const std::string& xLabel = m_xPlotLabel;
const std::string& yLabel = m_yPlotLabel;

const boost::regex HRegex = boost::regex("^H.*$");
const boost::regex KRegex = boost::regex("^K.*$");
const boost::regex LRegex = boost::regex("^L.*$");

const int H = 0;
const int K = 1;
const int L = 2;

Mantid::Kernel::V3D positionInCoordinateSystem;
if(boost::regex_match(xLabel, HRegex) && boost::regex_match(yLabel, KRegex)) //HKL
if(boost::regex_match(xLabel, m_HRegex) && boost::regex_match(yLabel, m_KRegex)) //HKL
{
m_indexOfPlotX = H;
m_indexOfPlotY = K;
m_indexOfPlotZ = L;
}
else if(boost::regex_match(xLabel, HRegex) && boost::regex_match(yLabel, LRegex)) //HLK
else if(boost::regex_match(xLabel, m_HRegex) && boost::regex_match(yLabel, m_LRegex)) //HLK
{
m_indexOfPlotX = H;
m_indexOfPlotY = L;
m_indexOfPlotZ = K;
}
else if(boost::regex_match(xLabel, LRegex) && boost::regex_match(yLabel, HRegex)) //LHK
else if(boost::regex_match(xLabel, m_LRegex) && boost::regex_match(yLabel, m_HRegex)) //LHK
{
m_indexOfPlotX = L;
m_indexOfPlotY = H;
m_indexOfPlotZ = K;
}
else if(boost::regex_match(xLabel, LRegex) && boost::regex_match(yLabel, KRegex)) //LKH
else if(boost::regex_match(xLabel, m_LRegex) && boost::regex_match(yLabel, m_KRegex)) //LKH
{
m_indexOfPlotX = L;
m_indexOfPlotY = K;
m_indexOfPlotZ = H;
}
else if(boost::regex_match(xLabel, KRegex) && boost::regex_match(yLabel, LRegex)) //KLH
else if(boost::regex_match(xLabel, m_KRegex) && boost::regex_match(yLabel, m_LRegex)) //KLH
{
m_indexOfPlotX = K;
m_indexOfPlotY = L;
m_indexOfPlotZ = H;
}
else if(boost::regex_match(xLabel, KRegex) && boost::regex_match(yLabel, HRegex)) //KHL
else if(boost::regex_match(xLabel, m_KRegex) && boost::regex_match(yLabel, m_HRegex)) //KHL
{
m_indexOfPlotX = K;
m_indexOfPlotY = H;
Expand All @@ -68,23 +66,29 @@ namespace MantidQt
}

PeakTransform::PeakTransform(const PeakTransform& other):
m_xPlotLabel(other.m_xPlotLabel),
m_yPlotLabel(other.m_yPlotLabel),
m_indexOfPlotX(other.m_indexOfPlotX),
m_indexOfPlotY(other.m_indexOfPlotY),
m_indexOfPlotZ(other.m_indexOfPlotZ),
m_xPlotLabel(other.m_xPlotLabel),
m_yPlotLabel(other.m_yPlotLabel)
m_HRegex(other.m_HRegex),
m_KRegex(other.m_KRegex),
m_LRegex(other.m_LRegex)
{
}

PeakTransform& PeakTransform::operator=(const PeakTransform & other)
{
if(this != &other)
{
m_xPlotLabel = other.m_xPlotLabel;
m_yPlotLabel = other.m_yPlotLabel;
m_indexOfPlotX = other.m_indexOfPlotX;
m_indexOfPlotY = other.m_indexOfPlotY;
m_indexOfPlotZ = other.m_indexOfPlotZ;
m_xPlotLabel = other.m_xPlotLabel;
m_yPlotLabel = other.m_yPlotLabel;
m_HRegex = other.m_HRegex;
m_KRegex = other.m_KRegex;
m_LRegex = other.m_LRegex;
}
return *this;
}
Expand All @@ -93,6 +97,19 @@ namespace MantidQt
{
}

boost::regex PeakTransform::getFreePeakAxisRegex() const
{
switch(m_indexOfPlotZ)
{
case 0:
return m_HRegex;
case 1:
return m_KRegex;
case 2:
return m_LRegex;
}
}

Mantid::Kernel::V3D PeakTransform::transform(const Mantid::Kernel::V3D& original) const
{
// Will have the plots x, y, and z aligned to the correct h, k, l value.
Expand Down
39 changes: 25 additions & 14 deletions Code/Mantid/MantidQt/SliceViewer/src/SliceViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,6 @@ void SliceViewer::updateDisplay(bool resetAxes)
m_dimY = 1;
std::vector<coord_t> slicePoint;

std::vector<DimensionSliceWidget*> sliderWidgets;
//DimensionSliceWidget * widget
for (size_t d=0; d<m_ws->getNumDims(); d++)
{
Expand All @@ -1384,10 +1383,6 @@ void SliceViewer::updateDisplay(bool resetAxes)
{
m_dimY = d;
}
else
{
sliderWidgets.push_back(widget);
}
slicePoint.push_back(VMD_t(widget->getSlicePoint()));
}
// Avoid going out of range
Expand Down Expand Up @@ -1426,24 +1421,19 @@ void SliceViewer::updateDisplay(bool resetAxes)
m_overlayWSOutline->setShown(overlayInSlice);
}

if (sliderWidgets.size() > 0 ) // Temporary fix for crash when displaying Workspace2D (where m_dimWidgets only has 2 elements)
{
DimensionSliceWidget* slider = sliderWidgets.front(); // TODO, we need a better way of filtering the slider widgets to find the missing lattice unit.
m_peaksPresenter->updateWithSlicePoint(slider->getSlicePoint());
}

// Notify the graph that the underlying data changed
m_spect->setData(*m_data);
m_spect->itemChanged();
m_plot->replot();

/// Update the peak positions.
this->updatePeaksWithSlicePoint();

// Send out a signal
emit changedSlicePoint(m_slicePoint);
}



//------------------------------------------------------------------------------------
/** The user changed the shown dimension somewhere.
*
Expand Down Expand Up @@ -1481,10 +1471,11 @@ void SliceViewer::changedShownDim(int index, int dim, int oldDim)
}
}
}

// Show the new slice. This finds m_dimX and m_dimY
this->updateDisplay();
// Transform the peak overlays according to the new plotting.
m_peaksPresenter->changeShownDim();
// Show the new slice. This finds m_dimX and m_dimY
this->updateDisplay();
// Send out a signal
emit changedShownDim(m_dimX, m_dimY);
}
Expand Down Expand Up @@ -2098,6 +2089,7 @@ void SliceViewer::peakOverlay_toggled(bool checked)
IPeaksWorkspace_sptr peaksWS = AnalysisDataService::Instance().retrieveWS<IPeaksWorkspace>(list.front().toStdString());
PeakOverlayFactory* factory = new PeakOverlayFactory(m_plot, m_plot->canvas());
m_peaksPresenter = PeaksPresenter_sptr(new ConcretePeaksPresenter(factory, peaksWS));
updatePeaksWithSlicePoint();
}
}
}
Expand All @@ -2107,6 +2099,25 @@ void SliceViewer::peakOverlay_toggled(bool checked)
}
}

/**
Update the peaks overlay with a slice point.
Find the relevant dimension slider and then use the slice point from that slider.
*/
void SliceViewer::updatePeaksWithSlicePoint()
{
for (size_t d=0; d< m_ws->getNumDims(); d++)
{
DimensionSliceWidget * widget = m_dimWidgets[d];
if (widget->getShownDim() < 0)
{
if(m_peaksPresenter->isLabelOfFreeAxis(widget->getDimName()))
{
m_peaksPresenter->updateWithSlicePoint(widget->getSlicePoint());
}
}
}
}

} //namespace
}

Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ class ConcretePeaksPresenterTest : public CxxTest::TestSuite

TSM_ASSERT("MockView not used as expected.", Mock::VerifyAndClearExpectations(pMockView));
}

// TODO Test all 6 possible transformations in configureMappingTransform.

};

Expand Down

0 comments on commit a7866b4

Please sign in to comment.