Skip to content

Commit

Permalink
refs #5167. Blind optimisation.
Browse files Browse the repository at this point in the history
I havent done any benchmarking, but there are functions being run that dont always need to get run. Ive cached some variables rather than recalculate the results too. Would have been better to benchmark first, but Ill do some proper optimisation under another ticket at a later date.
  • Loading branch information
OwenArnold committed Nov 29, 2012
1 parent 610fa94 commit 453b6ed
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ namespace MantidQt
boost::shared_ptr<PeakOverlayViewFactory> m_factory;
/// Peak transformer
PeakTransform m_transform;
/// current slicing point.
double m_slicePoint;
/// Configurre peak transformations
bool configureMappingTransform();
/// Hide all views
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ namespace MantidQt
QwtPlot * m_plot;
QWidget * m_parent;
double m_peakRadius;
boost::shared_ptr<PeakOverlayView> createViewAtPoint(const Mantid::Kernel::V3D& position, const double& radius) const;

public:
PeakOverlayFactory(QwtPlot * plot, QWidget * parent);
virtual ~PeakOverlayFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public slots:
void findRangeSlice();

// Peak overlay methods.
void updatePeaksWithSlicePoint();
void updatePeakOverlaySliderWidget();
void enablePeakOverlaysIfAppropriate();


Expand Down Expand Up @@ -275,6 +275,9 @@ public slots:

// -------------------------- Controllers ------------------------
boost::shared_ptr<PeaksPresenter> m_peaksPresenter;

/// Pointer to widget used for peaks sliding.
DimensionSliceWidget* m_peaksSliderWidget;
};

} // namespace SliceViewer
Expand Down
10 changes: 7 additions & 3 deletions Code/Mantid/MantidQt/SliceViewer/src/ConcretePeaksPresenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace SliceViewer
@param peaksWS : IPeaksWorkspace to visualise (THE MODEL)
*/
ConcretePeaksPresenter::ConcretePeaksPresenter(PeakOverlayViewFactory* factory, Mantid::API::IPeaksWorkspace_sptr peaksWS) : m_viewPeaks(peaksWS->getNumberPeaks())
, m_factory(factory), m_transform("H", "K")
, m_factory(factory), m_transform("H", "K"), m_slicePoint(0)
{
if(factory == NULL)
{
Expand Down Expand Up @@ -71,9 +71,13 @@ namespace SliceViewer
*/
void ConcretePeaksPresenter::updateWithSlicePoint(const double& slicePoint)
{
for(VecPeakOverlayView::iterator it = m_viewPeaks.begin(); it != m_viewPeaks.end(); ++it)
if(m_slicePoint != slicePoint) // only update if required.
{
(*it)->setSlicePoint(slicePoint);
for(VecPeakOverlayView::iterator it = m_viewPeaks.begin(); it != m_viewPeaks.end(); ++it)
{
(*it)->setSlicePoint(slicePoint);
}
m_slicePoint = slicePoint;
}
}

Expand Down
7 changes: 1 addition & 6 deletions Code/Mantid/MantidQt/SliceViewer/src/PeakOverlayFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ namespace MantidQt

boost::shared_ptr<PeakOverlayView> PeakOverlayFactory::createView(const Mantid::Kernel::V3D& position) const
{
return this->createViewAtPoint(position, m_peakRadius);
}

boost::shared_ptr<PeakOverlayView> PeakOverlayFactory::createViewAtPoint(const Mantid::Kernel::V3D& position, const double& radius) const
{
return boost::make_shared<PeakOverlay>(m_plot, m_parent, position, radius);
return boost::make_shared<PeakOverlay>(m_plot, m_parent, position, this->m_peakRadius);
}

std::string PeakOverlayFactory::getPlotXLabel() const
Expand Down
35 changes: 20 additions & 15 deletions Code/Mantid/MantidQt/SliceViewer/src/SliceViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ SliceViewer::SliceViewer(QWidget *parent)
m_dimX(0), m_dimY(1),
m_logColor(false),
m_fastRender(true),
m_rebinMode(false), m_rebinLocked(true), m_peaksPresenter(PeaksPresenter_sptr(new NullPeaksPresenter))
m_rebinMode(false),
m_rebinLocked(true),
m_peaksPresenter(PeaksPresenter_sptr(new NullPeaksPresenter)),
m_peaksSliderWidget(NULL)
{
ui.setupUi(this);

Expand Down Expand Up @@ -1371,7 +1374,6 @@ void SliceViewer::updateDisplay(bool resetAxes)
m_dimY = 1;
std::vector<coord_t> slicePoint;

//DimensionSliceWidget * widget
for (size_t d=0; d<m_ws->getNumDims(); d++)
{
DimensionSliceWidget * widget = m_dimWidgets[d];
Expand Down Expand Up @@ -1399,6 +1401,12 @@ void SliceViewer::updateDisplay(bool resetAxes)
{
this->resetAxis(m_spect->xAxis(), m_X );
this->resetAxis(m_spect->yAxis(), m_Y );

// The dimensionality has changed. It might no longer be possible to plot peaks.
enablePeakOverlaysIfAppropriate();

// Transform the peak overlays according to the new plotting.
m_peaksPresenter->changeShownDim();
}

// Set the color range
Expand Down Expand Up @@ -1426,8 +1434,11 @@ void SliceViewer::updateDisplay(bool resetAxes)
m_spect->itemChanged();
m_plot->replot();

/// Update the peak positions.
this->updatePeaksWithSlicePoint();
/// Update the peak positions if peak relevant slider has changed.
if(m_peaksSliderWidget != NULL)
{
m_peaksPresenter->updateWithSlicePoint(m_peaksSliderWidget->getSlicePoint());
}

// Send out a signal
emit changedSlicePoint(m_slicePoint);
Expand Down Expand Up @@ -1471,14 +1482,8 @@ void SliceViewer::changedShownDim(int index, int dim, int oldDim)
}
}
}


// Show the new slice. This finds m_dimX and m_dimY
this->updateDisplay();
// The dimensionality has changed. It might no longer be possible to plot peaks. We need updateDisplay called first, because we read axis off the plot.
enablePeakOverlaysIfAppropriate();
// Transform the peak overlays according to the new plotting.
m_peaksPresenter->changeShownDim();
// Send out a signal
emit changedShownDim(m_dimX, m_dimY);
}
Expand Down Expand Up @@ -2098,7 +2103,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();
updatePeakOverlaySliderWidget();
}
}
}
Expand All @@ -2109,10 +2114,9 @@ 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.
Obtain the reference to a new PeakOverlay slider widget if necessary.
*/
void SliceViewer::updatePeaksWithSlicePoint()
void SliceViewer::updatePeakOverlaySliderWidget()
{
for (size_t d=0; d< m_ws->getNumDims(); d++)
{
Expand All @@ -2121,7 +2125,8 @@ void SliceViewer::updatePeaksWithSlicePoint()
{
if(m_peaksPresenter->isLabelOfFreeAxis(widget->getDimName()))
{
m_peaksPresenter->updateWithSlicePoint(widget->getSlicePoint());
m_peaksSliderWidget = widget; // Cache the widget being used for this.
m_peaksPresenter->updateWithSlicePoint(m_peaksSliderWidget->getSlicePoint()); // Ensure that the presenter is up-to-date with the change
}
}
}
Expand Down

0 comments on commit 453b6ed

Please sign in to comment.