mrpt.gui

mrpt.gui — GUI windows for 3D visualization.

Provides:
  • CDisplayWindowGUI: 3D scene viewer window based on nanogui (GLFW), available if HAS_NANOGUI (always, in the pip wheel).

  • CDisplayWindow3D : 3D scene viewer window based on wxWidgets, available if HAS_WXWIDGETS (not in the pip wheel).

  • CBaseGUIWindow : Base class of the wxWidgets windows.

Usage example:

import time
import mrpt.gui as gui
import mrpt.viz as viz

win = gui.CDisplayWindowGUI("My 3D Window", 800, 600)
scene = viz.Scene()
scene.insert(viz.stock_objects.CornerXYZ())
win.background_scene = scene
while win.spinOnce():  # False once the window is closed
    time.sleep(0.02)

Package Contents

class mrpt.gui.CBaseGUIWindow

C++ API: class mrpt::gui::CBaseGUIWindow

The base class for GUI window classes based on wxWidgets.

clearKeyHitFlag() → None

Assure that “keyHit” will return false until the next pushed key.

isOpen() → bool

Returns false if the user has already closed the window.

keyHit() → bool

Returns true if a key has been pushed, without blocking waiting for a new key being pushed.

waitForKey(ignoreControlKeys: bool = True) → int

Waits until a key is pressed in the window. Returns the key code.

class mrpt.gui.CDisplayWindow3D(windowCaption: str = '', width: int = 400, height: int = 300)

C++ API: class mrpt::gui::CDisplayWindow3D

Bases: CBaseGUIWindow

A graphical user interface (GUI) for efficiently rendering 3D scenes in real-time.

static Create(windowCaption: str = '', width: int = 400, height: int = 300) → CDisplayWindow3D

Creates a new 3D window (same arguments as the constructor).

forceRepaint() → None

Repaints the window. forceRepaint, repaint and updateWindow are all aliases of the same method.

get3DSceneAndLock() → mrpt.viz.Scene

Get locked 3D scene pointer. Call unlockAccess3DScene() when done.

getCameraAzimuthDeg() → float

Returns the camera azimuth angle, in degrees.

getCameraElevationDeg() → float

Returns the camera elevation angle, in degrees.

getCameraPointingToPoint() → tuple

Returns the point the camera looks at, as (x, y, z).

getCameraZoom() → float

Returns the camera distance to the point it looks at.

getFOV() → float

Returns the camera field of view, in degrees.

getRenderingFPS() → float

Get the average Frames Per Second (FPS) value from the last 250 rendering events.

grabImagesStart(prefix: str = 'video_') → None

Starts saving each rendered frame as a PNG file, with the given filename prefix.

grabImagesStop() → None

Stops image grabbing started by grabImagesStart.

isCameraProjective() → bool

Returns true for a perspective camera, false for an orthographic one.

repaint() → None

Repaints the window. forceRepaint, repaint and updateWindow are all aliases of the same method.

resize(arg0: int, arg1: int) → None

Resizes the window, stretching the image to fit into the display area.

setCameraAzimuthDeg(arg0: float) → None

Sets the camera azimuth angle, in degrees.

setCameraElevationDeg(arg0: float) → None

Sets the camera elevation angle, in degrees.

setCameraPointingToPoint(arg0: float, arg1: float, arg2: float) → None

Sets the point the camera looks at (x, y, z).

setCameraZoom(arg0: float) → None

Sets the camera distance to the point it looks at.

setFOV(arg0: float) → None

Sets the camera field of view, in degrees.

setImageView(img: mrpt.img.CImage) → None

Display a 2D image in this window

setMaxRange(arg0: float) → None

Sets the far clip distance of the camera.

setMinRange(arg0: float) → None

Sets the near clip distance of the camera.

setPos(arg0: int, arg1: int) → None

Changes the position of the window on the screen.

setProjectiveModel(arg0: bool) → None

Sets a perspective (true) or orthographic (false) camera.

setWindowTitle(arg0: str) → None

Changes the window title.

unlockAccess3DScene() → None

Releases the scene lock taken by get3DSceneAndLock().

updateWindow() → None

Repaints the window. forceRepaint, repaint and updateWindow are all aliases of the same method.

useCameraFromScene(arg0: bool) → None

If true, the camera of the scene viewport is used instead of the mouse-controlled one.

class mrpt.gui.CDisplayWindowGUI(caption: str = '', width: int = 800, height: int = 600, params: CDisplayWindowGUI_Params = ...)

C++ API: class mrpt::gui::CDisplayWindowGUI

A window with a background 3D scene and mouse camera control, based on nanogui.

Set the scene to show in background_scene. Then, either call spinOnce() from your own loop (it does not block), or register callbacks with addLoopCallback() and call mrpt.gui.nanogui_mainloop(), which blocks until all windows are closed.

property background_scene: mrpt.viz.Scene

The 3D scene rendered as the window background (None: no scene).

addDropFilesCallback(callback: Callable) → None

Adds a handler f(filenames) -> bool for files dropped onto the window.

addKeyboardCallback(callback: Callable) → None

Adds a keyboard handler f(key, scancode, action, modifiers) -> bool (True if handled). Key codes are GLFW key codes (e.g. ord(‘A’) for letters, 256 for ESC).

addLoopCallback(callback: Callable) → None

Adds a function to call before each repaint of the window.

camera() → mrpt.viz.COrbitCameraController

The mouse-controlled camera (a mrpt.viz.COrbitCameraController).

isOpen() → bool

Returns False if the window has been closed.

resize(width: int, height: int) → None

Resizes the window.

setIcon(img: mrpt.img.CImage) → None

Sets the window icon from an RGB or RGBA image.

setPos(x: int, y: int) → None

Changes the position of the window on the screen.

setVisible(visible: bool) → None

Shows or hides the window.

setWindowTitle(title: str) → None

Changes the window title.

spinOnce() → bool

Processes pending window events and repaints the window, without blocking. Returns False once the window has been closed.

class mrpt.gui.CDisplayWindowGUI_Params

C++ API: struct mrpt::gui::CDisplayWindowGUI_Params

Additional parameters for CDisplayWindowGUI windows.

property nSamples: int

Number of MSAA samples (0: no antialiasing).

fullscreen: bool
maximized: bool
resizable: bool
mrpt.gui.nanogui_leave() → None

Makes nanogui_mainloop() return (e.g. call it from a callback).

mrpt.gui.nanogui_mainloop(idle_loop_period_ms: int = 50, min_repaint_period_ms: int = 50) → None

Runs the GUI loop of all CDisplayWindowGUI windows until they are all closed, or nanogui_leave() is called. Loop callbacks run before each repaint.

mrpt.gui.HAS_NANOGUI: bool
mrpt.gui.HAS_WXWIDGETS: bool