55# SPDX-License-Identifier: MIT 
66# ---------------------------------------------------------------------------- 
77import  copy 
8- import  os 
8+ from  os . path   import   exists ,  join ,  dirname ,  basename ,  splitext 
99import  sys 
1010import  numpy  as  np 
1111import  open3d  as  o3d 
1212# pylint: disable-next=unused-import 
13+ from  open3d .visualization .tensorboard_plugin  import  summary   # noqa 
1314from  open3d .visualization .tensorboard_plugin .util  import  to_dict_batch 
1415from  torch .utils .tensorboard  import  SummaryWriter 
1516
1617BASE_LOGDIR  =  "demo_logs/pytorch/" 
17- MODEL_DIR  =  os .path .join (
18-     os .path .dirname (os .path .dirname (os .path .dirname (
19-         os .path .realpath (__file__ )))), "test_data" , "monkey" )
18+ MODEL_PATH  =  o3d .data .MonkeyModel ().path 
2019
2120
2221def  small_scale (run_name = "small_scale" ):
2322    """Basic demo with cube and cylinder with normals and colors. 
2423    """ 
25-     logdir  =  os . path . join (BASE_LOGDIR , run_name )
24+     logdir  =  join (BASE_LOGDIR , run_name )
2625    writer  =  SummaryWriter (logdir )
2726
2827    cube  =  o3d .geometry .TriangleMesh .create_box (1 , 2 , 4 , create_uv_map = True )
@@ -45,7 +44,7 @@ def property_reference(run_name="property_reference"):
4544    """Produces identical visualization to small_scale, but does not store 
4645    repeated properties of ``vertex_positions`` and ``vertex_normals``. 
4746    """ 
48-     logdir  =  os . path . join (BASE_LOGDIR , run_name )
47+     logdir  =  join (BASE_LOGDIR , run_name )
4948    writer  =  SummaryWriter (logdir )
5049
5150    cube  =  o3d .geometry .TriangleMesh .create_box (1 , 2 , 4 , create_uv_map = True )
@@ -79,7 +78,7 @@ def large_scale(n_steps=16,
7978    """Generate a large scale summary. Geometry resolution increases linearly 
8079    with step. Each element in a batch is painted a different color. 
8180    """ 
82-     logdir  =  os . path . join (BASE_LOGDIR , run_name )
81+     logdir  =  join (BASE_LOGDIR , run_name )
8382    writer  =  SummaryWriter (logdir )
8483    colors  =  []
8584    for  k  in  range (batch_size ):
@@ -116,14 +115,13 @@ def large_scale(n_steps=16,
116115                      max_outputs = batch_size )
117116
118117
119- def  with_material (model_dir = MODEL_DIR ):
118+ def  with_material (model_path = MODEL_PATH ):
120119    """Read an obj model from a directory and write as a TensorBoard summary. 
121120    """ 
122-     model_name  =  os .path .basename (model_dir )
123-     logdir  =  os .path .join (BASE_LOGDIR , model_name )
124-     model_path  =  os .path .join (model_dir , model_name  +  ".obj" )
125-     model  =  o3d .t .geometry .TriangleMesh .from_legacy (
126-         o3d .io .read_triangle_mesh (model_path ))
121+     model_dir  =  dirname (model_path )
122+     model_name  =  splitext (basename (model_path ))[0 ]
123+     logdir  =  join (BASE_LOGDIR , model_name )
124+     model  =  o3d .t .io .read_triangle_mesh (model_path )
127125    summary_3d  =  {
128126        "vertex_positions" : model .vertex .positions ,
129127        "vertex_normals" : model .vertex .normals ,
@@ -134,8 +132,8 @@ def with_material(model_dir=MODEL_DIR):
134132    names_to_o3dprop  =  {"ao" : "ambient_occlusion" }
135133
136134    for  texture  in  ("albedo" , "normal" , "ao" , "metallic" , "roughness" ):
137-         texture_file  =  os . path . join (model_dir , texture  +  ".png" )
138-         if  os . path . exists (texture_file ):
135+         texture_file  =  join (model_dir , texture  +  ".png" )
136+         if  exists (texture_file ):
139137            texture  =  names_to_o3dprop .get (texture , texture )
140138            summary_3d .update ({
141139                ("material_texture_map_"  +  texture ):
@@ -149,11 +147,11 @@ def with_material(model_dir=MODEL_DIR):
149147
150148
151149def  demo_scene ():
152-     """Write the demo_scene.py example showing rich PBR materials as a summary 
150+     """Write the demo_scene.py example showing rich PBR materials as a summary.  
153151    """ 
154152    import  demo_scene 
155153    geoms  =  demo_scene .create_scene ()
156-     writer  =  SummaryWriter (os . path . join (BASE_LOGDIR , 'demo_scene' ))
154+     writer  =  SummaryWriter (join (BASE_LOGDIR , 'demo_scene' ))
157155    for  geom_data  in  geoms :
158156        geom  =  geom_data ["geometry" ]
159157        summary_3d  =  {}
0 commit comments