freRigidRegistrationProcessorBase.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: freRigidRegistrationProcessorBase.txx,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 __freRigidRegistrationProcessorBase_txx
00023 #define __freRigidRegistrationProcessorBase_txx
00024 
00025 #include "freRigidRegistrationProcessorBase.h"
00026 #include "freOptimizerControllerBase.h"
00027 
00028 namespace FREE
00029 {
00030 
00034 
00035 template <class TRegistrationMethod, class TTransformBase, class TInterpolateBase,
00036 class TMetricBase, class TOptimizerBase, unsigned int VImageDimension>
00037 void
00038 RigidRegistrationProcessorBase<TRegistrationMethod, TTransformBase, TInterpolateBase, TMetricBase, TOptimizerBase, VImageDimension>::
00039 SetMetric(MetricType* pMetric)
00040 {
00041   if (pMetric != m_Metric.GetPointer())
00042   {
00043     m_Metric = pMetric;
00044     if (m_Registration.IsNotNull()) m_Registration->SetMetric(pMetric);
00045   }
00046 };
00047 
00048 template <class TRegistrationMethod, class TTransformBase, class TInterpolateBase,
00049 class TMetricBase, class TOptimizerBase, unsigned int VImageDimension>
00050 void
00051 RigidRegistrationProcessorBase<TRegistrationMethod, TTransformBase, TInterpolateBase, TMetricBase, TOptimizerBase, VImageDimension>::
00052 SetTransform(TransformType* pTransform)
00053 {
00054   if (pTransform != this->m_Transform.GetPointer())
00055   {
00056     this->m_Transform = pTransform;
00057     if (m_Registration.IsNotNull()) m_Registration->SetTransform(pTransform);
00058   }
00059 };
00060 
00061 template <class TRegistrationMethod, class TTransformBase, class TInterpolateBase,
00062 class TMetricBase, class TOptimizerBase, unsigned int VImageDimension>
00063 void
00064 RigidRegistrationProcessorBase<TRegistrationMethod, TTransformBase, TInterpolateBase, TMetricBase, TOptimizerBase, VImageDimension>::
00065 SetOptimizer(OptimizerType* pOptimizer)
00066 {
00067   if (pOptimizer != m_Optimizer.GetPointer())
00068   {
00069     m_Optimizer = pOptimizer;
00070     if (m_Registration.IsNotNull()) m_Registration->SetOptimizer(pOptimizer);
00071   }
00072 };
00073 
00074 template <class TRegistrationMethod, class TTransformBase, class TInterpolateBase,
00075 class TMetricBase, class TOptimizerBase, unsigned int VImageDimension>
00076 void
00077 RigidRegistrationProcessorBase<TRegistrationMethod, TTransformBase, TInterpolateBase, TMetricBase, TOptimizerBase, VImageDimension>::
00078 SetInterpolator(InterpolatorType* pInterpolator)
00079 {
00080   if (pInterpolator != m_Interpolator.GetPointer())
00081   {
00082     m_Interpolator = pInterpolator;
00083     if (m_Registration.IsNotNull()) m_Registration->SetInterpolator(pInterpolator);
00084   }
00085 };
00086 
00087 template <class TRegistrationMethod, class TTransformBase, class TInterpolateBase,
00088 class TMetricBase, class TOptimizerBase, unsigned int VImageDimension>
00089 const long
00090 RigidRegistrationProcessorBase<TRegistrationMethod, TTransformBase, TInterpolateBase, TMetricBase, TOptimizerBase, VImageDimension>::
00091 GetMaxIterationCount() const
00092 {
00093     if (this->m_pComponentCache)
00094     {
00095         SessionComponentCache* pCache = this->m_pComponentCache->SubCaches().GetElement(cComp_MainOptimizer);
00096         if(pCache)
00097         {
00098             const GenericOptimizerController* pOptCtrl = dynamic_cast<const GenericOptimizerController*>(pCache->Controller());
00099             if (!pOptCtrl) throwExceptionMacro("Error. Cannot get max iteration count. Component of main optimizer cache is not a descendant of OptimizerControllerInterface.");
00100             return pOptCtrl->GetMaxIterationCount(pCache,this->m_iResolutionLevel);
00101         }
00102     }
00103     return -1;
00104 };
00105 
00106 template <class TRegistrationMethod, class TTransformBase, class TInterpolateBase,
00107 class TMetricBase, class TOptimizerBase, unsigned int VImageDimension>
00108 void
00109 RigidRegistrationProcessorBase<TRegistrationMethod, TTransformBase, TInterpolateBase, TMetricBase, TOptimizerBase, VImageDimension>::
00110 ComputeRegistration()
00111 {
00112     Superclass::ComputeRegistration();
00113     if (this->m_Transform.IsNull())
00114         throwExceptionMacro("Cannot start registration; no transformation component available.");
00115     if (this->m_Interpolator.IsNull())
00116         throwExceptionMacro("Cannot start registration; no interpolation component available.");
00117     if (this->m_Metric.IsNull())
00118         throwExceptionMacro("Cannot start registration; no metric component available.");
00119     if (this->m_Optimizer.IsNull())
00120         throwExceptionMacro("Cannot start registration; no optimizer component available.");
00121 
00122     if (!(this->m_pComponentCache))
00123         throwExceptionMacro("Cannot start registration; no processor cache available. Ensure that the registration is initialized properly.");
00124 
00125     this->m_pOptimizerCache = this->m_pComponentCache->GetCacheByIDPath(cIDPSelf+IDPath(cComp_MainOptimizer));
00126     if (!this->m_pOptimizerCache)
00127         throwExceptionMacro("Cannot start registration; no optimizer cache available. Ensure that the registration is initialized properly.");
00128 
00129     this->m_lCurIteration = 0;
00130     //Rest will be defined in derived versions of the base class;
00131 };
00132 
00133 template <class TRegistrationMethod, class TTransformBase, class TInterpolateBase,
00134 class TMetricBase, class TOptimizerBase, unsigned int VImageDimension>
00135 RigidRegistrationProcessorBase<TRegistrationMethod, TTransformBase, TInterpolateBase, TMetricBase, TOptimizerBase, VImageDimension>::
00136 RigidRegistrationProcessorBase()
00137 {
00138     this->m_Interpolator = NULL;
00139     this->m_Metric = NULL;
00140     this->m_Optimizer = NULL;
00141     this->m_pOptimizerCache = NULL;
00142 
00143     this->m_Registration = RegistrationType::New();
00144 
00145     this->m_IterationObserver = IterationObserver::New();
00146     this->m_IterationNotificationEvent = NotificationEvent<Self>::New(this, &Self::OnNewIteration);
00147 }
00148 
00149 template <class TRegistrationMethod, class TTransformBase, class TInterpolateBase,
00150 class TMetricBase, class TOptimizerBase, unsigned int VImageDimension>
00151 RigidRegistrationProcessorBase<TRegistrationMethod, TTransformBase, TInterpolateBase, TMetricBase, TOptimizerBase, VImageDimension>::
00152 ~RigidRegistrationProcessorBase()
00153 {}
00154 ;
00155 
00156 template <class TRegistrationMethod, class TTransformBase, class TInterpolateBase,
00157 class TMetricBase, class TOptimizerBase, unsigned int VImageDimension>
00158 typename RigidRegistrationProcessorBase<TRegistrationMethod, TTransformBase, TInterpolateBase, TMetricBase, TOptimizerBase, VImageDimension>::TransformFieldPointer
00159 RigidRegistrationProcessorBase<TRegistrationMethod, TTransformBase, TInterpolateBase, TMetricBase, TOptimizerBase, VImageDimension>::
00160 ComputeTransformationField(const PointType& origin, const RegionType& region, const SpacingType& spacing)
00161 {
00162   return TransformInterface::ComputeTransformationField(origin,region,spacing);
00163 };
00164 
00165 template <class TRegistrationMethod, class TTransformBase, class TInterpolateBase,
00166 class TMetricBase, class TOptimizerBase, unsigned int VImageDimension>
00167 bool
00168 RigidRegistrationProcessorBase<TRegistrationMethod, TTransformBase, TInterpolateBase, TMetricBase, TOptimizerBase, VImageDimension>::
00169 TransformationIsValid () const
00170 {
00171   return this->m_bRegistrationStarted;
00172 };
00173 
00174 template <class TRegistrationMethod, class TTransformBase, class TInterpolateBase,
00175 class TMetricBase, class TOptimizerBase, unsigned int VImageDimension>
00176 void
00177 RigidRegistrationProcessorBase<TRegistrationMethod, TTransformBase, TInterpolateBase, TMetricBase, TOptimizerBase, VImageDimension>::
00178 NotifyProgress(const RegistrationStatusType status, const std::string& sComment)
00179 {
00180   if(this->fnOnProgress.IsNotNull())
00181     this->fnOnProgress->Execute(status, sComment,this);
00182 };
00183 
00184 template <class TRegistrationMethod, class TTransformBase, class TInterpolateBase,
00185 class TMetricBase, class TOptimizerBase, unsigned int VImageDimension>
00186 typename RigidRegistrationProcessorBase<TRegistrationMethod, TTransformBase, TInterpolateBase, TMetricBase, TOptimizerBase, VImageDimension>::TransformFunctionMediaPointer
00187 RigidRegistrationProcessorBase<TRegistrationMethod, TTransformBase, TInterpolateBase, TMetricBase, TOptimizerBase, VImageDimension>::
00188 GetTransformationFunction()
00189 {
00190   return GetTransformationFunction(this->m_FixedOrigin,this->m_FixedRegion,this->m_FixedSpacing);
00191 };
00192 
00193 template <class TRegistrationMethod, class TTransformBase, class TInterpolateBase,
00194 class TMetricBase, class TOptimizerBase, unsigned int VImageDimension>
00195 typename RigidRegistrationProcessorBase<TRegistrationMethod, TTransformBase, TInterpolateBase, TMetricBase, TOptimizerBase, VImageDimension>::TransformFunctionMediaPointer
00196 RigidRegistrationProcessorBase<TRegistrationMethod, TTransformBase, TInterpolateBase, TMetricBase, TOptimizerBase, VImageDimension>::
00197 GetInverseTransformationFunction()
00198 {
00199   return GetInverseTransformationFunction(this->m_FixedOrigin,this->m_FixedRegion,this->m_FixedSpacing);
00200 };
00201 
00202 template <class TRegistrationMethod, class TTransformBase, class TInterpolateBase,
00203 class TMetricBase, class TOptimizerBase, unsigned int VImageDimension>
00204 void
00205 RigidRegistrationProcessorBase<TRegistrationMethod, TTransformBase, TInterpolateBase, TMetricBase, TOptimizerBase, VImageDimension>::
00206 OnNewIteration(void* pSender, long threadID)
00207 {
00208     if(this->fnOnNextIteration.IsNotNull())
00209     {
00210       this->fnOnNextIteration->Execute(this->m_lCurIteration, NULL, this, 0);
00211     }
00212 
00213     this->m_lCurIteration++;
00214 
00215     //Store the current position of the optimizer (thus the parameters of the transform),
00216     //this enables the ComputeTransformationField to compute interims transformation fields
00217     //of the ongoing registration process.
00218     //use the controller interface to get the current position. Needed for
00219     //optimizers with different interface behaviour (e.g. vnl optimizer)
00220     const GenericOptimizerController* pOptimizerCtrl = dynamic_cast<const GenericOptimizerController*>(this->m_pOptimizerCache->Controller());
00221     if (!pOptimizerCtrl) throwExceptionMacro("Error. Cannot get current position. Component of main optimizer cache is not a descendant of OptimizerControllerInterface.");
00222     this->m_CurrentTransformParameters = pOptimizerCtrl->GetCurrentPosition(this->m_pOptimizerCache);
00223 };
00224 
00225 template <class TRegistrationMethod, class TTransformBase, class TInterpolateBase,
00226 class TMetricBase, class TOptimizerBase, unsigned int VImageDimension>
00227 void
00228 RigidRegistrationProcessorBase<TRegistrationMethod, TTransformBase, TInterpolateBase, TMetricBase, TOptimizerBase, VImageDimension>::
00229 ResetInternals()
00230 {
00231     //Set images to null to force the metric to release the images;
00232     this->m_Registration->SetFixedImage(0);
00233     this->m_Registration->SetMovingImage(0);
00234     //Reset the registration by creating a new one.
00235     this->m_Registration = RegistrationType::New();
00236 };
00237 
00238 }//End of Namespace free
00239 
00240 #endif

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