Commit 396a0264c05c0bb05d79823d05bf947dad78ae37

Authored by Thiago Franco de Moraes
1 parent b5d8f652

Surface area (#37)

* Calculating surface area

* remove prints

* Updating surface info when overwriting surface

* Calculating area when selecting greatest surface, select surface or separate all surfaces

* Copying area when duplicating surface
invesalius/data/surface.py
... ... @@ -59,7 +59,8 @@ class Surface():
59 59 self.polydata = ''
60 60 self.colour = ''
61 61 self.transparency = const.SURFACE_TRANSPARENCY
62   - self.volume = 0
  62 + self.volume = 0.0
  63 + self.area = 0.0
63 64 self.is_shown = 1
64 65 if not name:
65 66 self.name = const.SURFACE_NAME_PATTERN %(self.index+1)
... ... @@ -81,6 +82,7 @@ class Surface():
81 82 'transparency': self.transparency,
82 83 'visible': bool(self.is_shown),
83 84 'volume': self.volume,
  85 + 'area': self.area,
84 86 }
85 87 plist_filename = filename + '.plist'
86 88 #plist_filepath = os.path.join(dir_temp, filename + '.plist')
... ... @@ -100,6 +102,10 @@ class Surface():
100 102 self.transparency = sp['transparency']
101 103 self.is_shown = sp['visible']
102 104 self.volume = sp['volume']
  105 + try:
  106 + self.area = sp['area']
  107 + except KeyError:
  108 + self.area = 0.0
103 109 self.polydata = pu.Import(os.path.join(dirpath, sp['polydata']))
104 110 Surface.general_index = max(Surface.general_index, self.index)
105 111  
... ... @@ -164,7 +170,8 @@ class SurfaceManager():
164 170 name = new_name,
165 171 colour = original_surface.colour,
166 172 transparency = original_surface.transparency,
167   - volume = original_surface.volume)
  173 + volume = original_surface.volume,
  174 + area = original_surface.area)
168 175  
169 176 def OnRemove(self, pubsub_evt):
170 177 selected_items = pubsub_evt.data
... ... @@ -240,7 +247,7 @@ class SurfaceManager():
240 247  
241 248 def CreateSurfaceFromPolydata(self, polydata, overwrite=False,
242 249 name=None, colour=None,
243   - transparency=None, volume=None):
  250 + transparency=None, volume=None, area=None):
244 251 normals = vtk.vtkPolyDataNormals()
245 252 normals.SetInputData(polydata)
246 253 normals.SetFeatureAngle(80)
... ... @@ -290,7 +297,7 @@ class SurfaceManager():
290 297 session.ChangeProject()
291 298  
292 299 # The following lines have to be here, otherwise all volumes disappear
293   - if not volume:
  300 + if not volume or not area:
294 301 triangle_filter = vtk.vtkTriangleFilter()
295 302 triangle_filter.SetInputData(polydata)
296 303 triangle_filter.Update()
... ... @@ -299,18 +306,22 @@ class SurfaceManager():
299 306 measured_polydata.SetInputConnection(triangle_filter.GetOutputPort())
300 307 measured_polydata.Update()
301 308 volume = measured_polydata.GetVolume()
  309 + area = measured_polydata.GetSurfaceArea()
302 310 surface.volume = volume
  311 + surface.area = area
303 312 print ">>>>", surface.volume
304 313 else:
305 314 surface.volume = volume
  315 + surface.area = area
  316 +
306 317 self.last_surface_index = surface.index
307 318  
308 319 Publisher.sendMessage('Load surface actor into viewer', actor)
309 320  
310 321 Publisher.sendMessage('Update surface info in GUI',
311   - (surface.index, surface.name,
312   - surface.colour, surface.volume,
313   - surface.transparency))
  322 + (surface.index, surface.name,
  323 + surface.colour, surface.volume,
  324 + surface.area, surface.transparency))
314 325 return surface.index
315 326  
316 327 def OnCloseProject(self, pubsub_evt):
... ... @@ -329,9 +340,9 @@ class SurfaceManager():
329 340 proj = prj.Project()
330 341 surface = proj.surface_dict[index]
331 342 Publisher.sendMessage('Update surface info in GUI',
332   - (index, surface.name,
333   - surface.colour, surface.volume,
334   - surface.transparency))
  343 + (index, surface.name,
  344 + surface.colour, surface.volume,
  345 + surface.area, surface.transparency))
335 346 self.last_surface_index = index
336 347 if surface.is_shown:
337 348 self.ShowActor(index, True)
... ... @@ -377,8 +388,8 @@ class SurfaceManager():
377 388 # The following lines have to be here, otherwise all volumes disappear
378 389 Publisher.sendMessage('Update surface info in GUI',
379 390 (surface.index, surface.name,
380   - surface.colour, surface.volume,
381   - surface.transparency))
  391 + surface.colour, surface.volume,
  392 + surface.area, surface.transparency))
382 393 if not surface.is_shown:
383 394 self.ShowActor(key, False)
384 395  
... ... @@ -727,7 +738,9 @@ class SurfaceManager():
727 738 # measured_polydata.ReleaseDataFlagOn()
728 739 measured_polydata.SetInputData(to_measure)
729 740 volume = float(measured_polydata.GetVolume())
  741 + area = float(measured_polydata.GetSurfaceArea())
730 742 surface.volume = volume
  743 + surface.area = area
731 744 self.last_surface_index = surface.index
732 745 del measured_polydata
733 746 del to_measure
... ... @@ -745,6 +758,7 @@ class SurfaceManager():
745 758 Publisher.sendMessage('Update surface info in GUI',
746 759 (surface.index, surface.name,
747 760 surface.colour, surface.volume,
  761 + surface.area,
748 762 surface.transparency))
749 763  
750 764 #When you finalize the progress. The bar is cleaned.
... ...
invesalius/gui/data_notebook.py
... ... @@ -769,12 +769,14 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin):
769 769 self.InsertColumn(0, "", wx.LIST_FORMAT_CENTER)
770 770 self.InsertColumn(1, _("Name"))
771 771 self.InsertColumn(2, _(u"Volume (mm³)"))
772   - self.InsertColumn(3, _("Transparency"), wx.LIST_FORMAT_RIGHT)
  772 + self.InsertColumn(3, _(u"Area (mm²)"))
  773 + self.InsertColumn(4, _("Transparency"), wx.LIST_FORMAT_RIGHT)
773 774  
774 775 self.SetColumnWidth(0, 25)
775 776 self.SetColumnWidth(1, 85)
776 777 self.SetColumnWidth(2, 85)
777   - self.SetColumnWidth(3, 80)
  778 + self.SetColumnWidth(3, 85)
  779 + self.SetColumnWidth(4, 80)
778 780  
779 781 def __init_image_list(self):
780 782 self.imagelist = wx.ImageList(16, 16)
... ... @@ -834,7 +836,8 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin):
834 836 name = pubsub_evt.data[1]
835 837 colour = pubsub_evt.data[2]
836 838 volume = "%.3f"%pubsub_evt.data[3]
837   - transparency = "%d%%"%(int(100*pubsub_evt.data[4]))
  839 + area = "%.3f"%pubsub_evt.data[4]
  840 + transparency = "%d%%"%(int(100*pubsub_evt.data[5]))
838 841  
839 842 if index not in self.surface_list_index:
840 843 image = self.CreateColourBitmap(colour)
... ... @@ -844,25 +847,29 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin):
844 847 self.surface_list_index[index] = image_index
845 848  
846 849 if (index in index_list) and index_list:
847   - self.UpdateItemInfo(index, name, volume, transparency, colour)
  850 + self.UpdateItemInfo(index, name, volume, area, transparency, colour)
848 851 else:
849   - self.InsertNewItem(index, name, volume, transparency, colour)
  852 + self.InsertNewItem(index, name, volume, area, transparency, colour)
  853 + else:
  854 + self.UpdateItemInfo(index, name, volume, area, transparency, colour)
850 855  
851 856 def InsertNewItem(self, index=0, label="Surface 1", volume="0 mm3",
852   - transparency="0%%", colour=None):
  857 + area="0 mm2", transparency="0%%", colour=None):
853 858 self.InsertStringItem(index, "")
854 859 self.SetStringItem(index, 1, label,
855 860 imageId = self.surface_list_index[index])
856 861 self.SetStringItem(index, 2, volume)
857   - self.SetStringItem(index, 3, transparency)
  862 + self.SetStringItem(index, 3, area)
  863 + self.SetStringItem(index, 4, transparency)
858 864 self.SetItemImage(index, 1)
859 865  
860 866 def UpdateItemInfo(self, index=0, label="Surface 1", volume="0 mm3",
861   - transparency="0%%", colour=None):
  867 + area="0 mm2", transparency="0%%", colour=None):
862 868 self.SetStringItem(index, 1, label,
863 869 imageId = self.surface_list_index[index])
864 870 self.SetStringItem(index, 2, volume)
865   - self.SetStringItem(index, 3, transparency)
  871 + self.SetStringItem(index, 3, area)
  872 + self.SetStringItem(index, 4, transparency)
866 873 self.SetItemImage(index, 1)
867 874  
868 875 def CreateColourBitmap(self, colour):
... ... @@ -893,7 +900,7 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin):
893 900 index and value.
894 901 """
895 902 index, value = pubsub_evt.data
896   - self.SetStringItem(index, 3, "%d%%"%(int(value*100)))
  903 + self.SetStringItem(index, 4, "%d%%"%(int(value*100)))
897 904  
898 905 def EditSurfaceColour(self, pubsub_evt):
899 906 """
... ...