MorphoGraphX
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QTransferFunctionViewer.hpp
1 #ifndef QTRANSFERFUNCTIONVIEWER_HPP
2 #define QTRANSFERFUNCTIONVIEWER_HPP
3 
4 #include <Config.hpp>
5 
6 #include <TransferFunction.hpp>
7 
8 #include <QColor>
9 #include <QLinearGradient>
10 #include <QPainterPath>
11 #include <QWidget>
12 #include <vector>
13 
14 class QMouseEvent;
15 class QPixmap;
16 class QAction;
17 class QPaintEvent;
18 
19 namespace mgx {
20 namespace gui {
21 
22 class mgx_EXPORT QTransferFunctionViewer : public QWidget {
23  Q_OBJECT
24 public:
26  enum BackgroundType { BG_CHECKS, BG_WHITE, BG_BLACK };
27 
28  QTransferFunctionViewer(QWidget* parent = 0, Qt::WindowFlags f = 0);
29  virtual ~QTransferFunctionViewer() {
30  }
31 
32  size_t nbValues() const;
33 
34  const TransferFunction& transferFunction() const {
35  return transfer_fct;
36  }
37 
38 public slots:
39  void changeNbValues(int n);
40  void reverseFunction();
41  void changeTransferFunction(const TransferFunction& fct);
42  void setupGradient();
43  void setHistogram(const std::vector<double>& h);
44  void setBounds(double min, double max);
45  void setStickers(const std::vector<double>& s);
46  void setMarkerSize(int s);
47  void setCheckSize(int s);
48  void setBackgroundType(BackgroundType type);
49  void setInterpolation(TransferFunction::Interpolation i);
50  void setSelectionColor(QColor col);
51  void editMarkers();
52  void autoAdjust();
53 
54 signals:
55  void changedTransferFunction(const TransferFunction& fct);
56 
57 protected:
58  void paintEvent(QPaintEvent* event);
59  void mouseDoubleClickEvent(QMouseEvent* e);
60  void mousePressEvent(QMouseEvent* e);
61  void mouseReleaseEvent(QMouseEvent* e);
62  void mouseMoveEvent(QMouseEvent* e);
63  void resetMouseInteraction();
64 
65  void prepareHistogram();
66 
67  void createBackground();
68  QPixmap createChecks();
69 
70  TransferFunction transfer_fct;
71  std::vector<double> histogram, hist_values;
72  double minValue, maxValue;
73  QPainterPath hist_shape;
74  bool use_histogram;
75  std::vector<double> stickers;
76  bool sticking;
77  int marker_size;
78  bool select_pos;
79  double current_pos;
80  int bg_size;
81  double bg_bright;
82  double bg_dark;
83  QColor activ_pos_color;
84  Colorf saved_color;
85  double saved_pos;
86  QAction* reverse_act, *edit_markers;
87  QLinearGradient gradient;
88  BackgroundType bg_type;
89  size_t _nb_values;
90 };
91 } // namespace gui
92 } // namespace mgx
93 #endif // QTRANSFERFUNCTIONVIEWER_HPP
Definition: QTransferFunctionViewer.hpp:22
Interpolation
Type of interpolation.
Definition: TransferFunction.hpp:28
Class defining a transfer function as linear interpolation between set values.
Definition: TransferFunction.hpp:23