From 7137baa63a517a83e188f29eae9fa58f6b9f1ea7 Mon Sep 17 00:00:00 2001 From: tatiana Date: Mon, 25 Jan 2010 14:26:09 +0000 Subject: [PATCH] ADD: Photo feature (fix #59) --- invesalius/constants.py | 9 +++++---- invesalius/data/viewer_slice.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ invesalius/data/viewer_volume.py | 47 ++++++++++++++++++++++++++++++++++++++++++++++- invesalius/gui/dialogs.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++----- invesalius/gui/task_exporter.py | 35 ++++++++++++++++++++++++++++++++++- 5 files changed, 193 insertions(+), 11 deletions(-) diff --git a/invesalius/constants.py b/invesalius/constants.py index 19ee54d..976c9dc 100644 --- a/invesalius/constants.py +++ b/invesalius/constants.py @@ -55,9 +55,10 @@ TEXT_POS_VCENTRE_LEFT = (X, 0.5) # SetVerticalJustificationToCentered # Slice orientation -AXIAL = 0 -CORONAL = 1 -SAGITAL = 2 +AXIAL = 1 +CORONAL = 2 +SAGITAL = 3 +VOLUME = 4 # Colour representing each orientation ORIENTATION_COLOUR = {'AXIAL': (1,0,0), # Red @@ -355,7 +356,7 @@ FILETYPE_JPG = wx.NewId() FILETYPE_PNG = wx.NewId() FILETYPE_PS = wx.NewId() FILETYPE_POV = wx.NewId() -FILETYPE_OBJ = wx.NewId() +FILETYPE_TIF = wx.NewId() IMAGE_TILING = {"1 x 1":(1,1), "1 x 2":(1,2), "1 x 3":(1,3), "1 x 4":(1,4), diff --git a/invesalius/data/viewer_slice.py b/invesalius/data/viewer_slice.py index a01b289..4b90793 100755 --- a/invesalius/data/viewer_slice.py +++ b/invesalius/data/viewer_slice.py @@ -829,6 +829,63 @@ class Viewer(wx.Panel): 'Show text actors on viewers') ps.Publisher().subscribe(self.OnHideText, 'Hide text actors on viewers') + ps.Publisher().subscribe(self.OnExportPicture,'Export picture to file') + + + + def OnExportPicture(self, pubsub_evt): + ps.Publisher().sendMessage('Begin busy cursor') + + id, filename, filetype = pubsub_evt.data + dict = {"AXIAL": const.AXIAL, + "CORONAL": const.CORONAL, + "SAGITAL": const.SAGITAL} + + if id == dict[self.orientation]: + print "ok" + if filetype == const.FILETYPE_POV: + print 1 + renwin = self.interactor.GetRenderWindow() + image = vtk.vtkWindowToImageFilter() + image.SetInput(renwin) + writer = vtk.vtkPOVExporter() + writer.SetFilePrefix(filename.split(".")[0]) + writer.SetRenderWindow(renwin) + writer.Write() + return + else: + print 2 + #Use tiling to generate a large rendering. + image = vtk.vtkRenderLargeImage() + image.SetInput(self.ren) + image.SetMagnification(2) + + image = image.GetOutput() + + + # write image file + if (filetype == const.FILETYPE_BMP): + print 3 + writer = vtk.vtkBMPWriter() + elif (filetype == const.FILETYPE_JPG): + print 4 + writer = vtk.vtkJPEGWriter() + elif (filetype == const.FILETYPE_PNG): + print 5 + writer = vtk.vtkPNGWriter() + elif (filetype == const.FILETYPE_PS): + print 6 + writer = vtk.vtkPostScriptWriter() + elif (filetype == const.FILETYPE_TIF): + print 7 + writer = vtk.vtkTIFFWriter() + filename = "%s.tif"%filename.strip(".tif") + + writer.SetInput(image) + writer.SetFileName(filename) + writer.Write() + + ps.Publisher().sendMessage('End busy cursor') def OnShowText(self, pubsub_evt): print "OnShowText" diff --git a/invesalius/data/viewer_volume.py b/invesalius/data/viewer_volume.py index 82f1c4b..8592161 100755 --- a/invesalius/data/viewer_volume.py +++ b/invesalius/data/viewer_volume.py @@ -127,8 +127,53 @@ class Viewer(wx.Panel): ps.Publisher().subscribe(self.OnShowText, 'Show text actors on viewers') ps.Publisher().subscribe(self.OnCloseProject, 'Close project data') + ps.Publisher().subscribe(self.OnExportPicture,'Export picture to file') - + + + def OnExportPicture(self, pubsub_evt): + ps.Publisher().sendMessage('Begin busy cursor') + id, filename, filetype = pubsub_evt.data + + if id == const.VOLUME: + if filetype == const.FILETYPE_POV: + renwin = self.interactor.GetRenderWindow() + image = vtk.vtkWindowToImageFilter() + image.SetInput(renwin) + writer = vtk.vtkPOVExporter() + writer.SetFilePrefix(filename.split(".")[0]) + writer.SetRenderWindow(renwin) + writer.Write() + return + else: + #Use tiling to generate a large rendering. + image = vtk.vtkRenderLargeImage() + image.SetInput(self.ren) + image.SetMagnification(2) + + image = image.GetOutput() + + + # write image file + if (filetype == const.FILETYPE_BMP): + writer = vtk.vtkBMPWriter() + elif (filetype == const.FILETYPE_JPG): + writer = vtk.vtkJPEGWriter() + elif (filetype == const.FILETYPE_PNG): + writer = vtk.vtkPNGWriter() + elif (filetype == const.FILETYPE_PS): + writer = vtk.vtkPostScriptWriter() + elif (filetype == const.FILETYPE_TIF): + writer = vtk.vtkTIFFWriter() + filename = "%s.tif"%filename.strip(".tif") + + writer.SetInput(image) + writer.SetFileName(filename) + writer.Write() + ps.Publisher().sendMessage('End busy cursor') + + + def OnCloseProject(self, pubsub_evt): if self.raycasting_volume: self.raycasting_volume = False diff --git a/invesalius/gui/dialogs.py b/invesalius/gui/dialogs.py index 7491ba2..8cf76c7 100644 --- a/invesalius/gui/dialogs.py +++ b/invesalius/gui/dialogs.py @@ -25,8 +25,8 @@ from wx.lib.wordwrap import wordwrap import wx.lib.pubsub as ps - -import project +import constants as const +import project as proj import session as ses @@ -126,9 +126,6 @@ class ProgressDialog(object): - - - #--------- WILDCARD_OPEN = "InVesalius 3 project (*.inv3)|*.inv3|"\ "All files (*.*)|*.*" @@ -476,5 +473,54 @@ class NewSurfaceDialog(wx.Dialog): #def GetValue(self): # return self.text.GetValue() + _("| mask: ") + MASK_LIST[self.combo_surface_name.GetSelection()] +INDEX_TO_EXTENSION = {0: "bmp", 1: "jpg", 2: "png", 3: "ps", 4:"povray", 5:"tiff"} +WILDCARD_SAVE_PICTURE = _("BMP image")+" (*.bmp)|*.bmp|"+\ + _("JPG image")+" (*.jpg)|*.jpg|"+\ + _("PNG image")+" (*.png)|*.png|"+\ + _("PostScript document")+" (*.ps)|*.ps|"+\ + _("POV-Ray file)")+" (*.pov)|*.pov|"+\ + _("TIFF image")+" (*.tif)|*.tif" + + +def ExportPicture(type_=""): + import constants as const + + INDEX_TO_TYPE = {0: const.FILETYPE_BMP, + 1: const.FILETYPE_JPG, + 2: const.FILETYPE_PNG, + 3: const.FILETYPE_PS, + 4: const.FILETYPE_POV, + 5: const.FILETYPE_TIF} + + print "ExportPicture" + project = proj.Project() + + if sys.platform == 'win32': + project_name = project.name + else: + project_name = project.name+".jpg" + + + dlg = wx.FileDialog(None, + "Save %s picture as..." %type_, + "", # last used directory + "%s_%s"%(project_name, type_), # filename + WILDCARD_SAVE_PICTURE, + wx.SAVE|wx.OVERWRITE_PROMPT) + dlg.SetFilterIndex(1) # default is VTI + + if dlg.ShowModal() == wx.ID_OK: + filetype_index = dlg.GetFilterIndex() + filetype = INDEX_TO_TYPE[filetype_index] + extension = INDEX_TO_EXTENSION[filetype_index] + filename = dlg.GetPath() + print "filename", filename + if sys.platform != 'win32': + if filename.split(".")[-1] != extension: + filename = filename + "."+ extension + return filename, filetype + else: + return () + diff --git a/invesalius/gui/task_exporter.py b/invesalius/gui/task_exporter.py index e5d40fa..b55256e 100644 --- a/invesalius/gui/task_exporter.py +++ b/invesalius/gui/task_exporter.py @@ -26,6 +26,7 @@ import wx.lib.platebtn as pbtn import wx.lib.pubsub as ps import constants as const +import gui.dialogs as dlg import project as proj BTN_MASK = wx.NewId() @@ -180,6 +181,8 @@ class InnerTaskPanel(wx.Panel): button_picture = pbtn.PlateButton(self, BTN_PICTURE, "", BMP_TAKE_PICTURE, style=button_style) + self.button_picture = button_picture + button_surface = pbtn.PlateButton(self, BTN_SURFACE, "", BMP_EXPORT_SURFACE, style=button_style) @@ -220,9 +223,39 @@ class InnerTaskPanel(wx.Panel): self.SetSizer(main_sizer) self.Fit() self.sizer = main_sizer + self.__init_menu() + + def __init_menu(self): + + + menu = wx.Menu() + self.id_to_name = {const.AXIAL:_("Axial slice"), + const.CORONAL:_("Coronal slice"), + const.SAGITAL:_("Sagittal slice"), + const.VOLUME:_("Volume")} + + for id in self.id_to_name: + item = wx.MenuItem(menu, id, self.id_to_name[id]) + menu.AppendItem(item) + + self.menu_picture = menu + menu.Bind(wx.EVT_MENU, self.OnMenuPicture) + + def OnMenuPicture(self, evt): + print "OnMenuPicture" + id = evt.GetId() + value = dlg.ExportPicture(self.id_to_name[id]) + if value: + filename, filetype = value + print filename, filetype + ps.Publisher().sendMessage('Export picture to file', + (id, filename, filetype)) + + def OnLinkExportPicture(self, evt=None): - pass + self.button_picture.PopupMenu(self.menu_picture) + def OnLinkExportMask(self, evt=None): project = proj.Project() -- libgit2 0.21.2