Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 93 additions & 13 deletions cpp/cython/CythonSVR_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,27 @@ def test_sphere_center_at_origin(self):
expected_phi_voxels = [2,2,2,2,0,0,0,0]
self.verify_voxels(voxels, expected_radial_voxels, expected_theta_voxels, expected_phi_voxels)

def test_ray_slight_offset_in_XY_plane(self):
ray_origin = np.array([-13.0, -13.0, -13.0])
ray_direction = np.array([1.0, 1.5, 1.0])
min_bound = np.array([-20.0, -20.0, -20.0])
max_bound = np.array([20.0, 20.0, 20.0])
sphere_center = np.array([0.0, 0.0, 0.0])
sphere_max_radius = 10.0
num_radial_sections = 4
num_angular_sections = 4
num_azimuthal_sections = 4
t_begin = 0.0
t_end = 30.0
voxels = CythonSVR.walk_spherical_volume(ray_origin, ray_direction, min_bound, max_bound, num_radial_sections,
num_angular_sections, num_azimuthal_sections, sphere_center,
sphere_max_radius, t_begin, t_end)
expected_radial_voxels = [1, 2, 2, 3, 2, 2, 1]
expected_theta_voxels = [2, 2, 1, 1, 1, 0, 0]
expected_phi_voxels = [2, 2, 2, 2, 2, 0, 0]
self.verify_voxels(voxels, expected_radial_voxels, expected_theta_voxels, expected_phi_voxels)


def test_ray_direction_travels_along_X_axis(self):
ray_origin = np.array([-15.0, 0.0, 0.0])
ray_direction = np.array([1.0, 0.0, 0.0])
Expand All @@ -76,8 +97,8 @@ def test_ray_direction_travels_along_X_axis(self):
num_angular_sections, num_azimuthal_sections, sphere_center,
sphere_max_radius, t_begin, t_end)
expected_radial_voxels = [1,2,3,4,4,3,2,1]
expected_theta_voxels = [4,4,4,4,5,5,5,5]
expected_phi_voxels = [2,2,2,2,3,3,3,3]
expected_theta_voxels = [3,3,3,3,0,0,0,0]
expected_phi_voxels = [1,1,1,1,0,0,0,0]
self.verify_voxels(voxels, expected_radial_voxels, expected_theta_voxels, expected_phi_voxels)

def test_ray_direction_travels_along_Y_axis(self):
Expand All @@ -97,7 +118,7 @@ def test_ray_direction_travels_along_Y_axis(self):
num_angular_sections, num_azimuthal_sections, sphere_center,
sphere_max_radius, t_begin, t_end)
expected_radial_voxels = [1,2,3,4,4,3,2,1]
expected_theta_voxels = [6,6,6,6,7,7,7,7]
expected_theta_voxels = [5,5,5,5,1,1,1,1]
expected_phi_voxels = [0,0,0,0,0,0,0,0]
self.verify_voxels(voxels, expected_radial_voxels, expected_theta_voxels, expected_phi_voxels)

Expand All @@ -119,7 +140,7 @@ def test_ray_direction_travels_along_Z_axis(self):
sphere_max_radius, t_begin, t_end)
expected_radial_voxels = [1,2,3,4,4,3,2,1]
expected_theta_voxels = [0,0,0,0,0,0,0,0]
expected_phi_voxels = [3,3,3,3,0,0,0,0]
expected_phi_voxels = [2,2,2,2,0,0,0,0]
self.verify_voxels(voxels, expected_radial_voxels, expected_theta_voxels, expected_phi_voxels)

def test_ray_parallel_to_XY_plane(self):
Expand All @@ -140,7 +161,7 @@ def test_ray_parallel_to_XY_plane(self):
sphere_max_radius, t_begin, t_end)
expected_radial_voxels = [1,2,3,4,4,3,2,1]
expected_theta_voxels = [2,2,2,2,0,0,0,0]
expected_phi_voxels = [2,2,2,2,3,3,3,3]
expected_phi_voxels = [1,1,1,1,0,0,0,0]
self.verify_voxels(voxels, expected_radial_voxels, expected_theta_voxels, expected_phi_voxels)

def test_ray_parallel_to_XZ_plane(self):
Expand All @@ -150,7 +171,7 @@ def test_ray_parallel_to_XZ_plane(self):
max_bound = np.array([20.0, 20.0, 20.0])
sphere_center = np.array([0.0, 0.0, 0.0])
sphere_max_radius = 10.0
num_radial_sections = 5
num_radial_sections = 4
num_angular_sections = 4
num_azimuthal_sections = 4
t_begin = 0.0
Expand All @@ -159,9 +180,9 @@ def test_ray_parallel_to_XZ_plane(self):
voxels = CythonSVR.walk_spherical_volume(ray_origin, ray_direction, min_bound, max_bound, num_radial_sections,
num_angular_sections, num_azimuthal_sections, sphere_center,
sphere_max_radius, t_begin, t_end)
expected_radial_voxels = [1,2,3,4,5,5,4,3,2,1]
expected_theta_voxels = [2,2,2,2,2,3,3,3,3,3]
expected_phi_voxels = [2,2,2,2,2,0,0,0,0,0]
expected_radial_voxels = [1,2,3,4,4,3,2,1]
expected_theta_voxels = [1,1,1,1,0,0,0,0]
expected_phi_voxels = [2,2,2,2,0,0,0,0]
self.verify_voxels(voxels, expected_radial_voxels, expected_theta_voxels, expected_phi_voxels)

def test_ray_parallel_to_YZ_plane(self):
Expand All @@ -171,7 +192,7 @@ def test_ray_parallel_to_YZ_plane(self):
max_bound = np.array([20.0, 20.0, 20.0])
sphere_center = np.array([0.0, 0.0, 0.0])
sphere_max_radius = 10.0
num_radial_sections = 5
num_radial_sections = 4
num_angular_sections = 4
num_azimuthal_sections = 4
t_begin = 0.0
Expand All @@ -180,11 +201,70 @@ def test_ray_parallel_to_YZ_plane(self):
voxels = CythonSVR.walk_spherical_volume(ray_origin, ray_direction, min_bound, max_bound, num_radial_sections,
num_angular_sections, num_azimuthal_sections, sphere_center,
sphere_max_radius, t_begin, t_end)
expected_radial_voxels = [1,2,3,4,5,5,4,3,2,1]
expected_theta_voxels = [3,3,3,3,3,0,0,0,0,0]
expected_phi_voxels = [3,3,3,3,3,0,0,0,0,0]
expected_radial_voxels = [1,2,3,4,4,3,2,1]
expected_theta_voxels = [2,2,2,2,0,0,0,0]
expected_phi_voxels = [2,2,2,2,0,0,0,0]
self.verify_voxels(voxels, expected_radial_voxels, expected_theta_voxels, expected_phi_voxels)

def test_ray_dir_neg_Y_positive_XZ(self):
ray_origin = np.array([-13.0, 17.0, -15.0])
ray_direction = np.array([1.0, -1.2, 1.3])
min_bound = np.array([-20.0, -20.0, -20.0])
max_bound = np.array([20.0, 20.0, 20.0])
sphere_center = np.array([0.0, 0.0, 0.0])
sphere_max_radius = 10.0
num_radial_sections = 4
num_angular_sections = 4
num_azimuthal_sections = 4
t_begin = 0.0
t_end = 30.0
voxels = CythonSVR.walk_spherical_volume(ray_origin, ray_direction, min_bound, max_bound, num_radial_sections,
num_angular_sections, num_azimuthal_sections, sphere_center,
sphere_max_radius, t_begin, t_end)
expected_radial_voxels = [1, 2, 3, 3, 4, 4, 3, 3, 2, 1]
expected_theta_voxels = [1, 1, 1, 1, 1, 0, 0, 3, 3, 3]
expected_phi_voxels = [2, 2, 2, 1, 1, 0, 0, 0, 0, 0]
self.verify_voxels(voxels, expected_radial_voxels, expected_theta_voxels, expected_phi_voxels)

def test_ray_dir_neg_Z_positive_XY(self):
ray_origin = np.array([-13.0, -12.0, 15.3])
ray_direction = np.array([1.4, 2.0, -1.3])
min_bound = np.array([-20.0, -20.0, -20.0])
max_bound = np.array([20.0, 20.0, 20.0])
sphere_center = np.array([0.0, 0.0, 0.0])
sphere_max_radius = 10.0
num_radial_sections = 4
num_angular_sections = 4
num_azimuthal_sections = 4
t_begin = 0.0
t_end = 30.0
voxels = CythonSVR.walk_spherical_volume(ray_origin, ray_direction, min_bound, max_bound, num_radial_sections,
num_angular_sections, num_azimuthal_sections, sphere_center,
sphere_max_radius, t_begin, t_end)
expected_radial_voxels = [1, 1, 2, 2, 1]
expected_theta_voxels = [2, 1, 1, 0, 0]
expected_phi_voxels = [1, 1, 1, 0, 0]
self.verify_voxels(voxels, expected_radial_voxels, expected_theta_voxels, expected_phi_voxels)

def test_ray_dir_neg_X_positive_YZ(self):
ray_origin = np.array([13.0, -15.0, -15.0])
ray_direction = np.array([-1.0, 1.0, 1.0])
min_bound = np.array([-20.0, -20.0, -20.0])
max_bound = np.array([20.0, 20.0, 20.0])
sphere_center = np.array([0.0, 0.0, 0.0])
sphere_max_radius = 10.0
num_radial_sections = 4
num_angular_sections = 4
num_azimuthal_sections = 4
t_begin = 0.0
t_end = 30.0
voxels = CythonSVR.walk_spherical_volume(ray_origin, ray_direction, min_bound, max_bound, num_radial_sections,
num_angular_sections, num_azimuthal_sections, sphere_center,
sphere_max_radius, t_begin, t_end)
expected_radial_voxels = [1, 2, 3, 3, 4, 4, 3, 2, 1]
expected_theta_voxels = [3, 3, 3, 2, 2, 1, 1, 1, 1]
expected_phi_voxels = [3, 3, 3, 2, 2, 1, 1, 1, 1]
self.verify_voxels(voxels, expected_radial_voxels, expected_theta_voxels, expected_phi_voxels)

if __name__ == '__main__':
unittest.main()
44 changes: 22 additions & 22 deletions cpp/cython/printTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,43 @@
# To verify that the C++ and Cythonized versions both work, this script allows for me to type the inputs once and
# print both tests.

cpp_title = ""
python_title = ""
min_bound = np.array([0.0, 0.0, 0.0])
max_bound = np.array([0.0, 0.0, 0.0])
cpp_title = "RayDirectionNegativeXPositiveYZ"
python_title = "test_ray_dir_neg_X_positive_YZ"
min_bound = np.array([-20.0, -20.0, -20.0])
max_bound = np.array([20.0, 20.0, 20.0])
sphere_center = np.array([0.0,0.0,0.0])
sphere_max_radius = 0.0
num_radial_sections = 0
num_angular_sections = 0
num_azimuthal_sections = 0
ray_origin = np.array([0.0, 0.0, 0.0])
ray_dir = np.array([0.0, 0.0, 0.0])
sphere_max_radius = 10.0
num_radial_sections = 4
num_angular_sections = 4
num_azimuthal_sections = 4
ray_origin = np.array([13.0, -15.0, -15.0])
ray_dir = np.array([-1.0, 1.0, 1.0])
t_begin = 0.0
t_end = 0.0
expected_radial_voxels = str([0, 1, 2, 3])[1:-1]
expected_angular_voxels = str([0, 1, 2, 3])[1:-1]
expected_azimuthal_voxels = str([0, 1, 2, 3])[1:-1]
t_end = 30.0
expected_radial_voxels = str([1,2,3,3,4,4,3,2,1])[1:-1]
expected_angular_voxels = str([3,3,3,2,2,1,1,1,1])[1:-1]
expected_azimuthal_voxels = str([3,3,3,2,2,1,1,1,1])[1:-1]

print("TEST(SphericalCoordinateTraversal, {0}) {{".format(cpp_title))
print(" const BoundVec3 min_bound({0}, {1}, {2});".format(min_bound[0], min_bound[1], min_bound[2]))
print(" const BoundVec3 max_bound({0}, {1}, {2});".format(max_bound[0], max_bound[1], max_bound[2]))
print(" const BoundVec3 sphere_center({0}, {1}, {2});".format(sphere_center[0], sphere_center[1], sphere_center[2]))
print(" const double sphere_max_radius = {0};".format(sphere_max_radius))
print(" const std::size num_radial_sections = {0};".format(num_radial_sections))
print(" const std::size num_angular_sections = {0};".format(num_angular_sections))
print(" const std::size num_azimuthal_sections = {0};".format(num_azimuthal_sections))
print(" const std::size_t num_radial_sections = {0};".format(num_radial_sections))
print(" const std::size_t num_angular_sections = {0};".format(num_angular_sections))
print(" const std::size_t num_azimuthal_sections = {0};".format(num_azimuthal_sections))
print(" const SphericalVoxelGrid grid(min_bound, max_bound, num_radial_sections,")
print(" num_angular_sections, num_azimuthal_sections,")
print(" sphere_center, sphere_max_radius);")
print(" const BoundVec3 ray_origin({0}, {1}, {2});".format(ray_origin[0], ray_origin[1], ray_origin[2]))
print(" const BoundVec3 ray_dir({0}, {1}, {2});".format(ray_dir[0], ray_dir[1], ray_dir[2]))
print(" const FreeVec3 ray_direction({0}, {1}, {2});".format(ray_dir[0], ray_dir[1], ray_dir[2]))
print(" const Ray ray(ray_origin, ray_direction);")
print(" const double t_begin = {0};".format(t_begin))
print(" const double t_end = {0};".format(t_end))
print("\n const auto actual_voxels = sphericalCoordinate(ray, grid, t_begin, t_end);")
print("\n const auto actual_voxels = sphericalCoordinateVoxelTraversal(ray, grid, t_begin, t_end);")
print(" const std::vector<int> expected_radial_voxels = {{{0}}};".format(expected_radial_voxels))
print(" const std::vector<int> expected_angular_voxels = {{{0}}};".format(expected_angular_voxels))
print(" const std::vector<int> expected_azimthual_voxels = {{{0}}};".format(expected_azimuthal_voxels))
print(" const std::vector<int> expected_theta_voxels = {{{0}}};".format(expected_angular_voxels))
print(" const std::vector<int> expected_phi_voxels = {{{0}}};".format(expected_azimuthal_voxels))
print(" expectEqualVoxels(actual_voxels, expected_radial_voxels, expected_theta_voxels, expected_phi_voxels);")
print("}")

Expand All @@ -60,7 +60,7 @@

print(" voxels = CythonSVR.walk_spherical_volume(ray_origin, ray_direction, min_bound, max_bound, num_radial_sections,")
print(" num_angular_sections, num_azimuthal_sections, sphere_center,")
print(" sphere_max_radius, t_begin, t_end")
print(" sphere_max_radius, t_begin, t_end)")
print(" expected_radial_voxels = [{0}]".format(expected_radial_voxels))
print(" expected_theta_voxels = [{0}]".format(expected_angular_voxels))
print(" expected_phi_voxels = [{0}]".format(expected_azimuthal_voxels))
Expand Down
Loading