/*========================================================================= * * Copyright Insight Software Consortium * * 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 __itkCustomTransformInitializer_hxx #define __itkCustomTransformInitializer_hxx #include "itkCustomTransformInitializer.h" namespace itk { template< class TTransform, class TPointSet, class TMovingImage > CustomTransformInitializer< TTransform, TPointSet, TMovingImage > ::CustomTransformInitializer() { m_FixedCalculator = PointSetCalculatorType::New(); m_MovingCalculator = MovingImageCalculatorType::New(); } template< class TTransform, class TPointSet, class TMovingImage > void CustomTransformInitializer< TTransform, TPointSet, TMovingImage > ::InitializeTransform() { // Sanity check if ( !m_PointSet ) { itkExceptionMacro("Fixed Point Set has not been set"); return; } if ( !m_MovingImage ) { itkExceptionMacro("Moving Image has not been set"); return; } if ( !m_Transform ) { itkExceptionMacro("Transform has not been set"); return; } // If images come from filters, then update those filters. if ( m_PointSet->GetSource() ) { m_PointSet->GetSource()->Update(); } if ( m_MovingImage->GetSource() ) { m_MovingImage->GetSource()->Update(); } InputPointType rotationCenter; OutputVectorType translationVector; m_FixedCalculator->SetPointSet(m_PointSet); m_FixedCalculator->Compute(); m_MovingCalculator->SetImage(m_MovingImage); m_MovingCalculator->Compute(); typename PointSetCalculatorType::VectorType fixedCenter = m_FixedCalculator->GetCenterOfGravity(); typename MovingImageCalculatorType::VectorType movingCenter = m_MovingCalculator->GetCenterOfGravity(); for ( unsigned int i = 0; i < InputSpaceDimension; i++ ) { rotationCenter[i] = fixedCenter[i]; translationVector[i] = movingCenter[i] - fixedCenter[i]; } m_Transform->SetCenter(rotationCenter); m_Transform->SetTranslation(translationVector); } template< class TTransform, class TPointSet, class TMovingImage > void CustomTransformInitializer< TTransform, TPointSet, TMovingImage > ::PrintSelf(std::ostream & os, Indent indent) const { Superclass::PrintSelf(os, indent); os << indent << "Transform = " << std::endl; if ( m_Transform ) { os << indent << m_Transform << std::endl; } else { os << indent << "None" << std::endl; } os << indent << "PointSet = " << std::endl; if ( m_PointSet ) { os << indent << m_PointSet << std::endl; } else { os << indent << "None" << std::endl; } os << indent << "MovingImage = " << std::endl; if ( m_MovingImage ) { os << indent << m_MovingImage << std::endl; } else { os << indent << "None" << std::endl; } os << indent << "MovingMomentCalculator = " << std::endl; if ( m_MovingCalculator ) { os << indent << m_MovingCalculator << std::endl; } else { os << indent << "None" << std::endl; } os << indent << "FixedMomentCalculator = " << std::endl; if ( m_FixedCalculator ) { os << indent << m_FixedCalculator << std::endl; } else { os << indent << "None" << std::endl; } } } // namespace itk #endif /* __itkCustomTransformInitializer_hxx */