From 8412c2d69b0462e278ae9e092504d04c489b7da4 Mon Sep 17 00:00:00 2001 From: Dario Mylonopoulos Date: Fri, 15 Sep 2023 18:55:27 +0200 Subject: [PATCH] Added gui_stats method and stats section to gui --- aitviewer/renderables/meshes.py | 13 +++++++++++++ aitviewer/scene/node.py | 9 +++++++++ aitviewer/scene/scene.py | 9 +++++++++ 3 files changed, 31 insertions(+) diff --git a/aitviewer/renderables/meshes.py b/aitviewer/renderables/meshes.py index 4e3161c..7cdffbd 100644 --- a/aitviewer/renderables/meshes.py +++ b/aitviewer/renderables/meshes.py @@ -707,6 +707,19 @@ def gui(self, imgui): if imgui.button("Show Normals ##show_normals{}".format(self.unique_name)): self._show_normals() + @hooked + def gui_stats(self, imgui): + for k, v in { + "Vertices": self.vertices.shape[1], + "Faces": self.faces.shape[0], + "Vertex colors": "yes" if self._vertex_colors is not None else "no", + "UVs": "yes" if self.uv_coords is not None else "no", + "Face normals": "yes" if self._face_normals is not None else "no", + "Face colors": "yes" if self._face_colors is not None else "no", + "Texture": "yes" if self.has_texture else "no", + }.items(): + imgui.text(f"{k}: {v}") + def gui_context_menu(self, imgui, x: int, y: int): _, self.flat_shading = imgui.menu_item("Flat shading", "F", selected=self.flat_shading, enabled=True) _, self.draw_edges = imgui.menu_item("Draw edges", "E", selected=self.draw_edges, enabled=True) diff --git a/aitviewer/scene/node.py b/aitviewer/scene/node.py index b9b2292..67898f4 100644 --- a/aitviewer/scene/node.py +++ b/aitviewer/scene/node.py @@ -443,6 +443,15 @@ def gui(self, imgui): """ pass + def gui_stats(self, imgui): + """ + Render GUI for stats about the node, rendered at the bottom of the scene hierarchy. + Should be implemented with @hooked decorator to print stats from parent classes. + :param imgui: imgui context. + See https://pyimgui.readthedocs.io/en/latest/reference/imgui.core.html for available elements to render + """ + imgui.text(f"Frames: {self.n_frames}") + def gui_modes(self, imgui): """Render GUI with toolbar (tools) for this particular node""" diff --git a/aitviewer/scene/scene.py b/aitviewer/scene/scene.py index 855c09f..2351089 100644 --- a/aitviewer/scene/scene.py +++ b/aitviewer/scene/scene.py @@ -376,6 +376,15 @@ def gui_selected(self, imgui): imgui.spacing() imgui.spacing() + imgui.spacing() + imgui.spacing() + imgui.spacing() + imgui.same_line(spacing=8) + imgui.begin_group() + if imgui.collapsing_header("Stats")[0]: + s.gui_stats(imgui) + imgui.end_group() + def gui(self, imgui): imgui.text(f"FPS: {self.fps:.1f}") # Background color