conquer3d 0.7.7__tar.gz → 0.7.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. {conquer3d-0.7.7/conquer3d.egg-info → conquer3d-0.7.8}/PKG-INFO +1 -1
  2. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/_C.so +0 -0
  3. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/data_structure/bvh.cu +40 -101
  4. conquer3d-0.7.8/conquer3d/csrc/data_structure/bvh_traverse.cuh +82 -0
  5. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/data_structure/mesh_bvh.cu +42 -131
  6. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/data_structure/triangle_mesh.cu +78 -142
  7. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/ops/flood_fill.cu +5 -126
  8. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/ops/flood_fill_cf.cu +35 -178
  9. conquer3d-0.7.8/conquer3d/csrc/ops/flood_fill_common.cuh +129 -0
  10. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/ops/mc.cu +4 -108
  11. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/ops/mtg.cu +4 -103
  12. conquer3d-0.7.8/conquer3d/csrc/ops/voxel_classify.cuh +136 -0
  13. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/primitive/gs_aabb.cu +125 -181
  14. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/primitive/pgs_aabb.cu +79 -114
  15. {conquer3d-0.7.7 → conquer3d-0.7.8/conquer3d.egg-info}/PKG-INFO +1 -1
  16. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d.egg-info/SOURCES.txt +3 -0
  17. {conquer3d-0.7.7 → conquer3d-0.7.8}/pyproject.toml +1 -1
  18. {conquer3d-0.7.7 → conquer3d-0.7.8}/LICENSE +0 -0
  19. {conquer3d-0.7.7 → conquer3d-0.7.8}/MANIFEST.in +0 -0
  20. {conquer3d-0.7.7 → conquer3d-0.7.8}/README.md +0 -0
  21. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/_C.pyi +0 -0
  22. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/__init__.py +0 -0
  23. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/conversion/__init__.py +0 -0
  24. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/conversion/grid.py +0 -0
  25. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/conversion/mesh.py +0 -0
  26. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/conversion/tmesh.py +0 -0
  27. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/creation/__init__.py +0 -0
  28. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/creation/triangle_creation.py +0 -0
  29. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/binds/creation/triangle_creation.cpp +0 -0
  30. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/binds/data_structure/bvh.cpp +0 -0
  31. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/binds/data_structure/grid.cpp +0 -0
  32. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/binds/data_structure/gs_bvh.cpp +0 -0
  33. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/binds/data_structure/kdtree.cpp +0 -0
  34. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/binds/data_structure/mesh_bvh.cpp +0 -0
  35. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/binds/data_structure/pgs_bvh.cpp +0 -0
  36. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/binds/data_structure/triangle_mesh.cpp +0 -0
  37. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/binds/data_structure/zcurve.cpp +0 -0
  38. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/binds/ops/chamfer.cpp +0 -0
  39. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/binds/ops/dc.cpp +0 -0
  40. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/binds/ops/dmc.cpp +0 -0
  41. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/binds/ops/flood_fill.cpp +0 -0
  42. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/binds/ops/flood_fill_cf.cpp +0 -0
  43. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/binds/ops/mc.cpp +0 -0
  44. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/binds/ops/mca.cpp +0 -0
  45. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/binds/ops/mt.cpp +0 -0
  46. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/binds/ops/mtg.cpp +0 -0
  47. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/binds/ops/volint.cpp +0 -0
  48. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/binds/primitive/gs.cpp +0 -0
  49. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/binds/primitive/pgs.cpp +0 -0
  50. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/binds/primitive/ray.cpp +0 -0
  51. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/binds/primitive/triangle.cpp +0 -0
  52. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/check.h +0 -0
  53. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/constants.h +0 -0
  54. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/creation/triangle_creation.h +0 -0
  55. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/data_structure/bvh.h +0 -0
  56. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/data_structure/grid.cu +0 -0
  57. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/data_structure/grid.h +0 -0
  58. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/data_structure/gs_bvh.h +0 -0
  59. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/data_structure/kdtree.cu +0 -0
  60. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/data_structure/kdtree.h +0 -0
  61. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/data_structure/mesh_bvh.h +0 -0
  62. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/data_structure/pgs_bvh.h +0 -0
  63. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/data_structure/triangle_mesh.h +0 -0
  64. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/data_structure/zcurve.cu +0 -0
  65. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/data_structure/zcurve.h +0 -0
  66. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/maths/f2x2.h +0 -0
  67. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/maths/f3x1.h +0 -0
  68. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/maths/f3x3.h +0 -0
  69. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/maths/f3x4.h +0 -0
  70. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/maths/f4x1.h +0 -0
  71. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/maths/f4x4.h +0 -0
  72. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/maths/maths.h +0 -0
  73. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/maths/ops.h +0 -0
  74. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/maths/qef.h +0 -0
  75. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/ops/chamfer.cu +0 -0
  76. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/ops/chamfer.h +0 -0
  77. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/ops/dc.cu +0 -0
  78. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/ops/dc.h +0 -0
  79. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/ops/dc_data.h +0 -0
  80. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/ops/dmc.cu +0 -0
  81. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/ops/dmc.h +0 -0
  82. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/ops/dmc_data.h +0 -0
  83. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/ops/flood_fill.h +0 -0
  84. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/ops/flood_fill_cf.h +0 -0
  85. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/ops/mc.h +0 -0
  86. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/ops/mc_data.h +0 -0
  87. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/ops/mca.cu +0 -0
  88. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/ops/mca.h +0 -0
  89. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/ops/mca_data.h +0 -0
  90. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/ops/mt.cu +0 -0
  91. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/ops/mt.h +0 -0
  92. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/ops/mt_data.h +0 -0
  93. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/ops/mtg.h +0 -0
  94. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/ops/mtg_data.h +0 -0
  95. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/ops/volint.cu +0 -0
  96. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/ops/volint.h +0 -0
  97. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/primitive/aabb.h +0 -0
  98. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/primitive/edge.h +0 -0
  99. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/primitive/gs.cu +0 -0
  100. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/primitive/gs.h +0 -0
  101. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/primitive/gs_math.cuh +0 -0
  102. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/primitive/pgs.cu +0 -0
  103. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/primitive/pgs.h +0 -0
  104. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/primitive/pgs_math.cuh +0 -0
  105. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/primitive/ray.h +0 -0
  106. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/primitive/triangle.h +0 -0
  107. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/csrc/pybind.cpp +0 -0
  108. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/data/__init__.py +0 -0
  109. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/data/assets/__init__.py +0 -0
  110. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/data/assets/common.py +0 -0
  111. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/data/assets/iphigenia.py +0 -0
  112. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/data/collate/__init__.py +0 -0
  113. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/data/collate/mesh.py +0 -0
  114. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/data/collate/sparse_tensor.py +0 -0
  115. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/data/dataset/__init__.py +0 -0
  116. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/data/dataset/base_mesh.py +0 -0
  117. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/data/dataset/digit3d.py +0 -0
  118. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/data/dataset/digit3dmv.py +0 -0
  119. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/data/dataset/mesh.py +0 -0
  120. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/data/dataset/redwood.py +0 -0
  121. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/data/transform/__init__.py +0 -0
  122. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/data/transform/base.py +0 -0
  123. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/data/transform/ops.py +0 -0
  124. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/data/transform/vertex.py +0 -0
  125. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/data_structure/__init__.py +0 -0
  126. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/data_structure/bmesh.py +0 -0
  127. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/data_structure/grid.py +0 -0
  128. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/data_structure/sort.py +0 -0
  129. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/io/__init__.py +0 -0
  130. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/io/obj.py +0 -0
  131. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/io/off.py +0 -0
  132. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/io/ply.py +0 -0
  133. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/ops/__init__.py +0 -0
  134. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/ops/delaunay_triangulation.py +0 -0
  135. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/ops/diff_marching_cubes.py +0 -0
  136. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/ops/diff_marching_tetrahedra_grid.py +0 -0
  137. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/ops/distance.py +0 -0
  138. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/ops/dpsr.py +0 -0
  139. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/ops/dual_contouring.py +0 -0
  140. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/ops/dual_marching_cubes.py +0 -0
  141. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/ops/hermite.py +0 -0
  142. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/ops/marching_cubes.py +0 -0
  143. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/ops/marching_cubes_asymptotic.py +0 -0
  144. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/ops/marching_tetrahedra.py +0 -0
  145. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/ops/marching_tetrahedra_grid.py +0 -0
  146. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/ops/volint.py +0 -0
  147. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/primitive/__init__.py +0 -0
  148. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/primitive/gs.py +0 -0
  149. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d/primitive/pgs.py +0 -0
  150. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d.egg-info/dependency_links.txt +0 -0
  151. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d.egg-info/not-zip-safe +0 -0
  152. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d.egg-info/requires.txt +0 -0
  153. {conquer3d-0.7.7 → conquer3d-0.7.8}/conquer3d.egg-info/top_level.txt +0 -0
  154. {conquer3d-0.7.7 → conquer3d-0.7.8}/setup.cfg +0 -0
  155. {conquer3d-0.7.7 → conquer3d-0.7.8}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: conquer3d
3
- Version: 0.7.7
3
+ Version: 0.7.8
4
4
  Summary: Geometric Cuda Tool Box
5
5
  Author-email: Do Hoang Khoi <khoido8899@gmail.com>
6
6
  License-Expression: MIT
@@ -5,6 +5,7 @@
5
5
 
6
6
  #include "bvh.h"
7
7
  #include "zcurve.h"
8
+ #include "bvh_traverse.cuh"
8
9
  #include "../primitive/ray.h"
9
10
 
10
11
  #include <thrust/device_vector.h>
@@ -434,41 +435,19 @@ __global__ void query_bvh_kernel(
434
435
  float3 q_max = query_maxs[q_idx];
435
436
 
436
437
  // The local thread stack
437
- int stack[BVH_STACK_SIZE];
438
- int stack_ptr = 0;
439
-
440
- // Push the Root Node (Index 0) to start
441
- stack[0] = 0;
442
-
443
- while (stack_ptr >= 0)
444
- {
445
- int node_idx = stack[stack_ptr--];
446
-
447
- if (aabb::test_aabb_overlap(q_min, q_max, bvh_aabb_mins[node_idx], bvh_aabb_maxs[node_idx]))
448
- {
449
- if (node_idx >= num_objects - 1)
450
- {
451
- int leaf_idx = node_idx - (num_objects - 1);
452
- int original_obj_id = object_ids[leaf_idx];
453
-
454
- uint64_t write_idx = (uint64_t)atomicAdd((unsigned long long int*)hit_counter, 1ULL);
455
-
456
- if (write_idx < max_capacity) {
457
- out_query_ids[write_idx] = q_idx;
458
- out_object_ids[write_idx] = original_obj_id;
459
- }
460
- }
461
- else
462
- {
463
- if (stack_ptr + 2 < BVH_STACK_SIZE)
464
- {
465
- int2 children = bvh_children[node_idx];
466
- stack[++stack_ptr] = children.x;
467
- stack[++stack_ptr] = children.y;
468
- }
438
+ bvh::traverse(num_objects, bvh_children,
439
+ [&] (int node_idx) {
440
+ return aabb::test_aabb_overlap(q_min, q_max,
441
+ bvh_aabb_mins[node_idx], bvh_aabb_maxs[node_idx]);
442
+ },
443
+ [&] (int leaf_idx) {
444
+ uint64_t write_idx = (uint64_t)atomicAdd((unsigned long long int*)hit_counter, 1ULL);
445
+ if (write_idx < max_capacity) {
446
+ out_query_ids[write_idx] = q_idx;
447
+ out_object_ids[write_idx] = object_ids[leaf_idx];
469
448
  }
470
- }
471
- }
449
+ return true;
450
+ });
472
451
  }
473
452
 
474
453
  void query(
@@ -545,42 +524,22 @@ __global__ void query_self_bvh_kernel(
545
524
  float3 q_max = bvh_aabb_maxs[node_offset + leaf_idx];
546
525
  int original_q_id = object_ids[leaf_idx];
547
526
 
548
- int stack[BVH_STACK_SIZE];
549
- int stack_ptr = 0;
550
- stack[0] = 0;
551
-
552
- while (stack_ptr >= 0)
553
- {
554
- int node_idx = stack[stack_ptr--];
555
-
556
- if (aabb::test_aabb_overlap(q_min, q_max, bvh_aabb_mins[node_idx], bvh_aabb_maxs[node_idx]))
557
- {
558
- if (node_idx >= num_objects - 1)
559
- {
560
- int other_leaf_idx = node_idx - (num_objects - 1);
561
- int original_obj_id = object_ids[other_leaf_idx];
562
-
563
- if (original_q_id < original_obj_id)
564
- {
565
- uint64_t write_idx = (uint64_t)atomicAdd((unsigned long long int*)hit_counter, 1ULL);
566
-
567
- if (write_idx < max_capacity) {
568
- out_query_ids[write_idx] = original_q_id;
569
- out_object_ids[write_idx] = original_obj_id;
570
- }
571
- }
572
- }
573
- else
574
- {
575
- if (stack_ptr + 2 < BVH_STACK_SIZE)
576
- {
577
- int2 children = bvh_children[node_idx];
578
- stack[++stack_ptr] = children.x;
579
- stack[++stack_ptr] = children.y;
527
+ bvh::traverse(num_objects, bvh_children,
528
+ [&] (int node_idx) {
529
+ return aabb::test_aabb_overlap(q_min, q_max,
530
+ bvh_aabb_mins[node_idx], bvh_aabb_maxs[node_idx]);
531
+ },
532
+ [&] (int other_leaf_idx) {
533
+ int original_obj_id = object_ids[other_leaf_idx];
534
+ if (original_q_id < original_obj_id) {
535
+ uint64_t write_idx = (uint64_t)atomicAdd((unsigned long long int*)hit_counter, 1ULL);
536
+ if (write_idx < max_capacity) {
537
+ out_query_ids[write_idx] = original_q_id;
538
+ out_object_ids[write_idx] = original_obj_id;
580
539
  }
581
540
  }
582
- }
583
- }
541
+ return true;
542
+ });
584
543
  }
585
544
 
586
545
  void query_self(
@@ -655,40 +614,20 @@ __global__ void query_ray_bvh_kernel(
655
614
 
656
615
  Ray ray(ray_origins[q_idx], ray_dirs[q_idx]);
657
616
 
658
- int stack[BVH_STACK_SIZE];
659
- int stack_ptr = 0;
660
- stack[0] = 0;
661
-
662
- while (stack_ptr >= 0)
663
- {
664
- int node_idx = stack[stack_ptr--];
665
- float t_hit;
666
-
667
- if (ray.is_intersect_aabb(bvh_aabb_mins[node_idx], bvh_aabb_maxs[node_idx], t_hit))
668
- {
669
- if (node_idx >= num_objects - 1)
670
- {
671
- int leaf_idx = node_idx - (num_objects - 1);
672
- int original_obj_id = object_ids[leaf_idx];
673
-
674
- uint64_t write_idx = (uint64_t)atomicAdd((unsigned long long int*)hit_counter, 1ULL);
675
-
676
- if (write_idx < max_capacity) {
677
- out_query_ids[write_idx] = q_idx;
678
- out_object_ids[write_idx] = original_obj_id;
679
- }
680
- }
681
- else
682
- {
683
- if (stack_ptr + 2 < BVH_STACK_SIZE)
684
- {
685
- int2 children = bvh_children[node_idx];
686
- stack[++stack_ptr] = children.x;
687
- stack[++stack_ptr] = children.y;
688
- }
617
+ bvh::traverse(num_objects, bvh_children,
618
+ [&] (int node_idx) {
619
+ float t_hit;
620
+ return ray.is_intersect_aabb(bvh_aabb_mins[node_idx],
621
+ bvh_aabb_maxs[node_idx], t_hit);
622
+ },
623
+ [&] (int leaf_idx) {
624
+ uint64_t write_idx = (uint64_t)atomicAdd((unsigned long long int*)hit_counter, 1ULL);
625
+ if (write_idx < max_capacity) {
626
+ out_query_ids[write_idx] = q_idx;
627
+ out_object_ids[write_idx] = object_ids[leaf_idx];
689
628
  }
690
- }
691
- }
629
+ return true;
630
+ });
692
631
  }
693
632
 
694
633
  void query_ray(
@@ -0,0 +1,82 @@
1
+ /**
2
+ * @file bvh_traverse.cuh
3
+ * @brief Shared stack-based descent over a Linear BVH.
4
+ *
5
+ * @details Every query in the library walks the hierarchy the same way: pop a node, ask
6
+ * whether it is worth entering, and either visit it as a leaf or push its two children.
7
+ * Only the node test and the leaf action differ. Writing that loop once and passing those
8
+ * two steps as functors keeps the traversal -- including the stack bound, the leaf index
9
+ * arithmetic and the overflow guard -- in a single place, so a fix lands everywhere rather
10
+ * than in one of eighteen copies.
11
+ *
12
+ * The functors are device lambdas and are fully inlined, so the generated code matches the
13
+ * hand-written loop it replaces.
14
+ *
15
+ * @note Two query shapes are deliberately *not* expressed here and remain hand-written:
16
+ * nearest-point search, which pushes the closer child last and prunes each child against
17
+ * the running best distance, and the Fast Winding Number descent, which does work on the
18
+ * branch where the node test *fails* rather than skipping it. Forcing either into this
19
+ * interface would obscure it for no gain.
20
+ */
21
+
22
+ #ifndef BVH_TRAVERSE_CUH
23
+ #define BVH_TRAVERSE_CUH
24
+
25
+ #include "../constants.h"
26
+ #include <cuda_runtime.h>
27
+
28
+ namespace bvh
29
+ {
30
+ /**
31
+ * @brief Walks the hierarchy, visiting every leaf the node test admits.
32
+ *
33
+ * @tparam NodeTest Callable `bool(int node_idx)`; return false to prune the subtree.
34
+ * @tparam LeafVisit Callable `bool(int leaf_idx)` receiving the leaf's slot in
35
+ * `object_ids`; return false to abandon the traversal, which is how
36
+ * any-hit queries stop at their first result.
37
+ *
38
+ * @param[in] num_objects Number of primitives $N$; internal nodes occupy $[0, N-1)$ and
39
+ * leaves $[N-1, 2N-1)$.
40
+ * @param[in] children Device array of $N - 1$ child index pairs.
41
+ * @param[in] node_test Predicate deciding whether to enter a node.
42
+ * @param[in] leaf_visit Action performed at an admitted leaf.
43
+ *
44
+ * @warning The stack holds `BVH_STACK_SIZE` entries in local memory. A hierarchy deeper
45
+ * than that silently drops the remaining children rather than failing, so a
46
+ * pathologically unbalanced tree can under-report. Morton ordering keeps real trees
47
+ * far shallower than the bound.
48
+ */
49
+ template <class NodeTest, class LeafVisit>
50
+ __device__ __forceinline__ void traverse(
51
+ const int num_objects,
52
+ const int2 *__restrict__ children,
53
+ NodeTest node_test,
54
+ LeafVisit leaf_visit)
55
+ {
56
+ int stack[BVH_STACK_SIZE];
57
+ int stack_ptr = 0;
58
+ stack[0] = 0;
59
+
60
+ while (stack_ptr >= 0)
61
+ {
62
+ const int node_idx = stack[stack_ptr--];
63
+
64
+ if (!node_test(node_idx))
65
+ continue;
66
+
67
+ if (node_idx >= num_objects - 1)
68
+ {
69
+ if (!leaf_visit(node_idx - (num_objects - 1)))
70
+ return;
71
+ }
72
+ else if (stack_ptr + 2 < BVH_STACK_SIZE)
73
+ {
74
+ const int2 c = children[node_idx];
75
+ if (c.x >= 0) stack[++stack_ptr] = c.x;
76
+ if (c.y >= 0) stack[++stack_ptr] = c.y;
77
+ }
78
+ }
79
+ }
80
+ }
81
+
82
+ #endif // BVH_TRAVERSE_CUH
@@ -4,6 +4,7 @@
4
4
  */
5
5
 
6
6
  #include "mesh_bvh.h"
7
+ #include "bvh_traverse.cuh"
7
8
  #include "../primitive/triangle.h"
8
9
  #include "../primitive/edge.h"
9
10
  #include <thrust/device_vector.h>
@@ -239,42 +240,19 @@ __global__ void filter_ray_triangle_intersections_kernel(
239
240
  Ray ray2(p, ray_dir, 0.0f);
240
241
 
241
242
  int hit_count = 0;
242
- int stack[BVH_STACK_SIZE];
243
- int stack_ptr = 0;
244
- stack[0] = 0;
245
-
246
- while (stack_ptr >= 0)
247
- {
248
- int node_idx = stack[stack_ptr--];
249
-
250
- float t_hit_aabb;
251
- if (!ray2.is_intersect_aabb(bvh_aabb_mins[node_idx], bvh_aabb_maxs[node_idx], t_hit_aabb))
252
- {
253
- continue;
254
- }
255
-
256
- if (node_idx >= num_objects - 1)
257
- {
258
- int tri_id = object_ids[node_idx - (num_objects - 1)];
259
- int3 tri = triangles[tri_id];
243
+ bvh::traverse(num_objects, bvh_children,
244
+ [&] (int node_idx) {
245
+ float t_hit_aabb;
246
+ return ray2.is_intersect_aabb(bvh_aabb_mins[node_idx],
247
+ bvh_aabb_maxs[node_idx], t_hit_aabb);
248
+ },
249
+ [&] (int leaf_idx) {
250
+ int3 tri = triangles[object_ids[leaf_idx]];
260
251
  Triangle T(vertices[tri.x], vertices[tri.y], vertices[tri.z]);
261
-
262
252
  float t_hit, u, v;
263
- if (T.is_intersect_ray(ray2, t_hit, u, v))
264
- {
265
- hit_count++;
266
- }
267
- }
268
- else
269
- {
270
- if (stack_ptr + 2 < BVH_STACK_SIZE)
271
- {
272
- int2 children = bvh_children[node_idx];
273
- stack[++stack_ptr] = children.x;
274
- stack[++stack_ptr] = children.y;
275
- }
276
- }
277
- }
253
+ if (T.is_intersect_ray(ray2, t_hit, u, v)) hit_count++;
254
+ return true;
255
+ });
278
256
 
279
257
  return (hit_count % 2 == 1) ? -1.0f : 1.0f;
280
258
  }
@@ -934,41 +912,18 @@ __global__ void query_voxel_mesh_bvh_kernel(
934
912
  float3 q_min = query_mins[q_idx];
935
913
  float3 q_max = query_maxs[q_idx];
936
914
 
937
- int stack[BVH_STACK_SIZE];
938
- int stack_ptr = 0;
939
- stack[0] = 0;
940
-
941
915
  bool is_intersect = false;
942
-
943
- while (stack_ptr >= 0)
944
- {
945
- int node_idx = stack[stack_ptr--];
946
-
947
- if (!aabb::test_aabb_overlap(q_min, q_max, bvh_aabb_mins[node_idx], bvh_aabb_maxs[node_idx]))
948
- continue;
949
-
950
- if (node_idx >= num_objects - 1)
951
- {
952
- int tri_id = object_ids[node_idx - (num_objects - 1)];
953
- int3 tri = triangles[tri_id];
916
+ bvh::traverse(num_objects, bvh_children,
917
+ [&] (int node_idx) {
918
+ return aabb::test_aabb_overlap(q_min, q_max,
919
+ bvh_aabb_mins[node_idx], bvh_aabb_maxs[node_idx]);
920
+ },
921
+ [&] (int leaf_idx) {
922
+ int3 tri = triangles[object_ids[leaf_idx]];
954
923
  Triangle T(vertices[tri.x], vertices[tri.y], vertices[tri.z]);
955
-
956
- if (T.is_voxel_intersect(q_min, q_max))
957
- {
958
- is_intersect = true;
959
- break;
960
- }
961
- }
962
- else
963
- {
964
- if (stack_ptr + 2 < BVH_STACK_SIZE)
965
- {
966
- int2 children = bvh_children[node_idx];
967
- stack[++stack_ptr] = children.x;
968
- stack[++stack_ptr] = children.y;
969
- }
970
- }
971
- }
924
+ if (T.is_voxel_intersect(q_min, q_max)) { is_intersect = true; return false; }
925
+ return true;
926
+ });
972
927
 
973
928
  out_intersect[q_idx] = is_intersect;
974
929
  }
@@ -1066,40 +1021,18 @@ __global__ void count_active_voxels_mesh_bvh_kernel(
1066
1021
  q_min.y + voxel_size.y,
1067
1022
  q_min.z + voxel_size.z);
1068
1023
 
1069
- int stack[BVH_STACK_SIZE];
1070
- int stack_ptr = 0;
1071
- stack[0] = 0;
1072
1024
  bool is_intersect = false;
1073
-
1074
- while (stack_ptr >= 0)
1075
- {
1076
- int node_idx = stack[stack_ptr--];
1077
-
1078
- if (!aabb::test_aabb_overlap(q_min, q_max, bvh_aabb_mins[node_idx], bvh_aabb_maxs[node_idx]))
1079
- continue;
1080
-
1081
- if (node_idx >= num_objects - 1)
1082
- {
1083
- int tri_id = object_ids[node_idx - (num_objects - 1)];
1084
- int3 tri = triangles[tri_id];
1025
+ bvh::traverse(num_objects, bvh_children,
1026
+ [&] (int node_idx) {
1027
+ return aabb::test_aabb_overlap(q_min, q_max,
1028
+ bvh_aabb_mins[node_idx], bvh_aabb_maxs[node_idx]);
1029
+ },
1030
+ [&] (int leaf_idx) {
1031
+ int3 tri = triangles[object_ids[leaf_idx]];
1085
1032
  Triangle T(vertices[tri.x], vertices[tri.y], vertices[tri.z]);
1086
-
1087
- if (T.is_voxel_intersect(q_min, q_max))
1088
- {
1089
- is_intersect = true;
1090
- break;
1091
- }
1092
- }
1093
- else
1094
- {
1095
- if (stack_ptr + 2 < BVH_STACK_SIZE)
1096
- {
1097
- int2 children = bvh_children[node_idx];
1098
- stack[++stack_ptr] = children.x;
1099
- stack[++stack_ptr] = children.y;
1100
- }
1101
- }
1102
- }
1033
+ if (T.is_voxel_intersect(q_min, q_max)) { is_intersect = true; return false; }
1034
+ return true;
1035
+ });
1103
1036
 
1104
1037
  if (is_intersect) {
1105
1038
  atomicAdd(active_counter, 1ULL);
@@ -1166,40 +1099,18 @@ __global__ void collect_active_voxels_mesh_bvh_kernel(
1166
1099
  q_min.y + voxel_size.y,
1167
1100
  q_min.z + voxel_size.z);
1168
1101
 
1169
- int stack[BVH_STACK_SIZE];
1170
- int stack_ptr = 0;
1171
- stack[0] = 0;
1172
1102
  bool is_intersect = false;
1173
-
1174
- while (stack_ptr >= 0)
1175
- {
1176
- int node_idx = stack[stack_ptr--];
1177
-
1178
- if (!aabb::test_aabb_overlap(q_min, q_max, bvh_aabb_mins[node_idx], bvh_aabb_maxs[node_idx]))
1179
- continue;
1180
-
1181
- if (node_idx >= num_objects - 1)
1182
- {
1183
- int tri_id = object_ids[node_idx - (num_objects - 1)];
1184
- int3 tri = triangles[tri_id];
1103
+ bvh::traverse(num_objects, bvh_children,
1104
+ [&] (int node_idx) {
1105
+ return aabb::test_aabb_overlap(q_min, q_max,
1106
+ bvh_aabb_mins[node_idx], bvh_aabb_maxs[node_idx]);
1107
+ },
1108
+ [&] (int leaf_idx) {
1109
+ int3 tri = triangles[object_ids[leaf_idx]];
1185
1110
  Triangle T(vertices[tri.x], vertices[tri.y], vertices[tri.z]);
1186
-
1187
- if (T.is_voxel_intersect(q_min, q_max))
1188
- {
1189
- is_intersect = true;
1190
- break;
1191
- }
1192
- }
1193
- else
1194
- {
1195
- if (stack_ptr + 2 < BVH_STACK_SIZE)
1196
- {
1197
- int2 children = bvh_children[node_idx];
1198
- stack[++stack_ptr] = children.x;
1199
- stack[++stack_ptr] = children.y;
1200
- }
1201
- }
1202
- }
1111
+ if (T.is_voxel_intersect(q_min, q_max)) { is_intersect = true; return false; }
1112
+ return true;
1113
+ });
1203
1114
 
1204
1115
  if (is_intersect) {
1205
1116
  unsigned long long write_idx = atomicAdd(active_counter, 1ULL);