I believe you would have gotten more response by a title that ask for the calculation of the volume of a boob :).
To start, in order to calculate the volume of a mesh, it should be a closed mesh. So I think that you need to select the faces/vertices that you don't need and remove them from the mesh.
Than find a way to close the volume:
- In Meshlab: Try the poisson option under point set
- Or use i.e. Blender to close the volume manually
Once this is done, it becomes easy according to this paper.
The trick is to calculate the signed volume of a tetrahedron - based on your triangle and topped off at the origin. The sign of the volume comes from whether your triangle is pointing in the direction of the origin. (The normal of the triangle is itself dependent upon the order of your vertices, which is why you don't see it explicitly referenced below.)
This all boils down to the following simple function:
float signedVolumeOfTriangle(pcl::PointXYZ p1, pcl::PointXYZ p2, pcl::PointXYZ p3)
{
float v321 = p3.x*p2.y*p1.z;
float v231 = p2.x*p3.y*p1.z;
float v312 = p3.x*p1.y*p2.z;
float v132 = p1.x*p3.y*p2.z;
float v213 = p2.x*p1.y*p3.z;
float v123 = p1.x*p2.y*p3.z;
return (1.0f/6.0f)*(-v321 + v231 + v312 - v132 - v213 + v123);
}
and then a function to calculate the volume of the mesh:
float volumeOfMesh(pcl::PolygonMesh mesh)
{
float vols = 0.0;
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
pcl::fromPointCloud2(mesh.cloud,*cloud);
for(int triangle=0;triangle<mesh.polygons.size();triangle++)
{
pcl::PointXYZ pt1 = cloud->points[mesh.polygons[triangle].vertices[0]];
pcl::PointXYZ pt2 = cloud->points[mesh.polygons[triangle].vertices[1]];
pcl::PointXYZ pt3 = cloud->points[mesh.polygons[triangle].vertices[2]];
vols += signedVolumeOfTriangle(pt1, pt2, pt3);
}
return Math.Abs(vols.Sum());
}
I didn't test the code and don't know if you can use PCL, but this should get you started.