diff --git a/invesalius/data/vtk_utils.py b/invesalius/data/vtk_utils.py index 0056206..714d3e6 100644 --- a/invesalius/data/vtk_utils.py +++ b/invesalius/data/vtk_utils.py @@ -219,6 +219,8 @@ class TextZero(object): self.text = '' self.position = (0, 0) self.symbolic_syze = wx.FONTSIZE_MEDIUM + self.bottom_pos = False + self.right_pos = False def SetColour(self, colour): self.property.SetColor(colour) @@ -282,10 +284,15 @@ class TextZero(object): coord.SetCoordinateSystemToNormalizedDisplay() coord.SetValue(*self.position) x, y = coord.GetComputedDisplayValue(canvas.evt_renderer) - font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT) # font.SetWeight(wx.FONTWEIGHT_BOLD) font.SetSymbolicSize(self.symbolic_syze) + if self.bottom_pos or self.right_pos: + w, h = canvas.calc_text_size(self.text, font) + if self.right_pos: + x -= w + if self.bottom_pos: + y += h canvas.draw_text(self.text, (x, y), font=font) diff --git a/invesalius/gui/dicom_preview_panel.py b/invesalius/gui/dicom_preview_panel.py index c2509b8..2be5254 100644 --- a/invesalius/gui/dicom_preview_panel.py +++ b/invesalius/gui/dicom_preview_panel.py @@ -37,6 +37,7 @@ import invesalius.data.vtk_utils as vtku import invesalius.utils as utils from invesalius.data import imagedata_utils from invesalius.data import converters +from invesalius.gui.widgets.canvas_renderer import CanvasRendererCTX if sys.platform == 'win32': try: @@ -716,47 +717,63 @@ class SingleImagePreview(wx.Panel): self.window_level = const.WINDOW_LEVEL[_("Bone")][1] def __init_vtk(self): - text_image_size = vtku.Text() + text_image_size = vtku.TextZero() text_image_size.SetPosition(const.TEXT_POS_LEFT_UP) text_image_size.SetValue("") - text_image_size.SetSize(const.TEXT_SIZE_SMALL) + text_image_size.SetSymbolicSize(wx.FONTSIZE_SMALL) self.text_image_size = text_image_size - text_image_location = vtku.Text() - text_image_location.SetVerticalJustificationToBottom() + text_image_location = vtku.TextZero() + # text_image_location.SetVerticalJustificationToBottom() text_image_location.SetPosition(const.TEXT_POS_LEFT_DOWN) text_image_location.SetValue("") - text_image_location.SetSize(const.TEXT_SIZE_SMALL) + text_image_location.bottom_pos = True + text_image_location.SetSymbolicSize(wx.FONTSIZE_SMALL) self.text_image_location = text_image_location - text_patient = vtku.Text() - text_patient.SetJustificationToRight() + text_patient = vtku.TextZero() + # text_patient.SetJustificationToRight() text_patient.SetPosition(const.TEXT_POS_RIGHT_UP) text_patient.SetValue("") - text_patient.SetSize(const.TEXT_SIZE_SMALL) + text_patient.right_pos = True + text_patient.SetSymbolicSize(wx.FONTSIZE_SMALL) self.text_patient = text_patient - text_acquisition = vtku.Text() - text_acquisition.SetJustificationToRight() - text_acquisition.SetVerticalJustificationToBottom() + text_acquisition = vtku.TextZero() + # text_acquisition.SetJustificationToRight() + # text_acquisition.SetVerticalJustificationToBottom() text_acquisition.SetPosition(const.TEXT_POS_RIGHT_DOWN) text_acquisition.SetValue("") - text_acquisition.SetSize(const.TEXT_SIZE_SMALL) + text_acquisition.right_pos = True + text_acquisition.bottom_pos = True + text_acquisition.SetSymbolicSize(wx.FONTSIZE_SMALL) self.text_acquisition = text_acquisition - renderer = vtk.vtkRenderer() - renderer.AddActor(text_image_size.actor) - renderer.AddActor(text_image_location.actor) - renderer.AddActor(text_patient.actor) - renderer.AddActor(text_acquisition.actor) - self.renderer = renderer + self.renderer = vtk.vtkRenderer() + self.renderer.SetLayer(0) + + cam = self.renderer.GetActiveCamera() + + self.canvas_renderer = vtk.vtkRenderer() + self.canvas_renderer.SetLayer(1) + self.canvas_renderer.SetActiveCamera(cam) + self.canvas_renderer.SetInteractive(0) + self.canvas_renderer.PreserveDepthBufferOn() style = vtk.vtkInteractorStyleImage() - self.interactor.GetRenderWindow().AddRenderer(renderer) + self.interactor.GetRenderWindow().SetNumberOfLayers(2) + self.interactor.GetRenderWindow().AddRenderer(self.renderer) + self.interactor.GetRenderWindow().AddRenderer(self.canvas_renderer) self.interactor.SetInteractorStyle(style) self.interactor.Render() + self.canvas = CanvasRendererCTX(self, self.renderer, self.canvas_renderer) + self.canvas.draw_list.append(self.text_image_size) + self.canvas.draw_list.append(self.text_image_location) + self.canvas.draw_list.append(self.text_patient) + self.canvas.draw_list.append(self.text_acquisition) + def __init_gui(self): slider = wx.Slider(self, id=-1, -- libgit2 0.21.2