CustusX  15.3.4-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #ifndef CXTRANSFERFUNCTIONALPHAWIDGET_H_
34 #define CXTRANSFERFUNCTIONALPHAWIDGET_H_
35 
36 #include "cxGuiExport.h"
37 
38 #include "cxBaseWidget.h"
39 
40 #include <limits.h>
41 #include "cxImage.h"
42 #include "cxForwardDeclarations.h"
43 #include "cxActiveImageProxy.h"
44 #include "cxLegacySingletons.h"
45 class QRect;
46 
47 namespace cx
48 {
59 class cxGui_EXPORT TransferFunctionAlphaWidget : public BaseWidget
60 {
61  Q_OBJECT
62 
63  void clearBackground(QPainter &painter);
64 public:
65  TransferFunctionAlphaWidget(PatientModelServicePtr patientModelService, QWidget* parent);
66  virtual ~TransferFunctionAlphaWidget();
67  virtual QString defaultWhatsThis() const;
68 
69  void setData(ImagePtr image, ImageTFDataPtr tfData);
70  void setReadOnly(bool readOnly);
71 
72 public slots:
73  void activeImageTransferFunctionsChangedSlot();
74 
75 protected:
76  struct AlphaPoint
77  {
78  int position;
79  int value;
81  position(INT_MIN),
82  value(INT_MIN)
83  {}
84  AlphaPoint(int pos, int val) :
85  position(pos),
86  value(val)
87  {}
88  void reset()
89  {
90  position = INT_MIN;
91  value = INT_MIN;
92  }
93  bool isValid()
94  {
95  if(position != INT_MIN)
96  return true;
97  return false;
98  }
99  };
100 
101  virtual void enterEvent(QEvent* event);
102  virtual void leaveEvent(QEvent* event);
103  virtual void mousePressEvent(QMouseEvent* event);
104  virtual void mouseReleaseEvent(QMouseEvent* event);
105  virtual void mouseMoveEvent(QMouseEvent* event);
106  virtual void keyPressEvent(QKeyEvent* event);
107 
108  virtual void paintEvent(QPaintEvent* event);
109  virtual void resizeEvent(QResizeEvent* evt);
110 
111  AlphaPoint selectPoint(QPoint pos);
112  AlphaPoint getCurrentAlphaPoint(QPoint pos);
113  void toggleSelectedPoint(QPoint pos);
114  void moveCurrentAlphaPoint(AlphaPoint newAlphaPoint);
115  QPoint alpha2screen(AlphaPoint pt) const;
116  void updateTooltip(QPoint pos);
117  void updateTooltip(AlphaPoint point);
118 
119  bool isEndpoint(int intensity) const;
120  void paintHistogram(QPainter& painter);
121  void paintOpacityGraph(QPainter& painter);
122  std::pair<int,int> findAllowedMoveRangeAroundAlphaPoint(int selectedPointIntensity);
123 
124  QRect mFullArea;
125  QRect mPlotArea;
126  int mBorder;
127  bool mReadOnly;
128 
129  std::map<int, QRect> mPointRects;
131 // bool mEndPoint;///< Current alpha point is an endpoint
132 
136 
137  virtual QSize sizeHint () const { return QSize(200, 100);};
138 };
139 }
140 #endif /* CXTRANSFERFUNCTIONALPHAWIDGET_H_ */
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:48
boost::shared_ptr< class ActiveImageProxy > ActiveImageProxyPtr
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
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:108
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.