scene_user_geometry.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright 2009-2021 Intel Corporation
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include "accelset.h"
  5. namespace embree
  6. {
  7. /*! User geometry with user defined intersection functions */
  8. struct UserGeometry : public AccelSet
  9. {
  10. /*! type of this geometry */
  11. static const Geometry::GTypeMask geom_type = Geometry::MTY_USER_GEOMETRY;
  12. public:
  13. UserGeometry (Device* device, unsigned int items = 0, unsigned int numTimeSteps = 1);
  14. virtual void setMask (unsigned mask);
  15. virtual void setBoundsFunction (RTCBoundsFunction bounds, void* userPtr);
  16. virtual void setIntersectFunctionN (RTCIntersectFunctionN intersect);
  17. virtual void setOccludedFunctionN (RTCOccludedFunctionN occluded);
  18. virtual void build() {}
  19. virtual void addElementsToCount (GeometryCounts & counts) const;
  20. __forceinline float projectedPrimitiveArea(const size_t i) const { return 0.0f; }
  21. };
  22. namespace isa
  23. {
  24. struct UserGeometryISA : public UserGeometry
  25. {
  26. UserGeometryISA (Device* device)
  27. : UserGeometry(device) {}
  28. PrimInfo createPrimRefArray(PrimRef* prims, const range<size_t>& r, size_t k, unsigned int geomID) const
  29. {
  30. PrimInfo pinfo(empty);
  31. for (size_t j=r.begin(); j<r.end(); j++)
  32. {
  33. BBox3fa bounds = empty;
  34. if (!buildBounds(j,&bounds)) continue;
  35. const PrimRef prim(bounds,geomID,unsigned(j));
  36. pinfo.add_center2(prim);
  37. prims[k++] = prim;
  38. }
  39. return pinfo;
  40. }
  41. PrimInfo createPrimRefArrayMB(mvector<PrimRef>& prims, size_t itime, const range<size_t>& r, size_t k, unsigned int geomID) const
  42. {
  43. PrimInfo pinfo(empty);
  44. for (size_t j=r.begin(); j<r.end(); j++)
  45. {
  46. BBox3fa bounds = empty;
  47. if (!buildBounds(j,itime,bounds)) continue;
  48. const PrimRef prim(bounds,geomID,unsigned(j));
  49. pinfo.add_center2(prim);
  50. prims[k++] = prim;
  51. }
  52. return pinfo;
  53. }
  54. PrimInfo createPrimRefArrayMB(PrimRef* prims, const BBox1f& time_range, const range<size_t>& r, size_t k, unsigned int geomID) const
  55. {
  56. PrimInfo pinfo(empty);
  57. const BBox1f t0t1 = BBox1f::intersect(getTimeRange(), time_range);
  58. if (t0t1.empty()) return pinfo;
  59. for (size_t j = r.begin(); j < r.end(); j++) {
  60. LBBox3fa lbounds = empty;
  61. if (!linearBounds(j, t0t1, lbounds))
  62. continue;
  63. const PrimRef prim(lbounds.bounds(), geomID, unsigned(j));
  64. pinfo.add_center2(prim);
  65. prims[k++] = prim;
  66. }
  67. return pinfo;
  68. }
  69. PrimInfoMB createPrimRefMBArray(mvector<PrimRefMB>& prims, const BBox1f& t0t1, const range<size_t>& r, size_t k, unsigned int geomID) const
  70. {
  71. PrimInfoMB pinfo(empty);
  72. for (size_t j=r.begin(); j<r.end(); j++)
  73. {
  74. if (!valid(j, timeSegmentRange(t0t1))) continue;
  75. const PrimRefMB prim(linearBounds(j,t0t1),this->numTimeSegments(),this->time_range,this->numTimeSegments(),geomID,unsigned(j));
  76. pinfo.add_primref(prim);
  77. prims[k++] = prim;
  78. }
  79. return pinfo;
  80. }
  81. };
  82. }
  83. DECLARE_ISA_FUNCTION(UserGeometry*, createUserGeometry, Device*);
  84. }