/*========================================================================= Program: vtkINRIA3D Module: $Id: itkGeneralTransform.cxx 1 2008-01-22 19:01:33Z ntoussaint $ Language: C++ Author: $Author: ntoussaint $ Date: $Date: 2008-01-22 20:01:33 +0100 (Tue, 22 Jan 2008) $ Version: $Revision: 1 $ Copyright (c) 2007 INRIA - Asclepios Project. All rights reserved. See Copyright.txt for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef _itkGeneralTransform_cxx #define _itkGeneralTransform_cxx #include "itkGeneralTransform.h" namespace itk { /* * Constructor */ // Constructor with default arguments template GeneralTransform ::GeneralTransform(): Superclass( ParametersDimension ) { } /* * Destructor */ // Constructor with default arguments template GeneralTransform ::~GeneralTransform() { m_RemovedTransformList.clear(); m_TransformList.clear(); } // Set the parameters template void GeneralTransform ::SetFixedParameters( const FixedParametersType & parameters ) { itkExceptionMacro("GeneralTransform does not handle any parameter system yet"); } // Set the parameters template void GeneralTransform ::SetParameters( const ParametersType & parameters ) { itkExceptionMacro("GeneralTransform does not handle any parameter system yet"); } // Get the parameters template const typename GeneralTransform::ParametersType & GeneralTransform ::GetParameters( void ) const { itkExceptionMacro("GeneralTransform does not handle any parameter system yet"); return this->m_Parameters; } // Print self template void GeneralTransform:: PrintSelf(std::ostream &os, Indent indent) const { Superclass::PrintSelf(os,indent); os << indent << "Number Of Transforms in Stack : " << this->GetNumberOfTransformsInStack() << std::endl; os << indent << "Is Transform Linear ? : " << this->IsLinear() << std::endl; } // Transform a point template typename GeneralTransform::OutputPointType GeneralTransform:: TransformPoint(const InputPointType &point) const { OutputPointType output; output = point; typename TransformListType::const_reverse_iterator it = m_TransformList.rbegin(); while(it != m_TransformList.rend()) { output = (*it)->TransformPoint (output); it++; } return output; } // Transform a vector template typename GeneralTransform::OutputVectorType GeneralTransform:: TransformVector(const InputVectorType &vect) const { OutputVectorType output; output = vect; typename TransformListType::const_reverse_iterator it = m_TransformList.rbegin(); while(it != m_TransformList.rend()) { output = (*it)->TransformVector (output); it++; } return output; } // Transform a vnl_vector_fixed template typename GeneralTransform::OutputVnlVectorType GeneralTransform:: TransformVector(const InputVnlVectorType &vect) const { OutputVnlVectorType output; output = vect; typename TransformListType::const_reverse_iterator it = m_TransformList.rbegin(); while(it != m_TransformList.rend()) { output = (*it)->TransformVector (output); it++; } return output; } // Transform a CovariantVector template typename GeneralTransform::OutputCovariantVectorType GeneralTransform:: TransformCovariantVector(const InputCovariantVectorType &vect) const { itkExceptionMacro("cannot transform covariant vector with this type of transform"); return vect; } // return an inverse transformation template bool GeneralTransform:: GetInverse( Self* inverse) const { (void) inverse; return false; } // Set the parameters for an Identity transform of this class template void GeneralTransform:: SetIdentity() { this->RemoveAllTransforms(); } template bool GeneralTransform:: Redo (void) { if (!m_RemovedTransformList.size()) return false; m_TransformList.push_back(m_RemovedTransformList.back()); m_RemovedTransformList.pop_back(); return true; } template bool GeneralTransform:: Undo (void) { if (!m_TransformList.size()) return false; m_RemovedTransformList.push_back(m_TransformList.back()); m_TransformList.pop_back(); return true; } template unsigned int GeneralTransform:: InsertTransform (TransformConstPointerType arg) { m_TransformList.push_back(arg); m_RemovedTransformList.clear(); return m_TransformList.size(); } template typename GeneralTransform::TransformConstPointerType GeneralTransform:: GetTransform (unsigned int i) { if (i >= m_TransformList.size() ) return ITK_NULLPTR; return m_TransformList[i]; } template void GeneralTransform:: RemoveAllTransforms (void) { m_TransformList.clear(); m_RemovedTransformList.clear(); } template typename GeneralTransform::MatrixOffsetTransformPointerType GeneralTransform:: GetGlobalLinearTransform (void) const { if (!this->IsLinear()) { itkExceptionMacro("Transform input is not in a linear form"); } typename MatrixOffsetTransformType::Pointer ret = MatrixOffsetTransformType::New(); ret->SetIdentity(); typename TransformListType::const_iterator it = this->m_TransformList.begin(); while( it != this->m_TransformList.end()) { const MatrixOffsetTransformType* transform = dynamic_cast(it->GetPointer()); if(transform) ret->Compose (transform, 1); else { const Self *genTrs = dynamic_cast(it->GetPointer()); if(genTrs) ret->Compose(genTrs->GetGlobalLinearTransform()); } it++; } return ret; } template bool GeneralTransform:: IsLinear (void) const { typename TransformListType::const_iterator it = m_TransformList.begin(); while( it != m_TransformList.end()) { const itk::Transform *transform = it->GetPointer(); if(!transform->IsLinear()) return false; ++it; } return true; } } // namespace #endif