ITK 6.0.0
Insight Toolkit
 
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#include "itkImageBase.h"
31
32namespace itk
33{
83template <typename TParametersValueType, unsigned int VInputDimension = 3, unsigned int VOutputDimension = 3>
84class ITK_TEMPLATE_EXPORT Transform : public TransformBaseTemplate<TParametersValueType>
85{
86public:
87 ITK_DISALLOW_COPY_AND_MOVE(Transform);
90 using Self = Transform;
96 itkOverrideGetNameOfClassMacro(Transform);
97
99 static constexpr unsigned int InputSpaceDimension = VInputDimension;
100 static constexpr unsigned int OutputSpaceDimension = VOutputDimension;
101
106 unsigned int
107 GetInputSpaceDimension() const override
109 return VInputDimension;
110 }
113 unsigned int
114 GetOutputSpaceDimension() const override
116 return VOutputDimension;
122 using typename Superclass::ParametersType;
125
131 using JacobianPositionType = vnl_matrix_fixed<ParametersValueType, VOutputDimension, VInputDimension>;
132 using InverseJacobianPositionType = vnl_matrix_fixed<ParametersValueType, VInputDimension, VOutputDimension>;
142
143 /* Standard symmetric second rank tensor type for this class */
146
147 /* Standard tensor type for this class */
150
154
156 using InputVnlVectorType = vnl_vector_fixed<TParametersValueType, VInputDimension>;
157 using OutputVnlVectorType = vnl_vector_fixed<TParametersValueType, VOutputDimension>;
158
162
166
168
174
176
181 virtual OutputPointType
182 TransformPoint(const InputPointType &) const = 0;
183
185 virtual OutputVectorType
187 {
188 itkExceptionMacro("TransformVector(const InputVectorType &)is unimplemented for " << this->GetNameOfClass());
189 }
190
195 virtual OutputVectorType
196 TransformVector(const InputVectorType & vector, const InputPointType & point) const;
197
199 virtual OutputVnlVectorType
201 {
202 itkExceptionMacro("TransformVector( const InputVnlVectorType & ) is unimplemented for " << this->GetNameOfClass());
204
209 virtual OutputVnlVectorType
210 TransformVector(const InputVnlVectorType & vector, const InputPointType & point) const;
211
214 TransformVector(const InputVectorPixelType & itkNotUsed(vector)) const
215 {
216 itkExceptionMacro("TransformVector( const InputVectorPixelType & ) is unimplemented for "
217 << this->GetNameOfClass());
218 }
219
224 virtual OutputVectorPixelType
225 TransformVector(const InputVectorPixelType & vector, const InputPointType & point) const;
226
230 {
231 itkExceptionMacro("TransformCovariantVector( const InputCovariantVectorType & ) is unimplemented for "
232 << this->GetNameOfClass());
233 }
234
240 virtual OutputCovariantVectorType
242
243
246 TransformCovariantVector(const InputVectorPixelType & itkNotUsed(vector)) const
247 {
248 itkExceptionMacro("TransformCovariantVector(const InputVectorPixelType &)is unimplemented for "
249 << this->GetNameOfClass());
251
257 virtual OutputVectorPixelType
259
263 {
264 itkExceptionMacro("TransformDiffusionTensor3D( const InputDiffusionTensor3DType & ) is unimplemented for "
265 << this->GetNameOfClass());
266 }
267
275
278 TransformDiffusionTensor3D(const InputVectorPixelType & itkNotUsed(tensor)) const
279 {
280 itkExceptionMacro("TransformDiffusionTensor( const InputVectorPixelType & ) is unimplemented for "
281 << this->GetNameOfClass());
282 }
283
284 virtual OutputVectorPixelType
285 TransformDiffusionTensor3D(const InputVectorPixelType & inputTensor, const InputPointType & point) const;
286
294 const InputPointType & point) const;
295
299 {
300 itkExceptionMacro(
301 "TransformSymmetricSecondRankTensor( const InputSymmetricSecondRankTensorType & ) is unimplemented for "
302 << this->GetNameOfClass());
303 }
304
308 {
309 itkExceptionMacro("TransformSymmetricSecondRankTensor( const InputVectorPixelType & ) is unimplemented for "
310 << this->GetNameOfClass());
311 }
312
319 virtual OutputVectorPixelType
321
329 void
330 SetParameters(const ParametersType &) override = 0;
331
339 void
341 {
342 this->SetParameters(p);
343 }
344
349 void
350 CopyInParameters(const ParametersValueType * const begin, const ParametersValueType * const end) override;
351
356 void
358 const FixedParametersValueType * const end) override;
359
361 const ParametersType &
362 GetParameters() const override
363 {
364 return m_Parameters;
365 }
366
368 void
370
372 const FixedParametersType &
373 GetFixedParameters() const override
374 {
375 return m_FixedParameters;
376 }
377
385 virtual void
387
393 * the number of image dimensions. If it is an affine transform, this will
394 * be the same as the GetNumberOfParameters().
395 */
398 {
399 return this->GetNumberOfParameters();
400 }
401
403 NumberOfParametersType
404 GetNumberOfParameters() const override
405 {
406 return this->m_Parameters.Size();
407 }
408
410 virtual NumberOfParametersType
413 return this->m_FixedParameters.Size();
414 }
415
424 bool
425 GetInverse(Self * itkNotUsed(inverseTransform)) const
426 {
427 return false;
428 }
429
436 virtual InverseTransformBasePointer
438 {
439 return nullptr;
440 }
441
443 std::string
444 GetTransformTypeAsString() const override;
445
447
452 GetTransformCategory() const override
453 {
454 return Superclass::TransformCategoryEnum::UnknownTransformCategory;
455 }
456
457 virtual bool
458 IsLinear() const
459 {
460 return this->GetTransformCategory() == Superclass::TransformCategoryEnum::Linear;
461 }
462
497 virtual void
499 JacobianType & itkNotUsed(jacobian)) const = 0;
500
501 virtual void
503 JacobianType & jacobian,
504 JacobianType & itkNotUsed(cachedJacobian)) const
505 {
506 // NOTE: default implementation is not optimized, and just falls back to original methods.
508 }
509
510
516 virtual void
518 JacobianPositionType & itkNotUsed(jacobian)) const
519 {
520 itkExceptionMacro("ComputeJacobianWithRespectToPosition( InputPointType, JacobianType ) is unimplemented for "
521 << this->GetNameOfClass());
522 }
523
524#if !defined(ITK_LEGACY_REMOVE)
525 itkLegacyMacro(virtual void ComputeJacobianWithRespectToPosition(const InputPointType & x, JacobianType & jacobian)
526 const;)
527#endif
528
534 virtual void
536
537#if !defined(ITK_LEGACY_REMOVE)
538 itkLegacyMacro(virtual void ComputeInverseJacobianWithRespectToPosition(const InputPointType & x,
539 JacobianType & jacobian) const;)
540#endif
541
552#if defined(ITK_WRAPPING_PARSER) || defined(SWIG_VERSION)
553 // This variant replaces a compile time error with a runtime error.
554 // It is therefore suitable to only be available for wrapping.
555 void
557 {
558 if (VInputDimension != VOutputDimension)
559 {
560 itkExceptionMacro("ApplyToImageMetadata is only usable with transforms with equal input and output dimensions."
561 " This class is: "
562 << this->GetNameOfClass());
563 }
564 this->ApplyToImageMetadataInternal(image);
565 }
566#else
567 // These two variants are only available in C++.
568 // In case of different input and output dimensions, compile error will be produced.
569 template <typename TImage>
570 std::enable_if_t<TImage::ImageDimension == VInputDimension && TImage::ImageDimension == VOutputDimension, void>
571 ApplyToImageMetadata(TImage * image) const
572 {
573 this->ApplyToImageMetadataInternal(image);
574 }
575 template <typename TImage>
576 std::enable_if_t<TImage::ImageDimension == VInputDimension && TImage::ImageDimension == VOutputDimension, void>
581#endif
583
584protected:
591 InternalClone() const override;
592
594 Transform() = default;
595
597 ~Transform() override = default;
598
601
602 OutputDiffusionTensor3DType
604 const InverseJacobianPositionType &) const;
605
608 template <typename TTransform>
610 InvertTransform(const TTransform & transform)
611 {
612 const auto inverse = TTransform::New();
613 return transform.GetInverse(inverse) ? inverse.GetPointer() : nullptr;
614 }
615
616private:
618 void
620
621 template <typename TType>
622 static std::string
624 {
625 std::string rval("other");
626
627 return rval;
628 }
629
630 static std::string
632 {
633 std::string rval("float");
634
635 return rval;
636 }
637
638 static std::string
640 {
641 std::string rval("double");
642
643 return rval;
644 }
645};
646} // end namespace itk
647
648#ifndef ITK_MANUAL_INSTANTIATION
649# include "itkTransform.hxx"
650#endif
651
652#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.
CovariantVector< CoordinateRepresentationType, VOutputDimension > OutputCovariantVectorType
DiffusionTensor3D< CoordinateRepresentationType > OutputDiffusionTensor3DType
vnl_matrix_fixed< ParametersValueType, VInputDimension, VOutputDimension > InverseJacobianPositionType
Base class for templated image classes.
SmartPointer< Self > Pointer
vnl_vector_fixed< TParametersValueType, Self::InputSpaceDimension > InputVnlVectorType
vnl_vector_fixed< TParametersValueType, Self::OutputSpaceDimension > OutputVnlVectorType
A templated class holding a M x N size Matrix.
Definition itkMatrix.h:71
vnl_matrix_fixed< ParametersValueType, VOutputDimension, VInputDimension > JacobianPositionType
Transform< TParametersValueType, VDimension, VSubDimensions > Superclass
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
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
Transform< TParametersValueType, VOutputDimension, VInputDimension > InverseTransformBaseType
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
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 ApplyToImageMetadataInternal(ImageBase< VInputDimension > *image) 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
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 OutputVectorPixelType TransformDiffusionTensor3D(const InputVectorPixelType &tensor) const
NumberOfParametersType GetNumberOfParameters() const 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, VInputDimension > InputVectorType
Vector< TParametersValueType, VOutputDimension > OutputVectorType
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....