Fraxinus  22.04-rc3
An IGT application
cxTransferFunctionAlphaWidget.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #ifndef CXTRANSFERFUNCTIONALPHAWIDGET_H_
13 #define CXTRANSFERFUNCTIONALPHAWIDGET_H_
14 
15 #include "cxGuiExport.h"
16 
17 #include "cxBaseWidget.h"
18 
19 #include <limits.h>
20 #include "cxImage.h"
21 #include "cxForwardDeclarations.h"
22 #include "cxActiveImageProxy.h"
23 class QRect;
24 
25 namespace cx
26 {
37 class cxGui_EXPORT TransferFunctionAlphaWidget : public BaseWidget
38 {
39  Q_OBJECT
40 
41  void clearBackground(QPainter &painter);
42 public:
43  TransferFunctionAlphaWidget(ActiveDataPtr activeData, QWidget* parent);
44  virtual ~TransferFunctionAlphaWidget();
45 
46  void setData(ImagePtr image, ImageTFDataPtr tfData);
47  void setReadOnly(bool readOnly);
48 
49 public slots:
50  void activeImageTransferFunctionsChangedSlot();
51 
52 protected:
53  struct AlphaPoint
54  {
55  int position;
56  int value;
58  position(INT_MIN),
59  value(INT_MIN)
60  {}
61  AlphaPoint(int pos, int val) :
62  position(pos),
63  value(val)
64  {}
65  void reset()
66  {
67  position = INT_MIN;
68  value = INT_MIN;
69  }
70  bool isValid()
71  {
72  if(position != INT_MIN)
73  return true;
74  return false;
75  }
76  };
77 
78  virtual void enterEvent(QEvent* event);
79  virtual void leaveEvent(QEvent* event);
80  virtual void mousePressEvent(QMouseEvent* event);
81  virtual void mouseReleaseEvent(QMouseEvent* event);
82  virtual void mouseMoveEvent(QMouseEvent* event);
83  virtual void keyPressEvent(QKeyEvent* event);
84 
85  virtual void paintEvent(QPaintEvent* event);
86  virtual void resizeEvent(QResizeEvent* evt);
87 
88  AlphaPoint selectPoint(QPoint pos);
89  AlphaPoint getCurrentAlphaPoint(QPoint pos);
90  void toggleSelectedPoint(QPoint pos);
91  void moveCurrentAlphaPoint(AlphaPoint newAlphaPoint);
92  QPoint alpha2screen(AlphaPoint pt) const;
93  void updateTooltip(QPoint pos);
94  void updateTooltip(AlphaPoint point);
95 
96  bool isEndpoint(int intensity) const;
97  void paintHistogram(QPainter& painter);
98  void paintOpacityGraph(QPainter& painter);
99  std::pair<int,int> findAllowedMoveRangeAroundAlphaPoint(int selectedPointIntensity);
100 
101  QRect mFullArea;
102  QRect mPlotArea;
103  int mBorder;
104  bool mReadOnly;
105 
106  std::map<int, QRect> mPointRects;
108 // bool mEndPoint;///< Current alpha point is an endpoint
109 
113 
114  virtual QSize sizeHint () const { return QSize(200, 100);};
115 };
116 }
117 #endif /* CXTRANSFERFUNCTIONALPHAWIDGET_H_ */
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
boost::shared_ptr< class ActiveImageProxy > ActiveImageProxyPtr
boost::shared_ptr< class ActiveData > ActiveDataPtr
Definition: cxColorWidget.h:21
bool mReadOnly
Is class readOnly? Eg no mouse interaction possible.
AlphaPoint mSelectedAlphaPoint
The current alpha point.
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:88
int mBorder
The size of the border around the transferfunction. The size of the rectangles are mBorder * 2...
std::map< int, QRect > mPointRects
Cache with all point rectangles.
boost::shared_ptr< class ImageTFData > ImageTFDataPtr
Internal placeholder for a function point.
Namespace for all CustusX production code.