CustusX  15.4.0-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("Interactive volume cropping");
66 
67  QGroupBox* activeGroupBox = new QGroupBox("Interactive cropper");
68  activeGroupBox->setToolTip(this->toolTip());
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 
100 void CroppingWidget::boxValuesChanged()
101 {
102  mInteractiveCropper->setBoundingBox(mBBWidget->getValue());
103 }
104 
105 void CroppingWidget::cropperChangedSlot()
106 {
107  std::vector<int> dims = mInteractiveCropper->getDimensions();
108  if(dims.size() < 3)
109  return;
110 
111  QString dimensionText = "Dimensions: "+qstring_cast(dims.at(0))+", "+qstring_cast(dims.at(1))+", "+qstring_cast(dims.at(2));
112  mBoundingBoxDimensions->setText(dimensionText);
113  mUseCropperCheckBox->setChecked(mInteractiveCropper->getUseCropping());
114  mShowBoxCheckBox->setChecked(mInteractiveCropper->getShowBoxWidget());
115 
116  mBBWidget->setValue(mInteractiveCropper->getBoundingBox(), mInteractiveCropper->getMaxBoundingBox());
117 }
118 
119 ImagePtr CroppingWidget::cropClipButtonClickedSlot()
120 {
121  ImagePtr image = patientService()->getActiveImage();
122 
123  ImagePtr retval = cropImage(patientService(), image);
124  patientService()->insertData(retval);
125  return retval;
126 }
127 
128 }
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.
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)