MeshLib C++ Docs
Loading...
Searching...
No Matches
MRPythonViewer.h
Go to the documentation of this file.
1#pragma once
2
5
7#include "MRMesh/MRLine.h"
8#include "MRMesh/MRVector2.h"
9#include "MRMesh/MRVector3.h"
10#include "MRMesh/MRViewportId.h"
11
12#include <functional>
13#include <string>
14
15namespace MR::PythonViewer
16{
17
21{
22};
23
32
35{
36 int animationMaxFps = 30;
37 bool fullscreen = false;
38 int width = 0;
39 int height = 0;
40 bool isAnimating = false;
41 std::string name = "MRViewer";
43};
44
45enum class MouseButton
46{
50};
51
52enum class KeyMod
53{
54 Empty = 0,
55 Ctrl = 0x0002,
56 Super = 0x0008,
57 Shift = 0x0001,
58 Alt = 0x0004,
59};
61
62
64
72
79
83{
84public:
85 explicit Viewport( ViewportId id ) : id( id ) {}
86
88
92 void cameraLookAlong( const Vector3f& dir, const Vector3f& up ) const;
93
96 void cameraRotateAround( const Line3f& axis, float angle ) const;
97
99 [[nodiscard]] Vector3f projectToViewportSpace( const Vector3f& input ) const;
100};
101
104{
105public:
108 [[nodiscard]] Viewport viewport( ViewportId viewportId = {} ) const;
109
112 void incrementForceRedrawFrames( int num = 1, bool swapOnLastOnly = false ) const;
113
114 void skipFrames( int frames ) const;
115
119
121 void captureScreenShot( const std::string& path ) const;
122
124 void captureUIScreenShot( const std::string& path ) const;
125
127 void shutdown( int exitCode = 0, bool interruptible = true ) const;
128
131
133 void mouseUp( MouseButton button, KeyMod modifier = KeyMod::Empty ) const;
134
137 void mouseMove( int x, int y ) const;
138
140 [[nodiscard]] Vector2f getMousePos() const;
141
143 [[nodiscard]] Vector3f viewportToScreen( const Vector3f& viewportPoint, ViewportId id ) const;
144
146 void showSceneTree( bool show ) const;
147};
148
153void launch( const ViewerLaunchParams& params = {}, const ViewerSetup& setup = {} );
154
159
161void runFromGUIThread( const std::function<void()>& lambda );
162
165
166}
#define MR_MAKE_FLAG_OPERATORS(T)
Generates operators for a enum (at namespace scope).
Definition MRFlagOperators.h:6
GLFW-based mesh viewer.
Definition MRPythonViewer.h:104
void captureScreenShot(const std::string &path) const
Captures part of window (redraw 3d scene over UI (without redrawing UI))
void incrementForceRedrawFrames(int num=1, bool swapOnLastOnly=false) const
void mouseMove(int x, int y) const
void preciseFitDataViewport(ViewportMask vpList=ViewportMask::all(), const ViewportFitDataParams &params={}) const
Viewport viewport(ViewportId viewportId={}) const
Vector2f getMousePos() const
Get the current mouse position.
void showSceneTree(bool show) const
Shows or hide scene tree.
void shutdown(int exitCode=0, bool interruptible=true) const
sets stop event loop flag (this flag is glfwShouldWindowClose equivalent); the viewer's launch then r...
void mouseUp(MouseButton button, KeyMod modifier=KeyMod::Empty) const
Simulate mouse up event.
void captureUIScreenShot(const std::string &path) const
Captures full window screenshot with UI.
void skipFrames(int frames) const
Vector3f viewportToScreen(const Vector3f &viewportPoint, ViewportId id) const
Convert viewport coordinates to to screen coordinates.
void mouseDown(MouseButton button, KeyMod modifier=KeyMod::Empty) const
Simulate mouse down event.
Definition MRPythonViewer.h:83
void cameraLookAlong(const Vector3f &dir, const Vector3f &up) const
void cameraRotateAround(const Line3f &axis, float angle) const
const ViewportId id
Definition MRPythonViewer.h:87
Vector3f projectToViewportSpace(const Vector3f &input) const
Project world space point to viewport coordinates (in pixels), (0,0) will be at the top-left corner o...
Viewport(ViewportId id)
Definition MRPythonViewer.h:85
Definition MRSetupViewer.h:16
Definition MRViewportId.h:16
stores mask of viewport unique identifiers
Definition MRViewportId.h:42
static ViewportMask all()
mask meaning all or any viewports
Definition MRViewportId.h:49
@ angle
Direction, normally Vector3f.
Definition MRFeatureObject.h:26
Definition MRPythonScene.h:19
MouseButton
Definition MRPythonViewer.h:46
@ Right
Definition MRPythonViewer.h:48
@ Left
Definition MRPythonViewer.h:47
@ Middle
Definition MRPythonViewer.h:49
void launch(const ViewerLaunchParams &params={}, const ViewerSetup &setup={})
void runFromGUIThread(const std::function< void()> &lambda)
Executes given function from GUI thread, and returns after it is done.
void shutViewerAtExit()
Registered with atexit by the module, and removed from it: closes the viewer the way a closed window ...
@ button
Definition MRPythonUiInteraction.h:15
KeyMod
Definition MRPythonViewer.h:53
@ Super
Definition MRPythonViewer.h:56
@ Ctrl
Definition MRPythonViewer.h:55
@ Shift
Definition MRPythonViewer.h:57
@ Alt
Definition MRPythonViewer.h:58
@ Empty
Definition MRPythonViewer.h:54
ViewerLaunchParamsMode
Definition MRPythonViewer.h:25
@ Show
Show window immediately.
Definition MRPythonViewer.h:26
@ Hide
Don't show window.
Definition MRPythonViewer.h:28
@ TryHidden
Launches in "Hide" mode if OpenGL is present and "NoWindow" if it is not.
Definition MRPythonViewer.h:29
@ NoWindow
Don't initialize GL window (don't call GL functions)(force isAnimating)
Definition MRPythonViewer.h:30
@ HideInit
Show window after init.
Definition MRPythonViewer.h:27
KeyMod getPrimaryCtrlKeyMod()
Returns the main control modifier of this platform: KeyMod.Super (Cmd) on macOS, KeyMod....
ViewportFitMode
Fit mode ( types of objects for which the fit is applied )
Definition MRPythonViewer.h:67
@ SelectedObjects
fit only selected objects
Definition MRPythonViewer.h:70
@ SelectedPrimitives
fit only selected primitives
Definition MRPythonViewer.h:69
@ Visible
fit all visible objects
Definition MRPythonViewer.h:68
This struct contains rules for viewer launch.
Definition MRPythonViewer.h:35
int animationMaxFps
max fps if animating
Definition MRPythonViewer.h:36
int height
Definition MRPythonViewer.h:39
std::string name
Window name.
Definition MRPythonViewer.h:41
bool isAnimating
if true - calls render without system events
Definition MRPythonViewer.h:40
int width
Definition MRPythonViewer.h:38
bool fullscreen
if true starts fullscreen
Definition MRPythonViewer.h:37
ViewerLaunchParamsMode windowMode
Definition MRPythonViewer.h:42
Definition MRPythonViewer.h:21
Definition MRPythonViewer.h:74
ViewportFitMode mode
fit mode
Definition MRPythonViewer.h:77
float factor
part of the screen for scene location
Definition MRPythonViewer.h:75
bool snapView
snapView - to snap camera angle to closest canonical quaternion
Definition MRPythonViewer.h:76