From 3ca2cf40f8454f24332d7db7a94ec4c18c29a0ee Mon Sep 17 00:00:00 2001 From: tatiana Date: Thu, 19 Nov 2009 21:28:18 +0000 Subject: [PATCH] ENH: Text actors in slice --- invesalius/constants.py | 28 ++++++++++++++++++++-------- invesalius/data/slice_data.py | 4 ++-- invesalius/data/viewer_slice.py | 42 ++++++++++++++++++++++++------------------ invesalius/data/vtk_utils.py | 10 ++++++++-- invesalius/gui/dicom_preview_panel.py | 12 ++++-------- invesalius/gui/frame.py | 2 +- 6 files changed, 59 insertions(+), 39 deletions(-) diff --git a/invesalius/constants.py b/invesalius/constants.py index 0eeaf6b..679de85 100644 --- a/invesalius/constants.py +++ b/invesalius/constants.py @@ -29,17 +29,29 @@ from project import Project TEXT_SIZE = 14 TEXT_SIZE_LARGE = 16 TEXT_COLOUR = (1,1,1) + (X,Y) = (0.03, 0.97) TEXT_POS_LEFT_UP = (X, Y) -TEXT_POS_LEFT_DOWN = (X, 1-Y) -TEXT_POS_LEFT_DOWN_SLC = (X, 1-0.93) -TEXT_POS_RIGHT_UP = (1-X, Y) -TEXT_POS_RIGHT_DOWN = (1-X, 1-Y) TEXT_POSITION = TEXT_POS_LEFT_UP -TEXT_POS_HCENTRE_UP = (0.5, 0.97) -TEXT_POS_HCENTRE_DOWN = (0.5, 0.07) -TEXT_POS_VCENTRE_RIGHT = (0.95, 0.5) -TEXT_POS_VCENPRE_LEFT = (0.03, 0.5) +#------------------------------------------------------------------ +TEXT_POS_LEFT_DOWN = (X, 1-Y) # SetVerticalJustificationToBottom +#------------------------------------------------------------------ +TEXT_POS_RIGHT_UP = (1-X, Y) # SetJustificationToRight +#------------------------------------------------------------------ +TEXT_POS_RIGHT_DOWN = (1-X, 1-Y) # SetVerticalJustificationToBottom & + # SetJustificationToRight +#------------------------------------------------------------------ +TEXT_POS_HCENTRE_DOWN = (0.5, 1-Y) # SetJustificationToCentered + # SetVerticalJustificationToBottom +#------------------------------------------------------------------ +TEXT_POS_HCENTRE_UP = (0.5, Y) # SetJustificationToCentered +#------------------------------------------------------------------ +TEXT_POS_VCENTRE_RIGHT = (1-X, 0.5) # SetVerticalJustificationToCentered + # SetJustificationToRight +#------------------------------------------------------------------ +TEXT_POS_VCENTRE_LEFT = (X, 0.5) # SetVerticalJustificationToCentered +#------------------------------------------------------------------ + # Slice orientation AXIAL = 0 diff --git a/invesalius/data/slice_data.py b/invesalius/data/slice_data.py index b73b800..32f51b0 100644 --- a/invesalius/data/slice_data.py +++ b/invesalius/data/slice_data.py @@ -34,10 +34,10 @@ class SliceData(object): colour = const.ORIENTATION_COLOUR[self.orientation] text = vu.Text() - #text.BoldOn() text.SetColour(colour) - text.SetPosition(const.TEXT_POS_LEFT_DOWN_SLC) text.SetSize(const.TEXT_SIZE_LARGE) + text.SetPosition(const.TEXT_POS_LEFT_DOWN) + text.SetVerticalJustificationToBottom() text.SetValue(self.number) self.text = text diff --git a/invesalius/data/viewer_slice.py b/invesalius/data/viewer_slice.py index 3696b76..d9698ce 100755 --- a/invesalius/data/viewer_slice.py +++ b/invesalius/data/viewer_slice.py @@ -387,14 +387,15 @@ class Viewer(wx.Panel): def EnableText(self): if not (self.wl_text): - text = self.wl_text = vtku.Text() - self.ren.AddActor(text.actor) - proj = project.Project() - self.SetWLText(proj.level, proj.window) - + proj = project.Project() colour = const.ORIENTATION_COLOUR[self.orientation] - #### Orientation text + # Window & Level text + self.wl_text = vtku.Text() + self.SetWLText(proj.level, proj.window) + + + # Orientation text if self.orientation == 'AXIAL': values = ['R', 'L', 'A', 'P'] elif self.orientation == 'SAGITAL': @@ -403,32 +404,40 @@ class Viewer(wx.Panel): values = ['P', 'A', 'T', 'B'] left_text = vtku.Text() - left_text.SetColour(colour) left_text.ShadowOff() - left_text.SetPosition(const.TEXT_POS_VCENPRE_LEFT) + left_text.SetColour(colour) + left_text.SetPosition(const.TEXT_POS_VCENTRE_LEFT) + left_text.SetVerticalJustificationToCentered() left_text.SetValue(values[0]) right_text = vtku.Text() - right_text.SetColour(colour) right_text.ShadowOff() + right_text.SetColour(colour) right_text.SetPosition(const.TEXT_POS_VCENTRE_RIGHT) + right_text.SetVerticalJustificationToCentered() + right_text.SetJustificationToRight() right_text.SetValue(values[1]) up_text = vtku.Text() - up_text.SetColour(colour) up_text.ShadowOff() + up_text.SetColour(colour) up_text.SetPosition(const.TEXT_POS_HCENTRE_UP) + up_text.SetJustificationToCentered() up_text.SetValue(values[2]) down_text = vtku.Text() - down_text.SetColour(colour) down_text.ShadowOff() + down_text.SetColour(colour) down_text.SetPosition(const.TEXT_POS_HCENTRE_DOWN) + down_text.SetJustificationToCentered() + down_text.SetVerticalJustificationToBottom() down_text.SetValue(values[3]) self.orientation_texts = [left_text, right_text, up_text, - down_text] + down_text] + + self.ren.AddActor(self.wl_text.actor) self.ren.AddActor(left_text.actor) self.ren.AddActor(right_text.actor) self.ren.AddActor(up_text.actor) @@ -835,12 +844,9 @@ class Viewer(wx.Panel): position = (slice_xi, slice_yi, slice_xf, slice_yf) slice_data = self.slice_data_list[n] slice_data.renderer.SetViewport(position) - x = slice_xi + (0.03*proportion_x) - ratio = 0 - if self.layout[1] > 1: - ratio = 0.04 - y = slice_yi +(0.09*proportion_y)+ratio - slice_data.text.SetPosition((x,y)) + # Text actor position + x, y = const.TEXT_POS_LEFT_DOWN + slice_data.text.SetPosition((x+slice_xi,y+slice_yi)) slice_data.SetCursor(self.__create_cursor()) self.__update_camera(slice_data) n += 1 diff --git a/invesalius/data/vtk_utils.py b/invesalius/data/vtk_utils.py index efffa4b..ad32815 100644 --- a/invesalius/data/vtk_utils.py +++ b/invesalius/data/vtk_utils.py @@ -103,13 +103,13 @@ class Text(object): mapper.SetTextProperty(property) self.mapper = mapper - x, y = const.TEXT_POSITION actor = vtk.vtkActor2D() actor.SetMapper(mapper) actor.GetPositionCoordinate().SetCoordinateSystemToNormalizedDisplay() - actor.GetPositionCoordinate().SetValue(x,y) self.actor = actor + self.SetPosition(const.TEXT_POS_LEFT_UP) + def SetColour(self, colour): self.property.SetColor(colour) @@ -137,9 +137,15 @@ class Text(object): def SetJustificationToRight(self): self.property.SetJustificationToRight() + def SetJustificationToCentered(self): + self.property.SetJustificationToCentered() + + def SetVerticalJustificationToBottom(self): self.property.SetVerticalJustificationToBottom() + def SetVerticalJustificationToCentered(self): + self.property.SetVerticalJustificationToCentered() def Show(self, value=1): if value: diff --git a/invesalius/gui/dicom_preview_panel.py b/invesalius/gui/dicom_preview_panel.py index cde72a0..2755fd7 100755 --- a/invesalius/gui/dicom_preview_panel.py +++ b/invesalius/gui/dicom_preview_panel.py @@ -60,33 +60,29 @@ class SingleImagePreview(wx.Panel): actor = vtk.vtkImageActor() self.actor = actor - LEFT_UP = (X, Y) = const.TEXT_POS_LEFT_UP text_image_size = vtku.Text() - text_image_size.SetPosition(LEFT_UP) + text_image_size.SetPosition(const.TEXT_POS_LEFT_UP) text_image_size.SetValue("image size") self.text_image_size = text_image_size - LEFT_DOWN = (X, 1-Y) text_image_location = vtku.Text() text_image_location.SetVerticalJustificationToBottom() - text_image_location.SetPosition(LEFT_DOWN) + text_image_location.SetPosition(const.TEXT_POS_LEFT_DOWN) text_image_location.SetValue("localization") self.text_image_location = text_image_location value = "id\nprotocol" - RIGHT_UP = (1-X, Y) text_patient = vtku.Text() text_patient.SetJustificationToRight() - text_patient.SetPosition(RIGHT_UP) + text_patient.SetPosition(const.TEXT_POS_RIGHT_UP) text_patient.SetValue(value) self.text_patient = text_patient value = "date time\n Made in InVesalius" - RIGHT_DOWN = (1-X, 1-Y) text_acquisition = vtku.Text() text_acquisition.SetJustificationToRight() text_acquisition.SetVerticalJustificationToBottom() - text_acquisition.SetPosition(RIGHT_DOWN) + text_acquisition.SetPosition(const.TEXT_POS_RIGHT_DOWN) text_acquisition.SetValue(value) self.text_acquisition = text_acquisition diff --git a/invesalius/gui/frame.py b/invesalius/gui/frame.py index 7369851..5b490e5 100755 --- a/invesalius/gui/frame.py +++ b/invesalius/gui/frame.py @@ -451,7 +451,7 @@ class ProjectToolBar(wx.ToolBar): def OnToolImport(self, event): dirpath = dlg.ShowImportDirDialog() if dirpath: - ps.Publisher().sendMessage("Load data to import panel", path) + ps.Publisher().sendMessage("Load data to import panel", dirpath) event.Skip() def OnToolOpen(self, event): -- libgit2 0.21.2