'libigl how to get ray intersections

I'm using libigl in a geometry project I'm working on. I need to use a function that casts a ray and gives me the intersections. I've found ray_mesh_intersect Problem is I can't find an example of this function anywhere, even on the docs!

I currently tried to give the function an empty input vector but it doesn't seem to work.

#include <iostream>
#include <igl/readSTL.h>
#include <igl/opengl/glfw/Viewer.h>
#include <igl/ray_mesh_intersect.h>
#include <Eigen/src/Core/Matrix.h>
#include <Eigen/src/Core/MatrixBase.h>

#define ARGV_COUNT 2

Eigen::MatrixXd Vs, Ns;
Eigen::MatrixXi Fs;

int main(int argc, char *argv[])
{

  if (argc != ARGV_COUNT)
  {
    std::cout << "Useage: ./example <path_to_stl>" << std::endl;
    return 1;
  }

  const std::string filePath = std::string(argv[1]);

  // load a mesh
  std::ifstream fileStream (filePath);
  igl::readSTL(fileStream, Vs, Fs, Ns);
  
  std::string dir,_1,_2,name;
  igl::read_triangle_mesh(filePath ,Vs ,Fs,dir,_1,_2,name);

  std::cout << "DIR:" << dir << std::endl;
  std::cout << "_1:" << _1 << std::endl;
  std::cout << "_2:" << _2 << std::endl;
  std::cout << "name:" << name << std::endl;

  Eigen::MatrixXd source;
  Eigen::MatrixXd dirEigen;
  igl::Hit hitted;

  igl::ray_mesh_intersect(source, dirEigen, Vs, Fs, hitted);

  // Plot the mesh
  igl::opengl::glfw::Viewer viewer;
  viewer.data().set_mesh(Vs, Fs);
  viewer.data().set_face_based(true);
  viewer.launch();
}

the current program crashes. But compiles.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source