Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmlMitkTransferFunctionItem.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3  The Medical Imaging Interaction Toolkit (MITK)
4 
5  Copyright (c) German Cancer Research Center,
6  Division of Medical and Biological Informatics.
7  All rights reserved.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without
10  even the implied warranty of MERCHANTABILITY or FITNESS FOR
11  A PARTICULAR PURPOSE.
12 
13  See LICENSE.txt or http://www.mitk.org for details.
14 
15  ===================================================================*/
16 
18 
19 #include <QQuickWindow>
20 
22 
24 QQuickItem(parent)
25 {
26  instance = this;
27 
28  this->m_Max = 0;
29  this->m_Min = 0;
30 
31  this->m_CurrentMin = 0;
32  this->m_CurrentMax = 0;
33 
34  this->setEnabled(false);
35 
36  setAcceptHoverEvents(true);
37  setAcceptedMouseButtons(Qt::AllButtons);
38 }
39 
41 {
42 }
43 
45 {
46  int fact = -event->delta() * 0.15;
47 
48  if(event->orientation() == Qt::Horizontal)
49  {
50  int lower = this->m_CurrentMin + fact;
51  int upper = this->m_CurrentMax + fact;
52 
53  if(lower < this->m_Min )
54  {
55  this->m_CurrentMin = this->m_Min;
56  }
57  else if (upper > this->m_Max)
58  {
59  this->m_CurrentMax = this->m_Max;
60  }
61  else
62  {
63  this->m_CurrentMin = lower;
64  this->m_CurrentMax = upper;
65  }
66  emit this->sync();
67 
68  UpdateRanges();
69  }
70 }
71 
73 {
74  if (node)
75  {
76  tfpToChange = dynamic_cast<mitk::TransferFunctionProperty*>(node->GetProperty("TransferFunction", renderer));
77 
78  if(!tfpToChange)
79  {
80  if (! dynamic_cast<mitk::Image*>(node->GetData()))
81  {
82  MITK_WARN << "QmlMitkTransferFunctionItem::SetDataNode called with non-image node";
83  // goto turnOff;
84  }
85 
86  node->SetProperty("TransferFunction", tfpToChange = mitk::TransferFunctionProperty::New() );
87  }
88 
90 
91  if( mitk::BaseData* data = node->GetData() )
92  {
94 
95  this->setMin(h->GetMin());
96  this->setMax(h->GetMax());
97 
98  this->m_CurrentMin = h->GetMin();
99  this->m_CurrentMax = h->GetMax();
100 
101  this->m_ColorItem->SetHistogram( h );
102  this->m_OpacityItem->SetHistogram( h );
103  // m_ColorTransferFunctionCanvas->SetHistogram( h );
104 
105  emit this->sync();
106  }
107 
108  OnUpdateCanvas();
109 
110  return;
111  }
112 }
113 
115 {
116 
117  if(tfpToChange.IsNull())
118  return;
119 
121 
122  if(tf.IsNull())
123  return;
124 
125  this->m_OpacityItem->SetPiecewiseFunction( tf->GetScalarOpacityFunction() );
126  //m_GradientOpacityCanvas->SetPiecewiseFunction( tf->GetGradientOpacityFunction() );
127  this->m_ColorItem->SetColorTransferFunction( tf->GetColorTransferFunction() );
128 
129  UpdateRanges();
130 
131  this->m_ColorItem->update();
132  //m_GradientOpacityCanvas->update();
133  this->m_OpacityItem->update();
134 }
135 
137 {
138  this->m_ColorItem = item;
139 }
140 
142 {
143  return this->m_ColorItem;
144 }
145 
147 {
148  this->m_OpacityItem = item;
149 }
150 
152 {
153  return this->m_OpacityItem;
154 }
155 
157 {
158  int lower = this->m_CurrentMin;
159  int upper = this->m_CurrentMax;
160 
161  this->m_OpacityItem->SetMin(lower);
162  this->m_OpacityItem->SetMax(upper);
163 
164  // m_GradientOpacityCanvas->SetMin(lower);
165  // m_GradientOpacityCanvas->SetMax(upper);
166 
167  this->m_ColorItem->SetMin(lower);
168  this->m_ColorItem->SetMax(upper);
169 
170  this->m_OpacityItem->update();
171  this->m_ColorItem->update();
172 }
173 
174 
176 {
177  UpdateRanges();
178 
179  //m_GradientOpacityCanvas->update();
180  this->m_OpacityItem->update();
181  this->m_ColorItem->update();
182 }
183 
185 {
186  this->m_CurrentMin = this->m_Min;
187  this->m_CurrentMax = this->m_Max;
188 
189  UpdateRanges();
190 }
191 
193 {
194  this->m_Min = min;
195  emit this->minChanged();
196 }
197 
199 {
200  this->m_Max = max;
201  emit this->maxChanged();
202 }
203 
205 {
206  this->m_CurrentMin = currentMin;
207  UpdateRanges();
208 }
209 
211 {
212  this->m_CurrentMax = currentMax;
213  UpdateRanges();
214 }
215 
217 {
218  return this->m_Min;
219 }
220 
222 {
223  return this->m_Max;
224 }
225 
227 {
228  return this->m_CurrentMin;
229 }
230 
232 {
233  return this->m_CurrentMax;
234 }
235 
237 {
240  qmlRegisterType<QmlMitkTransferFunctionItem>("Mitk.Views", 1, 0, "TransferItem");
241 }
The TransferFunctionProperty class Property class for the mitk::TransferFunction. ...
QmlMitkColorTransferFunctionCanvas * m_ColorItem
void setColorItem(QmlMitkColorTransferFunctionCanvas *item)
Base of all data objects.
Definition: mitkBaseData.h:39
void setOpactityItem(QmlMitkPiecewiseFunctionCanvas *item)
static QmlMitkTransferFunctionItem * instance
void SetColorTransferFunction(vtkColorTransferFunction *colorTransferFunction)
Organizes the rendering process.
virtual double GetMax() const =0
Returns the maximum value of the histogram.
QmlMitkPiecewiseFunctionCanvas * m_OpacityItem
QmlMitkPiecewiseFunctionCanvas * getOpacityItem()
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
mitk::BaseProperty * GetProperty(const char *propertyKey, const mitk::BaseRenderer *renderer=nullptr) const
Get the property (instance of BaseProperty) with key propertyKey from the PropertyList of the rendere...
virtual double GetMin() const =0
Returns the minimal value of the histogram.
void SetPiecewiseFunction(vtkPiecewiseFunction *piecewiseFunction)
void wheelEvent(QWheelEvent *event) override
mitk::TransferFunctionProperty::Pointer tfpToChange
QmlMitkTransferFunctionItem(QQuickItem *parent=nullptr)
#define MITK_WARN
Definition: mitkLogMacros.h:23
Abstract superclass for histograms with double values. Classes which are deriving from this class can...
void SetHistogram(mitk::SimpleHistogram *histogram)
static T max(T x, T y)
Definition: svm.cpp:70
void OnSpanChanged(int lower, int upper)
static T min(T x, T y)
Definition: svm.cpp:67
QmlMitkColorTransferFunctionCanvas * getColorItem()
mitk::SimpleHistogramCache histogramCache
void SetProperty(const char *propertyKey, BaseProperty *property, const mitk::BaseRenderer *renderer=nullptr)
Set the property (instance of BaseProperty) with key propertyKey in the PropertyList of the renderer ...
void SetDataNode(mitk::DataNode *node, const mitk::BaseRenderer *renderer=nullptr)
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66