src.acoustools.Mesh.Convert

 1from acoustools.Utilities import device, DTYPE, BOARD_POSITIONS
 2import acoustools.Constants as Constants
 3
 4import vedo, torch
 5import matplotlib.pyplot as plt
 6import numpy as np
 7
 8from torch import Tensor
 9from vedo import Mesh
10
11from acoustools.Mesh.Load import load_scatterer
12from acoustools.Mesh.Transform import centre_scatterer, scale_to_diameter
13from acoustools.Mesh.Features import get_centres_as_points, get_normals_as_points
14
15
16def mesh_to_board(path:str, compute_areas:bool = True, compute_normals:bool=True, dx:float=0,
17                   dy:float=0,dz:float=0, rotx:float=0, roty:float=0, rotz:float=0, root_path:str="", force:bool=False, flip_normals = True, diameter = 2*BOARD_POSITIONS, centre=True):
18    '''
19    Loads a scatterer as a `vedo` `Mesh` and interprets it as a transducer board with a transducer at each mesh centre
20    :param path: The name of the scatterer to load
21    :param compute_areas: if `True` will call `scatterer.compute_cell_size()`. Default `True`
22    :param compute_normals: if `True` will call `scatterer.compute_normals()`. Default `True`
23    :param dx: Translation in the x direction to apply
24    :param dy: Translation in the y direction to apply
25    :param dz: Translation in the z direction to apply
26    :param rotx: Rotation around the x axis to apply
27    :param roty: Rotation around the y axis to apply
28    :param rotz: Rotation around the z axis to apply
29    :param root_path: The folder containing the file, the scatterer to be loaded will be loaded from `root_path+path`
30    :param flip_normals: If True will flip the normals 
31    :param diameter: Size to scale the mesh to in thr x-axis
32    :return: The `vedo` `Mesh` of the scatterer
33    '''
34    
35    scatterer = load_scatterer(path=path,compute_areas=compute_areas,  compute_normals=compute_normals, 
36                               dx=dx, dy=dy, dz=dz, rotx=rotx, roty=roty, rotz=rotz, root_path=root_path,force=force)
37    
38    if centre: centre_scatterer(scatterer)
39    
40    if diameter is not None: scale_to_diameter(scatterer, diameter)
41    
42    centres = get_centres_as_points(scatterer).squeeze(0).permute(1,0)
43    norms = get_normals_as_points(scatterer).squeeze(0).permute(1,0)  
44    if flip_normals: norms = norms * -1
45
46    return centres, norms
47    
def mesh_to_board( path: str, compute_areas: bool = True, compute_normals: bool = True, dx: float = 0, dy: float = 0, dz: float = 0, rotx: float = 0, roty: float = 0, rotz: float = 0, root_path: str = '', force: bool = False, flip_normals=True, diameter=0.2365, centre=True):
18def mesh_to_board(path:str, compute_areas:bool = True, compute_normals:bool=True, dx:float=0,
19                   dy:float=0,dz:float=0, rotx:float=0, roty:float=0, rotz:float=0, root_path:str="", force:bool=False, flip_normals = True, diameter = 2*BOARD_POSITIONS, centre=True):
20    '''
21    Loads a scatterer as a `vedo` `Mesh` and interprets it as a transducer board with a transducer at each mesh centre
22    :param path: The name of the scatterer to load
23    :param compute_areas: if `True` will call `scatterer.compute_cell_size()`. Default `True`
24    :param compute_normals: if `True` will call `scatterer.compute_normals()`. Default `True`
25    :param dx: Translation in the x direction to apply
26    :param dy: Translation in the y direction to apply
27    :param dz: Translation in the z direction to apply
28    :param rotx: Rotation around the x axis to apply
29    :param roty: Rotation around the y axis to apply
30    :param rotz: Rotation around the z axis to apply
31    :param root_path: The folder containing the file, the scatterer to be loaded will be loaded from `root_path+path`
32    :param flip_normals: If True will flip the normals 
33    :param diameter: Size to scale the mesh to in thr x-axis
34    :return: The `vedo` `Mesh` of the scatterer
35    '''
36    
37    scatterer = load_scatterer(path=path,compute_areas=compute_areas,  compute_normals=compute_normals, 
38                               dx=dx, dy=dy, dz=dz, rotx=rotx, roty=roty, rotz=rotz, root_path=root_path,force=force)
39    
40    if centre: centre_scatterer(scatterer)
41    
42    if diameter is not None: scale_to_diameter(scatterer, diameter)
43    
44    centres = get_centres_as_points(scatterer).squeeze(0).permute(1,0)
45    norms = get_normals_as_points(scatterer).squeeze(0).permute(1,0)  
46    if flip_normals: norms = norms * -1
47
48    return centres, norms

Loads a scatterer as a vedo Mesh and interprets it as a transducer board with a transducer at each mesh centre

Parameters
  • path: The name of the scatterer to load
  • compute_areas: if True will call scatterer.compute_cell_size(). Default True
  • compute_normals: if True will call scatterer.compute_normals(). Default True
  • dx: Translation in the x direction to apply
  • dy: Translation in the y direction to apply
  • dz: Translation in the z direction to apply
  • rotx: Rotation around the x axis to apply
  • roty: Rotation around the y axis to apply
  • rotz: Rotation around the z axis to apply
  • root_path: The folder containing the file, the scatterer to be loaded will be loaded from root_path+path
  • flip_normals: If True will flip the normals
  • diameter: Size to scale the mesh to in thr x-axis
Returns

The vedo Mesh of the scatterer