MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / compute_bounds

Method compute_bounds

src/ifcgeom/Iterator.cpp:276–324  ·  view source on GitHub ↗

Computes model's bounding box (bounds_min and bounds_max). @note Can take several minutes for large files.

Source from the content-addressed store, hash-verified

274/// Computes model's bounding box (bounds_min and bounds_max).
275/// @note Can take several minutes for large files.
276void IfcGeom::Iterator::compute_bounds(bool with_geometry)
277{
278 for (int i = 0; i < 3; ++i) {
279 bounds_min_.components()(i) = std::numeric_limits<double>::infinity();
280 bounds_max_.components()(i) = -std::numeric_limits<double>::infinity();
281 }
282
283 if (with_geometry) {
284 size_t num_created = 0;
285 do {
286 IfcGeom::Element* geom_object = get();
287 const IfcGeom::TriangulationElement* o = static_cast<const IfcGeom::TriangulationElement*>(geom_object);
288 const IfcGeom::Representation::Triangulation& mesh = o->geometry();
289 auto mat = o->transformation().data()->ccomponents();
290 Eigen::Vector4d vec, transformed;
291
292 for (typename std::vector<double>::const_iterator it = mesh.verts().begin(); it != mesh.verts().end();) {
293 const double& x = *(it++);
294 const double& y = *(it++);
295 const double& z = *(it++);
296 vec << x, y, z, 1.;
297 transformed = mat * vec;
298
299 for (int i = 0; i < 3; ++i) {
300 bounds_min_.components()(i) = std::min(bounds_min_.components()(i), transformed(i));
301 bounds_max_.components()(i) = std::max(bounds_max_.components()(i), transformed(i));
302 }
303 }
304 } while (++num_created, next());
305 } else {
306 std::vector<ifcopenshell::geometry::geometry_conversion_task> reps;
307 converter_->mapping()->get_representations(reps, filters_);
308
309 std::vector<IfcUtil::IfcBaseClass*> products;
310 for (auto& r : reps) {
311 std::copy(r.products->begin(), r.products->end(), std::back_inserter(products));
312 }
313
314 for (auto& product : products) {
315 auto prod_item = converter_->mapping()->map(product);
316 auto vec = ifcopenshell::geometry::taxonomy::cast<ifcopenshell::geometry::taxonomy::geom_item>(prod_item)->matrix->translation_part();
317
318 for (int i = 0; i < 3; ++i) {
319 bounds_min_.components()(i) = std::min(bounds_min_.components()(i), vec(i));
320 bounds_max_.components()(i) = std::max(bounds_max_.components()(i), vec(i));
321 }
322 }
323 }
324}
325
326const IfcUtil::IfcBaseClass* IfcGeom::Iterator::create_shape_model_for_next_entity() {
327 geometry_conversion_result* task = nullptr;

Callers 1

IfcConvert.cppFile · 0.80

Calls 7

getFunction · 0.85
copyFunction · 0.85
dataMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
get_representationsMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected