|
double calculate_volume(const TriangleCollection& triangle_collection) { |
This function assumes that the 4th point is the origin (0, 0, 0), but it's in France, and thus small rounding errors accumulate, and you do not get the "true" volume.
The solution is to define the 4th point as something close to the triangle (or its centroid) and thus something like this:
double calculate_volume(const TriangleCollection& triangle_collection) {
Vector centroid(0, 0, 0);
size_t count = 0;
for (const auto& t : triangle_collection) {
for (int i = 0; i < 3; ++i) {
centroid = centroid + Vector(t[i][0], t[i][1], t[i][2]);
++count;
}
}
centroid /= count;
double sum = 0;
for (const auto& t : triangle_collection) {
auto a = Vector(t[0][0], t[0][1], t[0][2]) - centroid;
auto b = Vector(t[1][0], t[1][1], t[1][2]) - centroid;
auto c = Vector(t[2][0], t[2][1], t[2][2]) - centroid;
sum += CGAL::scalar_product(a, CGAL::cross_product(b, c));
}
return sum / 6;
}
roofer/src/core/reconstruction/MeshTriangulatorLegacy.cpp
Line 49 in 570eb95
This function assumes that the 4th point is the origin (0, 0, 0), but it's in France, and thus small rounding errors accumulate, and you do not get the "true" volume.
The solution is to define the 4th point as something close to the triangle (or its centroid) and thus something like this: