ITK  6.0.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>
85public:
86 ITK_DISALLOW_COPY_AND_MOVE(Transform);
90 using Self = Transform;
96 itkOverrideGetNameOfClassMacro(Transform);
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;
117 }
118
122 using typename Superclass::ParametersType;
125
131 using JacobianPositionType = vnl_matrix_fixed<ParametersValueType, VOutputDimension, VInputDimension>;
132 using InverseJacobianPositionType = vnl_matrix_fixed<ParametersValueType, VInputDimension, VOutputDimension>;
133
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
166
168
170
174
176
181 virtual OutputPointType
182 TransformPoint(const InputPointType &) const = 0;
183
185 virtual OutputVectorType
187 {
188 itkExceptionMacro("TransformVector(const InputVectorType &)"
189 "is unimplemented for "
190 << this->GetNameOfClass());
191 }
192
197 virtual OutputVectorType
198 TransformVector(const InputVectorType & vector, const InputPointType & point) const;
199
201 virtual OutputVnlVectorType
203 {
204 itkExceptionMacro("TransformVector( const InputVnlVectorType & ) is "
205 "unimplemented for "
206 << this->GetNameOfClass());
207 }
208
213 virtual OutputVnlVectorType
215
218 TransformVector(const InputVectorPixelType & itkNotUsed(vector)) const
219 {
220 itkExceptionMacro("TransformVector( const InputVectorPixelType & ) is "
221 "unimplemented for "
222 << this->GetNameOfClass());
223 }
224
229 virtual OutputVectorPixelType
231
235 {
236 itkExceptionMacro("TransformCovariantVector( const InputCovariantVectorType & ) is "
237 "unimplemented for "
238 << this->GetNameOfClass());
239 }
240
246 virtual OutputCovariantVectorType
248
249
252 TransformCovariantVector(const InputVectorPixelType & itkNotUsed(vector)) const
253 {
254 itkExceptionMacro("TransformCovariantVector(const InputVectorPixelType &)"
255 "is unimplemented for "
256 << this->GetNameOfClass());
257 }
258
264 virtual OutputVectorPixelType
266
270 {
271 itkExceptionMacro("TransformDiffusionTensor3D( const InputDiffusionTensor3DType & ) is "
272 "unimplemented for "
273 << this->GetNameOfClass());
274 }
275
281 virtual OutputDiffusionTensor3DType
283
286 TransformDiffusionTensor3D(const InputVectorPixelType & itkNotUsed(tensor)) const
287 {
288 itkExceptionMacro("TransformDiffusionTensor( const InputVectorPixelType & ) is "
289 "unimplemented for "
290 << this->GetNameOfClass());
291 }
292
293 virtual OutputVectorPixelType
295
303 const InputPointType & point) const;
304
308 {
309 itkExceptionMacro("TransformSymmetricSecondRankTensor( const InputSymmetricSecondRankTensorType & ) is "
310 "unimplemented for "
311 << this->GetNameOfClass());
312 }
313
315 virtual OutputVectorPixelType
317 {
318 itkExceptionMacro("TransformSymmetricSecondRankTensor( const InputVectorPixelType & ) is "
319 "unimplemented for "
320 << this->GetNameOfClass());
321 }
322
329 virtual OutputVectorPixelType
331
339 void
340 SetParameters(const ParametersType &) override = 0;
341
349 void
351 {
352 this->SetParameters(p);
353 }
354
359 void
360 CopyInParameters(const ParametersValueType * const begin, const ParametersValueType * const end) override;
361
366 void
368 const FixedParametersValueType * const end) override;
369
371 const ParametersType &
372 GetParameters() const override
373 {
374 return m_Parameters;
375 }
376
378 void
380
382 const FixedParametersType &
383 GetFixedParameters() const override
384 {
385 return m_FixedParameters;
386 }
387
395 virtual void
397
408 {
409 return this->GetNumberOfParameters();
410 }
411
413 NumberOfParametersType
414 GetNumberOfParameters() const override
415 {
416 return this->m_Parameters.Size();
417 }
418
422 {
423 return this->m_FixedParameters.Size();
424 }
425
434 bool
435 GetInverse(Self * itkNotUsed(inverseTransform)) const
436 {
437 return false;
438 }
439
446 virtual InverseTransformBasePointer
448 {
449 return nullptr;
450 }
451
453 std::string
454 GetTransformTypeAsString() const override;
455
457
462 GetTransformCategory() const override
463 {
464 return Superclass::TransformCategoryEnum::UnknownTransformCategory;
465 }
466
467 virtual bool
468 IsLinear() const
469 {
470 return (this->GetTransformCategory() == Superclass::TransformCategoryEnum::Linear);
471 }
472
507 virtual void
509 JacobianType & itkNotUsed(jacobian)) const = 0;
512 virtual void
514 JacobianType & jacobian,
515 JacobianType & itkNotUsed(cachedJacobian)) const
516 {
517 // NOTE: default implementation is not optimized, and just falls back to original methods.
518 this->ComputeJacobianWithRespectToParameters(p, jacobian);
519 }
520
521
527 virtual void
529 JacobianPositionType & itkNotUsed(jacobian)) const
530 {
531 itkExceptionMacro("ComputeJacobianWithRespectToPosition( InputPointType, JacobianType )"
532 " is unimplemented for "
533 << this->GetNameOfClass());
534 }
535 itkLegacyMacro(virtual void ComputeJacobianWithRespectToPosition(const InputPointType & x, JacobianType & jacobian)
536 const;)
545 virtual void
546 ComputeInverseJacobianWithRespectToPosition(const InputPointType & pnt, InverseJacobianPositionType & jacobian) const;
547 itkLegacyMacro(virtual void ComputeInverseJacobianWithRespectToPosition(const InputPointType & x,
548 JacobianType & jacobian) const;)
560 template <typename TImage>
561 std::enable_if_t<TImage::ImageDimension == VInputDimension && TImage::ImageDimension == VOutputDimension, void>
562 ApplyToImageMetadata(TImage * image) const;
563 template <typename TImage>
564 std::enable_if_t<TImage::ImageDimension == VInputDimension && TImage::ImageDimension == VOutputDimension, void>
566 {
567 this->ApplyToImageMetadata(image.GetPointer()); // Delegate to the raw pointer signature
568 }
571protected:
577 typename LightObject::Pointer
578 InternalClone() const override;
579
581 Transform() = default;
582
584 ~Transform() override = default;
585
586 mutable ParametersType m_Parameters{};
587 mutable FixedParametersType m_FixedParameters{};
588
589 OutputDiffusionTensor3DType
591 const InverseJacobianPositionType &) const;
592
595 template <typename TTransform>
597 InvertTransform(const TTransform & transform)
598 {
599 const auto inverse = TTransform::New();
600 return transform.GetInverse(inverse) ? inverse.GetPointer() : nullptr;
601 }
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
OptimizerParameters< FixedParametersValueType > FixedParametersType
IdentifierType NumberOfParametersType
TParametersValueType ParametersValueType
OptimizerParameters< ParametersValueType > ParametersType
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.
vnl_vector_fixed< double, Self::InputSpaceDimension > InputVnlVectorType
vnl_vector_fixed< double, Self::OutputSpaceDimension > OutputVnlVectorType
A templated class holding a M x N size Matrix.
Definition: itkMatrix.h:53
vnl_matrix_fixed< ParametersValueType, VOutputDimension, VInputDimension > JacobianPositionType
Definition: itkTransform.h:131
Class to hold and manage different parameter types used during optimization.
Similarity2DTransform of a vector space (e.g. space coordinates)
ObjectType * GetPointer() const noexcept
Represent a symmetric tensor of second rank.
Transform points and vectors from an input space to an output space.
Definition: itkTransform.h:84
virtual NumberOfParametersType GetNumberOfLocalParameters() const
Definition: itkTransform.h:407
virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &vector, const InputPointType &point) const
void SetFixedParameters(const FixedParametersType &) override=0
void SetParameters(const ParametersType &) override=0
virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(const InputSymmetricSecondRankTensorType &) const
Definition: itkTransform.h:307
virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D(const InputDiffusionTensor3DType &inputTensor, const InputPointType &point) const
virtual bool IsLinear() const
Definition: itkTransform.h:468
bool GetInverse(Self *) const
Definition: itkTransform.h:435
TransformCategoryEnum GetTransformCategory() const override
Definition: itkTransform.h:462
virtual OutputVectorPixelType TransformSymmetricSecondRankTensor(const InputVectorPixelType &) const
Definition: itkTransform.h:316
virtual OutputVectorPixelType TransformVector(const InputVectorPixelType &vector, const InputPointType &point) const
template< typename TImage > std std::enable_if_t< TImage::ImageDimension==VInputDimension &&TImage::ImageDimension==VOutputDimension, void > ApplyToImageMetadata(SmartPointer< TImage > image) const
Definition: itkTransform.h:565
virtual InverseTransformBasePointer GetInverseTransform() const
Definition: itkTransform.h:447
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:269
virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const
Definition: itkTransform.h:202
virtual void ComputeJacobianWithRespectToPosition(const InputPointType &, JacobianPositionType &) const
Definition: itkTransform.h:528
static std::string GetTransformTypeAsString(float *)
Definition: itkTransform.h:615
static std::string GetTransformTypeAsString(TType *)
Definition: itkTransform.h:607
~Transform() override=default
Transform()=default
const ParametersType & GetParameters() const override
Definition: itkTransform.h:372
const FixedParametersType & GetFixedParameters() const override
Definition: itkTransform.h:383
virtual OutputPointType TransformPoint(const InputPointType &) const =0
virtual void ComputeJacobianWithRespectToParametersCachedTemporaries(const InputPointType &p, JacobianType &jacobian, JacobianType &) const
Definition: itkTransform.h:513
virtual OutputVectorType TransformVector(const InputVectorType &vector, const InputPointType &point) const
virtual OutputVectorType TransformVector(const InputVectorType &) const
Definition: itkTransform.h:186
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:156
vnl_matrix_fixed< ParametersValueType, VOutputDimension, VInputDimension > JacobianPositionType
Definition: itkTransform.h:131
virtual OutputVectorPixelType TransformVector(const InputVectorPixelType &) const
Definition: itkTransform.h:218
vnl_matrix_fixed< ParametersValueType, VInputDimension, VOutputDimension > InverseJacobianPositionType
Definition: itkTransform.h:132
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:350
static InverseTransformBasePointer InvertTransform(const TTransform &transform)
Definition: itkTransform.h:597
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:286
unsigned int GetOutputSpaceDimension() const override
Definition: itkTransform.h:114
virtual OutputVectorPixelType TransformDiffusionTensor3D(const InputVectorPixelType &inputTensor, const InputPointType &point) const
typename InverseTransformBaseType::Pointer InverseTransformBasePointer
Definition: itkTransform.h:167
void CopyInFixedParameters(const FixedParametersValueType *const begin, const FixedParametersValueType *const end) override
virtual OutputVectorPixelType TransformCovariantVector(const InputVectorPixelType &) const
Definition: itkTransform.h:252
NumberOfParametersType GetNumberOfParameters() const override
Definition: itkTransform.h:414
virtual NumberOfParametersType GetNumberOfFixedParameters() const
Definition: itkTransform.h:421
static std::string GetTransformTypeAsString(double *)
Definition: itkTransform.h:623
virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const
Definition: itkTransform.h:234
virtual OutputVectorPixelType TransformSymmetricSecondRankTensor(const InputVectorPixelType &inputTensor, const InputPointType &point) const
LightObject::Pointer InternalClone() const override
vnl_vector_fixed< TParametersValueType, VOutputDimension > OutputVnlVectorType
Definition: itkTransform.h:157
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