Loading...
Searching...
No Matches
elxTransformIO.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 elxTransformIO_h
#define elxTransformIO_h
#include "itkAdvancedCombinationTransform.h"
#include "ExternalTransform/elxAdvancedTransformAdapter.h"
#include <itkCompositeTransform.h>
#include <itkTransform.h>
#include <itkTransformBase.h>
#include <cassert>
#include <string>
namespace elastix
{
class BaseComponent;
class Configuration;
class TransformIO
{
public:
static itk::OptimizerParameters<double>
GetParameters(const bool fixed, const itk::TransformBase & transform)
{
return fixed ? transform.GetFixedParameters() : transform.GetParameters();
}
static void
SetParameters(const bool fixed, itk::TransformBase & transform, const itk::OptimizerParameters<double> & parameters)
{
fixed ? transform.SetFixedParameters(parameters) : transform.SetParameters(parameters);
}
static std::string
ConvertITKNameOfClassToElastixClassName(const std::string & itkNameOfClass);
template <unsigned NDimension>
static itk::SmartPointer<itk::CompositeTransform<double, NDimension>>
ConvertToItkCompositeTransform(
const itk::AdvancedCombinationTransform<double, NDimension> & advancedCombinationTransform)
{
const auto numberOfTransforms = advancedCombinationTransform.GetNumberOfTransforms();
if ((numberOfTransforms > 1) && (!advancedCombinationTransform.GetUseComposition()))
{
// A combination of multiple transforms can only be converted to CompositeTransform when the original combination
// uses composition.
return nullptr;
}
const auto compositeTransform = itk::CompositeTransform<double, NDimension>::New();
for (itk::SizeValueType n{}; n < numberOfTransforms; ++n)
{
const auto nthTransform = advancedCombinationTransform.GetNthTransform(n);
const auto singleItkTransform = ConvertToSingleItkTransform(*nthTransform);
compositeTransform->AddTransform((singleItkTransform == nullptr) ? nthTransform : singleItkTransform);
}
return compositeTransform;
}
template <unsigned NDimension>
static itk::SmartPointer<itk::CompositeTransform<double, NDimension>>
ConvertToCompositionOfItkTransforms(
const itk::AdvancedCombinationTransform<double, NDimension> & advancedCombinationTransform)
{
const auto numberOfTransforms = advancedCombinationTransform.GetNumberOfTransforms();
if ((numberOfTransforms > 1) && (!advancedCombinationTransform.GetUseComposition()))
{
// A combination of multiple transforms can only be converted to CompositeTransform when the original combination
// uses composition.
return nullptr;
}
const auto compositeTransform = itk::CompositeTransform<double, NDimension>::New();
for (itk::SizeValueType n{}; n < numberOfTransforms; ++n)
{
const auto nthTransform = advancedCombinationTransform.GetNthTransform(n);
const auto singleItkTransform = ConvertToSingleItkTransform(*nthTransform);
if (singleItkTransform == nullptr)
{
return nullptr;
}
compositeTransform->AddTransform(singleItkTransform);
}
return compositeTransform;
}
template <unsigned NDimension>
static itk::SmartPointer<itk::Transform<double, NDimension, NDimension>>
ConvertToSingleItkTransform(const itk::Transform<double, NDimension, NDimension> & elxTransform)
{
// Do not use this function for elastix combination transforms!
using CombinationTransformType = itk::AdvancedCombinationTransform<double, NDimension>;
assert(dynamic_cast<const CombinationTransformType *>(&elxTransform) == nullptr);
if (const auto transformAdapter = dynamic_cast<const AdvancedTransformAdapter<double, NDimension> *>(&elxTransform))
{
return transformAdapter->GetModifiableExternalTransform();
}
return dynamic_cast<itk::Transform<double, NDimension, NDimension> *>(
ConvertItkTransformBaseToSingleItkTransform(elxTransform).GetPointer());
}
static void
Write(const itk::Object & itkTransform, const std::string & fileName);
static itk::TransformBase::Pointer
Read(const std::string & fileName);
template <typename TElastixTransform>
static std::string
MakeDeformationFieldFileName(const TElastixTransform & elxTransform)
{
return MakeDeformationFieldFileName(*(elxTransform.GetConfiguration()),
elxTransform.GetElastix()->GetCurrentTransformParameterFileName());
}
private:
static itk::TransformBase::Pointer
ConvertItkTransformBaseToSingleItkTransform(const itk::TransformBase & elxTransform);
static std::string
MakeDeformationFieldFileName(const Configuration & configuration, const std::string & transformParameterFileName);
};
} // namespace elastix
#endif
elastix::AdvancedTransformAdapter
Adapts the ITK transform that is specified by AdvancedTransformAdapter::SetExternalTransform to the e...
Definition elxAdvancedTransformAdapter.h:40
elastix::BaseComponent
The BaseComponent class is a class that all elastix components should inherit from.
Definition elxBaseComponent.h:54
elastix::Configuration
A class that deals with user given parameters and command line arguments.
Definition elxConfiguration.h:53
elastix::TransformIO
Definition elxTransformIO.h:37
elastix::TransformIO::ConvertToSingleItkTransform
static itk::SmartPointer< itk::Transform< double, NDimension, NDimension > > ConvertToSingleItkTransform(const itk::Transform< double, NDimension, NDimension > &elxTransform)
Definition elxTransformIO.h:125
elastix::TransformIO::MakeDeformationFieldFileName
static std::string MakeDeformationFieldFileName(const TElastixTransform &elxTransform)
Makes the deformation field file name, as used by BSplineTransformWithDiffusion and DeformationFieldT...
Definition elxTransformIO.h:153
elastix::TransformIO::Write
static void Write(const itk::Object &itkTransform, const std::string &fileName)
elastix::TransformIO::MakeDeformationFieldFileName
static std::string MakeDeformationFieldFileName(const Configuration &configuration, const std::string &transformParameterFileName)
elastix::TransformIO::ConvertToCompositionOfItkTransforms
static itk::SmartPointer< itk::CompositeTransform< double, NDimension > > ConvertToCompositionOfItkTransforms(const itk::AdvancedCombinationTransform< double, NDimension > &advancedCombinationTransform)
Definition elxTransformIO.h:92
elastix::TransformIO::Read
static itk::TransformBase::Pointer Read(const std::string &fileName)
elastix::TransformIO::ConvertToItkCompositeTransform
static itk::SmartPointer< itk::CompositeTransform< double, NDimension > > ConvertToItkCompositeTransform(const itk::AdvancedCombinationTransform< double, NDimension > &advancedCombinationTransform)
Definition elxTransformIO.h:63
elastix::TransformIO::SetParameters
static void SetParameters(const bool fixed, itk::TransformBase &transform, const itk::OptimizerParameters< double > &parameters)
Definition elxTransformIO.h:46
elastix::TransformIO::GetParameters
static itk::OptimizerParameters< double > GetParameters(const bool fixed, const itk::TransformBase &transform)
Definition elxTransformIO.h:40
elastix::TransformIO::ConvertITKNameOfClassToElastixClassName
static std::string ConvertITKNameOfClassToElastixClassName(const std::string &itkNameOfClass)
elastix::TransformIO::ConvertItkTransformBaseToSingleItkTransform
static itk::TransformBase::Pointer ConvertItkTransformBaseToSingleItkTransform(const itk::TransformBase &elxTransform)
itk::AdvancedCombinationTransform
This class combines two transforms: an 'initial transform' with a 'current transform'.
Definition itkAdvancedCombinationTransform.h:57
itk::AdvancedCombinationTransform::GetNumberOfTransforms
SizeValueType GetNumberOfTransforms() const
itk::AdvancedCombinationTransform::GetNthTransform
const TransformTypePointer GetNthTransform(SizeValueType n) const
itk::AdvancedCombinationTransform::GetUseComposition
virtual bool GetUseComposition() const
elxAdvancedTransformAdapter.h
itkAdvancedCombinationTransform.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 |