NorMIT-nav  18.04
An IGT application
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) 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 
12 #include "cxSmoothingImageFilter.h"
13 
14 #include "cxAlgorithmHelpers.h"
15 #include <itkSmoothingRecursiveGaussianImageFilter.h>
17 
18 #include "cxUtilHelpers.h"
20 #include "cxStringProperty.h"
21 #include "cxDoubleProperty.h"
22 #include "cxBoolProperty.h"
23 #include "cxTypeConversions.h"
24 #include "cxImage.h"
25 
26 #include "cxPatientModelService.h"
27 #include "cxVolumeHelpers.h"
28 #include "cxVisServices.h"
29 
30 namespace cx
31 {
32 
34  FilterImpl(services)
35 {
36 }
37 
39 {
40  return "Smoothing";
41 }
42 
44 {
45  return "smoothing_image_filter";
46 }
47 
49 {
50  return "<html>"
51  "<h3>Smoothing.</h3>"
52  "<p>Wrapper for a itk::SmoothingRecursiveGaussianImageFilter.</p>"
53  "<p>Computes the smoothing of an image by convolution with "
54  "the Gaussian kernels implemented as IIR filters."
55  "This filter is implemented using the recursive gaussian filters.</p>"
56  "</html>";
57 }
58 
60 {
61  return DoubleProperty::initialize("Smoothing sigma", "",
62  "Used for smoothing the segmented volume. Measured in units of image spacing.",
63  0.10, DoubleRange(0, 5, 0.01), 2, root);
64 }
65 
67 {
68  mOptionsAdapters.push_back(this->getSigma(mOptions));
69 }
70 
72 {
74 
75  temp = StringPropertySelectImage::New(mServices->patient());
76  temp->setValueName("Input");
77  temp->setHelp("Select image input for smoothing");
78  mInputTypes.push_back(temp);
79 }
80 
82 {
84 
85  temp = StringPropertySelectData::New(mServices->patient());
86  temp->setValueName("Output");
87  temp->setHelp("Output smoothed image");
88  mOutputTypes.push_back(temp);
89 }
90 
92 {
93  ImagePtr input = this->getCopiedInputImage();
94  if (!input)
95  return false;
96 
98 
99  itkImageType::ConstPointer itkImage = AlgorithmHelper::getITKfromSSCImage(input);
100 
101  typedef itk::SmoothingRecursiveGaussianImageFilter<itkImageType, itkImageType> smoothingFilterType;
102  smoothingFilterType::Pointer smoohingFilter = smoothingFilterType::New();
103  smoohingFilter->SetSigma(sigma->getValue());
104  smoohingFilter->SetInput(itkImage);
105  smoohingFilter->Update();
106  itkImage = smoohingFilter->GetOutput();
107 
108  //Convert ITK to VTK
109  itkToVtkFilterType::Pointer itkToVtkFilter = itkToVtkFilterType::New();
110  itkToVtkFilter->SetInput(itkImage);
111  itkToVtkFilter->Update();
112 
113  vtkImageDataPtr rawResult = vtkImageDataPtr::New();
114  rawResult->DeepCopy(itkToVtkFilter->GetOutput());
115  // TODO: possible memory problem here - check debug mem system of itk/vtk
116 
117  mRawResult = rawResult;
118  return true;
119 }
120 
122 {
123  if (!mRawResult)
124  return false;
125 
126  ImagePtr input = this->getCopiedInputImage();
127 
128  if (!input)
129  return false;
130 
131  QString uid = input->getUid() + "_sm%1";
132  QString name = input->getName()+" sm%1";
133  ImagePtr output = createDerivedImage(mServices->patient(),
134  uid, name,
135  mRawResult, input);
136 
137  mRawResult = NULL;
138  if (!output)
139  return false;
140 
141  mServices->patient()->insertData(output);
142 
143  // set output
144  mOutputTypes.front()->setValue(output->getUid());
145 
146  return true;
147 }
148 
149 
150 } // namespace cx
151 
SmoothingImageFilter(VisServicesPtr services)
std::vector< SelectDataStringPropertyBasePtr > mInputTypes
Definition: cxFilterImpl.h:73
QDomElement mCopiedOptions
Definition: cxFilterImpl.h:80
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
static StringPropertySelectDataPtr New(PatientModelServicePtr patientModelService, QString typeRegexp=".*")
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:32
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
DoublePropertyPtr getSigma(QDomElement root)
virtual QString getHelp() const
std::vector< PropertyPtr > mOptionsAdapters
Definition: cxFilterImpl.h:75
virtual QString getName() const
VisServicesPtr mServices
Definition: cxFilterImpl.h:82
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:76
boost::shared_ptr< class DoubleProperty > DoublePropertyPtr
std::vector< SelectDataStringPropertyBasePtr > mOutputTypes
Definition: cxFilterImpl.h:74
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
Namespace for all CustusX production code.