CustusX  15.3.3-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxClippingWidget.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 #include "cxClippingWidget.h"
33 
34 #include <QVBoxLayout>
35 #include <QPushButton>
36 #include <QCheckBox>
37 #include <QGroupBox>
38 #include "cxStringPropertyBase.h"
40 #include "cxDefinitionStrings.h"
41 #include "cxInteractiveClipper.h"
43 #include "cxImage.h"
44 #include "cxLegacySingletons.h"
45 #include "cxPatientModelService.h"
46 #include "cxLogicManager.h"
47 #include "cxViewService.h"
48 
49 namespace cx
50 {
51 
53  mInteractiveClipper(clipper)
54 {
55  connect(mInteractiveClipper.get(), SIGNAL(changed()), this, SIGNAL(changed()));
56 }
57 
59 {
60  return "Slice Plane";
61 }
62 bool StringPropertyClipPlane::setValue(const QString& value)
63 {
64  PLANE_TYPE plane = string2enum<PLANE_TYPE> (value);
65  if (plane == mInteractiveClipper->getSlicePlane())
66  return false;
67  mInteractiveClipper->setSlicePlane(plane);
68  return true;
69 }
71 {
72  return qstring_cast(mInteractiveClipper->getSlicePlane());
73 }
75 {
76  return "Chose the slice plane to clip with.";
77 }
79 {
80  std::vector<PLANE_TYPE> planes = mInteractiveClipper->getAvailableSlicePlanes();
81  QStringList retval;
82  //retval << ""; // removed this. No idea why we need an empty entry.
83  for (unsigned i = 0; i < planes.size(); ++i)
84  retval << qstring_cast(planes[i]);
85  return retval;
86 }
87 
91 
92 ClippingWidget::ClippingWidget(PatientModelServicePtr patientModelService, QWidget* parent) :
93  BaseWidget(parent, "ClippingWidget", "Clip"),
94  mPatientModelService(patientModelService)
95 {
96  mInteractiveClipper = viewService()->getClipper();
97  connect(mInteractiveClipper.get(), SIGNAL(changed()), this, SLOT(clipperChangedSlot()));
98 
99  mImageAdapter = StringPropertySelectImage::New(patientModelService);
100  LabeledComboBoxWidget* imageCombo = new LabeledComboBoxWidget(this, mImageAdapter);
101  connect(mImageAdapter.get(), SIGNAL(changed()), this, SLOT(imageChangedSlot()));
102 
103  this->setToolTip(this->defaultWhatsThis());
104 
105  QVBoxLayout* layout = new QVBoxLayout(this);
106 
107  QGroupBox* activeClipGroupBox = new QGroupBox("Interactive clipper");
108  activeClipGroupBox->setToolTip(this->defaultWhatsThis());
109  layout->addWidget(activeClipGroupBox);
110  QVBoxLayout* activeClipLayout = new QVBoxLayout(activeClipGroupBox);
111 
112  mPlaneAdapter = StringPropertyClipPlane::New(mInteractiveClipper);
113  LabeledComboBoxWidget* combo = new LabeledComboBoxWidget(this, mPlaneAdapter);
114 
115  mUseClipperCheckBox = new QCheckBox("Use Clipper");
116  mUseClipperCheckBox->setToolTip("Turn on interactive clipping for the selected volume.");
117  connect(mUseClipperCheckBox, SIGNAL(toggled(bool)), mInteractiveClipper.get(), SLOT(useClipper(bool)));
118  activeClipLayout->addWidget(mUseClipperCheckBox);
119  activeClipLayout->addWidget(imageCombo);
120  activeClipLayout->addWidget(combo);
121  mInvertPlaneCheckBox = new QCheckBox("Invert plane");
122  mInvertPlaneCheckBox->setToolTip("Use the inverse (mirror) of the selected slice plane.");
123  connect(mInvertPlaneCheckBox, SIGNAL(toggled(bool)), mInteractiveClipper.get(), SLOT(invertPlane(bool)));
124  activeClipLayout->addWidget(mInvertPlaneCheckBox);
125 
126  QPushButton* saveButton = new QPushButton("Save clip plane");
127  saveButton->setToolTip("Save the interactive plane as a clip plane in the selected volume.");
128  connect(saveButton, SIGNAL(clicked()), this, SLOT(saveButtonClickedSlot()));
129  //saveButton->setEnabled(false);
130  QPushButton* clearButton = new QPushButton("Clear saved planes");
131  clearButton->setToolTip("Remove all saved clip planes from the selected volume");
132  connect(clearButton, SIGNAL(clicked()), this, SLOT(clearButtonClickedSlot()));
133  //clearButton->setEnabled(false);
134  activeClipLayout->addWidget(saveButton);
135  layout->addWidget(clearButton);
136 
137  layout->addStretch();
138 
139  this->clipperChangedSlot();
140 }
141 
143 {
144  return "<html>"
145  "<h3>Functonality for clipping a volume</h3>"
146  "<p>"
147  "Define clip planes in a volume. The interactive clipper is attached "
148  "to the active tool, and clips the active volume according to a slice "
149  "definition. "
150  "</p>"
151  "<p>"
152  "The current clip can also be saved along with the volume. This can be "
153  "done several times."
154  "</p>"
155  "<p><i></i></p>"
156  "</html>";
157 }
158 
159 void ClippingWidget::clipperChangedSlot()
160 {
161  mUseClipperCheckBox->setChecked(mInteractiveClipper->getUseClipper());
162  mInvertPlaneCheckBox->setChecked(mInteractiveClipper->getInvertPlane());
163  if (mInteractiveClipper->getImage())
164  mImageAdapter->setValue(mInteractiveClipper->getImage()->getUid());
165 }
166 
167 void ClippingWidget::imageChangedSlot()
168 {
169  mInteractiveClipper->setImage(mPatientModelService->getData<Image>(mImageAdapter->getValue()));
170 }
171 
172 void ClippingWidget::clearButtonClickedSlot()
173 {
174  mInteractiveClipper->clearClipPlanesInVolume();
175 }
176 
177 void ClippingWidget::saveButtonClickedSlot()
178 {
179  mInteractiveClipper->saveClipPlaneToVolume();
180 }
181 
182 }
QString qstring_cast(const T &val)
virtual QString getValue() const
get the data value.
static StringPropertyBasePtr New(InteractiveClipperPtr clipper)
virtual QString getHelp() const
return a descriptive help string for the data, used for example as a tool tip.
virtual QString getDisplayName() const
name of data entity. Used for display to user.
virtual QStringList getValueRange() const
Composite widget for string selection.
boost::shared_ptr< class InteractiveClipper > InteractiveClipperPtr
InteractiveClipperPtr mInteractiveClipper
StringPropertyClipPlane(InteractiveClipperPtr clipper)
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
void changed()
emit when the underlying data value is changed: The user interface will be updated.
virtual QString defaultWhatsThis() const
Returns a short description of what this widget will do for you.
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:108
ClippingWidget(cx::PatientModelServicePtr patientModelService, QWidget *parent)
cxLogicManager_EXPORT ViewServicePtr viewService()
static StringPropertySelectImagePtr New(PatientModelServicePtr patientModelService)
virtual bool setValue(const QString &value)
set the data value.