00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __freTransformFunctionMedia_txx
00023 #define __freTransformFunctionMedia_txx
00024
00025 #include "freTransformFunctionMedia.h"
00026
00027 namespace FREE
00028 {
00029
00033
00034
00035 template <class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
00036 void
00037 TransformFunctionMedia<TScalarType, NInputDimensions, NOutputDimensions>::
00038 SetFieldRegion(const RegionType ®ion)
00039 {
00040 m_FieldRegion = region;
00041 };
00042
00043 template <class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
00044 void
00045 TransformFunctionMedia<TScalarType, NInputDimensions, NOutputDimensions>::
00046 Reset()
00047 {
00048 m_Transform = 0;
00049
00050 m_FieldSpacing.Fill(1.0);
00051 m_FieldOrigin.Fill(0.0);
00052
00053 typename RegionType::IndexType index;
00054 index.Fill(0);
00055 typename RegionType::SizeType size;
00056 size.Fill(1);
00057 m_FieldRegion = RegionType(index, size);
00058 };
00059
00060 template <class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
00061 TransformFunctionMedia<TScalarType, NInputDimensions, NOutputDimensions>::
00062 ~TransformFunctionMedia()
00063 {
00064 Reset();
00065 };
00066
00067 template <class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
00068 TransformFunctionMedia<TScalarType, NInputDimensions, NOutputDimensions>::
00069 TransformFunctionMedia()
00070 {
00071 Reset();
00072 };
00073
00074 template <class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
00075 typename TransformFunctionMedia<TScalarType, NInputDimensions, NOutputDimensions>::TransformFieldPointer
00076 TransformFunctionMedia<TScalarType, NInputDimensions, NOutputDimensions>::
00077 GenerateField()
00078 {
00079 if (m_Transform.IsNull()) throwExceptionMacro("Error cannot generate field. Transform function has no transformation set.");
00080
00081 TransformFieldPointer smpField = TransformFieldType::New();
00082
00083 try
00084 {
00085
00086 smpField->SetOrigin(m_FieldOrigin);
00087 smpField->SetSpacing(m_FieldSpacing);
00088 smpField->SetRegions(m_FieldRegion);
00089 smpField->Allocate();
00090
00091 typename TransformFieldType::ValueType zeroVector;
00092 for (int i=0; i<TransformFieldType::ImageDimension; i++)
00093 zeroVector.SetNthComponent(i,0);
00094 smpField->FillBuffer(zeroVector);
00095
00096
00097 typedef itk::ImageRegionIterator<TransformFieldType> IteratorType;
00098 IteratorType iterator(smpField,m_FieldRegion);
00099
00100
00101 typedef typename TransformFieldType::PointType PointType;
00102 PointType actPoint;
00103 for (iterator.GoToBegin(); !(iterator.IsAtEnd()); ++iterator)
00104 {
00105 smpField->TransformIndexToPhysicalPoint(iterator.GetIndex(),actPoint);
00106 PointType transPoint = m_Transform->TransformPoint(actPoint);
00107 iterator.Set(transPoint-actPoint);
00108 }
00109 }
00110 catchAllNPassMacro("Unknown error when computing transformation field.");
00111
00112 return smpField;
00113 }
00114
00115 }
00116
00117 #endif