diff --git a/docs/changelog.md b/docs/changelog.md index 89cbf0e..efb3a26 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -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. diff --git a/pyviz3d/visualizer.py b/pyviz3d/visualizer.py index 2d32373..4539395 100644 --- a/pyviz3d/visualizer.py +++ b/pyviz3d/visualizer.py @@ -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, @@ -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 ) @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. diff --git a/setup.py b/setup.py index 4971bdd..5f41eba 100644 --- a/setup.py +++ b/setup.py @@ -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,