CustusX  22.04-rc2
An IGT application
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) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 #include "cxClippingWidget.h"
12 
13 #include <QVBoxLayout>
14 #include <QPushButton>
15 #include <QCheckBox>
16 #include <QGroupBox>
17 #include "cxStringPropertyBase.h"
19 #include "cxInteractiveClipper.h"
21 #include "cxImage.h"
22 #include "cxPatientModelService.h"
23 #include "cxViewService.h"
24 #include "cxVisServices.h"
25 #include "cxStringProperty.h"
26 #include "cxLogger.h"
27 #include "cxHelperWidgets.h"
29 
30 namespace cx
31 {
32 
33 ClippingWidget::ClippingWidget(VisServicesPtr services, QWidget* parent) :
34  BaseWidget(parent, "clipping_widget", "Clip"),
35  mServices(services)
36 {
37  connect(mServices->view().get(), &ViewService::activeLayoutChanged, this, &ClippingWidget::setupUI);
38  this->setupUI();
39 }
40 
41 void ClippingWidget::setupUI()
42 {
43  if (mInteractiveClipper)
44  return;
45 
46  mInteractiveClipper.reset(new InteractiveClipper(mServices));
47 
48  if (!mInteractiveClipper)
49  return;
50 
51  connect(mInteractiveClipper.get(), SIGNAL(changed()), this, SLOT(clipperChangedSlot()));
52 
53  mDataAdapter = StringPropertySelectData::New(mServices->patient());
54  LabeledComboBoxWidget* imageCombo = new LabeledComboBoxWidget(this, mDataAdapter);
55  connect(mDataAdapter.get(), SIGNAL(changed()), this, SLOT(imageChangedSlot()));
56 
57  this->setToolTip("Interactive volume clipping");
58 
59  QVBoxLayout* layout = new QVBoxLayout(this);
60 
61  QGroupBox* activeClipGroupBox = new QGroupBox("Interactive clipper");
62  activeClipGroupBox->setToolTip(this->toolTip());
63  layout->addWidget(activeClipGroupBox);
64  QVBoxLayout* activeClipLayout = new QVBoxLayout(activeClipGroupBox);
65 
66  mPlaneAdapter = StringPropertyClipPlane::New(mInteractiveClipper);
67  LabeledComboBoxWidget* combo = new LabeledComboBoxWidget(this, mPlaneAdapter);
68 
69  mUseClipperCheckBox = new QCheckBox("Use Clipper");
70  mUseClipperCheckBox->setToolTip("Turn on interactive clipping for the selected volume.");
71  connect(mUseClipperCheckBox, SIGNAL(toggled(bool)), mInteractiveClipper.get(), SLOT(useClipper(bool)));
72  activeClipLayout->addWidget(mUseClipperCheckBox);
73  activeClipLayout->addWidget(imageCombo);
74  activeClipLayout->addWidget(combo);
75  mInvertPlaneCheckBox = new QCheckBox("Invert plane");
76  mInvertPlaneCheckBox->setToolTip("Use the inverse (mirror) of the selected slice plane.");
77  connect(mInvertPlaneCheckBox, SIGNAL(toggled(bool)), mInteractiveClipper.get(), SLOT(invertPlane(bool)));
78  activeClipLayout->addWidget(mInvertPlaneCheckBox);
79 
80  QPushButton* saveButton = new QPushButton("Save clip plane");
81  saveButton->setToolTip("Save the interactive plane as a clip plane in the selected volume.");
82  connect(saveButton, SIGNAL(clicked()), this, SLOT(saveButtonClickedSlot()));
83  //saveButton->setEnabled(false);
84  QPushButton* clearButton = new QPushButton("Clear saved planes");
85  clearButton->setToolTip("Remove all saved clip planes from the selected volume");
86  connect(clearButton, SIGNAL(clicked()), this, SLOT(clearButtonClickedSlot()));
87  //clearButton->setEnabled(false);
88  activeClipLayout->addWidget(saveButton);
89  layout->addWidget(clearButton);
90 
91  layout->addStretch();
92 
93  this->clipperChangedSlot();
94 }
95 
96 void ClippingWidget::clipperChangedSlot()
97 {
98  mUseClipperCheckBox->setChecked(mInteractiveClipper->getUseClipper());
99  mInvertPlaneCheckBox->setChecked(mInteractiveClipper->getInvertPlane());
100  if (mInteractiveClipper->getData())
101  mDataAdapter->setValue(mInteractiveClipper->getData()->getUid());
102 }
103 
104 void ClippingWidget::imageChangedSlot()
105 {
106  mInteractiveClipper->setData(mServices->patient()->getData(mDataAdapter->getValue()));
107 }
108 
109 void ClippingWidget::clearButtonClickedSlot()
110 {
111  mInteractiveClipper->clearClipPlanesInVolume();
112 }
113 
114 void ClippingWidget::saveButtonClickedSlot()
115 {
116  mInteractiveClipper->saveClipPlaneToVolume();
117 }
118 
119 }
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
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:88
ClippingWidget(VisServicesPtr services, QWidget *parent)
static StringPropertyClipPlanePtr New(InteractiveClipperPtr clipper)
Namespace for all CustusX production code.