NorMIT-nav  16.5
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(ActiveDataPtr activeData, QWidget* parent);
66  virtual ~TransferFunctionAlphaWidget();
67 
68  void setData(ImagePtr image, ImageTFDataPtr tfData);
69  void setReadOnly(bool readOnly);
70 
71 public slots:
72  void activeImageTransferFunctionsChangedSlot();
73 
74 protected:
75  struct AlphaPoint
76  {
77  int position;
78  int value;
80  position(INT_MIN),
81  value(INT_MIN)
82  {}
83  AlphaPoint(int pos, int val) :
84  position(pos),
85  value(val)
86  {}
87  void reset()
88  {
89  position = INT_MIN;
90  value = INT_MIN;
91  }
92  bool isValid()
93  {
94  if(position != INT_MIN)
95  return true;
96  return false;
97  }
98  };
99 
100  virtual void enterEvent(QEvent* event);
101  virtual void leaveEvent(QEvent* event);
102  virtual void mousePressEvent(QMouseEvent* event);
103  virtual void mouseReleaseEvent(QMouseEvent* event);
104  virtual void mouseMoveEvent(QMouseEvent* event);
105  virtual void keyPressEvent(QKeyEvent* event);
106 
107  virtual void paintEvent(QPaintEvent* event);
108  virtual void resizeEvent(QResizeEvent* evt);
109 
110  AlphaPoint selectPoint(QPoint pos);
111  AlphaPoint getCurrentAlphaPoint(QPoint pos);
112  void toggleSelectedPoint(QPoint pos);
113  void moveCurrentAlphaPoint(AlphaPoint newAlphaPoint);
114  QPoint alpha2screen(AlphaPoint pt) const;
115  void updateTooltip(QPoint pos);
116  void updateTooltip(AlphaPoint point);
117 
118  bool isEndpoint(int intensity) const;
119  void paintHistogram(QPainter& painter);
120  void paintOpacityGraph(QPainter& painter);
121  std::pair<int,int> findAllowedMoveRangeAroundAlphaPoint(int selectedPointIntensity);
122 
123  QRect mFullArea;
124  QRect mPlotArea;
125  int mBorder;
126  bool mReadOnly;
127 
128  std::map<int, QRect> mPointRects;
130 // bool mEndPoint;///< Current alpha point is an endpoint
131 
135 
136  virtual QSize sizeHint () const { return QSize(200, 100);};
137 };
138 }
139 #endif /* CXTRANSFERFUNCTIONALPHAWIDGET_H_ */
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:48
boost::shared_ptr< class ActiveImageProxy > ActiveImageProxyPtr
boost::shared_ptr< class ActiveData > ActiveDataPtr
Definition: cxColorWidget.h:42
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.