Loading [MathJax]/extensions/tex2jax.js
ITK 6.0.0
Insight Toolkit
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
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);
89 using Self = Transform;
95 itkOverrideGetNameOfClassMacro(Transform);
98 static constexpr unsigned int InputSpaceDimension = VInputDimension;
99 static constexpr unsigned int OutputSpaceDimension = VOutputDimension;
100
103
105 unsigned int
106 GetInputSpaceDimension() const override
108 return VInputDimension;
109 }
110
112 unsigned int
113 GetOutputSpaceDimension() const override
114 {
115 return VOutputDimension;
121 using typename Superclass::ParametersType;
122 using typename Superclass::ParametersValueType;
130 using JacobianPositionType = vnl_matrix_fixed<ParametersValueType, VOutputDimension, VInputDimension>;
131 using InverseJacobianPositionType = vnl_matrix_fixed<ParametersValueType, VInputDimension, VOutputDimension>;
141
142 /* Standard symmetric second rank tensor type for this class */
146 /* Standard tensor type for this class */
149
155 using InputVnlVectorType = vnl_vector_fixed<TParametersValueType, VInputDimension>;
156 using OutputVnlVectorType = vnl_vector_fixed<TParametersValueType, VOutputDimension>;
167
169
173
175
180 virtual OutputPointType
181 TransformPoint(const InputPointType &) const = 0;
182
184 virtual OutputVectorType
186 {
187 itkExceptionMacro("TransformVector(const InputVectorType &)"
188 "is unimplemented for "
189 << this->GetNameOfClass());
190 }
191
196 virtual OutputVectorType
197 TransformVector(const InputVectorType & vector, const InputPointType & point) const;
198
200 virtual OutputVnlVectorType
202 {
203 itkExceptionMacro("TransformVector( const InputVnlVectorType & ) is "
204 "unimplemented for "
205 << this->GetNameOfClass());
206 }
207
212 virtual OutputVnlVectorType
213 TransformVector(const InputVnlVectorType & vector, const InputPointType & point) const;
214
217 TransformVector(const InputVectorPixelType & itkNotUsed(vector)) const
218 {
219 itkExceptionMacro("TransformVector( const InputVectorPixelType & ) is "
220 "unimplemented for "
221 << this->GetNameOfClass());
222 }
223
229 TransformVector(const InputVectorPixelType & vector, const InputPointType & point) const;
230
234 {
235 itkExceptionMacro("TransformCovariantVector( const InputCovariantVectorType & ) is "
236 "unimplemented for "
237 << this->GetNameOfClass());
238 }
239
245 virtual OutputCovariantVectorType
247
248
251 TransformCovariantVector(const InputVectorPixelType & itkNotUsed(vector)) const
252 {
253 itkExceptionMacro("TransformCovariantVector(const InputVectorPixelType &)"
254 "is unimplemented for "
255 << this->GetNameOfClass());
256 }
257
263 virtual OutputVectorPixelType
265
269 {
270 itkExceptionMacro("TransformDiffusionTensor3D( const InputDiffusionTensor3DType & ) is "
271 "unimplemented for "
272 << this->GetNameOfClass());
273 }
274
280 virtual OutputDiffusionTensor3DType
282
285 TransformDiffusionTensor3D(const InputVectorPixelType & itkNotUsed(tensor)) const
286 {
287 itkExceptionMacro("TransformDiffusionTensor( const InputVectorPixelType & ) is "
288 "unimplemented for "
289 << this->GetNameOfClass());
290 }
291
292 virtual OutputVectorPixelType
293 TransformDiffusionTensor3D(const InputVectorPixelType & inputTensor, const InputPointType & point) const;
294
302 const InputPointType & point) const;
303
307 {
308 itkExceptionMacro("TransformSymmetricSecondRankTensor( const InputSymmetricSecondRankTensorType & ) is "
309 "unimplemented for "
310 << this->GetNameOfClass());
311 }
312
314 virtual OutputVectorPixelType
316 {
317 itkExceptionMacro("TransformSymmetricSecondRankTensor( const InputVectorPixelType & ) is "
318 "unimplemented for "
319 << this->GetNameOfClass());
320 }
321
328 virtual OutputVectorPixelType
330
338 void
339 SetParameters(const ParametersType &) override = 0;
340
348 void
350 {
351 this->SetParameters(p);
352 }
353
358 void
359 CopyInParameters(const ParametersValueType * const begin, const ParametersValueType * const end) override;
360
365 void
367 const FixedParametersValueType * const end) override;
368
370 const ParametersType &
371 GetParameters() const override
372 {
373 return m_Parameters;
374 }
375
377 void
379
381 const FixedParametersType &
382 GetFixedParameters() const override
383 {
384 return m_FixedParameters;
385 }
386
394 virtual void
396
397 /** Return the number of local parameters that completely defines the
398 * Transform at an individual voxel.
399 * For transforms with local support, this will enable downstream
400 * computation of the jacobian wrt only the local support region.
401 * For instance, in the case of a deformation field, this will be equal to
402 * the number of image dimensions. If it is an affine transform, this will
403 * be the same as the GetNumberOfParameters().
404 */
407 {
408 return this->GetNumberOfParameters();
409 }
410
412 NumberOfParametersType
413 GetNumberOfParameters() const override
414 {
415 return this->m_Parameters.Size();
417
419 virtual NumberOfParametersType
421 {
422 return this->m_FixedParameters.Size();
423 }
433 bool
434 GetInverse(Self * itkNotUsed(inverseTransform)) const
435 {
436 return false;
437 }
438
445 virtual InverseTransformBasePointer
447 {
448 return nullptr;
449 }
452 std::string
453 GetTransformTypeAsString() const override;
454
456
461 GetTransformCategory() const override
462 {
463 return Superclass::TransformCategoryEnum::UnknownTransformCategory;
464 }
465
466 virtual bool
467 IsLinear() const
468 {
469 return (this->GetTransformCategory() == Superclass::TransformCategoryEnum::Linear);
470 }
471
506 virtual void
508 JacobianType & itkNotUsed(jacobian)) const = 0;
509
510 virtual void
512 JacobianType & jacobian,
513 JacobianType & itkNotUsed(cachedJacobian)) const
514 {
515 // NOTE: default implementation is not optimized, and just falls back to original methods.
517 }
518
519
525 virtual void
527 JacobianPositionType & itkNotUsed(jacobian)) const
528 {
529 itkExceptionMacro("ComputeJacobianWithRespectToPosition( InputPointType, JacobianType )"
530 " is unimplemented for "
531 << this->GetNameOfClass());
532 }
533
534#if !defined(ITK_LEGACY_REMOVE)
535 itkLegacyMacro(virtual void ComputeJacobianWithRespectToPosition(const InputPointType & x, JacobianType & jacobian)
536 const;)
537#endif
538
544 virtual void
546
547#if !defined(ITK_LEGACY_REMOVE)
548 itkLegacyMacro(virtual void ComputeInverseJacobianWithRespectToPosition(const InputPointType & x,
549 JacobianType & jacobian) const;)
550#endif
551
562 template <typename TImage>
563 std::enable_if_t<TImage::ImageDimension == VInputDimension && TImage::ImageDimension == VOutputDimension, void>
564 ApplyToImageMetadata(TImage * image) const;
565 template <typename TImage>
566 std::enable_if_t<TImage::ImageDimension == VInputDimension && TImage::ImageDimension == VOutputDimension, void>
568 {
569 this->ApplyToImageMetadata(image.GetPointer()); // Delegate to the raw pointer signature
570 }
571
572protected:
578 typename LightObject::Pointer
579 InternalClone() const override;
580
582 Transform() = default;
583
585 ~Transform() override = default;
586
589
590 OutputDiffusionTensor3DType
592 const InverseJacobianPositionType &) const;
593
596 template <typename TTransform>
598 InvertTransform(const TTransform & transform)
599 {
600 const auto inverse = TTransform::New();
601 return transform.GetInverse(inverse) ? inverse.GetPointer() : nullptr;
602 }
603
604private:
605 template <typename TType>
606 static std::string
608 {
609 std::string rval("other");
610
611 return rval;
612 }
613
614 static std::string
616 {
617 std::string rval("float");
618
619 return rval;
620 }
621
622 static std::string
624 {
625 std::string rval("double");
626
627 return rval;
628 }
629};
630} // end namespace itk
631
632#ifndef ITK_MANUAL_INSTANTIATION
633# include "itkTransform.hxx"
634#endif
635
636#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.
VariableLengthVector< CoordinateRepresentationType > InputVectorPixelType
vnl_vector_fixed< TParametersValueType, VInputDimension > InputVnlVectorType
VariableLengthVector< CoordinateRepresentationType > OutputVectorPixelType
SmartPointer< Self > Pointer
vnl_vector_fixed< TParametersValueType, Self::OutputSpaceDimension > OutputVnlVectorType
A templated class holding a M x N size Matrix.
Definition itkMatrix.h:53
vnl_matrix_fixed< ParametersValueType, VInputDimension, VOutputDimension > InverseJacobianPositionType
A templated class holding a geometric point in n-Dimensional space.
Definition itkPoint.h:54
Implements transparent reference counting.
ObjectType * GetPointer() const noexcept
Represent a symmetric tensor of second rank.
IdentifierType NumberOfParametersType
TransformBaseTemplateEnums::TransformCategory TransformCategoryEnum
Transform points and vectors from an input space to an output space.
OptimizerParameters< ParametersValueType > ParametersType
VariableLengthVector< TParametersValueType > OutputVectorPixelType
virtual NumberOfParametersType GetNumberOfLocalParameters() const
std::string GetTransformTypeAsString() const override
virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &vector, const InputPointType &point) const
DiffusionTensor3D< TParametersValueType > InputDiffusionTensor3DType
virtual void ComputeInverseJacobianWithRespectToPosition(const InputPointType &pnt, InverseJacobianPositionType &jacobian) const
void SetFixedParameters(const FixedParametersType &) override=0
void SetParameters(const ParametersType &) override=0
virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D(const InputDiffusionTensor3DType &inputTensor, const InputPointType &point) const
Matrix< double, Self::OutputSpaceDimension, Self::InputSpaceDimension > DirectionChangeMatrix
virtual bool IsLinear() const
std::enable_if_t< TImage::ImageDimension==VInputDimension &&TImage::ImageDimension==VOutputDimension, void > ApplyToImageMetadata(TImage *image) const
virtual OutputVectorPixelType TransformVector(const InputVectorPixelType &vector) const
virtual void ComputeJacobianWithRespectToParameters(const InputPointType &p, JacobianType &jacobian) const =0
virtual void ComputeJacobianWithRespectToPosition(const InputPointType &x, JacobianPositionType &jacobian) const
Matrix< double, Self::InputSpaceDimension, Self::InputSpaceDimension > InputDirectionMatrix
Matrix< TParametersValueType, Self::OutputSpaceDimension, Self::InputSpaceDimension > MatrixType
virtual OutputVectorPixelType TransformSymmetricSecondRankTensor(const InputVectorPixelType &tensor) const
TransformCategoryEnum GetTransformCategory() const override
virtual void ComputeJacobianWithRespectToParametersCachedTemporaries(const InputPointType &p, JacobianType &jacobian, JacobianType &cachedJacobian) const
virtual OutputVectorPixelType TransformVector(const InputVectorPixelType &vector, const InputPointType &point) const
virtual InverseTransformBasePointer GetInverseTransform() const
Point< TParametersValueType, VOutputDimension > OutputPointType
unsigned int GetInputSpaceDimension() const override
virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const
virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(const InputSymmetricSecondRankTensorType &tensor) const
static std::string GetTransformTypeAsString(float *)
static std::string GetTransformTypeAsString(TType *)
~Transform() override=default
Transform()=default
const ParametersType & GetParameters() const override
SymmetricSecondRankTensor< TParametersValueType, VInputDimension > InputSymmetricSecondRankTensorType
OptimizerParameters< FixedParametersValueType > FixedParametersType
SymmetricSecondRankTensor< TParametersValueType, VOutputDimension > OutputSymmetricSecondRankTensorType
const FixedParametersType & GetFixedParameters() const override
VariableLengthVector< TParametersValueType > InputVectorPixelType
bool GetInverse(Self *inverseTransform) const
virtual OutputPointType TransformPoint(const InputPointType &) const =0
CovariantVector< TParametersValueType, VOutputDimension > OutputCovariantVectorType
virtual OutputVectorType TransformVector(const InputVectorType &vector, const InputPointType &point) const
Matrix< double, Self::OutputSpaceDimension, Self::OutputSpaceDimension > OutputDirectionMatrix
virtual OutputVectorType TransformVector(const InputVectorType &) const
virtual void UpdateTransformParameters(const DerivativeType &update, ParametersValueType factor=1.0)
virtual OutputVectorPixelType TransformCovariantVector(const InputVectorPixelType &vector) const
TransformBaseTemplate< TParametersValueType > Superclass
TransformBaseTemplateEnums::TransformCategory TransformCategoryEnum
virtual OutputVectorPixelType TransformCovariantVector(const InputVectorPixelType &vector, const InputPointType &point) const
vnl_vector_fixed< TParametersValueType, VInputDimension > InputVnlVectorType
vnl_matrix_fixed< ParametersValueType, VOutputDimension, VInputDimension > JacobianPositionType
vnl_matrix_fixed< ParametersValueType, VInputDimension, VOutputDimension > InverseJacobianPositionType
void CopyInParameters(const ParametersValueType *const begin, const ParametersValueType *const end) override
DiffusionTensor3D< TParametersValueType > OutputDiffusionTensor3DType
Transform(NumberOfParametersType numberOfParameters)
OutputDiffusionTensor3DType PreservationOfPrincipalDirectionDiffusionTensor3DReorientation(const InputDiffusionTensor3DType &, const InverseJacobianPositionType &) const
void SetParametersByValue(const ParametersType &p) override
static InverseTransformBasePointer InvertTransform(const TTransform &transform)
Point< TParametersValueType, VInputDimension > InputPointType
virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(const InputSymmetricSecondRankTensorType &inputTensor, const InputPointType &point) const
virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &vector, const InputPointType &point) const
unsigned int GetOutputSpaceDimension() const override
virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D(const InputDiffusionTensor3DType &tensor) const
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
typename InverseTransformBaseType::Pointer InverseTransformBasePointer
CovariantVector< TParametersValueType, VInputDimension > InputCovariantVectorType
Vector< TParametersValueType, VInputDimension > InputVectorType
void CopyInFixedParameters(const FixedParametersValueType *const begin, const FixedParametersValueType *const end) override
virtual NumberOfParametersType GetNumberOfFixedParameters() const
static std::string GetTransformTypeAsString(double *)
virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const
virtual OutputVectorPixelType TransformSymmetricSecondRankTensor(const InputVectorPixelType &inputTensor, const InputPointType &point) const
LightObject::Pointer InternalClone() const override
Vector< TParametersValueType, VOutputDimension > OutputVectorType
vnl_vector_fixed< TParametersValueType, VOutputDimension > OutputVnlVectorType
A templated class holding a n-Dimensional vector.
Definition itkVector.h:63
Vector< TParametersValueType, VOutputDimension > OutputVectorType
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....