5
5
# SPDX-License-Identifier: MIT
6
6
# ----------------------------------------------------------------------------
7
7
import copy
8
- import os
8
+ from os . path import exists , join , dirname , basename , splitext
9
9
import sys
10
10
import numpy as np
11
11
import open3d as o3d
12
12
# pylint: disable-next=unused-import
13
+ from open3d .visualization .tensorboard_plugin import summary # noqa
13
14
from open3d .visualization .tensorboard_plugin .util import to_dict_batch
14
15
from torch .utils .tensorboard import SummaryWriter
15
16
16
17
BASE_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
20
19
21
20
22
21
def small_scale (run_name = "small_scale" ):
23
22
"""Basic demo with cube and cylinder with normals and colors.
24
23
"""
25
- logdir = os . path . join (BASE_LOGDIR , run_name )
24
+ logdir = join (BASE_LOGDIR , run_name )
26
25
writer = SummaryWriter (logdir )
27
26
28
27
cube = o3d .geometry .TriangleMesh .create_box (1 , 2 , 4 , create_uv_map = True )
@@ -45,7 +44,7 @@ def property_reference(run_name="property_reference"):
45
44
"""Produces identical visualization to small_scale, but does not store
46
45
repeated properties of ``vertex_positions`` and ``vertex_normals``.
47
46
"""
48
- logdir = os . path . join (BASE_LOGDIR , run_name )
47
+ logdir = join (BASE_LOGDIR , run_name )
49
48
writer = SummaryWriter (logdir )
50
49
51
50
cube = o3d .geometry .TriangleMesh .create_box (1 , 2 , 4 , create_uv_map = True )
@@ -79,7 +78,7 @@ def large_scale(n_steps=16,
79
78
"""Generate a large scale summary. Geometry resolution increases linearly
80
79
with step. Each element in a batch is painted a different color.
81
80
"""
82
- logdir = os . path . join (BASE_LOGDIR , run_name )
81
+ logdir = join (BASE_LOGDIR , run_name )
83
82
writer = SummaryWriter (logdir )
84
83
colors = []
85
84
for k in range (batch_size ):
@@ -116,14 +115,13 @@ def large_scale(n_steps=16,
116
115
max_outputs = batch_size )
117
116
118
117
119
- def with_material (model_dir = MODEL_DIR ):
118
+ def with_material (model_path = MODEL_PATH ):
120
119
"""Read an obj model from a directory and write as a TensorBoard summary.
121
120
"""
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 )
127
125
summary_3d = {
128
126
"vertex_positions" : model .vertex .positions ,
129
127
"vertex_normals" : model .vertex .normals ,
@@ -134,8 +132,8 @@ def with_material(model_dir=MODEL_DIR):
134
132
names_to_o3dprop = {"ao" : "ambient_occlusion" }
135
133
136
134
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 ):
139
137
texture = names_to_o3dprop .get (texture , texture )
140
138
summary_3d .update ({
141
139
("material_texture_map_" + texture ):
@@ -149,11 +147,11 @@ def with_material(model_dir=MODEL_DIR):
149
147
150
148
151
149
def 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.
153
151
"""
154
152
import demo_scene
155
153
geoms = demo_scene .create_scene ()
156
- writer = SummaryWriter (os . path . join (BASE_LOGDIR , 'demo_scene' ))
154
+ writer = SummaryWriter (join (BASE_LOGDIR , 'demo_scene' ))
157
155
for geom_data in geoms :
158
156
geom = geom_data ["geometry" ]
159
157
summary_3d = {}
0 commit comments