"""Generic classes to visualize and save pointcloud data."""from__future__importannotationsimportnumpyasnpfrom..sceneimportScene3D
[docs]classPointCloudVisualizerBackend:"""Visualization Backen Interface for Pointclouds."""def__init__(self,class_color_mapping:list[tuple[int,int,int]],instance_color_mapping:list[tuple[int,int,int]]|None=None,)->None:"""Creates a new Open3D visualization backend. Args: class_color_mapping (list[tuple[int, int ,int]]): List of length n_classes that maps each class index to a unique color. instance_color_mapping (list[tuple[int, int ,int]], optional): List of length n_instances that maps each instance id to a unique color. Defaults to None. """self.scenes:list[Scene3D]=[]self.class_color_mapping=np.asarray(class_color_mapping)ifnp.any(self.class_color_mapping>1):# Color mapping from [0, 255]self.class_color_mapping=self.class_color_mapping/255ifinstance_color_mappingisNone:self.instance_color_mapping=self.class_color_mappingelse:self.instance_color_mapping=np.asarray(instance_color_mapping)ifnp.any(self.instance_color_mapping>1):self.instance_color_mapping=self.instance_color_mapping/255
[docs]defcreate_new_scene(self)->Scene3D:"""Creates a new empty scene."""self.scenes.append(Scene3D())returnself.get_current_scene()
[docs]defget_current_scene(self)->Scene3D:"""Returns the currently active scene. If no scene is available, an new empty one is created. Returns: Scene3D: current pointcloud scene """if(len(self.scenes))==0:returnself.create_new_scene()returnself.scenes[-1]
[docs]defshow(self,blocking:bool=True)->None:"""Shows the visualization. Args: blocking (bool): If the visualization should be blocking and wait for human input """raiseNotImplementedError()
[docs]defreset(self)->None:"""Clears all stored data."""self.scenes=[]
[docs]defadd_scene(self,scene:Scene3D)->None:"""Adds a given Scene3D to the visualization. Args: scene (Scene3D): 3D scene that should be added. """self.scenes.append(scene)
[docs]defsave_to_disk(self,path_to_out_folder:str)->None:"""Saves the visualization to disk. Args: path_to_out_folder (str): Path to output folder """raiseNotImplementedError()