"""
This module contains the ControlImageResult class, which provides methods for applying the current view mode to an image
and displaying the resulting image in the UI. It handles functionalities such as applying remapping for 'AnypointView'
and 'PanoramaView', as well as zooming and cropping based on user interaction.
"""
[docs]
class ControlImageResult:
"""
This class provides methods for applying the current view mode to an image and displaying the resulting image in the UI.
It handles functionalities such as applying remapping for 'AnypointView' and 'PanoramaView', as well as zooming and cropping
based on user interaction.
Attributes:
_controller: The controller object responsible for managing the application flow.
_ui_object: User interface object containing UI elements.
_model: The model object containing application data and logic.
_display_image: Function for displaying an image to a label in the UI.
Methods:
_apply_view_mode(image): Apply the current view mode to the image.
_display_result_image(image_result): Display the resulting image in the UI.
create_image_result(): Creates and displays the resulting image in the user interface.
"""
def __init__(self, controller):
self._controller = controller
self._ui_object = controller.ui_object
self._model = controller.model
self.image_result = None
self._display_image = self._controller.model.show_image_to_label
[docs]
def _apply_view_mode(self, image):
"""
Apply the current view mode to the image.
Arg:
image: The image to which the view mode is applied.
Return:
The image after applying the view mode.
"""
try:
if self._model.mode_view == "FisheyeView":
return image
if self._model.mode_view == "AnypointView":
return self._model.view_anypoint.image_anypoint(image)
if self._model.mode_view == "PanoramaView":
image_result = self._model.view_panorama.panorama_image(image)
if self._model.view_panorama.panorama_mode == "car":
return self._model.view_panorama.crop_panorama_car(image_result)
return self._model.view_panorama.crop_panorama_tube(image_result)
# If none of the conditions are met, return the original image
return image
except Exception as e:
self._model.activity_logger.error(f"ControlImageResult._apply_view_mode(): Error: {str(e)}")
return image
[docs]
def _display_result_image(self, image_result):
"""
Display the resulting image in the UI.
Arg:
image_result: The resulting image to be displayed.
"""
try:
if self._model.view_properties.zooming_size is None:
self._model.view_properties.zooming_size = self._controller.width_image_result
if self._model.view_zoom_area.state_rubberband:
image_result = self._model.view_zoom_area.crop_image(image_result)
self._display_image(self._controller.ui_object.label_result, image_result,
self._model.view_properties.zooming_size,
options={"angle": -self._model.view_properties.rotate_degree,
"plus_icon": True})
else:
if self._controller.ctrl_fullscreen.full_screen_mode:
width_full_screen_mode = self._controller.round_to_nearest_100(
self._controller.ctrl_fullscreen.new_window.width())
self._display_image(self._controller.ctrl_fullscreen.label_full_screen,
image_result,
width_full_screen_mode,
options={"plus_icon": True})
else:
self._display_image(self._controller.ui_object.label_result, image_result,
self._model.view_properties.zooming_size,
options={"angle": -self._model.view_properties.rotate_degree,
"plus_icon": True})
self._controller.view_zoom.show_percentage_zoom()
except Exception as e:
self._model.activity_logger.error(f"ControlImageResult._display_result_image(): Error: {str(e)}")
[docs]
def create_image_result(self):
"""
Create and display the resulting image in the user interface.
Modifies the image based on the view mode and checkbox states, such as applying remapping for 'AnypointView'
and 'PanoramaView'. Handles zooming and cropping based on user interaction.
Return:
None
"""
try:
if self._model.debug_mode:
self._model.activity_logger.info(
"ControlImageResult: create_image_result(), Create image result and show to ui")
if self._model.recenter_mode_view:
image = self._model.image_recenter.copy()
else:
image = self._model.process_image_ori()
image_result = self._apply_view_mode(image)
self._model.image_result = image_result
self._display_result_image(image_result)
except Exception as e:
self._model.activity_logger.error(f"ControlImageResult.create_image_result(): Error: {str(e)}")