Loading...
Searching...
No Matches
itkStackTransform.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 itkStackTransform_h
#define itkStackTransform_h
#include "itkAdvancedTransform.h"
#include "itkIndex.h"
#include <cassert>
namespace itk
{
template <class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
class ITK_TEMPLATE_EXPORT StackTransform : public AdvancedTransform<TScalarType, NInputDimensions, NOutputDimensions>
{
public:
ITK_DISALLOW_COPY_AND_MOVE(StackTransform);
using Self = StackTransform;
using Superclass = AdvancedTransform<TScalarType, NInputDimensions, NOutputDimensions>;
using Pointer = SmartPointer<Self>;
using ConstPointer = SmartPointer<const Self>;
itkTypeMacro(StackTransform, AdvancedTransform);
itkStaticConstMacro(InputSpaceDimension, unsigned int, NInputDimensions);
itkStaticConstMacro(OutputSpaceDimension, unsigned int, NOutputDimensions);
itkStaticConstMacro(ReducedInputSpaceDimension, unsigned int, NInputDimensions - 1);
itkStaticConstMacro(ReducedOutputSpaceDimension, unsigned int, NOutputDimensions - 1);
using typename Superclass::ScalarType;
using typename Superclass::ParametersType;
using typename Superclass::FixedParametersType;
using typename Superclass::NumberOfParametersType;
using typename Superclass::ParametersValueType;
using typename Superclass::JacobianType;
using typename Superclass::SpatialJacobianType;
using typename Superclass::JacobianOfSpatialJacobianType;
using typename Superclass::SpatialHessianType;
using typename Superclass::JacobianOfSpatialHessianType;
using typename Superclass::NonZeroJacobianIndicesType;
using typename Superclass::InputPointType;
using typename Superclass::InputVectorType;
using typename Superclass::OutputVectorType;
using typename Superclass::InputVnlVectorType;
using typename Superclass::OutputVnlVectorType;
using typename Superclass::OutputCovariantVectorType;
using typename Superclass::InputCovariantVectorType;
using typename Superclass::OutputPointType;
using typename Superclass::OutputVectorPixelType;
using typename Superclass::InputVectorPixelType;
using SubTransformType =
AdvancedTransform<TScalarType, Self::ReducedInputSpaceDimension, Self::ReducedOutputSpaceDimension>;
using SubTransformPointer = typename SubTransformType::Pointer;
using SubTransformJacobianType = typename SubTransformType::JacobianType;
using SubTransformInputPointType = typename SubTransformType::InputPointType;
using SubTransformOutputPointType = typename SubTransformType::OutputPointType;
using ParametersArrayType = typename ParametersType::ArrayType;
OutputPointType
TransformPoint(const InputPointType & inputPoint) const override;
void
GetJacobian(const InputPointType & inputPoint, JacobianType & jac, NonZeroJacobianIndicesType & nzji) const override;
void
SetParameters(const ParametersType & param) override;
const ParametersType &
GetParameters() const override;
void
SetFixedParameters(const FixedParametersType & fixedParameters) override
{
const auto numberOfFixedParameters = fixedParameters.size();
if (numberOfFixedParameters < NumberOfGeneralFixedParametersOfStack)
{
itkExceptionMacro("The number of FixedParameters (" << numberOfFixedParameters << ") should be at least "
<< NumberOfGeneralFixedParametersOfStack);
}
if (Superclass::m_FixedParameters != fixedParameters)
{
Superclass::m_FixedParameters = fixedParameters;
CreateSubTransforms(FixedParametersType(fixedParameters.data_block() + NumberOfGeneralFixedParametersOfStack,
numberOfFixedParameters - NumberOfGeneralFixedParametersOfStack));
UpdateStackSpacingAndOrigin();
this->Modified();
}
}
NumberOfParametersType
GetNumberOfParameters() const override
{
if (this->m_SubTransformContainer.empty())
{
return 0;
}
else
{
return this->m_SubTransformContainer.size() * m_SubTransformContainer[0]->GetNumberOfParameters();
}
}
void
SetNumberOfSubTransforms(const unsigned int num)
{
if (this->m_SubTransformContainer.size() != num)
{
this->m_SubTransformContainer.clear();
this->m_SubTransformContainer.resize(num);
this->Modified();
}
}
auto
GetNumberOfSubTransforms() const
{
return static_cast<unsigned>(m_SubTransformContainer.size());
}
itkSetMacro(StackSpacing, TScalarType);
itkGetConstMacro(StackSpacing, TScalarType);
itkSetMacro(StackOrigin, TScalarType);
itkGetConstMacro(StackOrigin, TScalarType);
void
SetSubTransform(unsigned int i, SubTransformType * transform)
{
this->m_SubTransformContainer[i] = transform;
this->Modified();
}
void
UpdateFixedParameters()
{
const SubTransformType * const subTransform =
m_SubTransformContainer.empty() ? nullptr : m_SubTransformContainer.front();
this->UpdateFixedParametersInternally((subTransform == nullptr) ? FixedParametersType()
: subTransform->GetFixedParameters());
}
void
SetAllSubTransforms(const SubTransformType & transform)
{
const auto & fixedParametersOfSubTransform = transform.GetFixedParameters();
const auto & parametersOfSubTransform = transform.GetParameters();
UpdateFixedParametersInternally(fixedParametersOfSubTransform);
for (auto & subTransform : m_SubTransformContainer)
{
// Copy transform
SubTransformPointer transformcopy = dynamic_cast<SubTransformType *>(transform.CreateAnother().GetPointer());
transformcopy->SetFixedParameters(fixedParametersOfSubTransform);
transformcopy->SetParameters(parametersOfSubTransform);
// Set sub transform
subTransform = transformcopy;
}
}
SubTransformPointer
GetSubTransform(unsigned int i)
{
return this->m_SubTransformContainer[i];
}
NumberOfParametersType
GetNumberOfNonZeroJacobianIndices() const override;
protected:
StackTransform() = default;
~StackTransform() override = default;
// Indices of the general fixed parameters into the FixedParameters array, and the number of those parameters.
enum
{
IndexOfNumberOfSubTransforms,
IndexOfStackSpacing,
IndexOfStackOrigin,
NumberOfGeneralFixedParametersOfStack
};
void
CreateSubTransforms(const FixedParametersType & fixedParametersOfSubTransform)
{
assert(Superclass::m_FixedParameters.size() >= NumberOfGeneralFixedParametersOfStack);
const auto numberOfSubTransforms = Superclass::m_FixedParameters[IndexOfNumberOfSubTransforms];
if (numberOfSubTransforms >= 0.0 && numberOfSubTransforms <= UINT_MAX &&
static_cast<double>(static_cast<unsigned>(numberOfSubTransforms)) == numberOfSubTransforms)
{
m_SubTransformContainer.resize(static_cast<unsigned>(numberOfSubTransforms));
}
else
{
itkExceptionMacro("The FixedParameters element (" << numberOfSubTransforms
<< ") should be a valid number (the number of subtransforms).");
}
for (auto & subTransform : m_SubTransformContainer)
{
subTransform = this->CreateSubTransform();
subTransform->SetFixedParameters(fixedParametersOfSubTransform);
}
}
void
UpdateStackSpacingAndOrigin()
{
assert(Superclass::m_FixedParameters.size() >= NumberOfGeneralFixedParametersOfStack);
m_StackSpacing = Superclass::m_FixedParameters[IndexOfStackSpacing];
m_StackOrigin = Superclass::m_FixedParameters[IndexOfStackOrigin];
}
virtual void
UpdateFixedParametersInternally(const FixedParametersType & fixedParametersOfSubTransform)
{
const auto numberOfFixedParametersOfSubTransform = fixedParametersOfSubTransform.size();
FixedParametersType & fixedParametersOfStack = this->Superclass::m_FixedParameters;
const auto minimumNumberOfFixedParametersOfStack =
NumberOfGeneralFixedParametersOfStack + numberOfFixedParametersOfSubTransform;
if (fixedParametersOfStack.size() < minimumNumberOfFixedParametersOfStack)
{
fixedParametersOfStack.set_size(minimumNumberOfFixedParametersOfStack);
}
fixedParametersOfStack[IndexOfNumberOfSubTransforms] = m_SubTransformContainer.size();
fixedParametersOfStack[IndexOfStackOrigin] = m_StackOrigin;
fixedParametersOfStack[IndexOfStackSpacing] = m_StackSpacing;
std::copy_n(fixedParametersOfSubTransform.begin(),
numberOfFixedParametersOfSubTransform,
fixedParametersOfStack.begin() + NumberOfGeneralFixedParametersOfStack);
}
private:
// Private using-declarations, to avoid `-Woverloaded-virtual` warnings from GCC (GCC 11.4).
using Superclass::TransformCovariantVector;
using Superclass::TransformVector;
virtual SubTransformPointer
CreateSubTransform() const = 0;
static constexpr const char * unimplementedOverrideMessage = "Not implemented for StackTransform";
OutputVectorType
TransformVector(const InputVectorType &) const override
{
itkExceptionMacro(<< unimplementedOverrideMessage);
}
OutputVnlVectorType
TransformVector(const InputVnlVectorType &) const override
{
itkExceptionMacro(<< unimplementedOverrideMessage);
}
OutputCovariantVectorType
TransformCovariantVector(const InputCovariantVectorType &) const override
{
itkExceptionMacro(<< unimplementedOverrideMessage);
}
void
GetSpatialJacobian(const InputPointType &, SpatialJacobianType &) const override
{
itkExceptionMacro(<< unimplementedOverrideMessage);
}
void
GetSpatialHessian(const InputPointType &, SpatialHessianType &) const override
{
itkExceptionMacro(<< unimplementedOverrideMessage);
}
void
GetJacobianOfSpatialJacobian(const InputPointType &,
JacobianOfSpatialJacobianType &,
NonZeroJacobianIndicesType &) const override
{
itkExceptionMacro(<< unimplementedOverrideMessage);
}
void
GetJacobianOfSpatialJacobian(const InputPointType &,
SpatialJacobianType &,
JacobianOfSpatialJacobianType &,
NonZeroJacobianIndicesType &) const override
{
itkExceptionMacro(<< unimplementedOverrideMessage);
}
void
GetJacobianOfSpatialHessian(const InputPointType &,
JacobianOfSpatialHessianType &,
NonZeroJacobianIndicesType &) const override
{
itkExceptionMacro(<< unimplementedOverrideMessage);
}
void
GetJacobianOfSpatialHessian(const InputPointType &,
SpatialHessianType &,
JacobianOfSpatialHessianType &,
NonZeroJacobianIndicesType &) const override
{
itkExceptionMacro(<< unimplementedOverrideMessage);
}
// Transform container
std::vector<SubTransformPointer> m_SubTransformContainer{};
// Stack spacing and origin of last dimension
TScalarType m_StackSpacing{ 1.0 };
TScalarType m_StackOrigin{ 0.0 };
};
} // end namespace itk
#ifndef ITK_MANUAL_INSTANTIATION
# include "itkStackTransform.hxx"
#endif
#endif
TScalarType
itk::AdvancedTransform< TScalarType, Self::ReducedInputSpaceDimension, Self::ReducedOutputSpaceDimension >::Pointer
SmartPointer< Self > Pointer
Definition itkAdvancedTransform.h:91
itk::AdvancedTransform::SpatialHessianType
FixedArray< Matrix< ScalarType, InputSpaceDimension, InputSpaceDimension >, OutputSpaceDimension > SpatialHessianType
Definition itkAdvancedTransform.h:137
itk::AdvancedTransform::SpatialJacobianType
Matrix< ScalarType, OutputSpaceDimension, InputSpaceDimension > SpatialJacobianType
Definition itkAdvancedTransform.h:134
itk::AdvancedTransform::JacobianOfSpatialHessianType
std::vector< SpatialHessianType > JacobianOfSpatialHessianType
Definition itkAdvancedTransform.h:139
itk::AdvancedTransform::JacobianOfSpatialJacobianType
std::vector< SpatialJacobianType > JacobianOfSpatialJacobianType
Definition itkAdvancedTransform.h:135
itk::AdvancedTransform< TScalarType, NInputDimensions, NOutputDimensions >::AdvancedTransform
AdvancedTransform()=default
itk::AdvancedTransform::NonZeroJacobianIndicesType
std::vector< unsigned long > NonZeroJacobianIndicesType
Definition itkAdvancedTransform.h:133
itk::StackTransform< ScalarType, FixedImageDimension, MovingImageDimension >::SpatialJacobianType
Matrix< ScalarType, OutputSpaceDimension, InputSpaceDimension > SpatialJacobianType
itk::StackTransform::Superclass
AdvancedTransform< TScalarType, NInputDimensions, NOutputDimensions > Superclass
Definition itkStackTransform.h:47
itk::StackTransform::itkStaticConstMacro
itkStaticConstMacro(ReducedOutputSpaceDimension, unsigned int, NOutputDimensions - 1)
itk::StackTransform< ScalarType, FixedImageDimension, MovingImageDimension >::m_StackSpacing
ScalarType m_StackSpacing
Definition itkStackTransform.h:393
itk::StackTransform::itkStaticConstMacro
itkStaticConstMacro(InputSpaceDimension, unsigned int, NInputDimensions)
itk::StackTransform< ScalarType, FixedImageDimension, MovingImageDimension >::UpdateStackSpacingAndOrigin
void UpdateStackSpacingAndOrigin()
Definition itkStackTransform.h:274
itk::StackTransform< ScalarType, FixedImageDimension, MovingImageDimension >::JacobianOfSpatialHessianType
std::vector< SpatialHessianType > JacobianOfSpatialHessianType
itk::StackTransform::itkStaticConstMacro
itkStaticConstMacro(ReducedInputSpaceDimension, unsigned int, NInputDimensions - 1)
itk::StackTransform::SubTransformPointer
typename SubTransformType::Pointer SubTransformPointer
Definition itkStackTransform.h:86
itk::StackTransform::GetNumberOfParameters
NumberOfParametersType GetNumberOfParameters() const override
Definition itkStackTransform.h:143
itk::StackTransform< ScalarType, FixedImageDimension, MovingImageDimension >::CreateSubTransforms
void CreateSubTransforms(const FixedParametersType &fixedParametersOfSubTransform)
Definition itkStackTransform.h:250
itk::StackTransform::StackTransform
StackTransform()=default
itk::StackTransform::GetSpatialJacobian
void GetSpatialJacobian(const InputPointType &, SpatialJacobianType &) const override
Definition itkStackTransform.h:342
itk::StackTransform::SetFixedParameters
void SetFixedParameters(const FixedParametersType &fixedParameters) override
Definition itkStackTransform.h:120
itk::StackTransform::SubTransformJacobianType
typename SubTransformType::JacobianType SubTransformJacobianType
Definition itkStackTransform.h:87
itk::StackTransform< ScalarType, FixedImageDimension, MovingImageDimension >::m_StackOrigin
ScalarType m_StackOrigin
Definition itkStackTransform.h:394
itk::StackTransform< ScalarType, FixedImageDimension, MovingImageDimension >::unimplementedOverrideMessage
static constexpr const char * unimplementedOverrideMessage
Definition itkStackTransform.h:318
itk::StackTransform::Self
StackTransform Self
Definition itkStackTransform.h:46
itk::StackTransform::GetNumberOfNonZeroJacobianIndices
NumberOfParametersType GetNumberOfNonZeroJacobianIndices() const override
itk::StackTransform::SetSubTransform
void SetSubTransform(unsigned int i, SubTransformType *transform)
Definition itkStackTransform.h:184
itk::StackTransform::SubTransformInputPointType
typename SubTransformType::InputPointType SubTransformInputPointType
Definition itkStackTransform.h:90
itk::StackTransform< ScalarType, FixedImageDimension, MovingImageDimension >::JacobianOfSpatialJacobianType
std::vector< SpatialJacobianType > JacobianOfSpatialJacobianType
itk::StackTransform::GetJacobianOfSpatialHessian
void GetJacobianOfSpatialHessian(const InputPointType &, SpatialHessianType &, JacobianOfSpatialHessianType &, NonZeroJacobianIndicesType &) const override
Definition itkStackTransform.h:380
itk::StackTransform::TransformPoint
OutputPointType TransformPoint(const InputPointType &inputPoint) const override
itk::StackTransform< ScalarType, FixedImageDimension, MovingImageDimension >::IndexOfStackSpacing
@ IndexOfStackSpacing
Definition itkStackTransform.h:244
itk::StackTransform< ScalarType, FixedImageDimension, MovingImageDimension >::IndexOfStackOrigin
@ IndexOfStackOrigin
Definition itkStackTransform.h:245
itk::StackTransform< ScalarType, FixedImageDimension, MovingImageDimension >::IndexOfNumberOfSubTransforms
@ IndexOfNumberOfSubTransforms
Definition itkStackTransform.h:243
itk::StackTransform< ScalarType, FixedImageDimension, MovingImageDimension >::NumberOfGeneralFixedParametersOfStack
@ NumberOfGeneralFixedParametersOfStack
Definition itkStackTransform.h:246
itk::StackTransform::ConstPointer
SmartPointer< const Self > ConstPointer
Definition itkStackTransform.h:49
itk::StackTransform::UpdateFixedParameters
void UpdateFixedParameters()
Definition itkStackTransform.h:194
itk::StackTransform::GetJacobianOfSpatialJacobian
void GetJacobianOfSpatialJacobian(const InputPointType &, SpatialJacobianType &, JacobianOfSpatialJacobianType &, NonZeroJacobianIndicesType &) const override
Definition itkStackTransform.h:362
itk::StackTransform::GetJacobianOfSpatialHessian
void GetJacobianOfSpatialHessian(const InputPointType &, JacobianOfSpatialHessianType &, NonZeroJacobianIndicesType &) const override
Definition itkStackTransform.h:371
itk::StackTransform::~StackTransform
~StackTransform() override=default
itk::StackTransform::GetParameters
const ParametersType & GetParameters() const override
itk::StackTransform::ParametersArrayType
typename ParametersType::ArrayType ParametersArrayType
Definition itkStackTransform.h:94
itk::StackTransform< ScalarType, FixedImageDimension, MovingImageDimension >::SpatialHessianType
FixedArray< Matrix< ScalarType, InputSpaceDimension, InputSpaceDimension >, OutputSpaceDimension > SpatialHessianType
itk::StackTransform< ScalarType, FixedImageDimension, MovingImageDimension >::NonZeroJacobianIndicesType
std::vector< unsigned long > NonZeroJacobianIndicesType
itk::StackTransform::SetAllSubTransforms
void SetAllSubTransforms(const SubTransformType &transform)
Definition itkStackTransform.h:205
itk::StackTransform::SetNumberOfSubTransforms
void SetNumberOfSubTransforms(const unsigned int num)
Definition itkStackTransform.h:158
itk::StackTransform::TransformVector
OutputVectorType TransformVector(const InputVectorType &) const override
Definition itkStackTransform.h:322
itk::StackTransform::SubTransformType
AdvancedTransform< TScalarType, Self::ReducedInputSpaceDimension, Self::ReducedOutputSpaceDimension > SubTransformType
Definition itkStackTransform.h:84
itk::StackTransform::ITK_DISALLOW_COPY_AND_MOVE
ITK_DISALLOW_COPY_AND_MOVE(StackTransform)
itk::StackTransform::GetNumberOfSubTransforms
auto GetNumberOfSubTransforms() const
Definition itkStackTransform.h:170
itk::StackTransform::GetJacobianOfSpatialJacobian
void GetJacobianOfSpatialJacobian(const InputPointType &, JacobianOfSpatialJacobianType &, NonZeroJacobianIndicesType &) const override
Definition itkStackTransform.h:354
itk::StackTransform::SubTransformOutputPointType
typename SubTransformType::OutputPointType SubTransformOutputPointType
Definition itkStackTransform.h:91
itk::StackTransform< ScalarType, FixedImageDimension, MovingImageDimension >::UpdateFixedParametersInternally
virtual void UpdateFixedParametersInternally(const FixedParametersType &fixedParametersOfSubTransform)
Definition itkStackTransform.h:285
itk::StackTransform::GetJacobian
void GetJacobian(const InputPointType &inputPoint, JacobianType &jac, NonZeroJacobianIndicesType &nzji) const override
itk::StackTransform::GetSpatialHessian
void GetSpatialHessian(const InputPointType &, SpatialHessianType &) const override
Definition itkStackTransform.h:348
itk::StackTransform::TransformCovariantVector
OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const override
Definition itkStackTransform.h:334
itk::StackTransform::itkStaticConstMacro
itkStaticConstMacro(OutputSpaceDimension, unsigned int, NOutputDimensions)
itk::StackTransform< ScalarType, FixedImageDimension, MovingImageDimension >::CreateSubTransform
virtual SubTransformPointer CreateSubTransform() const=0
itk::StackTransform::Pointer
SmartPointer< Self > Pointer
Definition itkStackTransform.h:48
itk::StackTransform::GetSubTransform
SubTransformPointer GetSubTransform(unsigned int i)
Definition itkStackTransform.h:226
itk::StackTransform::SetParameters
void SetParameters(const ParametersType &param) override
itk::StackTransform::TransformVector
OutputVnlVectorType TransformVector(const InputVnlVectorType &) const override
Definition itkStackTransform.h:328
itk::StackTransform< ScalarType, FixedImageDimension, MovingImageDimension >::m_SubTransformContainer
std::vector< SubTransformPointer > m_SubTransformContainer
Definition itkStackTransform.h:390
itkAdvancedTransform.h
itk
Definition itkAdvancedImageToImageMetric.h:43

Generated on 1768596610 for elastix by 1.15.0 |