EmbreeIntersector.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. // num_rays number of rays shot (at least one)
  46. // Returns true if and only if there was a hit
  47. bool intersectRay(
  48. const RowVector3& origin,
  49. const RowVector3& direction,
  50. std::vector<embree::Hit > &hits,
  51. int & num_rays) const;
  52. // Given a ray find the first *front-facing* hit
  53. //
  54. // Inputs:
  55. // a 3d first end point of segment
  56. // ab 3d vector from a to other endpoint b
  57. // Output:
  58. // hit embree information about hit
  59. // Returns true if and only if there was a hit
  60. bool intersectSegment(const RowVector3& a, const RowVector3& ab, embree::Hit &hit) const;
  61. private:
  62. embree::BuildTriangle *triangles;
  63. embree::BuildVertex *vertices;
  64. embree::Ref<embree::Accel> _accel;
  65. embree::Ref<embree::Intersector> _intersector;
  66. };
  67. }
  68. #ifdef IGL_HEADER_ONLY
  69. # include "EmbreeIntersector.cpp"
  70. #endif
  71. #endif //EMBREE_INTERSECTOR_H