Skip to content

Commit

Permalink
refs #6271. Zoom to Slice Point
Browse files Browse the repository at this point in the history
.The last set of changes allowed zooming, but now we should be able to land on the correct slice location too.
  • Loading branch information
OwenArnold committed Jan 11, 2013
1 parent 0e8454d commit c92bd85
Show file tree
Hide file tree
Showing 28 changed files with 367 additions and 236 deletions.
3 changes: 3 additions & 0 deletions Code/Mantid/MantidQt/SliceViewer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set ( SRC_FILES
src/DimensionSliceWidget.cpp
src/LineOverlay.cpp
src/LineViewer.cpp
src/PeakBoundingBox.cpp
src/PeakOverlaySphere.cpp
src/PeakOverlayCross.cpp
src/PeakOverlaySphereFactory.cpp
Expand Down Expand Up @@ -45,6 +46,7 @@ set ( INC_FILES
inc/MantidQtSliceViewer/LinePlotOptions.h
inc/MantidQtSliceViewer/LineViewer.h
inc/MantidQtSliceViewer/NullPeaksPresenter.h
inc/MantidQtSliceViewer/PeakBoundingBox.h
inc/MantidQtSliceViewer/PeakOverlaySphere.h
inc/MantidQtSliceViewer/PeakOverlayCross.h
inc/MantidQtSliceViewer/PeakOverlayView.h
Expand Down Expand Up @@ -107,6 +109,7 @@ set ( UI_FILES
set ( TEST_FILES
test/CompositePeaksPresenterTest.h
test/ConcretePeaksPresenterTest.h
test/PeakBoundingBoxTest.h
test/PeakPaletteTest.h
test/PeakTransformHKLTest.h
test/PeakTransformQSampleTest.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace MantidQt
void setBackgroundColour(const QColor){/*Do nothing*/}
void showBackgroundRadius(const bool show){/*Do nothing*/}
void setShown(const bool show){/*Do nothing*/}
virtual RectangleType getBoundingBox(const int peakIndex) const {return m_default->getBoundingBox(peakIndex);}
virtual PeakBoundingBox getBoundingBox(const int peakIndex) const {return m_default->getBoundingBox(peakIndex);}


virtual std::string getTransformName() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace MantidQt
void setBackgroundColour(const QColor);
std::string getTransformName() const;
void setShown(const bool shown);
virtual RectangleType getBoundingBox(const int) const;
virtual PeakBoundingBox getBoundingBox(const int) const;
private:
/// Peak overlay views.
VecPeakOverlayView m_viewPeaks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace MantidQt
std::string getTransformName() const {return "";}
void showBackgroundRadius(const bool){/*Do nothing*/}
void setShown(const bool){/*Do nothing*/}
virtual RectangleType getBoundingBox(const int) const{return boost::make_tuple(Mantid::Kernel::V2D(), Mantid::Kernel::V2D());}
virtual PeakBoundingBox getBoundingBox(const int) const{return PeakBoundingBox();}
};

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#ifndef MANTID_SLICEVIEWER_PEAK_BOUNDING_BOX_H_
#define MANTID_SLICEVIEWER_PEAK_BOUNDING_BOX_H_

#include "MantidKernel/System.h"

namespace MantidQt
{
namespace SliceViewer
{
/**
@class DoubleParam
IntToType Parameter Type. Simple mechanism for ensuring type
safety when working with so many arguments of the same core type in PeakBoundingBox.
*/
template<int I>
class DLLExport DoubleParam
{
public:
explicit DoubleParam(const double& val) : value(val){}
DoubleParam(const DoubleParam<I>& other) : value(other.value) {}
DoubleParam<I>& operator=(const DoubleParam<I>& other){value = other.value; return *this;}
double operator()() const {return value;}
private:
double value;
enum{typeValue = I};
};

typedef DoubleParam<0> Left;
typedef DoubleParam<1> Right;
typedef DoubleParam<2> Top;
typedef DoubleParam<3> Bottom;
typedef DoubleParam<4> SlicePoint;

/** A bounding box for a peak. Allows the SliceViewer to zoom to that region.
@date 2013-01-09
Copyright &copy; 2011 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport PeakBoundingBox
{
private:

Left m_left;
Right m_right;
Top m_top;
Bottom m_bottom;

/// Slice parellel to projection (z) position
SlicePoint m_slicePoint;

public:
/// Default constructor
PeakBoundingBox();
/// Constructor
PeakBoundingBox(const Left& left, const Right& right, const Top& top, const Bottom& bottom, const SlicePoint& slicePoint);
/// Destructor
~PeakBoundingBox();
/// Copy constructor
PeakBoundingBox(const PeakBoundingBox& other);
/// Assignment
PeakBoundingBox& operator=(const PeakBoundingBox& other);

/// Get the box left edge
double left() const;
/// Get the box right edge
double right() const;
/// Get the box top edge
double top() const;
/// Get the box bottom edge
double bottom() const;
/// Get the slice point
double slicePoint() const;

};
}
}

#endif /* MANTID_SLICEVIEWER_PEAK_BOUNDING_BOX_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace SliceViewer
/// Change background colour
virtual void changeBackgroundColour(const QColor);
/// Get a bounding box for this peak.
virtual RectangleType getBoundingBox() const;
virtual PeakBoundingBox getBoundingBox() const;

private:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace SliceViewer
/// Show the background radius
virtual void showBackgroundRadius(const bool show);
/// Get a bounding box for this peak.
virtual RectangleType getBoundingBox() const;
virtual PeakBoundingBox getBoundingBox() const;

private:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
#include "MantidKernel/V2D.h"
#include "MantidQtSliceViewer/PeakTransform.h"
#include "MantidQtSliceViewer/PeakPalette.h"
#include "MantidQtSliceViewer/PeakBoundingBox.h"
#include <QPointF>
#include <boost/shared_ptr.hpp>
#include <boost/tuple/tuple.hpp>

namespace MantidQt
{
namespace SliceViewer
{

typedef boost::tuple<Mantid::Kernel::V2D, Mantid::Kernel::V2D> RectangleType;

/** Abstract view in MVP model representing a PeakOverlay.
@date 2012-08-24
Expand Down Expand Up @@ -60,7 +57,7 @@ namespace MantidQt
/// Show the background radius
virtual void showBackgroundRadius(const bool){}
/// Get a bounding box around the peak in windows coordinates.
virtual RectangleType getBoundingBox() const = 0;
virtual PeakBoundingBox getBoundingBox() const = 0;
/// Destructor
virtual ~PeakOverlayView()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <boost/shared_ptr.hpp>
#include "MantidKernel/System.h"
#include "MantidQtSliceViewer/PeakPalette.h"
#include "MantidQtSliceViewer/PeakOverlayView.h"
#include "MantidQtSliceViewer/PeakBoundingBox.h"
#include <set>

namespace Mantid
Expand All @@ -24,6 +24,7 @@ namespace SliceViewer
// Forward dec.
class PeakOverlayViewFactory;
class PeakTransform;
class PeakOverlayView;

// Alias
typedef std::set<boost::shared_ptr<const Mantid::API::IPeaksWorkspace> > SetPeaksWorkspaces;
Expand All @@ -48,7 +49,7 @@ namespace SliceViewer
virtual std::string getTransformName() const = 0;
virtual void showBackgroundRadius(const bool shown) = 0;
virtual void setShown(const bool shown) = 0;
virtual RectangleType getBoundingBox(const int peakIndex) const = 0;
virtual PeakBoundingBox getBoundingBox(const int peakIndex) const = 0;
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ namespace MantidQt
return (m_opacityAtDistance != m_opacityMin);
}
/// Get the bounding box.
RectangleType getBoundingBox() const;
/// Get the bounding box in windows coordinates.
RectangleType getBoundingBox(const double& windowHeight, const double& windowWidth, const double& viewWidth, const double& viewHeight) const;
PeakBoundingBox getBoundingBox() const;

private:
/// Original origin x=h, y=k, z=l
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ namespace MantidQt
void showBackgroundRadius(const bool show);

/// Get the bounding box in natural coordinates.
RectangleType getBoundingBox() const;

/// Get the bounding box in windows coordinates.
RectangleType getBoundingBox(const double& windowHeight, const double& windowWidth, const double& viewWidth, const double& viewHeight) const;
PeakBoundingBox getBoundingBox() const;

private:
/// Original origin x=h, y=k, z=l
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class EXPORT_OPT_MANTIDQT_SLICEVIEWER SliceViewer : public QWidget, public Zooma
boost::shared_ptr<ProxyCompositePeaksPresenter> getPeaksPresenter() const;

/// Methods from implementation of ZoomablePeaksView.
virtual void zoomToRectangle(Mantid::Kernel::V2D& lowerLeft, Mantid::Kernel::V2D& upperRight);
virtual void zoomToRectangle(const PeakBoundingBox& box);

signals:
/// Signal emitted when the X/Y index of the shown dimensions is changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace MantidQt
{
namespace SliceViewer
{
/// Forward dec
class PeakBoundingBox;

/** Abstract view in Representing a view that can be zoomed in upon.
Expand Down Expand Up @@ -37,34 +39,11 @@ namespace MantidQt
{
public:
/// Zoom to a peak position provided by a boundary rectangle in the windows coordinate system.
virtual void zoomToRectangle(Mantid::Kernel::V2D& lowerLeft, Mantid::Kernel::V2D& upperRight) = 0;
virtual void zoomToRectangle(const PeakBoundingBox&) = 0;
/// Destructor
virtual ~ZoomablePeaksView(){ }
};

/**
@class ZoomableAdapter
Templated adapter to zoom to peak. Alows objects from outside this type hierachy to be made to work seamlessly with it.
*/
template <class Adaptee>
class DLLExport ZoomableAdapter : public ZoomablePeaksView
{
private:
Adaptee * const _adaptee;
ZoomableAdapter& operator=(const ZoomableAdapter& other);
ZoomableAdapter(const ZoomableAdapter& other);
public:
ZoomableAdapter(Adaptee* const adaptee) : _adaptee(adaptee)
{
}

void zoomToRectangle(Mantid::Kernel::V2D& lowerLeft, Mantid::Kernel::V2D& upperRight)
{
_adaptee.zoomToRectange(lowerLeft, upperRight);
}
virtual ~ZoomableAdapter(){ }
};
}
}

#endif /* MANTID_SLICEVIEWER_PEAKOVERLAY_VIEW_H_ */
#endif /* MANTID_SLICEVIEWER_ZOOMABLE_PEAKS_VIEW_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ namespace MantidQt
auto iterator = getPresenterIteratorFromWorkspace(peaksWS);
auto subjectPresenter = *iterator;
auto boundingBox = subjectPresenter->getBoundingBox(peakIndex);
m_zoomablePlottingWidget->zoomToRectangle(boundingBox.get<0>(), boundingBox.get<1>());
m_zoomablePlottingWidget->zoomToRectangle(boundingBox);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ namespace SliceViewer
@param peakIndex: index into contained peaks workspace.
@return the bounding box corresponding to the peakIndex.
*/
RectangleType ConcretePeaksPresenter::getBoundingBox(const int peakIndex) const
PeakBoundingBox ConcretePeaksPresenter::getBoundingBox(const int peakIndex) const
{
if(peakIndex < 0 || peakIndex > m_viewPeaks.size())
{
Expand Down
70 changes: 70 additions & 0 deletions Code/Mantid/MantidQt/SliceViewer/src/PeakBoundingBox.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include "MantidQtSliceViewer/PeakBoundingBox.h"
#include <stdexcept>

namespace MantidQt
{
namespace SliceViewer
{
PeakBoundingBox::PeakBoundingBox() : m_left(0), m_right(0), m_top(0), m_bottom(0), m_slicePoint(0)
{
}

PeakBoundingBox::PeakBoundingBox(const Left& left, const Right& right, const Top& top, const Bottom& bottom, const SlicePoint& slicePoint) : m_left(left), m_right(right), m_top(top), m_bottom(bottom), m_slicePoint(slicePoint)
{
if(right() < left())
{
throw std::invalid_argument("Right < Left");
}
if(top() < bottom())
{
throw std::invalid_argument("Top < Bottom");
}
}

PeakBoundingBox::~PeakBoundingBox()
{
}

PeakBoundingBox::PeakBoundingBox(const PeakBoundingBox& other) : m_left(other.m_left), m_right(other.m_right), m_top(other.m_top), m_bottom(other.m_bottom), m_slicePoint(other.m_slicePoint)
{
}

PeakBoundingBox& PeakBoundingBox::operator=(const PeakBoundingBox& other)
{
if(&other != this)
{
m_top = other.m_top;
m_bottom = other.m_bottom;
m_left = other.m_left;
m_right = other.m_right;
m_slicePoint = other.m_slicePoint;
}
return *this;
}

double PeakBoundingBox::left() const
{
return m_left();
}

double PeakBoundingBox::right() const
{
return m_right();
}

double PeakBoundingBox::top() const
{
return m_top();
}

double PeakBoundingBox::bottom() const
{
return m_bottom();
}

double PeakBoundingBox::slicePoint() const
{
return m_slicePoint();
}
}
}

0 comments on commit c92bd85

Please sign in to comment.