NorMIT-nav  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
cx::DoublePropertyImageTFDataBase::setValueInternal
virtual void setValueInternal(double val)=0
cx::DoublePropertyImageTFDataAlpha
Definition: cxTransferFunctionWidget.h:105
cx::TransferFunctionWidget::TransferFunctionWidget
TransferFunctionWidget(PatientModelServicePtr patientModelService, QWidget *parent, bool connectToActiveImage=true)
Definition: cxTransferFunctionWidget.cpp:279
cx::DoublePropertyImageTFDataBase::DoublePropertyImageTFDataBase
DoublePropertyImageTFDataBase()
Definition: cxTransferFunctionWidget.cpp:45
cx::DoublePropertyImageTFDataLevel::getValueRange
virtual DoubleRange getValueRange() const
Definition: cxTransferFunctionWidget.cpp:112
cx::DoublePropertyImageTFDataLLR::setValueInternal
virtual void setValueInternal(double val)
Definition: cxTransferFunctionWidget.cpp:129
cxShadingParamsInterfaces.h
cx::Image::transferFunctionsChanged
void transferFunctionsChanged()
emitted when image transfer functions in 2D or 3D are changed.
cx::DoublePropertyImageTFDataBase::setValue
virtual bool setValue(double val)
set the data value.
Definition: cxTransferFunctionWidget.cpp:70
cxTransferFunctionWidget.h
cxActiveData.h
cx::TransferFunction3DWidget::activeImageChangedSlot
void activeImageChangedSlot()
Definition: cxTransferFunctionWidget.cpp:196
cxDataViewSelectionWidget.h
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::ActiveImageProxy::activeImageChanged
void activeImageChanged(const QString &uid)
The original image changed signal from DataManager.
cx::TransferFunction2DWidget::mDataLLR
DoublePropertyImageTFDataBasePtr mDataLLR
Definition: cxTransferFunctionWidget.h:152
cx::TransferFunction2DWidget::mActiveData
ActiveDataPtr mActiveData
Definition: cxTransferFunctionWidget.h:155
cx::BaseWidget
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:88
cx::Property::changed
void changed()
emit when the underlying data value is changed: The user interface will be updated.
cx::DoublePropertyImageTFDataWindow::setValueInternal
virtual void setValueInternal(double val)
Definition: cxTransferFunctionWidget.cpp:86
cx::TransferFunction3DWidget::mTransferFunctionColorWidget
TransferFunctionColorWidget * mTransferFunctionColorWidget
Definition: cxTransferFunctionWidget.h:131
cx::DoublePropertyImageTFDataAlpha::setValueInternal
virtual void setValueInternal(double val)
Definition: cxTransferFunctionWidget.cpp:151
cx::ImageTFDataPtr
boost::shared_ptr< class ImageTFData > ImageTFDataPtr
Definition: cxForwardDeclarations.h:52
cx::DoublePropertyImageTFDataBase::getValueInternal
virtual double getValueInternal() const =0
cx::ActiveImageProxy::New
static ActiveImageProxyPtr New(ActiveDataPtr activeData)
Definition: cxActiveImageProxy.h:44
cx::TransferFunction2DWidget::mTransferFunctionColorWidget
TransferFunctionColorWidget * mTransferFunctionColorWidget
Definition: cxTransferFunctionWidget.h:151
cx::DoublePropertyImageTFDataLLR::getValueRange
virtual DoubleRange getValueRange() const
Definition: cxTransferFunctionWidget.cpp:133
cx::TransferFunction3DWidget::mLayout
QVBoxLayout * mLayout
Definition: cxTransferFunctionWidget.h:129
cx::TransferFunction3DWidget::mActiveData
ActiveDataPtr mActiveData
Definition: cxTransferFunctionWidget.h:134
cx::TransferFunction2DWidget::TransferFunction2DWidget
TransferFunction2DWidget(ActiveDataPtr activeData, QWidget *parent, bool connectToActiveImage=true)
Definition: cxTransferFunctionWidget.cpp:218
cx::DoublePropertyImageTFDataAlpha::getValueRange
virtual DoubleRange getValueRange() const
Definition: cxTransferFunctionWidget.cpp:155
cx::ActiveImageProxy::transferFunctionsChanged
void transferFunctionsChanged()
cx::Image::getLookupTable2D
virtual ImageLUT2DPtr getLookupTable2D()
Definition: cxImage.cpp:316
cx::TransferFunctionColorWidget
Definition: cxTransferFunctionColorWidget.h:37
cx::ActiveImageProxyPtr
boost::shared_ptr< class ActiveImageProxy > ActiveImageProxyPtr
Definition: cxDataInterface.h:29
cx::TransferFunctionColorWidget::setData
void setData(ImagePtr image, ImageTFDataPtr tfData)
Definition: cxTransferFunctionColorWidget.cpp:68
cx::TransferFunction3DWidget::imageChangedSlot
void imageChangedSlot(ImagePtr image)
Definition: cxTransferFunctionWidget.cpp:202
cx::TransferFunction3DWidget::mTransferFunctionAlphaWidget
TransferFunctionAlphaWidget * mTransferFunctionAlphaWidget
Definition: cxTransferFunctionWidget.h:130
cx::TransferFunction2DWidget::mTransferFunctionAlphaWidget
TransferFunctionAlphaWidget * mTransferFunctionAlphaWidget
Definition: cxTransferFunctionWidget.h:150
cx::TransferFunction2DWidget::mDataAlpha
DoublePropertyImageTFDataBasePtr mDataAlpha
Definition: cxTransferFunctionWidget.h:152
cx::TransferFunction2DWidget::mDataLevel
DoublePropertyImageTFDataBasePtr mDataLevel
Definition: cxTransferFunctionWidget.h:152
cx::DoublePropertyImageTFDataBase::getValue
virtual double getValue() const
get the data value.
Definition: cxTransferFunctionWidget.cpp:63
cx::DoublePropertyImageTFDataAlpha::getValueInternal
virtual double getValueInternal() const
Definition: cxTransferFunctionWidget.cpp:147
cx::PatientModelServicePtr
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
Definition: cxLogicManager.h:25
cx::DoublePropertyImageTFDataBase::setImageTFData
void setImageTFData(ImageTFDataPtr tfData, ImagePtr image)
Definition: cxTransferFunctionWidget.cpp:49
cxTypeConversions.h
cxPatientModelService.h
cx::ImagePtr
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
cxSettings.h
cx::TransferFunctionAlphaWidget::setData
void setData(ImagePtr image, ImageTFDataPtr tfData)
Definition: cxTransferFunctionAlphaWidget.cpp:49
cx::TransferFunctionAlphaWidget
Definition: cxTransferFunctionAlphaWidget.h:37
cx::DoublePropertyImageTFDataLLR
Definition: cxTransferFunctionWidget.h:92
cx::TransferFunction2DWidget::mLayout
QVBoxLayout * mLayout
Definition: cxTransferFunctionWidget.h:149
cx::TransferFunctionAlphaWidget::setReadOnly
void setReadOnly(bool readOnly)
Set class readonly: Disable mouse interaction.
Definition: cxTransferFunctionAlphaWidget.cpp:59
cx::DoublePropertyImageTFDataWindow::getValueInternal
virtual double getValueInternal() const
Definition: cxTransferFunctionWidget.cpp:81
cxTransferFunctionColorWidget.h
cx::DoublePropertyImageTFDataLevel::setValueInternal
virtual void setValueInternal(double val)
Definition: cxTransferFunctionWidget.cpp:107
cx::Image
A volumetric data set.
Definition: cxImage.h:45
cx::SliderGroupWidget
Composite widget for scalar data manipulation.
Definition: cxDoubleWidgets.h:173
cxTransferFunctionPresetWidget.h
cx::TransferFunction3DWidget::TransferFunction3DWidget
TransferFunction3DWidget(ActiveDataPtr activeData, QWidget *parent, bool connectToActiveImage=true)
Definition: cxTransferFunctionWidget.cpp:167
cx::DoubleRange
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:32
cx::TransferFunction2DWidget::mDataWindow
DoublePropertyImageTFDataBasePtr mDataWindow
Definition: cxTransferFunctionWidget.h:152
cx::ActiveDataPtr
boost::shared_ptr< class ActiveData > ActiveDataPtr
Definition: cxColorWidget.h:21
cxTransferFunctionAlphaWidget.h
cxImageTF3D.h
cxShadingWidget.h
cxImageLUT2D.h
cx::TransferFunction2DWidget::mActiveImageProxy
ActiveImageProxyPtr mActiveImageProxy
Definition: cxTransferFunctionWidget.h:154
cx::TransferFunction3DWidget
Definition: cxTransferFunctionWidget.h:116
cx::DoublePropertyImageTFDataBase::mImageTFData
ImageTFDataPtr mImageTFData
Definition: cxTransferFunctionWidget.h:59
cx::DoublePropertyImageTFDataWindow
Definition: cxTransferFunctionWidget.h:67
cx::TransferFunctionPresetWidget
Definition: cxTransferFunctionPresetWidget.h:32
cx::DoublePropertyImageTFDataLLR::getValueInternal
virtual double getValueInternal() const
Definition: cxTransferFunctionWidget.cpp:125
cx::DoublePropertyImageTFDataLevel
Definition: cxTransferFunctionWidget.h:79
cx::TransferFunction2DWidget::activeImageChangedSlot
void activeImageChangedSlot()
Definition: cxTransferFunctionWidget.cpp:256
cx::DoublePropertyImageTFDataBase::mImage
ImagePtr mImage
Definition: cxTransferFunctionWidget.h:60
cx::DoublePropertyImageTFDataWindow::getValueRange
virtual DoubleRange getValueRange() const
Definition: cxTransferFunctionWidget.cpp:91
cx::DoublePropertyImageTFDataLevel::getValueInternal
virtual double getValueInternal() const
Definition: cxTransferFunctionWidget.cpp:102
cx::TransferFunction3DWidget::mActiveImageProxy
ActiveImageProxyPtr mActiveImageProxy
Definition: cxTransferFunctionWidget.h:133