From 4061f93560ab90d93db17d5ec49c339490bb7277 Mon Sep 17 00:00:00 2001 From: Ken Arroyo Ohori Date: Mon, 20 Mar 2017 20:57:17 -0600 Subject: [PATCH] Export non-simple Nef too --- .../kernels/cgal/CgalConversionFunctions.cpp | 16 +++++++-- .../kernels/cgal/CgalConversionResult.cpp | 34 +++++++++++++++++-- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/ifcgeom/kernels/cgal/CgalConversionFunctions.cpp b/src/ifcgeom/kernels/cgal/CgalConversionFunctions.cpp index 818ee56f47..6d69e9c384 100644 --- a/src/ifcgeom/kernels/cgal/CgalConversionFunctions.cpp +++ b/src/ifcgeom/kernels/cgal/CgalConversionFunctions.cpp @@ -41,13 +41,23 @@ CGAL::Nef_polyhedron_3 IfcGeom::CgalKernel::create_nef_polyhedron(std::l // fresult.close(); return CGAL::Nef_polyhedron_3(); } if (!polyhedron.is_closed()) { - std::cout << "create_nef_polyhedron: Polyhedron not closed" << std::endl; // std::ofstream fresult; // fresult.open("/Users/ken/Desktop/open.off"); // fresult << polyhedron << std::endl; // fresult.close(); - // TODO: Nef constructor doesn't support open meshes - return CGAL::Nef_polyhedron_3(polyhedron); + CGAL::Nef_polyhedron_3 mesh; + unsigned int current_face = 0; + for (auto &face: faces(polyhedron)) { + ++current_face; +// if (current_face%10 == 0) std::cout << current_face << "/" << polyhedron.size_of_facets() << std::endl; + std::list points_in_face; + CGAL::Polyhedron_3::Halfedge_around_facet_const_circulator current_halfedge = face->facet_begin(); + do { + points_in_face.push_back(current_halfedge->vertex()->point()); + ++current_halfedge; + } while (current_halfedge != face->facet_begin()); + mesh += CGAL::Nef_polyhedron_3(points_in_face.begin(), points_in_face.end()); + } return mesh; } if (!CGAL::Polygon_mesh_processing::is_outward_oriented(polyhedron)) { CGAL::Polygon_mesh_processing::reverse_face_orientations(polyhedron); diff --git a/src/ifcgeom/kernels/cgal/CgalConversionResult.cpp b/src/ifcgeom/kernels/cgal/CgalConversionResult.cpp index 171b7ee2e8..93abf453b4 100644 --- a/src/ifcgeom/kernels/cgal/CgalConversionResult.cpp +++ b/src/ifcgeom/kernels/cgal/CgalConversionResult.cpp @@ -4,11 +4,39 @@ void IfcGeom::CgalShape::Triangulate(const IfcGeom::IteratorSettings & settings, const IfcGeom::ConversionResultPlacement * place, IfcGeom::Representation::Triangulation* t, int surface_style_id) const { cgal_shape_t s = shape_; const cgal_placement_t& trsf = dynamic_cast(place)->trsf(); -// std::cout << "Model: " << s.size_of_facets() << " facets and " << s.size_of_vertices() << " vertices" << std::endl; -// std::cout << "Valid: " << s.is_valid() << std::endl; + + std::cout << "Nef Model: " << s.number_of_facets() << " facets and " << s.number_of_vertices() << " vertices" << std::endl; + std::cout << "Simple: " << s.is_simple() << std::endl; CGAL::Polyhedron_3 polyhedron; - s.convert_to_polyhedron(polyhedron); + if (s.is_simple()) s.convert_to_polyhedron(polyhedron); + else { + std::list face_list; + face_list.push_back(cgal_face_t()); + std::set::Halffacet_const_handle> visited_halffacets; + for (CGAL::Nef_polyhedron_3::Halffacet_const_iterator current_halffacet = s.halffacets_begin(); + current_halffacet != s.halffacets_end(); + ++current_halffacet) { + if (visited_halffacets.count(current_halffacet->twin())) continue; + for (CGAL::Nef_polyhedron_3::Halffacet_cycle_const_iterator current_halffacet_cycle = current_halffacet->facet_cycles_begin(); + current_halffacet_cycle != current_halffacet->facet_cycles_end(); + ++current_halffacet_cycle) { + if (current_halffacet_cycle.is_shalfloop()) continue; + CGAL::Nef_polyhedron_3::SHalfedge_const_handle first_shalfedge = current_halffacet_cycle; + CGAL::Nef_polyhedron_3::SHalfedge_const_handle current_shalfedge = first_shalfedge; + if (!face_list.back().outer.empty()) face_list.push_back(cgal_face_t()); + do { + face_list.back().outer.push_back(current_shalfedge->source()->center_vertex()->point()); + current_shalfedge = current_shalfedge->next(); + } while (current_shalfedge != first_shalfedge); + } + } if (face_list.back().outer.empty()) face_list.pop_back(); + PolyhedronBuilder builder(&face_list); + polyhedron.delegate(builder); + } + + std::cout << "Polyhedron Model: " << polyhedron.size_of_facets() << " facets and " << polyhedron.size_of_vertices() << " vertices" << std::endl; + std::cout << "Valid: " << polyhedron.is_valid() << std::endl; // Apply transformation if (place != NULL) for (auto &vertex: vertices(polyhedron)) {