Fraxinus  2023.01.05-dev+develop.0da12
An IGT application
cxTransferFunctionWidget.cpp
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 
13 
14 #include <QVBoxLayout>
15 #include <QComboBox>
16 #include <QStringList>
17 #include <QInputDialog>
18 #include <QPushButton>
19 #include <QActionGroup>
20 #include <QToolButton>
21 #include <QAction>
22 #include <QMessageBox>
23 
24 #include "cxImageTF3D.h"
25 #include "cxImageLUT2D.h"
26 
27 #include "cxTypeConversions.h"
31 #include "cxShadingWidget.h"
34 #include "cxSettings.h"
35 #include "cxPatientModelService.h"
36 #include "cxActiveData.h"
37 
38 namespace cx
39 {
40 
41 //---------------------------------------------------------
42 //---------------------------------------------------------
43 //---------------------------------------------------------
44 
46 {
47 }
48 
50 {
51  if (mImage)
52  disconnect(mImage.get(), &Image::transferFunctionsChanged, this, &Property::changed);
53 
54  mImageTFData = tfData;
55  mImage = image;
56 
57  if (image)
58  connect(image.get(), &Image::transferFunctionsChanged, this, &Property::changed);
59 
60  emit changed();
61 }
62 
64 {
65  if (!mImageTFData)
66  return 0.0;
67  return this->getValueInternal();
68 }
69 
71 {
72  if (!mImageTFData)
73  return false;
74  this->setValueInternal(val);
75  return true;
76 }
77 
78 //---------------------------------------------------------
79 //---------------------------------------------------------
80 
82 {
83  return mImageTFData->getWindow();
84 }
85 
87 {
88  mImageTFData->setWindow(val);
89 }
90 
92 {
93  if (!mImage)
94  return DoubleRange();
95  double range = mImage->getMax() - mImage->getMin();
96  return DoubleRange(1,range,range/1000.0);
97 }
98 
99 //---------------------------------------------------------
100 //---------------------------------------------------------
101 
103 {
104  return mImageTFData->getLevel();
105 }
106 
108 {
109  mImageTFData->setLevel(val);
110 }
111 
113 {
114  if (!mImageTFData)
115  return DoubleRange();
116 
117  double max = mImage->getMax();
118  double min = mImage->getMin();
119  return DoubleRange(min,max,1);
120 }
121 
122 //---------------------------------------------------------
123 //---------------------------------------------------------
124 
126 {
127  return mImageTFData->getLLR();
128 }
130 {
131  mImageTFData->setLLR(val);
132 }
134 {
135  if (!mImageTFData)
136  return DoubleRange();
137 
138  double max = mImage->getMax();
139  double min = mImage->getMin();
140  //Set range to min - 1 to allow an llr that shows all values
141  return DoubleRange(min - 1,max,(max-min)/1000.0);
142 }
143 
144 //---------------------------------------------------------
145 //---------------------------------------------------------
146 
148 {
149  return mImageTFData->getAlpha();
150 }
152 {
153  mImageTFData->setAlpha(val);
154 }
156 {
157  if (!mImageTFData)
158  return DoubleRange();
159 
160  double max = 1.0;
161  return DoubleRange(0,max,max/100.0);
162 }
163 
164 //---------------------------------------------------------
165 //---------------------------------------------------------
166 
167 TransferFunction3DWidget::TransferFunction3DWidget(ActiveDataPtr activeData, QWidget* parent, bool connectToActiveImage) :
168  BaseWidget(parent, "transfer_function_3d_widget", "3D"),
169  mLayout(new QVBoxLayout(this)),
170  mActiveImageProxy(ActiveImageProxyPtr()),
171  mActiveData(activeData)
172 {
173  this->setToolTip("Set a transfer function on a 3D volume");
176 
177  mTransferFunctionAlphaWidget->setSizePolicy(QSizePolicy::MinimumExpanding,
178  QSizePolicy::MinimumExpanding);
179  mTransferFunctionColorWidget->setSizePolicy(QSizePolicy::Expanding,
180  QSizePolicy::Fixed);
181 
184 
185  this->setLayout(mLayout);
186 
187  if(connectToActiveImage)
188  {
192  }
193  this->activeImageChangedSlot();
194 }
195 
197 {
198  ImagePtr activeImage = mActiveData->getActive<Image>();
199  this->imageChangedSlot(activeImage);
200 }
201 
203 {
204  ImageTFDataPtr tf;
205  if (image)
206  tf = image->getTransferFunctions3D();
207  else
208  image.reset();
209 
212 }
213 
214 //---------------------------------------------------------
215 //---------------------------------------------------------
216 //---------------------------------------------------------
217 
218 TransferFunction2DWidget::TransferFunction2DWidget(ActiveDataPtr activeData, QWidget* parent, bool connectToActiveImage) :
219  BaseWidget(parent, "transfer_function_2d_widget", "2D"),
220  mLayout(new QVBoxLayout(this)),
221  mActiveData(activeData)
222 {
223  this->setToolTip("Set a transfer function on a 2D image");
227 
232 
236 
237  mTransferFunctionAlphaWidget->setSizePolicy(QSizePolicy::MinimumExpanding,
238  QSizePolicy::MinimumExpanding);
239  mTransferFunctionColorWidget->setSizePolicy(QSizePolicy::Expanding,
240  QSizePolicy::Fixed);
241 
244 
245  QGridLayout* gridLayout = new QGridLayout;
246  mLayout->addLayout(gridLayout);
247  new SliderGroupWidget(this, mDataWindow, gridLayout, 0);
248  new SliderGroupWidget(this, mDataLevel, gridLayout, 1);
249  new SliderGroupWidget(this, mDataAlpha, gridLayout, 2);
250  new SliderGroupWidget(this, mDataLLR, gridLayout, 3);
251 
252  this->setLayout(mLayout);
253  this->activeImageChangedSlot();
254 }
255 
257 {
258  ImagePtr image = mActiveData->getActive<Image>();
259  ImageTFDataPtr tf;
260  if (image)
261  tf = image->getLookupTable2D();
262  else
263  image.reset();
264 
267 
268  mDataWindow->setImageTFData(tf, image);
269  mDataLevel->setImageTFData(tf, image);
270  mDataAlpha->setImageTFData(tf, image);
271  mDataLLR->setImageTFData(tf, image);
272 }
273 
274 
275 //---------------------------------------------------------
276 //---------------------------------------------------------
277 //---------------------------------------------------------
278 
279 TransferFunctionWidget::TransferFunctionWidget(PatientModelServicePtr patientModelService, QWidget* parent, bool connectToActiveImage) :
280  BaseWidget(parent, "transfer_function_widget", "Transfer Function")
281 {
282  this->setToolTip("Set a new or predefined transfer function on a volume");
283  QVBoxLayout* mLayout = new QVBoxLayout(this);
284 
285  TransferFunction3DWidget* transferFunctionWidget = new TransferFunction3DWidget(patientModelService->getActiveData(), this, connectToActiveImage);
286 
287  mLayout->setMargin(0);
288  mLayout->addWidget(transferFunctionWidget);
289  mLayout->addWidget(new TransferFunctionPresetWidget(patientModelService, this, true));
290 
291  this->setLayout(mLayout);
292 }
293 
294 }//namespace cx
virtual bool setValue(double val)
set the data value.
virtual double getValueInternal() const =0
void setImageTFData(ImageTFDataPtr tfData, ImagePtr image)
Composite widget for scalar data manipulation.
virtual DoubleRange getValueRange() const
TransferFunctionAlphaWidget * mTransferFunctionAlphaWidget
virtual double getValue() const
get the data value.
TransferFunctionColorWidget * mTransferFunctionColorWidget
virtual DoubleRange getValueRange() const
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:32
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
DoublePropertyImageTFDataBasePtr mDataLLR
TransferFunctionColorWidget * mTransferFunctionColorWidget
boost::shared_ptr< class ActiveImageProxy > ActiveImageProxyPtr
void setData(ImagePtr image, ImageTFDataPtr tfData)
boost::shared_ptr< class ActiveData > ActiveDataPtr
Definition: cxColorWidget.h:21
TransferFunction2DWidget(ActiveDataPtr activeData, QWidget *parent, bool connectToActiveImage=true)
virtual DoubleRange getValueRange() const
void transferFunctionsChanged()
virtual void setValueInternal(double val)=0
TransferFunctionAlphaWidget * mTransferFunctionAlphaWidget
static ActiveImageProxyPtr New(ActiveDataPtr activeData)
virtual DoubleRange getValueRange() const
A volumetric data set.
Definition: cxImage.h:45
DoublePropertyImageTFDataBasePtr mDataAlpha
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
void transferFunctionsChanged()
emitted when image transfer functions in 2D or 3D are changed.
void changed()
emit when the underlying data value is changed: The user interface will be updated.
void setReadOnly(bool readOnly)
Set class readonly: Disable mouse interaction.
TransferFunctionWidget(PatientModelServicePtr patientModelService, QWidget *parent, bool connectToActiveImage=true)
void setData(ImagePtr image, ImageTFDataPtr tfData)
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:88
DoublePropertyImageTFDataBasePtr mDataLevel
boost::shared_ptr< class ImageTFData > ImageTFDataPtr
void activeImageChanged(const QString &uid)
The original image changed signal from DataManager.
DoublePropertyImageTFDataBasePtr mDataWindow
TransferFunction3DWidget(ActiveDataPtr activeData, QWidget *parent, bool connectToActiveImage=true)
virtual ImageLUT2DPtr getLookupTable2D()
Definition: cxImage.cpp:316
Namespace for all CustusX production code.