ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkMatrixOffsetTransformBase.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 itkMatrixOffsetTransformBase_h
19 #define itkMatrixOffsetTransformBase_h
20 
21 
22 #include "itkMacro.h"
23 #include "itkMatrix.h"
24 #include "itkTransform.h"
25 
26 #include <iostream>
27 
28 namespace itk
29 {
30 
31 /* MatrixOrthogonalityTolerance is a utility to
32  * allow setting the tolerance limits used for
33  * checking if a matrix meet the orthogonality
34  * constraints of being a rigid rotation matrix.
35  * The tolerance needs to be different for
36  * matricies of type float vs. double.
37  */
38 template<typename T>
40 
41 template <>
42 class ITK_TEMPLATE_EXPORT MatrixOrthogonalityTolerance<double>
43 {
44 public:
45  static double GetTolerance() { return 1e-10; }
46 };
47 
48 template <>
49 class ITK_TEMPLATE_EXPORT MatrixOrthogonalityTolerance<float>
50 {
51 public:
52  static float GetTolerance() { return 1e-5f; }
53 };
54 
96 template<typename TParametersValueType=double,
97  unsigned int NInputDimensions = 3,
98  unsigned int NOutputDimensions = 3>
99 class ITK_TEMPLATE_EXPORT MatrixOffsetTransformBase :
100  public Transform<TParametersValueType, NInputDimensions, NOutputDimensions>
101 {
102 public:
105  using Superclass = Transform<TParametersValueType,
106  NInputDimensions,
107  NOutputDimensions>;
108 
111 
113  itkTypeMacro(MatrixOffsetTransformBase, Transform);
114 
116  itkNewMacro(Self);
117 
119  static constexpr unsigned int InputSpaceDimension = NInputDimensions;
120  static constexpr unsigned int OutputSpaceDimension = NOutputDimensions;
121  static constexpr unsigned int ParametersDimension = NOutputDimensions * ( NInputDimensions + 1 );
122 
124  using FixedParametersType = typename Superclass::FixedParametersType;
125  using FixedParametersValueType = typename Superclass::FixedParametersValueType;
126  using ParametersType = typename Superclass::ParametersType;
127  using ParametersValueType = typename Superclass::ParametersValueType;
128 
130  using JacobianType = typename Superclass::JacobianType;
131  using JacobianPositionType = typename Superclass::JacobianPositionType;
132  using InverseJacobianPositionType = typename Superclass::InverseJacobianPositionType;
133 
135  using TransformCategoryType = typename Superclass::TransformCategoryType;
136 
138  using ScalarType = typename Superclass::ScalarType;
139 
141  using InputVectorType = Vector<TParametersValueType,
142  Self::InputSpaceDimension>;
143  using OutputVectorType = Vector<TParametersValueType,
144  Self::OutputSpaceDimension>;
146 
148  using InputCovariantVectorType = CovariantVector<TParametersValueType,
149  Self::InputSpaceDimension>;
150  using OutputCovariantVectorType = CovariantVector<TParametersValueType,
151  Self::OutputSpaceDimension>;
152 
153  using InputVectorPixelType = typename Superclass::InputVectorPixelType;
154  using OutputVectorPixelType = typename Superclass::OutputVectorPixelType;
155 
157  using InputDiffusionTensor3DType = typename Superclass::InputDiffusionTensor3DType;
158  using OutputDiffusionTensor3DType = typename Superclass::OutputDiffusionTensor3DType;
159 
161  using InputSymmetricSecondRankTensorType = typename Superclass::InputSymmetricSecondRankTensorType;
162  using OutputSymmetricSecondRankTensorType = typename Superclass::OutputSymmetricSecondRankTensorType;
163 
166 
168  using InputVnlVectorType = vnl_vector_fixed<TParametersValueType,
169  Self::InputSpaceDimension>;
170  using OutputVnlVectorType = vnl_vector_fixed<TParametersValueType,
171  Self::OutputSpaceDimension>;
172 
174  using InputPointType = Point<TParametersValueType,
175  Self::InputSpaceDimension>;
177  using OutputPointType = Point<TParametersValueType,
178  Self::OutputSpaceDimension>;
180 
182  using MatrixType = Matrix<TParametersValueType, Self::OutputSpaceDimension,
183  Self::InputSpaceDimension>;
185 
187  using InverseMatrixType = Matrix<TParametersValueType, Self::InputSpaceDimension,
188  Self::OutputSpaceDimension>;
189 
191 
194 
196 
198 
201  using InverseTransformBaseType = typename Superclass::InverseTransformBaseType;
203 
207  virtual void SetIdentity();
208 
213  {
214  return Self::Linear;
215  }
216 
228  virtual void SetMatrix(const MatrixType & matrix)
229  {
230  m_Matrix = matrix; this->ComputeOffset();
231  this->ComputeMatrixParameters();
232  m_MatrixMTime.Modified(); this->Modified(); return;
233  }
235 
243  virtual const MatrixType & GetMatrix() const
244  {
245  return m_Matrix;
246  }
247 
256  void SetOffset(const OutputVectorType & offset)
257  {
258  m_Offset = offset; this->ComputeTranslation();
259  this->Modified(); return;
260  }
262 
268  const OutputVectorType & GetOffset() const
269  {
270  return m_Offset;
271  }
272 
295  void SetCenter(const InputPointType & center)
296  {
297  m_Center = center; this->ComputeOffset();
298  this->Modified(); return;
299  }
301 
308  const InputPointType & GetCenter() const
309  {
310  return m_Center;
311  }
312 
319  void SetTranslation(const OutputVectorType & translation)
320  {
321  m_Translation = translation; this->ComputeOffset();
322  this->Modified(); return;
323  }
325 
333  {
334  return m_Translation;
335  }
336 
341  void SetParameters(const ParametersType & parameters) override;
342 
344  const ParametersType & GetParameters() const override;
345 
347  void SetFixedParameters(const FixedParametersType &) override;
348 
350  const FixedParametersType & GetFixedParameters() const override;
351 
363  void Compose(const Self *other, bool pre = false);
364 
373  OutputPointType TransformPoint(const InputPointType & point) const override;
374 
375  using Superclass::TransformVector;
376 
377  OutputVectorType TransformVector(const InputVectorType & vector) const override;
378 
379  OutputVnlVectorType TransformVector(const InputVnlVectorType & vector) const override;
380 
381  OutputVectorPixelType TransformVector(const InputVectorPixelType & vector) const override;
382 
383  using Superclass::TransformCovariantVector;
384 
385  OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType & vector) const override;
386 
387  OutputVectorPixelType TransformCovariantVector(const InputVectorPixelType & vector) const override;
388 
389  using Superclass::TransformDiffusionTensor3D;
390 
391  OutputDiffusionTensor3DType TransformDiffusionTensor3D(const InputDiffusionTensor3DType & tensor) const override;
392 
393  OutputVectorPixelType TransformDiffusionTensor3D(const InputVectorPixelType & tensor ) const override;
394 
395  using Superclass::TransformSymmetricSecondRankTensor;
396  OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor( const InputSymmetricSecondRankTensorType & tensor ) const override;
397 
398  OutputVectorPixelType TransformSymmetricSecondRankTensor( const InputVectorPixelType & tensor ) const override;
399 
400 
410  void ComputeJacobianWithRespectToParameters(const InputPointType & x, JacobianType & j) const override;
411 
412 
416  void ComputeJacobianWithRespectToPosition(const InputPointType & x, JacobianPositionType & jac) const override;
417  using Superclass::ComputeJacobianWithRespectToPosition;
418 
422  void ComputeInverseJacobianWithRespectToPosition(const InputPointType & x,
423  InverseJacobianPositionType & jac) const override;
424  using Superclass::ComputeInverseJacobianWithRespectToPosition;
425 
444  bool GetInverse(Self *inverse) const;
446 
448  InverseTransformBasePointer GetInverseTransform() const override;
449 
455  bool IsLinear() const override
456  {
457  return true;
458  }
459 
460 protected:
463  const InverseMatrixType & GetInverseMatrix() const;
464 
465 protected:
473  MatrixOffsetTransformBase(const MatrixType & matrix, const OutputVectorType & offset);
474  MatrixOffsetTransformBase(unsigned int paramDims);
477 
479  ~MatrixOffsetTransformBase() override = default;
480 
482  void PrintSelf(std::ostream & s, Indent indent) const override;
483 
485  {
486  return m_InverseMatrix;
487  }
488  void SetVarInverseMatrix(const InverseMatrixType & matrix) const
489  {
490  m_InverseMatrix = matrix; m_InverseMatrixMTime.Modified();
491  }
492  bool InverseMatrixIsOld() const
493  {
494  if( m_MatrixMTime != m_InverseMatrixMTime )
495  {
496  return true;
497  }
498  else
499  {
500  return false;
501  }
502  }
503 
504  virtual void ComputeMatrixParameters();
505 
506  virtual void ComputeMatrix();
507 
508  void SetVarMatrix(const MatrixType & matrix)
509  {
510  m_Matrix = matrix; m_MatrixMTime.Modified();
511  }
512 
513  virtual void ComputeTranslation();
514 
515  void SetVarTranslation(const OutputVectorType & translation)
516  {
517  m_Translation = translation;
518  }
519 
520  virtual void ComputeOffset();
521 
522  void SetVarOffset(const OutputVectorType & offset)
523  {
524  m_Offset = offset;
525  }
526 
527  void SetVarCenter(const InputPointType & center)
528  {
529  m_Center = center;
530  }
531 
532  itkGetConstMacro(Singular, bool);
533 private:
534 
535  MatrixOffsetTransformBase(const Self & other) = delete;
536  const Self & operator=(const Self &) = delete;
537 
538  MatrixType m_Matrix; // Matrix of the transformation
539  OutputVectorType m_Offset; // Offset of the transformation
540  mutable InverseMatrixType m_InverseMatrix; // Inverse of the matrix
541  mutable bool m_Singular; // Is m_Inverse singular?
542 
545 
549 }; // class MatrixOffsetTransformBase
550 } // namespace itk
551 
552 #ifndef ITK_MANUAL_INSTANTIATION
553 #include "itkMatrixOffsetTransformBase.hxx"
554 #endif
555 
556 #endif /* itkMatrixOffsetTransformBase_h */
vnl_vector_fixed< TParametersValueType, NOutputDimensions > OutputVnlVectorType
Definition: itkTransform.h:158
typename Superclass::ParametersType ParametersType
Definition: itkTransform.h:119
void SetVarCenter(const InputPointType &center)
Light weight base class for most itk classes.
typename Superclass::FixedParametersType FixedParametersType
Definition: itkTransform.h:117
vnl_matrix_fixed< ParametersValueType, NInputDimensions, NOutputDimensions > InverseJacobianPositionType
Definition: itkTransform.h:129
void SetCenter(const InputPointType &center)
Represent a symmetric tensor of second rank.
Matrix and Offset transformation of a vector space (e.g. space coordinates)
void SetVarTranslation(const OutputVectorType &translation)
const OutputVectorType & GetTranslation() const
TCoordRep ValueType
Definition: itkPoint.h:61
void SetVarMatrix(const MatrixType &matrix)
Transform points and vectors from an input space to an output space.
Definition: itkTransform.h:83
Represents an array whose length can be defined at run-time.
Array2D class representing a 2D array with size defined at construction time.
Definition: itkArray2D.h:45
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
void SetTranslation(const OutputVectorType &translation)
typename InverseTransformBaseType::Pointer InverseTransformBasePointer
Definition: itkTransform.h:169
Generate a unique, increasing time value.
Definition: itkTimeStamp.h:60
vnl_vector_fixed< TParametersValueType, NInputDimensions > InputVnlVectorType
Definition: itkTransform.h:157
typename Superclass::FixedParametersValueType FixedParametersValueType
Definition: itkTransform.h:118
virtual void SetMatrix(const MatrixType &matrix)
const InverseMatrixType & GetVarInverseMatrix() const
ParametersValueType ScalarType
Definition: itkTransform.h:124
static constexpr double e
The base of the natural logarithm or Euler&#39;s number
Definition: itkMath.h:53
virtual const MatrixType & GetMatrix() const
Control indentation during Print() invocation.
Definition: itkIndent.h:49
void SetVarInverseMatrix(const InverseMatrixType &matrix) const
const OutputVectorType & GetOffset() const
const InputPointType & GetCenter() const
TransformCategoryType GetTransformCategory() const override
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:52
Represent a diffusion tensor as used in DTI images.
A templated class holding a n-Dimensional covariant vector.
void SetVarOffset(const OutputVectorType &offset)
typename Superclass::ParametersValueType ParametersValueType
Definition: itkTransform.h:120
vnl_matrix_fixed< ParametersValueType, NOutputDimensions, NInputDimensions > JacobianPositionType
Definition: itkTransform.h:128
void SetOffset(const OutputVectorType &offset)