18 #ifndef __itkPSMImageDomainWithGradients_h 19 #define __itkPSMImageDomainWithGradients_h 22 #include "itkImageDuplicator.h" 23 #include "itkPSMImageDomain.h" 24 #include "itkVectorLinearInterpolateImageFunction.h" 25 #include "itkGradientImageFilter.h" 26 #include "itkFixedArray.h" 40 template <
class T,
unsigned int VDimension>
47 typedef SmartPointer<Self> Pointer;
48 typedef SmartPointer<const Self> ConstPointer;
49 typedef WeakPointer<const Self> ConstWeakPointer;
55 typedef typename Superclass::ScalarInterpolatorType ScalarInterpolatorType;
56 typedef GradientImageFilter<ImageType> GradientImageFilterType;
57 typedef typename GradientImageFilterType::OutputImageType GradientImageType;
58 typedef VectorLinearInterpolateImageFunction<GradientImageType, typename PointType::CoordRepType>
59 GradientInterpolatorType;
61 typedef FixedArray<T, VDimension> VectorType;
62 typedef vnl_vector_fixed<T, VDimension> VnlVectorType;
71 itkStaticConstMacro(Dimension,
unsigned int, VDimension);
77 Superclass::SetImage(I);
80 typename GradientImageFilterType::Pointer filter = GradientImageFilterType::New();
82 filter->SetUseImageSpacingOn();
84 m_GradientImage = filter->GetOutput();
86 m_GradientInterpolator->SetInputImage(m_GradientImage);
88 itkGetObjectMacro(GradientImage, GradientImageType);
96 {
return m_GradientInterpolator->Evaluate(p); }
97 inline VnlVectorType SampleGradientVnl(
const PointType &p)
const 98 {
return VnlVectorType( this->SampleGradient(p).GetDataPointer() ); }
99 inline VnlVectorType SampleNormalVnl(
const PointType &p, T epsilon = 1.0e-5)
const 101 VnlVectorType grad = this->SampleGradientVnl(p);
102 double q = 1.0 / (grad.magnitude() + epsilon);
103 for (
unsigned int i = 0; i < VDimension; i++) { grad[i] *= q; }
108 itkGetObjectMacro(GradientInterpolator, GradientInterpolatorType);
115 const PointType &pos,
119 if (this->m_ConstraintsEnabled ==
true)
121 const double epsilon = 1.0e-10;
123 double dotprod = 0.0;
124 VnlVectorType normal = this->SampleNormalVnl(pos, epsilon);
125 for (
unsigned int i = 0; i < VDimension; i++) { dotprod += normal[i] * gradE[i]; }
126 for (
unsigned int i = 0; i < VDimension; i++) { gradE[i] -= normal[i] * dotprod; }
136 m_GradientInterpolator = GradientInterpolatorType::New();
139 void PrintSelf(std::ostream& os, Indent indent)
const 141 Superclass::PrintSelf(os, indent);
142 os << indent <<
"m_GradientImage = " << m_GradientImage << std::endl;
143 os << indent <<
"m_GradientInterpolator = " << m_GradientInterpolator << std::endl;
149 void operator=(
const Self&);
151 typename GradientImageType::Pointer m_GradientImage;
152 typename GradientInterpolatorType::Pointer m_GradientInterpolator;
Image< T, VDimension > ImageType
virtual bool ApplyVectorConstraints(vnl_vector_fixed< double, VDimension > &gradE, const PointType &pos, double) const
Superclass::PointType PointType
void SetImage(ImageType *I)
VectorType SampleGradient(const PointType &p) const
PSMImageDomainWithGradients Self