CustusX  15.3.4-beta
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 (mImageTFData)
74 
75  mImageTFData = tfData;
76  mImage = image;
77 
78  if (mImageTFData)
79  connect(mImageTFData.get(), &ImageTFData::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  mTransferFunctionAlphaWidget = new TransferFunctionAlphaWidget(patientModelService, this);
195  mTransferFunctionColorWidget = new TransferFunctionColorWidget(patientModelService, this);
196 
197  mTransferFunctionAlphaWidget->setSizePolicy(QSizePolicy::MinimumExpanding,
198  QSizePolicy::MinimumExpanding);
199  mTransferFunctionColorWidget->setSizePolicy(QSizePolicy::Expanding,
200  QSizePolicy::Fixed);
201 
204 
205  this->setLayout(mLayout);
206 
207  if(connectToActiveImage)
208  {
209  mActiveImageProxy = ActiveImageProxy::New(patientModelService);
212  }
213 }
214 
216 {
217  return "<html>"
218  "<h3>3D Transfer Function</h3>"
219  "<p>Lets you set a transfer function on a 3D volume.</p>"
220  "<p><i></i></p>"
221  "</html>";
222 }
223 
225 {
226  ImagePtr activeImage = mPatientModelService->getActiveImage();
227  this->imageChangedSlot(activeImage);
228 }
229 
231 {
232  ImageTFDataPtr tf;
233  if (image)
234  tf = image->getTransferFunctions3D();
235  else
236  image.reset();
237 
240 }
241 
242 //---------------------------------------------------------
243 //---------------------------------------------------------
244 //---------------------------------------------------------
245 
246 TransferFunction2DWidget::TransferFunction2DWidget(PatientModelServicePtr patientModelService, QWidget* parent, bool connectToActiveImage) :
247  BaseWidget(parent, "TransferFunction2DWidget", "2D"),
248  mLayout(new QVBoxLayout(this)),
249  mPatientModelService(patientModelService)
250 {
251  mTransferFunctionAlphaWidget = new TransferFunctionAlphaWidget(patientModelService, this);
253  mTransferFunctionColorWidget = new TransferFunctionColorWidget(patientModelService, this);
254 
259 
260  mActiveImageProxy = ActiveImageProxy::New(patientModelService);
263 
264  mTransferFunctionAlphaWidget->setSizePolicy(QSizePolicy::MinimumExpanding,
265  QSizePolicy::MinimumExpanding);
266  mTransferFunctionColorWidget->setSizePolicy(QSizePolicy::Expanding,
267  QSizePolicy::Fixed);
268 
271 
272  QGridLayout* gridLayout = new QGridLayout;
273  mLayout->addLayout(gridLayout);
274  new SliderGroupWidget(this, mDataWindow, gridLayout, 0);
275  new SliderGroupWidget(this, mDataLevel, gridLayout, 1);
276  new SliderGroupWidget(this, mDataAlpha, gridLayout, 2);
277  new SliderGroupWidget(this, mDataLLR, gridLayout, 3);
278 
279  this->setLayout(mLayout);
280 }
281 
283 {
284  return "<html>"
285  "<h3>2D Transfer Function</h3>"
286  "<p>Lets you set a transfer function on a 2D image.</p>"
287  "<p><i></i></p>"
288  "</html>";
289 }
290 
292 {
293  ImagePtr image = mPatientModelService->getActiveImage();
294  ImageTFDataPtr tf;
295  if (image)
296  tf = image->getLookupTable2D();
297  else
298  image.reset();
299 
302 
303  mDataWindow->setImageTFData(tf, image);
304  mDataLevel->setImageTFData(tf, image);
305  mDataAlpha->setImageTFData(tf, image);
306  mDataLLR->setImageTFData(tf, image);
307 }
308 
309 
310 //---------------------------------------------------------
311 //---------------------------------------------------------
312 //---------------------------------------------------------
313 
314 TransferFunctionWidget::TransferFunctionWidget(PatientModelServicePtr patientModelService, QWidget* parent, bool connectToActiveImage) :
315  BaseWidget(parent, "TransferFunctionWidget", "Transfer Function")
316 {
317  QVBoxLayout* mLayout = new QVBoxLayout(this);
318 
319  TransferFunction3DWidget* transferFunctionWidget = new TransferFunction3DWidget(patientModelService, this, connectToActiveImage);
320 
321  mLayout->setMargin(0);
322  mLayout->addWidget(transferFunctionWidget);
323  mLayout->addWidget(new TransferFunctionPresetWidget(patientModelService, this, true));
324 
325  this->setLayout(mLayout);
326 }
327 
329 {
330  return "<html>"
331  "<h3>Transfer Function.</h3>"
332  "<p>Lets you set a new or predefined transfer function on a volume.</p>"
333  "<p><i></i></p>"
334  "</html>";
335 }
336 }//namespace cx
void transferFunctionsChanged()
virtual QString defaultWhatsThis() const
Returns a short description of what this widget will do for you.
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
virtual QString defaultWhatsThis() const
Returns a short description of what this widget will do for you.
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 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)
virtual QString defaultWhatsThis() const
Returns a short description of what this widget will do for you.
boost::shared_ptr< class ImageTFData > ImageTFDataPtr
void activeImageChanged(const QString &uid)
The original image changed signal from DataManager.
DoublePropertyImageTFDataBasePtr mDataWindow