1 from ..
import pinocchio_pywrap
as pin
2 from ..shortcuts
import buildModelsFromUrdf, createDatas
11 IMAGEIO_SUPPORT =
True 13 IMAGEIO_SUPPORT =
False 17 """Pinocchio visualizers are employed to easily display a model at a given configuration. 18 BaseVisualizer is not meant to be directly employed, but only to provide a uniform interface and a few common methods. 19 New visualizers should extend this class and override its methods as neeeded. 34 """Construct a display from the given model, collision model, and visual model. 35 If copy_models is True, the models are copied. Otherwise, they are simply kept as a reference.""" 56 if visual_data
is None and self.
visual_model is not None:
62 """Re-build the data objects. Needed if the models were modified. 63 Warning: this will delete any information stored in all data objects.""" 69 """Return the name of the geometry object inside the viewer.""" 73 """Init the viewer by loading the gui and creating a window.""" 77 """Create the scene displaying the robot meshes in the viewer""" 80 def reload(self, new_geometry_object, geometry_type=None):
81 """Reload a geometry_object given by its type""" 85 """Delete all the objects from the whole scene""" 89 """Display the robot at configuration q or refresh the rendering 90 from the current placements contained in data by placing all the bodies in the viewer.""" 94 """Set whether to display collision objects or not.""" 98 """Set whether to display visual objects or not.""" 99 raise NotImplementedError()
102 """Set the visualizer background color.""" 103 raise NotImplementedError()
106 """Set the camera target.""" 107 raise NotImplementedError()
110 """Set the camera's 3D position.""" 111 raise NotImplementedError()
114 """Set camera zoom value.""" 115 raise NotImplementedError()
118 """Set camera 6D pose using a 4x4 matrix.""" 119 raise NotImplementedError()
122 """Captures an image from the viewer and returns an RGB array.""" 126 raise NotImplementedError()
129 raise NotImplementedError()
132 """Draw current frame velocities.""" 133 raise NotImplementedError()
141 def play(self, q_trajectory, dt=None, callback=None, capture=False, **kwargs):
142 """Play a trajectory with given time step. Optionally capture RGB images and returns them.""" 143 nsteps = len(q_trajectory)
148 for i
in range(nsteps):
151 if callback
is not None:
152 callback(i, **kwargs)
160 elapsed_time = t1 - t0
161 if dt
is not None and elapsed_time < dt:
162 self.
sleep(dt - elapsed_time)
167 """Create a video recording context, generating the output filename if necessary. 169 Code inspired from https://github.com/petrikvladimir/RoboMeshCat. 171 if not IMAGEIO_SUPPORT:
172 import warnings, contextlib
173 warnings.warn(
"Video context cannot be created because imageio is not available.", UserWarning)
174 return contextlib.nullcontext()
176 if directory
is None:
177 from tempfile
import gettempdir
179 directory = gettempdir()
180 f_fmt =
"%Y%m%d_%H%M%S" 182 filename = time.strftime(
"{}.{}".format(f_fmt, ext))
183 filename = osp.join(directory, filename)
190 self.
vid_writer = imageio.get_writer(filename, fps=fps, **kwargs)
193 print(
"[Entering video recording context]")
198 self.
viz._video_writer =
None 201 __all__ = [
"BaseVisualizer"]
def setCameraPosition(self, position)
def getViewerNodeName(self, geometry_object, geometry_type)
def displayCollisions(self, visibility)
JointDataTpl< Scalar, Options, JointCollectionTpl > createData(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through CreateData visitor to create a JointDataTpl.
def has_video_writer(self)
def reload(self, new_geometry_object, geometry_type=None)
def display(self, q=None)
def play(self, q_trajectory, dt=None, callback=None, capture=False, kwargs)
def initViewer(self, args, kwargs)
def __init__(self, model=pin.Model(), collision_model=None, visual_model=None, copy_models=False, data=None, collision_data=None, visual_data=None)
def drawFrameVelocities(self, args, kwargs)
def create_video_ctx(self, filename=None, fps=30, directory=None, kwargs)
def __init__(self, viz, fps, filename, kwargs)
def setCameraTarget(self, target)
def displayVisuals(self, visibility)
def setCameraZoom(self, zoom)
def disableCameraControl(self)
def loadViewerModel(self, args, kwargs)
def enableCameraControl(self)
def captureImage(self, w=None, h=None)
def setCameraPose(self, pose=np.eye(4))
def setBackgroundColor(self, args, kwargs)