18 #ifndef __itkPSMImplicitSurfaceDomain_hxx 19 #define __itkPSMImplicitSurfaceDomain_hxx 20 #include "itkPSMImplicitSurfaceDomain.h" 22 #include "vnl/vnl_math.h" 23 #include "vnl/vnl_cross.h" 28 template<
class T,
unsigned int VDimension>
30 PSMImplicitSurfaceDomain<T, VDimension>::
31 SetCuttingPlane(
const vnl_vector<double> &a,
const vnl_vector<double> &b,
32 const vnl_vector<double> &c)
36 if (VDimension == 3) q = vnl_cross_3d((b-a),(c-a));
37 else if (VDimension == 2) q = vnl_cross_2d((b-a),(c-a));
39 if (q.magnitude() > 0.0)
41 m_CuttingPlaneNormal = q / q.magnitude();
42 m_CuttingPlanePoint = a;
43 m_UseCuttingPlane =
true;
47 template<
class T,
unsigned int VDimension>
52 double maxtimestep)
const 54 if (this->m_UseCuttingPlane ==
true)
57 vnl_vector_fixed<double, VDimension> x;
58 vnl_vector_fixed<T, VDimension> grad = this->SampleGradientVnl(pos);
59 for (
unsigned int i = 0; i < VDimension; i++)
61 const double D = dot_product(m_CuttingPlaneNormal, x- m_CuttingPlanePoint);
67 vnl_vector_fixed<double, VDimension> df;
68 const double k = (-2.0 / (D * D * D));
69 df[0] = k * grad[0] * m_CuttingPlaneNormal[0];
70 df[1] = k * grad[1] * m_CuttingPlaneNormal[1];
71 df[2] = k * grad[2] * m_CuttingPlaneNormal[2];
76 if (gradE.magnitude() > maxtimestep)
79 gradE = gradE * maxtimestep;
84 return Superclass::ApplyVectorConstraints(gradE,pos,maxtimestep);
87 template<
class T,
unsigned int VDimension>
93 bool flag = Superclass::ApplyConstraints(p);
95 if (this->m_ConstraintsEnabled ==
true)
101 const T epsilon = m_Tolerance * 0.001;
102 T f = this->Sample(p);
105 while ( fabs(f) > (m_Tolerance * mult) || gradmag < epsilon)
108 vnl_vector_fixed<T, VDimension> grad = this->SampleGradientVnl(p);
110 gradmag = grad.magnitude();
111 vnl_vector_fixed<T, VDimension> vec = grad * ( f / (gradmag + epsilon) );
112 for (
unsigned int i = 0; i < VDimension; i++)
132 template <
class T,
unsigned int VDimension>
137 for (
unsigned int i = 0; i < VDimension; i++)
138 { sum += (b[i]-a[i]) * (b[i]-a[i]); }
virtual bool ApplyVectorConstraints(vnl_vector_fixed< double, VDimension > &gradE, const PointType &pos, double maxtimestep) const
virtual double Distance(const PointType &, const PointType &) const
virtual bool ApplyConstraints(PointType &p) const