Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Libs/Mesh/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,42 @@ std::vector<Field> Mesh::distance(const Mesh& target, const DistanceMethod metho
}
} break;

case SymmetricPointToCell: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a unit test for that case ?

/*
referenceMesh (point) -> targetMesh (cell) (and get closestPoint)
referenceMesh (cell) -> targetMesh (closestPoint)
*/
auto targetCellLocator = vtkSmartPointer<vtkCellLocator>::New();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the faster vtkStaticCellLocator

targetCellLocator->SetDataSet(target.poly_data_);
targetCellLocator->BuildLocator();

auto refCellLocator = vtkSmartPointer<vtkCellLocator>::New();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vtkStaticCellLocator as above

refCellLocator->SetDataSet(poly_data_);
refCellLocator->BuildLocator();

double dist2_target, dist2_ref;
auto cell_target = vtkSmartPointer<vtkGenericCell>::New();
auto cell_ref = vtkSmartPointer<vtkGenericCell>::New();
vtkIdType cellId_target, cellId_ref;
int subId_target, subId_ref;
Point3 closestPoint_target, closestPoint_ref;


for (int i = 0; i < numPoints(); i++) {
poly_data_->GetPoint(i, currentPoint.GetDataPointer()); // ref point
// ref mesh point -> target mesh cell
targetCellLocator->FindClosestPoint(currentPoint.GetDataPointer(), closestPoint_target.GetDataPointer(), cell_target, cellId_target,
subId_target, dist2_target);
// target mesh closest point -> ref mesh cell
refCellLocator->FindClosestPoint(closestPoint_target.GetDataPointer(), closestPoint_ref.GetDataPointer(), cell_ref, cellId_ref,
subId_ref, dist2_ref);

ids->SetValue(i, cellId_target);
auto mean_sym_dist = (std::sqrt(dist2_target) + std::sqrt(dist2_ref))/2;
distance->SetValue(i, mean_sym_dist);
}
} break;

default:
throw std::invalid_argument("invalid distance method");
}
Expand Down
2 changes: 1 addition & 1 deletion Libs/Mesh/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Mesh {
public:
enum FieldType { Point, Face };
enum AlignmentType { Rigid, Similarity, Affine };
enum DistanceMethod { PointToPoint, PointToCell };
enum DistanceMethod { PointToPoint, PointToCell, SymmetricPointToCell };
enum CurvatureType { Principal, Gaussian, Mean };
enum SubdivisionType { Butterfly, Loop };

Expand Down
7 changes: 4 additions & 3 deletions Libs/Python/ShapeworksPython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,9 +797,10 @@ PYBIND11_MODULE(shapeworks_py, m) {

// Mesh::DistanceMethod
py::enum_<Mesh::DistanceMethod>(mesh, "DistanceMethod")
.value("PointToPoint", Mesh::DistanceMethod::PointToPoint)
.value("PointToCell", Mesh::DistanceMethod::PointToCell)
.export_values();
.value("PointToPoint", Mesh::DistanceMethod::PointToPoint)
.value("PointToCell", Mesh::DistanceMethod::PointToCell)
.value("SymmetricPointToCell", Mesh::DistanceMethod::SymmetricPointToCell)
.export_values();
;

// Mesh::CurvatureType
Expand Down
4 changes: 3 additions & 1 deletion Studio/Visualization/Viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,9 @@ void Viewer::display_shape(std::shared_ptr<Shape> shape) {
}

Mesh m2(compare_poly_data);
auto field = m.distance(m2)[0];
auto field = m.distance(m2, Mesh::DistanceMethod::SymmetricPointToCell)[0];
// TODO: disable debug
std::cout << "Debug Mode | Computing distance with SymmetricPointToCell method in Studio Viewer " << std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

K, let's remove this debug line and I think it's good to go.

m.setField("distance", field, Mesh::Point);
}

Expand Down