ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkInvertDisplacementFieldImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkInvertDisplacementFieldImageFilter_h
19 #define itkInvertDisplacementFieldImageFilter_h
20 
21 #include "itkImageToImageFilter.h"
24 #include <mutex>
25 
26 namespace itk
27 {
28 
40 template <typename TInputImage, typename TOutputImage = TInputImage>
41 class ITK_TEMPLATE_EXPORT InvertDisplacementFieldImageFilter
42  : public ImageToImageFilter<TInputImage, TOutputImage>
43 {
44 public:
45  ITK_DISALLOW_COPY_AND_ASSIGN(InvertDisplacementFieldImageFilter);
46 
51 
53  itkNewMacro( Self );
54 
56  static constexpr unsigned int ImageDimension = TInputImage::ImageDimension;
57 
58  using InputFieldType = TInputImage;
59  using OutputFieldType = TOutputImage;
60 
63 
65  using PixelType = typename OutputFieldType::PixelType;
66  using VectorType = typename OutputFieldType::PixelType;
70 
72  using SpacingType = typename OutputFieldType::SpacingType;
76 
78  using RealType = typename VectorType::ComponentType;
83 
85  itkGetModifiableObjectMacro( Interpolator, InterpolatorType );
86 
88  void SetDisplacementField( const InputFieldType *field )
89  {
90  itkDebugMacro( "setting deformation field to " << field );
91  if ( field != this->GetInput( 0 ) )
92  {
93  this->SetInput( 0, field );
94  this->Modified();
95  if( ! this->m_Interpolator.IsNull() )
96  {
97  this->m_Interpolator->SetInputImage( field );
98  }
99  }
100  }
102 
107  {
108  return this->GetInput( 0 );
109  }
110 
112  itkSetInputMacro( InverseFieldInitialEstimate, InverseDisplacementFieldType );
113  itkGetInputMacro( InverseFieldInitialEstimate, InverseDisplacementFieldType );
115 
116  /* Set the interpolator. */
117  virtual void SetInterpolator( InterpolatorType* interpolator );
118 
119  /* Set/Get the number of iterations */
120  itkSetMacro( MaximumNumberOfIterations, unsigned int );
121  itkGetConstMacro( MaximumNumberOfIterations, unsigned int );
122 
123  /* Set/Get the mean stopping criterion */
124  itkSetMacro( MeanErrorToleranceThreshold, RealType );
125  itkGetConstMacro( MeanErrorToleranceThreshold, RealType );
126 
127  /* Set/Get the max stopping criterion */
128  itkSetMacro( MaxErrorToleranceThreshold, RealType );
129  itkGetConstMacro( MaxErrorToleranceThreshold, RealType );
130 
131  /* Get the max norm */
132  itkGetConstMacro( MaxErrorNorm, RealType );
133 
134  /* Get the mean norm */
135  itkGetConstMacro( MeanErrorNorm, RealType );
136 
137 /* Should we force the boundary to have zero displacement? */
138  itkSetMacro( EnforceBoundaryCondition, bool );
139  itkGetMacro( EnforceBoundaryCondition, bool );
140 
141 protected:
142 
145 
147  ~InvertDisplacementFieldImageFilter() override = default;
148 
150  void PrintSelf( std::ostream& os, Indent indent ) const override;
151 
153  void GenerateData() override;
154 
156  void DynamicThreadedGenerateData( const RegionType & ) override;
157 
158 private:
161 
162  unsigned int m_MaximumNumberOfIterations{20};
163 
166 
167  // internal ivars necessary for multithreading basic operations
168 
169  typename DisplacementFieldType::Pointer m_ComposedField;
171 
176  bool m_DoThreadedEstimateInverse{false};
177  bool m_EnforceBoundaryCondition{true};
178  std::mutex m_Mutex;
179 
180 };
181 
182 } // end namespace itk
183 
184 #ifndef ITK_MANUAL_INSTANTIATION
185 #include "itkInvertDisplacementFieldImageFilter.hxx"
186 #endif
187 
188 #endif
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Base class for all process objects that output image data.
typename OutputFieldType::DirectionType DirectionType
typename OutputImageType::RegionType OutputImageRegionType
Base class for filters that take an image as input and produce an image as output.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Base class for all vector image interpolaters.
Iteratively estimate the inverse field of a displacement field.
Templated n-dimensional image class.
Definition: itkImage.h:75
Linearly interpolate a vector image at specified positions.