gel.scripts.create_cell_surf_normals_mesh
Compute nodal cell surface normals, save as .vtk file
For all arguments, run create_cell_surf_normals_mesh --help
Uses Tensorflow (must be installed) to compute nodal normals on cell surface mesh, saves in provided directory.
1"""Compute nodal cell surface normals, save as .vtk file 2 3For all arguments, run `create_cell_surf_normals_mesh --help` 4 5Uses Tensorflow (must be installed) to compute nodal normals on cell 6surface mesh, saves in provided directory. 7""" 8import sys 9if "pdoc" not in sys.modules: 10 from tensorflow_graphics.geometry.representation.mesh.normals import vertex_normals 11import argparse 12import os 13import numpy as np 14import meshio 15 16 17def create_cell_surf_normals_mesh(cell_mesh_file, dest_dir): 18 """Creates mesh .vtk file with nodal normals. 19 20 * `cell_mesh_file`: str path to mesh file with downsampled, 21 centered cell surface (for instance, an .stl) 22 * `dest_dir`: str path to directory in which to create new mesh file 23 24 Side-effects: writes `cell_surf_with_normal.vtk` under `dest_dir` 25 """ 26 cell_surf_mesh = meshio.read(cell_mesh_file) 27 28 cell_vertices = cell_surf_mesh.points 29 cell_conn = cell_surf_mesh.cells[0].data 30 31 # Outward normal 32 cell_normals = -vertex_normals(cell_vertices, cell_conn) 33 34 cell_surf_mesh.point_data["n"] = cell_normals.numpy() 35 36 cell_surf_mesh.write(os.path.join(dest_dir, "cell_surf_with_normal.vtk")) 37 38 39def create_cell_surf_normals_mesh_main(): 40 """The function invoked by the command. Parses arguments and passes 41 to `create_cell_surf_with_normals_mesh`. 42 """ 43 parser = argparse.ArgumentParser( 44 description="Uses Tensorflow (must be installed) to compute nodal normals on cell surface mesh, saves in provided directory." 45 ) 46 parser.add_argument( 47 "-c", 48 type=str, 49 metavar="CELL_MESH_FILE", 50 help="input cell mesh file" 51 ) 52 parser.add_argument( 53 "-d", 54 type=str, 55 metavar="DEST_DIR", 56 help="directory in which cell_surf_with_normal.vtk will be " 57 "placed" 58 ) 59 args = parser.parse_args() 60 61 create_cell_surf_normals_mesh(args.c, args.d) 62 63 64if __name__=="__main__": 65 create_cell_surf_normals_mesh_main()
def
create_cell_surf_normals_mesh(cell_mesh_file, dest_dir):
18def create_cell_surf_normals_mesh(cell_mesh_file, dest_dir): 19 """Creates mesh .vtk file with nodal normals. 20 21 * `cell_mesh_file`: str path to mesh file with downsampled, 22 centered cell surface (for instance, an .stl) 23 * `dest_dir`: str path to directory in which to create new mesh file 24 25 Side-effects: writes `cell_surf_with_normal.vtk` under `dest_dir` 26 """ 27 cell_surf_mesh = meshio.read(cell_mesh_file) 28 29 cell_vertices = cell_surf_mesh.points 30 cell_conn = cell_surf_mesh.cells[0].data 31 32 # Outward normal 33 cell_normals = -vertex_normals(cell_vertices, cell_conn) 34 35 cell_surf_mesh.point_data["n"] = cell_normals.numpy() 36 37 cell_surf_mesh.write(os.path.join(dest_dir, "cell_surf_with_normal.vtk"))
Creates mesh .vtk file with nodal normals.
cell_mesh_file: str path to mesh file with downsampled, centered cell surface (for instance, an .stl)dest_dir: str path to directory in which to create new mesh file
Side-effects: writes cell_surf_with_normal.vtk under dest_dir
def
create_cell_surf_normals_mesh_main():
40def create_cell_surf_normals_mesh_main(): 41 """The function invoked by the command. Parses arguments and passes 42 to `create_cell_surf_with_normals_mesh`. 43 """ 44 parser = argparse.ArgumentParser( 45 description="Uses Tensorflow (must be installed) to compute nodal normals on cell surface mesh, saves in provided directory." 46 ) 47 parser.add_argument( 48 "-c", 49 type=str, 50 metavar="CELL_MESH_FILE", 51 help="input cell mesh file" 52 ) 53 parser.add_argument( 54 "-d", 55 type=str, 56 metavar="DEST_DIR", 57 help="directory in which cell_surf_with_normal.vtk will be " 58 "placed" 59 ) 60 args = parser.parse_args() 61 62 create_cell_surf_normals_mesh(args.c, args.d)
The function invoked by the command. Parses arguments and passes
to create_cell_surf_with_normals_mesh.