17 #ifndef __itkFEMFiniteDifferenceFunctionLoad_txx
18 #define __itkFEMFiniteDifferenceFunctionLoad_txx
28 template<
class TMoving,
class TFixed>
35 for (
unsigned int i=0; i<ImageDimension; i++)
37 m_MetricRadius[i] = 1;
40 m_DifferenceFunction=
NULL;
41 m_DeformationField=
NULL;
46 template<
class TMoving,
class TFixed>
53 if (!m_DifferenceFunction)
55 typename defaultRegistrationFunctionType::Pointer drfp
56 = defaultRegistrationFunctionType::New();
57 this->SetMetric(static_cast<FiniteDifferenceFunctionType *>(drfp));
59 std::cout <<
" load sizes " << m_DeformationField->GetLargestPossibleRegion().GetSize()
60 <<
" image " << m_FixedImage->GetLargestPossibleRegion().GetSize() << std::endl;
62 m_DifferenceFunction->InitializeIteration();
67 template<
class TMoving,
class TFixed>
71 this->InitializeIteration();
74 template<
class TMoving,
class TFixed>
78 if ( m_DifferenceFunction )
79 std::cout <<
" energy " << m_DifferenceFunction->GetEnergy() << std::endl;
82 template<
class TMoving,
class TFixed>
86 if ( m_DifferenceFunction )
87 return m_DifferenceFunction->GetEnergy();
91 template<
class TMoving,
class TFixed>
95 if ( m_DifferenceFunction ) m_DifferenceFunction->SetEnergy(e);
98 template<
class TMoving,
class TFixed>
105 #if __DEFINED__FIXME__THIS_IS_NEVER_REACHED_BECAUSE_OF_OVERRIDING_RETURN_STATEMENT__
106 template<
class TMoving,
class TFixed>
111 Float energy=0.0,defe=0.0;
114 vnl_vector_fixed<Float,2*ImageDimension> InVec(0.0);
122 ArrayType::iterator elt = el->begin();
124 const unsigned int Nnodes=(*elt)->GetNumberOfNodes();
126 FEMVectorType Gpos,Gsol;
127 Gpos.set_size(ImageDimension); Gpos.fill(0.0);
128 Gsol.set_size(ImageDimension); Gsol.fill(0.0);
130 solmat.set_size(Nnodes*ImageDimension,1);
132 for(; elt!=el->end(); elt++)
134 for(
unsigned int i=0; i<m_NumberOfIntegrationPoints; i++)
136 dynamic_cast<Element*
>(&*(*elt))->GetIntegrationPointAndWeight(i,ip,w,m_NumberOfIntegrationPoints);
140 Float detJ=(*elt)->JacobianDeterminant(ip);
142 for(
unsigned int f=0; f<ImageDimension; f++)
146 for(
unsigned int n=0; n<Nnodes; n++)
148 posval += shapef[n]*(((*elt)->GetNodeCoordinates(n))[f]);
149 float nodeval=( (m_Solution)->GetSolutionValue( (*elt)->GetNode(n)->GetDegreeOfFreedom(f) , m_SolutionIndex)
150 +(m_Solution)->GetSolutionValue( (*elt)->GetNode(n)->GetDegreeOfFreedom(f) , m_SolutionIndex2)*step);
152 solval += shapef[n] * nodeval;
153 solmat[(n*ImageDimension)+f][0]=nodeval;
157 InVec[f+ImageDimension]=solval;
172 for(
unsigned int n=0; n<Nnodes; n++)
183 return vcl_fabs((
double)energy*(
double)m_Gamma-(
double)defe);
187 template<
class TMoving,
class TFixed>
188 typename FiniteDifferenceFunctionLoad<TMoving , TFixed>::FEMVectorType
206 femVec.set_size(ImageDimension);
209 if (!m_DifferenceFunction || !m_DeformationField || !m_FixedImage || !m_MovingImage)
211 std::cout <<
" initializing FE() ";
212 this->InitializeIteration();
213 std::cout <<
" done " << std::endl;
214 if (!m_DeformationField || !m_FixedImage || !m_MovingImage )
216 std::cout <<
" input data {field,fixed/moving image} are not set ";
219 std::cout <<
" sizes " << m_DeformationField->GetLargestPossibleRegion().GetSize()
220 <<
" image " << m_FixedImage->GetLargestPossibleRegion().GetSize() << std::endl;
223 typedef typename TMoving::IndexType::IndexValueType OIndexValueType;
224 typename TMoving::IndexType oindex;
228 for(k = 0; k < ImageDimension; k++ )
231 if ( vnl_math_isnan(Gpos[k]) || vnl_math_isinf(Gpos[k]) ||
232 vnl_math_isnan(Gsol[k]) || vnl_math_isinf(Gsol[k]) ||
233 vcl_fabs(Gpos[k]) > 1.e33 || vcl_fabs(Gsol[k]) > 1.e33 )
237 else oindex[k]=(long) (Gpos[k]+0.5);
238 if (oindex[k] > static_cast<OIndexValueType>(m_FixedSize[k]-1) || oindex[k] < 0) inimage=
false;
250 FieldIteratorType nD(m_MetricRadius, m_DeformationField, m_DeformationField->GetLargestPossibleRegion());
253 void* globalData=
NULL;
254 OutVec = m_DifferenceFunction->ComputeUpdate(nD, globalData);
256 for (k=0;k<ImageDimension;k++)
258 if ( vnl_math_isnan(OutVec[k]) || vnl_math_isinf(OutVec[k] )) femVec[k]=0.0;
259 else femVec[k]=OutVec[k];
264 template<
class TMoving,
class TFixed>
268 std::string clsnm = std::string(
"FiniteDifferenceFunctionLoad(")+
typeid(TMoving).name()+
","+
typeid(TFixed).name()+
")";
269 static const int CLID_ =
FEMOF::Register( FiniteDifferenceFunctionLoad::NewB,clsnm.c_str());
275 template<
class TMoving,
class TFixed>