Loading...
Searching...
No Matches
elxTransformBase.h
Go to the documentation of this file.
/*=========================================================================
*
* Copyright UMC Utrecht and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef elxTransformBase_h
#define elxTransformBase_h
#include "elxMacro.h"
#include "elxBaseComponentSE.h"
#include "elxDefaultConstruct.h"
#include <itkDeref.h>
#include "elxElastixBase.h"
#include "itkAdvancedTransform.h"
#include "itkAdvancedCombinationTransform.h"
#include "elxComponentDatabase.h"
#include "elxProgressCommand.h"
// ITK header files:
#include <itkImage.h>
#include <itkOptimizerParameters.h>
#include <itkTransformMeshFilter.h>
namespace elastix
{
// using namespace itk; //Not here, because a TransformBase class was added to ITK...
template <class TElastix>
class ITK_TEMPLATE_EXPORT TransformBase : public BaseComponentSE<TElastix>
{
public:
ITK_DISALLOW_COPY_AND_MOVE(TransformBase);
using Self = TransformBase;
using Superclass = BaseComponentSE<TElastix>;
itkTypeMacro(TransformBase, BaseComponentSE);
using typename Superclass::RegistrationType;
using CommandLineArgumentMapType = Configuration ::CommandLineArgumentMapType;
using CommandLineEntryType = Configuration ::CommandLineEntryType;
using CoordRepType = ElastixBase::CoordRepType;
using FixedImageType = typename TElastix::FixedImageType;
using MovingImageType = typename TElastix::MovingImageType;
using ComponentDescriptionType = ComponentDatabase::ComponentDescriptionType;
using PtrToCreator = ComponentDatabase::PtrToCreator;
itkStaticConstMacro(FixedImageDimension, unsigned int, FixedImageType::ImageDimension);
itkStaticConstMacro(MovingImageDimension, unsigned int, MovingImageType::ImageDimension);
using CombinationTransformType = itk::AdvancedCombinationTransform<CoordRepType, Self::FixedImageDimension>;
using ITKBaseType = CombinationTransformType;
using InitialTransformType = typename CombinationTransformType::InitialTransformType;
using ValueType = double;
using ParametersType = itk::OptimizerParameters<ValueType>;
using InputPointType = typename ITKBaseType::InputPointType;
using OutputPointType = typename ITKBaseType::OutputPointType;
using VectorPixelType = itk::Vector<float, FixedImageDimension>;
using DeformationFieldImageType = itk::Image<VectorPixelType, FixedImageDimension>;
using ITKRegistrationType = typename RegistrationType::ITKBaseType;
using OptimizerType = typename ITKRegistrationType::OptimizerType;
using ScalesType = itk::Optimizer::ScalesType;
using SpatialJacobianDeterminantImageType = itk::Image<float, FixedImageDimension>;
using SpatialJacobianMatrixImageType =
itk::Image<itk::Matrix<float, MovingImageDimension, FixedImageDimension>, FixedImageDimension>;
using ParameterMapType = typename TElastix::ParameterMapType;
ITKBaseType *
GetAsITKBaseType()
{
return &(this->GetSelf());
}
const ITKBaseType *
GetAsITKBaseType() const
{
return &(this->GetSelf());
}
int
BeforeAllTransformix();
void
SetInitialTransform(InitialTransformType * _arg);
void
SetTransformParameterFileName(const std::string & filename);
virtual void
ReadFromFile();
void
CreateTransformParameterMap(const ParametersType & param,
ParameterMapType & parameterMap,
const bool includeDerivedTransformParameters = true) const;
void
WriteToFile(std::ostream & transformationParameterInfo, const ParametersType & param) const;
void
SetReadWriteTransformParameters(const bool _arg);
void
ReadInitialTransformFromFile(const std::string & transformParameterFileName);
void
TransformPoints() const;
typename SpatialJacobianDeterminantImageType::Pointer
ComputeSpatialJacobianDeterminantImage() const;
typename SpatialJacobianMatrixImageType::Pointer
ComputeSpatialJacobianMatrixImage() const;
void
ComputeAndWriteSpatialJacobianDeterminantImage() const;
void
ComputeAndWriteSpatialJacobianMatrixImage() const;
void
SetFinalParameters();
template <typename TMesh>
typename TMesh::Pointer
TransformMesh(const TMesh & mesh) const
{
DefaultConstruct<itk::TransformMeshFilter<TMesh, TMesh, CombinationTransformType>> transformMeshFilter;
transformMeshFilter.SetTransform(&const_cast<CombinationTransformType &>(this->GetSelf()));
transformMeshFilter.SetInput(&mesh);
transformMeshFilter.Update();
return transformMeshFilter.GetOutput();
}
protected:
TransformBase() = default;
~TransformBase() override = default;
bool
HasITKTransformParameters() const
{
const Configuration & configuration = itk::Deref(Superclass::GetConfiguration());
return configuration.HasParameter("ITKTransformParameters");
}
void
AutomaticScalesEstimation(ScalesType & scales) const;
void
AutomaticScalesEstimationStackTransform(const unsigned int numSubTransforms, ScalesType & scales) const;
private:
elxDeclarePureVirtualGetSelfMacro(ITKBaseType);
template <template <typename, typename> class TSource, typename TOutputImage>
auto
CreateJacobianSource() const
{
const auto & resampleImageFilter = *(this->m_Elastix->GetElxResamplerBase()->GetAsITKBaseType());
const auto jacGenerator = TSource<TOutputImage, CoordRepType>::New();
jacGenerator->SetTransform(this->GetAsITKBaseType());
jacGenerator->SetOutputSize(resampleImageFilter.GetSize());
jacGenerator->SetOutputSpacing(resampleImageFilter.GetOutputSpacing());
jacGenerator->SetOutputOrigin(resampleImageFilter.GetOutputOrigin());
jacGenerator->SetOutputIndex(resampleImageFilter.GetOutputStartIndex());
jacGenerator->SetOutputDirection(resampleImageFilter.GetOutputDirection());
// NOTE: We can not use the following, since the fixed image does not exist in transformix
// jacGenerator->SetOutputParametersFromImage(
// this->GetRegistration()->GetAsITKBaseType()->GetFixedImage() );
return jacGenerator;
}
template <typename TImage>
auto
CreateChangeInformationImageFilter(TImage * image) const
{
const auto infoChanger = itk::ChangeInformationImageFilter<TImage>::New();
typename FixedImageType::DirectionType originalDirection;
const bool retdc = this->m_Elastix->GetOriginalFixedImageDirection(originalDirection);
infoChanger->SetOutputDirection(originalDirection);
infoChanger->SetChangeDirection(retdc && !this->m_Elastix->GetUseDirectionCosines());
infoChanger->SetInput(image);
return infoChanger;
}
void
ReadInitialTransformFromConfiguration(const Configuration::ConstPointer);
int
BeforeAllBase() override;
void
BeforeRegistrationBase() override;
void
AfterRegistrationBase() override;
const InitialTransformType *
GetInitialTransform() const;
itkGetStringMacro(TransformParameterFileName);
void
TransformPointsSomePoints(const std::string & filename) const;
void
TransformPointsSomePointsVTK(const std::string & filename) const;
typename DeformationFieldImageType::Pointer
GenerateDeformationFieldImage() const;
void WriteDeformationFieldImage(typename DeformationFieldImageType::Pointer) const;
void
TransformPointsAllPoints() const;
std::string
GetInitialTransformParameterFileName() const
{
const InitialTransformType * const initialTransform = this->GetInitialTransform();
if (!initialTransform)
{
return "NoInitialTransform";
}
const auto t0 = dynamic_cast<const Self *>(initialTransform);
return t0->GetTransformParameterFileName();
}
virtual ParameterMapType
CreateDerivedTransformParameterMap() const = 0;
virtual void
WriteDerivedTransformDataToFile() const
{}
std::string m_TransformParameterFileName;
ParametersType m_TransformParameters;
ParametersType m_FinalParameters;
bool m_ReadWriteTransformParameters{ true };
};
} // end namespace elastix
#ifndef ITK_MANUAL_INSTANTIATION
# include "elxTransformBase.hxx"
#endif
#endif // end #ifndef elxTransformBase_h
double
elastix::BaseComponentSE::BaseComponentSE
BaseComponentSE()=default
elastix::BaseComponentSE::m_Elastix
itk::WeakPointer< TElastix > m_Elastix
Definition elxBaseComponentSE.h:137
elastix::BaseComponentSE::GetConfiguration
const Configuration * GetConfiguration() const
Definition elxBaseComponentSE.h:111
elastix::BaseComponentSE::RegistrationType
typename ElastixType::RegistrationBaseType RegistrationType
Definition elxBaseComponentSE.h:62
elastix::BaseComponentSE::GetSelf
virtual const itk::Object & GetSelf() const =0
elastix::ComponentDatabase::PtrToCreator
ObjectPointer(*)() PtrToCreator
Definition elxComponentDatabase.h:75
elastix::ComponentDatabase::ComponentDescriptionType
std::string ComponentDescriptionType
Definition elxComponentDatabase.h:76
elastix::Configuration
A class that deals with user given parameters and command line arguments.
Definition elxConfiguration.h:53
elastix::Configuration::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition elxConfiguration.h:62
elastix::Configuration::HasParameter
bool HasParameter(const std::string &parameterName) const
Definition elxConfiguration.h:228
elastix::DefaultConstruct
Definition elxDefaultConstruct.h:36
elastix::ElastixBase::CoordRepType
double CoordRepType
Definition elxElastixBase.h:173
elastix::TransformBase::ValueType
double ValueType
Definition elxTransformBase.h:176
elastix::TransformBase::TransformMesh
TMesh::Pointer TransformMesh(const TMesh &mesh) const
Definition elxTransformBase.h:282
elastix::TransformBase< Self >::m_TransformParameterFileName
std::string m_TransformParameterFileName
Definition elxTransformBase.h:448
elastix::TransformBase::GetAsITKBaseType
const ITKBaseType * GetAsITKBaseType() const
Definition elxTransformBase.h:211
elastix::TransformBase::SpatialJacobianMatrixImageType
itk::Image< itk::Matrix< float, MovingImageDimension, FixedImageDimension >, FixedImageDimension > SpatialJacobianMatrixImageType
Definition elxTransformBase.h:194
elastix::TransformBase::Superclass
BaseComponentSE< TElastix > Superclass
Definition elxTransformBase.h:144
elastix::TransformBase::FixedImageType
typename TElastix::FixedImageType FixedImageType
Definition elxTransformBase.h:157
elastix::TransformBase::ITKRegistrationType
typename RegistrationType::ITKBaseType ITKRegistrationType
Definition elxTransformBase.h:188
elastix::TransformBase::SetInitialTransform
void SetInitialTransform(InitialTransformType *_arg)
elastix::TransformBase< Self >::m_TransformParameters
ParametersType m_TransformParameters
Definition elxTransformBase.h:449
elastix::TransformBase::GetAsITKBaseType
ITKBaseType * GetAsITKBaseType()
Definition elxTransformBase.h:203
elastix::TransformBase::TransformPointsSomePointsVTK
void TransformPointsSomePointsVTK(const std::string &filename) const
elastix::TransformBase::GenerateDeformationFieldImage
DeformationFieldImageType::Pointer GenerateDeformationFieldImage() const
elastix::TransformBase::SpatialJacobianDeterminantImageType
itk::Image< float, FixedImageDimension > SpatialJacobianDeterminantImageType
Definition elxTransformBase.h:193
elastix::TransformBase::GetInitialTransformParameterFileName
std::string GetInitialTransformParameterFileName() const
Definition elxTransformBase.h:426
elastix::TransformBase::ComputeSpatialJacobianDeterminantImage
SpatialJacobianDeterminantImageType::Pointer ComputeSpatialJacobianDeterminantImage() const
elastix::TransformBase::ReadInitialTransformFromConfiguration
void ReadInitialTransformFromConfiguration(const Configuration::ConstPointer)
elastix::TransformBase::SetFinalParameters
void SetFinalParameters()
elastix::TransformBase::DeformationFieldImageType
itk::Image< VectorPixelType, FixedImageDimension > DeformationFieldImageType
Definition elxTransformBase.h:185
elastix::TransformBase::TransformPoints
void TransformPoints() const
elastix::TransformBase::CoordRepType
ElastixBase::CoordRepType CoordRepType
Definition elxTransformBase.h:156
elastix::TransformBase::OutputPointType
typename ITKBaseType::OutputPointType OutputPointType
Definition elxTransformBase.h:181
elastix::TransformBase::AutomaticScalesEstimation
void AutomaticScalesEstimation(ScalesType &scales) const
elastix::TransformBase::CreateDerivedTransformParameterMap
virtual ParameterMapType CreateDerivedTransformParameterMap() const =0
elastix::TransformBase::SetReadWriteTransformParameters
void SetReadWriteTransformParameters(const bool _arg)
elastix::TransformBase::BeforeAllTransformix
int BeforeAllTransformix()
elastix::TransformBase::OptimizerType
typename ITKRegistrationType::OptimizerType OptimizerType
Definition elxTransformBase.h:189
elastix::TransformBase::ParameterMapType
typename TElastix::ParameterMapType ParameterMapType
Definition elxTransformBase.h:199
elastix::TransformBase::WriteToFile
void WriteToFile(std::ostream &transformationParameterInfo, const ParametersType &param) const
elastix::TransformBase::TransformPointsAllPoints
void TransformPointsAllPoints() const
elastix::TransformBase< Self >::m_FinalParameters
ParametersType m_FinalParameters
Definition elxTransformBase.h:450
elastix::TransformBase::ITK_DISALLOW_COPY_AND_MOVE
ITK_DISALLOW_COPY_AND_MOVE(TransformBase)
elastix::TransformBase< Self >::m_ReadWriteTransformParameters
bool m_ReadWriteTransformParameters
Definition elxTransformBase.h:453
elastix::TransformBase::MovingImageType
typename TElastix::MovingImageType MovingImageType
Definition elxTransformBase.h:158
elastix::TransformBase::Self
TransformBase Self
Definition elxTransformBase.h:143
elastix::TransformBase::ComputeAndWriteSpatialJacobianMatrixImage
void ComputeAndWriteSpatialJacobianMatrixImage() const
elastix::TransformBase::ComputeSpatialJacobianMatrixImage
SpatialJacobianMatrixImageType::Pointer ComputeSpatialJacobianMatrixImage() const
elastix::TransformBase::CreateChangeInformationImageFilter
auto CreateChangeInformationImageFilter(TImage *image) const
Definition elxTransformBase.h:354
elastix::TransformBase::InputPointType
typename ITKBaseType::InputPointType InputPointType
Definition elxTransformBase.h:180
elastix::TransformBase::elxDeclarePureVirtualGetSelfMacro
elxDeclarePureVirtualGetSelfMacro(ITKBaseType)
elastix::TransformBase::itkStaticConstMacro
itkStaticConstMacro(FixedImageDimension, unsigned int, FixedImageType::ImageDimension)
elastix::TransformBase::InitialTransformType
typename CombinationTransformType::InitialTransformType InitialTransformType
Definition elxTransformBase.h:173
elastix::TransformBase::CommandLineArgumentMapType
Configuration ::CommandLineArgumentMapType CommandLineArgumentMapType
Definition elxTransformBase.h:152
elastix::TransformBase::ComputeAndWriteSpatialJacobianDeterminantImage
void ComputeAndWriteSpatialJacobianDeterminantImage() const
elastix::TransformBase::ScalesType
itk::Optimizer::ScalesType ScalesType
Definition elxTransformBase.h:190
elastix::TransformBase::ReadFromFile
virtual void ReadFromFile()
elastix::TransformBase::CommandLineEntryType
Configuration ::CommandLineEntryType CommandLineEntryType
Definition elxTransformBase.h:153
elastix::TransformBase::CreateJacobianSource
auto CreateJacobianSource() const
Definition elxTransformBase.h:330
elastix::TransformBase::TransformPointsSomePoints
void TransformPointsSomePoints(const std::string &filename) const
elastix::TransformBase::TransformBase
TransformBase()=default
elastix::TransformBase::WriteDerivedTransformDataToFile
virtual void WriteDerivedTransformDataToFile() const
Definition elxTransformBase.h:444
elastix::TransformBase::ReadInitialTransformFromFile
void ReadInitialTransformFromFile(const std::string &transformParameterFileName)
elastix::TransformBase::CreateTransformParameterMap
void CreateTransformParameterMap(const ParametersType &param, ParameterMapType &parameterMap, const bool includeDerivedTransformParameters=true) const
elastix::TransformBase::AfterRegistrationBase
void AfterRegistrationBase() override
elastix::TransformBase::WriteDeformationFieldImage
void WriteDeformationFieldImage(typename DeformationFieldImageType::Pointer) const
elastix::TransformBase::itkStaticConstMacro
itkStaticConstMacro(MovingImageDimension, unsigned int, MovingImageType::ImageDimension)
elastix::TransformBase::ComponentDescriptionType
ComponentDatabase::ComponentDescriptionType ComponentDescriptionType
Definition elxTransformBase.h:161
elastix::TransformBase::HasITKTransformParameters
bool HasITKTransformParameters() const
Definition elxTransformBase.h:299
elastix::TransformBase::CombinationTransformType
itk::AdvancedCombinationTransform< CoordRepType, Self::FixedImageDimension > CombinationTransformType
Definition elxTransformBase.h:171
elastix::TransformBase::GetInitialTransform
const InitialTransformType * GetInitialTransform() const
elastix::TransformBase::VectorPixelType
itk::Vector< float, FixedImageDimension > VectorPixelType
Definition elxTransformBase.h:184
elastix::TransformBase::AutomaticScalesEstimationStackTransform
void AutomaticScalesEstimationStackTransform(const unsigned int numSubTransforms, ScalesType &scales) const
elastix::TransformBase::SetTransformParameterFileName
void SetTransformParameterFileName(const std::string &filename)
elastix::TransformBase::ITKBaseType
CombinationTransformType ITKBaseType
Definition elxTransformBase.h:172
elastix::TransformBase::PtrToCreator
ComponentDatabase::PtrToCreator PtrToCreator
Definition elxTransformBase.h:162
elastix::TransformBase::~TransformBase
~TransformBase() override=default
elastix::TransformBase::ParametersType
itk::OptimizerParameters< ValueType > ParametersType
Definition elxTransformBase.h:177
elastix::TransformBase::BeforeAllBase
int BeforeAllBase() override
elastix::TransformBase::BeforeRegistrationBase
void BeforeRegistrationBase() override
itk::AdvancedCombinationTransform
This class combines two transforms: an 'initial transform' with a 'current transform'.
Definition itkAdvancedCombinationTransform.h:57
itk::AdvancedCombinationTransform< CoordRepType, Self::FixedImageDimension >::InitialTransformType
Superclass InitialTransformType
Definition itkAdvancedCombinationTransform.h:110
elxBaseComponentSE.h
elxComponentDatabase.h
elxDefaultConstruct.h
elxElastixBase.h
elxMacro.h
elxProgressCommand.h
itkAdvancedCombinationTransform.h
itkAdvancedTransform.h
elastix
Definition elxDefaultConstruct.h:25
itk::OptimizerParameters
class ITK_TEMPLATE_EXPORT OptimizerParameters
Definition elxConversion.h:33

Generated on 1768596610 for elastix by 1.15.0 |