Skip to content

Commit

Permalink
CONVERT TRIANGLES
Browse files Browse the repository at this point in the history
  • Loading branch information
tf17270 committed Mar 13, 2024
1 parent 2e6f682 commit d317142
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lyceanem/raycasting/rayfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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])
Expand All @@ -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

Expand Down
Binary file added lyceanem/tests/data/triangle_type_array_ref.npy
Binary file not shown.
24 changes: 24 additions & 0 deletions lyceanem/tests/test_ray_functions.py
Original file line number Diff line number Diff line change
@@ -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"])



0 comments on commit d317142

Please sign in to comment.