geometry.h 27 KB

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