Commit f4762b06c488e57adb090462cf9354ab13908981
1 parent
6bd21102
Exists in
master
Using canvasrender on import dicom panel (FIX: 278)
Showing
2 changed files
with
44 additions
and
20 deletions
Show diff stats
invesalius/data/vtk_utils.py
... | ... | @@ -219,6 +219,8 @@ class TextZero(object): |
219 | 219 | self.text = '' |
220 | 220 | self.position = (0, 0) |
221 | 221 | self.symbolic_syze = wx.FONTSIZE_MEDIUM |
222 | + self.bottom_pos = False | |
223 | + self.right_pos = False | |
222 | 224 | |
223 | 225 | def SetColour(self, colour): |
224 | 226 | self.property.SetColor(colour) |
... | ... | @@ -282,10 +284,15 @@ class TextZero(object): |
282 | 284 | coord.SetCoordinateSystemToNormalizedDisplay() |
283 | 285 | coord.SetValue(*self.position) |
284 | 286 | x, y = coord.GetComputedDisplayValue(canvas.evt_renderer) |
285 | - | |
286 | 287 | font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT) |
287 | 288 | # font.SetWeight(wx.FONTWEIGHT_BOLD) |
288 | 289 | font.SetSymbolicSize(self.symbolic_syze) |
290 | + if self.bottom_pos or self.right_pos: | |
291 | + w, h = canvas.calc_text_size(self.text, font) | |
292 | + if self.right_pos: | |
293 | + x -= w | |
294 | + if self.bottom_pos: | |
295 | + y += h | |
289 | 296 | canvas.draw_text(self.text, (x, y), font=font) |
290 | 297 | |
291 | 298 | ... | ... |
invesalius/gui/dicom_preview_panel.py
... | ... | @@ -37,6 +37,7 @@ import invesalius.data.vtk_utils as vtku |
37 | 37 | import invesalius.utils as utils |
38 | 38 | from invesalius.data import imagedata_utils |
39 | 39 | from invesalius.data import converters |
40 | +from invesalius.gui.widgets.canvas_renderer import CanvasRendererCTX | |
40 | 41 | |
41 | 42 | if sys.platform == 'win32': |
42 | 43 | try: |
... | ... | @@ -716,47 +717,63 @@ class SingleImagePreview(wx.Panel): |
716 | 717 | self.window_level = const.WINDOW_LEVEL[_("Bone")][1] |
717 | 718 | |
718 | 719 | def __init_vtk(self): |
719 | - text_image_size = vtku.Text() | |
720 | + text_image_size = vtku.TextZero() | |
720 | 721 | text_image_size.SetPosition(const.TEXT_POS_LEFT_UP) |
721 | 722 | text_image_size.SetValue("") |
722 | - text_image_size.SetSize(const.TEXT_SIZE_SMALL) | |
723 | + text_image_size.SetSymbolicSize(wx.FONTSIZE_SMALL) | |
723 | 724 | self.text_image_size = text_image_size |
724 | 725 | |
725 | - text_image_location = vtku.Text() | |
726 | - text_image_location.SetVerticalJustificationToBottom() | |
726 | + text_image_location = vtku.TextZero() | |
727 | + # text_image_location.SetVerticalJustificationToBottom() | |
727 | 728 | text_image_location.SetPosition(const.TEXT_POS_LEFT_DOWN) |
728 | 729 | text_image_location.SetValue("") |
729 | - text_image_location.SetSize(const.TEXT_SIZE_SMALL) | |
730 | + text_image_location.bottom_pos = True | |
731 | + text_image_location.SetSymbolicSize(wx.FONTSIZE_SMALL) | |
730 | 732 | self.text_image_location = text_image_location |
731 | 733 | |
732 | - text_patient = vtku.Text() | |
733 | - text_patient.SetJustificationToRight() | |
734 | + text_patient = vtku.TextZero() | |
735 | + # text_patient.SetJustificationToRight() | |
734 | 736 | text_patient.SetPosition(const.TEXT_POS_RIGHT_UP) |
735 | 737 | text_patient.SetValue("") |
736 | - text_patient.SetSize(const.TEXT_SIZE_SMALL) | |
738 | + text_patient.right_pos = True | |
739 | + text_patient.SetSymbolicSize(wx.FONTSIZE_SMALL) | |
737 | 740 | self.text_patient = text_patient |
738 | 741 | |
739 | - text_acquisition = vtku.Text() | |
740 | - text_acquisition.SetJustificationToRight() | |
741 | - text_acquisition.SetVerticalJustificationToBottom() | |
742 | + text_acquisition = vtku.TextZero() | |
743 | + # text_acquisition.SetJustificationToRight() | |
744 | + # text_acquisition.SetVerticalJustificationToBottom() | |
742 | 745 | text_acquisition.SetPosition(const.TEXT_POS_RIGHT_DOWN) |
743 | 746 | text_acquisition.SetValue("") |
744 | - text_acquisition.SetSize(const.TEXT_SIZE_SMALL) | |
747 | + text_acquisition.right_pos = True | |
748 | + text_acquisition.bottom_pos = True | |
749 | + text_acquisition.SetSymbolicSize(wx.FONTSIZE_SMALL) | |
745 | 750 | self.text_acquisition = text_acquisition |
746 | 751 | |
747 | - renderer = vtk.vtkRenderer() | |
748 | - renderer.AddActor(text_image_size.actor) | |
749 | - renderer.AddActor(text_image_location.actor) | |
750 | - renderer.AddActor(text_patient.actor) | |
751 | - renderer.AddActor(text_acquisition.actor) | |
752 | - self.renderer = renderer | |
752 | + self.renderer = vtk.vtkRenderer() | |
753 | + self.renderer.SetLayer(0) | |
754 | + | |
755 | + cam = self.renderer.GetActiveCamera() | |
756 | + | |
757 | + self.canvas_renderer = vtk.vtkRenderer() | |
758 | + self.canvas_renderer.SetLayer(1) | |
759 | + self.canvas_renderer.SetActiveCamera(cam) | |
760 | + self.canvas_renderer.SetInteractive(0) | |
761 | + self.canvas_renderer.PreserveDepthBufferOn() | |
753 | 762 | |
754 | 763 | style = vtk.vtkInteractorStyleImage() |
755 | 764 | |
756 | - self.interactor.GetRenderWindow().AddRenderer(renderer) | |
765 | + self.interactor.GetRenderWindow().SetNumberOfLayers(2) | |
766 | + self.interactor.GetRenderWindow().AddRenderer(self.renderer) | |
767 | + self.interactor.GetRenderWindow().AddRenderer(self.canvas_renderer) | |
757 | 768 | self.interactor.SetInteractorStyle(style) |
758 | 769 | self.interactor.Render() |
759 | 770 | |
771 | + self.canvas = CanvasRendererCTX(self, self.renderer, self.canvas_renderer) | |
772 | + self.canvas.draw_list.append(self.text_image_size) | |
773 | + self.canvas.draw_list.append(self.text_image_location) | |
774 | + self.canvas.draw_list.append(self.text_patient) | |
775 | + self.canvas.draw_list.append(self.text_acquisition) | |
776 | + | |
760 | 777 | def __init_gui(self): |
761 | 778 | slider = wx.Slider(self, |
762 | 779 | id=-1, | ... | ... |