EmbreeIntersector.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #ifndef IGL_EMBREE_INTERSECTOR_H
  2. #define IGL_EMBREE_INTERSECTOR_H
  3. #undef interface
  4. #undef near
  5. #undef far
  6. #include "common/intersector.h"
  7. #include "common/accel.h"
  8. #include <vector>
  9. //#include "types.h"
  10. namespace igl
  11. {
  12. template <
  13. typename PointMatrixType,
  14. typename FaceMatrixType,
  15. typename RowVector3>
  16. class EmbreeIntersector
  17. {
  18. public:
  19. // V #V by 3 list of vertex positions
  20. // F #F by 3 list of Oriented triangles
  21. //
  22. // Note: this will only find front-facing hits. To consider all hits then
  23. // pass [F;fliplr(F)]
  24. EmbreeIntersector(const PointMatrixType & V, const FaceMatrixType & F);
  25. virtual ~EmbreeIntersector();
  26. // Given a ray find the first *front-facing* hit
  27. //
  28. // Inputs:
  29. // origin 3d origin point of ray
  30. // direction 3d (not necessarily normalized) direction vector of ray
  31. // Output:
  32. // hit embree information about hit
  33. // Returns true if and only if there was a hit
  34. bool intersectRay(
  35. const RowVector3& origin,
  36. const RowVector3& direction,
  37. embree::Hit &hit) const;
  38. // Given a ray find the all *front-facing* hits in order
  39. //
  40. // Inputs:
  41. // origin 3d origin point of ray
  42. // direction 3d (not necessarily normalized) direction vector of ray
  43. // Output:
  44. // hit embree information about hit
  45. // Returns true if and only if there was a hit
  46. bool intersectRay(
  47. const RowVector3& origin,
  48. const RowVector3& direction,
  49. std::vector<embree::Hit > &hits) const;
  50. // Given a ray find the first *front-facing* hit
  51. //
  52. // Inputs:
  53. // a 3d first end point of segment
  54. // ab 3d vector from a to other endpoint b
  55. // Output:
  56. // hit embree information about hit
  57. // Returns true if and only if there was a hit
  58. bool intersectSegment(const RowVector3& a, const RowVector3& ab, embree::Hit &hit) const;
  59. private:
  60. embree::BuildTriangle *triangles;
  61. embree::BuildVertex *vertices;
  62. embree::Ref<embree::Accel> _accel;
  63. embree::Ref<embree::Intersector> _intersector;
  64. };
  65. }
  66. #ifdef IGL_HEADER_ONLY
  67. # include "EmbreeIntersector.cpp"
  68. #endif
  69. #endif //EMBREE_INTERSECTOR_H