#pragma once#include"itkParticleShapeMatrixAttribute.h"#include"itkParticleVectorFunction.h"#include<vector>namespaceitk{template<unsignedintVDimension>classParticleEnsembleEntropyFunction:publicParticleVectorFunction<VDimension>{public:typedefParticleEnsembleEntropyFunctionSelf;typedefSmartPointer<Self>Pointer;typedefSmartPointer<constSelf>ConstPointer;typedefParticleVectorFunction<VDimension>Superclass;itkTypeMacro(ParticleEnsembleEntropyFunction,ParticleVectorFunction);typedeftypenameSuperclass::ParticleSystemTypeParticleSystemType;typedefParticleShapeMatrixAttribute<double,VDimension>ShapeMatrixType;typedeftypenameShapeMatrixType::DataTypeDataType;typedeftypenameSuperclass::VectorTypeVectorType;typedeftypenameParticleSystemType::PointTypePointType;typedefvnl_vector<DataType>vnl_vector_type;typedefvnl_matrix<DataType>vnl_matrix_type;itkNewMacro(Self);itkStaticConstMacro(Dimension,unsignedint,VDimension);virtualVectorTypeEvaluate(unsignedint,unsignedint,constParticleSystemType*,double&,double&)const;virtualVectorTypeEvaluate(unsignedinta,unsignedintb,constParticleSystemType*c,double&d)const{doublee;returnthis->Evaluate(a,b,c,d,e);}virtualdoubleEnergy(unsignedinta,unsignedintb,constParticleSystemType*c)const{doublee,d;this->Evaluate(a,b,c,d,e);returne;}voidWriteModes(conststd::string&,int)const;voidSetShapeMatrix(ShapeMatrixType*s){m_ShapeMatrix=s;}ShapeMatrixType*GetShapeMatrix(){returnm_ShapeMatrix.GetPointer();}constShapeMatrixType*GetShapeMatrix()const{returnm_ShapeMatrix.GetPointer();}virtualvoidBeforeIteration(){m_ShapeMatrix->BeforeIteration();if(m_Counter==0){this->ComputeCovarianceMatrix();}}virtualvoidAfterIteration(){m_ShapeMatrix->AfterIteration();// Update the annealing parameter.if(m_HoldMinimumVariance!=true&&!m_UseMeanEnergy){m_Counter++;if(m_Counter>=m_RecomputeCovarianceInterval){m_Counter=0;m_MinimumVariance*=m_MinimumVarianceDecayConstant;}}}voidSetMinimumVariance(doubled){m_MinimumVariance=d;}doubleGetMinimumVariance()const{returnm_MinimumVariance;}voidSetMinimumVarianceDecay(doubleinitial_value,doublefinal_value,doubletime_period){m_MinimumVarianceDecayConstant=exp(log(final_value/initial_value)/time_period);m_MinimumVariance=initial_value;m_HoldMinimumVariance=false;}boolGetMinimumVarianceDecayConstant()const{returnm_MinimumVarianceDecayConstant;}voidPrintShapeMatrix(){m_ShapeMatrix->PrintMatrix();}voidUseMeanEnergy(){m_UseMeanEnergy=true;}voidUseEntropy(){m_UseMeanEnergy=false;}boolGetHoldMinimumVariance()const{returnm_HoldMinimumVariance;}voidSetHoldMinimumVariance(boolb){m_HoldMinimumVariance=b;}voidSetRecomputeCovarianceInterval(inti){m_RecomputeCovarianceInterval=i;}intGetRecomputeCovarianceInterval()const{returnm_RecomputeCovarianceInterval;}virtualtypenameParticleVectorFunction<VDimension>::PointerClone(){typenameParticleEnsembleEntropyFunction<VDimension>::Pointercopy=ParticleEnsembleEntropyFunction<VDimension>::New();copy->m_PointsUpdate=this->m_PointsUpdate;copy->m_MinimumVariance=this->m_MinimumVariance;copy->m_MinimumEigenValue=this->m_MinimumEigenValue;copy->m_CurrentEnergy=this->m_CurrentEnergy;copy->m_HoldMinimumVariance=this->m_HoldMinimumVariance;copy->m_MinimumVarianceDecayConstant=this->m_MinimumVarianceDecayConstant;copy->m_RecomputeCovarianceInterval=this->m_RecomputeCovarianceInterval;copy->m_Counter=m_Counter;copy->m_DomainNumber=this->m_DomainNumber;copy->m_ParticleSystem=this->m_ParticleSystem;copy->m_ShapeMatrix=this->m_ShapeMatrix;copy->m_InverseCovMatrix=this->m_InverseCovMatrix;copy->m_points_mean=this->m_points_mean;copy->m_UseMeanEnergy=this->m_UseMeanEnergy;return(typenameParticleVectorFunction<VDimension>::Pointer)copy;}protected:ParticleEnsembleEntropyFunction(){// m_MinimumVarianceBase = 1.0;//exp(log(1.0e-5)/10000.0);m_HoldMinimumVariance=true;m_MinimumVariance=1.0e-5;m_MinimumEigenValue=0.0;m_MinimumVarianceDecayConstant=1.0;//log(2.0) / 50000.0;m_RecomputeCovarianceInterval=1;m_Counter=0;m_UseMeanEnergy=true;m_PointsUpdate=std::make_shared<vnl_matrix_type>(10,10);m_InverseCovMatrix=std::make_shared<vnl_matrix_type>(10,10);m_points_mean=std::make_shared<vnl_matrix_type>(10,10);}virtual~ParticleEnsembleEntropyFunction(){}voidoperator=(constParticleEnsembleEntropyFunction&);ParticleEnsembleEntropyFunction(constParticleEnsembleEntropyFunction&);typenameShapeMatrixType::Pointerm_ShapeMatrix;virtualvoidComputeCovarianceMatrix();std::shared_ptr<vnl_matrix_type>m_PointsUpdate;doublem_MinimumVariance;doublem_MinimumEigenValue;doublem_CurrentEnergy;boolm_HoldMinimumVariance;doublem_MinimumVarianceDecayConstant;intm_RecomputeCovarianceInterval;intm_Counter;boolm_UseMeanEnergy;std::shared_ptr<vnl_matrix_type>m_points_mean;// 3Nx3N - used for energy computationstd::shared_ptr<vnl_matrix_type>m_InverseCovMatrix;//3NxM - used for energy computation};}//end namespace#include"itkParticleEnsembleEntropyFunction.txx"