The following code loads a mesh off file, creates a vector of set of random points from the mesh. Then it finds the nearest points on the mesh for each of these sets of random points using knn. I found that the code is stuck in the knn step forever. This is for a mesh with 50000 points and 100000 faces. How to speed it up? Is there any error in my code as given below:
#include <igl/read_triangle_mesh.h>
#include <igl/octree.h>
#include <igl/knn.h>
#include <igl/random_points_on_mesh.h>
#include <igl/opengl/glfw/Viewer.h>
#include <igl/get_seconds.h>
#include <iostream>
#include <cstdlib>
#include <vector>
int main(int argc, char *argv[])
{
Eigen::MatrixXd V;
Eigen::MatrixXi F;
igl::read_triangle_mesh(argv[1],V,F);
// Sample mesh for point cloud
std::cout << "no. of points, faces "<< V.rows()<<"," <<F.rows()<< std::endl;
std::vector<Eigen::MatrixXd> vec_pts;
for (int i =0;i<10;i++)
{
Eigen::MatrixXd P;
Eigen::VectorXi I;
Eigen::MatrixXd B;
igl::random_points_on_mesh(25,V,F,B,I,P);
vec_pts.push_back(P);
}
std::cout << "points created "<< std::endl;
// Build octree
std::vector<std::vector<int > > O_PI;
Eigen::MatrixXi O_CH;
Eigen::MatrixXd O_CN;
Eigen::VectorXd O_W;
igl::octree(V,O_PI,O_CH,O_CN,O_W);
std::cout << "octree created "<< std::endl;
for (int i=0;i< vec_pts.size();i++)
{
Eigen::MatrixXd query = vec_pts[i];
Eigen::VectorXi I;
const double t_before = igl::get_seconds();
igl::knn(query,1,O_PI,O_CH,O_CN,O_W,I);
const double t_after = igl::get_seconds();
std::cout << "time for knn query in sec "<< t_after - t_before << std::endl;
}
}