Fraxinus  17.12-rc1
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) 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 class QRect;
45 
46 namespace cx
47 {
58 class cxGui_EXPORT TransferFunctionAlphaWidget : public BaseWidget
59 {
60  Q_OBJECT
61 
62  void clearBackground(QPainter &painter);
63 public:
64  TransferFunctionAlphaWidget(ActiveDataPtr activeData, QWidget* parent);
65  virtual ~TransferFunctionAlphaWidget();
66 
67  void setData(ImagePtr image, ImageTFDataPtr tfData);
68  void setReadOnly(bool readOnly);
69 
70 public slots:
71  void activeImageTransferFunctionsChangedSlot();
72 
73 protected:
74  struct AlphaPoint
75  {
76  int position;
77  int value;
79  position(INT_MIN),
80  value(INT_MIN)
81  {}
82  AlphaPoint(int pos, int val) :
83  position(pos),
84  value(val)
85  {}
86  void reset()
87  {
88  position = INT_MIN;
89  value = INT_MIN;
90  }
91  bool isValid()
92  {
93  if(position != INT_MIN)
94  return true;
95  return false;
96  }
97  };
98 
99  virtual void enterEvent(QEvent* event);
100  virtual void leaveEvent(QEvent* event);
101  virtual void mousePressEvent(QMouseEvent* event);
102  virtual void mouseReleaseEvent(QMouseEvent* event);
103  virtual void mouseMoveEvent(QMouseEvent* event);
104  virtual void keyPressEvent(QKeyEvent* event);
105 
106  virtual void paintEvent(QPaintEvent* event);
107  virtual void resizeEvent(QResizeEvent* evt);
108 
109  AlphaPoint selectPoint(QPoint pos);
110  AlphaPoint getCurrentAlphaPoint(QPoint pos);
111  void toggleSelectedPoint(QPoint pos);
112  void moveCurrentAlphaPoint(AlphaPoint newAlphaPoint);
113  QPoint alpha2screen(AlphaPoint pt) const;
114  void updateTooltip(QPoint pos);
115  void updateTooltip(AlphaPoint point);
116 
117  bool isEndpoint(int intensity) const;
118  void paintHistogram(QPainter& painter);
119  void paintOpacityGraph(QPainter& painter);
120  std::pair<int,int> findAllowedMoveRangeAroundAlphaPoint(int selectedPointIntensity);
121 
122  QRect mFullArea;
123  QRect mPlotArea;
124  int mBorder;
125  bool mReadOnly;
126 
127  std::map<int, QRect> mPointRects;
129 // bool mEndPoint;///< Current alpha point is an endpoint
130 
134 
135  virtual QSize sizeHint () const { return QSize(200, 100);};
136 };
137 }
138 #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:109
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.