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:
88
90 using Self = Transform;
99 static constexpr unsigned int InputSpaceDimension = VInputDimension;
100 static constexpr unsigned int OutputSpaceDimension = VOutputDimension;
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
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());
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
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
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
401 * computation of the jacobian wrt only the local support region.
402 * For instance, in the case of a deformation field, this will be equal to
403 * the number of image dimensions. If it is an affine transform, this will
404 * be the same as the GetNumberOfParameters().
405 */
408 {
409 return this->GetNumberOfParameters();
410 }
411
412 /** Return the number of parameters that completely define the Transform */
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 {
465 }
466
467 virtual bool
468 IsLinear() const
469 {
471 }
472
507 virtual void
509 JacobianType & itkNotUsed(jacobian)) const = 0;
511
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.
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
536#if !defined(ITK_LEGACY_REMOVE)
537 itkLegacyMacro(virtual void ComputeJacobianWithRespectToPosition(const InputPointType & x, JacobianType & jacobian)
538 const;)
539#endif
540
546 virtual void
548
549#if !defined(ITK_LEGACY_REMOVE)
550 itkLegacyMacro(virtual void ComputeInverseJacobianWithRespectToPosition(const InputPointType & x,
551 JacobianType & jacobian) const;)
552#endif
553
563 template <typename TImage>
564 std::enable_if_t<TImage::ImageDimension == VInputDimension && TImage::ImageDimension == VOutputDimension, void>
565 ApplyToImageMetadata(TImage * image) const;
566 template <typename TImage>
567 std::enable_if_t<TImage::ImageDimension == VInputDimension && TImage::ImageDimension == VOutputDimension, void>
569 {
570 this->ApplyToImageMetadata(image.GetPointer()); // Delegate to the raw pointer signature
571 }
572
573
574protected:
580 typename LightObject::Pointer
581 InternalClone() const override;
582
584 Transform() = default;
585
587 ~Transform() override = default;
588
591
592 OutputDiffusionTensor3DType
594 const InverseJacobianPositionType &) const;
595
598 template <typename TTransform>
600 InvertTransform(const TTransform & transform)
601 {
602 const auto inverse = TTransform::New();
603 return transform.GetInverse(inverse) ? inverse.GetPointer() : nullptr;
604 }
605
606
607private:
608 template <typename TType>
609 static std::string
611 {
612 std::string rval("other");
613
614 return rval;
615 }
616
617 static std::string
619 {
620 std::string rval("float");
621
622 return rval;
623 }
624
625 static std::string
627 {
628 std::string rval("double");
629
630 return rval;
631 }
632};
633} // end namespace itk
634
635#ifndef ITK_MANUAL_INSTANTIATION
636# include "itkTransform.hxx"
637#endif
638
639#endif
TransformBaseTemplate()=default
IdentifierType NumberOfParametersType
itkOverrideGetNameOfClassMacro(TransformBaseTemplate)
ITK_DISALLOW_COPY_AND_MOVE(TransformBaseTemplate)
static constexpr TransformCategoryEnum Linear
static constexpr TransformCategoryEnum UnknownTransformCategory
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 > OutputVectorPixelType
vnl_matrix_fixed< ParametersValueType, VInputDimension, VOutputDimension > InverseJacobianPositionType
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:53
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.
Transform points and vectors from an input space to an output space.
VariableLengthVector< TParametersValueType > OutputVectorPixelType
virtual NumberOfParametersType GetNumberOfLocalParameters() const
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
OptimizerParameters< FixedParametersValueType > FixedParametersType
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
TransformBaseTemplateEnums::TransformCategory TransformCategoryEnum
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
SymmetricSecondRankTensor< TParametersValueType, VOutputDimension > OutputSymmetricSecondRankTensorType
const FixedParametersType & GetFixedParameters() const override
VariableLengthVector< TParametersValueType > InputVectorPixelType
OptimizerParameters< ParametersValueType > ParametersType
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
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
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
const char * GetNameOfClass() const override
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