diff --git a/docs/examples/04_time_domain_channel_modelling.py b/docs/examples/04_time_domain_channel_modelling.py index c8178be..ac98bb3 100644 --- a/docs/examples/04_time_domain_channel_modelling.py +++ b/docs/examples/04_time_domain_channel_modelling.py @@ -13,8 +13,7 @@ """ import numpy as np -import open3d as o3d - +import meshio # %% # Frequency and Mesh Resolution # ------------------------------ @@ -57,38 +56,25 @@ # rotation_vector1 = np.radians(np.asarray([90.0, 0.0, 0.0])) rotation_vector2 = np.radians(np.asarray([0.0, 0.0, -90.0])) -transmit_horn_structure = GF.open3drotate( - transmit_horn_structure, - o3d.geometry.TriangleMesh.get_rotation_matrix_from_xyz(rotation_vector1), -) -transmit_horn_structure = GF.open3drotate( - transmit_horn_structure, - o3d.geometry.TriangleMesh.get_rotation_matrix_from_xyz(rotation_vector2), -) -transmit_horn_structure.translate(np.asarray([2.695, 0, 0]), relative=True) -transmitting_antenna_surface_coords = GF.open3drotate( - transmitting_antenna_surface_coords, - o3d.geometry.TriangleMesh.get_rotation_matrix_from_xyz(rotation_vector1), -) -transmitting_antenna_surface_coords = GF.open3drotate( - transmitting_antenna_surface_coords, - o3d.geometry.TriangleMesh.get_rotation_matrix_from_xyz(rotation_vector2), -) -transmitting_antenna_surface_coords.translate(np.asarray([2.695, 0, 0]), relative=True) + + + +transmit_horn_structure = GF.mesh_rotate(transmit_horn_structure, rotation_vector1) +transmit_horn_structure = GF.mesh_rotate(transmit_horn_structure, rotation_vector2) +transmit_horn_structure = GF.translate_mesh(transmit_horn_structure, np.asarray([2.695, 0, 0])) +transmitting_antenna_surface_coords = GF.mesh_rotate(transmitting_antenna_surface_coords, rotation_vector1) +transmitting_antenna_surface_coords = GF.mesh_rotate(transmitting_antenna_surface_coords, rotation_vector2) +transmitting_antenna_surface_coords = GF.translate_mesh(transmitting_antenna_surface_coords, np.asarray([2.695, 0, 0])) # %% # Position Receiver # ------------------ # rotate the receiving horn to desired orientation and translate to final position. -receive_horn_structure = GF.open3drotate( - receive_horn_structure, - o3d.geometry.TriangleMesh.get_rotation_matrix_from_xyz(rotation_vector1), -) -receive_horn_structure.translate(np.asarray([0, 1.427, 0]), relative=True) -receiving_antenna_surface_coords = GF.open3drotate( - receiving_antenna_surface_coords, - o3d.geometry.TriangleMesh.get_rotation_matrix_from_xyz(rotation_vector1), -) -receiving_antenna_surface_coords.translate(np.asarray([0, 1.427, 0]), relative=True) + + +receive_horn_structure = GF.mesh_rotate(receive_horn_structure, rotation_vector1) +receive_horn_structure = GF.translate_mesh(receive_horn_structure, np.asarray([0, 1.427, 0])) +receiving_antenna_surface_coords = GF.mesh_rotate(receiving_antenna_surface_coords, rotation_vector1) +receiving_antenna_surface_coords = GF.translate_mesh(receiving_antenna_surface_coords, np.asarray([0, 1.427, 0])) # %% # Create Scattering Plate @@ -100,16 +86,11 @@ ) position_vector = np.asarray([29e-3, 0.0, 0]) rotation_vector1 = np.radians(np.asarray([0.0, 90.0, 0.0])) -scatter_points = GF.open3drotate( - scatter_points, - o3d.geometry.TriangleMesh.get_rotation_matrix_from_xyz(rotation_vector1), -) -reflectorplate = GF.open3drotate( - reflectorplate, - o3d.geometry.TriangleMesh.get_rotation_matrix_from_xyz(rotation_vector1), -) -reflectorplate.translate(position_vector, relative=True) -scatter_points.translate(position_vector, relative=True) +scatter_points = GF.mesh_rotate(scatter_points, rotation_vector1) +reflectorplate = GF.mesh_rotate(reflectorplate, rotation_vector1) +reflectorplate = GF.translate_mesh(reflectorplate, position_vector) +scatter_points = GF.translate_mesh(scatter_points, position_vector) + # %% # Specify Reflection Angle @@ -119,15 +100,8 @@ plate_orientation_angle = 45.0 rotation_vector = np.radians(np.asarray([0.0, 0.0, plate_orientation_angle])) -scatter_points = GF.open3drotate( - scatter_points, - o3d.geometry.TriangleMesh.get_rotation_matrix_from_xyz(rotation_vector), -) -reflectorplate = GF.open3drotate( - reflectorplate, - o3d.geometry.TriangleMesh.get_rotation_matrix_from_xyz(rotation_vector), -) - +scatter_points = GF.mesh_rotate(scatter_points, rotation_vector) +reflectorplate = GF.mesh_rotate(reflectorplate, rotation_vector) from lyceanem.base_classes import structures blockers = structures([reflectorplate, receive_horn_structure, transmit_horn_structure]) @@ -138,20 +112,8 @@ # Use open3d function :func:`open3d.visualization.draw_geometries` to visualise the scene and ensure that all the # relavent sources and scatter points are correct. Point normal vectors can be displayed by pressing 'n' while the # window is open. -mesh_frame = o3d.geometry.TriangleMesh.create_coordinate_frame( - size=0.5, origin=[0, 0, 0] -) -o3d.visualization.draw_geometries( - [ - transmitting_antenna_surface_coords, - receiving_antenna_surface_coords, - scatter_points, - reflectorplate, - mesh_frame, - receive_horn_structure, - transmit_horn_structure, - ] -) + + # %% # .. image:: ../_static/03_frequency_domain_channel_model_picture_01.png @@ -183,14 +145,8 @@ rotation_vector = np.radians( np.asarray([0.0, 0.0, plate_orientation_angle + angle_increment]) ) -scatter_points = GF.open3drotate( - scatter_points, - o3d.geometry.TriangleMesh.get_rotation_matrix_from_xyz(rotation_vector), -) -reflectorplate = GF.open3drotate( - reflectorplate, - o3d.geometry.TriangleMesh.get_rotation_matrix_from_xyz(rotation_vector), -) +scatter_points = GF.mesh_rotate(scatter_points, rotation_vector) +reflectorplate = GF.mesh_rotate(reflectorplate, rotation_vector) from tqdm import tqdm @@ -201,14 +157,8 @@ for angle_inc in tqdm(range(len(angle_values))): rotation_vector = np.radians(np.asarray([0.0, 0.0, angle_increment])) - scatter_points = GF.open3drotate( - scatter_points, - o3d.geometry.TriangleMesh.get_rotation_matrix_from_xyz(rotation_vector), - ) - reflectorplate = GF.open3drotate( - reflectorplate, - o3d.geometry.TriangleMesh.get_rotation_matrix_from_xyz(rotation_vector), - ) + scatter_points = GF.mesh_rotate(scatter_points, rotation_vector) + reflectorplate = GF.mesh_rotate(reflectorplate, rotation_vector) blockers = structures( [reflectorplate, transmit_horn_structure, receive_horn_structure] ) diff --git a/docs/examples/05_array_beamforming.py b/docs/examples/05_array_beamforming.py index 32ad779..afc705f 100644 --- a/docs/examples/05_array_beamforming.py +++ b/docs/examples/05_array_beamforming.py @@ -12,7 +12,6 @@ """ import numpy as np -import open3d as o3d # %% # Setting Farfield Resolution and Wavelength @@ -38,16 +37,7 @@ body, array, source_coords = data.exampleUAV(10e9) -# %% -# Visualise the Resultant UAV and Array -# --------------------------------------- -# :func:`open3d.visualization.draw_geometries` can be used to visualise the open3d data -# structures :class:`open3d.geometry.PointCloud` and :class:`open3d.geometry.PointCloud` -mesh_frame = o3d.geometry.TriangleMesh.create_coordinate_frame( - size=0.5, origin=[0, 0, 0] -) -o3d.visualization.draw_geometries([body, array, source_coords, mesh_frame]) # %% # .. image:: ../_static/UAVArraywithPoints.png diff --git a/lyceanem/electromagnetics/beamforming.py b/lyceanem/electromagnetics/beamforming.py index e70c233..be494b4 100644 --- a/lyceanem/electromagnetics/beamforming.py +++ b/lyceanem/electromagnetics/beamforming.py @@ -894,7 +894,7 @@ def MaximumfieldMapDiscrete( @njit(cache=True, nogil=True) -def directivity_transformv2( +def directivity_transform( Etheta, Ephi, az_range=np.linspace(-180.0, 180.0, 19), diff --git a/lyceanem/models/time_domain.py b/lyceanem/models/time_domain.py index d83aba8..a80058f 100644 --- a/lyceanem/models/time_domain.py +++ b/lyceanem/models/time_domain.py @@ -1,8 +1,8 @@ import copy import numpy as np -import open3d as o3d import scipy.constants +import meshio from ..base_types import scattering_t from ..electromagnetics import empropagation as EM @@ -79,10 +79,10 @@ def calculate_scattering( if not multiE: if project_vectors: conformal_E_vectors = EM.calculate_conformalVectors( - desired_E_axis, np.asarray(aperture_coords.normals), antenna_axes + desired_E_axis, np.asarray(aperture_coords.point_data["normals"]), antenna_axes ) else: - if desired_E_axis.shape[0] == np.asarray(aperture_coords.normals).shape[0]: + if desired_E_axis.shape[0] == np.asarray(aperture_coords.point_data["normals"]).shape[0]: conformal_E_vectors = copy.deepcopy(desired_E_axis) else: conformal_E_vectors = np.repeat( @@ -91,7 +91,7 @@ def calculate_scattering( else: if project_vectors: conformal_E_vectors = EM.calculate_conformalVectors( - desired_E_axis, np.asarray(aperture_coords.normals), antenna_axes + desired_E_axis, np.asarray(aperture_coords.point_data["normals"]), antenna_axes ) else: if desired_E_axis.size == 3: @@ -103,7 +103,7 @@ def calculate_scattering( if scattering == 0: # only use the aperture point cloud, no scattering required. - scatter_points = o3d.geometry.PointCloud() + scatter_points = meshio.Mesh(points = np.empty((0,3), dtype=np.float32), cells=[]) unified_model = np.append( np.asarray(aperture_coords.points).astype(np.float32), @@ -111,8 +111,8 @@ def calculate_scattering( axis=0, ) unified_normals = np.append( - np.asarray(aperture_coords.normals).astype(np.float32), - np.asarray(sink_coords.normals).astype(np.float32), + np.asarray(aperture_coords.point_data["normals"]).astype(np.float32), + np.asarray(sink_coords.point_data["normals"]).astype(np.float32), axis=0, ) unified_weights = np.ones((unified_model.shape[0], 3), dtype=np.complex64) @@ -138,13 +138,13 @@ def calculate_scattering( aperture_coords.points ).astype(np.float32)[:, 2] point_informationv2[0:num_sources]["nx"] = np.asarray( - aperture_coords.normals + aperture_coords.point_data["normals"] ).astype(np.float32)[:, 0] point_informationv2[0:num_sources]["ny"] = np.asarray( - aperture_coords.normals + aperture_coords.point_data["normals"] ).astype(np.float32)[:, 1] point_informationv2[0:num_sources]["nz"] = np.asarray( - aperture_coords.normals + aperture_coords.point_data["normals"] ).astype(np.float32)[:, 2] # set position and velocity of sinks point_informationv2[num_sources : (num_sources + num_sinks)]["px"] = np.asarray( @@ -157,13 +157,13 @@ def calculate_scattering( sink_coords.points ).astype(np.float32)[:, 2] point_informationv2[num_sources : (num_sources + num_sinks)]["nx"] = np.asarray( - sink_coords.normals + sink_coords.point_data["normals"] ).astype(np.float32)[:, 0] point_informationv2[num_sources : (num_sources + num_sinks)]["ny"] = np.asarray( - sink_coords.normals + sink_coords.point_data["normals"] ).astype(np.float32)[:, 1] point_informationv2[num_sources : (num_sources + num_sinks)]["nz"] = np.asarray( - sink_coords.normals + sink_coords.point_data["normals"] ).astype(np.float32)[:, 2] point_informationv2[:]["ex"] = unified_weights[:, 0] @@ -191,11 +191,11 @@ def calculate_scattering( ) unified_normals = np.append( np.append( - np.asarray(aperture_coords.normals).astype(np.float32), - np.asarray(sink_coords.normals).astype(np.float32), + np.asarray(aperture_coords.point_data["normals"]).astype(np.float32), + np.asarray(sink_coords.point_data["normals"]).astype(np.float32), axis=0, ), - np.asarray(scatter_points.normals).astype(np.float32), + np.asarray(scatter_points.point_data["normals"]).astype(np.float32), axis=0, ) unified_weights = np.ones((unified_model.shape[0], 3), dtype=np.complex64) @@ -224,13 +224,13 @@ def calculate_scattering( aperture_coords.points ).astype(np.float32)[:, 2] point_informationv2[0:num_sources]["nx"] = np.asarray( - aperture_coords.normals + aperture_coords.point_data["normals"] ).astype(np.float32)[:, 0] point_informationv2[0:num_sources]["ny"] = np.asarray( - aperture_coords.normals + aperture_coords.point_data["normals"] ).astype(np.float32)[:, 1] point_informationv2[0:num_sources]["nz"] = np.asarray( - aperture_coords.normals + aperture_coords.point_data["normals"] ).astype(np.float32)[:, 2] # point_informationv2[0:num_sources]['ex']=unified_weights[0:num_sources,0] # point_informationv2[0:num_sources]['ey']=unified_weights[0:num_sources,1] @@ -249,13 +249,13 @@ def calculate_scattering( # point_informationv2[num_sources:(num_sources+num_sinks)]['vy']=0.0 # point_informationv2[num_sources:(num_sources+num_sinks)]['vz']=0.0 point_informationv2[num_sources : (num_sources + num_sinks)]["nx"] = np.asarray( - sink_coords.normals + sink_coords.point_data["normals"] ).astype(np.float32)[:, 0] point_informationv2[num_sources : (num_sources + num_sinks)]["ny"] = np.asarray( - sink_coords.normals + sink_coords.point_data["normals"] ).astype(np.float32)[:, 1] point_informationv2[num_sources : (num_sources + num_sinks)]["nz"] = np.asarray( - sink_coords.normals + sink_coords.point_data["normals"] ).astype(np.float32)[:, 2] point_informationv2[(num_sources + num_sinks) :]["px"] = np.asarray( scatter_points.points @@ -267,13 +267,13 @@ def calculate_scattering( scatter_points.points ).astype(np.float32)[:, 2] point_informationv2[(num_sources + num_sinks) :]["nx"] = np.asarray( - scatter_points.normals + scatter_points.point_data["normals"] ).astype(np.float32)[:, 0] point_informationv2[(num_sources + num_sinks) :]["ny"] = np.asarray( - scatter_points.normals + scatter_points.point_data["normals"] ).astype(np.float32)[:, 1] point_informationv2[(num_sources + num_sinks) :]["nz"] = np.asarray( - scatter_points.normals + scatter_points.point_data["normals"] ).astype(np.float32)[:, 2] point_informationv2[:]["ex"] = unified_weights[:, 0] point_informationv2[:]["ey"] = unified_weights[:, 1] @@ -305,7 +305,7 @@ def calculate_scattering( for e_inc in range(desired_E_axis.shape[0]): conformal_E_vectors = EM.calculate_conformalVectors( desired_E_axis[e_inc, :], - np.asarray(aperture_coords.normals).astype(np.float32), + np.asarray(aperture_coords.point_data["normals"]).astype(np.float32), ) unified_weights[0:num_sources, :] = conformal_E_vectors #/ num_sources point_informationv2[:]["ex"] = unified_weights[:, 0] @@ -399,7 +399,7 @@ def calculate_scattering( for e_inc in range(desired_E_axis.shape[1]): conformal_E_vectors = EM.calculate_conformalVectors( desired_E_axis[e_inc, :], - np.asarray(aperture_coords.normals).astype(np.float32),antenna_axes + np.asarray(aperture_coords.point_data["normals"]).astype(np.float32),antenna_axes ) for element in range(num_sources): point_informationv2[0:num_sources]["ex"] = 0.0