Skip to content

Commit 07f5ac6

Browse files
Stinkfist0aothms
authored andcommitted
IfcGeomIterator: compute model's bounding box only if needed (IfcConvert --center-model used).
1 parent 0eb6c59 commit 07f5ac6

2 files changed

Lines changed: 29 additions & 19 deletions

File tree

src/ifcconvert/IfcConvert.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ int main(int argc, char** argv)
296296
"Applicable for DAE output.")
297297
("center-model",
298298
"Centers the elements upon serialization by applying the center point of "
299-
"all placements as an offset. Applicable for OBJ and DAE output.")
299+
"all placements as an offset. Applicable for OBJ and DAE output. Can take several minutes on large models.")
300300
("model-offset", po::value<std::string>(&offset_str),
301301
"Applies an arbitrary offset of form 'x;y;z' to all placements. Applicable for OBJ and DAE output.")
302302
("site-local-placement",
@@ -638,14 +638,19 @@ int main(int argc, char** argv)
638638

639639
int old_progress = quiet ? 0 : -1;
640640

641-
if (center_model || model_offset) {
641+
if (is_tesselated && (center_model || model_offset)) {
642642
double* offset = serializer->settings().offset;
643643
if (center_model) {
644644
if (site_local_placement || building_local_placement) {
645645
Logger::Error("Cannot use --center-model together with --{site,building}-local-placement");
646646
delete serializer;
647647
return EXIT_FAILURE;
648648
}
649+
650+
if (!quiet) Logger::Status("Computing bounds...");
651+
context_iterator.compute_bounds();
652+
if (!quiet) Logger::Status("Done!");
653+
649654
gp_XYZ center = (context_iterator.bounds_min() + context_iterator.bounds_max()) * 0.5;
650655
offset[0] = -center.X();
651656
offset[1] = -center.Y();

src/ifcgeom/IfcGeomIterator.h

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,13 @@ namespace IfcGeom {
285285
done = 0;
286286
total = representations->size();
287287

288+
return true;
289+
}
290+
291+
/// Computes model's bounding box (bounds_min and bounds_max).
292+
/// @note Can take several minutes for large files.
293+
void compute_bounds()
294+
{
288295
for (int i = 1; i < 4; ++i) {
289296
bounds_min_.SetCoord(i, std::numeric_limits<double>::infinity());
290297
bounds_max_.SetCoord(i, -std::numeric_limits<double>::infinity());
@@ -294,21 +301,21 @@ namespace IfcGeom {
294301
for (IfcSchema::IfcProduct::list::it iter = products->begin(); iter != products->end(); ++iter) {
295302
IfcSchema::IfcProduct* product = *iter;
296303
if (product->hasObjectPlacement()) {
297-
// Use a fresh trsf every time in order to prevent the result to be concatenated
304+
// Use a fresh trsf every time in order to prevent the result to be concatenated
298305
gp_Trsf trsf;
299-
bool success = false;
300-
301-
try {
302-
success = kernel.convert(product->ObjectPlacement(), trsf);
303-
} catch (const std::exception& e) {
304-
Logger::Error(e);
305-
} catch (...) {
306-
Logger::Error("Failed to construct placement");
307-
}
308-
309-
if (!success) {
310-
continue;
311-
}
306+
bool success = false;
307+
308+
try {
309+
success = kernel.convert(product->ObjectPlacement(), trsf);
310+
} catch (const std::exception& e) {
311+
Logger::Error(e);
312+
} catch (...) {
313+
Logger::Error("Failed to construct placement");
314+
}
315+
316+
if (!success) {
317+
continue;
318+
}
312319

313320
const gp_XYZ& pos = trsf.TranslationPart();
314321
bounds_min_.SetX(std::min(bounds_min_.X(), pos.X()));
@@ -319,9 +326,7 @@ namespace IfcGeom {
319326
bounds_max_.SetZ(std::max(bounds_max_.Z(), pos.Z()));
320327
}
321328
}
322-
323-
return true;
324-
}
329+
}
325330

326331
int progress() const { return 100 * done / total; }
327332

0 commit comments

Comments
 (0)