base_visualizer.py
Go to the documentation of this file.
1 from .. import pinocchio_pywrap as pin
2 from ..shortcuts import buildModelsFromUrdf, createDatas
3 
4 import time
5 
6 class BaseVisualizer(object):
7  """Pinocchio visualizers are employed to easily display a model at a given configuration.
8  BaseVisualizer is not meant to be directly employed, but only to provide a uniform interface and a few common methods.
9  New visualizers should extend this class and override its methods as neeeded.
10  """
11 
12  def __init__(self, model = pin.Model(), collision_model = None, visual_model = None, copy_models = False, data = None, collision_data = None, visual_data = None):
13  """Construct a display from the given model, collision model, and visual model.
14  If copy_models is True, the models are copied. Otherwise, they are simply kept as a reference."""
15 
16  if copy_models:
17  self.model = model.copy()
18  self.collision_model = collision_model.copy()
19  self.visual_model = visual_model.copy()
20  else:
21  self.model = model
22  self.collision_model = collision_model
23  self.visual_model = visual_model
24 
25  if data is None:
26  self.data = self.model.createData()
27  else:
28  self.data = data
29 
30  if collision_data is None:
31  self.collision_data = self.collision_model.createData()
32  else:
33  self.collision_data = collision_data
34 
35  if visual_data is None:
36  self.visual_data = self.visual_model.createData()
37  else:
38  self.visual_data = visual_data
39 
40  def rebuildData(self):
41  """Re-build the data objects. Needed if the models were modified.
42  Warning: this will delete any information stored in all data objects."""
43  self.data, self.collision_data, self.visual_data = createDatas(self.model, self.collision_model, self.visual_model)
44 
45  def getViewerNodeName(self, geometry_object, geometry_type):
46  """Return the name of the geometry object inside the viewer."""
47  pass
48 
49  def initViewer(self, *args, **kwargs):
50  """Init the viewer by loading the gui and creating a window."""
51  pass
52 
53  def loadViewerModel(self, *args, **kwargs):
54  """Create the scene displaying the robot meshes in the viewer"""
55  pass
56 
57  def reload(self, new_geometry_object, geometry_type = None):
58  """ Reload a geometry_object given by its type"""
59  pass
60 
61  def clean(self):
62  """ Delete all the objects from the whole scene """
63  pass
64 
65  def display(self, q = None):
66  """Display the robot at configuration q or refresh the rendering
67  from the current placements contained in data by placing all the bodies in the viewer."""
68  pass
69 
70  def displayCollisions(self,visibility):
71  """Set whether to display collision objects or not."""
72  pass
73 
74  def displayVisuals(self,visibility):
75  """Set whether to display visual objects or not."""
76  pass
77 
78  def play(self, q_trajectory, dt):
79  """Play a trajectory with given time step."""
80  for k in range(q_trajectory.shape[1]):
81  t0 = time.time()
82  self.display(q_trajectory[:, k])
83  t1 = time.time()
84  elapsed_time = t1 - t0
85  if elapsed_time < dt:
86  time.sleep(dt - elapsed_time)
87 
88 __all__ = ['BaseVisualizer']
def getViewerNodeName(self, geometry_object, geometry_type)
def reload(self, new_geometry_object, geometry_type=None)
def createDatas(models)
Definition: shortcuts.py:52
def __init__(self, model=pin.Model(), collision_model=None, visual_model=None, copy_models=False, data=None, collision_data=None, visual_data=None)


pinocchio
Author(s):
autogenerated on Tue Jun 1 2021 02:45:02