Advertisement
Guest User

Updated Makehuman Weight Estimation

a guest
Dec 13th, 2015
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.75 KB | None | 0 0
  1. #!/usr/bin/env python2.7
  2. # -*- coding: utf-8 -*-
  3. #NOTE: export human as .dae, z up/face -y, and scale units cm to get volume/area from blender (3d printing tools addon)
  4.  
  5. """
  6. MakeHuman plugin for estimating the weight of the model using BSA (body surface
  7. are) based metrics.
  8.  
  9. **Project Name:** MakeHuman
  10.  
  11. **Product Home Page:** http://www.makehuman.org/
  12.  
  13. **Code Home Page:** https://bitbucket.org/MakeHuman/makehuman/
  14.  
  15. **Authors:** Jonas Hauquier, Marco Piccirilli
  16.  
  17. **Copyright(c):** MakeHuman Team 2001-2014
  18.  
  19. **Licensing:** AGPL3 (http://www.makehuman.org/doc/node/the_makehuman_application.html)
  20.  
  21. This file is part of MakeHuman (www.makehuman.org).
  22.  
  23. This program is free software: you can redistribute it and/or modify
  24. it under the terms of the GNU Affero General Public License as
  25. published by the Free Software Foundation, either version 3 of the
  26. License, or (at your option) any later version.
  27.  
  28. This program is distributed in the hope that it will be useful,
  29. but WITHOUT ANY WARRANTY; without even the implied warranty of
  30. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  31. GNU Affero General Public License for more details.
  32.  
  33. You should have received a copy of the GNU Affero General Public License
  34. along with this program. If not, see <http://www.gnu.org/licenses/>.
  35.  
  36. **Coding Standards:** See http://www.makehuman.org/node/165
  37.  
  38. Abstract
  39. --------
  40.  
  41. Experimental plugin for doing weight estimation on the human using different
  42. BSA-based formulas described in scientific literature.
  43. """
  44.  
  45. import gui3d
  46. import mh
  47. import gui
  48. import log
  49. import numpy as np
  50.  
  51. class WeightTaskView(gui3d.TaskView):
  52.  
  53. def __init__(self, category):
  54. gui3d.TaskView.__init__(self, category, 'Weight Estimation')
  55.  
  56. self.human = gui3d.app.selectedHuman
  57.  
  58. box = self.addLeftWidget(gui.GroupBox('Body Metrics'))
  59. self.statureLabel = box.addWidget(gui.TextView(''))
  60. self.bsaLabel = box.addWidget(gui.TextView('Surface area:'))
  61. self.bsaEdit = box.addWidget(gui.TextEdit(text='Surface area'))
  62. self.volumeLabel = box.addWidget(gui.TextView('Volume:'))
  63. self.volumeEdit = box.addWidget(gui.TextEdit(text='Volume'))
  64. self.aButton = box.addWidget(gui.Button('Calculate'))
  65. self.aButtonLabel = box.addWidget(gui.TextView('Pushed 0 times'))
  66. self.bsaTest = box.addWidget(gui.TextView('surface area is '))
  67. self.volumeTest = box.addWidget(gui.TextView('volume is '))
  68. self.pushed = 0
  69.  
  70. self.surfaceArea = 16163.3086
  71. self.meshVolume = 55231.7165
  72.  
  73. box = self.addLeftWidget(gui.GroupBox('Estimated Weight'))
  74.  
  75. self.aslaniLabel = box.addWidget(gui.TextView(''))
  76. self.DuBoisLabel = box.addWidget(gui.TextView(''))
  77. self.ReadingLabel = box.addWidget(gui.TextView(''))
  78. self.WangLabel = box.addWidget(gui.TextView(''))
  79. self.LivingstonLabel = box.addWidget(gui.TextView(''))
  80. self.MostellerLabel = box.addWidget(gui.TextView(''))
  81. self.AndersonLabel = box.addWidget(gui.TextView(''))
  82. self.HaycockLabel = box.addWidget(gui.TextView(''))
  83. self.bmiLabel = box.addWidget(gui.TextView(''))
  84.  
  85. @self.aButton.mhEvent
  86. def onClicked(event):
  87. #bsa = self.bsaEdit.toPlainText
  88. self.testBsa = self.bsaEdit.getText()
  89. self.testVol = self.volumeEdit.getText()
  90. self.floatyBsa = float(self.testBsa)
  91. self.floatyVol = float(self.testVol)
  92. #self.test = "test"
  93. #self.bsaTest.setTextFormat('surface area is %s', self.test)
  94. self.bsaTest.setTextFormat('surface area is %f', self.floatyBsa)
  95. #self.volumeTest.setTextFormat('volume is %s', self.testVol)
  96. self.volumeTest.setTextFormat('volume is is %f', self.floatyVol)
  97. self.surfaceArea = self.floatyBsa
  98. self.meshVolume = self.floatyVol
  99. self.calculateWeight()
  100. self.pushed += 1
  101. self.aButtonLabel.setTextFormat('Pushed %d times', self.pushed)
  102.  
  103. def onHumanChanged(self, event):
  104. self.calculateWeight()
  105.  
  106.  
  107. def calculateWeight(self):
  108. humanMesh = self.human.meshData
  109.  
  110. height = self.human.getHeightCm()
  111. #bsa = mesh_operations.calculateSurface(humanMesh, faceMask=humanMesh.getFaceMask())/100
  112. bsa = self.surfaceArea/10000
  113. #manually enter area obtained in blender
  114.  
  115. #Shuter and Aslani, 2000
  116. weight_aslani = np.power(bsa /(np.power(height, 0.655) * 0.00949), 1/0.441)
  117. #DuBois and DuBois, 1916
  118. weight_DuBois_1916=np.power(bsa /(np.power(height, 0.725) * 0.007184), 1/0.425)
  119. #Reading and Freeman, 2005
  120. weight_Reading=np.power(bsa /(np.power(height, 0.5) /60), 1/0.5)
  121. #Wang and Hihara, 2004
  122. weight_Wang=np.power(bsa /(np.power(height, 0.5) * 0.0168), 1/0.5)
  123. #Livingston and Lee 2001
  124. weight_Livingston=np.power(bsa / 0.1173, 1/0.6466)
  125. #Mosteller, 1987
  126. weight_Mosteller=np.power(bsa /(np.power(height, 0.5) * 0.0167), 1/0.5)
  127. #Anderson et al., 1985
  128. weight_Anderson=np.power(bsa /(np.power(height, 0.417) * 0.0239), 1/0.517)
  129. #Haycock et al., 1978
  130. weight_Haycock=np.power(bsa /(np.power(height, 0.3964) * 0.024265), 1/0.5378)
  131.  
  132. estimated_BMI = weight_aslani / (np.power(height/100,2))
  133.  
  134. #volume = mesh_operations.calculateVolume(humanMesh, faceMask=humanMesh.getFaceMask())/100
  135. volume = self.meshVolume/1000000
  136. #manually enter volume obtained in blender
  137.  
  138. self.statureLabel.setText('Stature: %.2f cm' % height)
  139. #self.bsaLabel.setText('BSA: %.2f m^2' % bsa)
  140. #self.volumeLabel.setText('Volume: %.2f m^3' % volume)
  141.  
  142. self.aslaniLabel.setText('Shuter & Aslani: %.2f kg' % weight_aslani)
  143. self.DuBoisLabel.setText('DuBois: %.2f kg' % weight_DuBois_1916)
  144. self.ReadingLabel.setText('Reading and Freeman: %.2f kg' % weight_Reading)
  145. self.WangLabel.setText('Wang and Hihara: %.2f kg' % weight_Wang)
  146. self.LivingstonLabel.setText('Livingston and Lee: %.2f kg' % weight_Livingston)
  147. self.MostellerLabel.setText('Mosteller: %.2f kg' % weight_Mosteller)
  148. self.AndersonLabel.setText('Anderson et al: %.2f kg' % weight_Anderson)
  149. self.HaycockLabel.setText('Haycock et al.: %.2f kg' % weight_Haycock)
  150. self.bmiLabel.setText('BMI from Aslani BSA: %.2f' % estimated_BMI)
  151.  
  152. def onShow(self, event):
  153. super(WeightTaskView, self).onShow(event)
  154. self.calculateWeight()
  155.  
  156.  
  157.  
  158. def load(app):
  159. category = app.getCategory('Modelling')
  160. taskview = category.addTask(WeightTaskView(category))
  161.  
  162. def unload(app):
  163. pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement