CustusX  15.3.4-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxCroppingWidget.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 #include "cxCroppingWidget.h"
34 #include <QVBoxLayout>
35 #include <QPushButton>
36 #include <QCheckBox>
37 #include <QGroupBox>
38 #include <QLabel>
39 #include <vtkImageData.h>
40 #include "cxStringPropertyBase.h"
42 #include "cxDefinitionStrings.h"
43 #include "cxUtilHelpers.h"
44 
46 #include "cxImageAlgorithms.h"
47 #include "cxInteractiveCropper.h"
48 #include "cxImage.h"
49 #include "cxLogicManager.h"
50 #include "cxPatientModelService.h"
51 #include "cxViewService.h"
52 #include "cxInteractiveCropper.h"
53 
54 namespace cx
55 {
56 
57 CroppingWidget::CroppingWidget(QWidget* parent) :
58  BaseWidget(parent, "CroppingWidget", "Crop")
59 {
60  mInteractiveCropper = viewService()->getCropper();
61  connect(mInteractiveCropper.get(), SIGNAL(changed()), this, SLOT(cropperChangedSlot()));
62 
63  QVBoxLayout* layout = new QVBoxLayout(this);
64 
65  this->setToolTip(this->defaultWhatsThis());
66 
67  QGroupBox* activeGroupBox = new QGroupBox("Interactive cropper");
68  activeGroupBox->setToolTip(this->defaultWhatsThis());
69  layout->addWidget(activeGroupBox);
70  QVBoxLayout* activeLayout = new QVBoxLayout(activeGroupBox);
71 
72  mUseCropperCheckBox = new QCheckBox("Use Cropper");
73  mUseCropperCheckBox->setToolTip("Turn on cropping for the active volume.");
74  connect(mUseCropperCheckBox, SIGNAL(toggled(bool)), mInteractiveCropper.get(), SLOT(useCropping(bool)));
75  activeLayout->addWidget(mUseCropperCheckBox);
76 
77  mShowBoxCheckBox = new QCheckBox("Show box");
78  mShowBoxCheckBox->setToolTip("Show crop box in 3D view. This also turns on cropping for convenience.");
79  connect(mShowBoxCheckBox, SIGNAL(toggled(bool)), mInteractiveCropper.get(), SLOT(showBoxWidget(bool)));
80  activeLayout->addWidget(mShowBoxCheckBox);
81 
82  mBoundingBoxDimensions = new QLabel("?, ?, ?");
83  mBoundingBoxDimensions->setToolTip("The dimensions of the croppers boundingbox.");
84  activeLayout->addWidget(mBoundingBoxDimensions);
85 
86  mBBWidget = new BoundingBoxWidget(this);
87  layout->addWidget(mBBWidget);
88  connect(mBBWidget, SIGNAL(changed()), this, SLOT(boxValuesChanged()));
89 
90  QPushButton* cropClipButton = new QPushButton("Create new cropped volume");
91  cropClipButton->setToolTip("Create a new volume containing only the volume inside the crop box.");
92  connect(cropClipButton, SIGNAL(clicked()), this, SLOT(cropClipButtonClickedSlot()));
93  layout->addWidget(cropClipButton);
94 
95  layout->addStretch();
96 
97  this->cropperChangedSlot();
98 }
99 
101 {
102  return "<html>"
103  "<h3>Functionality for cropping a volume.</h3>"
104  "<p>"
105  "Lets you crop a volume by defining a bounding box along the volume "
106  "axis. Everything outside the box is not shown."
107  "</p>"
108  "<p>"
109  "<b>How to use the bounding box:</b>"
110  "<ul>"
111  "<li>First click the bounding box to get the control spheres</li>"
112  "<li>Click and drag a sphere to change the crop area</li>"
113  "</ul>"
114  "</p>"
115  "<p>"
116  "<b>Tip:</b> To make the crop permanent, press the button to create a new volume from the crop."
117  "</p>"
118  "<p><i></i></p>"
119  "</html>";
120 }
121 
122 void CroppingWidget::boxValuesChanged()
123 {
124  mInteractiveCropper->setBoundingBox(mBBWidget->getValue());
125 }
126 
127 void CroppingWidget::cropperChangedSlot()
128 {
129  std::vector<int> dims = mInteractiveCropper->getDimensions();
130  if(dims.size() < 3)
131  return;
132 
133  QString dimensionText = "Dimensions: "+qstring_cast(dims.at(0))+", "+qstring_cast(dims.at(1))+", "+qstring_cast(dims.at(2));
134  mBoundingBoxDimensions->setText(dimensionText);
135  mUseCropperCheckBox->setChecked(mInteractiveCropper->getUseCropping());
136  mShowBoxCheckBox->setChecked(mInteractiveCropper->getShowBoxWidget());
137 
138  mBBWidget->setValue(mInteractiveCropper->getBoundingBox(), mInteractiveCropper->getMaxBoundingBox());
139 }
140 
141 ImagePtr CroppingWidget::cropClipButtonClickedSlot()
142 {
143  ImagePtr image = patientService()->getActiveImage();
144 
145  ImagePtr retval = cropImage(patientService(), image);
146  patientService()->insertData(retval);
147  return retval;
148 }
149 
150 }
QString qstring_cast(const T &val)
vtkImageDataPtr cropImage(vtkImageDataPtr input, IntBoundingBox3D cropbox)
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:48
Widget displays/edits a BoundingBox3D.
virtual QString defaultWhatsThis() const
Returns a short description of what this widget will do for you.
CroppingWidget(QWidget *parent)
DoubleBoundingBox3D getValue() const
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:108
cxLogicManager_EXPORT ViewServicePtr viewService()
cxLogicManager_EXPORT PatientModelServicePtr patientService()
void setValue(const DoubleBoundingBox3D &value, const DoubleBoundingBox3D &range)