Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ADD_ELXCOMPONENT( StackTransformBendingEnergyPenalty
elxStackTransformBendingEnergyPenaltyTerm.h
elxStackTransformBendingEnergyPenaltyTerm.hxx
elxStackTransformBendingEnergyPenaltyTerm.cxx
itkStackTransformBendingEnergyPenaltyTerm.h
itkStackTransformBendingEnergyPenaltyTerm.hxx
)

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*=========================================================================
*
* 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.
*
*=========================================================================*/
#include "elxStackTransformBendingEnergyPenaltyTerm.h"

elxInstallMacro( StackTransformBendingEnergyPenalty );
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
/*=========================================================================
*
* 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 __elxStackTransformBendingEnergyPenaltyTerm_H__
#define __elxStackTransformBendingEnergyPenaltyTerm_H__

#include "elxIncludes.h" // include first to avoid MSVS warning
#include "itkStackTransformBendingEnergyPenaltyTerm.h"

#include "itkAdvancedBSplineDeformableTransform.h"
#include "itkStackTransform.h"

namespace elastix
{

/**
* \class StackTransformBendingEnergyPenalty
* \brief A penalty term based on the bending energy of a thin metal sheet.
*
*
* [1]: D. Rueckert, L. I. Sonoda, C. Hayes, D. L. G. Hill,
* M. O. Leach, and D. J. Hawkes, "Nonrigid registration
* using free-form deformations: Application to breast MR
* images", IEEE Trans. Med. Imaging 18, 712-721, 1999.\n
* [2]: M. Staring and S. Klein,
* "Itk::Transforms supporting spatial derivatives"",
* Insight Journal, http://hdl.handle.net/10380/3215 .\n
* [3]: M. Polfliet, et al. "Intrasubject multimodal groupwise
* registration with the conditional template entropy."
* Medical image analysis 46 (2018): 15-25.\n
*
* The parameters used in this class are:
* \parameter Metric: Select this metric as follows:\n
* <tt>(Metric "StackTransformBendingEnergyPenalty")</tt>
*
* \ingroup Metrics
*
*/

template< class TElastix >
class StackTransformBendingEnergyPenalty :
public
itk::StackTransformBendingEnergyPenaltyTerm<
typename MetricBase< TElastix >::FixedImageType,
double >,
public MetricBase< TElastix >
{
public:

/** Standard ITK-stuff. */
typedef StackTransformBendingEnergyPenalty Self;
typedef itk::StackTransformBendingEnergyPenaltyTerm< typename MetricBase< TElastix >::FixedImageType, double > Superclass1;
typedef MetricBase< TElastix > Superclass2;
typedef itk::SmartPointer< Self > Pointer;
typedef itk::SmartPointer< const Self > ConstPointer;

/** Method for creation through the object factory. */
itkNewMacro( Self );

/** Run-time type information (and related methods). */
itkTypeMacro( StackTransformBendingEnergyPenalty, itk::StackTransformBendingEnergyPenaltyTerm );

/** Name of this class.
* Use this name in the parameter file to select this specific metric. \n
* example: <tt>(Metric "StackTransformBendingEnergyPenalty")</tt>\n
*/
elxClassNameMacro( "StackTransformBendingEnergyPenalty" );

/** Typedefs from the superclass. */
typedef typename
Superclass1::CoordinateRepresentationType CoordinateRepresentationType;
typedef typename Superclass1::MovingImageType MovingImageType;
typedef typename Superclass1::MovingImagePixelType MovingImagePixelType;
typedef typename Superclass1::MovingImageConstPointer MovingImageConstPointer;
typedef typename Superclass1::FixedImageType FixedImageType;
typedef typename Superclass1::FixedImageConstPointer FixedImageConstPointer;
typedef typename Superclass1::FixedImageRegionType FixedImageRegionType;
typedef typename FixedImageType::SizeType FixedImageSizeType;
typedef typename Superclass1::TransformType TransformType;
typedef typename Superclass1::TransformPointer TransformPointer;
typedef typename Superclass1::InputPointType InputPointType;
typedef typename Superclass1::OutputPointType OutputPointType;
typedef typename Superclass1::TransformParametersType TransformParametersType;
typedef typename Superclass1::TransformJacobianType TransformJacobianType;
typedef typename Superclass1::InterpolatorType InterpolatorType;
typedef typename Superclass1::InterpolatorPointer InterpolatorPointer;
typedef typename Superclass1::RealType RealType;
typedef typename Superclass1::ScalarType ScalarType;
typedef typename Superclass1::GradientPixelType GradientPixelType;
typedef typename Superclass1::GradientImageType GradientImageType;
typedef typename Superclass1::GradientImagePointer GradientImagePointer;
typedef typename Superclass1::GradientImageFilterType GradientImageFilterType;
typedef typename Superclass1::GradientImageFilterPointer GradientImageFilterPointer;
typedef typename Superclass1::FixedImageMaskType FixedImageMaskType;
typedef typename Superclass1::FixedImageMaskPointer FixedImageMaskPointer;
typedef typename Superclass1::MovingImageMaskType MovingImageMaskType;
typedef typename Superclass1::MovingImageMaskPointer MovingImageMaskPointer;
typedef typename Superclass1::MeasureType MeasureType;
typedef typename Superclass1::DerivativeType DerivativeType;
typedef typename Superclass1::ParametersType ParametersType;
typedef typename Superclass1::FixedImagePixelType FixedImagePixelType;
typedef typename Superclass1::MovingImageRegionType MovingImageRegionType;
typedef typename Superclass1::ImageSamplerType ImageSamplerType;
typedef typename Superclass1::ImageSamplerPointer ImageSamplerPointer;
typedef typename Superclass1::ImageSampleContainerType ImageSampleContainerType;
typedef typename
Superclass1::ImageSampleContainerPointer ImageSampleContainerPointer;
typedef typename Superclass1::FixedImageLimiterType FixedImageLimiterType;
typedef typename Superclass1::MovingImageLimiterType MovingImageLimiterType;
typedef typename
Superclass1::FixedImageLimiterOutputType FixedImageLimiterOutputType;
typedef typename
Superclass1::MovingImageLimiterOutputType MovingImageLimiterOutputType;

/** The fixed image dimension. */
itkStaticConstMacro( FixedImageDimension, unsigned int,
FixedImageType::ImageDimension );

/** The moving image dimension. */
itkStaticConstMacro( MovingImageDimension, unsigned int,
MovingImageType::ImageDimension );

typedef itk::AdvancedBSplineDeformableTransformBase< ScalarType, FixedImageDimension > BSplineTransformBaseType;
typedef itk::AdvancedCombinationTransform< ScalarType, FixedImageDimension > CombinationTransformType;
typedef itk::StackTransform< ScalarType, FixedImageDimension, MovingImageDimension > StackTransformType;
typedef itk::AdvancedBSplineDeformableTransformBase< ScalarType, FixedImageDimension - 1 > ReducedDimensionBSplineTransformBaseType;

/** Typedef's inherited from elastix. */
typedef typename Superclass2::ElastixType ElastixType;
typedef typename Superclass2::ElastixPointer ElastixPointer;
typedef typename Superclass2::ConfigurationType ConfigurationType;
typedef typename Superclass2::ConfigurationPointer ConfigurationPointer;
typedef typename Superclass2::RegistrationType RegistrationType;
typedef typename Superclass2::RegistrationPointer RegistrationPointer;
typedef typename Superclass2::ITKBaseType ITKBaseType;

/** Sets up a timer to measure the initialization time and
* calls the Superclass' implementation.
*/
virtual void Initialize( void ) throw ( itk::ExceptionObject );

virtual void BeforeRegistration( void );

virtual void BeforeEachResolution( void );

protected:

/** The constructor. */
StackTransformBendingEnergyPenalty() {}

/** The destructor. */
virtual ~StackTransformBendingEnergyPenalty() {}

private:

/** The private constructor. */
StackTransformBendingEnergyPenalty( const Self & ); // purposely not implemented
/** The private copy constructor. */
void operator=( const Self & ); // purposely not implemented

};

} // end namespace elastix

#ifndef ITK_MANUAL_INSTANTIATION
#include "elxStackTransformBendingEnergyPenaltyTerm.hxx"
#endif

#endif // end #ifndef __elxStackTransformBendingEnergyPenaltyTerm_H__
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*=========================================================================
*
* 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 __elxStackTransformBendingEnergyPenaltyTerm_HXX__
#define __elxStackTransformBendingEnergyPenaltyTerm_HXX__

#include "elxStackTransformBendingEnergyPenaltyTerm.h"
#include "itkTimeProbe.h"

namespace elastix
{

/**
* ******************* Initialize ***********************
*/

template< class TElastix >
void
StackTransformBendingEnergyPenalty< TElastix >
::Initialize( void ) throw ( itk::ExceptionObject )
{
itk::TimeProbe timer;
timer.Start();
this->Superclass1::Initialize();
timer.Stop();
elxout << "Initialization of StackTransformBendingEnergy metric took: "
<< static_cast< long >( timer.GetMean() * 1000 ) << " ms." << std::endl;

} // end Initialize()


/**
* ***************** BeforeRegistration ***********************
*/

template< class TElastix >
void
StackTransformBendingEnergyPenalty< TElastix >
::BeforeRegistration( void )
{
bool subtractMean = false;
this->GetConfiguration()->ReadParameter( subtractMean, "SubtractMean", this->GetComponentLabel(), 0, 0 );
this->SetSubtractMean( subtractMean );
} // end BeforeRegistration()


/**
* ***************** BeforeEachResolution ***********************
*/

template< class TElastix >
void
StackTransformBendingEnergyPenalty< TElastix >
::BeforeEachResolution( void )
{
/** Get the current resolution level. */
unsigned int level = ( this->m_Registration->GetAsITKBaseType() )->GetCurrentLevel();

/** Check if this transform is a B-spline transform. */
CombinationTransformType * testPtr1 = dynamic_cast< CombinationTransformType * >( this->GetElastix()->GetElxTransformBase() );
if( testPtr1 )
{
/** Check for B-spline transform. */
BSplineTransformBaseType * testPtr2 = dynamic_cast< BSplineTransformBaseType * >( testPtr1->GetCurrentTransform() );
if( testPtr2 )
{
this->SetGridSize( testPtr2->GetGridRegion().GetSize() );
this->SetTransformIsBSpline( true );
itkExceptionMacro( << "This metric can only be used in combination with a StackTransform" );
}
else
{
StackTransformType * testPtr3 = dynamic_cast< StackTransformType * >( testPtr1->GetCurrentTransform() );
if( testPtr3 )
{
this->SetTransformIsStackTransform( true );

if( testPtr3->GetNumberOfSubTransforms() > 0 )
{
ReducedDimensionBSplineTransformBaseType * testPtr4
= dynamic_cast< ReducedDimensionBSplineTransformBaseType * >( testPtr3->GetSubTransform( 0 ).GetPointer() );
if( testPtr4 )
{
FixedImageSizeType gridSize;
gridSize.Fill( testPtr3->GetNumberOfSubTransforms() );
this->SetGridSize( gridSize );
this->SetSubTransformIsBSpline( true );

}
}
}
else
{
itkExceptionMacro( << "This metric can only be used in combination with a StackTransform" );
}
}
}

} // end BeforeEachResolution()


} // end namespace elastix

#endif // end #ifndef __elxStackTransformBendingEnergyPenaltyTerm_HXX__
Loading