/*========================================================================= 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"itkParticleDomain.h"#include"MeshWrapper.h"#include"TriMeshWrapper.h"#include<itkObjectFactory.h>namespaceitk{classMeshDomain:publicParticleDomain{public:typedefSmartPointer<MeshDomain>Pointer;itkSimpleNewMacro(MeshDomain);typedeftypenameParticleDomain::PointTypePointType;shapeworks::DomainTypeGetDomainType()constoverride{returnshapeworks::DomainType::Mesh;}boolApplyConstraints(PointType&p,intidx,booldbg=false)constoverride;boolApplyVectorConstraints(vnl_vector_fixed<double,DIMENSION>&gradE,constPointType&pos)const;vnl_vector_fixed<double,DIMENSION>ProjectVectorToSurfaceTangent(vnl_vector_fixed<double,DIMENSION>&gradE,constPointType&pos,intidx)constoverride;PointTypeUpdateParticlePosition(constPointType&point,intidx,vnl_vector_fixed<double,DIMENSION>&update)constoverride;virtualvoidInvalidateParticlePosition(intidx)constoverride;doubleGetCurvature(constPointType&p,intidx)constoverride{//TODO Why not return the actual curvaturereturnGetSurfaceMeanCurvature();}inlinedoubleGetSurfaceMeanCurvature()constoverride{// This function is used by MeanCurvatureAttribute which is used for good/bad assessment// These arbitrary values should eventually be replaced with actual computationreturn0.15;}inlinedoubleGetSurfaceStdDevCurvature()constoverride{// This function is used by MeanCurvatureAttribute which is used for good/bad assessment// These arbitrary values should eventually be replaced with actual computationreturn0.02;}constPointType&GetLowerBound()constoverride{returnmeshWrapper->GetMeshLowerBound();}constPointType&GetUpperBound()constoverride{returnmeshWrapper->GetMeshUpperBound();}PointTypeGetZeroCrossingPoint()constoverride{// TODO Hong// Apply constraints somehowif(meshWrapper==nullptr){// Fixed domain. Unsure if this is the correct thing to do, but it preserves existing behaviour.PointTypep;p[0]=p[1]=p[2]=0;returnp;}returnmeshWrapper->GetPointOnMesh();}PointTypeGetValidLocationNear(PointTypep)constoverride{PointTypevalid;valid[0]=p[0];valid[1]=p[1];valid[2]=p[2];ApplyConstraints(valid,-1);returnvalid;}doubleGetSurfaceArea()constoverride{// TODO return actual surface areareturn0;}doubleGetMaxDiameter()constoverride;inlinevnl_vector_fixed<float,DIMENSION>SampleGradientAtPoint(constPointType&point,intidx)constoverride{returnmeshWrapper->SampleNormalAtPoint(point,idx);}inlinevnl_vector_fixed<float,DIMENSION>SampleNormalAtPoint(constPointType&point,intidx)constoverride{returnmeshWrapper->SampleNormalAtPoint(point,idx);}inlineGradNTypeSampleGradNAtPoint(constPointType&p,intidx)constoverride{returnmeshWrapper->SampleGradNAtPoint(p,idx);}inlinedoubleDistance(constPointType&a,intidx_a,constPointType&b,intidx_b,vnl_vector_fixed<double,DIMENSION>*out_grad=nullptr)constoverride{returnmeshWrapper->ComputeDistance(a,idx_a,b,idx_b,out_grad);}inlinedoubleSquaredDistance(constPointType&a,intidx_a,constPointType&b,intidx_b)constoverride{doubledist=meshWrapper->ComputeDistance(a,idx_a,b,idx_b);returndist*dist;}inlineboolIsWithinDistance(constPointType&a,intidx_a,constPointType&b,intidx_b,doubletest_dist,double&dist)constoverride{returnmeshWrapper->IsWithinDistance(a,idx_a,b,idx_b,test_dist,dist);}voidDeleteImages()override{// TODO Change this to a generic delete function}voidDeletePartialDerivativeImages()override{// TODO Change this to a generic delete function}voidSetMesh(std::shared_ptr<shapeworks::MeshWrapper>mesh_){this->m_FixedDomain=false;meshWrapper=mesh_;}voidUpdateZeroCrossingPoint()override{}protected:MeshDomain(){}virtual~MeshDomain(){}voidPrintSelf(std::ostream&os,Indentindent)const{DataObject::Superclass::PrintSelf(os,indent);os<<indent<<"MeshDomain\n";}private:std::shared_ptr<shapeworks::MeshWrapper>meshWrapper;PointTypem_ZeroCrossingPoint;};}