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-09-12 10:34:04 +02:00
|
|
|
|
2023-03-21 20:15:01 +01:00
|
|
|
#include "../profile_helper.h"
|
2022-06-14 15:02:54 +02:00
|
|
|
|
2023-07-27 16:42:06 +08:00
|
|
|
taxonomy::ptr mapping::map_impl(const IfcSchema::IfcPolyLoop* inst) {
|
2023-03-21 20:15:01 +01:00
|
|
|
IfcSchema::IfcCartesianPoint::list::ptr points = inst->Polygon();
|
2022-06-14 15:02:54 +02:00
|
|
|
|
|
|
|
|
// Parse and store the points in a sequence
|
2023-07-27 16:42:06 +08:00
|
|
|
std::vector<taxonomy::point3::ptr> polygon;
|
2023-03-21 20:15:01 +01:00
|
|
|
polygon.reserve(points->size());
|
|
|
|
|
std::transform(points->begin(), points->end(), std::back_inserter(polygon), [this](const IfcSchema::IfcCartesianPoint* p) {
|
2023-07-27 16:42:06 +08:00
|
|
|
return taxonomy::cast<taxonomy::point3>(map(p));
|
2023-03-21 20:15:01 +01:00
|
|
|
});
|
2022-06-14 15:02:54 +02:00
|
|
|
|
|
|
|
|
// A loop should consist of at least three vertices
|
2023-03-21 20:15:01 +01:00
|
|
|
int original_count = polygon.size();
|
2022-06-14 15:02:54 +02:00
|
|
|
if (original_count < 3) {
|
2023-03-21 20:15:01 +01:00
|
|
|
Logger::Message(Logger::LOG_WARNING, "Not enough edges for:", inst);
|
|
|
|
|
return nullptr;
|
2022-06-14 15:02:54 +02:00
|
|
|
}
|
|
|
|
|
|
2023-03-21 20:15:01 +01:00
|
|
|
// @todo Remove points that are too close to one another
|
|
|
|
|
const double eps = conv_settings_.getValue(ConversionSettings::GV_PRECISION);
|
|
|
|
|
// util::remove_duplicate_points_from_loop(polygon, true, eps);
|
2022-06-14 15:02:54 +02:00
|
|
|
|
2023-03-21 20:15:01 +01:00
|
|
|
int count = polygon.size();
|
2022-06-14 15:02:54 +02:00
|
|
|
if (original_count - count != 0) {
|
|
|
|
|
std::stringstream ss; ss << (original_count - count) << " edges removed for:";
|
2023-03-21 20:15:01 +01:00
|
|
|
Logger::Message(Logger::LOG_WARNING, ss.str(), inst);
|
2022-06-14 15:02:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (count < 3) {
|
2023-03-21 20:15:01 +01:00
|
|
|
Logger::Message(Logger::LOG_WARNING, "Not enough edges for:", inst);
|
|
|
|
|
return nullptr;
|
2022-06-14 15:02:54 +02:00
|
|
|
}
|
|
|
|
|
|
2023-03-21 20:15:01 +01:00
|
|
|
// Contrary to polyline the loop is implicitly closed
|
|
|
|
|
polygon.push_back(polygon.front());
|
|
|
|
|
|
|
|
|
|
return polygon_from_points(polygon);
|
|
|
|
|
|
|
|
|
|
// @todo make sure wire intersection check happens
|
|
|
|
|
|
|
|
|
|
/*
|
2022-06-14 15:02:54 +02:00
|
|
|
BRepBuilderAPI_MakePolygon w;
|
|
|
|
|
for (int i = 1; i <= polygon.Length(); ++i) {
|
|
|
|
|
w.Add(polygon.Value(i));
|
|
|
|
|
}
|
|
|
|
|
w.Close();
|
|
|
|
|
|
|
|
|
|
result = w.Wire();
|
|
|
|
|
|
|
|
|
|
TopTools_ListOfShape results;
|
2022-11-14 09:23:59 +01:00
|
|
|
if (getValue(GV_NO_WIRE_INTERSECTION_CHECK) < 0. && util::wire_intersections(result, results, {getValue(GV_NO_WIRE_INTERSECTION_CHECK) < 0., getValue(GV_NO_WIRE_INTERSECTION_TOLERANCE) < 0., 0., getValue(GV_PRECISION)})) {
|
2022-06-14 15:02:54 +02:00
|
|
|
Logger::Error("Self-intersections with " + boost::lexical_cast<std::string>(results.Extent()) + " cycles detected", l);
|
2022-09-12 10:34:04 +02:00
|
|
|
util::select_largest(results, result);
|
2022-06-14 15:02:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
2023-03-21 20:15:01 +01:00
|
|
|
*/
|
2022-06-14 15:02:54 +02:00
|
|
|
}
|