diff --git a/gixstapose/main.py b/gixstapose/main.py index f1b699b..8feeb46 100644 --- a/gixstapose/main.py +++ b/gixstapose/main.py @@ -24,6 +24,7 @@ QVBoxLayout, QWidget, ) +from scipy.ndimage import rotate from gixstapose.diffractometer import Diffractometer from gixstapose.draw_scene import get_scene @@ -132,20 +133,30 @@ def createGridLayout(self): self.button111.setMaximumSize(QSize(100, 40)) botlayout.addWidget(self.button111, 0, 3, 2, 1) + self.button_zplus = QPushButton("rotate +5\N{DEGREE SIGN}") + self.button_zplus.setMaximumSize(QSize(100, 40)) + botlayout.addWidget(self.button_zplus, 0, 4, 2, 1) + + self.button_zminus = QPushButton("rotate -5\N{DEGREE SIGN}") + self.button_zminus.setMaximumSize(QSize(100, 40)) + botlayout.addWidget(self.button_zminus, 0, 5, 2, 1) + # Connect buttons to moving the camera # thanks to this wonderful answer # https://stackoverflow.com/a/57167056/11969403 self.button100.clicked.connect(lambda: self.move_camera((1, 0, 0))) self.button110.clicked.connect(lambda: self.move_camera((1, 1, 0))) self.button111.clicked.connect(lambda: self.move_camera((1, 1, 1))) + self.button_zplus.clicked.connect(lambda: self.rotate_camera(5)) + self.button_zminus.clicked.connect(lambda: self.rotate_camera(-5)) # Add space between buttons and slider - botlayout.setColumnMinimumWidth(4, 350) + botlayout.setColumnMinimumWidth(6, 150) # Zoom slider zlabel = QLabel("Zoom") zlabel.setAlignment(Qt.AlignCenter) - botlayout.addWidget(zlabel, 0, 5) + botlayout.addWidget(zlabel, 0, 7) self.zooms = [i for i in range(1, self.d.N) if self.d.N % i == 0] self.zoomslider = QSlider(Qt.Horizontal) @@ -154,9 +165,9 @@ def createGridLayout(self): self.zoomslider.setValue(self.zooms.index(self.d.zoom)) self.zoomslider.valueChanged.connect(self.change_zoom) self.zoomslider.setMaximumSize(QSize(600, 30)) - botlayout.addWidget(self.zoomslider, 1, 5) + botlayout.addWidget(self.zoomslider, 1, 7) - botlayout.setColumnMinimumWidth(6, 50) + botlayout.setColumnMinimumWidth(8, 50) self.bothorizontalGroupBox.setLayout(botlayout) @@ -223,6 +234,15 @@ def plot_diffract(self, camera): # diffraction pattern self.dp = self.d.diffract_from_camera(camera) + if self.d.up_ang is not None: + dp = rotate( + self.dp, + self.up_ang, + reshape=False, + cval=np.log10(self.bot), + order=1, + ) + self.diffract_ax.imshow(self.dp, cmap="jet") self.diffract_ax.figure.canvas.draw() self.repaint() @@ -234,6 +254,23 @@ def move_camera(self, pos): self.view._start_rendering() self.view.update() + def rotate_camera(self, angle_deg): + """Rotate the camera.""" + angle_rad = np.deg2rad(angle_deg) + + r_mat = np.array( + [ + [np.cos(angle_rad), -np.sin(angle_rad), 0], + [np.sin(angle_rad), np.cos(angle_rad), 0], + [0, 0, 1], + ] + ) + + self.view.scene.camera.up = self.view.scene.camera.up.dot(r_mat) + # self.repaint() + self.view._start_rendering() + self.view.update() + def camera_from_pos(pos): """Create a new camera instance at position."""