MeshLib C++ Docs
Loading...
Searching...
No Matches
MR::PythonViewer Namespace Reference

Classes

struct  UiEntry
struct  UiValueInt
struct  UiValueReal
struct  UiValueString
struct  UiValueUint
class  Viewer
 GLFW-based mesh viewer. More...
struct  ViewerLaunchParams
 This struct contains rules for viewer launch. More...
struct  ViewerSetup
class  Viewport
struct  ViewportFitDataParams

Enumerations

enum class  UiEntryType {
  button , group , valueInt , valueUint ,
  valueReal , valueString
}
 UI entry type enum. More...
enum class  ViewerLaunchParamsMode {
  Show , HideInit , Hide , TryHidden ,
  NoWindow
}
enum class  MouseButton { Left , Right , Middle }
enum class  KeyMod {
  Empty = 0 , Ctrl = 0x0002 , Super = 0x0008 , Shift = 0x0001 ,
  Alt = 0x0004
}
enum class  ViewportFitMode { Visible , SelectedPrimitives , SelectedObjects }
 Fit mode ( types of objects for which the fit is applied ) More...

Functions

void addMeshToScene (const Mesh &mesh, const std::string &name)
 Add given mesh to scene tree.
void addPointCloudToScene (const PointCloud &points, const std::string &name)
 Add given point cloud to scene tree.
void addLinesToScene (const Polyline3 &lines, const std::string &name)
 Add given lines to scene tree.
void addDistanceMapToScene (const DistanceMap &distancemap, const std::string &name, const AffineXf3f &dmap_to_local_xf)
 Add given distance map to scene tree.
void modifySelectedMesh (const Mesh &mesh)
 Assign a new mesh to the selected mesh object. Exactly one object must be selected.
std::vector< FaceBitSet > getSelectedMeshFaces ()
 Get selected face bitsets of the selected mesh objects.
std::vector< UndirectedEdgeBitSet > getSelectedMeshEdges ()
 Get selected edge bitsets of the selected mesh objects.
std::vector< VertBitSet > getSelectedPointCloudPoints ()
 Get selected point bitsets of the selected point cloud objects.
void setSelectedMeshFaces (const std::vector< FaceBitSet > &bitsets)
 Set selected face bitsets of the selected mesh objects.
void setSelectedMeshEdges (const std::vector< UndirectedEdgeBitSet > &bitsets)
 Set selected edge bitsets of the selected mesh objects.
void setSelectedPointCloudPoints (const std::vector< VertBitSet > &bitsets)
 Set selected point bitsets of the selected point cloud objects.
void clearScene ()
 remove all objects from scene tree
void selectByName (const std::string &objectName)
 select objects in scene tree with given name, unselect others
void selectByType (const std::string &typeName)
void unselectAll ()
 unselect all objects in scene tree
std::vector< std::shared_ptr< Object > > getSelectedObjects ()
std::vector< Mesh > getSelectedMeshes ()
 Get copies of all selected meshes in the scene.
std::vector< PointCloud > getSelectedPointClouds ()
 Get copies of all selected point clouds in the scene.
std::vector< Polyline3 > getSelectedPolylines ()
 Get copies of all selected polylines in the scene.
std::vector< DistanceMap > getSelectedDistanceMaps ()
 Get copies of all selected voxel grids in the scene.
void addVoxelsToScene (const VdbVolume &voxels, const std::string &name)
 Add given voxels to scene tree.
std::vector< VdbVolume > getSelectedVoxels ()
 Get copies of all selected voxel grids in the scene.
std::vector< UiEntry > _uiListEntries (const std::vector< std::string > &path)
 python_viewer.py wraps the functions with a leading underscore, to return lists and tuples.
std::vector< std::pair< std::vector< std::string >, UiEntry > > _uiListAllEntries (const std::vector< std::string > &rootPath)
void uiPressButton (const std::vector< std::string > &path)
 Simulate a button click. Use uiListEntries() to find button names.
UiValueInt uiReadValueInt (const std::vector< std::string > &path)
 Read a value from a drag/slider widget. This function is for signed integers.
UiValueUint uiReadValueUint (const std::vector< std::string > &path)
 Read a value from a drag/slider widget. This function is for unsigned integers.
UiValueReal uiReadValueReal (const std::vector< std::string > &path)
 Read a value from a drag/slider widget. This function is for real numbers.
UiValueString uiReadValueString (const std::vector< std::string > &path)
 Read a value from a drag/slider widget. This function is for strings.
void uiWriteValue (const std::vector< std::string > &path, std::int64_t value)
 Write a value to a drag/slider widget. This overload is for signed integers.
void uiWriteValue (const std::vector< std::string > &path, std::uint64_t value)
 Write a value to a drag/slider widget. This overload is for unsigned integers.
void uiWriteValue (const std::vector< std::string > &path, double value)
 Write a value to a drag/slider widget. This overload is for real numbers.
void uiWriteValue (const std::vector< std::string > &path, const std::string &value)
 Write a value to a drag/slider widget. This overload is for strings.
KeyMod getPrimaryCtrlKeyMod ()
 Returns the main control modifier of this platform: KeyMod.Super (Cmd) on macOS, KeyMod.Ctrl otherwise.
void launch (const ViewerLaunchParams &params={}, const ViewerSetup &setup={})
void showViewer ()
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 would, if it's still up.

Detailed Description

The API of the mrviewerpy Python module, generated from this header over the C bindings (scripts/mrbind/generate.mk). The calls wait for the viewer's GUI thread, so the module releases the GIL around every call (--release-gil).

Enumeration Type Documentation

◆ KeyMod

enum class MR::PythonViewer::KeyMod
strong
Enumerator
Empty 
Ctrl 
Super 
Shift 
Alt 

◆ MouseButton

enum class MR::PythonViewer::MouseButton
strong
Enumerator
Left 
Right 
Middle 

◆ UiEntryType

enum class MR::PythonViewer::UiEntryType
strong

UI entry type enum.

Enumerator
button 
group 
valueInt 
valueUint 
valueReal 
valueString 

◆ ViewerLaunchParamsMode

Enumerator
Show 

Show window immediately.

HideInit 

Show window after init.

Hide 

Don't show window.

TryHidden 

Launches in "Hide" mode if OpenGL is present and "NoWindow" if it is not.

NoWindow 

Don't initialize GL window (don't call GL functions)(force isAnimating)

◆ ViewportFitMode

Fit mode ( types of objects for which the fit is applied )

Enumerator
Visible 

fit all visible objects

SelectedPrimitives 

fit only selected primitives

SelectedObjects 

fit only selected objects

Function Documentation

◆ _uiListAllEntries()

std::vector< std::pair< std::vector< std::string >, UiEntry > > MR::PythonViewer::_uiListAllEntries ( const std::vector< std::string > & rootPath)
nodiscard

Flat depth-first list of every UI entry in the subtree rooted at rootPath. Pass an empty list for the whole tree. Each element is a (path, UiEntry) tuple where path[-1] == entry.name.

◆ _uiListEntries()

std::vector< UiEntry > MR::PythonViewer::_uiListEntries ( const std::vector< std::string > & path)
nodiscard

python_viewer.py wraps the functions with a leading underscore, to return lists and tuples.

List existing UI entries at the specified path. Pass an empty list to see top-level groups. Add group name to the end of the vector to see its contents. When you find the button you need, pass it to uiPressButton().

◆ addDistanceMapToScene()

void MR::PythonViewer::addDistanceMapToScene ( const DistanceMap & distancemap,
const std::string & name,
const AffineXf3f & dmap_to_local_xf )

Add given distance map to scene tree.

◆ addLinesToScene()

void MR::PythonViewer::addLinesToScene ( const Polyline3 & lines,
const std::string & name )

Add given lines to scene tree.

◆ addMeshToScene()

void MR::PythonViewer::addMeshToScene ( const Mesh & mesh,
const std::string & name )

Add given mesh to scene tree.

◆ addPointCloudToScene()

void MR::PythonViewer::addPointCloudToScene ( const PointCloud & points,
const std::string & name )

Add given point cloud to scene tree.

◆ addVoxelsToScene()

void MR::PythonViewer::addVoxelsToScene ( const VdbVolume & voxels,
const std::string & name )

Add given voxels to scene tree.

◆ clearScene()

void MR::PythonViewer::clearScene ( )

remove all objects from scene tree

◆ getPrimaryCtrlKeyMod()

KeyMod MR::PythonViewer::getPrimaryCtrlKeyMod ( )
nodiscard

Returns the main control modifier of this platform: KeyMod.Super (Cmd) on macOS, KeyMod.Ctrl otherwise.

◆ getSelectedDistanceMaps()

std::vector< DistanceMap > MR::PythonViewer::getSelectedDistanceMaps ( )
nodiscard

Get copies of all selected voxel grids in the scene.

◆ getSelectedMeshEdges()

std::vector< UndirectedEdgeBitSet > MR::PythonViewer::getSelectedMeshEdges ( )
nodiscard

Get selected edge bitsets of the selected mesh objects.

◆ getSelectedMeshes()

std::vector< Mesh > MR::PythonViewer::getSelectedMeshes ( )
nodiscard

Get copies of all selected meshes in the scene.

◆ getSelectedMeshFaces()

std::vector< FaceBitSet > MR::PythonViewer::getSelectedMeshFaces ( )
nodiscard

Get selected face bitsets of the selected mesh objects.

◆ getSelectedObjects()

std::vector< std::shared_ptr< Object > > MR::PythonViewer::getSelectedObjects ( )
nodiscard

◆ getSelectedPointCloudPoints()

std::vector< VertBitSet > MR::PythonViewer::getSelectedPointCloudPoints ( )
nodiscard

Get selected point bitsets of the selected point cloud objects.

◆ getSelectedPointClouds()

std::vector< PointCloud > MR::PythonViewer::getSelectedPointClouds ( )
nodiscard

Get copies of all selected point clouds in the scene.

◆ getSelectedPolylines()

std::vector< Polyline3 > MR::PythonViewer::getSelectedPolylines ( )
nodiscard

Get copies of all selected polylines in the scene.

◆ getSelectedVoxels()

std::vector< VdbVolume > MR::PythonViewer::getSelectedVoxels ( )
nodiscard

Get copies of all selected voxel grids in the scene.

◆ launch()

void MR::PythonViewer::launch ( const ViewerLaunchParams & params = {},
const ViewerSetup & setup = {} )

Starts the viewer with the given params and setup, and returns once it is up and accepts calls. On Windows and Linux the window opens here, and the script keeps running alongside it. On macOS the viewer runs on the calling thread, which must be the main one: the window opens in showViewer(), or at the interactive prompt, where it stays live while the interpreter waits for input, in input() too. Raises RuntimeError if the viewer could not start (no display, or already launched once in this process).

◆ modifySelectedMesh()

void MR::PythonViewer::modifySelectedMesh ( const Mesh & mesh)

Assign a new mesh to the selected mesh object. Exactly one object must be selected.

◆ runFromGUIThread()

void MR::PythonViewer::runFromGUIThread ( const std::function< void()> & lambda)

Executes given function from GUI thread, and returns after it is done.

◆ selectByName()

void MR::PythonViewer::selectByName ( const std::string & objectName)

select objects in scene tree with given name, unselect others

◆ selectByType()

void MR::PythonViewer::selectByType ( const std::string & typeName)

string typeName: {"Meshes", "Points", "Voxels"} objects in scene tree with given type, unselect others

◆ setSelectedMeshEdges()

void MR::PythonViewer::setSelectedMeshEdges ( const std::vector< UndirectedEdgeBitSet > & bitsets)

Set selected edge bitsets of the selected mesh objects.

◆ setSelectedMeshFaces()

void MR::PythonViewer::setSelectedMeshFaces ( const std::vector< FaceBitSet > & bitsets)

Set selected face bitsets of the selected mesh objects.

◆ setSelectedPointCloudPoints()

void MR::PythonViewer::setSelectedPointCloudPoints ( const std::vector< VertBitSet > & bitsets)

Set selected point bitsets of the selected point cloud objects.

◆ showViewer()

void MR::PythonViewer::showViewer ( )

Keeps the window open until the user closes it or shutdown() is called from another thread. On macOS the window opens here, so this call is required there; make it from the main thread. After it returns the viewer is closed for good, and further viewer calls raise RuntimeError.

◆ shutViewerAtExit()

void MR::PythonViewer::shutViewerAtExit ( )

Registered with atexit by the module, and removed from it: closes the viewer the way a closed window would, if it's still up.

◆ uiPressButton()

void MR::PythonViewer::uiPressButton ( const std::vector< std::string > & path)

Simulate a button click. Use uiListEntries() to find button names.

◆ uiReadValueInt()

UiValueInt MR::PythonViewer::uiReadValueInt ( const std::vector< std::string > & path)
nodiscard

Read a value from a drag/slider widget. This function is for signed integers.

◆ uiReadValueReal()

UiValueReal MR::PythonViewer::uiReadValueReal ( const std::vector< std::string > & path)
nodiscard

Read a value from a drag/slider widget. This function is for real numbers.

◆ uiReadValueString()

UiValueString MR::PythonViewer::uiReadValueString ( const std::vector< std::string > & path)
nodiscard

Read a value from a drag/slider widget. This function is for strings.

◆ uiReadValueUint()

UiValueUint MR::PythonViewer::uiReadValueUint ( const std::vector< std::string > & path)
nodiscard

Read a value from a drag/slider widget. This function is for unsigned integers.

◆ uiWriteValue() [1/4]

void MR::PythonViewer::uiWriteValue ( const std::vector< std::string > & path,
const std::string & value )

Write a value to a drag/slider widget. This overload is for strings.

◆ uiWriteValue() [2/4]

void MR::PythonViewer::uiWriteValue ( const std::vector< std::string > & path,
double value )

Write a value to a drag/slider widget. This overload is for real numbers.

◆ uiWriteValue() [3/4]

void MR::PythonViewer::uiWriteValue ( const std::vector< std::string > & path,
std::int64_t value )

Write a value to a drag/slider widget. This overload is for signed integers.

◆ uiWriteValue() [4/4]

void MR::PythonViewer::uiWriteValue ( const std::vector< std::string > & path,
std::uint64_t value )

Write a value to a drag/slider widget. This overload is for unsigned integers.

◆ unselectAll()

void MR::PythonViewer::unselectAll ( )

unselect all objects in scene tree