Source code for controllers.control_view_recenter

"""
This module contains classes for configuring panorama and recentering views in the application.

Classes:
    - PanoramaConfig: Manages configuration related to panorama views, including car and tube modes.
    - RecenterConfig: Manages configuration related to recentering images in the application.

Each class provides methods to handle user interactions, update configurations, and create necessary image transformations.
"""
from PyQt6 import QtCore


[docs] class RecenterConfig: """ This class provides methods to handle user interactions for changing the optical point coordinates, activating the change optical point feature, and creating recentered images based on the original image and recentering maps. Methods: __init__: Initializes a new instance of the RecenterConfig class. _connect_event: Connects UI signals to corresponding slots. activate_change_optical_point: Activates the change optical point feature based on the state of a checkbox. change_coordinate_optical_point: Changes the optical point coordinates based on user input. create_image_recenter: Creates a recentered image based on the original image and recentering maps. """
[docs] def __init__(self, controller): self._controller = controller self._model = controller.model self._ui_object = controller.ui_object self._ui_object.widget_container_content.setCurrentIndex(0) self._ui_object.widget_mode_view.hide() self._ui_object.frame_recenter_image.hide() self._ui_object.frame_pointer_in_recenter_frame.hide() self._ui_object.spinBox_icx.setEnabled(False) self._ui_object.spinBox_icy.setEnabled(False) self._ui_object.doubleSpinBox_alpha_rec.setEnabled(False) self._ui_object.doubleSpinBox_beta_rec.setEnabled(False) self._connect_event()
[docs] def _connect_event(self): self._ui_object.checkBox_reverse_view.toggled.connect(self.activate_change_optical_point) self._ui_object.spinBox_icx.valueChanged.connect(self.change_coordinate_optical_point) self._ui_object.spinBox_icy.valueChanged.connect(self.change_coordinate_optical_point)
[docs] def activate_change_optical_point(self): """ Activate change optical point feature. Arg: state (bool): The state of the checkbox. """ if self._model.debug_mode: self._model.activity_logger.info("RecenterConfig: activate_change_optical_point(), " "Activate change optical point by radio button") if self._controller.model.image_original is not None: if self._controller.model.source_usable: if self._model.set_moildev.moildev_main is None: self._controller.model.mode_view = "FisheyeView" message = ("Source not usable to apply Panorama transformation, \n" "or cant access the parameter of the image on the database," "please select another source or or contact the developer if you are confused.") self._controller.ctrl_message_box.display_message_box(message, "information") else: if self._ui_object.checkBox_reverse_view.isChecked(): self._controller.model.recenter_mode_view = True self._ui_object.frame_recenter_image.show() self._ui_object.label_pos_x.setText(str(self._model.main_config["Image_original"]["center_coord"][0])) self._ui_object.label_pos_y.setText(str(self._model.main_config["Image_original"]["center_coord"][1])) self._ui_object.spinBox_icx.setEnabled(True) self._ui_object.spinBox_icy.setEnabled(True) self._controller.model.view_recenter.create_maps_recenter() self.create_image_recenter() self._ui_object.frame_pointer_in_recenter_frame.show() # self._ui_object.stackedWidget_2.hide() self._controller.display_image_to_ui() else: self._controller.model.recenter_mode_view = False self._ui_object.spinBox_icx.setEnabled(False) self._ui_object.spinBox_icy.setEnabled(False) self._ui_object.frame_recenter_image.hide() self._ui_object.frame_pointer_in_recenter_frame.hide() # self._ui_object.stackedWidget_2.show() self._controller.display_image_to_ui() self._model.save_main_config_update() else: self._controller.model.mode_view = "FisheyeView" message = ("Source not usable to apply anypoint transformation, \n" "or cant access the parameter of the image on the database," "please select another source or or contact the developer if you are confused.") self._controller.ctrl_message_box.display_message_box(message, "information") else: self._controller.model.mode_view = "FisheyeView" message = "No media found, please select the file \nbefore you perform the operation!" self._controller.ctrl_message_box.display_message_box(message, "information")
[docs] def change_coordinate_optical_point(self): """ Change optical point coordinates. """ if self._model.image_original is not None: self._model.main_config["Image_recenter"]["Recenter_coordinate"][0] = self._ui_object.spinBox_icx.value() self._model.main_config["Image_recenter"]["Recenter_coordinate"][1] = self._ui_object.spinBox_icy.value() self._ui_object.doubleSpinBox_alpha_rec.blockSignals(True) self._ui_object.doubleSpinBox_beta_rec.blockSignals(True) self._ui_object.doubleSpinBox_alpha_rec.setValue(round(self._model.main_config["Image_recenter"]["alpha"], 2)) self._ui_object.doubleSpinBox_beta_rec.setValue(round(self._model.main_config["Image_recenter"]["beta"], 2)) self._ui_object.doubleSpinBox_alpha_rec.blockSignals(False) self._ui_object.doubleSpinBox_beta_rec.blockSignals(False) self._controller.model.view_recenter.create_maps_recenter() self.create_image_recenter() self._controller.display_image_to_ui()
[docs] def create_image_recenter(self): """ Create a recentered image. This method generates a recentered image based on the original image and recentering maps. Return: numpy.ndarray: The recentered image. Raise: ValueError: If the recentering maps are not set. """ if self._model.debug_mode: self._model.activity_logger.info("RecenterConfig: create_image_recenter(), " "Create image recenter") # image = self._model.image_ori_used.copy() image = self._model.process_image_ori() maps_x_rt, maps_y_rt, maps_x_rec, maps_y_rec = self._controller.model.view_recenter.maps_recenter image_pano = self._model.remap_image(image, maps_x_rt, maps_y_rt) self._model.image_recenter = self._model.remap_image(image_pano, maps_x_rec, maps_y_rec)