#pragma once#include<vector>#include"Constraint.h"#include"Eigen/Dense"#include"FreeFormConstraint.h"#include"Mesh.h"#include"PlaneConstraint.h"#include"SphereConstraint.h"#include"itkPoint.h"#include"vnl/vnl_cross.h"#include"vnl/vnl_inverse.h"namespaceshapeworks{classConstraints{public:usingPoint3=itk::Point<double,3>;Constraints(){active_=false;}~Constraints(){}// Set constraintsvoidaddPlane(constvnl_vector<double>&a,constvnl_vector<double>&b,constvnl_vector<double>&c);voidaddSphere(constvnl_vector_fixed<double,DIMENSION>&v,doubler);voidaddFreeFormConstraint(std::shared_ptr<shapeworks::Mesh>mesh);// TransformsbooltransformConstraints(constvnl_matrix_fixed<double,4,4>&transform);booltransformPlanes(constvnl_matrix_fixed<double,4,4>&transform);// Apply functionsstd::stringstreamapplyBoundaryConstraints(vnl_vector_fixed<double,3>&gradE,constPoint3&pos);std::stringstreamapplyBoundaryConstraints(vnl_vector_fixed<float,3>&gradE,constPoint3&pos);std::stringstreamapplyPlaneConstraints(vnl_vector_fixed<double,3>&gradE,constPoint3&pos);// Write constraintsboolwritePlanes(std::stringfilename){returntrue;}boolwriteSpheres(std::stringfilename){returntrue;}boolwriteFreeFormConstraint(std::stringfilename){returntrue;}// Is defined? functionsboolisCuttingPlaneDefined()const{return!planeConstraints_.empty();}boolisCuttingSphereDefined()const{return!sphereConstraints_.empty();}// Plane constraintstd::vector<PlaneConstraint>&getPlaneConstraints(){returnplaneConstraints_;}std::vector<SphereConstraint>&getSphereConstraints(){returnsphereConstraints_;}// Is any constraint violated by point pos?boolisAnyViolated(constPoint3&pos);// Constraint violationsstd::vector<int>planesViolated(Eigen::Vector3dpt);voidprintAll();std::stringviolationReport(constPoint3&pos);std::vector<std::vector<double>>violationReportData(constPoint3&pos);// ============================// Augmented Lagragian Fuctions// ============================// Energy gradient computationsvnl_vector_fixed<double,3>constraintsGradient(constPoint3&pos)const;// Lagragian gradient computationvnl_vector_fixed<double,3>constraintsLagrangianGradient(constPoint3&pos,constPoint3&prepos,doubleC);// Parameters lambda, mu and z initializationvoidInitializeLagrangianParameters(doublelambda,doublemu,doublez);voidUpdateZs(constPoint3&pos,doubleC);voidUpdateMus(constPoint3&pos,doubleC);boolGetActive(){returnactive_;}voidSetActive(boolac){active_=ac;}voidRead(std::stringfilename);voidWrite(std::stringfilename);FreeFormConstraint&getFreeformConstraint();boolhasConstraints();// return a mesh that has been clipped by the constraintsvoidclipMesh(Mesh&mesh);private:std::vector<PlaneConstraint>planeConstraints_;std::vector<SphereConstraint>sphereConstraints_;FreeFormConstraintfreeFormConstraint_;// Projections and intersectsboolactive_;Eigen::Vector3dprojectOntoLine(Eigen::Vector3da,Eigen::Vector3db,Eigen::Vector3dp);Eigen::Vector3dlinePlaneIntersect(Eigen::Vector3dn,Eigen::Vector3dp0,Eigen::Vector3dl0,Eigen::Vector3dl);boolPlanePlaneIntersect(Eigen::Vector3dn1,Eigen::Vector3dp1,Eigen::Vector3dn2,Eigen::Vector3dp2,Eigen::Vector3d&l0_result,Eigen::Vector3d&l1_result);};}// namespace shapeworks