Skip to content

Commit 031516e

Browse files
authored
Merge branch 'master' into dependabot/pip/pillow-10.2.0
2 parents f060325 + a6b1c43 commit 031516e

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

Libs/Mesh/Mesh.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ double Mesh::interpolateFieldAtPoint(const std::string& field, const Point3& que
10021002
Eigen::Vector3d values(this->getFieldValue(field, v1), this->getFieldValue(field, v2),
10031003
this->getFieldValue(field, v3));
10041004

1005-
return (bary * values.transpose()).mean();
1005+
return values[0] * bary[0] + values[1] * bary[1] + values[2] * bary[2];
10061006
}
10071007

10081008
Mesh& Mesh::applySubdivisionFilter(const SubdivisionType type, int subdivision) {

Libs/Python/ShapeworksPython.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,14 @@ PYBIND11_MODULE(shapeworks_py, m)
10971097
"returns closest point id in this mesh to the given point in space",
10981098
"point"_a)
10991099

1100+
.def("interpolateFieldAtPoint",
1101+
[](Mesh &mesh, const std::string& name, std::vector<double> p) -> decltype(auto) {
1102+
return mesh.interpolateFieldAtPoint(name, Point({p[0], p[1], p[2]}));
1103+
},
1104+
"Interpolate the feature at the location using barycentric coordinate",
1105+
"field"_a,
1106+
"point"_a)
1107+
11001108
.def("geodesicDistance",
11011109
static_cast<double (Mesh::*)(int,int) const>(&Mesh::geodesicDistance),
11021110
//py::overload_cast_const<int, int>(&Mesh::geodesicDistance),

Testing/MeshTests/MeshTests.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,3 +808,36 @@ TEST(MeshTests, thicknessTest) {
808808
Mesh baseline(std::string(TEST_DATA_DIR) + "/thickness/thickness.vtk");
809809
ASSERT_TRUE(thickness == baseline);
810810
}
811+
812+
TEST(MeshTests, interpolateFieldAtPoint) {
813+
814+
Eigen::MatrixXd points;
815+
Eigen::MatrixXi faces;
816+
817+
points.resize(3, 3);
818+
points.block<1, 3>(0, 0) = Eigen::Vector3d(-10, 0, 50);
819+
points.block<1, 3>(1, 0) = Eigen::Vector3d(0, 10, 50);
820+
points.block<1, 3>(2, 0) = Eigen::Vector3d(10, 0, 50);
821+
822+
faces.resize(1, 3);
823+
faces(0) = 0;
824+
faces(1) = 1;
825+
faces(2) = 2;
826+
827+
Mesh mesh(points, faces);
828+
829+
auto values = vtkDoubleArray::New();
830+
values->SetNumberOfValues(3);
831+
values->SetValue(0, -100);
832+
values->SetValue(1, 0);
833+
values->SetValue(2, 100);
834+
835+
const std::string fieldName = "Test";
836+
mesh.setField(fieldName, values, Mesh::Point);
837+
838+
ASSERT_DOUBLE_EQ(mesh.interpolateFieldAtPoint(fieldName, Point3({-10, 0, 50})), -100);
839+
ASSERT_DOUBLE_EQ(mesh.interpolateFieldAtPoint(fieldName, Point3({0, 10, 50})), 0);
840+
ASSERT_DOUBLE_EQ(mesh.interpolateFieldAtPoint(fieldName, Point3({10, 0, 50})), 100);
841+
ASSERT_DOUBLE_EQ(mesh.interpolateFieldAtPoint(fieldName, Point3({0, 0, 50})), 0);
842+
}
843+

Testing/OptimizeTests/OptimizeTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ TEST(OptimizeTests, ffc_test) {
570570
stats.compute_modes();
571571
stats.principal_component_projections();
572572

573-
bool good = check_constraint_violations(app, 4.0e-1);
573+
bool good = check_constraint_violations(app, 6.0e-1);
574574

575575
ASSERT_TRUE(good);
576576
}

0 commit comments

Comments
 (0)