36 #ifndef __itkNumericInverse_h
37 #define __itkNumericInverse_h
44 #include <itkTransform.h>
48 #include <vnl/algo/vnl_svd.h>
56 template <
class ScalarType>
65 operator() (
const std::vector<ScalarType> & x,
66 std::vector<ScalarType> & F,
67 std::vector<std::vector<ScalarType> > & J)
const = 0;
73 template <
class ScalarType>
76 std::vector<ScalarType> & x,
77 const unsigned int & ntrial,
78 const ScalarType & tolx,
79 const ScalarType & tolf)
82 const unsigned int n = x.size();
84 std::vector<ScalarType> F(n);
85 std::vector<std::vector<ScalarType> > J(n);
86 for (
unsigned int i = 0; i < n; i++) J[i].resize(n);
88 vnl_matrix<ScalarType> A(n, n);
89 vnl_vector<ScalarType> b(n);
91 for (
unsigned int k = 0; k < ntrial; k++)
97 ScalarType errf = ScalarType(0);
98 for (
unsigned int i = 0; i < n; i++)
102 if (errf <= tolf)
break;
105 for (
unsigned int i = 0; i < n; i++)
107 for (
unsigned int j = 0; j < n; j++)
114 for (
unsigned int i = 0; i < n; i++)
119 vnl_svd<double> svd(A);
120 vnl_vector<double> dx = svd.solve(b);
123 ScalarType errx = ScalarType(0);
124 for (
unsigned int i = 0; i < n; i++)
129 if (errx <= tolx)
break;
144 template <
class TTransform>
149 typedef TTransform TransformType;
150 typedef typename TTransform::ScalarType ScalarType;
153 transform_(transform)
158 void operator() (
const std::vector<ScalarType> & x,
159 std::vector<ScalarType> & F,
160 std::vector<std::vector<ScalarType> > & J)
const
162 transform_.eval(x, F, J);
164 const unsigned int n = x.size();
165 for (
unsigned int i = 0; i < n; i++)
173 bool transform(
const std::vector<ScalarType> & y,
174 std::vector<ScalarType> & x,
175 bool x_is_initialized =
false)
const
178 if (!x_is_initialized) x = y;
179 return NewtonRaphson(*
this, x, 50, 1e-12, 1e-12);
184 const TransformType & transform_;
187 mutable std::vector<ScalarType> y_;
192 #endif // __itkNumericInverse_h
Definition: itkNormalizeImageFilterWithMask.h:48
Definition: itkNumericInverse.h:57
Definition: itkNumericInverse.h:145
Definition: itkNumericInverse.h:50