rational-linkages 2.1.0__cp312-cp312-win_arm64.whl → 2.2.3__cp312-cp312-win_arm64.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.
@@ -1,9 +1,7 @@
1
1
  import sys
2
-
3
2
  import numpy as np
4
- import pyqtgraph.opengl as gl
5
- from PyQt6 import QtCore, QtGui, QtWidgets
6
- from PyQt6.QtWidgets import QApplication
3
+
4
+ from warnings import warn
7
5
 
8
6
  from .DualQuaternion import DualQuaternion
9
7
  from .Linkage import LineSegment
@@ -17,6 +15,21 @@ from .RationalCurve import RationalCurve
17
15
  from .RationalMechanism import RationalMechanism
18
16
  from .TransfMatrix import TransfMatrix
19
17
 
18
+ # Try importing GUI components
19
+ try:
20
+ import pyqtgraph.opengl as gl
21
+ from PyQt6 import QtCore, QtGui, QtWidgets
22
+ from PyQt6.QtWidgets import QApplication
23
+ except (ImportError, OSError):
24
+ warn("Failed to import OpenGL or PyQt6. If you expect interactive GUI to work, "
25
+ "please check the package installation.")
26
+
27
+ gl = None
28
+ QtCore = None
29
+ QtGui = None
30
+ QtWidgets = None
31
+ QApplication = None
32
+
20
33
 
21
34
  class PlotterPyqtgraph:
22
35
  """
@@ -598,543 +611,550 @@ class PlotterPyqtgraph:
598
611
  event.accept()
599
612
 
600
613
 
601
- class CustomGLViewWidget(gl.GLViewWidget):
602
- def __init__(self, white_background=False, *args, **kwargs):
603
- super().__init__(*args, **kwargs)
604
- self.labels = []
605
- self.white_background = white_background
606
- # Create an overlay widget for displaying text
607
- self.text_overlay = QtWidgets.QWidget(self)
608
- self.text_overlay.setAttribute(
609
- QtCore.Qt.WidgetAttribute.WA_TransparentForMouseEvents)
610
- self.text_overlay.setStyleSheet("background:transparent;")
611
- self.text_overlay.resize(self.size())
612
- self.text_overlay.show()
613
-
614
- def resizeEvent(self, event):
615
- super().resizeEvent(event)
616
- if hasattr(self, 'text_overlay'):
614
+ if gl is not None:
615
+ class CustomGLViewWidget(gl.GLViewWidget):
616
+ def __init__(self, white_background=False, *args, **kwargs):
617
+ super().__init__(*args, **kwargs)
618
+ self.labels = []
619
+ self.white_background = white_background
620
+ # Create an overlay widget for displaying text
621
+ self.text_overlay = QtWidgets.QWidget(self)
622
+ self.text_overlay.setAttribute(
623
+ QtCore.Qt.WidgetAttribute.WA_TransparentForMouseEvents)
624
+ self.text_overlay.setStyleSheet("background:transparent;")
617
625
  self.text_overlay.resize(self.size())
618
-
619
- def add_label(self, point, text):
620
- """Adds a label for a 3D point."""
621
- self.labels.append({'point': point, 'text': text})
622
- self.update()
623
-
624
- def paintEvent(self, event):
625
- # Only handle standard OpenGL rendering here - no mixing with QPainter
626
- super().paintEvent(event)
627
-
628
- # Schedule label painting as a separate operation
629
- QtCore.QTimer.singleShot(0, self.update_text_overlay)
630
-
631
- def update_text_overlay(self):
632
- """Update the text overlay with current labels"""
633
- # Create a new painter for the overlay widget
634
- self.text_overlay.update()
635
-
636
- def _obtain_label_vec(self, pt):
637
- """Obtain the label vector."""
638
- # Convert the 3D point to homogeneous coordinates
639
- if isinstance(pt, np.ndarray):
640
- point_vec = pt
641
- elif isinstance(pt, PointHomogeneous):
642
- point_vec = [pt.coordinates_normalized[1],
643
- pt.coordinates_normalized[2],
644
- pt.coordinates_normalized[3]]
645
- elif isinstance(pt, TransfMatrix):
646
- point_vec = [pt.t[0], pt.t[1], pt.t[2]]
647
- elif isinstance(pt, FramePlotHelper):
648
- point_vec = [pt.tr.t[0], pt.tr.t[1], pt.tr.t[2]]
649
- else: # is pyqtgraph marker (scatter)
650
- point_vec = [pt.pos[0][0], pt.pos[0][1], pt.pos[0][2]]
651
-
652
- return QtGui.QVector4D(point_vec[0], point_vec[1], point_vec[2], 1.0)
653
-
654
- # This method renders text on the overlay
655
- def paintOverlay(self, event):
656
- painter = QtGui.QPainter(self.text_overlay)
657
- painter.setRenderHint(QtGui.QPainter.RenderHint.Antialiasing)
658
- if self.white_background:
659
- painter.setPen(QtGui.QColor(QtCore.Qt.GlobalColor.black))
660
- else:
661
- painter.setPen(QtGui.QColor(QtCore.Qt.GlobalColor.white))
662
-
663
- # Get the Model-View-Projection matrix
664
- projection_matrix = self.projectionMatrix()
665
- view_matrix = self.viewMatrix()
666
- mvp = projection_matrix * view_matrix
667
-
668
- # Draw all labels
669
- for entry in self.labels:
670
- point = entry['point']
671
- text = entry['text']
672
-
673
- projected = mvp.map(self._obtain_label_vec(point))
674
- if projected.w() != 0:
675
- ndc_x = projected.x() / projected.w()
676
- ndc_y = projected.y() / projected.w()
677
- # Check if the point is in front of the camera
678
- if projected.z() / projected.w() < 1.0:
679
- x = int((ndc_x * 0.5 + 0.5) * self.width())
680
- y = int((1 - (ndc_y * 0.5 + 0.5)) * self.height())
681
- painter.drawText(x, y, text)
682
-
683
- painter.end()
684
-
685
- def showEvent(self, event):
686
- super().showEvent(event)
687
- self.text_overlay.installEventFilter(self)
688
-
689
- def eventFilter(self, obj, event):
690
- if obj is self.text_overlay and event.type() == QtCore.QEvent.Type.Paint:
691
- self.paintOverlay(event)
692
- return True
693
- return super().eventFilter(obj, event)
694
-
695
-
696
- class FramePlotHelper:
697
- def __init__(self,
698
- transform: TransfMatrix = TransfMatrix(),
699
- width: float = 2.,
700
- length: float = 1.,
701
- antialias: bool = True):
702
- """
703
- Create a coordinate frame using three GLLinePlotItems.
704
-
705
- :param TransfMatrix transform: The initial transformation matrix.
706
- :param float width: The width of the lines.
707
- :param float length: The length of the axes.
708
- :param bool antialias: Whether to use antialiasing
709
- """
710
- # Create GLLinePlotItems for the three axes.
711
- # The initial positions are placeholders; they will be set properly in setData().
712
- self.x_axis = gl.GLLinePlotItem(pos=np.zeros((2, 3)),
713
- color=(1, 0, 0, 0.5),
714
- glOptions='translucent',
715
- width=width,
716
- antialias=antialias)
717
- self.y_axis = gl.GLLinePlotItem(pos=np.zeros((2, 3)),
718
- color=(0, 1, 0, 0.5),
719
- glOptions='translucent',
720
- width=width,
721
- antialias=antialias)
722
- self.z_axis = gl.GLLinePlotItem(pos=np.zeros((2, 3)),
723
- color=(0, 0, 1, 0.5),
724
- glOptions='translucent',
725
- width=width,
726
- antialias=antialias)
727
-
728
- # Set the initial transformation
729
- self.tr = transform
730
- self.length = length
731
- self.setData(transform)
732
-
733
- def setData(self, transform: TransfMatrix):
734
- """
735
- Update the coordinate frame using a new 4x4 transformation matrix.
736
-
737
- :param TransfMatrix transform: The new transformation matrix.
738
- """
739
- self.tr = transform
740
-
741
- # Update the positions for each axis.
742
- self.x_axis.setData(pos=np.array([transform.t, transform.t + self.length * transform.n]))
743
- self.y_axis.setData(pos=np.array([transform.t, transform.t + self.length * transform.o]))
744
- self.z_axis.setData(pos=np.array([transform.t, transform.t + self.length * transform.a]))
745
-
746
- def addToView(self, view: gl.GLViewWidget):
747
- """
748
- Add all three axes to a GLViewWidget.
749
-
750
- :param gl.GLViewWidget view: The view to add the axes to.
751
- """
752
- view.addItem(self.x_axis)
753
- view.addItem(self.y_axis)
754
- view.addItem(self.z_axis)
755
-
756
-
757
- class InteractivePlotterWidget(QtWidgets.QWidget):
758
- """
759
- A QWidget that contains a PlotterPyqtgraph 3D view and interactive controls.
760
-
761
- Containts (sliders and text boxes) for plotting and manipulating a mechanism.
762
- """
763
- def __init__(self,
764
- mechanism: RationalMechanism,
765
- base=None,
766
- show_tool: bool = True,
767
- steps: int = 1000,
768
- joint_sliders_lim: float = 1.0,
769
- arrows_length: float = 1.0,
770
- white_background: bool = False,
771
- parent=None,
772
- parent_app=None):
773
- super().__init__(parent)
774
- self.setMinimumSize(800, 600)
775
-
776
- self.mechanism = mechanism
777
- self.show_tool = show_tool
778
- self.steps = steps
779
- self.joint_sliders_lim = joint_sliders_lim
780
- self.arrows_length = arrows_length
781
-
782
- if base is not None:
783
- if isinstance(base, TransfMatrix):
784
- if not base.is_rotation():
785
- raise ValueError("Given matrix is not proper rotation.")
786
- self.base = base
787
- self.base_arr = self.base.array()
788
- elif isinstance(base, DualQuaternion):
789
- self.base = TransfMatrix(base.dq2matrix())
790
- self.base_arr = self.base.array()
626
+ self.text_overlay.show()
627
+
628
+ def resizeEvent(self, event):
629
+ super().resizeEvent(event)
630
+ if hasattr(self, 'text_overlay'):
631
+ self.text_overlay.resize(self.size())
632
+
633
+ def add_label(self, point, text):
634
+ """Adds a label for a 3D point."""
635
+ self.labels.append({'point': point, 'text': text})
636
+ self.update()
637
+
638
+ def paintEvent(self, event):
639
+ # Only handle standard OpenGL rendering here - no mixing with QPainter
640
+ super().paintEvent(event)
641
+
642
+ # Schedule label painting as a separate operation
643
+ QtCore.QTimer.singleShot(0, self.update_text_overlay)
644
+
645
+ def update_text_overlay(self):
646
+ """Update the text overlay with current labels"""
647
+ # Create a new painter for the overlay widget
648
+ self.text_overlay.update()
649
+
650
+ def _obtain_label_vec(self, pt):
651
+ """Obtain the label vector."""
652
+ # Convert the 3D point to homogeneous coordinates
653
+ if isinstance(pt, np.ndarray):
654
+ point_vec = pt
655
+ elif isinstance(pt, PointHomogeneous):
656
+ point_vec = [pt.coordinates_normalized[1],
657
+ pt.coordinates_normalized[2],
658
+ pt.coordinates_normalized[3]]
659
+ elif isinstance(pt, TransfMatrix):
660
+ point_vec = [pt.t[0], pt.t[1], pt.t[2]]
661
+ elif isinstance(pt, FramePlotHelper):
662
+ point_vec = [pt.tr.t[0], pt.tr.t[1], pt.tr.t[2]]
663
+ else: # is pyqtgraph marker (scatter)
664
+ point_vec = [pt.pos[0][0], pt.pos[0][1], pt.pos[0][2]]
665
+
666
+ return QtGui.QVector4D(point_vec[0], point_vec[1], point_vec[2], 1.0)
667
+
668
+ # This method renders text on the overlay
669
+ def paintOverlay(self, event):
670
+ painter = QtGui.QPainter(self.text_overlay)
671
+ painter.setRenderHint(QtGui.QPainter.RenderHint.Antialiasing)
672
+ if self.white_background:
673
+ painter.setPen(QtGui.QColor(QtCore.Qt.GlobalColor.black))
791
674
  else:
792
- raise TypeError("Base must be a TransfMatrix or DualQuaternion instance.")
793
- else:
794
- self.base = None
795
- self.base_arr = None
796
-
797
- self.white_background = white_background
798
- if self.white_background:
799
- self.render_mode = 'translucent'
800
- else:
801
- self.render_mode = 'additive'
802
-
803
- # Create the PlotterPyqtgraph instance.
804
- self.plotter = PlotterPyqtgraph(base=None,
805
- steps=self.steps,
806
- arrows_length=self.arrows_length,
807
- white_background=self.white_background,
808
- parent_app=parent_app)
809
- # Optionally adjust the camera.
810
- self.plotter.widget.setCameraPosition(distance=10, azimuth=30, elevation=30)
811
-
812
- # Main layout: split between the 3D view and a control panel.
813
- main_layout = QtWidgets.QHBoxLayout(self)
814
-
815
- # Add the 3D view (PlotterPyqtgraph’s widget) to the layout.
816
- main_layout.addWidget(self.plotter.widget, stretch=5)
817
-
818
- # Create the control panel (on the right).
819
- control_panel = QtWidgets.QWidget()
820
- control_layout = QtWidgets.QVBoxLayout(control_panel)
821
-
822
- # --- Driving joint angle slider ---
823
- control_layout.addWidget(QtWidgets.QLabel("Joint angle [rad]:"))
824
- self.move_slider = self.create_float_slider(0.0, 2 * np.pi, 0.0,
825
- orientation=QtCore.Qt.Orientation.Horizontal)
826
- control_layout.addWidget(self.move_slider)
827
-
828
- # --- Text boxes ---
829
- self.text_box_angle = QtWidgets.QLineEdit()
830
- self.text_box_angle.setPlaceholderText("Set angle [rad]:")
831
- control_layout.addWidget(self.text_box_angle)
832
-
833
- self.text_box_param = QtWidgets.QLineEdit()
834
- self.text_box_param.setPlaceholderText("Set parameter t [-]:")
835
- control_layout.addWidget(self.text_box_param)
836
-
837
- self.save_mech_pkl = QtWidgets.QLineEdit()
838
- self.save_mech_pkl.setPlaceholderText("Save mechanism PKL, filename:")
839
- control_layout.addWidget(self.save_mech_pkl)
840
-
841
- self.save_figure_box = QtWidgets.QLineEdit()
842
- self.save_figure_box.setPlaceholderText("Save figure PNG, filename:")
843
- control_layout.addWidget(self.save_figure_box)
844
-
845
- # --- Joint connection sliders ---
846
- joint_sliders_layout = QtWidgets.QHBoxLayout()
847
- self.joint_sliders = []
848
-
849
- # Initialize sliders for each joint
850
- for i in range(self.mechanism.num_joints):
851
- slider0, slider1 = self._init_joint_sliders(i, self.joint_sliders_lim)
852
- self.joint_sliders.append(slider0)
853
- self.joint_sliders.append(slider1)
854
-
855
- # Arrange sliders vertically for each joint
856
- joint_layout = QtWidgets.QVBoxLayout()
857
-
858
- joint_layout.addWidget(QtWidgets.QLabel(f"j{i}cp0"))
859
- joint_layout.addWidget(slider0)
860
- joint_layout.addWidget(QtWidgets.QLabel(f"j{i}cp1"))
861
- joint_layout.addWidget(slider1)
862
-
863
- joint_sliders_layout.addLayout(joint_layout)
864
-
865
- control_layout.addLayout(joint_sliders_layout)
866
-
867
- # Set default values for the first factorization
868
- for i in range(self.mechanism.factorizations[0].number_of_factors):
869
- default_val0 = self.mechanism.factorizations[0].linkage[i].points_params[0]
870
- default_val1 = self.mechanism.factorizations[0].linkage[i].points_params[1]
871
- self.joint_sliders[2 * i].setValue(int(default_val0 * 100))
872
- self.joint_sliders[2 * i + 1].setValue(int(default_val1 * 100))
873
-
874
- # Set default values for the second factorization
875
- offset = 2 * self.mechanism.factorizations[0].number_of_factors
876
- for i in range(self.mechanism.factorizations[1].number_of_factors):
877
- default_val0 = self.mechanism.factorizations[1].linkage[i].points_params[0]
878
- default_val1 = self.mechanism.factorizations[1].linkage[i].points_params[1]
879
- self.joint_sliders[offset + 2 * i].setValue(int(default_val0 * 100))
880
- self.joint_sliders[offset + 2 * i + 1].setValue(int(default_val1 * 100))
881
-
882
- main_layout.addWidget(control_panel, stretch=1)
883
-
884
- # --- Initialize plot items for the mechanism links ---
885
- self.lines = []
886
- num_lines = self.mechanism.num_joints * 2
887
- for i in range(num_lines):
888
- # if i is even, make the link color green, and joints red
889
- if i % 2 == 0:
890
- line_item = gl.GLLinePlotItem(pos=np.zeros((2, 3)),
891
- color=(0, 1, 0, 1),
892
- glOptions=self.render_mode,
893
- width=5,
894
- antialias=True)
675
+ painter.setPen(QtGui.QColor(QtCore.Qt.GlobalColor.white))
676
+
677
+ # Get the Model-View-Projection matrix
678
+ projection_matrix = self.projectionMatrix()
679
+ view_matrix = self.viewMatrix()
680
+ mvp = projection_matrix * view_matrix
681
+
682
+ # Draw all labels
683
+ for entry in self.labels:
684
+ point = entry['point']
685
+ text = entry['text']
686
+
687
+ projected = mvp.map(self._obtain_label_vec(point))
688
+ if projected.w() != 0:
689
+ ndc_x = projected.x() / projected.w()
690
+ ndc_y = projected.y() / projected.w()
691
+ # Check if the point is in front of the camera
692
+ if projected.z() / projected.w() < 1.0:
693
+ x = int((ndc_x * 0.5 + 0.5) * self.width())
694
+ y = int((1 - (ndc_y * 0.5 + 0.5)) * self.height())
695
+ painter.drawText(x, y, text)
696
+
697
+ painter.end()
698
+
699
+ def showEvent(self, event):
700
+ super().showEvent(event)
701
+ self.text_overlay.installEventFilter(self)
702
+
703
+ def eventFilter(self, obj, event):
704
+ if obj is self.text_overlay and event.type() == QtCore.QEvent.Type.Paint:
705
+ self.paintOverlay(event)
706
+ return True
707
+ return super().eventFilter(obj, event)
708
+ else:
709
+ CustomGLViewWidget = None
710
+
711
+
712
+ if gl is not None:
713
+ class FramePlotHelper:
714
+ def __init__(self,
715
+ transform: TransfMatrix = TransfMatrix(),
716
+ width: float = 2.,
717
+ length: float = 1.,
718
+ antialias: bool = True):
719
+ """
720
+ Create a coordinate frame using three GLLinePlotItems.
721
+
722
+ :param TransfMatrix transform: The initial transformation matrix.
723
+ :param float width: The width of the lines.
724
+ :param float length: The length of the axes.
725
+ :param bool antialias: Whether to use antialiasing
726
+ """
727
+ # Create GLLinePlotItems for the three axes.
728
+ # The initial positions are placeholders; they will be set properly in setData().
729
+ self.x_axis = gl.GLLinePlotItem(pos=np.zeros((2, 3)),
730
+ color=(1, 0, 0, 0.5),
731
+ glOptions='translucent',
732
+ width=width,
733
+ antialias=antialias)
734
+ self.y_axis = gl.GLLinePlotItem(pos=np.zeros((2, 3)),
735
+ color=(0, 1, 0, 0.5),
736
+ glOptions='translucent',
737
+ width=width,
738
+ antialias=antialias)
739
+ self.z_axis = gl.GLLinePlotItem(pos=np.zeros((2, 3)),
740
+ color=(0, 0, 1, 0.5),
741
+ glOptions='translucent',
742
+ width=width,
743
+ antialias=antialias)
744
+
745
+ # Set the initial transformation
746
+ self.tr = transform
747
+ self.length = length
748
+ self.setData(transform)
749
+
750
+ def setData(self, transform: TransfMatrix):
751
+ """
752
+ Update the coordinate frame using a new 4x4 transformation matrix.
753
+
754
+ :param TransfMatrix transform: The new transformation matrix.
755
+ """
756
+ self.tr = transform
757
+
758
+ # Update the positions for each axis.
759
+ self.x_axis.setData(pos=np.array([transform.t, transform.t + self.length * transform.n]))
760
+ self.y_axis.setData(pos=np.array([transform.t, transform.t + self.length * transform.o]))
761
+ self.z_axis.setData(pos=np.array([transform.t, transform.t + self.length * transform.a]))
762
+
763
+ def addToView(self, view: gl.GLViewWidget):
764
+ """
765
+ Add all three axes to a GLViewWidget.
766
+
767
+ :param gl.GLViewWidget view: The view to add the axes to.
768
+ """
769
+ view.addItem(self.x_axis)
770
+ view.addItem(self.y_axis)
771
+ view.addItem(self.z_axis)
772
+ else:
773
+ FramePlotHelper = None
774
+
775
+ if QtWidgets is not None:
776
+ class InteractivePlotterWidget(QtWidgets.QWidget):
777
+ """
778
+ A QWidget that contains a PlotterPyqtgraph 3D view and interactive controls.
779
+
780
+ Containts (sliders and text boxes) for plotting and manipulating a mechanism.
781
+ """
782
+ def __init__(self,
783
+ mechanism: RationalMechanism,
784
+ base=None,
785
+ show_tool: bool = True,
786
+ steps: int = 1000,
787
+ joint_sliders_lim: float = 1.0,
788
+ arrows_length: float = 1.0,
789
+ white_background: bool = False,
790
+ parent=None,
791
+ parent_app=None):
792
+ super().__init__(parent)
793
+ self.setMinimumSize(800, 600)
794
+
795
+ self.mechanism = mechanism
796
+ self.show_tool = show_tool
797
+ self.steps = steps
798
+ self.joint_sliders_lim = joint_sliders_lim
799
+ self.arrows_length = arrows_length
800
+
801
+ if base is not None:
802
+ if isinstance(base, TransfMatrix):
803
+ if not base.is_rotation():
804
+ raise ValueError("Given matrix is not proper rotation.")
805
+ self.base = base
806
+ self.base_arr = self.base.array()
807
+ elif isinstance(base, DualQuaternion):
808
+ self.base = TransfMatrix(base.dq2matrix())
809
+ self.base_arr = self.base.array()
810
+ else:
811
+ raise TypeError("Base must be a TransfMatrix or DualQuaternion instance.")
895
812
  else:
896
- line_item = gl.GLLinePlotItem(pos=np.zeros((2, 3)),
897
- color=(1, 0, 0, 1),
898
- glOptions=self.render_mode,
899
- width=5,
900
- antialias=True)
901
- self.lines.append(line_item)
902
- self.plotter.widget.addItem(line_item)
903
-
904
- # --- If desired, initialize tool plot and tool frame ---
905
- if self.show_tool:
906
- self.tool_link = gl.GLLinePlotItem(pos=np.zeros((3, 3)),
907
- color=(0, 1, 0, 0.5),
908
- glOptions=self.render_mode,
909
- width=5,
910
- antialias=True)
911
- self.plotter.widget.addItem(self.tool_link)
912
- self.tool_frame = FramePlotHelper(
913
- transform=TransfMatrix(self.mechanism.tool_frame.dq2matrix()),
914
- length=self.arrows_length)
915
- self.tool_frame.addToView(self.plotter.widget)
916
-
917
- # --- Plot the tool path ---
918
- self._plot_tool_path()
919
-
920
- # --- Connect signals to slots ---
921
- self.move_slider.valueChanged.connect(self.on_move_slider_changed)
922
- self.text_box_angle.returnPressed.connect(self.on_angle_text_entered)
923
- self.text_box_param.returnPressed.connect(self.on_param_text_entered)
924
- self.save_mech_pkl.returnPressed.connect(self.on_save_save_mech_pkl)
925
- self.save_figure_box.returnPressed.connect(self.on_save_figure_box)
926
- for slider in self.joint_sliders:
927
- slider.valueChanged.connect(self.on_joint_slider_changed)
928
-
929
- # Set initial configuration (home position)
930
- self.move_slider.setValue(self.move_slider.minimum())
931
- self.plot_slider_update(self.move_slider.value() / 100.0)
932
-
933
- self.setWindowTitle('Rational Linkages')
934
-
935
- # --- Helper to create a “float slider” (using integer scaling) ---
936
- def create_float_slider(self, min_val, max_val, init_val,
937
- orientation=QtCore.Qt.Orientation.Horizontal):
938
- slider = QtWidgets.QSlider(orientation)
939
- slider.setMinimum(int(min_val * 100))
940
- slider.setMaximum(int(max_val * 100))
941
- slider.setValue(int(init_val * 100))
942
- slider.setTickPosition(QtWidgets.QSlider.TickPosition.TicksBelow)
943
- slider.setTickInterval(10)
944
- return slider
945
-
946
- def _init_joint_sliders(self, idx, slider_limit):
947
- """
948
- Create a pair of vertical sliders for joint connection parameters.
949
- (The slider values are scaled by 100.)
950
- """
951
- slider0 = self.create_float_slider(-slider_limit,
952
- slider_limit,
953
- 0.0,
954
- orientation=QtCore.Qt.Orientation.Vertical)
955
- slider1 = self.create_float_slider(-slider_limit,
956
- slider_limit,
957
- 0.0,
958
- orientation=QtCore.Qt.Orientation.Vertical)
959
- return slider0, slider1
960
-
961
- def _plot_tool_path(self):
962
- """
963
- Plot the tool path (as a continuous line) using a set of computed points.
964
- """
965
- t_lin = np.linspace(0, 2 * np.pi, self.steps)
966
- t_vals = [self.mechanism.factorizations[0].joint_angle_to_t_param(t)
967
- for t in t_lin]
968
- ee_points = [self.mechanism.factorizations[0].direct_kinematics_of_tool(
969
- t, self.mechanism.tool_frame.dq2point_via_matrix())
970
- for t in t_vals]
971
-
972
- if self.base_arr is not None:
973
- # transform the end-effector points by the base transformation
974
- ee_points = [self.base_arr @ np.insert(p, 0, 1) for p in ee_points]
975
- # normalize
976
- ee_points = [p[1:4]/p[0] for p in ee_points]
977
-
978
- pts = np.array(ee_points)
979
- tool_path = gl.GLLinePlotItem(pos=pts,
980
- color=(0.5, 0.5, 0.5, 1),
981
- glOptions=self.render_mode,
982
- width=2,
983
- antialias=True)
984
- self.plotter.widget.addItem(tool_path)
985
-
986
- # --- Slots for interactive control events ---
987
- def on_move_slider_changed(self, value):
988
- """
989
- Called when the driving joint angle slider is moved.
990
- """
991
- angle = value / 100.0 # Convert back to a float value.
992
- self.plot_slider_update(angle)
813
+ self.base = None
814
+ self.base_arr = None
993
815
 
994
- def on_angle_text_entered(self):
995
- """
996
- Called when the angle text box is submitted.
997
- """
998
- try:
999
- val = float(self.text_box_angle.text())
1000
- # Normalize angle to [0, 2*pi]
1001
- if val >= 0:
1002
- val = val % (2 * np.pi)
816
+ self.white_background = white_background
817
+ if self.white_background:
818
+ self.render_mode = 'translucent'
1003
819
  else:
1004
- val = (val % (2 * np.pi)) - np.pi
1005
- self.move_slider.setValue(int(val * 100))
1006
- except ValueError:
1007
- pass
1008
-
1009
- def on_param_text_entered(self):
1010
- """
1011
- Called when the t-parameter text box is submitted.
1012
- """
1013
- try:
1014
- val = float(self.text_box_param.text())
1015
- self.plot_slider_update(val, t_param=val)
1016
- joint_angle = self.mechanism.factorizations[0].t_param_to_joint_angle(val)
1017
- self.move_slider.setValue(int(joint_angle * 100))
1018
- except ValueError:
1019
- pass
1020
-
1021
- def on_save_save_mech_pkl(self):
1022
- """
1023
- Called when the save text box is submitted.
1024
- """
1025
- filename = self.save_mech_pkl.text()
1026
- self.mechanism.save(filename=filename)
1027
-
1028
- QtWidgets.QMessageBox.information(self,
1029
- "Success",
1030
- f"Mechanism saved as {filename}.pkl")
1031
-
1032
- def on_save_figure_box(self):
1033
- """
1034
- Called when the filesave text box is submitted.
1035
-
1036
- Saves the current figure in the specified format.
1037
- """
1038
- filename = self.save_figure_box.text()
1039
-
1040
- # better quality but does not save the text overlay
1041
- #self.plotter.widget.readQImage().save(filename + "_old.png")
1042
- #self.plotter.widget.readQImage().save(filename + "_old.png", quality=100)
1043
-
1044
- image = QtGui.QImage(self.plotter.widget.size(),
1045
- QtGui.QImage.Format.Format_ARGB32_Premultiplied)
1046
- image.fill(QtCore.Qt.GlobalColor.transparent)
1047
-
1048
- # Create a painter and render the widget into the image
1049
- painter = QtGui.QPainter(image)
1050
- self.plotter.widget.render(painter)
1051
- painter.end()
1052
-
1053
- # Save the image
1054
- image.save(filename + ".png", "PNG", 80)
1055
-
1056
- QtWidgets.QMessageBox.information(self,
1057
- "Success",
1058
- f"Figure saved as {filename}.png")
820
+ self.render_mode = 'additive'
821
+
822
+ # Create the PlotterPyqtgraph instance.
823
+ self.plotter = PlotterPyqtgraph(base=None,
824
+ steps=self.steps,
825
+ arrows_length=self.arrows_length,
826
+ white_background=self.white_background,
827
+ parent_app=parent_app)
828
+ # Optionally adjust the camera.
829
+ self.plotter.widget.setCameraPosition(distance=10, azimuth=30, elevation=30)
830
+
831
+ # Main layout: split between the 3D view and a control panel.
832
+ main_layout = QtWidgets.QHBoxLayout(self)
833
+
834
+ # Add the 3D view (PlotterPyqtgraph’s widget) to the layout.
835
+ main_layout.addWidget(self.plotter.widget, stretch=5)
836
+
837
+ # Create the control panel (on the right).
838
+ control_panel = QtWidgets.QWidget()
839
+ control_layout = QtWidgets.QVBoxLayout(control_panel)
840
+
841
+ # --- Driving joint angle slider ---
842
+ control_layout.addWidget(QtWidgets.QLabel("Joint angle [rad]:"))
843
+ self.move_slider = self.create_float_slider(0.0, 2 * np.pi, 0.0,
844
+ orientation=QtCore.Qt.Orientation.Horizontal)
845
+ control_layout.addWidget(self.move_slider)
846
+
847
+ # --- Text boxes ---
848
+ self.text_box_angle = QtWidgets.QLineEdit()
849
+ self.text_box_angle.setPlaceholderText("Set angle [rad]:")
850
+ control_layout.addWidget(self.text_box_angle)
851
+
852
+ self.text_box_param = QtWidgets.QLineEdit()
853
+ self.text_box_param.setPlaceholderText("Set parameter t [-]:")
854
+ control_layout.addWidget(self.text_box_param)
855
+
856
+ self.save_mech_pkl = QtWidgets.QLineEdit()
857
+ self.save_mech_pkl.setPlaceholderText("Save mechanism PKL, filename:")
858
+ control_layout.addWidget(self.save_mech_pkl)
859
+
860
+ self.save_figure_box = QtWidgets.QLineEdit()
861
+ self.save_figure_box.setPlaceholderText("Save figure PNG, filename:")
862
+ control_layout.addWidget(self.save_figure_box)
863
+
864
+ # --- Joint connection sliders ---
865
+ joint_sliders_layout = QtWidgets.QHBoxLayout()
866
+ self.joint_sliders = []
867
+
868
+ # Initialize sliders for each joint
869
+ for i in range(self.mechanism.num_joints):
870
+ slider0, slider1 = self._init_joint_sliders(i, self.joint_sliders_lim)
871
+ self.joint_sliders.append(slider0)
872
+ self.joint_sliders.append(slider1)
873
+
874
+ # Arrange sliders vertically for each joint
875
+ joint_layout = QtWidgets.QVBoxLayout()
876
+
877
+ joint_layout.addWidget(QtWidgets.QLabel(f"j{i}cp0"))
878
+ joint_layout.addWidget(slider0)
879
+ joint_layout.addWidget(QtWidgets.QLabel(f"j{i}cp1"))
880
+ joint_layout.addWidget(slider1)
881
+
882
+ joint_sliders_layout.addLayout(joint_layout)
883
+
884
+ control_layout.addLayout(joint_sliders_layout)
885
+
886
+ # Set default values for the first factorization
887
+ for i in range(self.mechanism.factorizations[0].number_of_factors):
888
+ default_val0 = self.mechanism.factorizations[0].linkage[i].points_params[0]
889
+ default_val1 = self.mechanism.factorizations[0].linkage[i].points_params[1]
890
+ self.joint_sliders[2 * i].setValue(int(default_val0 * 100))
891
+ self.joint_sliders[2 * i + 1].setValue(int(default_val1 * 100))
892
+
893
+ # Set default values for the second factorization
894
+ offset = 2 * self.mechanism.factorizations[0].number_of_factors
895
+ for i in range(self.mechanism.factorizations[1].number_of_factors):
896
+ default_val0 = self.mechanism.factorizations[1].linkage[i].points_params[0]
897
+ default_val1 = self.mechanism.factorizations[1].linkage[i].points_params[1]
898
+ self.joint_sliders[offset + 2 * i].setValue(int(default_val0 * 100))
899
+ self.joint_sliders[offset + 2 * i + 1].setValue(int(default_val1 * 100))
900
+
901
+ main_layout.addWidget(control_panel, stretch=1)
902
+
903
+ # --- Initialize plot items for the mechanism links ---
904
+ self.lines = []
905
+ num_lines = self.mechanism.num_joints * 2
906
+ for i in range(num_lines):
907
+ # if i is even, make the link color green, and joints red
908
+ if i % 2 == 0:
909
+ line_item = gl.GLLinePlotItem(pos=np.zeros((2, 3)),
910
+ color=(0, 1, 0, 1),
911
+ glOptions=self.render_mode,
912
+ width=5,
913
+ antialias=True)
914
+ else:
915
+ line_item = gl.GLLinePlotItem(pos=np.zeros((2, 3)),
916
+ color=(1, 0, 0, 1),
917
+ glOptions=self.render_mode,
918
+ width=5,
919
+ antialias=True)
920
+ self.lines.append(line_item)
921
+ self.plotter.widget.addItem(line_item)
922
+
923
+ # --- If desired, initialize tool plot and tool frame ---
924
+ if self.show_tool:
925
+ self.tool_link = gl.GLLinePlotItem(pos=np.zeros((3, 3)),
926
+ color=(0, 1, 0, 0.5),
927
+ glOptions=self.render_mode,
928
+ width=5,
929
+ antialias=True)
930
+ self.plotter.widget.addItem(self.tool_link)
931
+ self.tool_frame = FramePlotHelper(
932
+ transform=TransfMatrix(self.mechanism.tool_frame.dq2matrix()),
933
+ length=self.arrows_length)
934
+ self.tool_frame.addToView(self.plotter.widget)
935
+
936
+ # --- Plot the tool path ---
937
+ self._plot_tool_path()
938
+
939
+ # --- Connect signals to slots ---
940
+ self.move_slider.valueChanged.connect(self.on_move_slider_changed)
941
+ self.text_box_angle.returnPressed.connect(self.on_angle_text_entered)
942
+ self.text_box_param.returnPressed.connect(self.on_param_text_entered)
943
+ self.save_mech_pkl.returnPressed.connect(self.on_save_save_mech_pkl)
944
+ self.save_figure_box.returnPressed.connect(self.on_save_figure_box)
945
+ for slider in self.joint_sliders:
946
+ slider.valueChanged.connect(self.on_joint_slider_changed)
947
+
948
+ # Set initial configuration (home position)
949
+ self.move_slider.setValue(self.move_slider.minimum())
950
+ self.plot_slider_update(self.move_slider.value() / 100.0)
951
+
952
+ self.setWindowTitle('Rational Linkages')
953
+
954
+ # --- Helper to create a “float slider” (using integer scaling) ---
955
+ def create_float_slider(self, min_val, max_val, init_val,
956
+ orientation=QtCore.Qt.Orientation.Horizontal):
957
+ slider = QtWidgets.QSlider(orientation)
958
+ slider.setMinimum(int(min_val * 100))
959
+ slider.setMaximum(int(max_val * 100))
960
+ slider.setValue(int(init_val * 100))
961
+ slider.setTickPosition(QtWidgets.QSlider.TickPosition.TicksBelow)
962
+ slider.setTickInterval(10)
963
+ return slider
964
+
965
+ def _init_joint_sliders(self, idx, slider_limit):
966
+ """
967
+ Create a pair of vertical sliders for joint connection parameters.
968
+ (The slider values are scaled by 100.)
969
+ """
970
+ slider0 = self.create_float_slider(-slider_limit,
971
+ slider_limit,
972
+ 0.0,
973
+ orientation=QtCore.Qt.Orientation.Vertical)
974
+ slider1 = self.create_float_slider(-slider_limit,
975
+ slider_limit,
976
+ 0.0,
977
+ orientation=QtCore.Qt.Orientation.Vertical)
978
+ return slider0, slider1
979
+
980
+ def _plot_tool_path(self):
981
+ """
982
+ Plot the tool path (as a continuous line) using a set of computed points.
983
+ """
984
+ t_lin = np.linspace(0, 2 * np.pi, self.steps)
985
+ t_vals = [self.mechanism.factorizations[0].joint_angle_to_t_param(t)
986
+ for t in t_lin]
987
+ ee_points = [self.mechanism.factorizations[0].direct_kinematics_of_tool(
988
+ t, self.mechanism.tool_frame.dq2point_via_matrix())
989
+ for t in t_vals]
990
+
991
+ if self.base_arr is not None:
992
+ # transform the end-effector points by the base transformation
993
+ ee_points = [self.base_arr @ np.insert(p, 0, 1) for p in ee_points]
994
+ # normalize
995
+ ee_points = [p[1:4]/p[0] for p in ee_points]
996
+
997
+ pts = np.array(ee_points)
998
+ tool_path = gl.GLLinePlotItem(pos=pts,
999
+ color=(0.5, 0.5, 0.5, 1),
1000
+ glOptions=self.render_mode,
1001
+ width=2,
1002
+ antialias=True)
1003
+ self.plotter.widget.addItem(tool_path)
1004
+
1005
+ # --- Slots for interactive control events ---
1006
+ def on_move_slider_changed(self, value):
1007
+ """
1008
+ Called when the driving joint angle slider is moved.
1009
+ """
1010
+ angle = value / 100.0 # Convert back to a float value.
1011
+ self.plot_slider_update(angle)
1012
+
1013
+ def on_angle_text_entered(self):
1014
+ """
1015
+ Called when the angle text box is submitted.
1016
+ """
1017
+ try:
1018
+ val = float(self.text_box_angle.text())
1019
+ # Normalize angle to [0, 2*pi]
1020
+ if val >= 0:
1021
+ val = val % (2 * np.pi)
1022
+ else:
1023
+ val = (val % (2 * np.pi)) - np.pi
1024
+ self.move_slider.setValue(int(val * 100))
1025
+ except ValueError:
1026
+ pass
1027
+
1028
+ def on_param_text_entered(self):
1029
+ """
1030
+ Called when the t-parameter text box is submitted.
1031
+ """
1032
+ try:
1033
+ val = float(self.text_box_param.text())
1034
+ self.plot_slider_update(val, t_param=val)
1035
+ joint_angle = self.mechanism.factorizations[0].t_param_to_joint_angle(val)
1036
+ self.move_slider.setValue(int(joint_angle * 100))
1037
+ except ValueError:
1038
+ pass
1039
+
1040
+ def on_save_save_mech_pkl(self):
1041
+ """
1042
+ Called when the save text box is submitted.
1043
+ """
1044
+ filename = self.save_mech_pkl.text()
1045
+ self.mechanism.save(filename=filename)
1046
+
1047
+ QtWidgets.QMessageBox.information(self,
1048
+ "Success",
1049
+ f"Mechanism saved as {filename}.pkl")
1050
+
1051
+ def on_save_figure_box(self):
1052
+ """
1053
+ Called when the filesave text box is submitted.
1054
+
1055
+ Saves the current figure in the specified format.
1056
+ """
1057
+ filename = self.save_figure_box.text()
1058
+
1059
+ # better quality but does not save the text overlay
1060
+ #self.plotter.widget.readQImage().save(filename + "_old.png")
1061
+ #self.plotter.widget.readQImage().save(filename + "_old.png", quality=100)
1062
+
1063
+ image = QtGui.QImage(self.plotter.widget.size(),
1064
+ QtGui.QImage.Format.Format_ARGB32_Premultiplied)
1065
+ image.fill(QtCore.Qt.GlobalColor.transparent)
1066
+
1067
+ # Create a painter and render the widget into the image
1068
+ painter = QtGui.QPainter(image)
1069
+ self.plotter.widget.render(painter)
1070
+ painter.end()
1071
+
1072
+ # Save the image
1073
+ image.save(filename + ".png", "PNG", 80)
1074
+
1075
+ QtWidgets.QMessageBox.information(self,
1076
+ "Success",
1077
+ f"Figure saved as {filename}.png")
1078
+
1079
+ def on_joint_slider_changed(self, value):
1080
+ """
1081
+ Called when any joint slider is changed.
1082
+ Updates the joint connection parameters and refreshes the plot.
1083
+ """
1084
+ num_of_factors = self.mechanism.factorizations[0].number_of_factors
1085
+ # Update first factorization's linkage parameters.
1086
+ for i in range(num_of_factors):
1087
+ self.mechanism.factorizations[0].linkage[i].set_point_by_param(
1088
+ 0, self.joint_sliders[2 * i].value() / 100.0)
1089
+ self.mechanism.factorizations[0].linkage[i].set_point_by_param(
1090
+ 1, self.joint_sliders[2 * i + 1].value() / 100.0)
1091
+ # Update second factorization's linkage parameters.
1092
+ for i in range(num_of_factors):
1093
+ self.mechanism.factorizations[1].linkage[i].set_point_by_param(
1094
+ 0, self.joint_sliders[2 * num_of_factors + 2 * i].value() / 100.0)
1095
+ self.mechanism.factorizations[1].linkage[i].set_point_by_param(
1096
+ 1, self.joint_sliders[2 * num_of_factors + 1 + 2 * i].value() / 100.0)
1097
+ self.plot_slider_update(self.move_slider.value() / 100.0)
1098
+
1099
+ def plot_slider_update(self, angle, t_param=None):
1100
+ """
1101
+ Update the mechanism plot based on the current joint angle or t parameter.
1102
+ """
1103
+ if t_param is not None:
1104
+ t = t_param
1105
+ else:
1106
+ t = self.mechanism.factorizations[0].joint_angle_to_t_param(angle)
1059
1107
 
1060
- def on_joint_slider_changed(self, value):
1061
- """
1062
- Called when any joint slider is changed.
1063
- Updates the joint connection parameters and refreshes the plot.
1064
- """
1065
- num_of_factors = self.mechanism.factorizations[0].number_of_factors
1066
- # Update first factorization's linkage parameters.
1067
- for i in range(num_of_factors):
1068
- self.mechanism.factorizations[0].linkage[i].set_point_by_param(
1069
- 0, self.joint_sliders[2 * i].value() / 100.0)
1070
- self.mechanism.factorizations[0].linkage[i].set_point_by_param(
1071
- 1, self.joint_sliders[2 * i + 1].value() / 100.0)
1072
- # Update second factorization's linkage parameters.
1073
- for i in range(num_of_factors):
1074
- self.mechanism.factorizations[1].linkage[i].set_point_by_param(
1075
- 0, self.joint_sliders[2 * num_of_factors + 2 * i].value() / 100.0)
1076
- self.mechanism.factorizations[1].linkage[i].set_point_by_param(
1077
- 1, self.joint_sliders[2 * num_of_factors + 1 + 2 * i].value() / 100.0)
1078
- self.plot_slider_update(self.move_slider.value() / 100.0)
1079
-
1080
- def plot_slider_update(self, angle, t_param=None):
1081
- """
1082
- Update the mechanism plot based on the current joint angle or t parameter.
1083
- """
1084
- if t_param is not None:
1085
- t = t_param
1086
- else:
1087
- t = self.mechanism.factorizations[0].joint_angle_to_t_param(angle)
1088
-
1089
- # Compute link positions.
1090
- links = (self.mechanism.factorizations[0].direct_kinematics(t) +
1091
- self.mechanism.factorizations[1].direct_kinematics(t)[::-1])
1092
- links.insert(0, links[-1])
1093
-
1094
- if self.base is not None:
1095
- # Transform the links by the base transformation.
1096
- links = [self.base_arr @ np.insert(p, 0, 1) for p in links]
1097
- # Normalize the homogeneous coordinates.
1098
- links = [p[1:4] / p[0] for p in links]
1099
-
1100
- # Update each line segment.
1101
- for i, line in enumerate(self.lines):
1102
- pt1 = links[i]
1103
- pt2 = links[i+1]
1104
- pts = np.array([pt1, pt2])
1105
- line.setData(pos=pts)
1106
-
1107
- if self.show_tool:
1108
- pts0 = self.mechanism.factorizations[0].direct_kinematics(t)[-1]
1109
- pts1 = self.mechanism.factorizations[0].direct_kinematics_of_tool(
1110
- t, self.mechanism.tool_frame.dq2point_via_matrix())
1111
- pts2 = self.mechanism.factorizations[1].direct_kinematics(t)[-1]
1112
-
1113
- tool_triangle = [pts0, pts1, pts2]
1108
+ # Compute link positions.
1109
+ links = (self.mechanism.factorizations[0].direct_kinematics(t) +
1110
+ self.mechanism.factorizations[1].direct_kinematics(t)[::-1])
1111
+ links.insert(0, links[-1])
1114
1112
 
1115
1113
  if self.base is not None:
1116
- # Transform the tool triangle by the base transformation.
1117
- tool_triangle = [self.base_arr @ np.insert(p, 0, 1)
1118
- for p in tool_triangle]
1114
+ # Transform the links by the base transformation.
1115
+ links = [self.base_arr @ np.insert(p, 0, 1) for p in links]
1119
1116
  # Normalize the homogeneous coordinates.
1120
- tool_triangle = [p[1:4] / p[0] for p in tool_triangle]
1121
-
1122
- self.tool_link.setData(pos=np.array(tool_triangle))
1123
-
1124
- # Update tool frame (pose) arrows.
1125
- pose_dq = DualQuaternion(self.mechanism.evaluate(t))
1126
- # Compute the pose matrix by composing the mechanism’s pose and tool frame.
1127
- pose_matrix = TransfMatrix(pose_dq.dq2matrix()) * TransfMatrix(
1128
- self.mechanism.tool_frame.dq2matrix())
1129
-
1130
- if self.base is not None:
1131
- # Transform the pose matrix by the base transformation.
1132
- pose_matrix = self.base * pose_matrix
1133
-
1134
- self.tool_frame.setData(pose_matrix)
1135
-
1136
- self.plotter.widget.update()
1137
-
1117
+ links = [p[1:4] / p[0] for p in links]
1118
+
1119
+ # Update each line segment.
1120
+ for i, line in enumerate(self.lines):
1121
+ pt1 = links[i]
1122
+ pt2 = links[i+1]
1123
+ pts = np.array([pt1, pt2])
1124
+ line.setData(pos=pts)
1125
+
1126
+ if self.show_tool:
1127
+ pts0 = self.mechanism.factorizations[0].direct_kinematics(t)[-1]
1128
+ pts1 = self.mechanism.factorizations[0].direct_kinematics_of_tool(
1129
+ t, self.mechanism.tool_frame.dq2point_via_matrix())
1130
+ pts2 = self.mechanism.factorizations[1].direct_kinematics(t)[-1]
1131
+
1132
+ tool_triangle = [pts0, pts1, pts2]
1133
+
1134
+ if self.base is not None:
1135
+ # Transform the tool triangle by the base transformation.
1136
+ tool_triangle = [self.base_arr @ np.insert(p, 0, 1)
1137
+ for p in tool_triangle]
1138
+ # Normalize the homogeneous coordinates.
1139
+ tool_triangle = [p[1:4] / p[0] for p in tool_triangle]
1140
+
1141
+ self.tool_link.setData(pos=np.array(tool_triangle))
1142
+
1143
+ # Update tool frame (pose) arrows.
1144
+ pose_dq = DualQuaternion(self.mechanism.evaluate(t))
1145
+ # Compute the pose matrix by composing the mechanism’s pose and tool frame.
1146
+ pose_matrix = TransfMatrix(pose_dq.dq2matrix()) * TransfMatrix(
1147
+ self.mechanism.tool_frame.dq2matrix())
1148
+
1149
+ if self.base is not None:
1150
+ # Transform the pose matrix by the base transformation.
1151
+ pose_matrix = self.base * pose_matrix
1152
+
1153
+ self.tool_frame.setData(pose_matrix)
1154
+
1155
+ self.plotter.widget.update()
1156
+ else:
1157
+ InteractivePlotterWidget = None
1138
1158
 
1139
1159
  class InteractivePlotter:
1140
1160
  """