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
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 &)is unimplemented for " << this->GetNameOfClass());
188 }
189
194 virtual OutputVectorType
195 TransformVector(const InputVectorType & vector, const InputPointType & point) const;
196
198 virtual OutputVnlVectorType
200 {
201 itkExceptionMacro("TransformVector( const InputVnlVectorType & ) is unimplemented for " << this->GetNameOfClass());
202 }
208 virtual OutputVnlVectorType
209 TransformVector(const InputVnlVectorType & vector, const InputPointType & point) const;
210
213 TransformVector(const InputVectorPixelType & itkNotUsed(vector)) const
214 {
215 itkExceptionMacro("TransformVector( const InputVectorPixelType & ) is unimplemented for "
216 << this->GetNameOfClass());
217 }
218
223 virtual OutputVectorPixelType
224 TransformVector(const InputVectorPixelType & vector, const InputPointType & point) const;
225
229 {
230 itkExceptionMacro("TransformCovariantVector( const InputCovariantVectorType & ) is unimplemented for "
231 << this->GetNameOfClass());
232 }
233
239 virtual OutputCovariantVectorType
241
242
245 TransformCovariantVector(const InputVectorPixelType & itkNotUsed(vector)) const
246 {
247 itkExceptionMacro("TransformCovariantVector(const InputVectorPixelType &)is unimplemented for "
248 << this->GetNameOfClass());
249 }
258
262 {
263 itkExceptionMacro("TransformDiffusionTensor3D( const InputDiffusionTensor3DType & ) is unimplemented for "
264 << this->GetNameOfClass());
265 }
266
274
277 TransformDiffusionTensor3D(const InputVectorPixelType & itkNotUsed(tensor)) const
278 {
279 itkExceptionMacro("TransformDiffusionTensor( const InputVectorPixelType & ) is unimplemented for "
280 << this->GetNameOfClass());
281 }
282
283 virtual OutputVectorPixelType
284 TransformDiffusionTensor3D(const InputVectorPixelType & inputTensor, const InputPointType & point) const;
293 const InputPointType & point) const;
294
298 {
299 itkExceptionMacro(
300 "TransformSymmetricSecondRankTensor( const InputSymmetricSecondRankTensorType & ) is unimplemented for "
301 << this->GetNameOfClass());
302 }
303
305 virtual OutputVectorPixelType
307 {
308 itkExceptionMacro("TransformSymmetricSecondRankTensor( const InputVectorPixelType & ) is unimplemented for "
309 << this->GetNameOfClass());
310 }
311
318 virtual OutputVectorPixelType
320
328 void
329 SetParameters(const ParametersType &) override = 0;
330
338 void
340 {
341 this->SetParameters(p);
342 }
343
348 void
349 CopyInParameters(const ParametersValueType * const begin, const ParametersValueType * const end) override;
350
355 void
357 const FixedParametersValueType * const end) override;
358
360 const ParametersType &
361 GetParameters() const override
362 {
363 return m_Parameters;
364 }
365
367 void
369
371 const FixedParametersType &
372 GetFixedParameters() const override
373 {
374 return m_FixedParameters;
375 }
376
384 virtual void
386
398 return this->GetNumberOfParameters();
399 }
400
402 NumberOfParametersType
403 GetNumberOfParameters() const override
404 {
405 return this->m_Parameters.Size();
406 }
407
408 /** Return the number of parameters that define the constant elements of a Transform */
411 {
412 return this->m_FixedParameters.Size();
413 }
414
423 bool
424 GetInverse(Self * itkNotUsed(inverseTransform)) const
425 {
426 return false;
427 }
428
435 virtual InverseTransformBasePointer
437 {
438 return nullptr;
439 }
440
442 std::string
443 GetTransformTypeAsString() const override;
444
446
451 GetTransformCategory() const override
452 {
453 return Superclass::TransformCategoryEnum::UnknownTransformCategory;
454 }
455
456 virtual bool
457 IsLinear() const
459 return this->GetTransformCategory() == Superclass::TransformCategoryEnum::Linear;
460 }
461
496 virtual void
498 JacobianType & itkNotUsed(jacobian)) const = 0;
499
500 virtual void
502 JacobianType & jacobian,
503 JacobianType & itkNotUsed(cachedJacobian)) const
504 {
505 // NOTE: default implementation is not optimized, and just falls back to original methods.
507 }
508
509
515 virtual void
517 JacobianPositionType & itkNotUsed(jacobian)) const
518 {
519 itkExceptionMacro("ComputeJacobianWithRespectToPosition( InputPointType, JacobianType ) is unimplemented for "
520 << this->GetNameOfClass());
521 }
522
523#if !defined(ITK_LEGACY_REMOVE)
524 itkLegacyMacro(virtual void ComputeJacobianWithRespectToPosition(const InputPointType & x, JacobianType & jacobian)
525 const;)
526#endif
527
533 virtual void
535
536#if !defined(ITK_LEGACY_REMOVE)
537 itkLegacyMacro(virtual void ComputeInverseJacobianWithRespectToPosition(const InputPointType & x,
538 JacobianType & jacobian) const;)
539#endif
540
551 template <typename TImage>
552 std::enable_if_t<TImage::ImageDimension == VInputDimension && TImage::ImageDimension == VOutputDimension, void>
553 ApplyToImageMetadata(TImage * image) const;
554 template <typename TImage>
555 std::enable_if_t<TImage::ImageDimension == VInputDimension && TImage::ImageDimension == VOutputDimension, void>
557 {
558 this->ApplyToImageMetadata(image.GetPointer()); // Delegate to the raw pointer signature
559 }
560
561protected:
567 typename LightObject::Pointer
568 InternalClone() const override;
569
571 Transform() = default;
572
574 ~Transform() override = default;
575
578
579 OutputDiffusionTensor3DType
581 const InverseJacobianPositionType &) const;
582
585 template <typename TTransform>
587 InvertTransform(const TTransform & transform)
588 {
589 const auto inverse = TTransform::New();
590 return transform.GetInverse(inverse) ? inverse.GetPointer() : nullptr;
591 }
592
593private:
594 template <typename TType>
595 static std::string
597 {
598 std::string rval("other");
599
600 return rval;
601 }
602
603 static std::string
605 {
606 std::string rval("float");
607
608 return rval;
609 }
610
611 static std::string
613 {
614 std::string rval("double");
615
616 return rval;
617 }
618};
619} // end namespace itk
620
621#ifndef ITK_MANUAL_INSTANTIATION
622# include "itkTransform.hxx"
623#endif
624
625#endif
Array2D class representing a 2D array.
Definition itkArray2D.h:43
Array class with size defined at construction time.
Definition itkArray.h:48
vnl_vector_fixed< TParametersValueType, SpaceDimension > OutputVnlVectorType
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
DiffusionTensor3D< CoordinateRepresentationType > OutputDiffusionTensor3DType
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
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 OutputVectorPixelType TransformDiffusionTensor3D(const InputVectorPixelType &tensor) const
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....