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