ITK  5.4.0
Insight Toolkit
itkTransform.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 itkTransform_h
19#define itkTransform_h
20
21#include <type_traits> // For std::enable_if
22#include "itkTransformBase.h"
23#include "itkVector.h"
27#include "vnl/vnl_vector_fixed.h"
28#include "vnl/vnl_matrix_fixed.h"
29#include "itkMatrix.h"
30
31namespace itk
32{
82template <typename TParametersValueType, unsigned int VInputDimension = 3, unsigned int VOutputDimension = 3>
83class ITK_TEMPLATE_EXPORT Transform : public TransformBaseTemplate<TParametersValueType>
84{
85public:
86 ITK_DISALLOW_COPY_AND_MOVE(Transform);
90 using Self = Transform;
94
96 itkOverrideGetNameOfClassMacro(Transform);
97
99 static constexpr unsigned int InputSpaceDimension = VInputDimension;
100 static constexpr unsigned int OutputSpaceDimension = VOutputDimension;
101
104
106 unsigned int
107 GetInputSpaceDimension() const override
108 {
109 return VInputDimension;
110 }
111
113 unsigned int
114 GetOutputSpaceDimension() const override
115 {
116 return VOutputDimension;
117 }
118
119
120 /* For storing the name of InputSpace */
121 itkSetMacro(InputSpaceName, std::string);
122 itkGetConstReferenceMacro(InputSpaceName, std::string);
123
130 itkSetMacro(OutputSpaceName, std::string);
131 itkGetConstReferenceMacro(OutputSpaceName, std::string);
132
134 using typename Superclass::FixedParametersType;
135 using typename Superclass::FixedParametersValueType;
136 using typename Superclass::ParametersType;
137 using typename Superclass::ParametersValueType;
139
142
145 using JacobianPositionType = vnl_matrix_fixed<ParametersValueType, VOutputDimension, VInputDimension>;
146 using InverseJacobianPositionType = vnl_matrix_fixed<ParametersValueType, VInputDimension, VOutputDimension>;
147
151
156
157 /* Standard symmetric second rank tensor type for this class */
160
161 /* Standard tensor type for this class */
164
168
170 using InputVnlVectorType = vnl_vector_fixed<TParametersValueType, VInputDimension>;
171 using OutputVnlVectorType = vnl_vector_fixed<TParametersValueType, VOutputDimension>;
172
176
180
182
184
188
189 using typename Superclass::NumberOfParametersType;
190
195 virtual OutputPointType
196 TransformPoint(const InputPointType &) const = 0;
197
199 virtual OutputVectorType
201 {
202 itkExceptionMacro("TransformVector(const InputVectorType &)"
203 "is unimplemented for "
204 << this->GetNameOfClass());
205 }
206
211 virtual OutputVectorType
212 TransformVector(const InputVectorType & vector, const InputPointType & point) const;
213
215 virtual OutputVnlVectorType
217 {
218 itkExceptionMacro("TransformVector( const InputVnlVectorType & ) is "
219 "unimplemented for "
220 << this->GetNameOfClass());
221 }
222
227 virtual OutputVnlVectorType
229
232 TransformVector(const InputVectorPixelType & itkNotUsed(vector)) const
233 {
234 itkExceptionMacro("TransformVector( const InputVectorPixelType & ) is "
235 "unimplemented for "
236 << this->GetNameOfClass());
237 }
238
243 virtual OutputVectorPixelType
245
249 {
250 itkExceptionMacro("TransformCovariantVector( const InputCovariantVectorType & ) is "
251 "unimplemented for "
252 << this->GetNameOfClass());
253 }
254
260 virtual OutputCovariantVectorType
262
263
266 TransformCovariantVector(const InputVectorPixelType & itkNotUsed(vector)) const
267 {
268 itkExceptionMacro("TransformCovariantVector(const InputVectorPixelType &)"
269 "is unimplemented for "
270 << this->GetNameOfClass());
271 }
272
278 virtual OutputVectorPixelType
280
284 {
285 itkExceptionMacro("TransformDiffusionTensor3D( const InputDiffusionTensor3DType & ) is "
286 "unimplemented for "
287 << this->GetNameOfClass());
288 }
289
295 virtual OutputDiffusionTensor3DType
297
300 TransformDiffusionTensor3D(const InputVectorPixelType & itkNotUsed(tensor)) const
301 {
302 itkExceptionMacro("TransformDiffusionTensor( const InputVectorPixelType & ) is "
303 "unimplemented for "
304 << this->GetNameOfClass());
305 }
306
307 virtual OutputVectorPixelType
309
317 const InputPointType & point) const;
318
322 {
323 itkExceptionMacro("TransformSymmetricSecondRankTensor( const InputSymmetricSecondRankTensorType & ) is "
324 "unimplemented for "
325 << this->GetNameOfClass());
326 }
327
329 virtual OutputVectorPixelType
331 {
332 itkExceptionMacro("TransformSymmetricSecondRankTensor( const InputVectorPixelType & ) is "
333 "unimplemented for "
334 << this->GetNameOfClass());
335 }
336
343 virtual OutputVectorPixelType
345
353 void
354 SetParameters(const ParametersType &) override = 0;
355
363 void
365 {
366 this->SetParameters(p);
367 }
368
373 void
374 CopyInParameters(const ParametersValueType * const begin, const ParametersValueType * const end) override;
375
380 void
382 const FixedParametersValueType * const end) override;
383
385 const ParametersType &
386 GetParameters() const override
387 {
388 return m_Parameters;
389 }
390
392 void
394
396 const FixedParametersType &
397 GetFixedParameters() const override
398 {
399 return m_FixedParameters;
400 }
401
409 virtual void
411
422 {
423 return this->GetNumberOfParameters();
424 }
425
427 NumberOfParametersType
428 GetNumberOfParameters() const override
429 {
430 return this->m_Parameters.Size();
431 }
432
434 virtual NumberOfParametersType
436 {
437 return this->m_FixedParameters.Size();
438 }
439
448 bool
449 GetInverse(Self * itkNotUsed(inverseTransform)) const
450 {
451 return false;
452 }
453
460 virtual InverseTransformBasePointer
462 {
463 return nullptr;
464 }
465
467 std::string
468 GetTransformTypeAsString() const override;
469
470 using typename Superclass::TransformCategoryEnum;
471
476 GetTransformCategory() const override
477 {
478 return Superclass::TransformCategoryEnum::UnknownTransformCategory;
479 }
480
481 virtual bool
482 IsLinear() const
483 {
484 return (this->GetTransformCategory() == Superclass::TransformCategoryEnum::Linear);
485 }
486
521 virtual void
523 JacobianType & itkNotUsed(jacobian)) const = 0;
526 virtual void
528 JacobianType & jacobian,
529 JacobianType & itkNotUsed(cachedJacobian)) const
530 {
531 // NOTE: default implementation is not optimized, and just falls back to original methods.
532 this->ComputeJacobianWithRespectToParameters(p, jacobian);
533 }
534
535
541 virtual void
543 JacobianPositionType & itkNotUsed(jacobian)) const
544 {
545 itkExceptionMacro("ComputeJacobianWithRespectToPosition( InputPointType, JacobianType )"
546 " is unimplemented for "
547 << this->GetNameOfClass());
548 }
549 itkLegacyMacro(virtual void ComputeJacobianWithRespectToPosition(const InputPointType & x, JacobianType & jacobian)
550 const);
559 virtual void
561 itkLegacyMacro(virtual void ComputeInverseJacobianWithRespectToPosition(const InputPointType & x,
562 JacobianType & jacobian) const);
574 template <typename TImage>
575 std::enable_if_t<TImage::ImageDimension == VInputDimension && TImage::ImageDimension == VOutputDimension, void>
576 ApplyToImageMetadata(TImage * image) const;
577 template <typename TImage>
578 std::enable_if_t<TImage::ImageDimension == VInputDimension && TImage::ImageDimension == VOutputDimension, void>
580 {
581 this->ApplyToImageMetadata(image.GetPointer()); // Delegate to the raw pointer signature
582 }
585protected:
591 typename LightObject::Pointer
592 InternalClone() const override;
593
595 Transform() = default;
596
598#if defined(__GNUC__)
599 // A bug in some versions of the GCC and Clang compilers
600 // result in an ICE or linker error when "= default" is requested.
601 // This was observed in at least gcc 4.8 and 5.4.0, and
602 // AppleClang 7.0.2 and 8.0.0. Probably others too.
603 // "= default" doesn't gain us much, so just don't use it here.
604 ~Transform() override{};
605#else
606 ~Transform() override = default;
607#endif
608 mutable ParametersType m_Parameters{};
609 mutable FixedParametersType m_FixedParameters{};
610
611 OutputDiffusionTensor3DType
613 const InverseJacobianPositionType &) const;
614
617 template <typename TTransform>
619 InvertTransform(const TTransform & transform)
620 {
621 const auto inverse = TTransform::New();
622 return transform.GetInverse(inverse) ? inverse.GetPointer() : nullptr;
623 }
626private:
627 std::string m_InputSpaceName{};
628 std::string m_OutputSpaceName{};
629
630 template <typename TType>
631 static std::string
633 {
634 std::string rval("other");
635
636 return rval;
637 }
638
639 static std::string
641 {
642 std::string rval("float");
643
644 return rval;
645 }
646
647 static std::string
649 {
650 std::string rval("double");
651
652 return rval;
653 }
654};
655} // end namespace itk
656
657#ifndef ITK_MANUAL_INSTANTIATION
658# include "itkTransform.hxx"
659#endif
660
661#endif
Array2D class representing a 2D array.
Definition: itkArray2D.h:43
Array class with size defined at construction time.
Definition: itkArray.h:48
A templated class holding a n-Dimensional covariant vector.
Represent a diffusion tensor as used in DTI images.
Light weight base class for most itk classes.
A templated class holding a M x N size Matrix.
Definition: itkMatrix.h:53
Class to hold and manage different parameter types used during optimization.
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:54
ObjectType * GetPointer() const noexcept
Represent a symmetric tensor of second rank.
IdentifierType NumberOfParametersType
TParametersValueType ParametersValueType
Transform points and vectors from an input space to an output space.
Definition: itkTransform.h:84
virtual NumberOfParametersType GetNumberOfLocalParameters() const
Definition: itkTransform.h:421
std::string GetTransformTypeAsString() const override
virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &vector, const InputPointType &point) const
virtual void ComputeInverseJacobianWithRespectToPosition(const InputPointType &pnt, InverseJacobianPositionType &jacobian) const
void SetFixedParameters(const FixedParametersType &) override=0
void SetParameters(const ParametersType &) override=0
virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(const InputSymmetricSecondRankTensorType &) const
Definition: itkTransform.h:321
virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D(const InputDiffusionTensor3DType &inputTensor, const InputPointType &point) const
virtual bool IsLinear() const
Definition: itkTransform.h:482
bool GetInverse(Self *) const
Definition: itkTransform.h:449
std::enable_if_t< TImage::ImageDimension==VInputDimension &&TImage::ImageDimension==VOutputDimension, void > ApplyToImageMetadata(TImage *image) const
TransformCategoryEnum GetTransformCategory() const override
Definition: itkTransform.h:476
virtual OutputVectorPixelType TransformSymmetricSecondRankTensor(const InputVectorPixelType &) const
Definition: itkTransform.h:330
virtual OutputVectorPixelType TransformVector(const InputVectorPixelType &vector, const InputPointType &point) const
virtual InverseTransformBasePointer GetInverseTransform() const
Definition: itkTransform.h:461
unsigned int GetInputSpaceDimension() const override
Definition: itkTransform.h:107
virtual void ComputeJacobianWithRespectToParameters(const InputPointType &, JacobianType &) const =0
virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D(const InputDiffusionTensor3DType &) const
Definition: itkTransform.h:283
virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const
Definition: itkTransform.h:216
virtual void ComputeJacobianWithRespectToPosition(const InputPointType &, JacobianPositionType &) const
Definition: itkTransform.h:542
static std::string GetTransformTypeAsString(float *)
Definition: itkTransform.h:640
static std::string GetTransformTypeAsString(TType *)
Definition: itkTransform.h:632
~Transform() override=default
Transform()=default
const ParametersType & GetParameters() const override
Definition: itkTransform.h:386
const FixedParametersType & GetFixedParameters() const override
Definition: itkTransform.h:397
virtual OutputPointType TransformPoint(const InputPointType &) const =0
virtual void ComputeJacobianWithRespectToParametersCachedTemporaries(const InputPointType &p, JacobianType &jacobian, JacobianType &) const
Definition: itkTransform.h:527
virtual OutputVectorType TransformVector(const InputVectorType &vector, const InputPointType &point) const
virtual OutputVectorType TransformVector(const InputVectorType &) const
Definition: itkTransform.h:200
virtual void UpdateTransformParameters(const DerivativeType &update, ParametersValueType factor=1.0)
virtual OutputVectorPixelType TransformCovariantVector(const InputVectorPixelType &vector, const InputPointType &point) const
vnl_vector_fixed< TParametersValueType, VInputDimension > InputVnlVectorType
Definition: itkTransform.h:170
vnl_matrix_fixed< ParametersValueType, VOutputDimension, VInputDimension > JacobianPositionType
Definition: itkTransform.h:145
virtual OutputVectorPixelType TransformVector(const InputVectorPixelType &) const
Definition: itkTransform.h:232
vnl_matrix_fixed< ParametersValueType, VInputDimension, VOutputDimension > InverseJacobianPositionType
Definition: itkTransform.h:146
void CopyInParameters(const ParametersValueType *const begin, const ParametersValueType *const end) override
Transform(NumberOfParametersType numberOfParameters)
OutputDiffusionTensor3DType PreservationOfPrincipalDirectionDiffusionTensor3DReorientation(const InputDiffusionTensor3DType &, const InverseJacobianPositionType &) const
void SetParametersByValue(const ParametersType &p) override
Definition: itkTransform.h:364
static InverseTransformBasePointer InvertTransform(const TTransform &transform)
Definition: itkTransform.h:619
virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(const InputSymmetricSecondRankTensorType &inputTensor, const InputPointType &point) const
virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &vector, const InputPointType &point) const
virtual OutputVectorPixelType TransformDiffusionTensor3D(const InputVectorPixelType &) const
Definition: itkTransform.h:300
unsigned int GetOutputSpaceDimension() const override
Definition: itkTransform.h:114
virtual OutputVectorPixelType TransformDiffusionTensor3D(const InputVectorPixelType &inputTensor, const InputPointType &point) const
std::enable_if_t< TImage::ImageDimension==VInputDimension &&TImage::ImageDimension==VOutputDimension, void > ApplyToImageMetadata(SmartPointer< TImage > image) const
Definition: itkTransform.h:579
typename InverseTransformBaseType::Pointer InverseTransformBasePointer
Definition: itkTransform.h:181
itkLegacyMacro(virtual void ComputeJacobianWithRespectToPosition(const InputPointType &x, JacobianType &jacobian) const)
void CopyInFixedParameters(const FixedParametersValueType *const begin, const FixedParametersValueType *const end) override
ParametersValueType ScalarType
Definition: itkTransform.h:141
virtual OutputVectorPixelType TransformCovariantVector(const InputVectorPixelType &) const
Definition: itkTransform.h:266
NumberOfParametersType GetNumberOfParameters() const override
Definition: itkTransform.h:428
virtual NumberOfParametersType GetNumberOfFixedParameters() const
Definition: itkTransform.h:435
static std::string GetTransformTypeAsString(double *)
Definition: itkTransform.h:648
virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const
Definition: itkTransform.h:248
virtual OutputVectorPixelType TransformSymmetricSecondRankTensor(const InputVectorPixelType &inputTensor, const InputPointType &point) const
itkLegacyMacro(virtual void ComputeInverseJacobianWithRespectToPosition(const InputPointType &x, JacobianType &jacobian) const)
LightObject::Pointer InternalClone() const override
vnl_vector_fixed< TParametersValueType, VOutputDimension > OutputVnlVectorType
Definition: itkTransform.h:171
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:63
const char * GetNameOfClass() const override
static Pointer New()
SmartPointer< Self > Pointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
*par Constraints *The filter 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