diff --git a/lyceanem/raycasting/rayfunctions.py b/lyceanem/raycasting/rayfunctions.py index 45c5742..20dcba4 100644 --- a/lyceanem/raycasting/rayfunctions.py +++ b/lyceanem/raycasting/rayfunctions.py @@ -14,6 +14,7 @@ import lyceanem.base_types as base_types import lyceanem.electromagnetics.empropagation as EM from ..utility import math_functions as math_functions +import meshio EPSILON = 1e-6 # how close to zero do we consider zero? example used 1e-7 @@ -670,14 +671,15 @@ def azeltocart(az_data, el_data, radius): def convertTriangles(triangle_object): """ - convert o3d triangle object to ray tracer triangle class + convert meshio.Mesh triangle object to ray tracer triangle class """ if triangle_object == None: triangles = np.empty(0, dtype=base_types.triangle_t) else: - vertices = np.asarray(triangle_object.vertices) - tri_index = np.asarray(triangle_object.triangles) - normals = np.asarray(triangle_object.triangle_normals) + assert triangle_object.cells[0].type == "triangle", "Not a triangle mesh" + + vertices = np.asarray(triangle_object.points) + tri_index = np.asarray(triangle_object.cells[0].data) triangles = np.empty(len(tri_index), dtype=base_types.triangle_t) for idx in range(len(tri_index)): triangles[idx]["v0x"] = np.single(vertices[tri_index[idx, 0], 0]) @@ -689,9 +691,6 @@ def convertTriangles(triangle_object): triangles[idx]["v2x"] = np.single(vertices[tri_index[idx, 2], 0]) triangles[idx]["v2y"] = np.single(vertices[tri_index[idx, 2], 1]) triangles[idx]["v2z"] = np.single(vertices[tri_index[idx, 2], 2]) - # triangles[idx]['normx']=np.single(normals[idx,0]) - # triangles[idx]['normy']=np.single(normals[idx,1]) - # triangles[idx]['normz']=np.single(normals[idx,2]) return triangles diff --git a/lyceanem/tests/data/triangle_type_array_ref.npy b/lyceanem/tests/data/triangle_type_array_ref.npy new file mode 100644 index 0000000..0b35c64 Binary files /dev/null and b/lyceanem/tests/data/triangle_type_array_ref.npy differ diff --git a/lyceanem/tests/test_ray_functions.py b/lyceanem/tests/test_ray_functions.py new file mode 100644 index 0000000..8cb4322 --- /dev/null +++ b/lyceanem/tests/test_ray_functions.py @@ -0,0 +1,24 @@ +from ..raycasting import rayfunctions as RF +import numpy as np +import pytest +import lyceanem.base_types as base_types + +import meshio + +def test_convertTriangles(): + reference = np.load("data/triangle_type_array_ref.npy") + mesh = meshio.read("data/receive_horn.ply") + triangles = RF.convertTriangles(mesh) + for i in range(triangles.size): + assert np.allclose(triangles[i]["v0x"], reference[i]["v0x"]) + assert np.allclose(triangles[i]["v0y"], reference[i]["v0y"]) + assert np.allclose(triangles[i]["v0z"], reference[i]["v0z"]) + assert np.allclose(triangles[i]["v1x"], reference[i]["v1x"]) + assert np.allclose(triangles[i]["v1y"], reference[i]["v1y"]) + assert np.allclose(triangles[i]["v1z"], reference[i]["v1z"]) + assert np.allclose(triangles[i]["v2x"], reference[i]["v2x"]) + assert np.allclose(triangles[i]["v2y"], reference[i]["v2y"]) + assert np.allclose(triangles[i]["v2z"], reference[i]["v2z"]) + + +