rational-linkages 2.2.0__cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl → 2.2.3__cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -40,14 +40,16 @@ class MotionDesigner:
40
40
 
41
41
  :examples:
42
42
 
43
- .. testcode:: [motiondesigner_example1]
43
+ Run motion designer without initial points or poses:
44
+
45
+ .. testcode:: [motiondesigner_ex1]
44
46
 
45
47
  from rational_linkages import MotionDesigner
46
48
 
47
49
  d = MotionDesigner(method='quadratic_from_poses')
48
50
  d.show()
49
51
 
50
- .. testoutput:: [motiondesigner_example1]
52
+ .. testoutput:: [motiondesigner_ex1]
51
53
  :hide:
52
54
 
53
55
  Closing the window... generated points for interpolation:
@@ -55,11 +57,15 @@ class MotionDesigner:
55
57
  [ 1. , -0.207522406 , -0.0333866662, -0.0691741237, -0.0625113682, -0.141265791 , -0.4478576802, -0.2637268902]
56
58
  [ 1. , 0.2333739522, -0.0427838517, 0.0777914503, -0.0839342318, 0.2991396249, 0.2980046603, 0.345444421 ]
57
59
 
58
- .. testcleanup:: [motiondesigner_example1]
60
+ .. testcleanup:: [motiondesigner_ex1]
59
61
 
60
62
  del d, MotionDesigner
61
63
 
62
- .. testcode:: [motiondesigner_example2]
64
+ Run motion designer with initial points:
65
+
66
+ .. code-block:: python
67
+
68
+ # NOT TESTED
63
69
 
64
70
  from rational_linkages import MotionDesigner, PointHomogeneous
65
71
 
@@ -76,19 +82,6 @@ class MotionDesigner:
76
82
  d = MotionDesigner(method='quadratic_from_points', initial_points_or_poses=chosen_points)
77
83
  d.show()
78
84
 
79
- .. testoutput:: [motiondesigner_example2]
80
- :hide:
81
-
82
- Closing the window... generated points for interpolation:
83
- [ 1. , -0.2 , 0. , 1.76]
84
- [1., 1., 1., 2.]
85
- [ 1., 3., -3., 1.]
86
- [ 1., 2., -4., 1.]
87
- [ 1., -2., -2., 2.]
88
-
89
- .. testcleanup:: [motiondesigner_example2]
90
-
91
- del d, MotionDesigner, PointHomogeneous, chosen_points
92
85
 
93
86
  """
94
87
  def __init__(self,
@@ -137,544 +130,548 @@ class MotionDesigner:
137
130
  except SystemExit:
138
131
  pass
139
132
 
140
- class MotionDesignerWidget(QtWidgets.QWidget):
141
- """
142
- Interactive plotting widget for designing motion curves with interpolated points.
143
-
144
- A widget that displays a 3D view of a motion curve and control points,
145
- plus a side panel with controls for selecting and modifying one of the
146
- control points (p0 to p6). Moving the sliders adjusts the x, y, and z
147
- coordinates of the selected control point, which then updates the curve.
148
- """
149
- def __init__(self,
150
- method: str = 'cubic_from_points',
151
- initial_pts: Union[list[PointHomogeneous], list[DualQuaternion]] = None,
152
- parent = None,
153
- steps: int = 1000,
154
- interval: tuple = (0, 1),
155
- arrows_length: float = 1.0,
156
- white_background: bool = False):
133
+ if QtWidgets is not None:
134
+ class MotionDesignerWidget(QtWidgets.QWidget):
157
135
  """
158
- Initialize the motion designer widget.
136
+ Interactive plotting widget for designing motion curves with interpolated points.
137
+
138
+ A widget that displays a 3D view of a motion curve and control points,
139
+ plus a side panel with controls for selecting and modifying one of the
140
+ control points (p0 to p6). Moving the sliders adjusts the x, y, and z
141
+ coordinates of the selected control point, which then updates the curve.
159
142
  """
160
- super().__init__(parent)
161
- self.setMinimumSize(900, 600)
162
-
163
- self.white_background = white_background
164
- self.points = self._initialize_points(method, initial_pts)
165
- self.method = method
166
- self.arrows_length = arrows_length
167
- self.mi = MotionInterpolation()
168
-
169
- # an instance of Pyqtgraph-based plotter
170
- self.plotter = PlotterPyqtgraph(steps=steps,
171
- interval=interval,
172
- arrows_length=self.arrows_length,
173
- white_background=self.white_background)
174
-
175
- self.mechanism_plotter = []
176
-
177
- if self.white_background:
178
- self.render_mode = 'opaque'
179
- else:
180
- self.render_mode = 'additive'
181
-
182
- self.previous_rpy_sliders_values = []
183
-
184
- # array of control point coordinates (in 3D)
185
- if method == 'quadratic_from_points' or method == 'cubic_from_points':
186
- self.plotted_points = np.array([pt.normalized_in_3d()
187
- for pt in self.points])
188
-
189
- # interpolated points markers
190
- self.markers = gl.GLScatterPlotItem(pos=self.plotted_points,
191
- color=(1, 0, 1, 1),
192
- glOptions=self.render_mode,
193
- size=10)
194
- self.plotter.widget.addItem(self.markers)
195
-
196
- for i, pt in enumerate(self.plotted_points):
197
- self.plotter.widget.add_label(pt, f"p{i}")
198
-
199
- elif method == 'quadratic_from_poses' or method == 'cubic_from_poses':
200
- poses_arrays = [TransfMatrix(pt.dq2matrix()) for pt in self.points]
201
- self.plotted_poses = [FramePlotHelper(transform=tr,
202
- width=10,
203
- length=2 * self.arrows_length)
204
- for tr in poses_arrays]
205
- for i, pose in enumerate(self.plotted_poses):
206
- pose.addToView(self.plotter.widget)
207
- self.plotter.widget.add_label(pose, f"p{i}")
208
- self.previous_rpy_sliders_values.append(pose.tr.rpy() * 100)
209
-
210
- self.curve_path_vis = None # path of motion curve
211
- self.curve_frames_vis = None # poses of motion curve
212
- self.lambda_val = 0.0
213
- self.motion_family_idx = 0
214
- self.update_curve_vis() # initial curve update
215
-
216
- ###################################
217
- # --- build the Control Panel --- #
218
- def create_separator():
143
+ def __init__(self,
144
+ method: str = 'cubic_from_points',
145
+ initial_pts: Union[list[PointHomogeneous], list[DualQuaternion]] = None,
146
+ parent = None,
147
+ steps: int = 1000,
148
+ interval: tuple = (0, 1),
149
+ arrows_length: float = 1.0,
150
+ white_background: bool = False):
219
151
  """
220
- Create a horizontal line separator (QFrame).
152
+ Initialize the motion designer widget.
221
153
  """
222
- separator = QtWidgets.QFrame()
223
- separator.setFrameShape(QtWidgets.QFrame.Shape.HLine)
224
- separator.setFrameShadow(QtWidgets.QFrame.Shadow.Sunken)
225
- return separator
226
-
227
- # combo box to select one of the points
228
- self.point_combo = QtWidgets.QComboBox()
229
- for i in range(1, len(self.points)):
230
- self.point_combo.addItem(f"Point {i}")
231
- self.point_combo.currentIndexChanged.connect(self.on_point_selection_changed)
232
-
233
- # sliders for adjusting x, y, and z
234
- self.slider_x = QtWidgets.QSlider(QtCore.Qt.Orientation.Horizontal)
235
- self.textbox_x = QtWidgets.QLineEdit()
236
- self.textbox_x.editingFinished.connect(
237
- lambda: self.on_textbox_changed(self.textbox_x.text(), self.slider_x)
238
- )
239
- self.slider_y = QtWidgets.QSlider(QtCore.Qt.Orientation.Horizontal)
240
- self.textbox_y = QtWidgets.QLineEdit()
241
- self.textbox_y.editingFinished.connect(
242
- lambda: self.on_textbox_changed(self.textbox_y.text(), self.slider_y)
243
- )
244
- self.slider_z = QtWidgets.QSlider(QtCore.Qt.Orientation.Horizontal)
245
- self.textbox_z = QtWidgets.QLineEdit()
246
- self.textbox_z.editingFinished.connect(
247
- lambda: self.on_textbox_changed(self.textbox_z.text(), self.slider_z)
248
- )
249
- # slider range
250
- for slider, textbox in [(self.slider_x, self.textbox_x),
251
- (self.slider_y, self.textbox_y),
252
- (self.slider_z, self.textbox_z)]:
253
- slider.setMinimum(-1000)
254
- slider.setMaximum(1000)
255
- slider.setSingleStep(1)
256
- slider.valueChanged.connect(self.on_slider_value_changed)
257
-
258
- if method == 'quadratic_from_poses' or method == 'cubic_from_poses':
259
- # sliders for adjusting roll, pitch, and yaw with textboxes
260
- self.slider_roll = QtWidgets.QSlider(QtCore.Qt.Orientation.Horizontal)
261
- self.textbox_roll = QtWidgets.QLineEdit()
262
- self.textbox_roll.editingFinished.connect(
263
- lambda: self.on_textbox_changed(self.textbox_roll.text(), self.slider_roll)
264
- )
265
- self.slider_pitch = QtWidgets.QSlider(QtCore.Qt.Orientation.Horizontal)
266
- self.textbox_pitch = QtWidgets.QLineEdit()
267
- self.textbox_pitch.editingFinished.connect(
268
- lambda: self.on_textbox_changed(self.textbox_pitch.text(), self.slider_pitch)
269
- )
270
- self.slider_yaw = QtWidgets.QSlider(QtCore.Qt.Orientation.Horizontal)
271
- self.textbox_yaw = QtWidgets.QLineEdit()
272
- self.textbox_yaw.editingFinished.connect(
273
- lambda: self.on_textbox_changed(self.textbox_yaw.text(), self.slider_yaw)
274
- )
154
+ super().__init__(parent)
155
+ self.setMinimumSize(900, 600)
275
156
 
276
- self.slider_roll_prev = 0
277
- self.slider_pitch_prev = 0
278
- self.slider_yaw_prev = 0
157
+ self.white_background = white_background
158
+ self.points = self._initialize_points(method, initial_pts)
159
+ self.method = method
160
+ self.arrows_length = arrows_length
161
+ self.mi = MotionInterpolation()
279
162
 
280
- # slider range
281
- for slider, textbox in [(self.slider_roll, self.textbox_roll),
282
- (self.slider_pitch, self.textbox_pitch),
283
- (self.slider_yaw, self.textbox_yaw)]:
284
- slider.setMinimum(int(-np.pi * 100))
285
- slider.setMaximum(int(np.pi * 100))
286
- slider.setSingleStep(1)
287
- slider.valueChanged.connect(self.on_slider_value_changed)
163
+ # an instance of Pyqtgraph-based plotter
164
+ self.plotter = PlotterPyqtgraph(steps=steps,
165
+ interval=interval,
166
+ arrows_length=self.arrows_length,
167
+ white_background=self.white_background)
288
168
 
289
- # slider for lambda of cubic curve with textbox
290
- if method == 'cubic_from_poses':
291
- self.slider_lambda = QtWidgets.QSlider(QtCore.Qt.Orientation.Horizontal)
292
- self.textbox_lambda = QtWidgets.QLineEdit()
169
+ self.mechanism_plotter = []
293
170
 
294
- self.slider_lambda.setMinimum(int(-500))
295
- self.slider_lambda.setMaximum(int(500))
296
- self.slider_lambda.setSingleStep(1)
171
+ if self.white_background:
172
+ self.render_mode = 'opaque'
173
+ else:
174
+ self.render_mode = 'additive'
297
175
 
298
- self.slider_lambda.valueChanged.connect(self.on_lambda_slider_value_changed)
299
- self.textbox_lambda.editingFinished.connect(
300
- lambda: self.on_lambda_textbox_changed(self.textbox_lambda.text(),
301
- self.slider_lambda))
176
+ self.previous_rpy_sliders_values = []
302
177
 
303
- # add button for swapping family
304
- self.swap_family_check_box = QtWidgets.QCheckBox(text="Swap family")
178
+ # array of control point coordinates (in 3D)
179
+ if method == 'quadratic_from_points' or method == 'cubic_from_points':
180
+ self.plotted_points = np.array([pt.normalized_in_3d()
181
+ for pt in self.points])
182
+
183
+ # interpolated points markers
184
+ self.markers = gl.GLScatterPlotItem(pos=self.plotted_points,
185
+ color=(1, 0, 1, 1),
186
+ glOptions=self.render_mode,
187
+ size=10)
188
+ self.plotter.widget.addItem(self.markers)
189
+
190
+ for i, pt in enumerate(self.plotted_points):
191
+ self.plotter.widget.add_label(pt, f"p{i}")
192
+
193
+ elif method == 'quadratic_from_poses' or method == 'cubic_from_poses':
194
+ poses_arrays = [TransfMatrix(pt.dq2matrix()) for pt in self.points]
195
+ self.plotted_poses = [FramePlotHelper(transform=tr,
196
+ width=10,
197
+ length=2 * self.arrows_length)
198
+ for tr in poses_arrays]
199
+ for i, pose in enumerate(self.plotted_poses):
200
+ pose.addToView(self.plotter.widget)
201
+ self.plotter.widget.add_label(pose, f"p{i}")
202
+ self.previous_rpy_sliders_values.append(pose.tr.rpy() * 100)
203
+
204
+ self.curve_path_vis = None # path of motion curve
205
+ self.curve_frames_vis = None # poses of motion curve
206
+ self.lambda_val = 0.0
305
207
  self.motion_family_idx = 0
306
- self.swap_family_check_box.stateChanged.connect(self.on_swap_family_check_box_changed)
307
- else:
308
- self.slider_lambda = None
309
- self.swap_family_check_box = None
310
- self.textbox_lambda = None
311
-
312
- # add button for mechanism synthesis
313
- self.synthesize_button = QtWidgets.QPushButton("Mechanism")
314
- self.synthesize_button.clicked.connect(self.on_synthesize_button_clicked)
315
-
316
- # initially for the first point
317
- self.set_sliders_for_point(0)
318
-
319
- # --- layout the 3D view and control panel ---
320
- main_layout = QtWidgets.QHBoxLayout(self)
321
- # add plotter (stored in self.plotter.widget)
322
- main_layout.addWidget(self.plotter.widget, stretch=1)
323
-
324
- # Build a vertical control panel.
325
- control_panel = QtWidgets.QWidget()
326
- cp_layout = QtWidgets.QVBoxLayout(control_panel)
327
-
328
- cp_layout.addWidget(QtWidgets.QLabel("Select control point:"))
329
- cp_layout.addWidget(self.point_combo)
330
- cp_layout.addSpacing(10)
331
-
332
- cp_layout.addWidget(QtWidgets.QLabel("Adjust X:"))
333
- cp_layout.addWidget(self.slider_x)
334
- cp_layout.addWidget(self.textbox_x)
335
- cp_layout.addWidget(QtWidgets.QLabel("Adjust Y:"))
336
- cp_layout.addWidget(self.slider_y)
337
- cp_layout.addWidget(self.textbox_y)
338
- cp_layout.addWidget(QtWidgets.QLabel("Adjust Z:"))
339
- cp_layout.addWidget(self.slider_z)
340
- cp_layout.addWidget(self.textbox_z)
341
- if method == 'quadratic_from_poses' or method == 'cubic_from_poses':
342
- cp_layout.addSpacing(10) # Add 10 pixels of space before the separator
343
- cp_layout.addWidget(create_separator())
344
- cp_layout.addWidget(QtWidgets.QLabel("Rotate X:"))
345
- cp_layout.addWidget(self.slider_roll)
346
- cp_layout.addWidget(self.textbox_roll)
347
- cp_layout.addWidget(QtWidgets.QLabel("Rotate Y:"))
348
- cp_layout.addWidget(self.slider_pitch)
349
- cp_layout.addWidget(self.textbox_pitch)
350
- cp_layout.addWidget(QtWidgets.QLabel("Rotate Z:"))
351
- cp_layout.addWidget(self.slider_yaw)
352
- cp_layout.addWidget(self.textbox_yaw)
353
- if method == 'cubic_from_poses':
354
- cp_layout.addSpacing(10) # Add 10 pixels of space before the separator
355
- cp_layout.addWidget(create_separator())
356
- cp_layout.addSpacing(10)
357
- cp_layout.addWidget(self.swap_family_check_box)
358
- cp_layout.addWidget(QtWidgets.QLabel("Lambda:"))
359
- cp_layout.addWidget(self.slider_lambda)
360
- cp_layout.addWidget(self.textbox_lambda)
361
-
362
- cp_layout.addSpacing(20)
363
- cp_layout.addWidget(self.synthesize_button)
364
-
365
- cp_layout.addStretch(1)
366
-
367
- main_layout.addWidget(control_panel)
368
- self.setLayout(main_layout)
369
- self.setWindowTitle("Motion Designer")
370
-
371
- def _initialize_points(self, method, initial_pts):
372
- predefined_points = {
373
- 'cubic_from_points': [
374
- PointHomogeneous(),
375
- PointHomogeneous([1, 1, 1, 0.3]),
376
- PointHomogeneous([1, 3, -3, 0.5]),
377
- PointHomogeneous([1, 0.5, -7, 1]),
378
- PointHomogeneous([1, -3.2, -7, 4]),
379
- PointHomogeneous([1, -7, -3, 2]),
380
- PointHomogeneous([1, -8, 3, 0.5])
381
- ],
382
- 'cubic_from_poses': [
383
- DualQuaternion(),
384
- DualQuaternion([0, 0, 0, 1, 1, 0, 1, 0]),
385
- DualQuaternion([1, 2, 0, 0, -2, 1, 0, 0]),
386
- DualQuaternion([3, 0, 1, 0, 1, 0, -3, 0])
387
- ],
388
- 'quadratic_from_points': [
389
- PointHomogeneous(),
390
- PointHomogeneous([1, 1, 1, 2]),
391
- PointHomogeneous([1, 3, -3, 1]),
392
- PointHomogeneous([1, 2, -4, 1]),
393
- PointHomogeneous([1, -2, -2, 2])
394
- ],
395
- 'quadratic_from_poses': [
396
- DualQuaternion(),
397
- DualQuaternion(
398
- TransfMatrix.from_vectors(
399
- approach_z=[-0.0362862, 0.400074, 0.915764],
400
- normal_x=[0.988751, -0.118680, 0.0910266],
401
- origin=[0.33635718, 0.9436004, 0.3428654]).matrix2dq()),
402
- DualQuaternion(
403
- TransfMatrix.from_vectors(
404
- approach_z=[-0.0463679, -0.445622, 0.894020],
405
- normal_x=[0.985161, 0.127655, 0.114724],
406
- origin=[-0.52857769, -0.4463076, -0.81766]).matrix2dq()),
407
- ]
408
- }
409
-
410
- required_points = {
411
- 'cubic_from_points': 7,
412
- 'cubic_from_poses': 4,
413
- 'quadratic_from_points': 5,
414
- 'quadratic_from_poses': 3
415
- }
416
-
417
- if method not in predefined_points:
418
- raise ValueError(f"Unknown method: {method}")
419
-
420
- if initial_pts is None:
421
- return predefined_points[method]
422
-
423
- if len(initial_pts) != required_points[method]:
424
- raise ValueError(
425
- f"For a {method.replace('_', ' ')}, {required_points[method]} points are needed.")
426
-
427
- return initial_pts
428
-
429
- def set_sliders_for_point(self, index):
430
- """
431
- Set the slider positions to reflect the current coordinates of the
432
- control point with the given index.
433
- (Here we assume that coordinates are in the range roughly –10..10.)
434
- """
435
- index = index + 1 # skip the first point/pose
436
- sliders = [self.slider_x, self.slider_y, self.slider_z]
437
- text_boxes = [self.textbox_x, self.textbox_y, self.textbox_z]
438
- if self.method == 'quadratic_from_points' or self.method == 'cubic_from_points':
439
- pt = self.plotted_points[index]
440
- values = [int(pt[i] * 100) for i in range(3)]
441
- else:
442
- sliders.extend([self.slider_roll, self.slider_pitch, self.slider_yaw])
443
- text_boxes.extend([self.textbox_roll, self.textbox_pitch, self.textbox_yaw])
444
- pt = self.plotted_poses[index]
445
- rpy = self.previous_rpy_sliders_values[index]
446
- values = [
447
- int(pt.tr.t[0] * 100),
448
- int(pt.tr.t[1] * 100),
449
- int(pt.tr.t[2] * 100),
450
- int(rpy[0]), # Roll
451
- int(rpy[1]), # Pitch
452
- int(rpy[2]) # Yaw
453
- ]
454
- (self.slider_roll_prev, self.slider_pitch_prev,
455
- self.slider_yaw_prev) = values[3:]
456
- #
457
- for slider, text_box, value in zip(sliders, text_boxes, values):
458
- slider.blockSignals(True)
459
- slider.setValue(value)
460
- text_box.setText(str(value / 100.0))
461
- slider.blockSignals(False)
462
-
463
- def on_synthesize_button_clicked(self):
464
- """
465
- Called when the "Synthesize mechanism" button is clicked. This method
466
- should be implemented to synthesize a mechanism based on the current
467
- control points.
468
- """
469
- if (self.method == 'quadratic_from_points'
470
- or self.method == 'cubic_from_points'
471
- or self.method == 'quadratic_from_poses'):
472
- c = MotionInterpolation.interpolate(self.points)
473
- else:
474
- p = MotionInterpolation.interpolate_cubic_numerically(
475
- self.points,
476
- lambda_val=self.lambda_val,
477
- k_idx=self.motion_family_idx)
478
- c = RationalCurve.from_coeffs(p)
479
- self.mechanism_plotter.append(
480
- InteractivePlotterWidget(mechanism=RationalMechanism(c.factorize()),
481
- arrows_length=self.arrows_length,
482
- parent_app=self.plotter.app))
483
- self.mechanism_plotter[-1].show()
484
-
485
-
486
- def on_point_selection_changed(self, index):
487
- """
488
- When a different point is selected in the combo box, update the slider
489
- positions to match that point’s coordinates.
490
- """
491
- self.set_sliders_for_point(index)
208
+ self.update_curve_vis() # initial curve update
209
+
210
+ ###################################
211
+ # --- build the Control Panel --- #
212
+ def create_separator():
213
+ """
214
+ Create a horizontal line separator (QFrame).
215
+ """
216
+ separator = QtWidgets.QFrame()
217
+ separator.setFrameShape(QtWidgets.QFrame.Shape.HLine)
218
+ separator.setFrameShadow(QtWidgets.QFrame.Shadow.Sunken)
219
+ return separator
220
+
221
+ # combo box to select one of the points
222
+ self.point_combo = QtWidgets.QComboBox()
223
+ for i in range(1, len(self.points)):
224
+ self.point_combo.addItem(f"Point {i}")
225
+ self.point_combo.currentIndexChanged.connect(self.on_point_selection_changed)
226
+
227
+ # sliders for adjusting x, y, and z
228
+ self.slider_x = QtWidgets.QSlider(QtCore.Qt.Orientation.Horizontal)
229
+ self.textbox_x = QtWidgets.QLineEdit()
230
+ self.textbox_x.editingFinished.connect(
231
+ lambda: self.on_textbox_changed(self.textbox_x.text(), self.slider_x)
232
+ )
233
+ self.slider_y = QtWidgets.QSlider(QtCore.Qt.Orientation.Horizontal)
234
+ self.textbox_y = QtWidgets.QLineEdit()
235
+ self.textbox_y.editingFinished.connect(
236
+ lambda: self.on_textbox_changed(self.textbox_y.text(), self.slider_y)
237
+ )
238
+ self.slider_z = QtWidgets.QSlider(QtCore.Qt.Orientation.Horizontal)
239
+ self.textbox_z = QtWidgets.QLineEdit()
240
+ self.textbox_z.editingFinished.connect(
241
+ lambda: self.on_textbox_changed(self.textbox_z.text(), self.slider_z)
242
+ )
243
+ # slider range
244
+ for slider, textbox in [(self.slider_x, self.textbox_x),
245
+ (self.slider_y, self.textbox_y),
246
+ (self.slider_z, self.textbox_z)]:
247
+ slider.setMinimum(-1000)
248
+ slider.setMaximum(1000)
249
+ slider.setSingleStep(1)
250
+ slider.valueChanged.connect(self.on_slider_value_changed)
492
251
 
493
- def on_slider_value_changed(self, value):
494
- """
495
- Called when any of the sliders change their value. Update the currently
496
- selected control point’s x, y, or z coordinate based on the slider values,
497
- update the control point markers, and then recalculate the motion curve.
498
- """
499
- index = self.point_combo.currentIndex() + 1
500
- # Convert slider values (integers) to floating‑point coordinates.
501
- new_x = self.slider_x.value() / 100.0
502
- new_y = self.slider_y.value() / 100.0
503
- new_z = self.slider_z.value() / 100.0
504
-
505
- self.textbox_x.setText(str(new_x))
506
- self.textbox_y.setText(str(new_y))
507
- self.textbox_z.setText(str(new_z))
508
-
509
- if self.method == 'quadratic_from_poses' or self.method == 'cubic_from_poses':
510
- if self.slider_roll.value() != self.slider_roll_prev:
511
- new_roll = (self.slider_roll.value() - self.slider_roll_prev) / 100.0
512
- new_mat = TransfMatrix.from_rotation('x', new_roll)
513
- new_tr = self.plotted_poses[index].tr * new_mat
514
- self.slider_roll_prev = self.slider_roll.value()
515
- self.textbox_roll.setText(str(self.slider_roll.value() / 100.0))
516
-
517
- elif self.slider_pitch.value() != self.slider_pitch_prev:
518
- new_pitch = (self.slider_pitch.value() - self.slider_pitch_prev) / 100.0
519
- new_mat = TransfMatrix.from_rotation('y', new_pitch)
520
- new_tr = self.plotted_poses[index].tr * new_mat
521
- self.slider_pitch_prev = self.slider_pitch.value()
522
- self.textbox_pitch.setText(str(self.slider_pitch.value() / 100.0))
523
-
524
- elif self.slider_yaw.value() != self.slider_yaw_prev:
525
- new_yaw = (self.slider_yaw.value() - self.slider_yaw_prev) / 100.0
526
- new_mat = TransfMatrix.from_rotation('z', new_yaw)
527
- new_tr = self.plotted_poses[index].tr * new_mat
528
- self.slider_yaw_prev = self.slider_yaw.value()
529
- self.textbox_yaw.setText(str(self.slider_yaw.value() / 100.0))
252
+ if method == 'quadratic_from_poses' or method == 'cubic_from_poses':
253
+ # sliders for adjusting roll, pitch, and yaw with textboxes
254
+ self.slider_roll = QtWidgets.QSlider(QtCore.Qt.Orientation.Horizontal)
255
+ self.textbox_roll = QtWidgets.QLineEdit()
256
+ self.textbox_roll.editingFinished.connect(
257
+ lambda: self.on_textbox_changed(self.textbox_roll.text(), self.slider_roll)
258
+ )
259
+ self.slider_pitch = QtWidgets.QSlider(QtCore.Qt.Orientation.Horizontal)
260
+ self.textbox_pitch = QtWidgets.QLineEdit()
261
+ self.textbox_pitch.editingFinished.connect(
262
+ lambda: self.on_textbox_changed(self.textbox_pitch.text(), self.slider_pitch)
263
+ )
264
+ self.slider_yaw = QtWidgets.QSlider(QtCore.Qt.Orientation.Horizontal)
265
+ self.textbox_yaw = QtWidgets.QLineEdit()
266
+ self.textbox_yaw.editingFinished.connect(
267
+ lambda: self.on_textbox_changed(self.textbox_yaw.text(), self.slider_yaw)
268
+ )
269
+
270
+ self.slider_roll_prev = 0
271
+ self.slider_pitch_prev = 0
272
+ self.slider_yaw_prev = 0
273
+
274
+ # slider range
275
+ for slider, textbox in [(self.slider_roll, self.textbox_roll),
276
+ (self.slider_pitch, self.textbox_pitch),
277
+ (self.slider_yaw, self.textbox_yaw)]:
278
+ slider.setMinimum(int(-np.pi * 100))
279
+ slider.setMaximum(int(np.pi * 100))
280
+ slider.setSingleStep(1)
281
+ slider.valueChanged.connect(self.on_slider_value_changed)
282
+
283
+ # slider for lambda of cubic curve with textbox
284
+ if method == 'cubic_from_poses':
285
+ self.slider_lambda = QtWidgets.QSlider(QtCore.Qt.Orientation.Horizontal)
286
+ self.textbox_lambda = QtWidgets.QLineEdit()
287
+
288
+ self.slider_lambda.setMinimum(int(-500))
289
+ self.slider_lambda.setMaximum(int(500))
290
+ self.slider_lambda.setSingleStep(1)
291
+
292
+ self.slider_lambda.valueChanged.connect(self.on_lambda_slider_value_changed)
293
+ self.textbox_lambda.editingFinished.connect(
294
+ lambda: self.on_lambda_textbox_changed(self.textbox_lambda.text(),
295
+ self.slider_lambda))
296
+
297
+ # add button for swapping family
298
+ self.swap_family_check_box = QtWidgets.QCheckBox(text="Swap family")
299
+ self.motion_family_idx = 0
300
+ self.swap_family_check_box.stateChanged.connect(self.on_swap_family_check_box_changed)
530
301
  else:
531
- new_tr = TransfMatrix.from_rpy_xyz(self.plotted_poses[index].tr.rpy(),
532
- [new_x, new_y, new_z])
302
+ self.slider_lambda = None
303
+ self.swap_family_check_box = None
304
+ self.textbox_lambda = None
533
305
 
534
- self.previous_rpy_sliders_values[index][0] = self.slider_roll.value()
535
- self.previous_rpy_sliders_values[index][1] = self.slider_pitch.value()
536
- self.previous_rpy_sliders_values[index][2] = self.slider_yaw.value()
306
+ # add button for mechanism synthesis
307
+ self.synthesize_button = QtWidgets.QPushButton("Mechanism")
308
+ self.synthesize_button.clicked.connect(self.on_synthesize_button_clicked)
537
309
 
538
- new_dq = DualQuaternion(new_tr.matrix2dq())
539
- self.points[index] = new_dq
540
- self.plotted_poses[index].setData(new_tr)
310
+ # initially for the first point
311
+ self.set_sliders_for_point(0)
541
312
 
542
- else:
543
- # update the selected control point
544
- self.points[index] = PointHomogeneous.from_3d_point([new_x, new_y, new_z])
545
- self.plotted_points[index] = np.array([new_x, new_y, new_z])
546
- # update the visual markers
547
- self.markers.setData(pos=self.plotted_points)
313
+ # --- layout the 3D view and control panel ---
314
+ main_layout = QtWidgets.QHBoxLayout(self)
315
+ # add plotter (stored in self.plotter.widget)
316
+ main_layout.addWidget(self.plotter.widget, stretch=1)
548
317
 
549
- # Recalculate and update the motion curve.
550
- self.update_curve_vis()
318
+ # Build a vertical control panel.
319
+ control_panel = QtWidgets.QWidget()
320
+ cp_layout = QtWidgets.QVBoxLayout(control_panel)
551
321
 
552
- def on_lambda_slider_value_changed(self, value):
553
- """
554
- Called when the lambda slider changes its value. Update the lambda value
555
- of the cubic curve, update the control point markers, and then recalculate
556
- the motion curve.
557
- """
558
- self.lambda_val = self.slider_lambda.value() / 100.0
559
- self.textbox_lambda.setText(str(self.lambda_val))
560
- self.update_curve_vis()
322
+ cp_layout.addWidget(QtWidgets.QLabel("Select control point:"))
323
+ cp_layout.addWidget(self.point_combo)
324
+ cp_layout.addSpacing(10)
561
325
 
562
- def on_swap_family_check_box_changed(self, state):
563
- """
564
- Called when the swap family checkbox changes its state. Update the
565
- motion curve to reflect the new motion family.
566
- """
567
- if state == 2:
568
- self.motion_family_idx = 1
569
- else:
570
- self.motion_family_idx = 0
326
+ cp_layout.addWidget(QtWidgets.QLabel("Adjust X:"))
327
+ cp_layout.addWidget(self.slider_x)
328
+ cp_layout.addWidget(self.textbox_x)
329
+ cp_layout.addWidget(QtWidgets.QLabel("Adjust Y:"))
330
+ cp_layout.addWidget(self.slider_y)
331
+ cp_layout.addWidget(self.textbox_y)
332
+ cp_layout.addWidget(QtWidgets.QLabel("Adjust Z:"))
333
+ cp_layout.addWidget(self.slider_z)
334
+ cp_layout.addWidget(self.textbox_z)
335
+ if method == 'quadratic_from_poses' or method == 'cubic_from_poses':
336
+ cp_layout.addSpacing(10) # Add 10 pixels of space before the separator
337
+ cp_layout.addWidget(create_separator())
338
+ cp_layout.addWidget(QtWidgets.QLabel("Rotate X:"))
339
+ cp_layout.addWidget(self.slider_roll)
340
+ cp_layout.addWidget(self.textbox_roll)
341
+ cp_layout.addWidget(QtWidgets.QLabel("Rotate Y:"))
342
+ cp_layout.addWidget(self.slider_pitch)
343
+ cp_layout.addWidget(self.textbox_pitch)
344
+ cp_layout.addWidget(QtWidgets.QLabel("Rotate Z:"))
345
+ cp_layout.addWidget(self.slider_yaw)
346
+ cp_layout.addWidget(self.textbox_yaw)
347
+ if method == 'cubic_from_poses':
348
+ cp_layout.addSpacing(10) # Add 10 pixels of space before the separator
349
+ cp_layout.addWidget(create_separator())
350
+ cp_layout.addSpacing(10)
351
+ cp_layout.addWidget(self.swap_family_check_box)
352
+ cp_layout.addWidget(QtWidgets.QLabel("Lambda:"))
353
+ cp_layout.addWidget(self.slider_lambda)
354
+ cp_layout.addWidget(self.textbox_lambda)
355
+
356
+ cp_layout.addSpacing(20)
357
+ cp_layout.addWidget(self.synthesize_button)
358
+
359
+ cp_layout.addStretch(1)
360
+
361
+ main_layout.addWidget(control_panel)
362
+ self.setLayout(main_layout)
363
+ self.setWindowTitle("Motion Designer")
364
+
365
+ def _initialize_points(self, method, initial_pts):
366
+ predefined_points = {
367
+ 'cubic_from_points': [
368
+ PointHomogeneous(),
369
+ PointHomogeneous([1, 1, 1, 0.3]),
370
+ PointHomogeneous([1, 3, -3, 0.5]),
371
+ PointHomogeneous([1, 0.5, -7, 1]),
372
+ PointHomogeneous([1, -3.2, -7, 4]),
373
+ PointHomogeneous([1, -7, -3, 2]),
374
+ PointHomogeneous([1, -8, 3, 0.5])
375
+ ],
376
+ 'cubic_from_poses': [
377
+ DualQuaternion(),
378
+ DualQuaternion([0, 0, 0, 1, 1, 0, 1, 0]),
379
+ DualQuaternion([1, 2, 0, 0, -2, 1, 0, 0]),
380
+ DualQuaternion([3, 0, 1, 0, 1, 0, -3, 0])
381
+ ],
382
+ 'quadratic_from_points': [
383
+ PointHomogeneous(),
384
+ PointHomogeneous([1, 1, 1, 2]),
385
+ PointHomogeneous([1, 3, -3, 1]),
386
+ PointHomogeneous([1, 2, -4, 1]),
387
+ PointHomogeneous([1, -2, -2, 2])
388
+ ],
389
+ 'quadratic_from_poses': [
390
+ DualQuaternion(),
391
+ DualQuaternion(
392
+ TransfMatrix.from_vectors(
393
+ approach_z=[-0.0362862, 0.400074, 0.915764],
394
+ normal_x=[0.988751, -0.118680, 0.0910266],
395
+ origin=[0.33635718, 0.9436004, 0.3428654]).matrix2dq()),
396
+ DualQuaternion(
397
+ TransfMatrix.from_vectors(
398
+ approach_z=[-0.0463679, -0.445622, 0.894020],
399
+ normal_x=[0.985161, 0.127655, 0.114724],
400
+ origin=[-0.52857769, -0.4463076, -0.81766]).matrix2dq()),
401
+ ]
402
+ }
403
+
404
+ required_points = {
405
+ 'cubic_from_points': 7,
406
+ 'cubic_from_poses': 4,
407
+ 'quadratic_from_points': 5,
408
+ 'quadratic_from_poses': 3
409
+ }
410
+
411
+ if method not in predefined_points:
412
+ raise ValueError(f"Unknown method: {method}")
413
+
414
+ if initial_pts is None:
415
+ return predefined_points[method]
416
+
417
+ if len(initial_pts) != required_points[method]:
418
+ raise ValueError(
419
+ f"For a {method.replace('_', ' ')}, {required_points[method]} points are needed.")
420
+
421
+ return initial_pts
422
+
423
+ def set_sliders_for_point(self, index):
424
+ """
425
+ Set the slider positions to reflect the current coordinates of the
426
+ control point with the given index.
427
+ (Here we assume that coordinates are in the range roughly –10..10.)
428
+ """
429
+ index = index + 1 # skip the first point/pose
430
+ sliders = [self.slider_x, self.slider_y, self.slider_z]
431
+ text_boxes = [self.textbox_x, self.textbox_y, self.textbox_z]
432
+ if self.method == 'quadratic_from_points' or self.method == 'cubic_from_points':
433
+ pt = self.plotted_points[index]
434
+ values = [int(pt[i] * 100) for i in range(3)]
435
+ else:
436
+ sliders.extend([self.slider_roll, self.slider_pitch, self.slider_yaw])
437
+ text_boxes.extend([self.textbox_roll, self.textbox_pitch, self.textbox_yaw])
438
+ pt = self.plotted_poses[index]
439
+ rpy = self.previous_rpy_sliders_values[index]
440
+ values = [
441
+ int(pt.tr.t[0] * 100),
442
+ int(pt.tr.t[1] * 100),
443
+ int(pt.tr.t[2] * 100),
444
+ int(rpy[0]), # Roll
445
+ int(rpy[1]), # Pitch
446
+ int(rpy[2]) # Yaw
447
+ ]
448
+ (self.slider_roll_prev, self.slider_pitch_prev,
449
+ self.slider_yaw_prev) = values[3:]
450
+ #
451
+ for slider, text_box, value in zip(sliders, text_boxes, values):
452
+ slider.blockSignals(True)
453
+ slider.setValue(value)
454
+ text_box.setText(str(value / 100.0))
455
+ slider.blockSignals(False)
571
456
 
572
- self.update_curve_vis()
457
+ def on_synthesize_button_clicked(self):
458
+ """
459
+ Called when the "Synthesize mechanism" button is clicked. This method
460
+ should be implemented to synthesize a mechanism based on the current
461
+ control points.
462
+ """
463
+ if (self.method == 'quadratic_from_points'
464
+ or self.method == 'cubic_from_points'
465
+ or self.method == 'quadratic_from_poses'):
466
+ c = MotionInterpolation.interpolate(self.points)
467
+ else:
468
+ p = MotionInterpolation.interpolate_cubic_numerically(
469
+ self.points,
470
+ lambda_val=self.lambda_val,
471
+ k_idx=self.motion_family_idx)
472
+ c = RationalCurve.from_coeffs(p)
473
+ self.mechanism_plotter.append(
474
+ InteractivePlotterWidget(mechanism=RationalMechanism(c.factorize()),
475
+ arrows_length=self.arrows_length,
476
+ parent_app=self.plotter.app))
477
+ self.mechanism_plotter[-1].show()
478
+
479
+
480
+ def on_point_selection_changed(self, index):
481
+ """
482
+ When a different point is selected in the combo box, update the slider
483
+ positions to match that point’s coordinates.
484
+ """
485
+ self.set_sliders_for_point(index)
573
486
 
574
- def on_lambda_textbox_changed(self, text, slider):
575
- """
576
- Update the given slider with the value from the corresponding textbox.
487
+ def on_slider_value_changed(self, value):
488
+ """
489
+ Called when any of the sliders change their value. Update the currently
490
+ selected control point’s x, y, or z coordinate based on the slider values,
491
+ update the control point markers, and then recalculate the motion curve.
492
+ """
493
+ index = self.point_combo.currentIndex() + 1
494
+ # Convert slider values (integers) to floating‑point coordinates.
495
+ new_x = self.slider_x.value() / 100.0
496
+ new_y = self.slider_y.value() / 100.0
497
+ new_z = self.slider_z.value() / 100.0
498
+
499
+ self.textbox_x.setText(str(new_x))
500
+ self.textbox_y.setText(str(new_y))
501
+ self.textbox_z.setText(str(new_z))
502
+
503
+ if self.method == 'quadratic_from_poses' or self.method == 'cubic_from_poses':
504
+ if self.slider_roll.value() != self.slider_roll_prev:
505
+ new_roll = (self.slider_roll.value() - self.slider_roll_prev) / 100.0
506
+ new_mat = TransfMatrix.from_rotation('x', new_roll)
507
+ new_tr = self.plotted_poses[index].tr * new_mat
508
+ self.slider_roll_prev = self.slider_roll.value()
509
+ self.textbox_roll.setText(str(self.slider_roll.value() / 100.0))
510
+
511
+ elif self.slider_pitch.value() != self.slider_pitch_prev:
512
+ new_pitch = (self.slider_pitch.value() - self.slider_pitch_prev) / 100.0
513
+ new_mat = TransfMatrix.from_rotation('y', new_pitch)
514
+ new_tr = self.plotted_poses[index].tr * new_mat
515
+ self.slider_pitch_prev = self.slider_pitch.value()
516
+ self.textbox_pitch.setText(str(self.slider_pitch.value() / 100.0))
517
+
518
+ elif self.slider_yaw.value() != self.slider_yaw_prev:
519
+ new_yaw = (self.slider_yaw.value() - self.slider_yaw_prev) / 100.0
520
+ new_mat = TransfMatrix.from_rotation('z', new_yaw)
521
+ new_tr = self.plotted_poses[index].tr * new_mat
522
+ self.slider_yaw_prev = self.slider_yaw.value()
523
+ self.textbox_yaw.setText(str(self.slider_yaw.value() / 100.0))
524
+ else:
525
+ new_tr = TransfMatrix.from_rpy_xyz(self.plotted_poses[index].tr.rpy(),
526
+ [new_x, new_y, new_z])
527
+
528
+ self.previous_rpy_sliders_values[index][0] = self.slider_roll.value()
529
+ self.previous_rpy_sliders_values[index][1] = self.slider_pitch.value()
530
+ self.previous_rpy_sliders_values[index][2] = self.slider_yaw.value()
531
+
532
+ new_dq = DualQuaternion(new_tr.matrix2dq())
533
+ self.points[index] = new_dq
534
+ self.plotted_poses[index].setData(new_tr)
577
535
 
578
- :param str text: The text input from the textbox. Should be a number.
579
- :param slider: The slider to update with the new value.
580
- """
581
- if text is not None:
582
- try:
583
- value = float(text)
584
- slider.blockSignals(True)
585
- slider.setValue(int(value * 100))
586
- slider.blockSignals(False)
536
+ else:
537
+ # update the selected control point
538
+ self.points[index] = PointHomogeneous.from_3d_point([new_x, new_y, new_z])
539
+ self.plotted_points[index] = np.array([new_x, new_y, new_z])
540
+ # update the visual markers
541
+ self.markers.setData(pos=self.plotted_points)
587
542
 
588
- if abs(value - 1.0) < 1e-10:
589
- value = 1.00000001 # avoid numerical issues with 1.0
590
- print("Warning: lambda value set to 1.0, using 1.00000001 instead.")
591
- self.lambda_val = value
592
- self.update_curve_vis()
593
- except ValueError:
594
- raise ValueError(f"Invalid input for slider: {text}")
543
+ # Recalculate and update the motion curve.
544
+ self.update_curve_vis()
595
545
 
596
- def on_textbox_changed(self, text, slider):
597
- """
598
- Update the given slider with the value from the corresponding textbox.
599
- """
600
- if text is not None:
601
- try:
602
- value = float(text)
603
- slider.blockSignals(True)
604
- slider.setValue(int(value * 100))
605
- slider.blockSignals(False)
546
+ def on_lambda_slider_value_changed(self, value):
547
+ """
548
+ Called when the lambda slider changes its value. Update the lambda value
549
+ of the cubic curve, update the control point markers, and then recalculate
550
+ the motion curve.
551
+ """
552
+ self.lambda_val = self.slider_lambda.value() / 100.0
553
+ self.textbox_lambda.setText(str(self.lambda_val))
554
+ self.update_curve_vis()
606
555
 
607
- self.on_slider_value_changed(value)
608
- except ValueError:
609
- raise ValueError(f"Invalid input for slider: {text}")
556
+ def on_swap_family_check_box_changed(self, state):
557
+ """
558
+ Called when the swap family checkbox changes its state. Update the
559
+ motion curve to reflect the new motion family.
560
+ """
561
+ if state == 2:
562
+ self.motion_family_idx = 1
563
+ else:
564
+ self.motion_family_idx = 0
610
565
 
611
- def update_curve_vis(self):
612
- """
613
- Recalculate the motion curve using the current control points. The
614
- interpolation is performed by MotionInterpolation. Then update the curve
615
- line in the GLViewWidget.
616
- """
566
+ self.update_curve_vis()
617
567
 
618
- # get the numeric coefficients from interpolation
619
- if self.method == 'cubic_from_points':
620
- coeffs = self.mi.interpolate_points_cubic(self.points,
621
- return_numeric=True)
622
- elif self.method == 'quadratic_from_points':
623
- coeffs = self.mi.interpolate_points_quadratic(self.points,
568
+ def on_lambda_textbox_changed(self, text, slider):
569
+ """
570
+ Update the given slider with the value from the corresponding textbox.
571
+
572
+ :param str text: The text input from the textbox. Should be a number.
573
+ :param slider: The slider to update with the new value.
574
+ """
575
+ if text is not None:
576
+ try:
577
+ value = float(text)
578
+ slider.blockSignals(True)
579
+ slider.setValue(int(value * 100))
580
+ slider.blockSignals(False)
581
+
582
+ if abs(value - 1.0) < 1e-10:
583
+ value = 1.00000001 # avoid numerical issues with 1.0
584
+ print("Warning: lambda value set to 1.0, using 1.00000001 instead.")
585
+ self.lambda_val = value
586
+ self.update_curve_vis()
587
+ except ValueError:
588
+ raise ValueError(f"Invalid input for slider: {text}")
589
+
590
+ def on_textbox_changed(self, text, slider):
591
+ """
592
+ Update the given slider with the value from the corresponding textbox.
593
+ """
594
+ if text is not None:
595
+ try:
596
+ value = float(text)
597
+ slider.blockSignals(True)
598
+ slider.setValue(int(value * 100))
599
+ slider.blockSignals(False)
600
+
601
+ self.on_slider_value_changed(value)
602
+ except ValueError:
603
+ raise ValueError(f"Invalid input for slider: {text}")
604
+
605
+ def update_curve_vis(self):
606
+ """
607
+ Recalculate the motion curve using the current control points. The
608
+ interpolation is performed by MotionInterpolation. Then update the curve
609
+ line in the GLViewWidget.
610
+ """
611
+
612
+ # get the numeric coefficients from interpolation
613
+ if self.method == 'cubic_from_points':
614
+ coeffs = self.mi.interpolate_points_cubic(self.points,
624
615
  return_numeric=True)
625
- elif self.method == 'quadratic_from_poses':
626
- coeffs = self.mi.interpolate_quadratic_numerically(self.points)
627
- elif self.method == 'cubic_from_poses':
628
- coeffs = self.mi.interpolate_cubic_numerically(self.points,
629
- lambda_val=self.lambda_val,
630
- k_idx=self.motion_family_idx)
631
-
632
- # create numpy polynomial objects
633
- curve = [np.polynomial.Polynomial(c[::-1]) for c in coeffs]
634
-
635
- # parameter values using a tangent substitution
636
- t_space = np.tan(np.linspace(-np.pi / 2, np.pi / 2, self.plotter.steps + 1))
637
- curve_points = []
638
- for t in t_space:
639
- dq = DualQuaternion([poly(t) for poly in curve]) # evaluate fot each t
640
- pt = dq.dq2point_via_matrix()
641
- curve_points.append(pt)
642
- curve_points = np.array(curve_points)
643
-
644
- t_space_frames = np.tan(np.linspace(-np.pi / 2, np.pi / 2, 51))
645
- curve_frames = []
646
- for t in t_space_frames:
647
- dq = DualQuaternion([poly(t) for poly in curve])
648
- curve_frames.append(TransfMatrix(dq.dq2matrix()))
649
-
650
- # if the curve line has not yet been created
651
- if self.curve_path_vis is None:
652
- self.curve_path_vis = gl.GLLinePlotItem(pos=curve_points,
653
- color=(0.5, 0.5, 0.5, 1),
654
- glOptions=self.render_mode,
655
- width=2,
656
- antialias=True)
657
- self.plotter.widget.addItem(self.curve_path_vis)
658
-
659
- self.curve_frames_vis = [FramePlotHelper(transform=tr,
660
- length=self.plotter.arrows_length)
661
- for tr in curve_frames]
662
- for frame in self.curve_frames_vis:
663
- frame.addToView(self.plotter.widget)
664
- else: # update the existing curve visuals
665
- self.curve_path_vis.setData(pos=curve_points)
666
- for i, frame in enumerate(self.curve_frames_vis):
667
- frame.setData(curve_frames[i])
668
-
669
- def closeEvent(self, event):
670
- """
671
- Called when the window is closed. Ensure that the Qt application exits.
672
- """
673
- print("Closing the window... generated points for interpolation:")
674
- for pt in self.points:
675
- print(pt)
676
- if self.slider_lambda:
677
- print(f"Lambda: {self.slider_lambda.value() / 100.0}")
678
- if self.swap_family_check_box:
679
- print(f"Motion family index: {self.motion_family_idx}")
680
- self.plotter.app.quit()
616
+ elif self.method == 'quadratic_from_points':
617
+ coeffs = self.mi.interpolate_points_quadratic(self.points,
618
+ return_numeric=True)
619
+ elif self.method == 'quadratic_from_poses':
620
+ coeffs = self.mi.interpolate_quadratic_numerically(self.points)
621
+ elif self.method == 'cubic_from_poses':
622
+ coeffs = self.mi.interpolate_cubic_numerically(self.points,
623
+ lambda_val=self.lambda_val,
624
+ k_idx=self.motion_family_idx)
625
+
626
+ # create numpy polynomial objects
627
+ curve = [np.polynomial.Polynomial(c[::-1]) for c in coeffs]
628
+
629
+ # parameter values using a tangent substitution
630
+ t_space = np.tan(np.linspace(-np.pi / 2, np.pi / 2, self.plotter.steps + 1))
631
+ curve_points = []
632
+ for t in t_space:
633
+ dq = DualQuaternion([poly(t) for poly in curve]) # evaluate fot each t
634
+ pt = dq.dq2point_via_matrix()
635
+ curve_points.append(pt)
636
+ curve_points = np.array(curve_points)
637
+
638
+ t_space_frames = np.tan(np.linspace(-np.pi / 2, np.pi / 2, 51))
639
+ curve_frames = []
640
+ for t in t_space_frames:
641
+ dq = DualQuaternion([poly(t) for poly in curve])
642
+ curve_frames.append(TransfMatrix(dq.dq2matrix()))
643
+
644
+ # if the curve line has not yet been created
645
+ if self.curve_path_vis is None:
646
+ self.curve_path_vis = gl.GLLinePlotItem(pos=curve_points,
647
+ color=(0.5, 0.5, 0.5, 1),
648
+ glOptions=self.render_mode,
649
+ width=2,
650
+ antialias=True)
651
+ self.plotter.widget.addItem(self.curve_path_vis)
652
+
653
+ self.curve_frames_vis = [FramePlotHelper(transform=tr,
654
+ length=self.plotter.arrows_length)
655
+ for tr in curve_frames]
656
+ for frame in self.curve_frames_vis:
657
+ frame.addToView(self.plotter.widget)
658
+ else: # update the existing curve visuals
659
+ self.curve_path_vis.setData(pos=curve_points)
660
+ for i, frame in enumerate(self.curve_frames_vis):
661
+ frame.setData(curve_frames[i])
662
+
663
+ def closeEvent(self, event):
664
+ """
665
+ Called when the window is closed. Ensure that the Qt application exits.
666
+ """
667
+ print("Closing the window... generated points for interpolation:")
668
+ for pt in self.points:
669
+ print(pt)
670
+ if self.slider_lambda:
671
+ print(f"Lambda: {self.slider_lambda.value() / 100.0}")
672
+ if self.swap_family_check_box:
673
+ print(f"Motion family index: {self.motion_family_idx}")
674
+ self.plotter.app.quit()
675
+
676
+ else:
677
+ MotionDesignerWidget = None