ITK  6.0.0
Insight Toolkit
itkBSplineBaseTransform.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  * 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 itkBSplineBaseTransform_h
19 #define itkBSplineBaseTransform_h
20 
21 #include <iostream>
22 #include "itkTransform.h"
23 #include "itkImage.h"
25 
26 namespace itk
27 {
33 template <typename TParametersValueType = double, unsigned int VDimension = 3, unsigned int VSplineOrder = 3>
34 class ITK_TEMPLATE_EXPORT BSplineBaseTransform : public Transform<TParametersValueType, VDimension, VDimension>
35 {
36 public:
37  ITK_DISALLOW_COPY_AND_MOVE(BSplineBaseTransform);
38 
44 
46  itkOverrideGetNameOfClassMacro(BSplineBaseTransform);
47 
49  static constexpr unsigned int SpaceDimension = VDimension;
50 
52  static constexpr unsigned int SplineOrder = VSplineOrder;
53 
55  itkCloneMacro(Self);
56 
58  using typename Superclass::ScalarType;
59 
61  using typename Superclass::FixedParametersType;
62  using typename Superclass::ParametersType;
63 
65  using typename Superclass::JacobianType;
66  using typename Superclass::JacobianPositionType;
68 
70  using typename Superclass::TransformCategoryEnum;
71 
73  using typename Superclass::NumberOfParametersType;
74 
78 
82 
84  using InputVnlVectorType = vnl_vector_fixed<TParametersValueType, SpaceDimension>;
85  using OutputVnlVectorType = vnl_vector_fixed<TParametersValueType, SpaceDimension>;
86 
90 
110  void
111  SetParameters(const ParametersType & parameters) override;
112 
135  void
136  SetFixedParameters(const FixedParametersType & parameters) override = 0;
155  void
156  SetParametersByValue(const ParametersType & parameters) override;
157 
166  void
167  SetIdentity();
168 
170  const ParametersType &
171  GetParameters() const override;
172 
174  const FixedParametersType &
175  GetFixedParameters() const override;
176 
178  using ParametersValueType = typename ParametersType::ValueType;
182 
194  virtual void
195  SetCoefficientImages(const CoefficientImageArray & images) = 0;
196 
200  {
201  return this->m_CoefficientImages;
202  }
203 
204  using typename Superclass::DerivativeType;
205 
216  void
217  UpdateTransformParameters(const DerivativeType & update, TParametersValueType factor = 1.0) override;
218 
221 
223  using SizeType = typename RegionType::SizeType;
227 
230  TransformPoint(const InputPointType & point) const override;
231 
234 
237 
239  static constexpr unsigned int NumberOfWeights{ WeightsFunctionType::NumberOfWeights };
240 
243 
252  virtual void
253  TransformPoint(const InputPointType & inputPoint,
254  OutputPointType & outputPoint,
255  WeightsType & weights,
256  ParameterIndexArrayType & indices,
257  bool & inside) const = 0;
258 
259 #if !defined(ITK_LEGACY_REMOVE)
260 
261  itkLegacyMacro(unsigned long GetNumberOfWeights() const)
262  {
263  return m_WeightsFunction->GetNumberOfWeights();
264  }
265 #endif
266 
269  using Superclass::TransformVector;
270  OutputVectorType
271  TransformVector(const InputVectorType &) const override
272  {
273  itkExceptionMacro("Method not applicable for deformable transform.");
274  }
279  OutputVnlVectorType
280  TransformVector(const InputVnlVectorType &) const override
281  {
282  itkExceptionMacro("Method not applicable for deformable transform. ");
283  }
284 
287  using Superclass::TransformCovariantVector;
288  OutputCovariantVectorType
290  {
291  itkExceptionMacro("Method not applicable for deformable transform. ");
292  }
296  void
297  ComputeJacobianFromBSplineWeightsWithRespectToPosition(const InputPointType &,
298  WeightsType &,
299  ParameterIndexArrayType &) const;
300 
301  void
302  ComputeJacobianWithRespectToParameters(const InputPointType &, JacobianType &) const override = 0;
303 
304  void
306  {
307  itkExceptionMacro("ComputeJacobianWithRespectToPosition not yet implemented "
308  "for "
309  << this->GetNameOfClass());
310  }
311  using Superclass::ComputeJacobianWithRespectToPosition;
312 
314  NumberOfParametersType
315  GetNumberOfParameters() const override = 0;
316 
318  virtual NumberOfParametersType
319  GetNumberOfParametersPerDimension() const = 0;
320 
321  TransformCategoryEnum
322  GetTransformCategory() const override
323  {
324  return Self::TransformCategoryEnum::BSpline;
325  }
326 
327  unsigned int
328  GetNumberOfAffectedWeights() const;
329 
331  using PixelType = typename ImageType::PixelType;
332 
334 
336  NumberOfParametersType
337  GetNumberOfLocalParameters() const override
338  {
339  return this->GetNumberOfParameters();
340  }
341 
342 protected:
344  void
345  PrintSelf(std::ostream & os, Indent indent) const override;
346 
347  BSplineBaseTransform() = default;
348  ~BSplineBaseTransform() override = default;
349 
351  itkSetObjectMacro(WeightsFunction, WeightsFunctionType);
352  itkGetModifiableObjectMacro(WeightsFunction, WeightsFunctionType);
356  void
357  WrapAsImages();
358 
359 protected:
361  void
362  SetFixedParametersFromTransformDomainInformation() const;
363 
365  virtual void
366  SetFixedParametersGridSizeFromTransformDomainInformation() const = 0;
367 
369  virtual void
370  SetFixedParametersGridOriginFromTransformDomainInformation() const = 0;
371 
373  virtual void
374  SetFixedParametersGridSpacingFromTransformDomainInformation() const = 0;
375 
377  virtual void
378  SetFixedParametersGridDirectionFromTransformDomainInformation() const = 0;
379 
381  virtual void
382  SetCoefficientImageInformationFromFixedParameters() = 0;
383 
385  virtual bool
386  InsideValidRegion(ContinuousIndexType &) const = 0;
387 
388  // NOTE: There is a natural duality between the
389  // two representations of of the coefficients
390  // whereby the m_InternalParametersBuffer is
391  // needed to fit into the optimization framework
392  // and the m_CoefficientImages is needed for
393  // the Jacobian computations. This implementation
394  // is an attempt to remove as much redundancy as possible
395  // and share as much information between the two
396  // instances as possible.
397  //
402  CoefficientImageArray m_CoefficientImages{ Self::ArrayOfImagePointerGeneratorHelper() };
403 
405  ParametersType m_InternalParametersBuffer{};
406 
409 
410 private:
411  static CoefficientImageArray
412  ArrayOfImagePointerGeneratorHelper();
413 }; // class BSplineBaseTransform
414 } // namespace itk
415 
416 #ifndef ITK_MANUAL_INSTANTIATION
417 # include "itkBSplineBaseTransform.hxx"
418 #endif
419 
420 #endif /* itkBSplineBaseTransform_h */
itk::BSplineBaseTransform::GetTransformCategory
TransformCategoryEnum GetTransformCategory() const override
Definition: itkBSplineBaseTransform.h:322
itk::BSplineInterpolationWeightFunction
Returns the weights over the support region used for B-spline interpolation/reconstruction.
Definition: itkBSplineInterpolationWeightFunction.h:48
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::BSplineBaseTransform::MeshSizeType
SizeType MeshSizeType
Definition: itkBSplineBaseTransform.h:333
GetNameOfClass
const char * GetNameOfClass() const override
itk::GTest::TypedefsAndConstructors::Dimension2::DirectionType
ImageBaseType::DirectionType DirectionType
Definition: itkGTestTypedefsAndConstructors.h:52
itk::BSplineBaseTransform::PhysicalDimensionsType
typename ImageType::SpacingType PhysicalDimensionsType
Definition: itkBSplineBaseTransform.h:330
itk::BSplineBaseTransform::SizeType
typename RegionType::SizeType SizeType
Definition: itkBSplineBaseTransform.h:223
itk::BSplineBaseTransform::WeightsType
typename WeightsFunctionType::WeightsType WeightsType
Definition: itkBSplineBaseTransform.h:235
itk::ImageRegion
An image region represents a structured region of data.
Definition: itkImageRegion.h:80
itk::BSplineBaseTransform::ComputeJacobianWithRespectToPosition
void ComputeJacobianWithRespectToPosition(const InputPointType &, JacobianPositionType &) const override
Definition: itkBSplineBaseTransform.h:305
itk::BSplineBaseTransform::DirectionType
typename ImageType::DirectionType DirectionType
Definition: itkBSplineBaseTransform.h:225
itk::BSplineBaseTransform::SpacingType
typename ImageType::SpacingType SpacingType
Definition: itkBSplineBaseTransform.h:224
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::Vector
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::BSplineBaseTransform::ParametersValueType
typename ParametersType::ValueType ParametersValueType
Definition: itkBSplineBaseTransform.h:178
itkImage.h
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itkBSplineInterpolationWeightFunction.h
itk::BSplineBaseTransform::TransformVector
OutputVectorType TransformVector(const InputVectorType &) const override
Definition: itkBSplineBaseTransform.h:271
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::BSplineBaseTransform::IndexType
typename RegionType::IndexType IndexType
Definition: itkBSplineBaseTransform.h:222
itk::BSplineBaseTransform::OriginType
typename ImageType::PointType OriginType
Definition: itkBSplineBaseTransform.h:226
itk::point
*par Constraints *The filter requires an image with at least two dimensions and a vector *length of at least The theory supports extension to scalar but *the implementation of the itk vector classes do not **The template parameter TRealType must be floating point(float or double) or *a user-defined "real" numerical type with arithmetic operations defined *sufficient to compute derivatives. **\par Performance *This filter will automatically multithread if run with *SetUsePrincipleComponents
itk::Transform< TParametersValueType, VDimension, VDimension >::ScalarType
ParametersValueType ScalarType
Definition: itkTransform.h:127
itk::FixedArray< ImagePointer, VDimension >
itk::BSplineBaseTransform::PixelType
typename ImageType::PixelType PixelType
Definition: itkBSplineBaseTransform.h:331
itk::BSplineBaseTransform::GetNumberOfLocalParameters
NumberOfParametersType GetNumberOfLocalParameters() const override
Definition: itkBSplineBaseTransform.h:337
itk::Image::PixelType
TPixel PixelType
Definition: itkImage.h:108
itk::BSplineBaseTransform::OutputVnlVectorType
vnl_vector_fixed< TParametersValueType, SpaceDimension > OutputVnlVectorType
Definition: itkBSplineBaseTransform.h:85
itk::CovariantVector
A templated class holding a n-Dimensional covariant vector.
Definition: itkCovariantVector.h:70
itk::BSplineBaseTransform::ImagePointer
typename ImageType::Pointer ImagePointer
Definition: itkBSplineBaseTransform.h:180
itk::Transform< TParametersValueType, VDimension, VDimension >::JacobianPositionType
vnl_matrix_fixed< ParametersValueType, VOutputDimension, VInputDimension > JacobianPositionType
Definition: itkTransform.h:131
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::ContinuousIndex
A templated class holding a point in n-Dimensional image space.
Definition: itkContinuousIndex.h:46
itk::Transform< TParametersValueType, VDimension, VDimension >::InverseJacobianPositionType
vnl_matrix_fixed< ParametersValueType, VInputDimension, VOutputDimension > InverseJacobianPositionType
Definition: itkTransform.h:132
itk::BSplineBaseTransform::TransformVector
OutputVnlVectorType TransformVector(const InputVnlVectorType &) const override
Definition: itkBSplineBaseTransform.h:280
itk::BSplineInterpolationWeightFunction::WeightsType
typename Superclass::OutputType WeightsType
Definition: itkBSplineInterpolationWeightFunction.h:76
itk::BSplineBaseTransform
A base class with common elements of BSplineTransform and BSplineDeformableTransform.
Definition: itkBSplineBaseTransform.h:34
itk::BSplineBaseTransform::GetCoefficientImages
const CoefficientImageArray GetCoefficientImages() const
Definition: itkBSplineBaseTransform.h:199
itk::BSplineBaseTransform::TransformCovariantVector
OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const override
Definition: itkBSplineBaseTransform.h:289
itk::Point
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:53
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:88
itk::Transform
Transform points and vectors from an input space to an output space.
Definition: itkTransform.h:83
New
static Pointer New()
itkTransform.h
itk::BSplineBaseTransform::ContinuousIndexType
typename WeightsFunctionType::ContinuousIndexType ContinuousIndexType
Definition: itkBSplineBaseTransform.h:236
itk::Array2D
Array2D class representing a 2D array.
Definition: itkArray2D.h:42
itk::BSplineBaseTransform::InputVnlVectorType
vnl_vector_fixed< TParametersValueType, SpaceDimension > InputVnlVectorType
Definition: itkBSplineBaseTransform.h:84
itk::images
*par Constraints *The filter requires an image with at least two dimensions and a vector *length of at least The theory supports extension to scalar images
Definition: itkVectorGradientMagnitudeImageFilter.h:107