|
| 1 | +/*========================================================================= |
| 2 | + * |
| 3 | + * Copyright NumFOCUS |
| 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 | + * https://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 itkFixedPointInverseDisplacementFieldImageFilter_h |
| 19 | +#define itkFixedPointInverseDisplacementFieldImageFilter_h |
| 20 | + |
| 21 | + |
| 22 | +#include "itkImageToImageFilter.h" |
| 23 | + |
| 24 | +#include "itkWarpVectorImageFilter.h" |
| 25 | +#include "itkVectorLinearInterpolateImageFunction.h" |
| 26 | +#include "itkImageRegionIterator.h" |
| 27 | +#include "itkTimeProbe.h" |
| 28 | + |
| 29 | +namespace itk |
| 30 | +{ |
| 31 | + |
| 32 | +/** \class FixedPointInverseDisplacementFieldImageFilter |
| 33 | + * |
| 34 | + * \brief Computes the inverse of a Displacement field using a fixed point iteration scheme. |
| 35 | + * |
| 36 | + * FixedPointInverseDisplacementFieldImageFilter takes a Displacement field as input and |
| 37 | + * computes the Displacement field that is its inverse. If the input Displacement |
| 38 | + * field was mapping coordinates from a space A into a space B, the output of |
| 39 | + * this filter will map coordinates from the space B into the space A. |
| 40 | + * |
| 41 | + * To compute the inverse of the given Displacement field, the fixed point algorithm by |
| 42 | + * Mingli Chen, Weiguo Lu, Quan Chen, Knneth J. Ruchala and Gusavo H. Olivera |
| 43 | + * described in the paper |
| 44 | + * |
| 45 | +\verbatim |
| 46 | +"A simple fixed-point approach to invert a Displacement field", |
| 47 | +Medical Physics, vol. 35, issue 1, p. 81 |
| 48 | +\endverbatim |
| 49 | + * is applied. |
| 50 | + * |
| 51 | + * \author Marcel Lüthi, Computer Science Department, University of Basel |
| 52 | + * |
| 53 | + * \ingroup ImageToImageFilter |
| 54 | + * \ingroup FixedPointInverseDisplacementField |
| 55 | + */ |
| 56 | + |
| 57 | +template <typename TInputImage, typename TOutputImage> |
| 58 | +class ITK_TEMPLATE_EXPORT FixedPointInverseDisplacementFieldImageFilter |
| 59 | + : public ImageToImageFilter<TInputImage, TOutputImage> |
| 60 | +{ |
| 61 | +public: |
| 62 | + ITK_DISALLOW_COPY_AND_MOVE(FixedPointInverseDisplacementFieldImageFilter); |
| 63 | + |
| 64 | + /** Standard class type alias. */ |
| 65 | + using Self = FixedPointInverseDisplacementFieldImageFilter; |
| 66 | + using Superclass = ImageToImageFilter<TInputImage, TOutputImage>; |
| 67 | + using Pointer = SmartPointer<Self>; |
| 68 | + using ConstPointer = SmartPointer<const Self>; |
| 69 | + |
| 70 | + /** Method for creation through the object factory. */ |
| 71 | + itkNewMacro(Self); |
| 72 | + |
| 73 | + /** Run-time type information (and related methods). */ |
| 74 | + itkTypeMacro(FixedPointInverseDisplacementFieldImageFilter, ImageToImageFilter); |
| 75 | + |
| 76 | + |
| 77 | + /** Some type alias. */ |
| 78 | + using InputImageType = TInputImage; |
| 79 | + using InputImageConstPointer = typename InputImageType::ConstPointer; |
| 80 | + using InputImagePointer = typename InputImageType::Pointer; |
| 81 | + using InputImagePointType = typename InputImageType::PointType; |
| 82 | + using InputImageRegionType = typename InputImageType::RegionType; |
| 83 | + using InputImageSpacingType = typename InputImageType::SpacingType; |
| 84 | + using InputImageIndexType = typename InputImageType::IndexType; |
| 85 | + |
| 86 | + |
| 87 | + using OutputImageType = TOutputImage; |
| 88 | + using OutputImagePointer = typename OutputImageType::Pointer; |
| 89 | + using OutputImagePixelType = typename OutputImageType::PixelType; |
| 90 | + using OutputImagePointType = typename OutputImageType::PointType; |
| 91 | + using OutputImageIndexType = typename OutputImageType::IndexType; |
| 92 | + using OutputImageValueType = typename OutputImagePixelType::ValueType; |
| 93 | + using OutputImageSizeType = typename OutputImageType::SizeType; |
| 94 | + using OutputImageSpacingType = typename OutputImageType::SpacingType; |
| 95 | + using OutputImageOriginPointType = typename TOutputImage::PointType; |
| 96 | + using TimeType = TimeProbe; |
| 97 | + |
| 98 | + |
| 99 | + /** Number of dimensions. */ |
| 100 | + static constexpr unsigned int ImageDimension = TOutputImage::ImageDimension; |
| 101 | + |
| 102 | + using InputConstIterator = ImageRegionConstIterator<InputImageType>; |
| 103 | + using InputIterator = ImageRegionIterator<InputImageType>; |
| 104 | + using OutputConstIterator = ImageRegionConstIterator<OutputImageType>; |
| 105 | + using OutputIterator = ImageRegionIterator<OutputImageType>; |
| 106 | + |
| 107 | + using VectorWarperType = WarpVectorImageFilter<TOutputImage, TInputImage, TOutputImage>; |
| 108 | + using InterpolatorVectorType = typename NumericTraits<typename TOutputImage::PixelType>::RealType; |
| 109 | + using OutputVectorType = typename TOutputImage::PixelType; |
| 110 | + using FieldInterpolatorType = VectorLinearInterpolateImageFunction<TInputImage, double>; |
| 111 | + using FieldInterpolatorPointer = typename FieldInterpolatorType::Pointer; |
| 112 | + using FieldInterpolatorOutputType = typename FieldInterpolatorType::OutputType; |
| 113 | + |
| 114 | + |
| 115 | + itkSetMacro(NumberOfIterations, unsigned int); |
| 116 | + itkGetConstMacro(NumberOfIterations, unsigned int); |
| 117 | + |
| 118 | + |
| 119 | + /** Set the size of the output image. */ |
| 120 | + itkSetMacro(Size, OutputImageSizeType); |
| 121 | + /** Get the size of the output image. */ |
| 122 | + itkGetConstReferenceMacro(Size, OutputImageSizeType); |
| 123 | + |
| 124 | + /** Set the output image spacing. */ |
| 125 | + itkSetMacro(OutputSpacing, OutputImageSpacingType); |
| 126 | + virtual void |
| 127 | + SetOutputSpacing(const double * values); |
| 128 | + |
| 129 | + /** Get the output image spacing. */ |
| 130 | + itkGetConstReferenceMacro(OutputSpacing, OutputImageSpacingType); |
| 131 | + |
| 132 | + /** Set the output image origin. */ |
| 133 | + itkSetMacro(OutputOrigin, OutputImageOriginPointType); |
| 134 | + virtual void |
| 135 | + SetOutputOrigin(const double * values); |
| 136 | + |
| 137 | +#ifdef ITK_USE_CONCEPT_CHECKING |
| 138 | + /** Begin concept checking */ |
| 139 | + itkConceptMacro(OutputHasNumericTraitsCheck, (Concept::HasNumericTraits<OutputImageValueType>)); |
| 140 | + itkConceptMacro(SameDimensionCheck, |
| 141 | + (Concept::SameDimension<TInputImage::ImageDimension, TOutputImage::ImageDimension>)); |
| 142 | + |
| 143 | + /** End concept checking */ |
| 144 | +#endif |
| 145 | + |
| 146 | +protected: |
| 147 | + FixedPointInverseDisplacementFieldImageFilter(); |
| 148 | + ~FixedPointInverseDisplacementFieldImageFilter() override = default; |
| 149 | + |
| 150 | + void |
| 151 | + PrintSelf(std::ostream & os, Indent indent) const override; |
| 152 | + |
| 153 | + void |
| 154 | + GenerateData() override; |
| 155 | + void |
| 156 | + GenerateOutputInformation() override; |
| 157 | + |
| 158 | + void |
| 159 | + GenerateInputRequestedRegion() override; |
| 160 | + |
| 161 | + unsigned int m_NumberOfIterations{ 5 }; |
| 162 | + |
| 163 | + |
| 164 | +private: |
| 165 | + OutputImageSizeType m_Size; // Size of the output image |
| 166 | + OutputImageSpacingType m_OutputSpacing; // output image spacing |
| 167 | + OutputImageOriginPointType m_OutputOrigin; // output image origin |
| 168 | +}; |
| 169 | + |
| 170 | +} // end namespace itk |
| 171 | + |
| 172 | +#ifndef ITK_MANUAL_INSTANTIATION |
| 173 | +# include "itkFixedPointInverseDisplacementFieldImageFilter.hxx" |
| 174 | +#endif |
| 175 | +#endif |
0 commit comments