VMTK
Loading...
Searching...
No Matches
vtkvmtkAnisotropicDiffusionImageFilter.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkAnisotropicDiffusionImageFilter.cxx,v $
5Language: C++
6Date: $Date: 2018/03/05 16:48:25 $
7Version: $Revision: 1.4 $
8
9 Copyright (c) Luca Antiga. All rights reserved.
10 See LICENSE file for details.
11
12 Portions of this code are covered under the VTK copyright.
13 See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm
14 for details.
15
16 Portions of this code are covered under the ITK copyright.
17 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm
18 for details.
19
20 This software is distributed WITHOUT ANY WARRANTY; without even
21 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
22 PURPOSE. See the above copyright notices for more information.
23 Note: this class was contributed by
24 Kurt Sansom
25 https://github.com/kayarre
26
27
28=========================================================================*/
29
31#include "vtkObjectFactory.h"
32#include "vtkType.h"
33
35
36#include "itkGradientAnisotropicDiffusionImageFilter.h"
37
39
41{
42 this->Conductance = 1.0;
43 this->TimeStep = 0.0625;
44 this->NumberOfIterations = 5;
45}
46
47
48template< class TImage >
49int vtkvmtkAnisotropicDiffusionImageFilter::FilterImage( vtkImageData* input,
50 vtkImageData* output,
51 typename TImage::Pointer image )
52{
53 using ImageType = TImage;
55
56 typedef itk::GradientAnisotropicDiffusionImageFilter< ImageType, ImageType > AnisotropicDiffusionFilterType;
57 typename AnisotropicDiffusionFilterType::Pointer anisotropicDiffusionFilter = AnisotropicDiffusionFilterType::New();
58
59 anisotropicDiffusionFilter->SetInput(image);
60 anisotropicDiffusionFilter->SetTimeStep(this->TimeStep);
61 anisotropicDiffusionFilter->SetNumberOfIterations(this->NumberOfIterations);
62 anisotropicDiffusionFilter->SetConductanceParameter(this->Conductance);
63
64 anisotropicDiffusionFilter->Update();
65 vtkvmtkITKFilterUtilities::ITKToVTKImage<ImageType>(anisotropicDiffusionFilter->GetOutput(),output);
66
67 return EXIT_SUCCESS;
68}
69
70
71template< int VDimension >
72int vtkvmtkAnisotropicDiffusionImageFilter::FilterScalarImage(vtkImageData* input,
73 vtkImageData* output,
74 int componentType )
75{
76 switch( componentType )
77 {
78 default:
79#if ITK_VERSION_MAJOR >= 5
80 // itkGradientAnisotropicDiffusionImageFilter only supports floating-point types
81 return EXIT_FAILURE;
82#else
83 case VTK_UNSIGNED_CHAR:
84 {
85 using PixelType = unsigned char;
86 using ImageType = itk::Image< PixelType, VDimension >;
87 typename ImageType::Pointer image = ImageType::New();
88 if( FilterImage< ImageType >( input, output, image ) == EXIT_FAILURE )
89 {
90 return EXIT_FAILURE;
91 }
92 break;
93 }
94
95 case VTK_CHAR:
96 {
97 using PixelType = char;
98 using ImageType = itk::Image< PixelType, VDimension >;
99 typename ImageType::Pointer image = ImageType::New();
100 if( FilterImage< ImageType >( input, output, image ) == EXIT_FAILURE )
101 {
102 return EXIT_FAILURE;
103 }
104 break;
105 }
106
107 case VTK_UNSIGNED_SHORT:
108 {
109 using PixelType = unsigned short;
110 using ImageType = itk::Image< PixelType, VDimension >;
111 typename ImageType::Pointer image = ImageType::New();
112 if( FilterImage< ImageType >( input, output, image ) == EXIT_FAILURE )
113 {
114 return EXIT_FAILURE;
115 }
116 break;
117 }
118
119 case VTK_SHORT:
120 {
121 using PixelType = short;
122 using ImageType = itk::Image< PixelType, VDimension >;
123 typename ImageType::Pointer image = ImageType::New();
124 if( FilterImage< ImageType >( input, output, image ) == EXIT_FAILURE )
125 {
126 return EXIT_FAILURE;
127 }
128 break;
129 }
130
131 case VTK_UNSIGNED_INT:
132 {
133 using PixelType = unsigned int;
134 using ImageType = itk::Image< PixelType, VDimension >;
135 typename ImageType::Pointer image = ImageType::New();
136 if( FilterImage< ImageType >( input, output, image ) == EXIT_FAILURE )
137 {
138 return EXIT_FAILURE;
139 }
140
141 break;
142 }
143
144 case VTK_INT:
145 {
146 using PixelType = int;
147 using ImageType = itk::Image< PixelType, VDimension >;
148 typename ImageType::Pointer image = ImageType::New();
149 if( FilterImage< ImageType >( input, output, image ) == EXIT_FAILURE )
150 {
151 return EXIT_FAILURE;
152 }
153 break;
154 }
155
156 case VTK_UNSIGNED_LONG:
157 {
158 using PixelType = unsigned long;
159 using ImageType = itk::Image< PixelType, VDimension >;
160 typename ImageType::Pointer image = ImageType::New();
161 if( FilterImage< ImageType >( input, output, image ) == EXIT_FAILURE )
162 {
163 return EXIT_FAILURE;
164 }
165
166 break;
167 }
168
169 case VTK_LONG:
170 {
171 using PixelType = long;
172 using ImageType = itk::Image< PixelType, VDimension >;
173 typename ImageType::Pointer image = ImageType::New();
174 if( FilterImage< ImageType >( input, output, image ) == EXIT_FAILURE )
175 {
176 return EXIT_FAILURE;
177 }
178 break;
179 }
180#endif
181 case VTK_FLOAT:
182 {
183 using PixelType = float;
184 using ImageType = itk::Image< PixelType, VDimension >;
185 typename ImageType::Pointer image = ImageType::New();
186 if( FilterImage< ImageType >( input, output, image ) == EXIT_FAILURE )
187 {
188 return EXIT_FAILURE;
189 }
190 break;
191 }
192
193 case VTK_DOUBLE:
194 {
195 using PixelType = double;
196 using ImageType = itk::Image< PixelType, VDimension >;
197 typename ImageType::Pointer image = ImageType::New();
198 if( FilterImage< ImageType >( input, output, image ) == EXIT_FAILURE )
199 {
200 return EXIT_FAILURE;
201 }
202 break;
203 }
204 }
205 return EXIT_SUCCESS;
206}
207
208
209
210void vtkvmtkAnisotropicDiffusionImageFilter::SimpleExecute(vtkImageData* input, vtkImageData* output)
211{
212 int imageDimension = input->GetDataDimension();
213 int componentType = input->GetScalarType();
214
215 if( imageDimension == 2 )
216 {
217 FilterScalarImage< 2 >( input, output, componentType );
218 }
219 else if( imageDimension == 3 )
220 {
221 FilterScalarImage< 3 >(input, output, componentType );
222 }
223
224}
225
Wraps itk::GradientAnisotropicDiffusionImageFilter.
virtual void SimpleExecute(vtkImageData *input, vtkImageData *output) override
static void ITKToVTKImage(typename TImage::Pointer input, vtkImageData *output)
static void VTKToITKImage(vtkImageData *input, typename TImage::Pointer output)
vtkStandardNewMacro(vtkvmtkAnisotropicDiffusionImageFilter)