Skip to content

Commit

Permalink
Merge pull request #3 from kumuji/verbose_save
Browse files Browse the repository at this point in the history
Added verbose option to save
  • Loading branch information
francisengelmann authored Jun 26, 2020
2 parents 733be5e + e6bc106 commit da1b48b
Showing 1 changed file with 43 additions and 23 deletions.
66 changes: 43 additions & 23 deletions pyviz3d/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@


class Visualizer:

def __init__(self, position=[3.0, 3.0, 3.0], look_at=[0.0, 0.0, 0.0]):
self.camera = Camera(position=np.array(np.array(position)),
look_at=np.array(np.array(look_at)))
self.elements = {'Camera_0': self.camera} # dict of elements to display

def add_points(self, name, positions, colors=None, normals=None, point_size=25, visible=True, alpha=1.0):
self.camera = Camera(
position=np.array(np.array(position)), look_at=np.array(np.array(look_at))
)
self.elements = {"Camera_0": self.camera} # dict of elements to display

def add_points(
self,
name,
positions,
colors=None,
normals=None,
point_size=25,
visible=True,
alpha=1.0,
):
"""Add points to the visualizer.
:param name: The name of the points displayed in the visualizer.
Expand Down Expand Up @@ -47,7 +56,9 @@ def add_points(self, name, positions, colors=None, normals=None, point_size=25,

alpha = min(max(alpha, 0.0), 1.0) # cap alpha to [0..1]

self.elements[name] = Points(positions, colors, normals, point_size, visible, alpha, shading_type)
self.elements[name] = Points(
positions, colors, normals, point_size, visible, alpha, shading_type
)

def add_lines(self, name, lines_start, lines_end, colors=None, visible=True):
"""Add lines to the visualizer.
Expand Down Expand Up @@ -81,7 +92,7 @@ def add_bounding_box(self, name, position, size, orientation=None):
"""
self.elements[name] = Cuboid(position, size, orientation)

def save(self, path, port=6008):
def save(self, path, port=6008, verbose=True):
"""Creates the visualization and displays the link to it.
:param path: The path to save the visualization files.
Expand All @@ -94,29 +105,38 @@ def save(self, path, port=6008):
shutil.rmtree(directory_destination)

# Copy website directory
directory_source = os.path.realpath(os.path.join(os.path.dirname(__file__), 'src'))
directory_source = os.path.realpath(
os.path.join(os.path.dirname(__file__), "src")
)
shutil.copytree(directory_source, directory_destination)

# Assemble binary data files
nodes_dict = {}
for name, e in self.elements.items():
binary_file_path = os.path.join(directory_destination, name+'.bin')
nodes_dict[name] = e.get_properties(name+'.bin')
binary_file_path = os.path.join(directory_destination, name + ".bin")
nodes_dict[name] = e.get_properties(name + ".bin")
e.write_binary(binary_file_path)

# Write json file containing all scene elements
json_file = os.path.join(directory_destination, 'nodes.json')
with open(json_file, 'w') as outfile:
json_file = os.path.join(directory_destination, "nodes.json")
with open(json_file, "w") as outfile:
json.dump(nodes_dict, outfile)

if not verbose:
return

# Display link
http_server_string = 'python -m SimpleHTTPServer ' + str(port)
if sys.version[0] == '3':
http_server_string = 'python -m http.server ' + str(port)
print('')
print('************************************************************************')
print('1) Start local server:')
print(' cd '+directory_destination+'; ' + http_server_string)
print('2) Open in browser:')
print(' http://0.0.0.0:' + str(port))
print('************************************************************************')
http_server_string = "python -m SimpleHTTPServer " + str(port)
if sys.version[0] == "3":
http_server_string = "python -m http.server " + str(port)
print("")
print(
"************************************************************************"
)
print("1) Start local server:")
print(" cd " + directory_destination + "; " + http_server_string)
print("2) Open in browser:")
print(" http://0.0.0.0:" + str(port))
print(
"************************************************************************"
)

0 comments on commit da1b48b

Please sign in to comment.