/*========================================================================= Copyright (c) 2009 Scientific Computing and Imaging Institute. See ShapeWorksLicense.txt for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information.=========================================================================*/#pragma once#include"ParticleImageDomainWithGradients.h"#include"itkImage.h"#include"itkGradientImageFilter.h"#include"itkFixedArray.h"#include"itkImageDuplicator.h"#include"itkDiscreteGaussianImageFilter.h"#include"itkDerivativeImageFilter.h"#include"vnl/vnl_matrix_fixed.h"namespaceshapeworks{template<classT>classParticleImageDomainWithGradN:publicParticleImageDomainWithGradients<T>{public:typedefParticleImageDomainWithGradients<T>Superclass;usingPointer=std::shared_ptr<ParticleImageDomainWithGradN>;typedeftypenameSuperclass::PointTypePointType;typedeftypenameSuperclass::ImageTypeImageType;typedeftypenameSuperclass::GradNTypeGradNType;typedeftypenameSuperclass::GradNTypeVnlMatrixType;voidSetImage(ImageType*I,doublenarrow_band){Superclass::SetImage(I,narrow_band);constautograd=this->GetVDBGradient();// Compute the gradient of normals component-wisefor(inti=0;i<3;i++){autonorm_i=openvdb::FloatGrid::create();norm_i->setTransform(this->transform());autonorm_i_accessor=norm_i->getAccessor();for(openvdb::VectorGrid::ValueOnCIterit=grad->cbeginValueOn();it.test();++it){constopenvdb::Vec3f&v=*it;norm_i_accessor.setValue(it.getCoord(),v[i]/v.length());}m_VDBGradNorms[i]=openvdb::tools::gradient(*norm_i);}}// end setimageinlineGradNTypeSampleGradNAtPoint(constPointType&p,intidx)constoverride{constautocoord=this->ToVDBCoord(p);GradNTypegrad_n;for(inti=0;i<3;i++){autograd_ni=openvdb::tools::BoxSampler::sample(m_VDBGradNorms[i]->tree(),coord);grad_n.set(i,0,grad_ni[0]);grad_n.set(i,1,grad_ni[1]);grad_n.set(i,2,grad_ni[2]);}returngrad_n;}voidDeletePartialDerivativeImages()override{for(unsignedinti=0;i<DIMENSION;i++){m_VDBGradNorms[i]=0;}}voidDeleteImages()override{Superclass::DeleteImages();DeletePartialDerivativeImages();}protected:ParticleImageDomainWithGradN(){}virtual~ParticleImageDomainWithGradN(){};voidPrintSelf(std::ostream&os,itk::Indentindent)const{Superclass::PrintSelf(os,indent);}private:typenameopenvdb::VectorGrid::Ptrm_VDBGradNorms[3];};}// end namespace itk