amino  1.0-beta2
Lightweight Robot Utility Library
scenewin.py
Go to the documentation of this file.
1 # Copyright (c) 2019, Colorado School of Mines
2 # All rights reserved.
3 #
4 # Author(s): Neil T. Dantam <ndantam@mines.edu>
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 #
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 #
13 # * Redistributions in binary form must reproduce the above
14 # copyright notice, this list of conditions and the following
15 # disclaimer in the documentation and/or other materials provided
16 # with the distribution.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
23 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
25 # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
27 # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
28 # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
29 # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 # SUCH DAMAGE.
31 
32 
35 """Scene Viewer Window"""
36 
37 import ctypes
38 from amino.mat import DVec
39 from amino.scenegraph import RxSg
40 from amino.kinematics import SceneFK
41 from amino.util import ensure_cstring
42 
43 LIBAMINOGL = ctypes.CDLL("libamino-gl.so")
44 
45 
46 class RxWin(ctypes.Structure):
47  """Opaque type for scene window"""
48 
49 class SceneWin:
50  """Scene Viewer Window."""
51  __slots__ = ['_ptr', '_scenegraph', '_q']
52 
53  def __init__(self,
54  title="PyAmino",
55  width=800,
56  height=600,
57  start=True,
58  background=True,
59  scenegraph=None,
60  config=None):
61  """Create a new window.
62 
63  Args:
64  title: the window title
65  width: window width in pixels
66  height: window width in pixels
67  start: whether to immediatly start the window
68  background: whether to run the window in an asynchronous background thread
69  scenegraph: scene to display
70  config: configuration of the scene
71  """
72  title = ensure_cstring(title)
73  self._ptr_ptr = LIBAMINOGL.aa_rx_win_default_create(title, width, height)
74  self._q_q = None
75  self._scenegraph_scenegraph = None
76 
77  if scenegraph:
78  self.scenegraphscenegraphscenegraphscenegraph = scenegraph
79  if config:
80  self.configconfigconfigconfig = config
81  if start:
82  self.startstart(background)
83 
84  def __del__(self):
85  LIBAMINOGL.aa_rx_win_destroy(self._ptr_ptr)
86 
87  def start(self, background=False):
88  """Start the window.
89 
90  Args:
91  background: whether to run the window in an asynchronous background thread
92  """
93 
94  if background:
95  LIBAMINOGL.aa_rx_win_run_async()
96  else:
97  LIBAMINOGL.aa_rx_win_run()
98 
99  @property
100  def scenegraph(self):
101  """The displayed scenegraph."""
102  return self._scenegraph_scenegraph
103 
104  @scenegraph.setter
105  def scenegraph(self, scenegraph):
106  self._scenegraph_scenegraph = scenegraph
107  self._q_q = DVec(scenegraph.config_count)
108  LIBAMINOGL.aa_rx_win_set_sg(self._ptr_ptr, scenegraph._ptr)
109 
110  @property
111  def config(self):
112  """The current configuration."""
113  return DVec(self._q_q)
114 
115  @config.setter
116  def config(self, config):
117  self._q_q = self._scenegraph_scenegraph.config_vector(config, self._q_q)
118  LIBAMINOGL.aa_rx_win_set_bconfig(self._ptr_ptr, self._q_q)
119 
120  @property
121  def fk(self):
122  """The current configuration FK."""
123  fk = SceneFK(self._scenegraph_scenegraph)
124  fk.config = self._q_q
125  return fk
126 
127  @fk.setter
128  def fk(self, value):
129  self.configconfigconfigconfig = value.config
130 
131  def stop(self):
132  """Stop the window."""
133  LIBAMINOGL.aa_rx_win_stop(self._ptr_ptr)
134 
135  def is_runnining(self):
136  """Returns True if the window is still running."""
137  return bool(LIBAMINOGL.aa_rx_win_is_running(self._ptr_ptr))
138 
139  def lock(self):
140  """Lock the window"""
141  LIBAMINOGL.aa_rx_win_lock(self._ptr_ptr)
142 
143  def unlock(self):
144  """Lock the window"""
145  LIBAMINOGL.aa_rx_win_unlock(self._ptr_ptr)
146 
147 
148 LIBAMINOGL.aa_gl_init.argtypes = []
149 
150 LIBAMINOGL.aa_rx_win_default_create.argtypes = [
151  ctypes.c_char_p, ctypes.c_int, ctypes.c_int
152 ]
153 LIBAMINOGL.aa_rx_win_default_create.restype = ctypes.POINTER(RxWin)
154 
155 LIBAMINOGL.aa_rx_win_destroy.argtypes = [ctypes.POINTER(RxWin)]
156 
157 LIBAMINOGL.aa_rx_win_set_bconfig.argtypes = [
158  ctypes.POINTER(RxWin), ctypes.POINTER(DVec)
159 ]
160 
161 LIBAMINOGL.aa_rx_win_run.argtypes = []
162 LIBAMINOGL.aa_rx_win_run_async.argtypes = []
163 LIBAMINOGL.aa_rx_win_stop.argtypes = [ctypes.POINTER(RxWin)]
164 
165 LIBAMINOGL.aa_rx_win_set_sg.argtypes = [
166  ctypes.POINTER(RxWin), ctypes.POINTER(RxSg)
167 ]
168 
169 LIBAMINOGL.aa_rx_win_is_running.argtypes = [ctypes.POINTER(RxWin)]
170 LIBAMINOGL.aa_rx_win_is_running.restype = ctypes.c_int
171 
172 LIBAMINOGL.aa_rx_win_lock.argtypes = [ctypes.POINTER(RxWin)]
173 LIBAMINOGL.aa_rx_win_unlock.argtypes = [ctypes.POINTER(RxWin)]
Vector of double floats.
Definition: mat.py:49
def start(self, background=False)
Start the window.
Definition: scenewin.py:92
def fk(self)
The current configuration FK.
Definition: scenewin.py:122
def __init__(self, title="PyAmino", width=800, height=600, start=True, background=True, scenegraph=None, config=None)
Create a new window.
Definition: scenewin.py:71
def scenegraph(self, scenegraph)
Definition: scenewin.py:105
def config(self)
The current configuration.
Definition: scenewin.py:112
def is_runnining(self)
Returns True if the window is still running.
Definition: scenewin.py:136
def scenegraph(self)
The displayed scenegraph.
Definition: scenewin.py:101
def stop(self)
Stop the window.
Definition: scenewin.py:132
def config(self, config)
Definition: scenewin.py:116
def lock(self)
Lock the window.
Definition: scenewin.py:140
def unlock(self)
Lock the window.
Definition: scenewin.py:144
Definition: mat.py:1