From ac56cedc3582840918ca2c8859961e17524b8b7c Mon Sep 17 00:00:00 2001 From: Thiago Franco de Moraes Date: Wed, 18 May 2016 13:30:44 -0300 Subject: [PATCH] Surface area (#37) --- invesalius/data/surface.py | 38 ++++++++++++++++++++++++++------------ invesalius/gui/data_notebook.py | 27 +++++++++++++++++---------- 2 files changed, 43 insertions(+), 22 deletions(-) diff --git a/invesalius/data/surface.py b/invesalius/data/surface.py index 6d497fe..d3bce6d 100644 --- a/invesalius/data/surface.py +++ b/invesalius/data/surface.py @@ -59,7 +59,8 @@ class Surface(): self.polydata = '' self.colour = '' self.transparency = const.SURFACE_TRANSPARENCY - self.volume = 0 + self.volume = 0.0 + self.area = 0.0 self.is_shown = 1 if not name: self.name = const.SURFACE_NAME_PATTERN %(self.index+1) @@ -81,6 +82,7 @@ class Surface(): 'transparency': self.transparency, 'visible': bool(self.is_shown), 'volume': self.volume, + 'area': self.area, } plist_filename = filename + '.plist' #plist_filepath = os.path.join(dir_temp, filename + '.plist') @@ -100,6 +102,10 @@ class Surface(): self.transparency = sp['transparency'] self.is_shown = sp['visible'] self.volume = sp['volume'] + try: + self.area = sp['area'] + except KeyError: + self.area = 0.0 self.polydata = pu.Import(os.path.join(dirpath, sp['polydata'])) Surface.general_index = max(Surface.general_index, self.index) @@ -164,7 +170,8 @@ class SurfaceManager(): name = new_name, colour = original_surface.colour, transparency = original_surface.transparency, - volume = original_surface.volume) + volume = original_surface.volume, + area = original_surface.area) def OnRemove(self, pubsub_evt): selected_items = pubsub_evt.data @@ -240,7 +247,7 @@ class SurfaceManager(): def CreateSurfaceFromPolydata(self, polydata, overwrite=False, name=None, colour=None, - transparency=None, volume=None): + transparency=None, volume=None, area=None): normals = vtk.vtkPolyDataNormals() normals.SetInputData(polydata) normals.SetFeatureAngle(80) @@ -290,7 +297,7 @@ class SurfaceManager(): session.ChangeProject() # The following lines have to be here, otherwise all volumes disappear - if not volume: + if not volume or not area: triangle_filter = vtk.vtkTriangleFilter() triangle_filter.SetInputData(polydata) triangle_filter.Update() @@ -299,18 +306,22 @@ class SurfaceManager(): measured_polydata.SetInputConnection(triangle_filter.GetOutputPort()) measured_polydata.Update() volume = measured_polydata.GetVolume() + area = measured_polydata.GetSurfaceArea() surface.volume = volume + surface.area = area print ">>>>", surface.volume else: surface.volume = volume + surface.area = area + self.last_surface_index = surface.index Publisher.sendMessage('Load surface actor into viewer', actor) Publisher.sendMessage('Update surface info in GUI', - (surface.index, surface.name, - surface.colour, surface.volume, - surface.transparency)) + (surface.index, surface.name, + surface.colour, surface.volume, + surface.area, surface.transparency)) return surface.index def OnCloseProject(self, pubsub_evt): @@ -329,9 +340,9 @@ class SurfaceManager(): proj = prj.Project() surface = proj.surface_dict[index] Publisher.sendMessage('Update surface info in GUI', - (index, surface.name, - surface.colour, surface.volume, - surface.transparency)) + (index, surface.name, + surface.colour, surface.volume, + surface.area, surface.transparency)) self.last_surface_index = index if surface.is_shown: self.ShowActor(index, True) @@ -377,8 +388,8 @@ class SurfaceManager(): # The following lines have to be here, otherwise all volumes disappear Publisher.sendMessage('Update surface info in GUI', (surface.index, surface.name, - surface.colour, surface.volume, - surface.transparency)) + surface.colour, surface.volume, + surface.area, surface.transparency)) if not surface.is_shown: self.ShowActor(key, False) @@ -727,7 +738,9 @@ class SurfaceManager(): # measured_polydata.ReleaseDataFlagOn() measured_polydata.SetInputData(to_measure) volume = float(measured_polydata.GetVolume()) + area = float(measured_polydata.GetSurfaceArea()) surface.volume = volume + surface.area = area self.last_surface_index = surface.index del measured_polydata del to_measure @@ -745,6 +758,7 @@ class SurfaceManager(): Publisher.sendMessage('Update surface info in GUI', (surface.index, surface.name, surface.colour, surface.volume, + surface.area, surface.transparency)) #When you finalize the progress. The bar is cleaned. diff --git a/invesalius/gui/data_notebook.py b/invesalius/gui/data_notebook.py index 6806641..bde92e5 100644 --- a/invesalius/gui/data_notebook.py +++ b/invesalius/gui/data_notebook.py @@ -765,12 +765,14 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): self.InsertColumn(0, "", wx.LIST_FORMAT_CENTER) self.InsertColumn(1, _("Name")) self.InsertColumn(2, _(u"Volume (mm³)")) - self.InsertColumn(3, _("Transparency"), wx.LIST_FORMAT_RIGHT) + self.InsertColumn(3, _(u"Area (mm²)")) + self.InsertColumn(4, _("Transparency"), wx.LIST_FORMAT_RIGHT) self.SetColumnWidth(0, 25) self.SetColumnWidth(1, 85) self.SetColumnWidth(2, 85) - self.SetColumnWidth(3, 80) + self.SetColumnWidth(3, 85) + self.SetColumnWidth(4, 80) def __init_image_list(self): self.imagelist = wx.ImageList(16, 16) @@ -830,7 +832,8 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): name = pubsub_evt.data[1] colour = pubsub_evt.data[2] volume = "%.3f"%pubsub_evt.data[3] - transparency = "%d%%"%(int(100*pubsub_evt.data[4])) + area = "%.3f"%pubsub_evt.data[4] + transparency = "%d%%"%(int(100*pubsub_evt.data[5])) if index not in self.surface_list_index: image = self.CreateColourBitmap(colour) @@ -840,25 +843,29 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): self.surface_list_index[index] = image_index if (index in index_list) and index_list: - self.UpdateItemInfo(index, name, volume, transparency, colour) + self.UpdateItemInfo(index, name, volume, area, transparency, colour) else: - self.InsertNewItem(index, name, volume, transparency, colour) + self.InsertNewItem(index, name, volume, area, transparency, colour) + else: + self.UpdateItemInfo(index, name, volume, area, transparency, colour) def InsertNewItem(self, index=0, label="Surface 1", volume="0 mm3", - transparency="0%%", colour=None): + area="0 mm2", transparency="0%%", colour=None): self.InsertStringItem(index, "") self.SetStringItem(index, 1, label, imageId = self.surface_list_index[index]) self.SetStringItem(index, 2, volume) - self.SetStringItem(index, 3, transparency) + self.SetStringItem(index, 3, area) + self.SetStringItem(index, 4, transparency) self.SetItemImage(index, 1) def UpdateItemInfo(self, index=0, label="Surface 1", volume="0 mm3", - transparency="0%%", colour=None): + area="0 mm2", transparency="0%%", colour=None): self.SetStringItem(index, 1, label, imageId = self.surface_list_index[index]) self.SetStringItem(index, 2, volume) - self.SetStringItem(index, 3, transparency) + self.SetStringItem(index, 3, area) + self.SetStringItem(index, 4, transparency) self.SetItemImage(index, 1) def CreateColourBitmap(self, colour): @@ -889,7 +896,7 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): index and value. """ index, value = pubsub_evt.data - self.SetStringItem(index, 3, "%d%%"%(int(value*100))) + self.SetStringItem(index, 4, "%d%%"%(int(value*100))) def EditSurfaceColour(self, pubsub_evt): """ -- libgit2 0.21.2