"""
This model_view_anypoint module manages the Anypoint view settings and operations within the MoilApp
"""
[docs]
class ModelViewAnypoint:
"""
Class responsible for managing Anypoint view settings and operations.
Attributes:
_model (object): The main model instance of the application.
_map_x_anypoint (numpy.ndarray): Map for the x-coordinate transformation in Anypoint view.
_map_y_anypoint (numpy.ndarray): Map for the y-coordinate transformation in Anypoint view.
_anypoint_mode (str): Current Anypoint mode.
Methods:
anypoint_mode.setter: Setter method for the current Anypoint mode.
maps_anypoint: Getter method for the Anypoint maps.
image_anypoint(image): Transforms the image using the Anypoint maps.
create_maps_anypoint_mode_1(): Creates Anypoint maps for mode 1 based on the configuration file.
create_maps_anypoint_mode_2(): Creates Anypoint maps for mode 2 based on the configuration file.
set_alpha_beta(alpha, beta): Sets the values of alpha and beta and updates the configuration file.
"""
def __init__(self, model):
self._model = model
self._map_x_anypoint = None
self._map_y_anypoint = None
self._anypoint_mode = "mode_1"
@property
def anypoint_mode(self):
"""
Get the current mode for Anypoint transformation.
Return:
str: The current mode for Anypoint transformation.
"""
try:
return self._anypoint_mode
except Exception as e:
self._model.activity_logger.error(f"ModelViewAnypoint.anypoint_mode(): Error: {str(e)}")
@anypoint_mode.setter
def anypoint_mode(self, mode):
"""
Set the mode for Anypoint transformation.
Arg:
mode (str): The mode to set for Anypoint transformation.
"""
try:
self._anypoint_mode = mode
self._model.active_view_mode = mode
except Exception as e:
self._model.activity_logger.error(f"ModelViewAnypoint.anypoint_mode(): Error: {str(e)}")
@property
def maps_anypoint(self):
"""
Get the Anypoint maps.
Returns:
tuple: A tuple containing the X and Y Anypoint maps.
"""
try:
return self._map_x_anypoint, self._map_y_anypoint
except Exception as e:
self._model.activity_logger.error(f"ModelViewAnypoint.maps_anypoint(): Error: {str(e)}")
[docs]
def image_anypoint(self, image):
"""
Apply Anypoint transformation to the given image.
Args:
image: The image to be transformed.
Returns:
The transformed image.
"""
try:
return self._model.remap_image(image, self._map_x_anypoint, self._map_y_anypoint)
except Exception as e:
self._model.activity_logger.error(f"ModelViewAnypoint.image_anypoint(): Error: {str(e)}")
[docs]
def create_maps_anypoint_mode_1(self):
"""
Creates maps for anypoint mode 1 based on the configuration file.
If the configuration file exists, the function loads the alpha, beta, and zoom values for mode 1 from the
configuration file. It then uses the loaded values to create the maps for anypoint mode 1 using the
`moildev.maps_anypoint_mode1()` method. If the `moildev` attribute is not `None`, the function also creates an
image result using the `create_image_result()` method.
Returns:
None.
"""
try:
if self._model.debug_mode:
self._model.activity_logger.info("ModelViewAnypoint: create_maps_anypoint_mode_1(), "
"Creating a maps x and map y image to create Anypoint mode 1.")
alpha = self._model.main_config["Mode_1"]["alpha"]
beta = self._model.main_config["Mode_1"]["beta"]
zoom = self._model.main_config["Mode_1"]["zoom"]
moildev = self._model.set_moildev.moildev_main
if moildev is not None:
self._map_x_anypoint, self._map_y_anypoint = moildev.maps_anypoint_mode1(alpha, beta, zoom)
except Exception as e:
self._model.activity_logger.error(f"ModelViewAnypoint.create_maps_anypoint_mode_1(): Error: {str(e)}")
[docs]
def create_maps_anypoint_mode_2(self):
"""
Creates maps for anypoint mode 2 based on the configuration file.
If the configuration file exists, the function loads the pitch, yaw, roll, and zoom values for mode 2 from the
configuration file. It then uses the loaded values to create the maps for anypoint m)ode 2 using the
`moildev.maps_anypoint_mode2()` method. If the `moildev` attribute is not `None`, the function also creates an
image result using the `create_image_result()` method.
Returns:
None.
"""
try:
if self._model.debug_mode:
self._model.activity_logger.info("ModelViewAnypoint: create_maps_anypoint_mode_2(), "
"Creating a maps x and map y image to create Anypoint mode 2.")
pitch = self._model.main_config["Mode_2"]["pitch"]
yaw = self._model.main_config["Mode_2"]["yaw"]
zoom = self._model.main_config["Mode_2"]["zoom"]
moildev = self._model.set_moildev.moildev_main
if moildev is not None:
self._map_x_anypoint, self._map_y_anypoint = moildev.maps_anypoint_mode2(pitch, yaw, zoom)
except Exception as e:
self._model.activity_logger.error(f"ModelViewAnypoint.create_maps_anypoint_mode_2(): Error: {str(e)}")
[docs]
def set_alpha_beta(self, alpha, beta):
"""
Set the values of alpha and beta and update the configuration file.
Args:
alpha (float): the alpha value to set.
beta (float): the beta value to set.
Returns:
None.
"""
try:
moildev = self._model.set_moildev.moildev_main
coord_x, coord_y = 0, 0
if self._model.main_config["Active_view"] == "mode_1":
if alpha == 75 and beta == 0:
coord_y = moildev.icy - round(moildev.get_rho_from_alpha(alpha))
coord_x = round(moildev.get_rho_from_alpha(beta)) + moildev.icx
elif alpha == 75 and beta == 180:
if any([alpha > 110, beta > 110]):
alpha = alpha - 110
beta = beta - 110
coord_y = moildev.icy + round(moildev.get_rho_from_alpha(beta))
coord_x = moildev.icx
elif alpha == 0 and beta == 0:
coord_y = moildev.icy
coord_x = moildev.icx
elif alpha == 75 and beta == -90:
coord_x = moildev.icx - round(moildev.get_rho_from_alpha(alpha))
coord_y = moildev.icy
elif alpha == 75 and beta == 90:
coord_x = moildev.icx + round(moildev.get_rho_from_alpha(alpha))
coord_y = moildev.icy
else:
if alpha == 75 and beta == 0:
coord_y = moildev.icy - round(moildev.get_rho_from_alpha(alpha))
coord_x = round(moildev.get_rho_from_alpha(beta)) + moildev.icx
elif alpha == -75 and beta == 0:
coord_y = moildev.icy + round(moildev.get_rho_from_alpha(abs(alpha)))
coord_x = moildev.icx
elif alpha == 0 and beta == 0:
coord_y = moildev.icy
coord_x = moildev.icx
elif alpha == 0 and beta == -75:
coord_x = moildev.icx - round(moildev.get_rho_from_alpha(abs(beta)))
coord_y = moildev.icy
elif alpha == 0 and beta == 75:
coord_x = moildev.icx + round(moildev.get_rho_from_alpha(beta))
coord_y = moildev.icy
return coord_x, coord_y
except Exception as e:
self._model.activity_logger.error(f"ModelViewAnypoint.set_alpha_beta(): Error: {str(e)}")