[javascript] Deform polydata using known segments for each cell

Basically, I need to replicate this BMI Visualizer - BMIWebgl | Perceiving Systems. They define a set of points and a function for each of them depending on height and weight.

I have polydata models and I need to warp them based on patient weight and height. Any hints? Does anyone have some working models?

Hello,

Based on that visualizer, here’s my two cents: I believe they defined some key point clouds for some parameters (e.g. 1.70m 70kg male, 1.80m 70kg male, 1.70m 80kg male…) and use some point cloud morphing algorithm to compute and render intermediate body models for non-key parameters on the fly. I don’t believe simple linear scaling would result in realistic body models.

take care,

Paulo

Their models are free to use

Male and Female

using this functions you can achieve what I want (And probably what they did)

    function getCoeff(value, min, max){
		ymin = -100;
		ymax = 100;
		if (value<min) {
			return ymin;
		};
		if (value>max){
			return ymax;
		};
		return ymin + (ymax-ymin)*(value-min)/(max-min);
	}

	function readJSONPolyData(modelJSON, height, weight){
		const coeff = [
			getCoeff(weight, modelJSON["measurements_min"]["weight"], modelJSON["measurements_max"]["weight"]),
			getCoeff(height*10, modelJSON["measurements_min"]["stature"], modelJSON["measurements_max"]["stature"])
		];
		let points = vtk.Common.Core.vtkPoints.newInstance();
		for (let i=0; i<modelJSON["vertex_means"].length/3; i+=1){
			let p=[0,0,0];
			for (let j=0; j<3; j+=1){
				p[j] = modelJSON["vertex_means"][i*3+j] + coeff[0]*modelJSON["vertex_offsets"]["weight"][i*3+j] + coeff[1]*modelJSON["vertex_offsets"]["stature"][i*3+j];
			};	
			points.insertNextPoint(p[0], p[1], p[2]);
		};

		cells = vtk.Common.Core.vtkCellArray.newInstance();
		for (let i=0; i<modelJSON["faces"].length; i+=1){
			cells.insertNextCell(modelJSON["faces"][i]);
		};

		trianglePolyData = vtk.Common.DataModel.vtkPolyData.newInstance();
		trianglePolyData.setPoints(points);
		trianglePolyData.setPolys(cells);

		return trianglePolyData;
	}