display.py
Go to the documentation of this file.
1 # Typical header of a Python script using Pinocchio
2 import gepetto.corbaserver
3 import pinocchio as pin
4 
5 
6 # Example of a class Display that connect to Gepetto-viewer and implement a
7 # 'place' method to set the position/rotation of a 3D visual object in a scene.
8 class Display:
9  """
10  Class Display: Example of a class implementing a client for the Gepetto-viewer
11  server. The main method of the class is 'place', that sets the position/rotation of
12  a 3D visual object in a scene.
13  """
14 
15  def __init__(self, windowName="pinocchio"):
16  """
17  This function connect with the Gepetto-viewer server and open a window with the
18  given name. If the window already exists, it is kept in the current state.
19  Otherwise, the newly-created window is set up with a scene named 'world'.
20  """
21 
22  # Create the client and connect it with the display server.
23  try:
24  self.viewer = gepetto.corbaserver.Client()
25  except: # noqa: E722
26  print("Error while starting the viewer client. ")
27  print("Check whether Gepetto-viewer is properly started")
28 
29  # Open a window for displaying your model.
30  try:
31  # If the window already exists, do not do anything.
32  windowID = self.viewer.gui.getWindowID(windowName)
33  print("Warning: window '" + windowName + "' already created.")
34  print(
35  "The previously created objects will not be destroyed "
36  "and do not have to be created again."
37  )
38  except: # noqa: E722
39  # Otherwise, create the empty window.
40  windowID = self.viewer.gui.createWindow(windowName)
41  # Start a new "scene" in this window, named "world", with just a floor.
42  self.viewer.gui.createScene("world")
43  self.viewer.gui.addSceneToWindow("world", windowID)
44 
45  # Finally, refresh the layout to obtain your first rendering.
46  self.viewer.gui.refresh()
47 
48  def place(self, objName, M, refresh=True):
49  """
50  This function places (ie changes both translation and rotation) of the object
51  names "objName" in place given by the SE3 object "M". By default, immediately
52  refresh the layout. If multiple objects have to be placed at the same time, do
53  the refresh only at the end of the list.
54  """
55  self.viewer.gui.applyConfiguration(objName, pin.se3ToXYZQUATtuple(M))
56  if refresh:
57  self.viewer.gui.refresh()
display.Display
Definition: display.py:8
display.Display.viewer
viewer
Definition: display.py:24
display.Display.place
def place(self, objName, M, refresh=True)
Definition: display.py:48
display.Display.__init__
def __init__(self, windowName="pinocchio")
Definition: display.py:15


pinocchio
Author(s):
autogenerated on Fri Nov 1 2024 02:41:43