Files
IfcOpenShell/src/ifcgeom/mapping/IfcAxis2Placement3D.cpp
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

61 lines
2.7 KiB
C++
Raw Normal View History

2022-06-14 15:02:54 +02:00
/********************************************************************************
* *
* This file is part of IfcOpenShell. *
* *
* IfcOpenShell is free software: you can redistribute it and/or modify *
* it under the terms of the Lesser GNU General Public License as published by *
* the Free Software Foundation, either version 3.0 of the License, or *
* (at your option) any later version. *
* *
* IfcOpenShell is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* Lesser GNU General Public License for more details. *
* *
* You should have received a copy of the Lesser GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
********************************************************************************/
2023-03-21 20:15:01 +01:00
#include "mapping.h"
2022-06-14 15:02:54 +02:00
2023-03-21 20:15:01 +01:00
#define mapping POSTFIX_SCHEMA(mapping)
2022-06-14 15:02:54 +02:00
2023-03-21 20:15:01 +01:00
using namespace ifcopenshell::geometry;
2022-06-14 15:02:54 +02:00
taxonomy::ptr mapping::map_impl(const IfcSchema::IfcAxis2Placement3D* inst) {
Eigen::Vector3d o(0, 0, 0), axis(0, 0, 1), refDirection, X(1, 0, 0);
try {
taxonomy::point3::ptr v = taxonomy::cast<taxonomy::point3>(map(inst->Location()));
o = *v->components_;
} catch (const std::exception&) {
Logger::Warning("Placement with invalid Location:", inst);
2022-06-14 15:02:54 +02:00
}
2023-03-21 20:15:01 +01:00
const bool hasAxis = !!inst->Axis();
const bool hasRef = !!inst->RefDirection();
2022-06-14 15:02:54 +02:00
if (hasAxis != hasRef) {
2023-03-21 20:15:01 +01:00
Logger::Warning("Axis and RefDirection should be specified together", inst);
2022-06-14 15:02:54 +02:00
}
if (hasAxis) {
taxonomy::direction3::ptr v = taxonomy::cast<taxonomy::direction3>(map(inst->Axis()));
axis = *v->components_;
2022-06-14 15:02:54 +02:00
}
if (hasRef) {
taxonomy::direction3::ptr v = taxonomy::cast<taxonomy::direction3>(map(inst->RefDirection()));
refDirection = *v->components_;
2022-06-14 15:02:54 +02:00
} else {
2023-03-21 20:15:01 +01:00
if (acos(axis.dot(X)) > 1.e-5) {
refDirection = { 1., 0., 0. };
2022-06-14 15:02:54 +02:00
} else {
2023-03-21 20:15:01 +01:00
refDirection = { 0., 0., 1. };
2022-06-14 15:02:54 +02:00
}
2023-03-21 20:15:01 +01:00
auto Xvec = axis.dot(refDirection) * axis;
auto Xaxis = refDirection - Xvec;
2022-06-14 15:02:54 +02:00
refDirection = Xaxis;
}
return taxonomy::make<taxonomy::matrix4>(o, axis, refDirection);
2022-06-14 15:02:54 +02:00
}