Use map in builder; stitch borders optional; fix positioning of 2d arrangement

This commit is contained in:
Thomas Krijnen
2020-09-14 13:55:14 +02:00
parent c40f9fdd97
commit 52942f8a3e
2 changed files with 27 additions and 15 deletions
+15 -3
View File
@@ -40,7 +40,7 @@ void CgalKernel::remove_duplicate_points_from_loop(cgal_wire_t& polygon) {
}
}
CGAL::Polyhedron_3<Kernel_> ifcopenshell::geometry::utils::create_polyhedron(std::list<cgal_face_t> &face_list) {
CGAL::Polyhedron_3<Kernel_> ifcopenshell::geometry::utils::create_polyhedron(std::list<cgal_face_t> &face_list, bool stitch_borders) {
// Naive creation
CGAL::Polyhedron_3<Kernel_> polyhedron;
@@ -49,7 +49,15 @@ CGAL::Polyhedron_3<Kernel_> ifcopenshell::geometry::utils::create_polyhedron(std
// Stitch edges
// std::cout << "Before: " << polyhedron.size_of_vertices() << " vertices and " << polyhedron.size_of_facets() << " facets" << std::endl;
CGAL::Polygon_mesh_processing::stitch_borders(polyhedron);
if (stitch_borders) {
// we have a map of points now in the builder, it's maybe not necessary anymore to stitch_borders?
// size_t ne = polyhedron.size_of_border_edges();
CGAL::Polygon_mesh_processing::stitch_borders(polyhedron);
// size_t ne2 = polyhedron.size_of_border_edges();
// std::wcout << (ne - ne2) << " removed" << std::endl;
}
polyhedron.normalize_border();
if (!polyhedron.is_valid(false, 1)) {
Logger::Message(Logger::LOG_ERROR, "create_polyhedron: Polyhedron not valid!");
@@ -1000,8 +1008,12 @@ bool CgalKernel::process_as_2d_polygon(const taxonomy::boolean_result* br, std::
loops.clear();
std::transform(wires.begin(), wires.end(), std::back_inserter(loops), wire_to_polygon_2);
auto& op_0_matrix = *extrusions[0]->matrix.components;
Eigen::Vector4d op_0_dir;
op_0_dir << (*extrusions[0]->direction.components), 0;
op_0_dir = op_0_matrix * op_0_dir;
z0 = op_0_matrix_2_3;
z1 = z0 + extrusions[0]->depth * (*extrusions[0]->direction.components)(2);
z1 = z0 + extrusions[0]->depth * op_0_dir(2);
if (z1 < z0) {
std::swap(z0, z1);
+12 -12
View File
@@ -53,24 +53,24 @@ public:
}
void operator()(CGAL::Polyhedron_3<Kernel_>::HalfedgeDS &hds) {
std::list<Kernel_::Point_3> points;
std::list<std::list<std::size_t>> facet_vertices;
// std::list<Kernel_::Point_3> points;
std::map<Kernel_::Point_3, size_t> points;
std::vector<std::vector<std::size_t>> facet_vertices(face_list->size());
CGAL::Polyhedron_incremental_builder_3<CGAL::Polyhedron_3<Kernel_>::HalfedgeDS> builder(hds, true);
size_t i = 0;
for (auto &face: *face_list) {
facet_vertices.push_back(std::list<std::size_t>());
for (auto &point: face.outer) {
facet_vertices.back().push_back(points.size());
points.push_back(point);
auto p = points.insert({ point, points.size() });
if (p.second) {
builder.add_vertex(point);
}
facet_vertices[i].push_back(p.first->second);
}
i++;
}
builder.begin_surface(points.size(), facet_vertices.size());
for (auto &point: points) {
// std::cout << "Adding point " << point << std::endl;
builder.add_vertex(point);
}
builder.begin_surface(points.size(), facet_vertices.size(), 0, CGAL::Polyhedron_incremental_builder_3<CGAL::Polyhedron_3<Kernel_>::HalfedgeDS>::ABSOLUTE_INDEXING);
for (auto &facet: facet_vertices) {
builder.begin_facet();
@@ -92,7 +92,7 @@ namespace geometry {
namespace utils {
IFC_GEOM_API CGAL::Polyhedron_3<Kernel_> create_cube(double d);
IFC_GEOM_API CGAL::Polyhedron_3<Kernel_> create_cube(const Kernel_::Point_3& lower, const Kernel_::Point_3& upper);
IFC_GEOM_API CGAL::Polyhedron_3<Kernel_> create_polyhedron(std::list<cgal_face_t> &face_list);
IFC_GEOM_API CGAL::Polyhedron_3<Kernel_> create_polyhedron(std::list<cgal_face_t> &face_list, bool stitch_borders=false);
IFC_GEOM_API CGAL::Polyhedron_3<Kernel_> create_polyhedron(const CGAL::Nef_polyhedron_3<Kernel_> &nef_polyhedron);
IFC_GEOM_API CGAL::Nef_polyhedron_3<Kernel_> create_nef_polyhedron(std::list<cgal_face_t> &face_list);
IFC_GEOM_API CGAL::Nef_polyhedron_3<Kernel_> create_nef_polyhedron(CGAL::Polyhedron_3<Kernel_> &polyhedron);