Skip to content
Snippets Groups Projects
SliceViewer.h 5.49 KiB
Newer Older
#ifndef SLICEVIEWER_H
#define SLICEVIEWER_H

#include "ColorBarWidget.h"
#include "MantidAPI/IMDIterator.h"
#include "MantidAPI/IMDWorkspace.h"
#include "MantidGeometry/MDGeometry/MDHistoDimension.h"
#include "MantidKernel/VMD.h"
#include "MantidQtAPI/MantidColorMap.h"
#include "MantidQtAPI/SyncedCheckboxes.h"
#include "MantidQtSliceViewer/LineOverlay.h"
#include <QtGui/qdialog.h>
#include <qwt_plot_spectrogram.h>
#include <qwt_plot.h>
Janik Zikovsky's avatar
Janik Zikovsky committed
#include <qwt_raster_data.h>
namespace MantidQt
{
namespace SliceViewer
{

/** GUI for viewing a 2D slice out of a multi-dimensional workspace.
 * You can select which dimension to plot as X,Y, and the cut point
 * along the other dimension(s).
 *
 */
class EXPORT_OPT_MANTIDQT_SLICEVIEWER SliceViewer : public QWidget
  SliceViewer(QWidget *parent = 0);
  ~SliceViewer();
  void setWorkspace(const QString & wsName);
  void setWorkspace(Mantid::API::IMDWorkspace_sptr ws);
  void zoomBy(double factor);
  void loadColorMap(QString filename = QString() );
  LineOverlay * getLineOverlay() { return m_lineOverlay; }
  Mantid::Kernel::VMD getSlicePoint() const { return m_slicePoint; }
  int getDimX() const;
  int getDimY() const;
  /// Methods for Python bindings
  void setXYDim(int indexX, int indexY);
  void setXYDim(const QString & dimX, const QString & dimY);
  void setSlicePoint(int dim, double value);
  void setSlicePoint(const QString & dim, double value);
  double getSlicePoint(int dim) const;
  double getSlicePoint(const QString & dim) const;
  void setColorScaleMin(double min);
  void setColorScaleMax(double max);
  void setColorScaleLog(bool log);
  void setColorScale(double min, double max, bool log);
  double getColorScaleMin() const;
  double getColorScaleMax() const;
  bool getColorScaleLog() const;
  void setXYLimits(double xleft, double xright, double ybottom, double ytop);
  QwtDoubleInterval getXLimits() const;
  QwtDoubleInterval getYLimits() const;
  void setXYCenter(double x, double y);
signals:
  /// Signal emitted when the X/Y index of the shown dimensions is changed
  void changedShownDim(size_t dimX, size_t dimY);
  /// Signal emitted when the slice point moves
  void changedSlicePoint(Mantid::Kernel::VMD slicePoint);
  /// Signal emitted when the LineViewer should be shown/hidden.
  void showLineViewer(bool);
  void changedShownDim(int index, int dim, int oldDim);
  void setXYLimitsDialog();
  void zoomInSlot();
  void zoomOutSlot();
  void loadColorMapSlot();
  void helpSliceViewer();
  void helpLineViewer();
  void setColorScaleAutoFull();
  void setColorScaleAutoSlice();
  // Slots that will be automatically connected via QMetaObject.connectSlotsByName
  void on_btnClearLine_clicked();

  // Synced checkboxes
  void LineMode_toggled(bool);
  void SnapToGrid_toggled(bool);
  void loadSettings();
  void saveSettings();

  void updateDisplay(bool resetAxes = false);
  void resetAxis(int axis, Mantid::Geometry::IMDDimension_const_sptr dim);
  QwtDoubleInterval getRange(Mantid::API::IMDIterator * it);
  void findRangeFull();
  void findRangeSlice();


  // -------------------------- Widgets ----------------------------

  /// Auto-generated UI controls.
  Ui::SliceViewerClass ui;

  /// Main plot object
  QwtPlot * m_plot;

  /// Spectrogram plot
  QwtPlotSpectrogram * m_spect;

  /// Layout containing the spectrogram
  QHBoxLayout * m_spectLayout;

  /// Color bar indicating the color scale
  /// Vector of the widgets for slicing dimensions
  std::vector<DimensionSliceWidget *> m_dimWidgets;

  /// The LineOverlay widget for drawing line cross-sections (hidden at startup)
  LineOverlay * m_lineOverlay;



  // -------------------------- Data Members ----------------------------

  /// Workspace being shown
  Mantid::API::IMDWorkspace_sptr m_ws;

  /// Set to true once the first workspace has been loaded in it
  bool m_firstWorkspaceOpen;

  /// File of the last loaded color map.
  QString m_currentColorMapFile;

  /// Vector of the dimensions to show.
  std::vector<Mantid::Geometry::MDHistoDimension_sptr> m_dimensions;

  /// Data presenter
  QwtRasterDataMD * m_data;

  /// The X and Y dimensions being plotted
  Mantid::Geometry::IMDDimension_const_sptr m_X;
  Mantid::Geometry::IMDDimension_const_sptr m_Y;
  /// The point of slicing in the other dimensions
  Mantid::Kernel::VMD m_slicePoint;

  /// The range of values to fit in the color map.
  QwtDoubleInterval m_colorRange;

  /// The calculated range of values in the FULL data set
  QwtDoubleInterval m_colorRangeFull;

  /// The calculated range of values ONLY in the currently viewed part of the slice
  QwtDoubleInterval m_colorRangeSlice;

  /// Use the log of the value for the color scale
  QMenu *m_menuColorOptions, *m_menuView, *m_menuHelp, *m_menuLine;
  /// Synced menu/buttons
  MantidQt::API::SyncedCheckboxes *m_syncLineMode, *m_syncSnapToGrid;

  /// Cached double for infinity
  double m_inf;
} // namespace SliceViewer
} // namespace Mantid

#endif // SLICEVIEWER_H