Skip to content
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ set(python_files
director/thirdparty/naming.py
director/thirdparty/pysdf.py
director/thirdparty/toposort.py
director/thirdparty/umsgpack.py
director/thirdparty/msgpack_numpy.py

urdf_parser_py/__init__.py
urdf_parser_py/sdf.py
Expand Down
8 changes: 5 additions & 3 deletions src/python/director/drakevisualizerapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ def main(globalsDict=None):
fact.register(mainwindowapp.MainWindowAppFactory)
fact.register(mainwindowapp.MainWindowPanelFactory)

args = drcargs.args()
options = fact.getDefaultOptions()
fact.setDependentOptions(options,
useTreeViewer=HAVE_LCMRL,
useDrakeVisualizer=True,
useLCMGLRenderer=True)
useLCMTreeViewer=HAVE_LCMRL and args.treeviewer_lcm,
useZMQTreeViewer=args.treeviewer_zmq_url,
useDrakeVisualizer=args.drakevisualizer_lcm,
useLCMGLRenderer=args.lcmgl_renderer)

fields = fact.construct(
options=options,
Expand Down
18 changes: 18 additions & 0 deletions src/python/director/drcargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,24 @@ def addDefaultArgs(self, parser):
default=[], action='append', metavar='filename',
help='python scripts to run at startup')

parser.add_argument('--treeviewer-zmq-url', type=str,
dest='treeviewer_zmq_url', default='tcp://*:57370')

tvlcm_parser = parser.add_mutually_exclusive_group(required=False)
tvlcm_parser.add_argument('--treeviewer-lcm', action='store_true', dest='treeviewer_lcm')
tvlcm_parser.add_argument('--no-treeviewer-lcm', action='store_false', dest='treeviewer_lcm')
parser.set_defaults(treeviewer_lcm=True)

dvlcm_parser = parser.add_mutually_exclusive_group(required=False)
dvlcm_parser.add_argument('--drakevisualizer-lcm', action='store_true', dest='drakevisualizer_lcm')
dvlcm_parser.add_argument('--no-drakevisualizer-lcm', action='store_false', dest='drakevisualizer_lcm')
parser.set_defaults(drakevisualizer_lcm=True)

lcmgl_parser = parser.add_mutually_exclusive_group(required=False)
lcmgl_parser.add_argument('--lcmgl-renderer', action='store_true', dest='lcmgl_renderer')
lcmgl_parser.add_argument('--no-lcmgl-renderer', action='store_false', dest='lcmgl_renderer')
parser.set_defaults(lcmgl_renderer=True)


_argParser = None
def getGlobalArgParser():
Expand Down
25 changes: 20 additions & 5 deletions src/python/director/mainwindowapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def __init__(self):

self.mainWindow = QtGui.QMainWindow()
self.mainWindow.resize(768 * (16/9.0), 768)
self.mainWindow.setAttribute(QtCore.Qt.WA_ShowWithoutActivating)
self.settings = QtCore.QSettings()

self.fileMenu = self.mainWindow.menuBar().addMenu('&File')
Expand Down Expand Up @@ -350,14 +351,16 @@ def getComponents(self):
'OutputConsole' : ['MainWindow'],
'UndoRedo' : ['MainWindow'],
'DrakeVisualizer' : ['MainWindow'],
'TreeViewer' : ['MainWindow'],
'LCMTreeViewer' : ['MainWindow'],
'ZMQTreeViewer' : ['MainWindow'],
'LCMGLRenderer' : ['MainWindow']}

# these components depend on lcm and lcmgl
# so they are disabled by default
disabledComponents = [
'DrakeVisualizer',
'TreeViewer',
'LCMTreeViewer',
'ZMQTreeViewer',
'LCMGLRenderer']

return components, disabledComponents
Expand Down Expand Up @@ -460,15 +463,27 @@ def initDrakeVisualizer(self, fields):
drakeVisualizer=drakeVisualizer
)

def initTreeViewer(self, fields):
def initLCMTreeViewer(self, fields):

from director import treeviewer
treeViewer = treeviewer.TreeViewer(fields.view)
treeViewer = treeviewer.LCMTreeViewer(fields.view)

applogic.MenuActionToggleHelper('Tools', treeViewer.name, treeViewer.isEnabled, treeViewer.setEnabled)

return FieldContainer(
treeViewer=treeViewer
lcmTreeViewer=treeViewer
)

def initZMQTreeViewer(self, fields):

from director import treeviewer
args = drcargs.args()
treeViewer = treeviewer.ZMQTreeViewer(fields.view, zmqUrl=args.treeviewer_zmq_url)

applogic.MenuActionToggleHelper('Tools', treeViewer.name, treeViewer.isEnabled, treeViewer.setEnabled)

return FieldContainer(
zmqTreeViewer=treeViewer
)

def initLCMGLRenderer(self, fields):
Expand Down
1 change: 1 addition & 0 deletions src/python/director/taskrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def callOnMain(self, func, *args, **kwargs):

def callOnThread(self, func, *args, **kwargs):
t = Thread(target=lambda: func(*args, **kwargs))
t.daemon = True # daemon kwarg doesn't exist in python 2.7
self.threads.append(t)
t.start()
self.timer.start()
Expand Down
111 changes: 111 additions & 0 deletions src/python/director/thirdparty/msgpack_numpy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/usr/bin/env python

"""
Support for serialization of numpy data types with msgpack.
"""

# Copyright (c) 2013-2017, Lev E. Givon.
# All rights reserved.

# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:

# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Lev E. Givon nor the names of any
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
# Modified by Robin Deits (2017):
# * Removed all explicit references to msgpack so that this can be used
# with umsgpack instead


import sys

import numpy as np

def encode(obj, chain=None):
"""
Data encoder for serializing numpy data types.
"""

if isinstance(obj, np.ndarray):
# If the dtype is structured, store the interface description;
# otherwise, store the corresponding array protocol type string:
if obj.dtype.kind == 'V':
kind = b'V'
descr = obj.dtype.descr
else:
kind = b''
descr = obj.dtype.str
return {b'nd': True,
b'type': descr,
b'kind': kind,
b'shape': obj.shape,
b'data': obj.tobytes()}
elif isinstance(obj, (np.bool_, np.number)):
return {b'nd': False,
b'type': obj.dtype.str,
b'data': obj.tobytes()}
elif isinstance(obj, complex):
return {b'complex': True,
b'data': obj.__repr__()}
else:
return obj if chain is None else chain(obj)

def tostr(x):
if sys.version_info >= (3, 0):
if isinstance(x, bytes):
return x.decode()
else:
return str(x)
else:
return x

def decode(obj, chain=None):
"""
Decoder for deserializing numpy data types.
"""

try:
if b'nd' in obj:
if obj[b'nd'] is True:

# Check if b'kind' is in obj to enable decoding of data
# serialized with older versions (#20):
if b'kind' in obj and obj[b'kind'] == b'V':
descr = [tuple(tostr(t) if type(t) is bytes else t for t in d) \
for d in obj[b'type']]
else:
descr = obj[b'type']
return np.fromstring(obj[b'data'],
dtype=np.dtype(descr)).reshape(obj[b'shape'])
else:
descr = obj[b'type']
return np.fromstring(obj[b'data'],
dtype=np.dtype(descr))[0]
elif b'complex' in obj:
return complex(tostr(obj[b'data']))
else:
return obj if chain is None else chain(obj)
except KeyError:
return obj if chain is None else chain(obj)
Loading