Computes model's bounding box (bounds_min and bounds_max). @note Can take several minutes for large files.
| 274 | /// Computes model's bounding box (bounds_min and bounds_max). |
| 275 | /// @note Can take several minutes for large files. |
| 276 | void 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 | |
| 326 | const IfcUtil::IfcBaseClass* IfcGeom::Iterator::create_shape_model_for_next_entity() { |
| 327 | geometry_conversion_result* task = nullptr; |
no test coverage detected