NorMIT-nav  2023.01.05-dev+develop.0da12
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 
cx::FilterImpl
Definition: cxFilterImpl.h:36
cxVolumeHelpers.h
cxAlgorithmHelpers.h
cx::StringPropertySelectData::New
static StringPropertySelectDataPtr New(PatientModelServicePtr patientModelService, QString typeRegexp=".*")
Definition: cxSelectDataStringProperty.h:101
cx::SmoothingImageFilter::createInputTypes
virtual void createInputTypes()
Definition: cxSmoothingImageFilter.cpp:71
cx::AlgorithmHelper::getITKfromSSCImage
static itkImageType::ConstPointer getITKfromSSCImage(ImagePtr image)
Definition: cxAlgorithmHelpers.cpp:35
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::SmoothingImageFilter::createOutputTypes
virtual void createOutputTypes()
Definition: cxSmoothingImageFilter.cpp:81
cxImage.h
cx::VisServicesPtr
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
cx::SmoothingImageFilter::createOptions
virtual void createOptions()
Definition: cxSmoothingImageFilter.cpp:66
vtkImageDataPtr
vtkSmartPointer< class vtkImageData > vtkImageDataPtr
Definition: cxVideoConnectionWidget.h:30
cx::SmoothingImageFilter::getHelp
virtual QString getHelp() const
Definition: cxSmoothingImageFilter.cpp:48
cxDoubleProperty.h
cxUtilHelpers.h
cx::FilterImpl::mOutputTypes
std::vector< SelectDataStringPropertyBasePtr > mOutputTypes
Definition: cxFilterImpl.h:74
cx::FilterImpl::mInputTypes
std::vector< SelectDataStringPropertyBasePtr > mInputTypes
Definition: cxFilterImpl.h:73
cx::FilterImpl::mOptions
QDomElement mOptions
Definition: cxFilterImpl.h:76
cx::FilterImpl::mCopiedOptions
QDomElement mCopiedOptions
Definition: cxFilterImpl.h:80
cx::FilterImpl::getCopiedInputImage
ImagePtr getCopiedInputImage(int index=0)
Definition: cxFilterImpl.cpp:104
cx::DoubleProperty::initialize
static DoublePropertyPtr initialize(const QString &uid, QString name, QString help, double value, DoubleRange range, int decimals, QDomNode root=QDomNode())
Definition: cxDoubleProperty.cpp:30
cx::DoublePropertyPtr
boost::shared_ptr< class DoubleProperty > DoublePropertyPtr
Definition: cxReconstructionMethodService.h:33
cx::SmoothingImageFilter::SmoothingImageFilter
SmoothingImageFilter(VisServicesPtr services)
Definition: cxSmoothingImageFilter.cpp:33
cx::StringPropertySelectImage::New
static StringPropertySelectImagePtr New(PatientModelServicePtr patientModelService)
Definition: cxSelectDataStringProperty.h:76
cx::SmoothingImageFilter::getType
virtual QString getType() const
Definition: cxSmoothingImageFilter.cpp:43
cxTypeConversions.h
cxPatientModelService.h
cxSmoothingImageFilter.h
cx::SmoothingImageFilter::postProcess
virtual bool postProcess()
Definition: cxSmoothingImageFilter.cpp:121
cx::ImagePtr
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
cxRegistrationTransform.h
cx::createDerivedImage
ImagePtr createDerivedImage(PatientModelServicePtr dataManager, QString uid, QString name, vtkImageDataPtr raw, ImagePtr parent)
Definition: cxVolumeHelpers.cpp:151
itk::ImageToVTKImageFilter::Pointer
SmartPointer< Self > Pointer
Definition: itkImageToVTKImageFilter.h:47
cxStringProperty.h
cxSelectDataStringProperty.h
cx::DoubleRange
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:32
cx::SmoothingImageFilter::getName
virtual QString getName() const
Definition: cxSmoothingImageFilter.cpp:38
cxBoolProperty.h
cx::FilterImpl::mOptionsAdapters
std::vector< PropertyPtr > mOptionsAdapters
Definition: cxFilterImpl.h:75
cx::SmoothingImageFilter::getSigma
DoublePropertyPtr getSigma(QDomElement root)
Definition: cxSmoothingImageFilter.cpp:59
cx::SelectDataStringPropertyBasePtr
boost::shared_ptr< class SelectDataStringPropertyBase > SelectDataStringPropertyBasePtr
Definition: cxMeshGlyphsWidget.h:26
cx::SmoothingImageFilter::execute
virtual bool execute()
Definition: cxSmoothingImageFilter.cpp:91
cx::FilterImpl::mServices
VisServicesPtr mServices
Definition: cxFilterImpl.h:82
cxVisServices.h