point_query.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // Copyright 2009-2021 Intel Corporation
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include "default.h"
  5. namespace embree
  6. {
  7. /* Point query structure for closest point query */
  8. template<int K>
  9. struct RTC_ALIGN(16) PointQueryK
  10. {
  11. /* Default construction does nothing */
  12. __forceinline PointQueryK() {}
  13. /* Constructs a ray from origin, direction, and ray segment. Near
  14. * has to be smaller than far */
  15. __forceinline PointQueryK(const Vec3vf<K>& p, const vfloat<K>& radius = inf, const vfloat<K>& time = zero)
  16. : p(p), time(time), radius(radius) {}
  17. /* Returns the size of the ray */
  18. static __forceinline size_t size() { return K; }
  19. /* Calculates if this is a valid ray that does not cause issues during traversal */
  20. __forceinline vbool<K> valid() const
  21. {
  22. const vbool<K> vx = (abs(p.x) <= vfloat<K>(FLT_LARGE));
  23. const vbool<K> vy = (abs(p.y) <= vfloat<K>(FLT_LARGE));
  24. const vbool<K> vz = (abs(p.z) <= vfloat<K>(FLT_LARGE));
  25. const vbool<K> vn = radius >= vfloat<K>(0);
  26. const vbool<K> vf = abs(time) < vfloat<K>(inf);
  27. return vx & vy & vz & vn & vf;
  28. }
  29. __forceinline void get(PointQueryK<1>* ray) const;
  30. __forceinline void get(size_t i, PointQueryK<1>& ray) const;
  31. __forceinline void set(const PointQueryK<1>* ray);
  32. __forceinline void set(size_t i, const PointQueryK<1>& ray);
  33. Vec3vf<K> p; // location of the query point
  34. vfloat<K> time; // time for motion blur
  35. vfloat<K> radius; // radius for the point query
  36. };
  37. /* Specialization for a single point query */
  38. template<>
  39. struct RTC_ALIGN(16) PointQueryK<1>
  40. {
  41. /* Default construction does nothing */
  42. __forceinline PointQueryK() {}
  43. /* Constructs a ray from origin, direction, and ray segment. Near
  44. * has to be smaller than far */
  45. __forceinline PointQueryK(const Vec3fa& p, float radius = inf, float time = zero)
  46. : p(p), time(time), radius(radius) {}
  47. /* Calculates if this is a valid ray that does not cause issues during traversal */
  48. __forceinline bool valid() const {
  49. return all(le_mask(abs(Vec3fa(p)), Vec3fa(FLT_LARGE)) & le_mask(Vec3fa(0.f), Vec3fa(radius))) && abs(time) < float(inf);
  50. }
  51. Vec3f p;
  52. float time;
  53. float radius;
  54. };
  55. /* Converts point query packet to single point query */
  56. template<int K>
  57. __forceinline void PointQueryK<K>::get(PointQueryK<1>* query) const
  58. {
  59. for (size_t i = 0; i < K; i++) // FIXME: use SIMD transpose
  60. {
  61. query[i].p.x = p.x[i];
  62. query[i].p.y = p.y[i];
  63. query[i].p.z = p.z[i];
  64. query[i].time = time[i];
  65. query[i].radius = radius[i];
  66. }
  67. }
  68. /* Extracts a single point query out of a point query packet*/
  69. template<int K>
  70. __forceinline void PointQueryK<K>::get(size_t i, PointQueryK<1>& query) const
  71. {
  72. query.p.x = p.x[i];
  73. query.p.y = p.y[i];
  74. query.p.z = p.z[i];
  75. query.radius = radius[i];
  76. query.time = time[i];
  77. }
  78. /* Converts single point query to point query packet */
  79. template<int K>
  80. __forceinline void PointQueryK<K>::set(const PointQueryK<1>* query)
  81. {
  82. for (size_t i = 0; i < K; i++)
  83. {
  84. p.x[i] = query[i].p.x;
  85. p.y[i] = query[i].p.y;
  86. p.z[i] = query[i].p.z;
  87. radius[i] = query[i].radius;
  88. time[i] = query[i].time;
  89. }
  90. }
  91. /* inserts a single point query into a point query packet element */
  92. template<int K>
  93. __forceinline void PointQueryK<K>::set(size_t i, const PointQueryK<1>& query)
  94. {
  95. p.x[i] = query.p.x;
  96. p.y[i] = query.p.y;
  97. p.z[i] = query.p.z;
  98. radius[i] = query.radius;
  99. time[i] = query.time;
  100. }
  101. /* Shortcuts */
  102. typedef PointQueryK<1> PointQuery;
  103. typedef PointQueryK<4> PointQuery4;
  104. typedef PointQueryK<8> PointQuery8;
  105. typedef PointQueryK<16> PointQuery16;
  106. struct PointQueryN;
  107. /* Outputs point query to stream */
  108. template<int K>
  109. __forceinline embree_ostream operator <<(embree_ostream cout, const PointQueryK<K>& query)
  110. {
  111. cout << "{ " << embree_endl
  112. << " p = " << query.p << embree_endl
  113. << " r = " << query.radius << embree_endl
  114. << " time = " << query.time << embree_endl
  115. << "}";
  116. return cout;
  117. }
  118. }