From a3665303aa23d4b54484c496d5cbb8c5dae2f857 Mon Sep 17 00:00:00 2001 From: tfmoraes Date: Mon, 23 Nov 2009 18:28:26 +0000 Subject: [PATCH] ENH: A box in each slice_data --- invesalius/data/slice_data.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ invesalius/data/viewer_slice.py | 18 ++++++++++++++++-- 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/invesalius/data/slice_data.py b/invesalius/data/slice_data.py index 32f51b0..2ab74aa 100644 --- a/invesalius/data/slice_data.py +++ b/invesalius/data/slice_data.py @@ -29,6 +29,7 @@ class SliceData(object): self.orientation = 'AXIAL' self.renderer = None self.__create_text() + self.__create_box() def __create_text(self): colour = const.ORIENTATION_COLOUR[self.orientation] @@ -41,6 +42,42 @@ class SliceData(object): text.SetValue(self.number) self.text = text + def __create_box(self): + xi = yi = 0.1 + xf = yf = 200 + line_i = vtk.vtkLineSource() + line_i.SetPoint1((xi, yi, 0)) + line_i.SetPoint2((xf, yi, 0)) + self.line_i = line_i + + line_s = vtk.vtkLineSource() + line_s.SetPoint1((xi, yf, 0)) + line_s.SetPoint2((xf, yf, 0)) + self.line_s = line_s + + line_l = vtk.vtkLineSource() + line_l.SetPoint1((xi, yi, 0)) + line_l.SetPoint2((xi, yf, 0)) + self.line_l = line_l + + line_r = vtk.vtkLineSource() + line_r.SetPoint1((xf, yi, 0)) + line_r.SetPoint2((xf, yf, 0)) + self.line_r = line_r + + box = vtk.vtkAppendPolyData() + box.AddInput(line_i.GetOutput()) + box.AddInput(line_s.GetOutput()) + box.AddInput(line_l.GetOutput()) + box.AddInput(line_r.GetOutput()) + + box_mapper = vtk.vtkPolyDataMapper2D() + box_mapper.SetInput(box.GetOutput()) + + box_actor = vtk.vtkActor2D() + box_actor.SetMapper(box_mapper) + self.box_actor = box_actor + def SetCursor(self, cursor): if self.cursor: self.renderer.RemoveActor(self.cursor.actor) @@ -55,11 +92,32 @@ class SliceData(object): self.orientation = orientation colour = const.ORIENTATION_COLOUR[self.orientation] self.text.SetColour(colour) + self.box_actor.GetProperty().SetColor(colour) + + def SetSize(self, size): + w, h = size + xi = yi = 0.1 + xf = w - 0.1 + yf = h - 0.1 + + self.line_i.SetPoint1((xi, yi, 0)) + self.line_i.SetPoint2((xf, yi, 0)) + + self.line_s.SetPoint1((xi, yf, 0)) + self.line_s.SetPoint2((xf, yf, 0)) + + self.line_l.SetPoint1((xi, yi, 0)) + self.line_l.SetPoint2((xi, yf, 0)) + + self.line_r.SetPoint1((xf, yi, 0)) + self.line_r.SetPoint2((xf, yf, 0)) def Hide(self): self.renderer.RemoveActor(self.actor) self.renderer.RemoveActor(self.text.actor) + self.renderer.RemoveActor(self.box_actor) def Show(self): self.renderer.AddActor(self.actor) self.renderer.AddActor(self.text.actor) + self.renderer.AddActor(self.box_actor) diff --git a/invesalius/data/viewer_slice.py b/invesalius/data/viewer_slice.py index aaa28eb..5e2ec8b 100755 --- a/invesalius/data/viewer_slice.py +++ b/invesalius/data/viewer_slice.py @@ -45,8 +45,8 @@ class Viewer(wx.Panel): def __init__(self, prnt, orientation='AXIAL'): wx.Panel.__init__(self, prnt, size=wx.Size(320, 300)) - colour = [255*c for c in const.ORIENTATION_COLOUR[orientation]] - self.SetBackgroundColour(colour) + #colour = [255*c for c in const.ORIENTATION_COLOUR[orientation]] + #self.SetBackgroundColour(colour) # Interactor additional style self.modes = []#['DEFAULT'] @@ -830,6 +830,7 @@ class Viewer(wx.Panel): #self.scroll.Bind(wx.EVT_SCROLL_ENDSCROLL, self.OnScrollBarRelease) self.interactor.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) self.interactor.Bind(wx.EVT_CONTEXT_MENU, self.OnContextMenu) + self.Bind(wx.EVT_SIZE, self.OnSize) def LoadImagedata(self, pubsub_evt): imagedata, mask_dict = pubsub_evt.data @@ -853,6 +854,9 @@ class Viewer(wx.Panel): proportion_y = 1.0 / self.layout[1] # The (0,0) in VTK is in bottom left. So the creation from renderers # must be # in inverted order, from the top left to bottom right + w, h = self.interactor.GetRenderWindow().GetSize() + w *= proportion_x + h *= proportion_y n = 0 for j in xrange(self.layout[1]-1, -1, -1): for i in xrange(self.layout[0]): @@ -868,6 +872,7 @@ class Viewer(wx.Panel): x, y = const.TEXT_POS_LEFT_DOWN slice_data.text.SetPosition((x+slice_xi,y+slice_yi)) slice_data.SetCursor(self.__create_cursor()) + slice_data.SetSize((w, h)) self.__update_camera(slice_data) n += 1 @@ -1097,6 +1102,7 @@ class Viewer(wx.Panel): slice_data.actor = actor renderer.AddActor(actor) renderer.AddActor(slice_data.text.actor) + renderer.AddActor(slice_data.box_actor) return slice_data def __update_camera(self, slice_data): @@ -1205,6 +1211,14 @@ class Viewer(wx.Panel): if evt: evt.Skip() + def OnSize(self, evt): + w, h = self.interactor.GetRenderWindow().GetSize() + w = float(w) / self.layout[0] + h = float(h) / self.layout[1] + for slice_data in self.slice_data_list: + slice_data.SetSize((w, h)) + evt.Skip() + def set_slice_number(self, index): self.slice_number = index for n, slice_data in enumerate(self.slice_data_list): -- libgit2 0.21.2