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 itkBSplineInterpolationWeightFunction_h 19 #define itkBSplineInterpolationWeightFunction_h 20 21 #include "itkFunctionBase.h" 22 #include "itkContinuousIndex.h" 23 #include "itkBSplineKernelFunction.h" 24 #include "itkArray.h" 25 #include "itkArray2D.h" 26 27 namespace itk 28 { 29 /** \class BSplineInterpolationWeightFunction 30 * \brief Returns the weights over the support region used for B-spline 31 * interpolation/reconstruction. 32 * 33 * Computes/evaluate the B-spline interpolation weights over the 34 * support region of the B-spline. 35 * 36 * This class is templated over the coordinate representation type, 37 * the space dimension and the spline order. 38 * 39 * \sa Point 40 * \sa Index 41 * \sa ContinuousIndex 42 * 43 * \ingroup Functions ImageInterpolators 44 * \ingroup ITKCommon 45 */ 46 template< 47 typename TCoordRep = float, 48 unsigned int VSpaceDimension = 2, 49 unsigned int VSplineOrder = 3 50 > 51 class ITK_TEMPLATE_EXPORT BSplineInterpolationWeightFunction: 52 public FunctionBase< ContinuousIndex< TCoordRep, VSpaceDimension >, 53 Array< double > > 54 { 55 public: 56 ITK_DISALLOW_COPY_AND_ASSIGN(BSplineInterpolationWeightFunction); 57 58 /** Standard class type aliases. */ 59 using Self = BSplineInterpolationWeightFunction; 60 using Superclass = FunctionBase< ContinuousIndex< TCoordRep, VSpaceDimension >, 61 Array< double > >; 62 63 using Pointer = SmartPointer< Self >; 64 using ConstPointer = SmartPointer< const Self >; 65 66 /** New macro for creation of through the object factory. */ 67 itkNewMacro(Self); 68 69 /** Run-time type information (and related methods). */ 70 itkTypeMacro(BSplineInterpolationWeightFunction, FunctionBase); 71 72 /** Space dimension. */ 73 static constexpr unsigned int SpaceDimension = VSpaceDimension; 74 75 /** Spline order. */ 76 static constexpr unsigned int SplineOrder = VSplineOrder; 77 78 /** OutputType type alias support. */ 79 using WeightsType = Array< double >; 80 81 /** Index and size type alias support. */ 82 using IndexType = Index< VSpaceDimension >; 83 using SizeType = Size< VSpaceDimension >; 84 85 /** ContinuousIndex type alias support. */ 86 using ContinuousIndexType = ContinuousIndex< TCoordRep, VSpaceDimension >; 87 88 /** Evaluate the weights at specified ContinuousIndex position. 89 * Subclasses must provide this method. */ 90 WeightsType Evaluate(const ContinuousIndexType & index) const override; 91 92 /** Evaluate the weights at specified ContinuousIndex position. 93 * The weights are returned in the user specified container. 94 * This function assume that weights can hold 95 * (SplineOrder + 1)^(SpaceDimension) elements. For efficiency, 96 * no size checking is done. 97 * On return, startIndex contains the start index of the 98 * support region over which the weights are defined. 99 */ 100 virtual void Evaluate(const ContinuousIndexType & index, 101 WeightsType & weights, IndexType & startIndex) const; 102 103 /** Get support region size. */ 104 itkGetConstMacro(SupportSize, SizeType); 105 106 /** Get number of weights. */ 107 itkGetConstMacro(NumberOfWeights, unsigned int); 108 109 protected: 110 BSplineInterpolationWeightFunction(); 111 ~BSplineInterpolationWeightFunction() override = default; 112 void PrintSelf(std::ostream & os, Indent indent) const override; 113 114 private: 115 /** Number of weights. */ 116 unsigned int m_NumberOfWeights; 117 118 /** Size of support region. */ 119 SizeType m_SupportSize; 120 121 /** Lookup table type. */ 122 using TableType = Array2D< unsigned int >; 123 124 /** Table mapping linear offset to indices. */ 125 TableType m_OffsetToIndexTable; 126 127 /** Interpolation kernel type. */ 128 using KernelType = BSplineKernelFunction< Self::SplineOrder >; 129 130 /** Interpolation kernel. */ 131 typename KernelType::Pointer m_Kernel; 132 }; 133 } // end namespace itk 134 135 #ifndef ITK_MANUAL_INSTANTIATION 136 #include "itkBSplineInterpolationWeightFunction.hxx" 137 #endif 138 139 #endif 140