18 #ifndef __itkPSMRBFCorrespondenceInterpolator_hxx 19 #define __itkPSMRBFCorrespondenceInterpolator_hxx 20 #include "itkPSMRBFCorrespondenceInterpolator.h" 25 template <
unsigned int VDimension>
26 PSMRBFCorrespondenceInterpolator<VDimension>
27 ::PSMRBFCorrespondenceInterpolator()
35 itkExceptionMacro(
"This function is currently only implemented for 3D point sets.");
40 template <
unsigned int VDimension>
46 if (m_PointSetA.size() == 0 || m_PointSetB.size() == 0)
48 itkExceptionMacro(
"Surface point sets have not been specified.");
52 if (m_PointSetA.size() != m_PointSetB.size())
54 itkExceptionMacro(
"Surface point sets A and B are not the same size.");
58 const unsigned int N = m_PointSetA.size();
63 typedef vnl_vector<double> vectype;
64 typedef vnl_matrix<double> matrixtype;
69 matrixtype A(N+4,N+4);
75 for (
unsigned int i = 0; i < N; i++)
77 Xi[0] = (m_PointSetA[i])[0];
78 Xi[1] = (m_PointSetA[i])[1];
79 Xi[2] = (m_PointSetA[i])[2];
81 for (
unsigned int j = 0; j < N; j++)
83 Xj[0] = (m_PointSetA[j])[0];
84 Xj[1] = (m_PointSetA[j])[1];
85 Xj[2] = (m_PointSetA[j])[2];
88 Phi(i,j) = (Xi - Xj).magnitude();
96 for (
unsigned int i = 0; i < 4; i++)
98 for (
unsigned int j = 0; j < N +4; j++)
100 if (j >= N) A(i,j) = 0.0;
101 else if (i == 3) A(i,j) = 1.0;
102 else A(i,j) = (m_PointSetA[j])[i];
107 for (
unsigned int i = 0; i < N; i++)
109 for (
unsigned int j = 0; j < N +4; j++)
111 if (j < N) A(i+4,j) = Phi(i,j);
112 else if (j == N+3) A(i+4,j) = 1.0;
113 else A(i+4,j) = (m_PointSetA[i])[2-(j-N)];
123 for (
unsigned int D = 0; D < 3; D++)
127 b[0] = b[1] = b[2] = b[3] = 0.0;
128 for(
unsigned int i = 0; i < N; i++)
130 b[i+4] = (m_PointSetB[i])[D];
136 x = vnl_svd<double>(A).solve(b);
139 for (
unsigned int i = 0; i < N; i++)
151 m_Initialized =
true;
154 template <
unsigned int VDimension>
159 if (m_Initialized ==
false)
161 itkExceptionMacro(
"Function has not been initialized");
165 const unsigned int N = m_PointSetA.size();
168 vnl_vector<double> X(VDimension);
169 for (
unsigned int D = 0; D < VDimension; D++)
173 std::vector<vnl_vector<double> > points(N);
174 for (
unsigned int i = 0; i < N; i++)
176 points[i].set_size(VDimension);
177 for (
unsigned int D = 0; D < VDimension; D++)
179 points[i](D) = m_PointSetA[i][D];
188 for (
unsigned int D = 0; D < VDimension; D++)
193 for (
unsigned int i = 0; i < N; i++)
195 ret[D] += m_C(i,D) * (X - points[i]).magnitude();
199 for (
unsigned int i = 0; i < VDimension; i++)
202 ret[D] += m_P(i+1,D) * X(i);
virtual PointType Evaluate(const PointType &pt) const