00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00087
00088
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
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 }
00129
00130 #endif