NorMIT-nav  2023.01.05-dev+develop.0da12
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_ */
cx::TransferFunctionAlphaWidget::mReadOnly
bool mReadOnly
Is class readOnly? Eg no mouse interaction possible.
Definition: cxTransferFunctionAlphaWidget.h:104
cx::TransferFunctionAlphaWidget::AlphaPoint::isValid
bool isValid()
Definition: cxTransferFunctionAlphaWidget.h:70
cxBaseWidget.h
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::BaseWidget
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:88
cxImage.h
cxForwardDeclarations.h
cx::TransferFunctionAlphaWidget::mImage
ImagePtr mImage
Definition: cxTransferFunctionAlphaWidget.h:110
cx::ImageTFDataPtr
boost::shared_ptr< class ImageTFData > ImageTFDataPtr
Definition: cxForwardDeclarations.h:52
cxActiveImageProxy.h
cx::TransferFunctionAlphaWidget::AlphaPoint::position
int position
Definition: cxTransferFunctionAlphaWidget.h:55
cx::TransferFunctionAlphaWidget::mActiveImageProxy
ActiveImageProxyPtr mActiveImageProxy
Definition: cxTransferFunctionAlphaWidget.h:112
cx::TransferFunctionAlphaWidget::AlphaPoint::value
int value
Definition: cxTransferFunctionAlphaWidget.h:56
cx::TransferFunctionAlphaWidget::mBorder
int mBorder
The size of the border around the transferfunction. The size of the rectangles are mBorder * 2.
Definition: cxTransferFunctionAlphaWidget.h:103
cx::ActiveImageProxyPtr
boost::shared_ptr< class ActiveImageProxy > ActiveImageProxyPtr
Definition: cxDataInterface.h:29
cx::TransferFunctionAlphaWidget::sizeHint
virtual QSize sizeHint() const
Definition: cxTransferFunctionAlphaWidget.h:114
cx::TransferFunctionAlphaWidget::mSelectedAlphaPoint
AlphaPoint mSelectedAlphaPoint
The current alpha point.
Definition: cxTransferFunctionAlphaWidget.h:107
cx::TransferFunctionAlphaWidget::AlphaPoint::AlphaPoint
AlphaPoint(int pos, int val)
Definition: cxTransferFunctionAlphaWidget.h:61
cx::TransferFunctionAlphaWidget::mPlotArea
QRect mPlotArea
The plot area.
Definition: cxTransferFunctionAlphaWidget.h:102
cx::ImagePtr
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
cx::TransferFunctionAlphaWidget
Definition: cxTransferFunctionAlphaWidget.h:37
cx::TransferFunctionAlphaWidget::AlphaPoint
Definition: cxTransferFunctionAlphaWidget.h:53
cx::TransferFunctionAlphaWidget::AlphaPoint::reset
void reset()
Definition: cxTransferFunctionAlphaWidget.h:65
cx::TransferFunctionAlphaWidget::AlphaPoint::AlphaPoint
AlphaPoint()
Definition: cxTransferFunctionAlphaWidget.h:57
cx::ActiveDataPtr
boost::shared_ptr< class ActiveData > ActiveDataPtr
Definition: cxColorWidget.h:21
cx::TransferFunctionAlphaWidget::mImageTF
ImageTFDataPtr mImageTF
Definition: cxTransferFunctionAlphaWidget.h:111
cx::TransferFunctionAlphaWidget::mPointRects
std::map< int, QRect > mPointRects
Cache with all point rectangles.
Definition: cxTransferFunctionAlphaWidget.h:106
cx::TransferFunctionAlphaWidget::mFullArea
QRect mFullArea
The full widget area.
Definition: cxTransferFunctionAlphaWidget.h:101