Octree.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright (C) 2009-2022, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include <Tests/Framework/Framework.h>
  6. #include <AnKi/Scene/Octree.h>
  7. namespace anki {
  8. ANKI_TEST(Scene, Octree)
  9. {
  10. HeapAllocator<U8> alloc(allocAligned, nullptr);
  11. // Fuzzy
  12. #if 0
  13. {
  14. Octree octree(alloc);
  15. octree.init(Vec3(-100.0f), Vec3(100.0f), 4);
  16. OrthographicFrustum frustum(-200.0f, 200.0f, -200.0f, 200.0f, 200.0f, -200.0f);
  17. frustum.resetTransform(Transform::getIdentity());
  18. const U ITERATION_COUNT = 1000;
  19. Array<OctreePlaceable, ITERATION_COUNT> placeables;
  20. std::vector<U32> placed;
  21. for(U i = 0; i < ITERATION_COUNT; ++i)
  22. {
  23. F32 min = randRange(-100.0f, 100.0f - 1.0f);
  24. F32 max = randRange(min + 1.0f, 100.0f);
  25. Aabb volume(Vec4(Vec3(min), 0.0f), Vec4(Vec3(max), 0.0f));
  26. I mode = rand() % 3;
  27. if(mode == 0)
  28. {
  29. // Place
  30. placeables[i].m_userData = &placeables[i];
  31. octree.place(volume, &placeables[i], true);
  32. placed.push_back(i);
  33. }
  34. else if(mode == 1 && placed.size() > 0)
  35. {
  36. // Remove
  37. octree.remove(placeables[placed.back()]);
  38. placed.pop_back();
  39. }
  40. else if(placed.size() > 0)
  41. {
  42. // Gather
  43. // Reset the placed
  44. for(U32 idx : placed)
  45. {
  46. placeables[idx].reset();
  47. }
  48. DynamicArrayAuto<void*> arr(alloc);
  49. octree.gatherVisible(frustum, 0, nullptr, nullptr, arr);
  50. ANKI_TEST_EXPECT_EQ(arr.getSize(), placed.size());
  51. for(U32 idx : placed)
  52. {
  53. Bool found = false;
  54. for(void* placeable : arr)
  55. {
  56. if(&placeables[idx] == static_cast<OctreePlaceable*>(placeable))
  57. {
  58. found = true;
  59. break;
  60. }
  61. }
  62. ANKI_TEST_EXPECT_EQ(found, true);
  63. }
  64. }
  65. }
  66. // Remove all
  67. while(!placed.empty())
  68. {
  69. octree.remove(placeables[placed.back()]);
  70. placed.pop_back();
  71. }
  72. }
  73. #endif
  74. }
  75. } // end namespace anki