CustusX  15.8
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 "cxPatientModelService.h"
48 #include "cxLogicManager.h"
49 
50 namespace cx
51 {
52 
53 ShadingWidget::ShadingWidget(PatientModelServicePtr patientModelService, QWidget* parent, bool connectToActiveImage) :
54  BaseWidget(parent, "ShadingWidget", "Shading"),
55  mLayout(new QVBoxLayout(this)),
56  mPatientModelService(patientModelService),
57  mActiveImageProxy(ActiveImageProxyPtr()),
58  mImage(ImagePtr()),
59  mImagePropertiesWidget(ImagePropertiesWidgetPtr())
60 {
61  this->init(connectToActiveImage);
62 }
63 
65 {}
66 
67 void ShadingWidget::init(bool connectToActiveImage)
68 {
69  mShadingCheckBox = new QCheckBox("Shading", this);
70  this->setToolTip("Volume shading properties");
71 
72  connect(mShadingCheckBox, &QCheckBox::toggled, this, &ShadingWidget::shadingToggledSlot);
73 
74  QGridLayout* shadingLayput = new QGridLayout();
75  shadingLayput->addWidget(mShadingCheckBox, 0,0);
76  SliderGroupWidget* shadingAmbientWidget = new SliderGroupWidget(this, DoublePropertyBasePtr(new DoublePropertyShadingAmbient(mPatientModelService)), shadingLayput, 1);
77  SliderGroupWidget* shadingDiffuseWidget = new SliderGroupWidget(this, DoublePropertyBasePtr(new DoublePropertyShadingDiffuse(mPatientModelService)), shadingLayput, 2);
78  SliderGroupWidget* shadingSpecularWidget = new SliderGroupWidget(this, DoublePropertyBasePtr(new DoublePropertyShadingSpecular(mPatientModelService)), shadingLayput, 3);
79  SliderGroupWidget* shadingSpecularPowerWidget = new SliderGroupWidget(this, DoublePropertyBasePtr(new DoublePropertyShadingSpecularPower(mPatientModelService)), shadingLayput, 4);
80 
81  shadingAmbientWidget->setEnabled(false);
82  shadingDiffuseWidget->setEnabled(false);
83  shadingSpecularWidget->setEnabled(false);
84  shadingSpecularPowerWidget->setEnabled(false);
85 
86  if (connectToActiveImage)
87  {
91  }
92 
94  shadingLayput->addWidget(mImagePropertiesWidget.get(), 5, 0, 1, 2);
95  mLayout->addLayout(shadingLayput);
96  mLayout->addStretch(1);
97 }
98 
100 {
101  if (mImage)
102  mImage->setShadingOn(val);
103 }
104 
106 {
107  ImagePtr activeImage = mPatientModelService->getActiveImage();
108  this->imageChangedSlot(activeImage);
109 }
110 
112 {
113  mImage = image;
114  if (mImage)
115  {
116  mShadingCheckBox->setChecked(mImage->getShadingOn());
117  mImagePropertiesWidget->imageChanged(image);
118  }
119 }
120 
121 }//namespace cx
void imageChangedSlot(ImagePtr image)
PatientModelServicePtr mPatientModelService
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
boost::shared_ptr< class ActiveImageProxy > ActiveImageProxyPtr
void transferFunctionsChanged()
QCheckBox * mShadingCheckBox
ImagePropertiesWidgetPtr mImagePropertiesWidget
ShadingWidget(PatientModelServicePtr patientModelService, QWidget *parent, bool connectToActiveImage=true)
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
boost::shared_ptr< class DoublePropertyBase > DoublePropertyBasePtr
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
static ActiveImageProxyPtr New(PatientModelServicePtr patientModelService)
boost::shared_ptr< class ImagePropertiesWidget > ImagePropertiesWidgetPtr
ActiveImageProxyPtr mActiveImageProxy
void activeImageChanged(const QString &uid)
The original image changed signal from DataManager.