00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __freClosedFormRegistrationProcessor_txx
00023 #define __freClosedFormRegistrationProcessor_txx
00024
00025 #include "freClosedFormRegistrationProcessor.h"
00026 #include "freTransformSetupAdaptor.h"
00027
00028 #include "itkLandmarkBasedTransformInitializer.h"
00029
00030 namespace FREE
00031 {
00032
00036
00037 template <unsigned int VImageDimension>
00038 const long
00039 ClosedFormRegistrationProcessor<VImageDimension>::
00040 GetMaxIterationCount() const
00041 {
00042 return 1;
00043 };
00044
00045 template <unsigned int VImageDimension>
00046 void
00047 ClosedFormRegistrationProcessor<VImageDimension>::
00048 ComputeRegistration()
00049 {
00050 Superclass::ComputeRegistration();
00051
00052 if (this->m_Transform.IsNull())
00053 throwExceptionMacro("Cannot start registration; no transformation component available.");
00054
00055 if (this->m_FixedPointSet.IsNull())
00056 throwExceptionMacro("Cannot start registration; no fixed point set available.");
00057 if (this->m_MovingPointSet.IsNull())
00058 throwExceptionMacro("Cannot start registration; no moving point set available.");
00059
00060 if (!this->m_pComponentCache)
00061 throwExceptionMacro("Cannot start registration; no processor cache available. Ensure that the registration is initialized properly.");
00062
00063 this->m_lCurIteration = 0;
00064
00065 try
00066 {
00067
00068 if(this->fnOnProgress.IsNotNull())
00069 this->fnOnProgress->Execute(RSTInitProcessor,"Computing transform via closed form solution",this);
00070
00071 typedef itk::LandmarkBasedTransformInitializer<TransformType, ImageType, ImageType> LandmarkInitializerType;
00072 typename LandmarkInitializerType::Pointer lmInitializer = LandmarkInitializerType::New();
00073
00074 lmInitializer->SetFixedLandmarks(this->m_FixedPointSet->GetPoints()->CastToSTLContainer());
00075 lmInitializer->SetMovingLandmarks(this->m_MovingPointSet->GetPoints()->CastToSTLContainer());
00076 lmInitializer->SetTransform(this->m_Transform);
00077 lmInitializer->InitializeTransform();
00078 }
00079 catchAllNPassMacro("Unknown Error while computing registration.");
00080
00081 try
00082 {
00083
00084 this->m_CurrentTransformParameters = this->m_Transform->GetParameters();
00085 ComponentSetup* pTransformSetup = this->GetComponentSetup()->Components().GetElement(cComp_MainTransform);
00086
00087 TransformSetupAdaptor finalTransformAdaptor(pTransformSetup);
00088 finalTransformAdaptor.SetCurrentTransformParameters(this->m_CurrentTransformParameters);
00089 }
00090 catchAllNPassMacro("Unknown Error while saving result.");
00091 };
00092
00093 template <unsigned int VImageDimension>
00094 ClosedFormRegistrationProcessor<VImageDimension>::
00095 ClosedFormRegistrationProcessor()
00096 {
00097 this->m_FixedPointSet = NULL;
00098 this->m_MovingPointSet = NULL;
00099 };
00100
00101 template <unsigned int VImageDimension>
00102 ClosedFormRegistrationProcessor<VImageDimension>::
00103 ~ClosedFormRegistrationProcessor()
00104 {}
00105 ;
00106
00107 template <unsigned int VImageDimension>
00108 typename ClosedFormRegistrationProcessor<VImageDimension>::TransformFieldPointer
00109 ClosedFormRegistrationProcessor<VImageDimension>::
00110 ComputeTransformationField(const PointType& origin, const RegionType& region, const SpacingType& spacing)
00111 {
00112 return TransformInterface::ComputeTransformationField(origin,region,spacing);
00113 };
00114
00115 template <unsigned int VImageDimension>
00116 bool
00117 ClosedFormRegistrationProcessor<VImageDimension>::
00118 TransformationIsValid () const
00119 {
00120 return this->m_bRegistrationStarted;
00121 };
00122
00123 template <unsigned int VImageDimension>
00124 void
00125 ClosedFormRegistrationProcessor<VImageDimension>::
00126 NotifyProgress(const RegistrationStatusType status, const std::string& sComment)
00127 {
00128 if(this->fnOnProgress.IsNotNull())
00129 this->fnOnProgress->Execute(status, sComment,this);
00130 };
00131
00132 template <unsigned int VImageDimension>
00133 typename ClosedFormRegistrationProcessor<VImageDimension>::TransformFunctionMediaPointer
00134 ClosedFormRegistrationProcessor<VImageDimension>::
00135 GetTransformationFunction()
00136 {
00137 PointType origin;
00138 origin.Fill(0.0);
00139
00140 RegionType region;
00141 typename RegionType::IndexType index;
00142 index.Fill(0);
00143 typename RegionType::SizeType size;
00144 size.Fill(0);
00145 region.SetIndex(index);
00146 region.SetSize(size);
00147
00148 SpacingType spacing;
00149 spacing.Fill(1);
00150
00151 return GetTransformationFunction(origin,region,spacing);
00152 };
00153
00154 template <unsigned int VImageDimension>
00155 typename ClosedFormRegistrationProcessor<VImageDimension>::TransformFunctionMediaPointer
00156 ClosedFormRegistrationProcessor<VImageDimension>::
00157 GetInverseTransformationFunction()
00158 {
00159 PointType origin;
00160 origin.Fill(0.0);
00161
00162 RegionType region;
00163 typename RegionType::IndexType index;
00164 index.Fill(0);
00165 typename RegionType::SizeType size;
00166 size.Fill(0);
00167 region.SetIndex(index);
00168 region.SetSize(size);
00169
00170 SpacingType spacing;
00171 spacing.Fill(1);
00172
00173 return GetInverseTransformationFunction(origin,region,spacing);
00174 };
00175
00176 template <unsigned int VImageDimension>
00177 void
00178 ClosedFormRegistrationProcessor< VImageDimension>::
00179 ReleaseInputs()
00180 {
00181 Superclass::ReleaseInputs();
00182 this->m_FixedPointSet = NULL;
00183 this->m_MovingPointSet = NULL;
00184 };
00185
00186 }
00187
00188 #endif