Fraxinus  16.5.0-fx-rc1
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxShadingWidget.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 
33 /*
34  * cxShadingWidget.cpp
35  *
36  * \date Aug 20, 2010
37  * \author christiana
38  */
39 #include "cxShadingWidget.h"
40 
41 #include <QVBoxLayout>
42 #include <QComboBox>
43 #include <QStringList>
44 #include "cxImageTF3D.h"
47 #include "cxActiveData.h"
48 
49 namespace cx
50 {
51 
53  BaseWidget(parent, "ImagePropertiesWidget", "Image Properties"),
54  mImage(ImagePtr())
55 {
56  mInterpolationType = new QComboBox(this);
57  mInterpolationType->insertItem(0, "Nearest");
58  mInterpolationType->insertItem(1, "Linear");
59  mInterpolationType->insertItem(2, "Cubic");
60  mInterpolationType->setToolTip("Change VTK interpolation type");
61 
62  connect(mInterpolationType, SIGNAL(currentIndexChanged(int)), this, SLOT(interpolationTypeChanged(int)));
63 
64  QLabel* interpolationTypeLabel = new QLabel("Volume interpolation type", this);
65 
66  QHBoxLayout* layout = new QHBoxLayout(this);
67  layout->addWidget(interpolationTypeLabel);
68  layout->addWidget(mInterpolationType);
69 }
70 
71 void ImageRenderPropertiesWidget::interpolationTypeChanged(int index)
72 {
73  if (mImage)
74  mImage->setInterpolationType(index);
75 }
76 
78 {
79  mImage = image;
80  if (mImage)
81  mInterpolationType->setCurrentIndex(mImage->getInterpolationType());
82 }
83 
84 //---------------------------------------------------------
85 //---------------------------------------------------------
86 //---------------------------------------------------------
87 
88 ShadingWidget::ShadingWidget(ActiveDataPtr activeData, QWidget* parent, bool connectToActiveImage) :
89  BaseWidget(parent, "ShadingWidget", "Shading"),
90  mLayout(new QVBoxLayout(this)),
91  mActiveData(activeData),
92  mActiveImageProxy(ActiveImageProxyPtr()),
93  mImage(ImagePtr()),
94  mImagePropertiesWidget(ImageRenderPropertiesWidgetPtr())
95 {
96  this->init(connectToActiveImage);
97 }
98 
100 {}
101 
102 void ShadingWidget::init(bool connectToActiveImage)
103 {
104  mShadingCheckBox = new QCheckBox("Shading", this);
105  this->setToolTip("Volume shading properties");
106 
107  connect(mShadingCheckBox, &QCheckBox::toggled, this, &ShadingWidget::shadingToggledSlot);
108 
109  QGridLayout* shadingLayput = new QGridLayout();
110  shadingLayput->addWidget(mShadingCheckBox, 0,0);
111  SliderGroupWidget* shadingAmbientWidget = new SliderGroupWidget(this, DoublePropertyBasePtr(new DoublePropertyShadingAmbient(mActiveData)), shadingLayput, 1);
112  SliderGroupWidget* shadingDiffuseWidget = new SliderGroupWidget(this, DoublePropertyBasePtr(new DoublePropertyShadingDiffuse(mActiveData)), shadingLayput, 2);
113  SliderGroupWidget* shadingSpecularWidget = new SliderGroupWidget(this, DoublePropertyBasePtr(new DoublePropertyShadingSpecular(mActiveData)), shadingLayput, 3);
114  SliderGroupWidget* shadingSpecularPowerWidget = new SliderGroupWidget(this, DoublePropertyBasePtr(new DoublePropertyShadingSpecularPower(mActiveData)), shadingLayput, 4);
115 
116  shadingAmbientWidget->setEnabled(false);
117  shadingDiffuseWidget->setEnabled(false);
118  shadingSpecularWidget->setEnabled(false);
119  shadingSpecularPowerWidget->setEnabled(false);
120 
121  if (connectToActiveImage)
122  {
126  }
127 
129  shadingLayput->addWidget(mImagePropertiesWidget.get(), 5, 0, 1, 2);
130  mLayout->addLayout(shadingLayput);
131  mLayout->addStretch(1);
132  this->activeImageChangedSlot();
133 }
134 
136 {
137  if (mImage)
138  mImage->setShadingOn(val);
139 }
140 
142 {
143  ImagePtr activeImage = mActiveData->getActive<Image>();
144  this->imageChangedSlot(activeImage);
145 }
146 
148 {
149  mImage = image;
150  if (mImage)
151  {
152  mShadingCheckBox->setChecked(mImage->getShadingOn());
153  mImagePropertiesWidget->imageChanged(image);
154  }
155 }
156 
157 }//namespace cx
void imageChangedSlot(ImagePtr image)
Composite widget for scalar data manipulation.
void activeImageChangedSlot()
listens to the contextdockwidget for when the current image is changed
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:48
ActiveDataPtr mActiveData
boost::shared_ptr< class ActiveImageProxy > ActiveImageProxyPtr
boost::shared_ptr< class ActiveData > ActiveDataPtr
Definition: cxColorWidget.h:42
void transferFunctionsChanged()
QCheckBox * mShadingCheckBox
ImageRenderPropertiesWidget(QWidget *parent)
static ActiveImageProxyPtr New(ActiveDataPtr activeData)
A volumetric data set.
Definition: cxImage.h:66
void imageChanged(ImagePtr image)
boost::shared_ptr< class DoublePropertyBase > DoublePropertyBasePtr
boost::shared_ptr< class ImageRenderPropertiesWidget > ImageRenderPropertiesWidgetPtr
QVBoxLayout * mLayout
void shadingToggledSlot(bool val)
void init(bool connectToActiveImage)
Initialize TransferFunctionWidget. Create members.
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:108
ImageRenderPropertiesWidgetPtr mImagePropertiesWidget
ActiveImageProxyPtr mActiveImageProxy
void activeImageChanged(const QString &uid)
The original image changed signal from DataManager.
ShadingWidget(ActiveDataPtr activeData, QWidget *parent, bool connectToActiveImage=true)