Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python2.7
- # -*- coding: utf-8 -*-
- #NOTE: export human as .dae, z up/face -y, and scale units cm to get volume/area from blender (3d printing tools addon)
- """
- MakeHuman plugin for estimating the weight of the model using BSA (body surface
- are) based metrics.
- **Project Name:** MakeHuman
- **Product Home Page:** http://www.makehuman.org/
- **Code Home Page:** https://bitbucket.org/MakeHuman/makehuman/
- **Authors:** Jonas Hauquier, Marco Piccirilli
- **Copyright(c):** MakeHuman Team 2001-2014
- **Licensing:** AGPL3 (http://www.makehuman.org/doc/node/the_makehuman_application.html)
- This file is part of MakeHuman (www.makehuman.org).
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- **Coding Standards:** See http://www.makehuman.org/node/165
- Abstract
- --------
- Experimental plugin for doing weight estimation on the human using different
- BSA-based formulas described in scientific literature.
- """
- import gui3d
- import mh
- import gui
- import log
- import numpy as np
- class WeightTaskView(gui3d.TaskView):
- def __init__(self, category):
- gui3d.TaskView.__init__(self, category, 'Weight Estimation')
- self.human = gui3d.app.selectedHuman
- box = self.addLeftWidget(gui.GroupBox('Body Metrics'))
- self.statureLabel = box.addWidget(gui.TextView(''))
- self.bsaLabel = box.addWidget(gui.TextView('Surface area:'))
- self.bsaEdit = box.addWidget(gui.TextEdit(text='Surface area'))
- self.volumeLabel = box.addWidget(gui.TextView('Volume:'))
- self.volumeEdit = box.addWidget(gui.TextEdit(text='Volume'))
- self.aButton = box.addWidget(gui.Button('Calculate'))
- self.aButtonLabel = box.addWidget(gui.TextView('Pushed 0 times'))
- self.bsaTest = box.addWidget(gui.TextView('surface area is '))
- self.volumeTest = box.addWidget(gui.TextView('volume is '))
- self.pushed = 0
- self.surfaceArea = 16163.3086
- self.meshVolume = 55231.7165
- box = self.addLeftWidget(gui.GroupBox('Estimated Weight'))
- self.aslaniLabel = box.addWidget(gui.TextView(''))
- self.DuBoisLabel = box.addWidget(gui.TextView(''))
- self.ReadingLabel = box.addWidget(gui.TextView(''))
- self.WangLabel = box.addWidget(gui.TextView(''))
- self.LivingstonLabel = box.addWidget(gui.TextView(''))
- self.MostellerLabel = box.addWidget(gui.TextView(''))
- self.AndersonLabel = box.addWidget(gui.TextView(''))
- self.HaycockLabel = box.addWidget(gui.TextView(''))
- self.bmiLabel = box.addWidget(gui.TextView(''))
- @self.aButton.mhEvent
- def onClicked(event):
- #bsa = self.bsaEdit.toPlainText
- self.testBsa = self.bsaEdit.getText()
- self.testVol = self.volumeEdit.getText()
- self.floatyBsa = float(self.testBsa)
- self.floatyVol = float(self.testVol)
- #self.test = "test"
- #self.bsaTest.setTextFormat('surface area is %s', self.test)
- self.bsaTest.setTextFormat('surface area is %f', self.floatyBsa)
- #self.volumeTest.setTextFormat('volume is %s', self.testVol)
- self.volumeTest.setTextFormat('volume is is %f', self.floatyVol)
- self.surfaceArea = self.floatyBsa
- self.meshVolume = self.floatyVol
- self.calculateWeight()
- self.pushed += 1
- self.aButtonLabel.setTextFormat('Pushed %d times', self.pushed)
- def onHumanChanged(self, event):
- self.calculateWeight()
- def calculateWeight(self):
- humanMesh = self.human.meshData
- height = self.human.getHeightCm()
- #bsa = mesh_operations.calculateSurface(humanMesh, faceMask=humanMesh.getFaceMask())/100
- bsa = self.surfaceArea/10000
- #manually enter area obtained in blender
- #Shuter and Aslani, 2000
- weight_aslani = np.power(bsa /(np.power(height, 0.655) * 0.00949), 1/0.441)
- #DuBois and DuBois, 1916
- weight_DuBois_1916=np.power(bsa /(np.power(height, 0.725) * 0.007184), 1/0.425)
- #Reading and Freeman, 2005
- weight_Reading=np.power(bsa /(np.power(height, 0.5) /60), 1/0.5)
- #Wang and Hihara, 2004
- weight_Wang=np.power(bsa /(np.power(height, 0.5) * 0.0168), 1/0.5)
- #Livingston and Lee 2001
- weight_Livingston=np.power(bsa / 0.1173, 1/0.6466)
- #Mosteller, 1987
- weight_Mosteller=np.power(bsa /(np.power(height, 0.5) * 0.0167), 1/0.5)
- #Anderson et al., 1985
- weight_Anderson=np.power(bsa /(np.power(height, 0.417) * 0.0239), 1/0.517)
- #Haycock et al., 1978
- weight_Haycock=np.power(bsa /(np.power(height, 0.3964) * 0.024265), 1/0.5378)
- estimated_BMI = weight_aslani / (np.power(height/100,2))
- #volume = mesh_operations.calculateVolume(humanMesh, faceMask=humanMesh.getFaceMask())/100
- volume = self.meshVolume/1000000
- #manually enter volume obtained in blender
- self.statureLabel.setText('Stature: %.2f cm' % height)
- #self.bsaLabel.setText('BSA: %.2f m^2' % bsa)
- #self.volumeLabel.setText('Volume: %.2f m^3' % volume)
- self.aslaniLabel.setText('Shuter & Aslani: %.2f kg' % weight_aslani)
- self.DuBoisLabel.setText('DuBois: %.2f kg' % weight_DuBois_1916)
- self.ReadingLabel.setText('Reading and Freeman: %.2f kg' % weight_Reading)
- self.WangLabel.setText('Wang and Hihara: %.2f kg' % weight_Wang)
- self.LivingstonLabel.setText('Livingston and Lee: %.2f kg' % weight_Livingston)
- self.MostellerLabel.setText('Mosteller: %.2f kg' % weight_Mosteller)
- self.AndersonLabel.setText('Anderson et al: %.2f kg' % weight_Anderson)
- self.HaycockLabel.setText('Haycock et al.: %.2f kg' % weight_Haycock)
- self.bmiLabel.setText('BMI from Aslani BSA: %.2f' % estimated_BMI)
- def onShow(self, event):
- super(WeightTaskView, self).onShow(event)
- self.calculateWeight()
- def load(app):
- category = app.getCategory('Modelling')
- taskview = category.addTask(WeightTaskView(category))
- def unload(app):
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement