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"
|
|
|
|
|
#define mapping POSTFIX_SCHEMA(mapping)
|
|
|
|
|
using namespace ifcopenshell::geometry;
|
2022-06-14 15:02:54 +02:00
|
|
|
|
|
|
|
|
#ifdef SCHEMA_HAS_IfcIndexedPolyCurve
|
|
|
|
|
|
2026-01-04 10:40:02 +01:00
|
|
|
taxonomy::ptr mapping::map_impl(const IfcSchema::IfcIndexedPolyCurve& inst) {
|
2022-06-14 15:02:54 +02:00
|
|
|
|
2026-01-04 10:40:02 +01:00
|
|
|
auto point_list = inst.Points();
|
2022-06-14 15:02:54 +02:00
|
|
|
std::vector< std::vector<double> > coordinates;
|
2026-01-04 10:40:02 +01:00
|
|
|
if (point_list.as<IfcSchema::IfcCartesianPointList2D>()) {
|
|
|
|
|
coordinates = point_list.as<IfcSchema::IfcCartesianPointList2D>().CoordList();
|
|
|
|
|
} else if (point_list.as<IfcSchema::IfcCartesianPointList3D>()) {
|
|
|
|
|
coordinates = point_list.as<IfcSchema::IfcCartesianPointList3D>().CoordList();
|
2022-06-14 15:02:54 +02:00
|
|
|
}
|
|
|
|
|
|
2023-07-27 16:42:06 +08:00
|
|
|
std::vector<taxonomy::point3::ptr> points;
|
2024-09-27 16:30:20 +05:00
|
|
|
if (coordinates.size() < 2) {
|
2026-03-31 15:32:36 +02:00
|
|
|
throw ifcopenshell::exception("IfcIndexedPolyCurve has less than 2 points.");
|
2024-09-27 16:30:20 +05:00
|
|
|
}
|
|
|
|
|
|
2022-06-14 15:02:54 +02:00
|
|
|
points.reserve(coordinates.size());
|
2023-03-21 20:15:01 +01:00
|
|
|
for (auto& coords : coordinates) {
|
2023-07-27 16:42:06 +08:00
|
|
|
points.push_back(taxonomy::make<taxonomy::point3>(
|
2023-03-21 20:15:01 +01:00
|
|
|
coords.size() < 1 ? 0. : coords[0] * length_unit_,
|
|
|
|
|
coords.size() < 2 ? 0. : coords[1] * length_unit_,
|
|
|
|
|
coords.size() < 3 ? 0. : coords[2] * length_unit_));
|
2022-06-14 15:02:54 +02:00
|
|
|
}
|
|
|
|
|
|
2022-11-13 11:04:16 +01:00
|
|
|
int max_index = (int) points.size();
|
2022-06-14 15:02:54 +02:00
|
|
|
|
2023-07-27 16:42:06 +08:00
|
|
|
auto loop = taxonomy::make<taxonomy::loop>();
|
2022-06-14 15:02:54 +02:00
|
|
|
|
2026-01-04 10:40:02 +01:00
|
|
|
if(inst.Segments()) {
|
|
|
|
|
auto segments = inst.Segments();
|
|
|
|
|
for (auto& segment : *segments) {
|
|
|
|
|
if (auto line = segment.as<IfcSchema::IfcLineIndex>()) {
|
2026-07-19 12:58:23 +03:00
|
|
|
std::vector<int64_t> indices = line;
|
2023-07-27 16:42:06 +08:00
|
|
|
taxonomy::point3::ptr previous;
|
2026-07-19 12:58:23 +03:00
|
|
|
for (std::vector<int64_t>::const_iterator jt = indices.begin(); jt != indices.end(); ++jt) {
|
2022-06-14 15:02:54 +02:00
|
|
|
if (*jt < 1 || *jt > max_index) {
|
2026-03-31 15:32:36 +02:00
|
|
|
throw ifcopenshell::exception("IfcIndexedPolyCurve index out of bounds for index " + boost::lexical_cast<std::string>(*jt));
|
2022-06-14 15:02:54 +02:00
|
|
|
}
|
2023-07-27 16:42:06 +08:00
|
|
|
auto current = points[*jt - 1];
|
2022-06-14 15:02:54 +02:00
|
|
|
if (jt != indices.begin()) {
|
2023-07-27 16:42:06 +08:00
|
|
|
loop->children.push_back(taxonomy::make<taxonomy::edge>(previous, current));
|
2022-06-14 15:02:54 +02:00
|
|
|
}
|
|
|
|
|
previous = current;
|
|
|
|
|
}
|
2026-01-04 10:40:02 +01:00
|
|
|
} else if (auto arc = segment.as<IfcSchema::IfcArcIndex>()) {
|
2026-07-19 12:58:23 +03:00
|
|
|
std::vector<int64_t> indices = arc;
|
2022-06-14 15:02:54 +02:00
|
|
|
if (indices.size() != 3) {
|
2026-03-31 15:32:36 +02:00
|
|
|
throw ifcopenshell::exception("Invalid IfcArcIndex encountered");
|
2022-06-14 15:02:54 +02:00
|
|
|
}
|
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
2026-07-19 12:58:23 +03:00
|
|
|
const int64_t& idx = indices[i];
|
2022-06-14 15:02:54 +02:00
|
|
|
if (idx < 1 || idx > max_index) {
|
2026-03-31 15:32:36 +02:00
|
|
|
throw ifcopenshell::exception("IfcIndexedPolyCurve index out of bounds for index " + boost::lexical_cast<std::string>(idx));
|
2022-06-14 15:02:54 +02:00
|
|
|
}
|
|
|
|
|
}
|
2023-03-21 20:15:01 +01:00
|
|
|
const auto& a = points[indices[0] - 1];
|
|
|
|
|
const auto& b = points[indices[1] - 1];
|
|
|
|
|
const auto& c = points[indices[2] - 1];
|
|
|
|
|
|
2023-07-27 16:42:06 +08:00
|
|
|
auto circ = taxonomy::circle::from_3_points(a->ccomponents(), b->ccomponents(), c->ccomponents());
|
2023-03-21 20:15:01 +01:00
|
|
|
if (circ) {
|
2023-07-27 16:42:06 +08:00
|
|
|
auto e = taxonomy::make<taxonomy::edge>(a, c);
|
2023-03-21 20:15:01 +01:00
|
|
|
e->basis = circ;
|
|
|
|
|
loop->children.push_back(e);
|
2022-06-14 15:02:54 +02:00
|
|
|
} else {
|
2026-07-09 13:30:48 +02:00
|
|
|
logger_.warning("GEO", 263, "Ignoring segment on", inst);
|
2022-06-14 15:02:54 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
2026-03-31 15:32:36 +02:00
|
|
|
throw ifcopenshell::exception("Unexpected IfcIndexedPolyCurve segment of type " + segment.concrete().declaration().name());
|
2022-06-14 15:02:54 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (points.begin() < points.end()) {
|
2023-03-21 20:15:01 +01:00
|
|
|
auto previous = points.begin();
|
|
|
|
|
for (auto current = previous+1; current < points.end(); ++current){
|
2023-07-27 16:42:06 +08:00
|
|
|
loop->children.push_back(taxonomy::make<taxonomy::edge>(*previous, *current));
|
2023-03-21 20:15:01 +01:00
|
|
|
previous = current;
|
2022-06-14 15:02:54 +02:00
|
|
|
}
|
|
|
|
|
}
|
2023-03-21 20:15:01 +01:00
|
|
|
|
|
|
|
|
return loop;
|
2022-06-14 15:02:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|