diff --git a/src/ifcgeom/kernels/opencascade/IfcGeomTree.h b/src/ifcgeom/kernels/opencascade/IfcGeomTree.h index 985e4e81cd..9e436ea24c 100644 --- a/src/ifcgeom/kernels/opencascade/IfcGeomTree.h +++ b/src/ifcgeom/kernels/opencascade/IfcGeomTree.h @@ -1438,12 +1438,12 @@ namespace IfcGeom { // Temporary structures for H5 std::vector triangulation_elements_; - std::map global_ids_; - std::map names_; - std::map> placements_; + std::map global_ids_; + std::map names_; + std::map placements_; std::map> local_verts_; std::map> local_faces_; - std::map> local_materials_; + std::map> local_materials_; std::map> local_material_ids_; bool enable_face_styles_ = false; @@ -1533,7 +1533,13 @@ namespace IfcGeom { const auto geometry_id = elem->geometry().id(); const auto& placement = placements_[elem->product()]; - matrices.emplace_back(placement.begin(), placement.end()); + { + decltype(matrices)::value_type m; + for (size_t i = 0; i < 16; ++i) { + m.push_back(static_cast(placement->ccomponents().data()[i])); + } + matrices.push_back(m); + } names.push_back(names_[elem->product()]); global_ids.push_back(global_ids_[elem->product()]); @@ -1596,16 +1602,16 @@ namespace IfcGeom { std::vector material_keys; for (const auto& material : materials) { float alpha = 1.0; - if (material.hasTransparency() && material.transparency() > 0) { - alpha = 1.0 - material.transparency(); + if (material->has_transparency() && material->transparency > 0) { + alpha = 1.0 - material->transparency; } int i = 0; bool is_existing_colour = false; for (const auto& colour : colours) { - if (std::abs(colour[0] - static_cast(material.diffuse()[0])) < tolerance - && std::abs(colour[1] - static_cast(material.diffuse()[1])) < tolerance - && std::abs(colour[2] - static_cast(material.diffuse()[2])) < tolerance + if (std::abs(colour[0] - static_cast(material->diffuse.ccomponents()[0])) < tolerance + && std::abs(colour[1] - static_cast(material->diffuse.ccomponents()[1])) < tolerance + && std::abs(colour[2] - static_cast(material->diffuse.ccomponents()[2])) < tolerance && std::abs(colour[3] - alpha) < tolerance) { is_existing_colour = true; break; @@ -1615,9 +1621,9 @@ namespace IfcGeom { if ( ! is_existing_colour) { colours.push_back({ - static_cast(material.diffuse()[0]), - static_cast(material.diffuse()[1]), - static_cast(material.diffuse()[2]), + static_cast(material->diffuse.ccomponents()[0]), + static_cast(material->diffuse.ccomponents()[1]), + static_cast(material->diffuse.ccomponents()[2]), alpha}); } material_keys.push_back(static_cast(i)); @@ -1725,17 +1731,20 @@ namespace IfcGeom { } template - void apply_matrix_to_flat_verts(const std::vector& flat_list, const std::vector& matrix, std::vector& result) { + void apply_matrix_to_flat_verts(const std::vector& flat_list, const ifcopenshell::geometry::taxonomy::matrix4::ptr& matrix, std::vector& result) { + Eigen::Vector3d vin; result.clear(); result.reserve(flat_list.size()); for (size_t i = 0; i < flat_list.size(); i += 3) { - float x = flat_list[i]; - float y = flat_list[i + 1]; - float z = flat_list[i + 2]; - result.push_back(x * matrix[0] + y * matrix[3] + z * matrix[6] + matrix[9]); - result.push_back(x * matrix[1] + y * matrix[4] + z * matrix[7] + matrix[10]); - result.push_back(x * matrix[2] + y * matrix[5] + z * matrix[8] + matrix[11]); + vin << + flat_list[i], + flat_list[i + 1], + flat_list[i + 2]; + auto vout = matrix->ccomponents() * vin.homogeneous(); + result.push_back(vout(0)); + result.push_back(vout(1)); + result.push_back(vout(2)); } } @@ -1773,21 +1782,24 @@ namespace IfcGeom { Bnd_OBB obb; { - auto& trsf = elem->transformation().data(); + auto& m = elem->transformation().data()->ccomponents(); auto& vs = elem->geometry().verts(); auto& fs = elem->geometry().faces(); + gp_Trsf tr; + tr.SetValues( + m(0, 0), m(0, 1), m(0, 2), m(0, 3), + m(1, 0), m(1, 1), m(1, 2), m(1, 3), + m(2, 0), m(2, 1), m(2, 2), m(2, 3) + ); + std::vector vs_transformed; vs_transformed.reserve(vs.size() / 3); for (size_t i = 0; i < vs.size(); i += 3) { gp_Pnt p(vs[i + 0], vs[i + 1], vs[i + 2]); - vs_transformed.push_back(p.Transformed(trsf)); + vs_transformed.push_back(p.Transformed(tr)); aabb.Add(vs_transformed.back()); } - - std::cout << "aabb: "; - aabb.DumpJson(std::cout); - std::cout << std::endl; std::unordered_map, std::vector, boost::hash>> quantized_normal_counts; @@ -1871,14 +1883,10 @@ namespace IfcGeom { obb.SetYComponent(ax3.YDirection(), halfsize.Y()); obb.SetZComponent(ax3.Direction(), halfsize.Z()); obb.SetCenter(cent.Transformed(trsf2.Inverted())); - - std::cout << "obb: "; - obb.DumpJson(std::cout); - std::cout << std::endl; } const auto& t = elem->product(); - const std::vector& matrix = elem->transformation().matrix().data(); + const auto& matrix = elem->transformation().data(); const std::vector& elem_verts_local = elem->geometry().verts(); const std::vector& elem_faces = elem->geometry().faces(); std::vector elem_verts;