1- /* =========================================================================
2- Copyright (c) 2009 Scientific Computing and Imaging Institute.
3- See ShapeWorksLicense.txt for details.
4-
5- This software is distributed WITHOUT ANY WARRANTY; without even
6- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
7- PURPOSE. See the above copyright notices for more information.
8- =========================================================================*/
9-
101#include " MeshDomain.h"
112
123namespace shapeworks {
134
5+ // -------------------------------------------------------------------
146bool MeshDomain::ApplyConstraints (PointType &p, int idx, bool dbg) const {
157 if (!mesh_wrapper_) {
168 return true ;
@@ -19,17 +11,20 @@ bool MeshDomain::ApplyConstraints(PointType &p, int idx, bool dbg) const {
1911 return true ;
2012}
2113
14+ // -------------------------------------------------------------------
2215bool MeshDomain::ApplyVectorConstraints (vnl_vector_fixed<double , DIMENSION> &gradE, const PointType &pos) const {
2316 // TODO need to refactor into update particle method
2417 // TODO reduce magnitude of vector so it doesn't violate constraints
2518 return true ;
2619}
2720
21+ // -------------------------------------------------------------------
2822vnl_vector_fixed<double , DIMENSION> MeshDomain::ProjectVectorToSurfaceTangent (
2923 vnl_vector_fixed<double , DIMENSION> &gradE, const PointType &pos, int idx) const {
3024 return mesh_wrapper_->ProjectVectorToSurfaceTangent (pos, idx, gradE);
3125}
3226
27+ // -------------------------------------------------------------------
3328MeshDomain::PointType MeshDomain::UpdateParticlePosition (const PointType &point, int idx,
3429 vnl_vector_fixed<double , DIMENSION> &update) const {
3530 vnl_vector_fixed<double , DIMENSION> negativeUpdate;
@@ -40,6 +35,7 @@ MeshDomain::PointType MeshDomain::UpdateParticlePosition(const PointType &point,
4035 return newPoint;
4136}
4237
38+ // -------------------------------------------------------------------
4339double MeshDomain::GetMaxDiameter () const {
4440 // todo should this not be the length of the bounding box diagonal?
4541 PointType boundingBoxSize = mesh_wrapper_->GetMeshUpperBound () - mesh_wrapper_->GetMeshLowerBound ();
@@ -50,6 +46,79 @@ double MeshDomain::GetMaxDiameter() const {
5046 return max;
5147}
5248
49+ // -------------------------------------------------------------------
50+ vnl_vector_fixed<float , 3 > MeshDomain::SampleGradientAtPoint (const PointType &point, int idx) const {
51+ return mesh_wrapper_->SampleNormalAtPoint (point, idx);
52+ }
53+
54+ // -------------------------------------------------------------------
55+ vnl_vector_fixed<float , 3 > MeshDomain::SampleNormalAtPoint (const PointType &point, int idx) const {
56+ return mesh_wrapper_->SampleNormalAtPoint (point, idx);
57+ }
58+
59+ // -------------------------------------------------------------------
60+ ParticleDomain::GradNType MeshDomain::SampleGradNAtPoint (const PointType &p, int idx) const {
61+ return mesh_wrapper_->SampleGradNAtPoint (p, idx);
62+ }
63+
64+ // -------------------------------------------------------------------
65+ double MeshDomain::Distance (const PointType &a, int idx_a, const PointType &b, int idx_b,
66+ vnl_vector_fixed<double , 3 > *out_grad) const {
67+ return geodesics_mesh_->ComputeDistance (a, idx_a, b, idx_b, out_grad);
68+ }
69+
70+ // -------------------------------------------------------------------
71+ double MeshDomain::SquaredDistance (const PointType &a, int idx_a, const PointType &b, int idx_b) const {
72+ double dist = geodesics_mesh_->ComputeDistance (a, idx_a, b, idx_b);
73+ return dist * dist;
74+ }
75+
76+ // -------------------------------------------------------------------
77+ bool MeshDomain::IsWithinDistance (const PointType &a, int idx_a, const PointType &b, int idx_b, double test_dist,
78+ double &dist) const {
79+ return geodesics_mesh_->IsWithinDistance (a, idx_a, b, idx_b, test_dist, dist);
80+ }
81+
82+ // -------------------------------------------------------------------
83+ void MeshDomain::SetMesh (std::shared_ptr<MeshWrapper> mesh, double geodesic_remesh_percent) {
84+ m_FixedDomain = false ;
85+ mesh_wrapper_ = mesh;
86+ sw_mesh_ = std::make_shared<Mesh>(mesh_wrapper_->GetPolydata ());
87+
88+ if (geodesic_remesh_percent >= 100.0 ) { // no remeshing
89+ geodesics_mesh_ = mesh_wrapper_;
90+ } else {
91+ auto poly_data = mesh_wrapper_->GetPolydata ();
92+ Mesh mesh_copy (poly_data);
93+ mesh_copy.remeshPercent (geodesic_remesh_percent, 1.0 );
94+ geodesics_mesh_ = std::make_shared<MeshWrapper>(mesh_copy.getVTKMesh ());
95+ }
96+ }
97+
98+ // -------------------------------------------------------------------
5399void MeshDomain::InvalidateParticlePosition (int idx) const { this ->mesh_wrapper_ ->InvalidateParticle (idx); }
54100
101+ // -------------------------------------------------------------------
102+ ParticleDomain::PointType MeshDomain::GetZeroCrossingPoint () const {
103+ // TODO Hong
104+ // Apply constraints somehow
105+ if (mesh_wrapper_ == nullptr ) {
106+ // Fixed domain. Unsure if this is the correct thing to do, but it preserves existing behaviour.
107+ PointType p;
108+ p[0 ] = p[1 ] = p[2 ] = 0 ;
109+ return p;
110+ }
111+ return mesh_wrapper_->GetPointOnMesh ();
112+ }
113+
114+ // -------------------------------------------------------------------
115+ ParticleDomain::PointType MeshDomain::GetValidLocationNear (PointType p) const {
116+ PointType valid;
117+ valid[0 ] = p[0 ];
118+ valid[1 ] = p[1 ];
119+ valid[2 ] = p[2 ];
120+ ApplyConstraints (valid, -1 );
121+ return valid;
122+ }
123+
55124} // namespace shapeworks
0 commit comments