geometry.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. // Copyright 2009-2021 Intel Corporation
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include "default.h"
  5. #include "device.h"
  6. #include "buffer.h"
  7. #include "../common/point_query.h"
  8. #include "../builders/priminfo.h"
  9. #include "../builders/priminfo_mb.h"
  10. namespace embree
  11. {
  12. class Scene;
  13. class Geometry;
  14. struct GeometryCounts
  15. {
  16. __forceinline GeometryCounts()
  17. : numFilterFunctions(0),
  18. numTriangles(0), numMBTriangles(0),
  19. numQuads(0), numMBQuads(0),
  20. numBezierCurves(0), numMBBezierCurves(0),
  21. numLineSegments(0), numMBLineSegments(0),
  22. numSubdivPatches(0), numMBSubdivPatches(0),
  23. numUserGeometries(0), numMBUserGeometries(0),
  24. numInstancesCheap(0), numMBInstancesCheap(0),
  25. numInstancesExpensive(0), numMBInstancesExpensive(0),
  26. numInstanceArrays(0), numMBInstanceArrays(0),
  27. numGrids(0), numMBGrids(0),
  28. numSubGrids(0), numMBSubGrids(0),
  29. numPoints(0), numMBPoints(0) {}
  30. __forceinline size_t size() const {
  31. return numTriangles + numQuads + numBezierCurves + numLineSegments + numSubdivPatches + numUserGeometries + numInstancesCheap + numInstancesExpensive + numInstanceArrays + numGrids + numPoints
  32. + numMBTriangles + numMBQuads + numMBBezierCurves + numMBLineSegments + numMBSubdivPatches + numMBUserGeometries + numMBInstancesCheap + numMBInstancesExpensive + numMBInstanceArrays + numMBGrids + numMBPoints;
  33. }
  34. __forceinline unsigned int enabledGeometryTypesMask() const
  35. {
  36. unsigned int mask = 0;
  37. if (numTriangles) mask |= 1 << 0;
  38. if (numQuads) mask |= 1 << 1;
  39. if (numBezierCurves+numLineSegments) mask |= 1 << 2;
  40. if (numSubdivPatches) mask |= 1 << 3;
  41. if (numUserGeometries) mask |= 1 << 4;
  42. if (numInstancesCheap) mask |= 1 << 5;
  43. if (numInstancesExpensive) mask |= 1 << 6;
  44. if (numInstanceArrays) mask |= 1 << 7;
  45. if (numGrids) mask |= 1 << 8;
  46. if (numPoints) mask |= 1 << 9;
  47. unsigned int maskMB = 0;
  48. if (numMBTriangles) maskMB |= 1 << 0;
  49. if (numMBQuads) maskMB |= 1 << 1;
  50. if (numMBBezierCurves+numMBLineSegments) maskMB |= 1 << 2;
  51. if (numMBSubdivPatches) maskMB |= 1 << 3;
  52. if (numMBUserGeometries) maskMB |= 1 << 4;
  53. if (numMBInstancesCheap) maskMB |= 1 << 5;
  54. if (numMBInstancesExpensive) maskMB |= 1 << 6;
  55. if (numMBInstanceArrays) maskMB |= 1 << 7;
  56. if (numMBGrids) maskMB |= 1 << 8;
  57. if (numMBPoints) maskMB |= 1 << 9;
  58. return (mask<<8) + maskMB;
  59. }
  60. __forceinline GeometryCounts operator+ (GeometryCounts const & rhs) const
  61. {
  62. GeometryCounts ret;
  63. ret.numFilterFunctions = numFilterFunctions + rhs.numFilterFunctions;
  64. ret.numTriangles = numTriangles + rhs.numTriangles;
  65. ret.numMBTriangles = numMBTriangles + rhs.numMBTriangles;
  66. ret.numQuads = numQuads + rhs.numQuads;
  67. ret.numMBQuads = numMBQuads + rhs.numMBQuads;
  68. ret.numBezierCurves = numBezierCurves + rhs.numBezierCurves;
  69. ret.numMBBezierCurves = numMBBezierCurves + rhs.numMBBezierCurves;
  70. ret.numLineSegments = numLineSegments + rhs.numLineSegments;
  71. ret.numMBLineSegments = numMBLineSegments + rhs.numMBLineSegments;
  72. ret.numSubdivPatches = numSubdivPatches + rhs.numSubdivPatches;
  73. ret.numMBSubdivPatches = numMBSubdivPatches + rhs.numMBSubdivPatches;
  74. ret.numUserGeometries = numUserGeometries + rhs.numUserGeometries;
  75. ret.numMBUserGeometries = numMBUserGeometries + rhs.numMBUserGeometries;
  76. ret.numInstancesCheap = numInstancesCheap + rhs.numInstancesCheap;
  77. ret.numMBInstancesCheap = numMBInstancesCheap + rhs.numMBInstancesCheap;
  78. ret.numInstancesExpensive = numInstancesExpensive + rhs.numInstancesExpensive;
  79. ret.numMBInstancesExpensive = numMBInstancesExpensive + rhs.numMBInstancesExpensive;
  80. ret.numInstanceArrays = numInstanceArrays + rhs.numInstanceArrays;
  81. ret.numMBInstanceArrays = numMBInstanceArrays + rhs.numMBInstanceArrays;
  82. ret.numGrids = numGrids + rhs.numGrids;
  83. ret.numMBGrids = numMBGrids + rhs.numMBGrids;
  84. ret.numSubGrids = numSubGrids + rhs.numSubGrids;
  85. ret.numMBSubGrids = numMBSubGrids + rhs.numMBSubGrids;
  86. ret.numPoints = numPoints + rhs.numPoints;
  87. ret.numMBPoints = numMBPoints + rhs.numMBPoints;
  88. return ret;
  89. }
  90. size_t numFilterFunctions; //!< number of geometries with filter functions enabled
  91. size_t numTriangles; //!< number of enabled triangles
  92. size_t numMBTriangles; //!< number of enabled motion blurred triangles
  93. size_t numQuads; //!< number of enabled quads
  94. size_t numMBQuads; //!< number of enabled motion blurred quads
  95. size_t numBezierCurves; //!< number of enabled curves
  96. size_t numMBBezierCurves; //!< number of enabled motion blurred curves
  97. size_t numLineSegments; //!< number of enabled line segments
  98. size_t numMBLineSegments; //!< number of enabled line motion blurred segments
  99. size_t numSubdivPatches; //!< number of enabled subdivision patches
  100. size_t numMBSubdivPatches; //!< number of enabled motion blurred subdivision patches
  101. size_t numUserGeometries; //!< number of enabled user geometries
  102. size_t numMBUserGeometries; //!< number of enabled motion blurred user geometries
  103. size_t numInstancesCheap; //!< number of enabled cheap instances
  104. size_t numMBInstancesCheap; //!< number of enabled motion blurred cheap instances
  105. size_t numInstancesExpensive; //!< number of enabled expensive instances
  106. size_t numMBInstancesExpensive; //!< number of enabled motion blurred expensive instances
  107. size_t numInstanceArrays; //!< number of enabled instance arrays
  108. size_t numMBInstanceArrays; //!< number of enabled motion blurred instance arrays
  109. size_t numGrids; //!< number of enabled grid geometries
  110. size_t numMBGrids; //!< number of enabled motion blurred grid geometries
  111. size_t numSubGrids; //!< number of enabled grid geometries
  112. size_t numMBSubGrids; //!< number of enabled motion blurred grid geometries
  113. size_t numPoints; //!< number of enabled points
  114. size_t numMBPoints; //!< number of enabled motion blurred points
  115. };
  116. /*! Base class all geometries are derived from */
  117. class Geometry : public RefCount
  118. {
  119. ALIGNED_CLASS_USM_(16);
  120. friend class Scene;
  121. public:
  122. /*! type of geometry */
  123. enum GType
  124. {
  125. GTY_FLAT_LINEAR_CURVE = 0,
  126. GTY_ROUND_LINEAR_CURVE = 1,
  127. GTY_ORIENTED_LINEAR_CURVE = 2,
  128. GTY_CONE_LINEAR_CURVE = 3,
  129. GTY_FLAT_BEZIER_CURVE = 4,
  130. GTY_ROUND_BEZIER_CURVE = 5,
  131. GTY_ORIENTED_BEZIER_CURVE = 6,
  132. GTY_FLAT_BSPLINE_CURVE = 8,
  133. GTY_ROUND_BSPLINE_CURVE = 9,
  134. GTY_ORIENTED_BSPLINE_CURVE = 10,
  135. GTY_FLAT_HERMITE_CURVE = 12,
  136. GTY_ROUND_HERMITE_CURVE = 13,
  137. GTY_ORIENTED_HERMITE_CURVE = 14,
  138. GTY_FLAT_CATMULL_ROM_CURVE = 16,
  139. GTY_ROUND_CATMULL_ROM_CURVE = 17,
  140. GTY_ORIENTED_CATMULL_ROM_CURVE = 18,
  141. GTY_TRIANGLE_MESH = 20,
  142. GTY_QUAD_MESH = 21,
  143. GTY_GRID_MESH = 22,
  144. GTY_SUBDIV_MESH = 23,
  145. GTY_SPHERE_POINT = 25,
  146. GTY_DISC_POINT = 26,
  147. GTY_ORIENTED_DISC_POINT = 27,
  148. GTY_USER_GEOMETRY = 29,
  149. GTY_INSTANCE_CHEAP = 30,
  150. GTY_INSTANCE_EXPENSIVE = 31,
  151. GTY_INSTANCE_ARRAY = 24,
  152. GTY_END = 32,
  153. GTY_BASIS_LINEAR = 0,
  154. GTY_BASIS_BEZIER = 4,
  155. GTY_BASIS_BSPLINE = 8,
  156. GTY_BASIS_HERMITE = 12,
  157. GTY_BASIS_CATMULL_ROM = 16,
  158. GTY_BASIS_MASK = 28,
  159. GTY_SUBTYPE_FLAT_CURVE = 0,
  160. GTY_SUBTYPE_ROUND_CURVE = 1,
  161. GTY_SUBTYPE_ORIENTED_CURVE = 2,
  162. GTY_SUBTYPE_MASK = 3,
  163. };
  164. enum GSubType
  165. {
  166. GTY_SUBTYPE_DEFAULT= 0,
  167. GTY_SUBTYPE_INSTANCE_LINEAR = 0,
  168. GTY_SUBTYPE_INSTANCE_QUATERNION = 1
  169. };
  170. enum GTypeMask
  171. {
  172. MTY_FLAT_LINEAR_CURVE = 1ul << GTY_FLAT_LINEAR_CURVE,
  173. MTY_ROUND_LINEAR_CURVE = 1ul << GTY_ROUND_LINEAR_CURVE,
  174. MTY_CONE_LINEAR_CURVE = 1ul << GTY_CONE_LINEAR_CURVE,
  175. MTY_ORIENTED_LINEAR_CURVE = 1ul << GTY_ORIENTED_LINEAR_CURVE,
  176. MTY_FLAT_BEZIER_CURVE = 1ul << GTY_FLAT_BEZIER_CURVE,
  177. MTY_ROUND_BEZIER_CURVE = 1ul << GTY_ROUND_BEZIER_CURVE,
  178. MTY_ORIENTED_BEZIER_CURVE = 1ul << GTY_ORIENTED_BEZIER_CURVE,
  179. MTY_FLAT_BSPLINE_CURVE = 1ul << GTY_FLAT_BSPLINE_CURVE,
  180. MTY_ROUND_BSPLINE_CURVE = 1ul << GTY_ROUND_BSPLINE_CURVE,
  181. MTY_ORIENTED_BSPLINE_CURVE = 1ul << GTY_ORIENTED_BSPLINE_CURVE,
  182. MTY_FLAT_HERMITE_CURVE = 1ul << GTY_FLAT_HERMITE_CURVE,
  183. MTY_ROUND_HERMITE_CURVE = 1ul << GTY_ROUND_HERMITE_CURVE,
  184. MTY_ORIENTED_HERMITE_CURVE = 1ul << GTY_ORIENTED_HERMITE_CURVE,
  185. MTY_FLAT_CATMULL_ROM_CURVE = 1ul << GTY_FLAT_CATMULL_ROM_CURVE,
  186. MTY_ROUND_CATMULL_ROM_CURVE = 1ul << GTY_ROUND_CATMULL_ROM_CURVE,
  187. MTY_ORIENTED_CATMULL_ROM_CURVE = 1ul << GTY_ORIENTED_CATMULL_ROM_CURVE,
  188. MTY_CURVE2 = MTY_FLAT_LINEAR_CURVE | MTY_ROUND_LINEAR_CURVE | MTY_CONE_LINEAR_CURVE | MTY_ORIENTED_LINEAR_CURVE,
  189. MTY_CURVE4 = MTY_FLAT_BEZIER_CURVE | MTY_ROUND_BEZIER_CURVE | MTY_ORIENTED_BEZIER_CURVE |
  190. MTY_FLAT_BSPLINE_CURVE | MTY_ROUND_BSPLINE_CURVE | MTY_ORIENTED_BSPLINE_CURVE |
  191. MTY_FLAT_HERMITE_CURVE | MTY_ROUND_HERMITE_CURVE | MTY_ORIENTED_HERMITE_CURVE |
  192. MTY_FLAT_CATMULL_ROM_CURVE | MTY_ROUND_CATMULL_ROM_CURVE | MTY_ORIENTED_CATMULL_ROM_CURVE,
  193. MTY_SPHERE_POINT = 1ul << GTY_SPHERE_POINT,
  194. MTY_DISC_POINT = 1ul << GTY_DISC_POINT,
  195. MTY_ORIENTED_DISC_POINT = 1ul << GTY_ORIENTED_DISC_POINT,
  196. MTY_POINTS = MTY_SPHERE_POINT | MTY_DISC_POINT | MTY_ORIENTED_DISC_POINT,
  197. MTY_CURVES = MTY_CURVE2 | MTY_CURVE4 | MTY_POINTS,
  198. MTY_TRIANGLE_MESH = 1ul << GTY_TRIANGLE_MESH,
  199. MTY_QUAD_MESH = 1ul << GTY_QUAD_MESH,
  200. MTY_GRID_MESH = 1ul << GTY_GRID_MESH,
  201. MTY_SUBDIV_MESH = 1ul << GTY_SUBDIV_MESH,
  202. MTY_USER_GEOMETRY = 1ul << GTY_USER_GEOMETRY,
  203. MTY_INSTANCE_CHEAP = 1ul << GTY_INSTANCE_CHEAP,
  204. MTY_INSTANCE_EXPENSIVE = 1ul << GTY_INSTANCE_EXPENSIVE,
  205. MTY_INSTANCE = MTY_INSTANCE_CHEAP | MTY_INSTANCE_EXPENSIVE,
  206. MTY_INSTANCE_ARRAY = 1ul << GTY_INSTANCE_ARRAY,
  207. MTY_ALL = -1
  208. };
  209. static const char* gtype_names[GTY_END];
  210. enum class State : unsigned {
  211. MODIFIED = 0,
  212. COMMITTED = 1,
  213. };
  214. public:
  215. /*! Geometry constructor */
  216. Geometry (Device* device, GType gtype, unsigned int numPrimitives, unsigned int numTimeSteps);
  217. /*! Geometry destructor */
  218. virtual ~Geometry();
  219. public:
  220. /*! tests if geometry is enabled */
  221. __forceinline bool isEnabled() const { return enabled; }
  222. /*! tests if geometry is disabled */
  223. __forceinline bool isDisabled() const { return !isEnabled(); }
  224. /* checks if argument version of filter functions are enabled */
  225. __forceinline bool hasArgumentFilterFunctions() const {
  226. return argumentFilterEnabled;
  227. }
  228. /*! tests if that geometry has some filter function set */
  229. __forceinline bool hasGeometryFilterFunctions () const {
  230. return (intersectionFilterN != nullptr) || (occlusionFilterN != nullptr);
  231. }
  232. /*! returns geometry type */
  233. __forceinline GType getType() const { return gtype; }
  234. /*! returns curve type */
  235. __forceinline GType getCurveType() const { return (GType)(gtype & GTY_SUBTYPE_MASK); }
  236. /*! returns curve basis */
  237. __forceinline GType getCurveBasis() const { return (GType)(gtype & GTY_BASIS_MASK); }
  238. /*! returns geometry type mask */
  239. __forceinline GTypeMask getTypeMask() const { return (GTypeMask)(1 << gtype); }
  240. /*! returns true of geometry contains motion blur */
  241. __forceinline bool hasMotionBlur () const {
  242. return numTimeSteps > 1;
  243. }
  244. /*! returns number of primitives */
  245. __forceinline size_t size() const { return numPrimitives; }
  246. /*! sets the number of primitives */
  247. virtual void setNumPrimitives(unsigned int numPrimitives_in);
  248. /*! sets number of time steps */
  249. virtual void setNumTimeSteps (unsigned int numTimeSteps_in);
  250. /*! sets motion blur time range */
  251. void setTimeRange (const BBox1f range);
  252. /*! gets motion blur time range */
  253. BBox1f getTimeRange () const;
  254. /*! sets number of vertex attributes */
  255. virtual void setVertexAttributeCount (unsigned int N) {
  256. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
  257. }
  258. /*! sets number of topologies */
  259. virtual void setTopologyCount (unsigned int N) {
  260. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
  261. }
  262. /*! sets the build quality */
  263. void setBuildQuality(RTCBuildQuality quality_in)
  264. {
  265. this->quality = quality_in;
  266. Geometry::update();
  267. }
  268. /* calculate time segment itime and fractional time ftime */
  269. __forceinline int timeSegment(float time, float& ftime) const {
  270. return getTimeSegment(time,time_range.lower,time_range.upper,fnumTimeSegments,ftime);
  271. }
  272. template<int N>
  273. __forceinline vint<N> timeSegment(const vfloat<N>& time, vfloat<N>& ftime) const {
  274. return getTimeSegment<N>(time,vfloat<N>(time_range.lower),vfloat<N>(time_range.upper),vfloat<N>(fnumTimeSegments),ftime);
  275. }
  276. /* calculate overlapping time segment range */
  277. __forceinline range<int> timeSegmentRange(const BBox1f& range) const {
  278. return getTimeSegmentRange(range,time_range,fnumTimeSegments);
  279. }
  280. /* returns time that corresponds to time step */
  281. __forceinline float timeStep(const int i) const {
  282. assert(i>=0 && i<(int)numTimeSteps);
  283. return time_range.lower + time_range.size()*float(i)/fnumTimeSegments;
  284. }
  285. /*! for all geometries */
  286. public:
  287. /*! Enable geometry. */
  288. virtual void enable();
  289. /*! Update geometry. */
  290. void update();
  291. /*! commit of geometry */
  292. virtual void commit();
  293. /*! Update geometry buffer. */
  294. virtual void updateBuffer(RTCBufferType type, unsigned int slot) {
  295. update(); // update everything for geometries not supporting this call
  296. }
  297. /*! Disable geometry. */
  298. virtual void disable();
  299. /*! Verify the geometry */
  300. virtual bool verify() { return true; }
  301. /*! called before every build */
  302. virtual void preCommit();
  303. /*! called after every build */
  304. virtual void postCommit();
  305. virtual void addElementsToCount (GeometryCounts & counts) const {
  306. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
  307. };
  308. /*! sets constant tessellation rate for the geometry */
  309. virtual void setTessellationRate(float N) {
  310. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
  311. }
  312. /*! Sets the maximal curve radius scale allowed by min-width feature. */
  313. virtual void setMaxRadiusScale(float s) {
  314. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
  315. }
  316. /*! Set user data pointer. */
  317. virtual void setUserData(void* ptr);
  318. /*! Get user data pointer. */
  319. __forceinline void* getUserData() const {
  320. return userPtr;
  321. }
  322. /*! interpolates user data to the specified u/v location */
  323. virtual void interpolate(const RTCInterpolateArguments* const args) {
  324. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
  325. }
  326. /*! interpolates user data to the specified u/v locations */
  327. virtual void interpolateN(const RTCInterpolateNArguments* const args);
  328. /* point query api */
  329. bool pointQuery(PointQuery* query, PointQueryContext* context);
  330. /*! for subdivision surfaces only */
  331. public:
  332. virtual void setSubdivisionMode (unsigned topologyID, RTCSubdivisionMode mode) {
  333. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
  334. }
  335. virtual void setVertexAttributeTopology(unsigned int vertexBufferSlot, unsigned int indexBufferSlot) {
  336. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
  337. }
  338. /*! Set displacement function. */
  339. virtual void setDisplacementFunction (RTCDisplacementFunctionN filter) {
  340. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
  341. }
  342. virtual unsigned int getFirstHalfEdge(unsigned int faceID) {
  343. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
  344. }
  345. virtual unsigned int getFace(unsigned int edgeID) {
  346. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
  347. }
  348. virtual unsigned int getNextHalfEdge(unsigned int edgeID) {
  349. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
  350. }
  351. virtual unsigned int getPreviousHalfEdge(unsigned int edgeID) {
  352. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
  353. }
  354. virtual unsigned int getOppositeHalfEdge(unsigned int topologyID, unsigned int edgeID) {
  355. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
  356. }
  357. /*! get fast access to first vertex buffer if applicable */
  358. virtual float * getCompactVertexArray () const {
  359. return nullptr;
  360. }
  361. /*! Returns the modified counter - how many times the geo has been modified */
  362. __forceinline unsigned int getModCounter () const {
  363. return modCounter_;
  364. }
  365. /*! for triangle meshes and bezier curves only */
  366. public:
  367. /*! Sets ray mask. */
  368. virtual void setMask(unsigned mask) {
  369. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
  370. }
  371. /*! Sets specified buffer. */
  372. virtual void setBuffer(RTCBufferType type, unsigned int slot, RTCFormat format, const Ref<Buffer>& buffer, size_t offset, size_t stride, unsigned int num) {
  373. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
  374. }
  375. /*! Gets specified buffer. */
  376. virtual void* getBuffer(RTCBufferType type, unsigned int slot) {
  377. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
  378. }
  379. /*! Set intersection filter function for ray packets of size N. */
  380. virtual void setIntersectionFilterFunctionN (RTCFilterFunctionN filterN);
  381. /*! Set occlusion filter function for ray packets of size N. */
  382. virtual void setOcclusionFilterFunctionN (RTCFilterFunctionN filterN);
  383. /* Enables argument version of intersection or occlusion filter function. */
  384. virtual void enableFilterFunctionFromArguments (bool enable) {
  385. argumentFilterEnabled = enable;
  386. }
  387. /*! for instances only */
  388. public:
  389. /*! Sets the instanced scene */
  390. virtual void setInstancedScene(const Ref<Scene>& scene) {
  391. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
  392. }
  393. /*! Sets the instanced scenes */
  394. virtual void setInstancedScenes(const RTCScene* scenes, size_t numScenes) {
  395. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
  396. }
  397. /*! Sets transformation of the instance */
  398. virtual void setTransform(const AffineSpace3fa& transform, unsigned int timeStep) {
  399. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
  400. }
  401. /*! Sets transformation of the instance */
  402. virtual void setQuaternionDecomposition(const AffineSpace3ff& qd, unsigned int timeStep) {
  403. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
  404. }
  405. /*! Returns the transformation of the instance */
  406. virtual AffineSpace3fa getTransform(float time) {
  407. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
  408. }
  409. /*! Returns the transformation of the instance */
  410. virtual AffineSpace3fa getTransform(size_t instance, float time) {
  411. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
  412. }
  413. /*! for user geometries only */
  414. public:
  415. /*! Set bounds function. */
  416. virtual void setBoundsFunction (RTCBoundsFunction bounds, void* userPtr) {
  417. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
  418. }
  419. /*! Set intersect function for ray packets of size N. */
  420. virtual void setIntersectFunctionN (RTCIntersectFunctionN intersect) {
  421. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
  422. }
  423. /*! Set occlusion function for ray packets of size N. */
  424. virtual void setOccludedFunctionN (RTCOccludedFunctionN occluded) {
  425. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
  426. }
  427. /*! Set point query function. */
  428. void setPointQueryFunction(RTCPointQueryFunction func);
  429. /*! returns number of time segments */
  430. __forceinline unsigned numTimeSegments () const {
  431. return numTimeSteps-1;
  432. }
  433. public:
  434. virtual PrimInfo createPrimRefArray(PrimRef* prims, const range<size_t>& r, size_t k, unsigned int geomID) const {
  435. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"createPrimRefArray not implemented for this geometry");
  436. }
  437. PrimInfo createPrimRefArray(mvector<PrimRef>& prims, const range<size_t>& r, size_t k, unsigned int geomID) const {
  438. return createPrimRefArray(prims.data(),r,k,geomID);
  439. }
  440. PrimInfo createPrimRefArray(avector<PrimRef>& prims, const range<size_t>& r, size_t k, unsigned int geomID) const {
  441. return createPrimRefArray(prims.data(),r,k,geomID);
  442. }
  443. virtual PrimInfo createPrimRefArray(mvector<PrimRef>& prims, mvector<SubGridBuildData>& sgrids, const range<size_t>& r, size_t k, unsigned int geomID) const {
  444. return createPrimRefArray(prims,r,k,geomID);
  445. }
  446. virtual PrimInfo createPrimRefArrayMB(mvector<PrimRef>& prims, size_t itime, const range<size_t>& r, size_t k, unsigned int geomID) const {
  447. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"createPrimRefMBArray not implemented for this geometry");
  448. }
  449. /*! Calculates the PrimRef over the complete time interval */
  450. virtual PrimInfo createPrimRefArrayMB(PrimRef* prims, const BBox1f& t0t1, const range<size_t>& r, size_t k, unsigned int geomID) const {
  451. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"createPrimRefMBArray not implemented for this geometry");
  452. }
  453. PrimInfo createPrimRefArrayMB(mvector<PrimRef>& prims, const BBox1f& t0t1, const range<size_t>& r, size_t k, unsigned int geomID) const {
  454. return createPrimRefArrayMB(prims.data(),t0t1,r,k,geomID);
  455. }
  456. PrimInfo createPrimRefArrayMB(avector<PrimRef>& prims, const BBox1f& t0t1, const range<size_t>& r, size_t k, unsigned int geomID) const {
  457. return createPrimRefArrayMB(prims.data(),t0t1,r,k,geomID);
  458. }
  459. virtual PrimInfoMB createPrimRefMBArray(mvector<PrimRefMB>& prims, const BBox1f& t0t1, const range<size_t>& r, size_t k, unsigned int geomID) const {
  460. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"createPrimRefMBArray not implemented for this geometry");
  461. }
  462. virtual PrimInfoMB createPrimRefMBArray(mvector<PrimRefMB>& prims, mvector<SubGridBuildData>& sgrids, const BBox1f& t0t1, const range<size_t>& r, size_t k, unsigned int geomID) const {
  463. return createPrimRefMBArray(prims,t0t1,r,k,geomID);
  464. }
  465. virtual LinearSpace3fa computeAlignedSpace(const size_t primID) const {
  466. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"computeAlignedSpace not implemented for this geometry");
  467. }
  468. virtual LinearSpace3fa computeAlignedSpaceMB(const size_t primID, const BBox1f time_range) const {
  469. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"computeAlignedSpace not implemented for this geometry");
  470. }
  471. virtual Vec3fa computeDirection(unsigned int primID) const {
  472. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"computeDirection not implemented for this geometry");
  473. }
  474. virtual Vec3fa computeDirection(unsigned int primID, size_t time) const {
  475. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"computeDirection not implemented for this geometry");
  476. }
  477. virtual BBox3fa vbounds(size_t primID) const {
  478. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"vbounds not implemented for this geometry");
  479. }
  480. virtual BBox3fa vbounds(const LinearSpace3fa& space, size_t primID) const {
  481. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"vbounds not implemented for this geometry");
  482. }
  483. virtual BBox3fa vbounds(const Vec3fa& ofs, const float scale, const float r_scale0, const LinearSpace3fa& space, size_t i, size_t itime = 0) const {
  484. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"vbounds not implemented for this geometry");
  485. }
  486. virtual LBBox3fa vlinearBounds(size_t primID, const BBox1f& time_range) const {
  487. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"vlinearBounds not implemented for this geometry");
  488. }
  489. virtual LBBox3fa vlinearBounds(size_t primID, const BBox1f& time_range, const SubGridBuildData * const sgrids) const {
  490. return vlinearBounds(primID,time_range);
  491. }
  492. virtual LBBox3fa vlinearBounds(const LinearSpace3fa& space, size_t primID, const BBox1f& time_range) const {
  493. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"vlinearBounds not implemented for this geometry");
  494. }
  495. virtual LBBox3fa vlinearBounds(const Vec3fa& ofs, const float scale, const float r_scale0, const LinearSpace3fa& space, size_t primID, const BBox1f& time_range) const {
  496. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"vlinearBounds not implemented for this geometry");
  497. }
  498. public:
  499. __forceinline bool hasIntersectionFilter() const { return intersectionFilterN != nullptr; }
  500. __forceinline bool hasOcclusionFilter() const { return occlusionFilterN != nullptr; }
  501. public:
  502. Device* device; //!< device this geometry belongs to
  503. void* userPtr; //!< user pointer
  504. unsigned int numPrimitives; //!< number of primitives of this geometry
  505. unsigned int numTimeSteps; //!< number of time steps
  506. float fnumTimeSegments; //!< number of time segments (precalculation)
  507. BBox1f time_range; //!< motion blur time range
  508. unsigned int mask; //!< for masking out geometry
  509. unsigned int modCounter_ = 1; //!< counter for every modification - used to rebuild scenes when geo is modified
  510. struct {
  511. GType gtype : 8; //!< geometry type
  512. GSubType gsubtype : 8; //!< geometry subtype
  513. RTCBuildQuality quality : 3; //!< build quality for geometry
  514. unsigned state : 2;
  515. bool enabled : 1; //!< true if geometry is enabled
  516. bool argumentFilterEnabled : 1; //!< true if argument filter functions are enabled for this geometry
  517. };
  518. RTCFilterFunctionN intersectionFilterN;
  519. RTCFilterFunctionN occlusionFilterN;
  520. RTCPointQueryFunction pointQueryFunc;
  521. };
  522. }