Skip to content
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update point_mesh_distance.cpp
  • Loading branch information
jnyao authored Oct 9, 2018
commit 8cca9c4d3619676c4b5821fbd2bd31ecfb788aa8
28 changes: 25 additions & 3 deletions src/point_mesh_distance.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#include "point_mesh_distance.h"
#include "point_triangle_distance.h"
#include <limits>
#include <iostream>
#include <igl/per_face_normals.h>

void point_mesh_distance(
const Eigen::MatrixXd & X,
Expand All @@ -10,7 +14,25 @@ void point_mesh_distance(
{
// Replace with your code
P.resizeLike(X);
N = Eigen::MatrixXd::Zero(X.rows(),X.cols());
for(int i = 0;i<X.rows();i++) P.row(i) = VY.row(i%VY.rows());
D = (X-P).rowwise().norm();
N = Eigen::MatrixXd::Zero(X.rows(), X.cols());
Eigen::MatrixXd AllN = Eigen::MatrixXd::Zero(FY.rows(), FY.cols());
igl::per_face_normals(VY, FY, AllN);
//for(int i = 0;i<X.rows();i++) P.row(i) = VY.row(i%VY.rows());
//D = (X-P).rowwise().norm();
D = Eigen::VectorXd(X.rows());

for (int i = 0; i < X.rows(); i++) {
double d; Eigen::RowVector3d p;
D(i) = std::numeric_limits<double>::infinity();
for (int j = 0; j < FY.rows(); j++) {
point_triangle_distance(X.row(i), VY.row(FY(j, 0)), VY.row(FY(j, 1)), VY.row(FY(j, 2)), d, p);
if (d < D(i)) {
D(i) = d;
P(i, 0) = p(0); P(i, 1) = p(1); P(i, 2) = p(2);
N.row(i) = AllN.row(j);
}
}
}


}