Reintroduce --model-offset/-rotation MODEL_OFFSET/_ROTATION setting #5231

This commit is contained in:
Thomas Krijnen
2024-09-13 11:37:05 +02:00
parent 81399ffd19
commit d879bf9f89
9 changed files with 87 additions and 206 deletions
+9 -5
View File
@@ -65,16 +65,21 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcObjectPlacement* inst) {
}
}
taxonomy::ptr result;
taxonomy::matrix4::ptr result;
if (!parent_placement_ignored && relative_to) {
result = taxonomy::make<taxonomy::matrix4>(
// @nb this is a bit silly, in 0.7 we didn't have a recursive function
// but a while loop to apply the hierarchical placements, so after the
// loop we could apply the global offset. Since we have a recursive
// function now we need to undo the global offset when recursing.
offset_and_rotation_.inverse() *
taxonomy::cast<taxonomy::matrix4>(map(relative_to))->ccomponents() *
taxonomy::cast<taxonomy::matrix4>(map(transform))->ccomponents()
);
} else {
// The parent placement of the current is a placement for a type that is
// being ignored (Site or Building) or it is the host element of an opening.
result = map(transform);
result = taxonomy::cast<taxonomy::matrix4>(map(transform));
}
if (fallback) {
@@ -84,10 +89,9 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcObjectPlacement* inst) {
}
}
return result;
result->components() = offset_and_rotation_ * result->ccomponents();
// @todo
// m4->components() = offset_and_rotation_ * m4->components();
return result;
}
/*
+22
View File
@@ -807,6 +807,28 @@ void mapping::initialize_units_() {
if (settings_.get<settings::SiteLocalPlacement>().get()) {
placement_rel_to_type_ = file_->schema()->declaration_by_name("IfcSite");
}
// Translation is applied first, then rotation.
if (settings_.get<ModelOffset>().has()) {
auto vs = settings_.get<ModelOffset>().get();
if (vs.size() == 3) {
offset_and_rotation_ *= Eigen::Affine3d(Eigen::Translation3d(vs[0], vs[1], vs[2])).matrix();
} else {
Logger::Error("Expected 3 values for model-offset setting");
}
}
if (settings_.get<ModelRotation>().has()) {
auto vs = settings_.get<ModelRotation>().get();
if (vs.size() == 4) {
auto m3 = Eigen::Quaterniond(vs[0], vs[1], vs[2], vs[3]).matrix();
Eigen::Matrix4d m4 = Eigen::Matrix4d::Identity();
m4 << m3;
offset_and_rotation_ *= m4;
} else {
Logger::Error("Expected 4 values for model-rotation setting");
}
}
}
void mapping::initialize_settings() {
+2
View File
@@ -30,6 +30,8 @@ namespace geometry {
const IfcParse::declaration* placement_rel_to_type_;
const IfcUtil::IfcBaseEntity* placement_rel_to_instance_;
Eigen::Matrix4d offset_and_rotation_ = Eigen::Matrix4d::Identity();
void initialize_units_();
void addRepresentationsFromContextIds(IfcSchema::IfcRepresentation::list::ptr&);