Fraxinus  16.5.0-fx-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxSmoothingImageFilter.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 "cxSmoothingImageFilter.h"
34 
35 #include "cxAlgorithmHelpers.h"
36 #include <itkSmoothingRecursiveGaussianImageFilter.h>
38 
39 #include "cxUtilHelpers.h"
41 #include "cxStringProperty.h"
42 #include "cxDoubleProperty.h"
43 #include "cxBoolProperty.h"
44 #include "cxTypeConversions.h"
45 #include "cxImage.h"
46 
47 #include "cxPatientModelService.h"
48 #include "cxVolumeHelpers.h"
49 #include "cxVisServices.h"
50 
51 namespace cx
52 {
53 
55  FilterImpl(services)
56 {
57 }
58 
60 {
61  return "Smoothing";
62 }
63 
65 {
66  return "SmoothingImageFilter";
67 }
68 
70 {
71  return "<html>"
72  "<h3>Smoothing.</h3>"
73  "<p>Wrapper for a itk::SmoothingRecursiveGaussianImageFilter.</p>"
74  "<p>Computes the smoothing of an image by convolution with "
75  "the Gaussian kernels implemented as IIR filters."
76  "This filter is implemented using the recursive gaussian filters.</p>"
77  "</html>";
78 }
79 
81 {
82  return DoubleProperty::initialize("Smoothing sigma", "",
83  "Used for smoothing the segmented volume. Measured in units of image spacing.",
84  0.10, DoubleRange(0, 5, 0.01), 2, root);
85 }
86 
88 {
89  mOptionsAdapters.push_back(this->getSigma(mOptions));
90 }
91 
93 {
95 
96  temp = StringPropertySelectImage::New(mServices->patient());
97  temp->setValueName("Input");
98  temp->setHelp("Select image input for smoothing");
99  mInputTypes.push_back(temp);
100 }
101 
103 {
105 
106  temp = StringPropertySelectData::New(mServices->patient());
107  temp->setValueName("Output");
108  temp->setHelp("Output smoothed image");
109  mOutputTypes.push_back(temp);
110 }
111 
113 {
114  ImagePtr input = this->getCopiedInputImage();
115  if (!input)
116  return false;
117 
119 
120  itkImageType::ConstPointer itkImage = AlgorithmHelper::getITKfromSSCImage(input);
121 
122  typedef itk::SmoothingRecursiveGaussianImageFilter<itkImageType, itkImageType> smoothingFilterType;
123  smoothingFilterType::Pointer smoohingFilter = smoothingFilterType::New();
124  smoohingFilter->SetSigma(sigma->getValue());
125  smoohingFilter->SetInput(itkImage);
126  smoohingFilter->Update();
127  itkImage = smoohingFilter->GetOutput();
128 
129  //Convert ITK to VTK
130  itkToVtkFilterType::Pointer itkToVtkFilter = itkToVtkFilterType::New();
131  itkToVtkFilter->SetInput(itkImage);
132  itkToVtkFilter->Update();
133 
134  vtkImageDataPtr rawResult = vtkImageDataPtr::New();
135  rawResult->DeepCopy(itkToVtkFilter->GetOutput());
136  // TODO: possible memory problem here - check debug mem system of itk/vtk
137 
138  mRawResult = rawResult;
139  return true;
140 }
141 
143 {
144  if (!mRawResult)
145  return false;
146 
147  ImagePtr input = this->getCopiedInputImage();
148 
149  if (!input)
150  return false;
151 
152  QString uid = input->getUid() + "_sm%1";
153  QString name = input->getName()+" sm%1";
154  ImagePtr output = createDerivedImage(mServices->patient(),
155  uid, name,
156  mRawResult, input);
157 
158  mRawResult = NULL;
159  if (!output)
160  return false;
161 
162  mServices->patient()->insertData(output);
163 
164  // set output
165  mOutputTypes.front()->setValue(output->getUid());
166 
167  return true;
168 }
169 
170 
171 } // namespace cx
172 
SmoothingImageFilter(VisServicesPtr services)
std::vector< SelectDataStringPropertyBasePtr > mInputTypes
Definition: cxFilterImpl.h:94
QDomElement mCopiedOptions
Definition: cxFilterImpl.h:101
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:62
static StringPropertySelectDataPtr New(PatientModelServicePtr patientModelService, QString typeRegexp=".*")
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:53
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:48
DoublePropertyPtr getSigma(QDomElement root)
virtual QString getHelp() const
std::vector< PropertyPtr > mOptionsAdapters
Definition: cxFilterImpl.h:96
virtual QString getName() const
VisServicesPtr mServices
Definition: cxFilterImpl.h:103
ImagePtr createDerivedImage(PatientModelServicePtr dataManager, QString uid, QString name, vtkImageDataPtr raw, ImagePtr parent)
boost::shared_ptr< class SelectDataStringPropertyBase > SelectDataStringPropertyBasePtr
ImagePtr getCopiedInputImage(int index=0)
QDomElement mOptions
Definition: cxFilterImpl.h:97
boost::shared_ptr< class DoubleProperty > DoublePropertyPtr
std::vector< SelectDataStringPropertyBasePtr > mOutputTypes
Definition: cxFilterImpl.h:95
virtual QString getType() const
static DoublePropertyPtr initialize(const QString &uid, QString name, QString help, double value, DoubleRange range, int decimals, QDomNode root=QDomNode())
static itkImageType::ConstPointer getITKfromSSCImage(ImagePtr image)
static StringPropertySelectImagePtr New(PatientModelServicePtr patientModelService)
vtkSmartPointer< class vtkImageData > vtkImageDataPtr