Skip to content

Commit

Permalink
Updates and fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
francisengelmann committed Oct 27, 2021
1 parent de4543c commit 5a9e2f3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## Version 0.2
- 0.2.25: Bug fixes.
- 0.2.24: Add arrows.
- 0.2.23: Add segments.
- 0.2.22: Add (oriented) bounding boxes.
- 0.2.21: Add .obj meshes and other overall improvements.
- 0.2.19: Add verbose flag to save function.
Expand Down
20 changes: 14 additions & 6 deletions pyviz3d/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ def __init__(self, position=[3.0, 3.0, 3.0], look_at=[0.0, 0.0, 0.0]):
)
self.elements = {"Camera_0": self.camera} # dict of elements to display

def __parse_name(self, name):
"""Makes sure the name does not contain invalid character combinations.
:param name:
:return:
"""
return name.replace(':', ';')

def add_points(
self,
name,
Expand Down Expand Up @@ -60,7 +68,7 @@ def add_points(

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

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

Expand All @@ -84,7 +92,7 @@ def add_lines(self, name, lines_start, lines_end, colors=None, visible=True):
colors = colors.astype(np.uint8)
lines_start = lines_start.astype(np.float32)
lines_end = lines_end.astype(np.float32)
self.elements[name] = Lines(lines_start, lines_end, colors, colors, visible)
self.elements[self.__parse_name(name)] = Lines(lines_start, lines_end, colors, colors, visible)

def add_bounding_box(self, name, position, size, orientation=None, color=None, alpha=1.0, edge_width=0.01, visible=True):
"""Add bounding box.
Expand All @@ -102,7 +110,7 @@ def add_bounding_box(self, name, position, size, orientation=None, color=None, a
orientation = np.array([0.0, 0.0, 0.0])
if color is None:
color = np.array([255, 0, 0])
self.elements[name] = Cuboid(position, size, orientation, color, alpha, edge_width, visible)
self.elements[self.__parse_name(name)] = Cuboid(position, size, orientation, color, alpha, edge_width, visible)

def add_mesh(self, name, path, translation=[0, 0, 0], rotation=[0, 0, 0], scale=[1, 1, 1], color=[255, 255, 255], visible=True):
"""Adds a polygon mesh to the scene, as specified in the path, it has to be an .obj file.
Expand All @@ -116,7 +124,7 @@ def add_mesh(self, name, path, translation=[0, 0, 0], rotation=[0, 0, 0], scale=
:param visible: Whether the object is visible or not.
"""
mesh = Mesh(path, translation=translation, rotation=rotation, scale=scale, color=color, visible=visible)
self.elements[name] = mesh
self.elements[self.__parse_name(name)] = mesh

def add_polyline(self, name, positions, color=None, alpha=1.0, edge_width=0.01, visible=True):
"""Add polyline.
Expand All @@ -130,7 +138,7 @@ def add_polyline(self, name, positions, color=None, alpha=1.0, edge_width=0.01,
"""
if color is None:
color = np.array([255, 0, 0])
self.elements[name] = Polyline(positions, color, alpha, edge_width, visible)
self.elements[self.__parse_name(name)] = Polyline(positions, color, alpha, edge_width, visible)

def add_arrow(self, name, start, end, color=None, alpha=1.0, stroke_width=0.01, head_width=0.03, visible=True):
"""Add polyline.
Expand All @@ -143,7 +151,7 @@ def add_arrow(self, name, start, end, color=None, alpha=1.0, stroke_width=0.01,
"""
if color is None:
color = np.array([255, 0, 0])
self.elements[name] = Arrow(start, end, color, alpha, stroke_width, head_width, visible)
self.elements[self.__parse_name(name)] = Arrow(start, end, color, alpha, stroke_width, head_width, visible)

def save(self, path, port=6008, verbose=True):
"""Creates the visualization and displays the link to it.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
long_description = f.read()

version = '0.2.23'
version = '0.2.25'

setup(name='pyviz3d',
version=version,
Expand Down

0 comments on commit 5a9e2f3

Please sign in to comment.