# Path: pytripgui/canvas_vc/plotter/images/patient_image_base.py
# class PatientImageBase(ABC):
#     """
#     Abstract base class that holds CRUD-like methods common for all shown images
# 
#     Method plot(data) must be implemented in subclasses, because it strongly depends on type of shown image
#     """
# 
#     def __init__(self, axes):
#         """
#         Parameters
#         ----------
#         axes : Axes -- axes on which images will be shown
#         """
#         self._axes: Axes = axes
#         self._image: Optional[AxesImage] = None
# 
#     @abstractmethod
#     def plot(self, data) -> None:
#         """
#         Plots image from passed data.
#         """
# 
#     def get(self) -> Optional[AxesImage]:
#         """
#         Returns plotted image.
#         """
#         return self._image
# 
#     def update(self, data) -> None:
#         """
#         Updates data in plotted image.
#         """
#         self._image.set_data(data.data_to_plot)
# 
#     def remove(self) -> None:
#         """
#         Removes image from axes.
#         """
#         self._image.remove()
#         self._image = None
# 
#     def is_present(self) -> bool:
#         """
#         Returns True if image is present and False if image is absent
#         """
#         return self._image is not None
# 
#     def calculate_extent(self, data: PlotDataBase):
#         """
#         Returns extent for passed data.
#         """
#         # get minimal X, Y and Z coordinates
#         cube: Cube = data.cube
#         min_x_mm, min_y_mm, min_z_mm = cube.indices_to_pos([0, 0, 0])
#         # get maximal X, Y and Z coordinates
#         # 'data.cube.dimz - 1' is described in https://github.com/pytrip/pytrip/issues/592
#         max_x_mm, max_y_mm, max_z_mm = cube.indices_to_pos([cube.dimx, cube.dimy, cube.dimz - 1])
#         plane = data.projection_selector.plane
#         # depending on plane, return proper list those above
#         # extent = [horizontal_min, horizontal_max, vertical_min, vertical_max]
#         # "Transversal" (xy)
#         if plane == "Transversal":
#             return min_x_mm, max_x_mm, min_y_mm, max_y_mm
#         # "Sagittal" (yz)
#         if plane == "Sagittal":
#             return min_y_mm, max_y_mm, min_z_mm, max_z_mm
#         # "Coronal" (xz)
#         if plane == "Coronal":
#             return min_x_mm, max_x_mm, min_z_mm, max_z_mm
# 
#         raise ValueError("Wrong plane string - " + plane + " - in " + type(self).__name__)
# 
# Path: pytripgui/canvas_vc/objects/dos.py
# class Dos(PlotDataBase):
#     def __init__(self, cube: Cube, selector: ProjectionSelector):
#         super().__init__(cube, selector)
# 
#         self.dose_axis = DoseAxisType.auto
# 
#         self.dos_scale = None
#         self.min_dose = 0
#         self.max_dose = None
#         self.factor = 1.0
#         self._max_dose_from_cube = None
# 
#     def prepare_data_to_plot(self):
#         if not self.cube:
#             return
# 
#         if self._max_dose_from_cube is None:
#             self._max_dose_from_cube = np.amax(self.cube.cube)
# 
#         self.dos_scale = self._get_proposed_scale()
#         self._set_aspect()
# 
#         if self.dos_scale == DoseAxisType.abs:
#             self.factor = 1000.0 / self.cube.target_dose
#         elif self.dos_scale == DoseAxisType.rel:
#             self.factor = 10.0
# 
#         self.max_dose = self._max_dose_from_cube / self.factor
# 
#         dos_data = self.projection_selector.get_projection(self.cube)
# 
#         self.data_to_plot = dos_data / self.factor
#         self.data_to_plot[self.data_to_plot <= self.min_dose] = self.min_dose
# 
#     def _get_proposed_scale(self):
#         if self.cube.target_dose <= 0:
#             return DoseAxisType.rel
#         if self.dose_axis == DoseAxisType.auto and self.cube.target_dose != 0.0:
#             return DoseAxisType.abs
#         return self.dose_axis


from matplotlib import pyplot as plt
from pytripgui.canvas_vc.plotter.images.patient_image_base import PatientImageBase
from pytripgui.canvas_vc.objects.dos import Dos




class DoseImage(PatientImageBase):
    def __init__(self, axes):
        super().__init__(axes)
        self._colormap = plt.get_cmap()
        self._colormap._init()
        self._colormap._lut[:, -1] = 0.7
        self._colormap._lut[0, -1] = 0.0
        self.zorder = 5

    def plot(self, data: Dos) -> None:
        extent = self.calculate_extent(data)
        self._image = self._axes.imshow(data.data_to_plot,
                                        cmap=self._colormap,
                                        vmax=data.max_dose,

# Path: pytripgui/canvas_vc/plotter/images/patient_image_base.py
# class PatientImageBase(ABC):
#     """
#     Abstract base class that holds CRUD-like methods common for all shown images
# 
#     Method plot(data) must be implemented in subclasses, because it strongly depends on type of shown image
#     """
# 
#     def __init__(self, axes):
#         """
#         Parameters
#         ----------
#         axes : Axes -- axes on which images will be shown
#         """
#         self._axes: Axes = axes
#         self._image: Optional[AxesImage] = None
# 
#     @abstractmethod
#     def plot(self, data) -> None:
#         """
#         Plots image from passed data.
#         """
# 
#     def get(self) -> Optional[AxesImage]:
#         """
#         Returns plotted image.
#         """
#         return self._image
# 
#     def update(self, data) -> None:
#         """
#         Updates data in plotted image.
#         """
#         self._image.set_data(data.data_to_plot)
# 
#     def remove(self) -> None:
#         """
#         Removes image from axes.
#         """
#         self._image.remove()
#         self._image = None
# 
#     def is_present(self) -> bool:
#         """
#         Returns True if image is present and False if image is absent
#         """
#         return self._image is not None
# 
#     def calculate_extent(self, data: PlotDataBase):
#         """
#         Returns extent for passed data.
#         """
#         # get minimal X, Y and Z coordinates
#         cube: Cube = data.cube
#         min_x_mm, min_y_mm, min_z_mm = cube.indices_to_pos([0, 0, 0])
#         # get maximal X, Y and Z coordinates
#         # 'data.cube.dimz - 1' is described in https://github.com/pytrip/pytrip/issues/592
#         max_x_mm, max_y_mm, max_z_mm = cube.indices_to_pos([cube.dimx, cube.dimy, cube.dimz - 1])
#         plane = data.projection_selector.plane
#         # depending on plane, return proper list those above
#         # extent = [horizontal_min, horizontal_max, vertical_min, vertical_max]
#         # "Transversal" (xy)
#         if plane == "Transversal":
#             return min_x_mm, max_x_mm, min_y_mm, max_y_mm
#         # "Sagittal" (yz)
#         if plane == "Sagittal":
#             return min_y_mm, max_y_mm, min_z_mm, max_z_mm
#         # "Coronal" (xz)
#         if plane == "Coronal":
#             return min_x_mm, max_x_mm, min_z_mm, max_z_mm
# 
#         raise ValueError("Wrong plane string - " + plane + " - in " + type(self).__name__)
# 
# Path: pytripgui/canvas_vc/objects/dos.py
# class Dos(PlotDataBase):
#     def __init__(self, cube: Cube, selector: ProjectionSelector):
#         super().__init__(cube, selector)
# 
#         self.dose_axis = DoseAxisType.auto
# 
#         self.dos_scale = None
#         self.min_dose = 0
#         self.max_dose = None
#         self.factor = 1.0
#         self._max_dose_from_cube = None
# 
#     def prepare_data_to_plot(self):
#         if not self.cube:
#             return
# 
#         if self._max_dose_from_cube is None:
#             self._max_dose_from_cube = np.amax(self.cube.cube)
# 
#         self.dos_scale = self._get_proposed_scale()
#         self._set_aspect()
# 
#         if self.dos_scale == DoseAxisType.abs:
#             self.factor = 1000.0 / self.cube.target_dose
#         elif self.dos_scale == DoseAxisType.rel:
#             self.factor = 10.0
# 
#         self.max_dose = self._max_dose_from_cube / self.factor
# 
#         dos_data = self.projection_selector.get_projection(self.cube)
# 
#         self.data_to_plot = dos_data / self.factor
#         self.data_to_plot[self.data_to_plot <= self.min_dose] = self.min_dose
# 
#     def _get_proposed_scale(self):
#         if self.cube.target_dose <= 0:
#             return DoseAxisType.rel
#         if self.dose_axis == DoseAxisType.auto and self.cube.target_dose != 0.0:
#             return DoseAxisType.abs
#         return self.dose_axis


# Path: pytripgui/canvas_vc/plotter/images/dose_image.py
from matplotlib import pyplot as plt
from pytripgui.canvas_vc.plotter.images.patient_image_base import PatientImageBase
from pytripgui.canvas_vc.objects.dos import Dos




class DoseImage(PatientImageBase):
    def __init__(self, axes):
        super().__init__(axes)
        self._colormap = plt.get_cmap()
        self._colormap._init()
        self._colormap._lut[:, -1] = 0.7
        self._colormap._lut[0, -1] = 0.0
        self.zorder = 5

    def plot(self, data: Dos) -> None:
        extent = self.calculate_extent(data)
        self._image = self._axes.imshow(data.data_to_plot,
                                        cmap=self._colormap,
                                        vmax=data.max_dose,

                                        aspect=data.aspect,
