rtcBuildBVH.3embree3 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. .TH "rtcBuildBVH" "3" "" "" "Embree Ray Tracing Kernels 3"
  2. .SS NAME
  3. .IP
  4. .nf
  5. \f[C]
  6. rtcBuildBVH\ \-\ builds\ a\ BVH
  7. \f[]
  8. .fi
  9. .SS SYNOPSIS
  10. .IP
  11. .nf
  12. \f[C]
  13. #include\ <embree3/rtcore.h>
  14. struct\ RTC_ALIGN(32)\ RTCBuildPrimitive
  15. {
  16. \ \ float\ lower_x,\ lower_y,\ lower_z;\
  17. \ \ unsigned\ int\ geomID;
  18. \ \ float\ upper_x,\ upper_y,\ upper_z;
  19. \ \ unsigned\ int\ primID;
  20. };
  21. typedef\ void*\ (*RTCCreateNodeFunction)\ (
  22. \ \ RTCThreadLocalAllocator\ allocator,
  23. \ \ unsigned\ int\ childCount,
  24. \ \ void*\ userPtr
  25. );
  26. typedef\ void\ (*RTCSetNodeChildrenFunction)\ (
  27. \ \ void*\ nodePtr,
  28. \ \ void**\ children,
  29. \ \ unsigned\ int\ childCount,
  30. \ \ void*\ userPtr
  31. );
  32. typedef\ void\ (*RTCSetNodeBoundsFunction)\ (
  33. \ \ void*\ nodePtr,
  34. \ \ const\ struct\ RTCBounds**\ bounds,
  35. \ \ unsigned\ int\ childCount,
  36. \ \ void*\ userPtr
  37. );
  38. typedef\ void*\ (*RTCCreateLeafFunction)\ (
  39. \ \ RTCThreadLocalAllocator\ allocator,
  40. \ \ const\ struct\ RTCBuildPrimitive*\ primitives,
  41. \ \ size_t\ primitiveCount,
  42. \ \ void*\ userPtr
  43. );
  44. typedef\ void\ (*RTCSplitPrimitiveFunction)\ (
  45. \ \ const\ struct\ RTCBuildPrimitive*\ primitive,
  46. \ \ unsigned\ int\ dimension,
  47. \ \ float\ position,
  48. \ \ struct\ RTCBounds*\ leftBounds,
  49. \ \ struct\ RTCBounds*\ rightBounds,
  50. \ \ void*\ userPtr
  51. );
  52. typedef\ bool\ (*RTCProgressMonitorFunction)(
  53. \ \ void*\ userPtr,\ double\ n
  54. );
  55. enum\ RTCBuildFlags
  56. {
  57. \ \ RTC_BUILD_FLAG_NONE,
  58. \ \ RTC_BUILD_FLAG_DYNAMIC
  59. };
  60. struct\ RTCBuildArguments
  61. {
  62. \ \ size_t\ byteSize;
  63. \ \ enum\ RTCBuildQuality\ buildQuality;
  64. \ \ enum\ RTCBuildFlags\ buildFlags;
  65. \ \ unsigned\ int\ maxBranchingFactor;
  66. \ \ unsigned\ int\ maxDepth;
  67. \ \ unsigned\ int\ sahBlockSize;
  68. \ \ unsigned\ int\ minLeafSize;
  69. \ \ unsigned\ int\ maxLeafSize;
  70. \ \ float\ traversalCost;
  71. \ \ float\ intersectionCost;
  72. \ \ RTCBVH\ bvh;
  73. \ \ struct\ RTCBuildPrimitive*\ primitives;
  74. \ \ size_t\ primitiveCount;
  75. \ \ size_t\ primitiveArrayCapacity;
  76. \ \
  77. \ \ RTCCreateNodeFunction\ createNode;
  78. \ \ RTCSetNodeChildrenFunction\ setNodeChildren;
  79. \ \ RTCSetNodeBoundsFunction\ setNodeBounds;
  80. \ \ RTCCreateLeafFunction\ createLeaf;
  81. \ \ RTCSplitPrimitiveFunction\ splitPrimitive;
  82. \ \ RTCProgressMonitorFunction\ buildProgress;
  83. \ \ void*\ userPtr;
  84. };
  85. struct\ RTCBuildArguments\ rtcDefaultBuildArguments();
  86. void*\ rtcBuildBVH(
  87. \ \ const\ struct\ RTCBuildArguments*\ args
  88. );
  89. \f[]
  90. .fi
  91. .SS DESCRIPTION
  92. .PP
  93. The \f[C]rtcBuildBVH\f[] function can be used to build a BVH in a
  94. user\-defined format over arbitrary primitives.
  95. All arguments to the function are provided through the
  96. \f[C]RTCBuildArguments\f[] structure.
  97. The first member of that structure must be set to the size of the
  98. structure in bytes (\f[C]bytesSize\f[] member) which allows future
  99. extensions of the structure.
  100. It is recommended to initialize the build arguments structure using the
  101. \f[C]rtcDefaultBuildArguments\f[] function.
  102. .PP
  103. The \f[C]rtcBuildBVH\f[] function gets passed the BVH to build
  104. (\f[C]bvh\f[] member), the array of primitives (\f[C]primitives\f[]
  105. member), the capacity of that array (\f[C]primitiveArrayCapacity\f[]
  106. member), the number of primitives stored inside the array
  107. (\f[C]primitiveCount\f[] member), callback function pointers, and a
  108. user\-defined pointer (\f[C]userPtr\f[] member) that is passed to all
  109. callback functions when invoked.
  110. The \f[C]primitives\f[] array can be freed by the application after the
  111. BVH is built.
  112. All callback functions are typically called from multiple threads, thus
  113. their implementation must be thread\-safe.
  114. .PP
  115. Four callback functions must be registered, which are invoked during
  116. build to create BVH nodes (\f[C]createNode\f[] member), to set the
  117. pointers to all children (\f[C]setNodeChildren\f[] member), to set the
  118. bounding boxes of all children (\f[C]setNodeBounds\f[] member), and to
  119. create a leaf node (\f[C]createLeaf\f[] member).
  120. .PP
  121. The function pointer to the primitive split function
  122. (\f[C]splitPrimitive\f[] member) may be \f[C]NULL\f[], however, then no
  123. spatial splitting in high quality mode is possible.
  124. The function pointer used to report the build progress
  125. (\f[C]buildProgress\f[] member) is optional and may also be
  126. \f[C]NULL\f[].
  127. .PP
  128. Further, some build settings are passed to configure the BVH build.
  129. Using the build quality settings (\f[C]buildQuality\f[] member), one can
  130. select between a faster, low quality build which is good for dynamic
  131. scenes, and a standard quality build for static scenes.
  132. One can also specify the desired maximum branching factor of the BVH
  133. (\f[C]maxBranchingFactor\f[] member), the maximum depth the BVH should
  134. have (\f[C]maxDepth\f[] member), the block size for the SAH heuristic
  135. (\f[C]sahBlockSize\f[] member), the minimum and maximum leaf size
  136. (\f[C]minLeafSize\f[] and \f[C]maxLeafSize\f[] member), and the
  137. estimated costs of one traversal step and one primitive intersection
  138. (\f[C]traversalCost\f[] and \f[C]intersectionCost\f[] members).
  139. When enabling the \f[C]RTC_BUILD_FLAG_DYNAMIC\f[] build flags
  140. (\f[C]buildFlags\f[] member), re\-build performance for dynamic scenes
  141. is improved at the cost of higher memory requirements.
  142. .PP
  143. To spatially split primitives in high quality mode, the builder needs
  144. extra space at the end of the build primitive array to store splitted
  145. primitives.
  146. The total capacity of the build primitive array is passed using the
  147. \f[C]primitiveArrayCapacity\f[] member, and should be about twice the
  148. number of primitives when using spatial splits.
  149. .PP
  150. The \f[C]RTCCreateNodeFunc\f[] and \f[C]RTCCreateLeafFunc\f[] callbacks
  151. are passed a thread local allocator object that should be used for fast
  152. allocation of nodes using the \f[C]rtcThreadLocalAlloc\f[] function.
  153. We strongly recommend using this allocation mechanism, as alternative
  154. approaches like standard \f[C]malloc\f[] can be over 10× slower.
  155. The allocator object passed to the create callbacks may be used only
  156. inside the current thread.
  157. Memory allocated using \f[C]rtcThreadLocalAlloc\f[] is automatically
  158. freed when the \f[C]RTCBVH\f[] object is deleted.
  159. If you use your own memory allocation scheme you have to free the memory
  160. yourself when the \f[C]RTCBVH\f[] object is no longer used.
  161. .PP
  162. The \f[C]RTCCreateNodeFunc\f[] callback additionally gets the number of
  163. children for this node in the range from 2 to
  164. \f[C]maxBranchingFactor\f[] (\f[C]childCount\f[] argument).
  165. .PP
  166. The \f[C]RTCSetNodeChildFunc\f[] callback function gets a pointer to the
  167. node as input (\f[C]nodePtr\f[] argument), an array of pointers to the
  168. children (\f[C]childPtrs\f[] argument), and the size of this array
  169. (\f[C]childCount\f[] argument).
  170. .PP
  171. The \f[C]RTCSetNodeBoundsFunc\f[] callback function gets a pointer to
  172. the node as input (\f[C]nodePtr\f[] argument), an array of pointers to
  173. the bounding boxes of the children (\f[C]bounds\f[] argument), and the
  174. size of this array (\f[C]childCount\f[] argument).
  175. .PP
  176. The \f[C]RTCCreateLeafFunc\f[] callback additionally gets an array of
  177. primitives as input (\f[C]primitives\f[] argument), and the size of this
  178. array (\f[C]primitiveCount\f[] argument).
  179. The callback should read the \f[C]geomID\f[] and \f[C]primID\f[] members
  180. from the passed primitives to construct the leaf.
  181. .PP
  182. The \f[C]RTCSplitPrimitiveFunc\f[] callback is invoked in high quality
  183. mode to split a primitive (\f[C]primitive\f[] argument) at the specified
  184. position (\f[C]position\f[] argument) and dimension (\f[C]dimension\f[]
  185. argument).
  186. The callback should return bounds of the clipped left and right parts of
  187. the primitive (\f[C]leftBounds\f[] and \f[C]rightBounds\f[] arguments).
  188. .PP
  189. The \f[C]RTCProgressMonitorFunction\f[] callback function is called with
  190. the estimated completion rate \f[C]n\f[] in the range [0, 1].
  191. Returning \f[C]true\f[] from the callback lets the build continue;
  192. returning \f[C]false\f[] cancels the build.
  193. .SS EXIT STATUS
  194. .PP
  195. On failure an error code is set that can be queried using
  196. \f[C]rtcGetDeviceError\f[].
  197. .SS SEE ALSO
  198. .PP
  199. [rtcNewBVH]