Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
.DS_*
.directory
.idea/
.vscode/

# PYC files
*.pyc
Expand Down
36 changes: 36 additions & 0 deletions Libs/Mesh/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,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 @@ -19,7 +19,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
1 change: 1 addition & 0 deletions Libs/Python/ShapeworksPython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,7 @@ PYBIND11_MODULE(shapeworks_py, m)
py::enum_<Mesh::DistanceMethod>(mesh, "DistanceMethod")
.value("PointToPoint", Mesh::DistanceMethod::PointToPoint)
.value("PointToCell", Mesh::DistanceMethod::PointToCell)
.value("SymmetricPointToCell", Mesh::DistanceMethod::SymmetricPointToCell)
.export_values();
;

Expand Down
4 changes: 3 additions & 1 deletion Studio/Visualization/Viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,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