ITK  5.2.0
Insight Toolkit
itkBSplineInterpolateImageFunction.h
Go to the documentation of this file.
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  * 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 /*=========================================================================
19  *
20  * Portions of this file are subject to the VTK Toolkit Version 3 copyright.
21  *
22  * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
23  *
24  * For complete copyright, license and disclaimer of warranty information
25  * please refer to the NOTICE file at the top of the ITK source tree.
26  *
27  *=========================================================================*/
28 #ifndef itkBSplineInterpolateImageFunction_h
29 #define itkBSplineInterpolateImageFunction_h
30 
31 #include <vector>
32 
34 #include "vnl/vnl_matrix.h"
35 
37 #include "itkConceptChecking.h"
38 #include "itkCovariantVector.h"
39 
40 namespace itk
41 {
81 template <typename TImageType, typename TCoordRep = double, typename TCoefficientType = double>
82 class ITK_TEMPLATE_EXPORT BSplineInterpolateImageFunction : public InterpolateImageFunction<TImageType, TCoordRep>
83 {
84 public:
85  ITK_DISALLOW_COPY_AND_MOVE(BSplineInterpolateImageFunction);
86 
92 
95 
97  itkNewMacro(Self);
98 
100  using OutputType = typename Superclass::OutputType;
101 
103  using InputImageType = typename Superclass::InputImageType;
104 
106  static constexpr unsigned int ImageDimension = Superclass::ImageDimension;
107 
110 
112  using SizeType = typename Superclass::SizeType;
113 
115  using ContinuousIndexType = typename Superclass::ContinuousIndexType;
116 
119 
122 
124  using CoefficientDataType = TCoefficientType;
126 
130 
133 
142  OutputType
143  Evaluate(const PointType & point) const override
144  {
145  ContinuousIndexType index;
146 
147  this->GetInputImage()->TransformPhysicalPointToContinuousIndex(point, index);
148  // No thread info passed in, so call method that doesn't need thread ID.
149  return (this->EvaluateAtContinuousIndex(index));
150  }
151 
152  virtual OutputType
153  Evaluate(const PointType & point, ThreadIdType threadId) const
154  {
155  ContinuousIndexType index;
156 
157  this->GetInputImage()->TransformPhysicalPointToContinuousIndex(point, index);
158  return (this->EvaluateAtContinuousIndex(index, threadId));
159  }
160 
161  OutputType
162  EvaluateAtContinuousIndex(const ContinuousIndexType & index) const override
163  {
164  // Don't know thread information, make evaluateIndex, weights on the stack.
165  // Slower, but safer.
166  vnl_matrix<long> evaluateIndex(ImageDimension, (m_SplineOrder + 1));
167  vnl_matrix<double> weights(ImageDimension, (m_SplineOrder + 1));
168 
169  // Pass evaluateIndex, weights by reference. They're only good as long
170  // as this method is in scope.
171  return this->EvaluateAtContinuousIndexInternal(index, evaluateIndex, weights);
172  }
173 
174  virtual OutputType
175  EvaluateAtContinuousIndex(const ContinuousIndexType & x, ThreadIdType threadId) const;
176 
177  CovariantVectorType
178  EvaluateDerivative(const PointType & point) const
179  {
180  ContinuousIndexType index;
181 
182  this->GetInputImage()->TransformPhysicalPointToContinuousIndex(point, index);
183  // No thread info passed in, so call method that doesn't need thread ID.
184  return (this->EvaluateDerivativeAtContinuousIndex(index));
185  }
186 
187  CovariantVectorType
188  EvaluateDerivative(const PointType & point, ThreadIdType threadId) const
189  {
190  ContinuousIndexType index;
191 
192  this->GetInputImage()->TransformPhysicalPointToContinuousIndex(point, index);
193  return (this->EvaluateDerivativeAtContinuousIndex(index, threadId));
194  }
195 
196  CovariantVectorType
198  {
199  // Don't know thread information, make evaluateIndex, weights,
200  // weightsDerivative
201  // on the stack.
202  // Slower, but safer.
203  vnl_matrix<long> evaluateIndex(ImageDimension, (m_SplineOrder + 1));
204  vnl_matrix<double> weights(ImageDimension, (m_SplineOrder + 1));
205  vnl_matrix<double> weightsDerivative(ImageDimension, (m_SplineOrder + 1));
206 
207  // Pass evaluateIndex, weights, weightsDerivative by reference. They're only
208  // good
209  // as long as this method is in scope.
210  return this->EvaluateDerivativeAtContinuousIndexInternal(x, evaluateIndex, weights, weightsDerivative);
211  }
212 
213  CovariantVectorType
214  EvaluateDerivativeAtContinuousIndex(const ContinuousIndexType & x, ThreadIdType threadId) const;
215 
216  void
218  {
219  ContinuousIndexType index;
220 
221  this->GetInputImage()->TransformPhysicalPointToContinuousIndex(point, index);
222 
223  // No thread info passed in, so call method that doesn't need thread ID.
224  this->EvaluateValueAndDerivativeAtContinuousIndex(index, value, deriv);
225  }
226 
227  void
229  OutputType & value,
230  CovariantVectorType & deriv,
231  ThreadIdType threadId) const
232  {
233  ContinuousIndexType index;
234 
235  this->GetInputImage()->TransformPhysicalPointToContinuousIndex(point, index);
236  this->EvaluateValueAndDerivativeAtContinuousIndex(index, value, deriv, threadId);
237  }
238 
239  void
241  OutputType & value,
242  CovariantVectorType & deriv) const
243  {
244  // Don't know thread information, make evaluateIndex, weights,
245  // weightsDerivative
246  // on the stack.
247  // Slower, but safer.
248  vnl_matrix<long> evaluateIndex(ImageDimension, (m_SplineOrder + 1));
249  vnl_matrix<double> weights(ImageDimension, (m_SplineOrder + 1));
250  vnl_matrix<double> weightsDerivative(ImageDimension, (m_SplineOrder + 1));
251 
252  // Pass evaluateIndex, weights, weightsDerivative by reference. They're only
253  // good
254  // as long as this method is in scope.
255  this->EvaluateValueAndDerivativeAtContinuousIndexInternal(
256  x, value, deriv, evaluateIndex, weights, weightsDerivative);
257  }
258 
259  void
260  EvaluateValueAndDerivativeAtContinuousIndex(const ContinuousIndexType & x,
261  OutputType & value,
262  CovariantVectorType & derivativeValue,
263  ThreadIdType threadId) const;
264 
267  void
268  SetSplineOrder(unsigned int SplineOrder);
269 
270  itkGetConstMacro(SplineOrder, int);
271 
272  void
273  SetNumberOfWorkUnits(ThreadIdType numThreads);
274 
275  itkGetConstMacro(NumberOfWorkUnits, ThreadIdType);
276 
278  void
279  SetInputImage(const TImageType * inputData) override;
280 
291  itkSetMacro(UseImageDirection, bool);
292  itkGetConstMacro(UseImageDirection, bool);
293  itkBooleanMacro(UseImageDirection);
295 
296  SizeType
297  GetRadius() const override
298  {
299  return SizeType::Filled(m_SplineOrder + 1);
300  }
301 
302 protected:
321  virtual OutputType
322  EvaluateAtContinuousIndexInternal(const ContinuousIndexType & x,
323  vnl_matrix<long> & evaluateIndex,
324  vnl_matrix<double> & weights) const;
325 
326  virtual void
327  EvaluateValueAndDerivativeAtContinuousIndexInternal(const ContinuousIndexType & x,
328  OutputType & value,
329  CovariantVectorType & derivativeValue,
330  vnl_matrix<long> & evaluateIndex,
331  vnl_matrix<double> & weights,
332  vnl_matrix<double> & weightsDerivative) const;
333 
334  virtual CovariantVectorType
335  EvaluateDerivativeAtContinuousIndexInternal(const ContinuousIndexType & x,
336  vnl_matrix<long> & evaluateIndex,
337  vnl_matrix<double> & weights,
338  vnl_matrix<double> & weightsDerivative) const;
339 
342  void
343  PrintSelf(std::ostream & os, Indent indent) const override;
344 
345  // These are needed by the smoothing spline routine.
346  // temp storage for processing of Coefficients
347  std::vector<CoefficientDataType> m_Scratch;
348  // Image size
350  // User specified spline order (3rd or cubic is the default)
351  unsigned int m_SplineOrder;
352 
353  // Spline coefficients
355 
356 private:
358  void
359  SetInterpolationWeights(const ContinuousIndexType & x,
360  const vnl_matrix<long> & EvaluateIndex,
361  vnl_matrix<double> & weights,
362  unsigned int splineOrder) const;
363 
365  void
366  SetDerivativeWeights(const ContinuousIndexType & x,
367  const vnl_matrix<long> & EvaluateIndex,
368  vnl_matrix<double> & weights,
369  unsigned int splineOrder) const;
370 
373  void
374  GeneratePointsToIndex();
375 
377  void
378  DetermineRegionOfSupport(vnl_matrix<long> & evaluateIndex,
379  const ContinuousIndexType & x,
380  unsigned int splineOrder) const;
381 
384  void
385  ApplyMirrorBoundaryConditions(vnl_matrix<long> & evaluateIndex, unsigned int splineOrder) const;
386 
387  Iterator m_CIterator; // Iterator for
388  // traversing spline
389  // coefficients.
390  unsigned long m_MaxNumberInterpolationPoints; // number of
391  // neighborhood
392  // points used for
393  // interpolation
394  std::vector<IndexType> m_PointsToIndex; // Preallocation of
395  // interpolation
396  // neighborhood
397  // indices
398 
400 
401  // flag to take or not the image direction into account when computing the
402  // derivatives.
404 
406  vnl_matrix<long> * m_ThreadedEvaluateIndex;
407  vnl_matrix<double> * m_ThreadedWeights;
408  vnl_matrix<double> * m_ThreadedWeightsDerivative;
409 };
410 } // namespace itk
411 
412 #ifndef ITK_MANUAL_INSTANTIATION
413 # include "itkBSplineInterpolateImageFunction.hxx"
414 #endif
415 
416 #endif
itk::BSplineInterpolateImageFunction::m_ThreadedWeights
vnl_matrix< double > * m_ThreadedWeights
Definition: itkBSplineInterpolateImageFunction.h:407
itk::BSplineInterpolateImageFunction::m_CoefficientFilter
CoefficientFilterPointer m_CoefficientFilter
Definition: itkBSplineInterpolateImageFunction.h:399
itkCovariantVector.h
itk::BSplineInterpolateImageFunction::m_PointsToIndex
std::vector< IndexType > m_PointsToIndex
Definition: itkBSplineInterpolateImageFunction.h:394
itk::BSplineInterpolateImageFunction::m_ThreadedWeightsDerivative
vnl_matrix< double > * m_ThreadedWeightsDerivative
Definition: itkBSplineInterpolateImageFunction.h:408
itk::BSplineInterpolateImageFunction::Evaluate
virtual OutputType Evaluate(const PointType &point, ThreadIdType threadId) const
Definition: itkBSplineInterpolateImageFunction.h:153
itk::BSplineInterpolateImageFunction
Evaluates the B-Spline interpolation of an image. Spline order may be from 0 to 5.
Definition: itkBSplineInterpolateImageFunction.h:82
itk::BSplineDecompositionImageFilter
Calculates the B-Spline coefficients of an image. Spline order may be from 0 to 5.
Definition: itkBSplineDecompositionImageFilter.h:74
itk::BSplineInterpolateImageFunction::GetRadius
SizeType GetRadius() const override
Definition: itkBSplineInterpolateImageFunction.h:297
itk::BSplineInterpolateImageFunction::m_NumberOfWorkUnits
ThreadIdType m_NumberOfWorkUnits
Definition: itkBSplineInterpolateImageFunction.h:405
itk::ImageLinearIteratorWithIndex< TImageType >
itk::BSplineInterpolateImageFunction::EvaluateAtContinuousIndex
OutputType EvaluateAtContinuousIndex(const ContinuousIndexType &index) const override
Definition: itkBSplineInterpolateImageFunction.h:162
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::BSplineInterpolateImageFunction< TImageType, TCoordRep, TImageType::PixelType >::IndexType
typename Superclass::IndexType IndexType
Definition: itkBSplineInterpolateImageFunction.h:109
itk::BSplineInterpolateImageFunction::m_MaxNumberInterpolationPoints
unsigned long m_MaxNumberInterpolationPoints
Definition: itkBSplineInterpolateImageFunction.h:390
itk::BSplineInterpolateImageFunction< TImageType, TCoordRep, TImageType::PixelType >::ContinuousIndexType
typename Superclass::ContinuousIndexType ContinuousIndexType
Definition: itkBSplineInterpolateImageFunction.h:115
itkConceptChecking.h
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::BSplineInterpolateImageFunction::EvaluateValueAndDerivativeAtContinuousIndex
void EvaluateValueAndDerivativeAtContinuousIndex(const ContinuousIndexType &x, OutputType &value, CovariantVectorType &deriv) const
Definition: itkBSplineInterpolateImageFunction.h:240
itk::BSplineInterpolateImageFunction< TImageType, TCoordRep, TImageType::PixelType >::CoefficientFilterPointer
typename CoefficientFilter::Pointer CoefficientFilterPointer
Definition: itkBSplineInterpolateImageFunction.h:129
itk::BSplineInterpolateImageFunction::m_ThreadedEvaluateIndex
vnl_matrix< long > * m_ThreadedEvaluateIndex
Definition: itkBSplineInterpolateImageFunction.h:406
itk::BSplineInterpolateImageFunction::EvaluateValueAndDerivative
void EvaluateValueAndDerivative(const PointType &point, OutputType &value, CovariantVectorType &deriv) const
Definition: itkBSplineInterpolateImageFunction.h:217
itk::BSplineInterpolateImageFunction< TImageType, TCoordRep, TImageType::PixelType >::InputImageType
typename Superclass::InputImageType InputImageType
Definition: itkBSplineInterpolateImageFunction.h:103
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::FunctionBase< Point< TCoordRep, TImageType ::ImageDimension >, NumericTraits< TImageType ::PixelType >::RealType >::OutputType
NumericTraits< TImageType ::PixelType >::RealType OutputType
Definition: itkFunctionBase.h:62
itk::BSplineInterpolateImageFunction::m_DataLength
TImageType::SizeType m_DataLength
Definition: itkBSplineInterpolateImageFunction.h:349
itk::BSplineInterpolateImageFunction::m_Coefficients
CoefficientImageType::ConstPointer m_Coefficients
Definition: itkBSplineInterpolateImageFunction.h:354
itk::BSplineInterpolateImageFunction::EvaluateDerivativeAtContinuousIndex
CovariantVectorType EvaluateDerivativeAtContinuousIndex(const ContinuousIndexType &x) const
Definition: itkBSplineInterpolateImageFunction.h:197
itkBSplineDecompositionImageFilter.h
itk::ThreadIdType
unsigned int ThreadIdType
Definition: itkIntTypes.h:99
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::BSplineInterpolateImageFunction::m_Scratch
std::vector< CoefficientDataType > m_Scratch
Definition: itkBSplineInterpolateImageFunction.h:347
itk::BSplineInterpolateImageFunction::EvaluateValueAndDerivative
void EvaluateValueAndDerivative(const PointType &point, OutputType &value, CovariantVectorType &deriv, ThreadIdType threadId) const
Definition: itkBSplineInterpolateImageFunction.h:228
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::BSplineInterpolateImageFunction::m_CIterator
Iterator m_CIterator
Definition: itkBSplineInterpolateImageFunction.h:387
itk::BSplineInterpolateImageFunction::EvaluateDerivative
CovariantVectorType EvaluateDerivative(const PointType &point) const
Definition: itkBSplineInterpolateImageFunction.h:178
itk::BSplineInterpolateImageFunction< TImageType, TCoordRep, TImageType::PixelType >::SizeType
typename Superclass::SizeType SizeType
Definition: itkBSplineInterpolateImageFunction.h:112
itk::CovariantVector
A templated class holding a n-Dimensional covariant vector.
Definition: itkCovariantVector.h:70
itk::BSplineInterpolateImageFunction::EvaluateDerivative
CovariantVectorType EvaluateDerivative(const PointType &point, ThreadIdType threadId) const
Definition: itkBSplineInterpolateImageFunction.h:188
itk::BSplineInterpolateImageFunction< TImageType, TCoordRep, TImageType::PixelType >::PointType
typename Superclass::PointType PointType
Definition: itkBSplineInterpolateImageFunction.h:118
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::BSplineInterpolateImageFunction::m_UseImageDirection
bool m_UseImageDirection
Definition: itkBSplineInterpolateImageFunction.h:403
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:86
itk::BSplineInterpolateImageFunction::Evaluate
OutputType Evaluate(const PointType &point) const override
Definition: itkBSplineInterpolateImageFunction.h:143
itkInterpolateImageFunction.h
itk::BSplineInterpolateImageFunction< TImageType, TCoordRep, TImageType::PixelType >::CoefficientDataType
TImageType::PixelType CoefficientDataType
Definition: itkBSplineInterpolateImageFunction.h:124
itk::InterpolateImageFunction
Base class for all image interpolators.
Definition: itkInterpolateImageFunction.h:45
itk::BSplineInterpolateImageFunction::m_SplineOrder
unsigned int m_SplineOrder
Definition: itkBSplineInterpolateImageFunction.h:351