IfcGeomIterator: compute model's bounding box only if needed (IfcConvert --center-model used).

This commit is contained in:
Stinkfist0
2018-08-20 14:36:53 +03:00
committed by Thomas Krijnen
parent 1c1fc9cd70
commit aee4fe89ae
2 changed files with 29 additions and 19 deletions
+7 -2
View File
@@ -296,7 +296,7 @@ int main(int argc, char** argv)
"Applicable for DAE output.") "Applicable for DAE output.")
("center-model", ("center-model",
"Centers the elements upon serialization by applying the center point of " "Centers the elements upon serialization by applying the center point of "
"all placements as an offset. Applicable for OBJ and DAE output.") "all placements as an offset. Applicable for OBJ and DAE output. Can take several minutes on large models.")
("model-offset", po::value<std::string>(&offset_str), ("model-offset", po::value<std::string>(&offset_str),
"Applies an arbitrary offset of form 'x;y;z' to all placements. Applicable for OBJ and DAE output.") "Applies an arbitrary offset of form 'x;y;z' to all placements. Applicable for OBJ and DAE output.")
("site-local-placement", ("site-local-placement",
@@ -638,7 +638,7 @@ int main(int argc, char** argv)
int old_progress = quiet ? 0 : -1; int old_progress = quiet ? 0 : -1;
if (center_model || model_offset) { if (is_tesselated && (center_model || model_offset)) {
double* offset = serializer->settings().offset; double* offset = serializer->settings().offset;
if (center_model) { if (center_model) {
if (site_local_placement || building_local_placement) { if (site_local_placement || building_local_placement) {
@@ -646,6 +646,11 @@ int main(int argc, char** argv)
delete serializer; delete serializer;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (!quiet) Logger::Status("Computing bounds...");
context_iterator.compute_bounds();
if (!quiet) Logger::Status("Done!");
gp_XYZ center = (context_iterator.bounds_min() + context_iterator.bounds_max()) * 0.5; gp_XYZ center = (context_iterator.bounds_min() + context_iterator.bounds_max()) * 0.5;
offset[0] = -center.X(); offset[0] = -center.X();
offset[1] = -center.Y(); offset[1] = -center.Y();
+7 -2
View File
@@ -285,6 +285,13 @@ namespace IfcGeom {
done = 0; done = 0;
total = representations->size(); total = representations->size();
return true;
}
/// Computes model's bounding box (bounds_min and bounds_max).
/// @note Can take several minutes for large files.
void compute_bounds()
{
for (int i = 1; i < 4; ++i) { for (int i = 1; i < 4; ++i) {
bounds_min_.SetCoord(i, std::numeric_limits<double>::infinity()); bounds_min_.SetCoord(i, std::numeric_limits<double>::infinity());
bounds_max_.SetCoord(i, -std::numeric_limits<double>::infinity()); bounds_max_.SetCoord(i, -std::numeric_limits<double>::infinity());
@@ -319,8 +326,6 @@ namespace IfcGeom {
bounds_max_.SetZ(std::max(bounds_max_.Z(), pos.Z())); bounds_max_.SetZ(std::max(bounds_max_.Z(), pos.Z()));
} }
} }
return true;
} }
int progress() const { return 100 * done / total; } int progress() const { return 100 * done / total; }