diff --git a/invesalius/data/vtk_utils.py b/invesalius/data/vtk_utils.py index 2edff6b..5c4c99e 100644 --- a/invesalius/data/vtk_utils.py +++ b/invesalius/data/vtk_utils.py @@ -113,7 +113,15 @@ class Text(object): self.mapper.SetInput(str(value)) def SetPosition(self, position): - self.actor.SetPositionCoordinate().SetValue(position) + self.actor.GetPositionCoordinate().SetValue(position[0], + position[1]) + + def SetJustificationToRight(self): + self.property.SetJustificationToRight() + + def SetVerticalJustificationToBottom(self): + self.property.SetVerticalJustificationToBottom() + def Show(self, value=1): if value: diff --git a/invesalius/gui/dicom_preview_panel.py b/invesalius/gui/dicom_preview_panel.py index 9c1206d..29dffb1 100755 --- a/invesalius/gui/dicom_preview_panel.py +++ b/invesalius/gui/dicom_preview_panel.py @@ -22,14 +22,15 @@ #TODO: To create a beautiful API import wx -import vtk -import vtkgdcm - import wx.lib.agw.buttonpanel as bp +import vtk from vtk.wx.wxVTKRenderWindowInteractor import wxVTKRenderWindowInteractor -from reader import dicom_reader +import vtkgdcm +import constants as const +from reader import dicom_reader +import data.vtk_utils as vtku NROWS = 3 NCOLS = 6 @@ -48,7 +49,105 @@ EVT_SELECT_SERIE = wx.PyEventBinder(myEVT_SELECT_SERIE, 1) myEVT_CLICK = wx.NewEventType() EVT_CLICK = wx.PyEventBinder(myEVT_CLICK, 1) +class SingleImagePreview(wx.Panel): + def __init__(self, parent): + wx.Panel.__init__(self, parent, -1) + self.__init_vtk() + self.filelist = [] + self.current_index = 0 + self.window_width = const.WINDOW_LEVEL["Bone"][0] + self.window_level = const.WINDOW_LEVEL["Bone"][1] + + def __init_vtk(self): + actor = vtk.vtkImageActor() + self.actor = actor + + LEFT_UP = (X, Y) = const.TEXT_POSITION + text_image_size = vtku.Text() + text_image_size.SetPosition(LEFT_UP) + text_image_size.SetValue("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.SetValue("IMAGE LOCAL") + + value = "ID PATIENT\n TEST" + RIGHT_UP = (1-X, Y) + text_patient = vtku.Text() + text_patient.SetJustificationToRight() + text_patient.SetPosition(RIGHT_UP) + text_patient.SetValue(value) + + value = "DATE\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.SetValue(value) + + renderer = vtk.vtkRenderer() + renderer.AddActor(actor) + 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 + + style = vtk.vtkInteractorStyleImage() + + interactor = wxVTKRenderWindowInteractor(self, -1, + size=wx.Size(400,400)) + interactor.GetRenderWindow().AddRenderer(renderer) + interactor.SetInteractorStyle(style) + interactor.Render() + self.interactor = interactor + + sizer = wx.BoxSizer(wx.VERTICAL) + sizer.Add(interactor, 1, wx.GROW|wx.EXPAND) + sizer.Fit(self) + self.SetSizer(sizer) + self.Layout() + self.Update() + self.SetAutoLayout(1) + + + def SetDicomGroup(self, group): + self.dicom_list = group.GetHandSortedList() + self.current_index = 0 + self.ShowSlice() + def ShowSlice(self): + index = self.current_index + dicom = self.dicom_list[index] + + filename = dicom.image.file + window_level = dicom.image.level + window_width = dicom.image.window + + reader = vtkgdcm.vtkGDCMImageReader() + reader.SetFileName(filename) + + colorer = vtk.vtkImageMapToWindowLevelColors() + colorer.SetInput(reader.GetOutput()) + colorer.SetWindow(float(window_width)) + colorer.SetLevel(float(window_level)) + + a = vtkgdcm.vtkImageColorViewer() + a.SetInput(colorer.GetOutput()) + #a.SetColorWindow(200) + #a.SetColorLevel(100) + a.Render() + import time + time.sleep(5) + + + self.actor.SetInput(colorer.GetOutput()) + #self.actor.SetInput(reader.GetOutput()) + self.renderer.ResetCamera() + self.interactor.Render() diff --git a/invesalius/gui/frame.py b/invesalius/gui/frame.py index f17393d..2c575fb 100755 --- a/invesalius/gui/frame.py +++ b/invesalius/gui/frame.py @@ -122,6 +122,7 @@ class Frame(wx.Frame): aui_manager.AddPane(imp.Panel(self), wx.aui.AuiPaneInfo(). Name("Import").Centre().Hide(). + MaximizeButton(True).Floatable(True). Caption("Preview medical data to be reconstructed"). CaptionVisible(True)) diff --git a/invesalius/gui/import_panel.py b/invesalius/gui/import_panel.py index c596154..94914f0 100644 --- a/invesalius/gui/import_panel.py +++ b/invesalius/gui/import_panel.py @@ -318,4 +318,48 @@ class SeriesPanel(wx.Panel): class SlicePanel(wx.Panel): def __init__(self, parent): wx.Panel.__init__(self, parent, -1) + self.__init_gui() + self.__bind_evt() + + def __bind_evt(self): + ps.Publisher().subscribe(self.ShowDicomSeries, 'Load dicom preview') + ps.Publisher().subscribe(self.SetDicomSeries, 'Load group into import panel') + ps.Publisher().subscribe(self.SetPatientSeries, 'Load patient into import panel') + + def __init_gui(self): self.SetBackgroundColour((255,255,255)) + print "----------------------------" + self.dicom_preview = dpp.SingleImagePreview(self) + + sizer = wx.BoxSizer(wx.VERTICAL) + sizer.Add(self.dicom_preview, 1, wx.GROW|wx.EXPAND) + sizer.Fit(self) + self.SetSizer(sizer) + self.Layout() + self.Update() + self.SetAutoLayout(1) + self.sizer = sizer + + def SetPatientSeries(self, pubsub_evt): + patient = pubsub_evt.data + group = patient.GetGroups()[0] + self.dicom_preview.SetDicomGroup(group) + self.sizer.Layout() + self.Update() + + + def SetDicomSeries(self, pubsub_evt): + group = pubsub_evt.data + self.dicom_preview.SetDicomGroup(group) + self.sizer.Layout() + self.Update() + + + def ShowDicomSeries(self, pubsub_evt): + patient = pubsub_evt.data + group = patient.GetGroups()[0] + self.dicom_preview.SetDicomGroup(group) + self.sizer.Layout() + self.Update() + + -- libgit2 0.21.2