freITKTransformControllerBase.txx

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   F.R.E.E. - flexible registration evaluation engine
00004   Version:   v.1.0.0
00005   Date:      $Date: 2006/09/01 12:00:00 $
00006   Module:    $RCSfile: freITKTransformControllerBase.txx,v $
00007   Language:  C++
00008 
00009 
00010   Copyright (c) 2007 Ralf o Floca (Department of Medical Informatics,
00011   Institute for Medical Biometry and Informatics, University of Heidelberg,
00012   Germany). All rights reserved.
00013   See FREECopyright.txt or http://www.mi.med.uni-hd.de/free/copyright.htm
00014   for details.
00015 
00016      This software is distributed WITHOUT ANY WARRANTY; without even 
00017      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00018      PURPOSE.  See the above copyright notices for more information.
00019 
00020 =========================================================================*/
00021 #ifndef __freITKTransformControllerBase_txx
00022 #define __freITKTransformControllerBase_txx
00023 
00024 #include "freITKTransformControllerBase.h"
00025 
00026 namespace FREE
00027 {
00028 
00032 template <class TITKTransform, unsigned int VDimension>
00033 typename ITKTransformControllerBase<TITKTransform, VDimension>::GenericComponentPointer
00034 ITKTransformControllerBase<TITKTransform, VDimension>::
00035 BuildInverseTransform(GenericComponentType* pTransformComponent) const
00036 {
00037   if (!pTransformComponent) throwCtrlExceptionMacro("","No transform component available. Passed component pointer is null.");
00038  
00039   typename ComponentType::Pointer smpTransform;
00040   typename ComponentType::Pointer smpInvTransform;
00041 
00042   try
00043   {
00044     smpTransform = dynamic_cast<ComponentType*>(pTransformComponent);
00045     smpInvTransform = dynamic_cast<ComponentType*>(smpTransform->CreateAnother().GetPointer());
00046   }
00047   catchAllNPassMacro("Wrong component type. Controller "<< this->ControllerID() << " cannot handle components of type " << pTransformComponent->GetNameOfClass() << ".");
00048 
00049   GenericComponentPointer result;
00050 
00051   if (smpTransform->GetInverse(smpInvTransform))
00052   {
00053     result = smpInvTransform.GetPointer();
00054   }
00055 
00056   return result;
00057 };
00058 
00059 template <class TITKTransform, unsigned int VDimension>
00060 ITKTransformControllerBase<TITKTransform, VDimension>::
00061 ITKTransformControllerBase()
00062 {
00063   //Profile settings
00064   this->UpdateControllerID(ControllerID::ITKTransformControllerBase);
00065   this->m_Description = "Base class for all trasformations based on itk::Transform.";
00066 };
00067 
00068 template <class TITKTransform, unsigned int VDimension>
00069 typename ITKTransformControllerBase<TITKTransform, VDimension>::TransformFunctionMediaPointer
00070 ITKTransformControllerBase<TITKTransform, VDimension>::
00071 GenerateTransformationFunction(SessionComponentCache* pTransformCache,
00072                                const TransformParametersType& parameters) const
00073 {
00074         if (!pTransformCache) throwCtrlExceptionMacro("","Cannot generate transform function. Passed cache is null.");
00075   if (!pTransformCache->ComponentIsAssigned()) throwCtrlExceptionMacro("","Cannot generate transform function. Cache has no component. ID Path: "<<pTransformCache->GetIDPath().ToStr());
00076 
00077   typename ComponentType::Pointer smpTransform;
00078   typename ComponentType::Pointer smpNewTransform;
00079 
00080   try
00081   {
00082     smpTransform = dynamic_cast<ComponentType*>(pTransformCache->Component().GetPointer());
00083   }
00084   catchAllNPassMacro("Transform in cache seems to have wrong type and cannot be casted. Controller "<< this->ControllerID() << " cannot handle components of type " << pTransformCache->Component()->GetNameOfClass() << ".");
00085 
00086   try
00087   {
00088     smpNewTransform = dynamic_cast<ComponentType*>(smpTransform->CreateAnother().GetPointer());
00089   }
00090   catchAllNPassMacro("Cloned transform seems to have wrong type and cannot be casted. Controller "<< this->ControllerID() << "; ID Path: " << pTransformCache->GetIDPath().ToStr());
00091 
00092   CopyFixedParameters(smpTransform,smpNewTransform);
00093 
00094   smpNewTransform->SetParametersByValue(parameters);
00095 
00096   TransformFunctionMediaPointer transformFunction = TransformFunctionMediaType::New();
00097   transformFunction->SetTransform(smpNewTransform);
00098 
00099   return transformFunction;
00100 };
00101 
00102 template <class TITKTransform, unsigned int VDimension>
00103 typename ITKTransformControllerBase<TITKTransform, VDimension>::TransformFunctionMediaPointer
00104 ITKTransformControllerBase<TITKTransform, VDimension>::
00105 GenerateInverseTransformationFunction(SessionComponentCache* pTransformCache,
00106                                       const TransformParametersType& parameters) const
00107 {
00108         if (!pTransformCache) throwCtrlExceptionMacro("","Cannot generate transform function. Passed cache is null.");
00109   if (!pTransformCache->ComponentIsAssigned()) throwCtrlExceptionMacro("","Cannot generate transform function. Cache has no component. ID Path: "<<pTransformCache->GetIDPath().ToStr());
00110 
00111   typename ComponentType::Pointer smpTransform;
00112   typename ComponentType::Pointer smpNewTransform;
00113 
00114   try
00115   {
00116     smpTransform = dynamic_cast<ComponentType*>(pTransformCache->Component().GetPointer());
00117   }
00118   catchAllNPassMacro("Transform in cache seems to have wrong type and cannot be casted. Controller "<< this->ControllerID() << " cannot handle components of type " << pTransformCache->Component()->GetNameOfClass() << ".");
00119 
00120   try
00121   {
00122     smpNewTransform = dynamic_cast<ComponentType*>(smpTransform->CreateAnother().GetPointer());
00123   }
00124   catchAllNPassMacro("Cloned transform seems to have wrong type and cannot be casted. Controller "<< this->ControllerID() << "; ID Path: " << pTransformCache->GetIDPath().ToStr());
00125 
00126   smpTransform->SetParametersByValue(parameters);
00127 
00128   TransformFunctionMediaPointer transformFunction = 0;
00129 
00130   if (smpTransform->GetInverse(smpNewTransform))
00131   { //transform can be inverted so create the transform function
00132     transformFunction = TransformFunctionMediaType::New();
00133     transformFunction->SetTransform(smpNewTransform);
00134   }
00135   return transformFunction;
00136 };
00137 
00138 template <class TITKTransform, unsigned int VDimension>
00139 void
00140 ITKTransformControllerBase<TITKTransform, VDimension>::
00141 CopyFixedParameters(ComponentType* pOrigin, ComponentType* pDestination) const
00142 {
00143   //default: do nothing
00144 };
00145 
00146 } //end of namespace free
00147 
00148 #endif

Generated at Sat Oct 13 16:24:54 2007 for f.r.e.e. - Flexible Registration and Evaluation Engine by doxygen 1.5.3 written by Dimitri van Heesch, © 1997-2000