freTransformBasedRegistrationProcessorInterface.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: freTransformBasedRegistrationProcessorInterface.h,v $
00007   Language:  C++
00008  
00009  
00010  
00011   Copyright (c) 2007 Ralf o Floca (Department of Medical Informatics,
00012   Institute for Medical Biometry and Informatics, University of Heidelberg,
00013   Germany). All rights reserved.
00014   See FREECopyright.txt or http://www.mi.med.uni-hd.de/free/copyright.htm
00015   for details.
00016  
00017      This software is distributed WITHOUT ANY WARRANTY; without even 
00018      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00019      PURPOSE.  See the above copyright notices for more information.
00020  
00021 =========================================================================*/
00022 #ifndef __freTransformBasedRegistrationProcessorInterface_txx
00023 #define __freTransformBasedRegistrationProcessorInterface_txx
00024 
00025 #include "freTransformBasedRegistrationProcessorInterface.h"
00026 
00027 namespace FREE
00028 {
00029 
00033 
00034 template <class TTransformBase,unsigned int VImageDimension>
00035 void
00036 TransformBasedRegistrationProcessorInterface<TTransformBase, VImageDimension>::
00037 SetTransform(TransformType* pTransform)
00038 {
00039   if (pTransform != m_Transform.GetPointer())
00040   {
00041     m_Transform = pTransform;
00042   }
00043 };
00044 
00045 template <class TTransformBase,unsigned int VImageDimension>
00046 TransformBasedRegistrationProcessorInterface<TTransformBase, VImageDimension>::
00047 TransformBasedRegistrationProcessorInterface()
00048 {
00049     m_Transform = NULL;
00050 }
00051 
00052 template <class TTransformBase,unsigned int VImageDimension>
00053 typename TransformBasedRegistrationProcessorInterface<TTransformBase, VImageDimension>::TransformFieldPointer
00054 TransformBasedRegistrationProcessorInterface<TTransformBase, VImageDimension>::
00055 ComputeTransformationField(const PointType& origin, const RegionType& region, const SpacingType& spacing)
00056 {
00057     NotifyProgress(RSTFinalizing, "Computing transformation field");
00058 
00059     TransformFunctionMediaPointer transformFunction = GetTransformationFunction(origin,region,spacing);
00060 
00061     TransformFieldPointer smpField = transformFunction->GenerateField();
00062 
00063     return smpField;
00064 };
00065 
00066 template <class TTransformBase,unsigned int VImageDimension>
00067 typename TransformBasedRegistrationProcessorInterface<TTransformBase, VImageDimension>::TransformFunctionMediaPointer
00068 TransformBasedRegistrationProcessorInterface<TTransformBase, VImageDimension>::
00069 GetTransformationFunction(const PointType& origin, const RegionType& region, const SpacingType& spacing)
00070 {
00071 
00072         if (!TransformationIsValid()) throwExceptionMacro("Cannot return transformation function before registration is processed.");
00073         if (m_Transform.IsNull()) throwExceptionMacro("Cannot return transformation function when transform is not set.");
00074 
00075   NotifyProgress(RSTFinalizing, "Computing transformation function");
00076 
00077   TransformPointer newTransform = dynamic_cast<TransformType*>((m_Transform->CreateAnother()).GetPointer());
00078   if (newTransform.IsNull()) throwExceptionMacro("Transform is not based on the TransformType. Class of transform: "<<m_Transform->GetNameOfClass());
00079   
00080   try
00081   {
00082     newTransform->SetFixedParameters(m_Transform->GetFixedParameters());
00083   }
00084   catch(...)
00085   {
00086     //not every transform has fixed parameters and the default implementation of itk
00087     //throws an exception if you try to get or set exception in these cases.
00088     //catch the exception an go on, with just setting the normal parameters
00089   }
00090 
00091   newTransform->SetParametersByValue(m_CurrentTransformParameters);
00092 
00093   TransformFunctionMediaPointer transformFunction = TransformFunctionMediaType::New();
00094   transformFunction->SetTransform(newTransform);
00095   transformFunction->SetFieldOrigin(origin);
00096   transformFunction->SetFieldSpacing(spacing);
00097   transformFunction->SetFieldRegion(region);
00098 
00099   return transformFunction;
00100 };
00101 
00102 template <class TTransformBase,unsigned int VImageDimension>
00103 typename TransformBasedRegistrationProcessorInterface<TTransformBase, VImageDimension>::TransformFunctionMediaPointer
00104 TransformBasedRegistrationProcessorInterface<TTransformBase, VImageDimension>::
00105 GetInverseTransformationFunction(const PointType& origin, const RegionType& region, const SpacingType& spacing)
00106 {
00107         if (!TransformationIsValid()) throwExceptionMacro("Cannot return transformation function before registration is processed.");
00108         if (m_Transform.IsNull()) throwExceptionMacro("Cannot return transformation function when transform is not set.");
00109 
00110   NotifyProgress(RSTFinalizing, "Computing transformation function");
00111 
00112   TransformPointer newTransform = dynamic_cast<TransformType*>((m_Transform->CreateAnother()).GetPointer());
00113   if (newTransform.IsNull()) throwExceptionMacro("Transform is not based on the TransformType. Class of transform: "<<m_Transform->GetNameOfClass());
00114 
00115     // get last actual transform parameter and set the transform component
00116   m_Transform->SetParametersByValue(m_CurrentTransformParameters);
00117   if (! m_Transform->GetInverse(newTransform)) throwExceptionMacro("Cannot generate inverse of the used transform. Transform: "<<m_Transform->GetNameOfClass());
00118 
00119   TransformFunctionMediaPointer transformFunction = TransformFunctionMediaType::New();
00120   transformFunction->SetTransform(newTransform);
00121   transformFunction->SetFieldOrigin(origin);
00122   transformFunction->SetFieldSpacing(spacing);
00123   transformFunction->SetFieldRegion(region);
00124 
00125   return transformFunction;
00126 };
00127 
00128 }//End of Namespace free
00129 
00130 #endif

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