Fraxinus  16.5.0-fx-rc4
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 "cxActiveData.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(ActiveDataPtr activeData, QWidget* parent, bool connectToActiveImage) :
189  BaseWidget(parent, "TransferFunction3DWidget", "3D"),
190  mLayout(new QVBoxLayout(this)),
191  mActiveImageProxy(ActiveImageProxyPtr()),
192  mActiveData(activeData)
193 {
194  this->setToolTip("Set a transfer function on a 3D volume");
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  {
213  }
214  this->activeImageChangedSlot();
215 }
216 
218 {
219  ImagePtr activeImage = mActiveData->getActive<Image>();
220  this->imageChangedSlot(activeImage);
221 }
222 
224 {
225  ImageTFDataPtr tf;
226  if (image)
227  tf = image->getTransferFunctions3D();
228  else
229  image.reset();
230 
233 }
234 
235 //---------------------------------------------------------
236 //---------------------------------------------------------
237 //---------------------------------------------------------
238 
239 TransferFunction2DWidget::TransferFunction2DWidget(ActiveDataPtr activeData, QWidget* parent, bool connectToActiveImage) :
240  BaseWidget(parent, "TransferFunction2DWidget", "2D"),
241  mLayout(new QVBoxLayout(this)),
242  mActiveData(activeData)
243 {
244  this->setToolTip("Set a transfer function on a 2D image");
248 
253 
257 
258  mTransferFunctionAlphaWidget->setSizePolicy(QSizePolicy::MinimumExpanding,
259  QSizePolicy::MinimumExpanding);
260  mTransferFunctionColorWidget->setSizePolicy(QSizePolicy::Expanding,
261  QSizePolicy::Fixed);
262 
265 
266  QGridLayout* gridLayout = new QGridLayout;
267  mLayout->addLayout(gridLayout);
268  new SliderGroupWidget(this, mDataWindow, gridLayout, 0);
269  new SliderGroupWidget(this, mDataLevel, gridLayout, 1);
270  new SliderGroupWidget(this, mDataAlpha, gridLayout, 2);
271  new SliderGroupWidget(this, mDataLLR, gridLayout, 3);
272 
273  this->setLayout(mLayout);
274  this->activeImageChangedSlot();
275 }
276 
278 {
279  ImagePtr image = mActiveData->getActive<Image>();
280  ImageTFDataPtr tf;
281  if (image)
282  tf = image->getLookupTable2D();
283  else
284  image.reset();
285 
288 
289  mDataWindow->setImageTFData(tf, image);
290  mDataLevel->setImageTFData(tf, image);
291  mDataAlpha->setImageTFData(tf, image);
292  mDataLLR->setImageTFData(tf, image);
293 }
294 
295 
296 //---------------------------------------------------------
297 //---------------------------------------------------------
298 //---------------------------------------------------------
299 
300 TransferFunctionWidget::TransferFunctionWidget(PatientModelServicePtr patientModelService, QWidget* parent, bool connectToActiveImage) :
301  BaseWidget(parent, "TransferFunctionWidget", "Transfer Function")
302 {
303  this->setToolTip("Set a new or predefined transfer function on a volume");
304  QVBoxLayout* mLayout = new QVBoxLayout(this);
305 
306  TransferFunction3DWidget* transferFunctionWidget = new TransferFunction3DWidget(patientModelService->getActiveData(), this, connectToActiveImage);
307 
308  mLayout->setMargin(0);
309  mLayout->addWidget(transferFunctionWidget);
310  mLayout->addWidget(new TransferFunctionPresetWidget(patientModelService, this, true));
311 
312  this->setLayout(mLayout);
313 }
314 
315 }//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
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)
boost::shared_ptr< class ActiveData > ActiveDataPtr
Definition: cxColorWidget.h:42
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:66
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
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:337