NorMIT-nav  16.5
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 "cxInteractiveClipper.h"
42 #include "cxImage.h"
43 #include "cxPatientModelService.h"
44 #include "cxViewService.h"
45 #include "cxVisServices.h"
46 #include "cxStringProperty.h"
47 #include "cxLogger.h"
48 #include "cxHelperWidgets.h"
50 
51 namespace cx
52 {
53 
54 ClippingWidget::ClippingWidget(VisServicesPtr services, QWidget* parent) :
55  BaseWidget(parent, "ClippingWidget", "Clip"),
56  mServices(services)
57 {
58  connect(mServices->view().get(), &ViewService::activeLayoutChanged, this, &ClippingWidget::setupUI);
59  this->setupUI();
60 }
61 
62 void ClippingWidget::setupUI()
63 {
64  if (mInteractiveClipper)
65  return;
66 
67  mInteractiveClipper.reset(new InteractiveClipper(mServices));
68 
69  if (!mInteractiveClipper)
70  return;
71 
72  connect(mInteractiveClipper.get(), SIGNAL(changed()), this, SLOT(clipperChangedSlot()));
73 
74  mDataAdapter = StringPropertySelectData::New(mServices->patient());
75  LabeledComboBoxWidget* imageCombo = new LabeledComboBoxWidget(this, mDataAdapter);
76  connect(mDataAdapter.get(), SIGNAL(changed()), this, SLOT(imageChangedSlot()));
77 
78  this->setToolTip("Interactive volume clipping");
79 
80  QVBoxLayout* layout = new QVBoxLayout(this);
81 
82  QGroupBox* activeClipGroupBox = new QGroupBox("Interactive clipper");
83  activeClipGroupBox->setToolTip(this->toolTip());
84  layout->addWidget(activeClipGroupBox);
85  QVBoxLayout* activeClipLayout = new QVBoxLayout(activeClipGroupBox);
86 
87  mPlaneAdapter = StringPropertyClipPlane::New(mInteractiveClipper);
88  LabeledComboBoxWidget* combo = new LabeledComboBoxWidget(this, mPlaneAdapter);
89 
90  mUseClipperCheckBox = new QCheckBox("Use Clipper");
91  mUseClipperCheckBox->setToolTip("Turn on interactive clipping for the selected volume.");
92  connect(mUseClipperCheckBox, SIGNAL(toggled(bool)), mInteractiveClipper.get(), SLOT(useClipper(bool)));
93  activeClipLayout->addWidget(mUseClipperCheckBox);
94  activeClipLayout->addWidget(imageCombo);
95  activeClipLayout->addWidget(combo);
96  mInvertPlaneCheckBox = new QCheckBox("Invert plane");
97  mInvertPlaneCheckBox->setToolTip("Use the inverse (mirror) of the selected slice plane.");
98  connect(mInvertPlaneCheckBox, SIGNAL(toggled(bool)), mInteractiveClipper.get(), SLOT(invertPlane(bool)));
99  activeClipLayout->addWidget(mInvertPlaneCheckBox);
100 
101  QPushButton* saveButton = new QPushButton("Save clip plane");
102  saveButton->setToolTip("Save the interactive plane as a clip plane in the selected volume.");
103  connect(saveButton, SIGNAL(clicked()), this, SLOT(saveButtonClickedSlot()));
104  //saveButton->setEnabled(false);
105  QPushButton* clearButton = new QPushButton("Clear saved planes");
106  clearButton->setToolTip("Remove all saved clip planes from the selected volume");
107  connect(clearButton, SIGNAL(clicked()), this, SLOT(clearButtonClickedSlot()));
108  //clearButton->setEnabled(false);
109  activeClipLayout->addWidget(saveButton);
110  layout->addWidget(clearButton);
111 
112  layout->addStretch();
113 
114  this->clipperChangedSlot();
115 }
116 
117 void ClippingWidget::clipperChangedSlot()
118 {
119  mUseClipperCheckBox->setChecked(mInteractiveClipper->getUseClipper());
120  mInvertPlaneCheckBox->setChecked(mInteractiveClipper->getInvertPlane());
121  if (mInteractiveClipper->getData())
122  mDataAdapter->setValue(mInteractiveClipper->getData()->getUid());
123 }
124 
125 void ClippingWidget::imageChangedSlot()
126 {
127  mInteractiveClipper->setData(mServices->patient()->getData(mDataAdapter->getValue()));
128 }
129 
130 void ClippingWidget::clearButtonClickedSlot()
131 {
132  mInteractiveClipper->clearClipPlanesInVolume();
133 }
134 
135 void ClippingWidget::saveButtonClickedSlot()
136 {
137  mInteractiveClipper->saveClipPlaneToVolume();
138 }
139 
140 }
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:62
static StringPropertySelectDataPtr New(PatientModelServicePtr patientModelService, QString typeRegexp=".*")
Composite widget for string selection.
void activeLayoutChanged()
emitted when the active layout changes
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:108
ClippingWidget(VisServicesPtr services, QWidget *parent)
static StringPropertyClipPlanePtr New(InteractiveClipperPtr clipper)