File: TestVoxelHashMap.cpp

package info (click to toggle)
vecgeom 1.2.8%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 24,016 kB
  • sloc: cpp: 88,803; ansic: 6,888; python: 1,035; sh: 582; sql: 538; makefile: 23
file content (84 lines) | stat: -rw-r--r-- 2,255 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "VecGeom/base/FlatVoxelHashMap.h"
#include "VecGeom/base/Vector3D.h"
#undef NDEBUG
#include <cassert>

using namespace vecgeom;

void testGeneralVersion()
{
  int Nx = 10;
  int Ny = 10;
  int Nz = 10;
  Vector3D<float> lower(-5, -5, -5);
  Vector3D<float> dim(10, 10, 10);

  // a voxel structure mapping to vector of ints per voxel
  FlatVoxelHashMap<int> voxels(lower, dim, Nx, Ny, Nz);

  Vector3D<float> p1(-4.9, -4.9, -4.9);
  assert(voxels.getVoxelKey(p1) == 0);
  Vector3D<float> p3(4.99, 4.99, 4.99);
  assert(voxels.getVoxelKey(p3) == Nx * Ny * Nz - 1);

  int length{0};
  assert(voxels.isOccupied(p1) == false);
  assert(voxels.getProperties(p1, length) == nullptr);
  assert(length == 0);

  voxels.addProperty(p1, 111);
  voxels.addProperty(p1, 112);
  assert(voxels.isOccupied(p1) == true);
  assert(voxels.getProperties(p1, length) != nullptr);
  assert(length == 2);
  auto props = voxels.getProperties(p1, length);
  assert(props[0] == 111);
  assert(props[1] == 112);

  // nearby point in same voxel
  Vector3D<float> p2(-4.85, -4.85, -4.85);
  assert(voxels.isOccupied(p2) == true);
  assert(voxels.getProperties(p2, length) != nullptr);
}

void testScalarVersion()
{
  int Nx = 10;
  int Ny = 10;
  int Nz = 10;
  Vector3D<float> lower(-5, -5, -5);
  Vector3D<float> dim(10, 10, 10);

  // a voxel structure mapping to a single int per voxel
  FlatVoxelHashMap<int, true> voxels(lower, dim, Nx, Ny, Nz);

  Vector3D<float> p1(-4.9, -4.9, -4.9);
  assert(voxels.getVoxelKey(p1) == 0);
  Vector3D<float> p3(4.99, 4.99, 4.99);
  assert(voxels.getVoxelKey(p3) == Nx * Ny * Nz - 1);

  int length{0};
  assert(voxels.isOccupied(p1) == false);
  assert(voxels.getProperties(p1, length) == nullptr);
  assert(length == 0);

  voxels.addProperty(p1, 111);
  assert(voxels.isOccupied(p1) == true);
  assert(voxels.getProperties(p1, length) != nullptr);
  assert(length == 1);
  auto props = voxels.getProperties(p1, length);
  assert(props[0] == 111);

  // nearby point in same voxel
  Vector3D<float> p2(-4.85, -4.85, -4.85);
  assert(voxels.isOccupied(p2) == true);
  assert(voxels.getProperties(p2, length) != nullptr);
}

int main()
{
  testGeneralVersion();
  testScalarVersion();
  std::cout << "test passed\n";
  return 0;
}