From 7d82f0c0a33e35b812520a4da8eabe4aaaf3515a Mon Sep 17 00:00:00 2001 From: Thiago Franco de Moraes Date: Tue, 17 May 2016 10:29:00 -0300 Subject: [PATCH] Calculating surface area --- invesalius/data/surface.py | 17 ++++++++++++++--- invesalius/gui/data_notebook.py | 25 ++++++++++++++++--------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/invesalius/data/surface.py b/invesalius/data/surface.py index 6d497fe..d6b757e 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) @@ -299,7 +305,9 @@ 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 @@ -377,8 +385,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 +735,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 +755,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 9a8d5ba..1d73ee4 100644 --- a/invesalius/gui/data_notebook.py +++ b/invesalius/gui/data_notebook.py @@ -769,12 +769,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) @@ -834,7 +836,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) @@ -844,25 +847,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) 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, "") + print ">>>>AREA<<<<<<", area + print ">>>>AREA<<<<<<", transparency 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): -- libgit2 0.21.2