MorphoGraphX
QTransferFunctionViewer.hpp
1 //
2 // This file is part of MorphoGraphX - http://www.MorphoGraphX.org
3 // Copyright (C) 2012-2015 Richard S. Smith and collaborators.
4 //
5 // If you use MorphoGraphX in your work, please cite:
6 // http://dx.doi.org/10.7554/eLife.05864
7 //
8 // MorphoGraphX is free software, and is licensed under under the terms of the
9 // GNU General (GPL) Public License version 2.0, http://www.gnu.org/licenses.
10 //
11 #ifndef QTRANSFERFUNCTIONVIEWER_HPP
12 #define QTRANSFERFUNCTIONVIEWER_HPP
13 
14 #include <Config.hpp>
15 
16 #include <TransferFunction.hpp>
17 
18 #include <QColor>
19 #include <QLinearGradient>
20 #include <QPainterPath>
21 #include <QWidget>
22 #include <vector>
23 
24 class QMouseEvent;
25 class QPixmap;
26 class QAction;
27 class QPaintEvent;
28 
29 namespace mgx {
30 namespace gui {
31 
32 class mgx_EXPORT QTransferFunctionViewer : public QWidget {
33  Q_OBJECT
34 public:
36  enum BackgroundType { BG_CHECKS, BG_WHITE, BG_BLACK };
37 
38  QTransferFunctionViewer(QWidget* parent = 0, Qt::WindowFlags f = 0);
39  virtual ~QTransferFunctionViewer() {
40  }
41 
42  size_t nbValues() const;
43 
44  const TransferFunction& transferFunction() const {
45  return transfer_fct;
46  }
47 
48 public slots:
49  void changeNbValues(int n);
50  void reverseFunction();
51  void changeTransferFunction(const TransferFunction& fct);
52  void setupGradient();
53  void setHistogram(const std::vector<double>& h);
54  void setBounds(double min, double max);
55  void setStickers(const std::vector<double>& s);
56  void setMarkerSize(int s);
57  void setCheckSize(int s);
58  void setBackgroundType(BackgroundType type);
59  void setInterpolation(TransferFunction::Interpolation i);
60  void setSelectionColor(QColor col);
61  void editMarkers();
62  void autoAdjust();
63 
64 signals:
65  void changedTransferFunction(const TransferFunction& fct);
66 
67 protected:
68  void paintEvent(QPaintEvent* event);
69  void mouseDoubleClickEvent(QMouseEvent* e);
70  void mousePressEvent(QMouseEvent* e);
71  void mouseReleaseEvent(QMouseEvent* e);
72  void mouseMoveEvent(QMouseEvent* e);
73  void resetMouseInteraction();
74 
75  void prepareHistogram();
76 
77  void createBackground();
78  QPixmap createChecks();
79 
80  TransferFunction transfer_fct;
81  std::vector<double> histogram, hist_values;
82  double minValue, maxValue;
83  QPainterPath hist_shape;
84  bool use_histogram;
85  std::vector<double> stickers;
86  bool sticking;
87  int marker_size;
88  bool select_pos;
89  double current_pos;
90  int bg_size;
91  double bg_bright;
92  double bg_dark;
93  QColor activ_pos_color;
94  Colorf saved_color;
95  double saved_pos;
96  QAction* reverse_act, *edit_markers;
97  QLinearGradient gradient;
98  BackgroundType bg_type;
99  size_t _nb_values;
100 };
101 } // namespace gui
102 } // namespace mgx
103 #endif // QTRANSFERFUNCTIONVIEWER_HPP
Definition: QTransferFunctionViewer.hpp:32
This namespace contains all the API of MorphoGraphX.
Definition: Assert.hpp:26
Interpolation
Type of interpolation.
Definition: TransferFunction.hpp:38
Class defining a transfer function as linear interpolation between set values.
Definition: TransferFunction.hpp:33