CustusX  15.8
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 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 
34 
35 #include <QVBoxLayout>
36 #include <QComboBox>
37 #include <QStringList>
38 #include <QInputDialog>
39 #include <QPushButton>
40 #include <QActionGroup>
41 #include <QToolButton>
42 #include <QAction>
43 #include <QMessageBox>
44 
45 #include "cxImageTF3D.h"
46 #include "cxImageLUT2D.h"
47 
48 #include "cxTypeConversions.h"
52 #include "cxShadingWidget.h"
55 #include "cxSettings.h"
56 #include "cxPatientModelService.h"
57 #include "cxLogicManager.h"
58 
59 namespace cx
60 {
61 
62 //---------------------------------------------------------
63 //---------------------------------------------------------
64 //---------------------------------------------------------
65 
67 {
68 }
69 
71 {
72  if (mImage)
73  disconnect(mImage.get(), &Image::transferFunctionsChanged, this, &Property::changed);
74 
75  mImageTFData = tfData;
76  mImage = image;
77 
78  if (image)
79  connect(image.get(), &Image::transferFunctionsChanged, this, &Property::changed);
80 
81  emit changed();
82 }
83 
85 {
86  if (!mImageTFData)
87  return 0.0;
88  return this->getValueInternal();
89 }
90 
92 {
93  if (!mImageTFData)
94  return false;
95  this->setValueInternal(val);
96  return true;
97 }
98 
99 //---------------------------------------------------------
100 //---------------------------------------------------------
101 
103 {
104  return mImageTFData->getWindow();
105 }
106 
108 {
109  mImageTFData->setWindow(val);
110 }
111 
113 {
114  if (!mImage)
115  return DoubleRange();
116  double range = mImage->getMax() - mImage->getMin();
117  return DoubleRange(1,range,range/1000.0);
118 }
119 
120 //---------------------------------------------------------
121 //---------------------------------------------------------
122 
124 {
125  return mImageTFData->getLevel();
126 }
127 
129 {
130  mImageTFData->setLevel(val);
131 }
132 
134 {
135  if (!mImageTFData)
136  return DoubleRange();
137 
138  double max = mImage->getMax();
139  double min = mImage->getMin();
140  return DoubleRange(min,max,1);
141 }
142 
143 //---------------------------------------------------------
144 //---------------------------------------------------------
145 
147 {
148  return mImageTFData->getLLR();
149 }
151 {
152  mImageTFData->setLLR(val);
153 }
155 {
156  if (!mImageTFData)
157  return DoubleRange();
158 
159  double max = mImage->getMax();
160  double min = mImage->getMin();
161  //Set range to min - 1 to allow an llr that shows all values
162  return DoubleRange(min - 1,max,(max-min)/1000.0);
163 }
164 
165 //---------------------------------------------------------
166 //---------------------------------------------------------
167 
169 {
170  return mImageTFData->getAlpha();
171 }
173 {
174  mImageTFData->setAlpha(val);
175 }
177 {
178  if (!mImageTFData)
179  return DoubleRange();
180 
181  double max = 1.0;
182  return DoubleRange(0,max,max/100.0);
183 }
184 
185 //---------------------------------------------------------
186 //---------------------------------------------------------
187 
188 TransferFunction3DWidget::TransferFunction3DWidget(PatientModelServicePtr patientModelService, QWidget* parent, bool connectToActiveImage) :
189  BaseWidget(parent, "TransferFunction3DWidget", "3D"),
190  mLayout(new QVBoxLayout(this)),
191  mPatientModelService(patientModelService),
192  mActiveImageProxy(ActiveImageProxyPtr())
193 {
194  this->setToolTip("Set a transfer function on a 3D volume");
195  mTransferFunctionAlphaWidget = new TransferFunctionAlphaWidget(patientModelService, this);
196  mTransferFunctionColorWidget = new TransferFunctionColorWidget(patientModelService, this);
197 
198  mTransferFunctionAlphaWidget->setSizePolicy(QSizePolicy::MinimumExpanding,
199  QSizePolicy::MinimumExpanding);
200  mTransferFunctionColorWidget->setSizePolicy(QSizePolicy::Expanding,
201  QSizePolicy::Fixed);
202 
205 
206  this->setLayout(mLayout);
207 
208  if(connectToActiveImage)
209  {
210  mActiveImageProxy = ActiveImageProxy::New(patientModelService);
213  }
214 }
215 
217 {
218  ImagePtr activeImage = mPatientModelService->getActiveImage();
219  this->imageChangedSlot(activeImage);
220 }
221 
223 {
224  ImageTFDataPtr tf;
225  if (image)
226  tf = image->getTransferFunctions3D();
227  else
228  image.reset();
229 
232 }
233 
234 //---------------------------------------------------------
235 //---------------------------------------------------------
236 //---------------------------------------------------------
237 
238 TransferFunction2DWidget::TransferFunction2DWidget(PatientModelServicePtr patientModelService, QWidget* parent, bool connectToActiveImage) :
239  BaseWidget(parent, "TransferFunction2DWidget", "2D"),
240  mLayout(new QVBoxLayout(this)),
241  mPatientModelService(patientModelService)
242 {
243  this->setToolTip("Set a transfer function on a 2D image");
244  mTransferFunctionAlphaWidget = new TransferFunctionAlphaWidget(patientModelService, this);
246  mTransferFunctionColorWidget = new TransferFunctionColorWidget(patientModelService, this);
247 
252 
253  mActiveImageProxy = ActiveImageProxy::New(patientModelService);
256 
257  mTransferFunctionAlphaWidget->setSizePolicy(QSizePolicy::MinimumExpanding,
258  QSizePolicy::MinimumExpanding);
259  mTransferFunctionColorWidget->setSizePolicy(QSizePolicy::Expanding,
260  QSizePolicy::Fixed);
261 
264 
265  QGridLayout* gridLayout = new QGridLayout;
266  mLayout->addLayout(gridLayout);
267  new SliderGroupWidget(this, mDataWindow, gridLayout, 0);
268  new SliderGroupWidget(this, mDataLevel, gridLayout, 1);
269  new SliderGroupWidget(this, mDataAlpha, gridLayout, 2);
270  new SliderGroupWidget(this, mDataLLR, gridLayout, 3);
271 
272  this->setLayout(mLayout);
273 }
274 
276 {
277  ImagePtr image = mPatientModelService->getActiveImage();
278  ImageTFDataPtr tf;
279  if (image)
280  tf = image->getLookupTable2D();
281  else
282  image.reset();
283 
286 
287  mDataWindow->setImageTFData(tf, image);
288  mDataLevel->setImageTFData(tf, image);
289  mDataAlpha->setImageTFData(tf, image);
290  mDataLLR->setImageTFData(tf, image);
291 }
292 
293 
294 //---------------------------------------------------------
295 //---------------------------------------------------------
296 //---------------------------------------------------------
297 
298 TransferFunctionWidget::TransferFunctionWidget(PatientModelServicePtr patientModelService, QWidget* parent, bool connectToActiveImage) :
299  BaseWidget(parent, "TransferFunctionWidget", "Transfer Function")
300 {
301  this->setToolTip("Set a new or predefined transfer function on a volume");
302  QVBoxLayout* mLayout = new QVBoxLayout(this);
303 
304  TransferFunction3DWidget* transferFunctionWidget = new TransferFunction3DWidget(patientModelService, this, connectToActiveImage);
305 
306  mLayout->setMargin(0);
307  mLayout->addWidget(transferFunctionWidget);
308  mLayout->addWidget(new TransferFunctionPresetWidget(patientModelService, this, true));
309 
310  this->setLayout(mLayout);
311 }
312 
313 }//namespace cx
PatientModelServicePtr mPatientModelService
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
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:53
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:48
DoublePropertyImageTFDataBasePtr mDataLLR
TransferFunctionColorWidget * mTransferFunctionColorWidget
boost::shared_ptr< class ActiveImageProxy > ActiveImageProxyPtr
void setData(ImagePtr image, ImageTFDataPtr tfData)
virtual DoubleRange getValueRange() const
void transferFunctionsChanged()
virtual void setValueInternal(double val)=0
TransferFunction2DWidget(PatientModelServicePtr patientModelService, QWidget *parent, bool connectToActiveImage=true)
TransferFunctionAlphaWidget * mTransferFunctionAlphaWidget
PatientModelServicePtr mPatientModelService
virtual DoubleRange getValueRange() const
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:108
TransferFunction3DWidget(PatientModelServicePtr patientModelService, QWidget *parent, bool connectToActiveImage=true)
DoublePropertyImageTFDataBasePtr mDataLevel
static ActiveImageProxyPtr New(PatientModelServicePtr patientModelService)
boost::shared_ptr< class ImageTFData > ImageTFDataPtr
void activeImageChanged(const QString &uid)
The original image changed signal from DataManager.
DoublePropertyImageTFDataBasePtr mDataWindow