mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 18:16:40 +00:00
Export non-simple Nef too
This commit is contained in:
@@ -41,13 +41,23 @@ CGAL::Nef_polyhedron_3<Kernel> IfcGeom::CgalKernel::create_nef_polyhedron(std::l
|
||||
// fresult.close();
|
||||
return CGAL::Nef_polyhedron_3<Kernel>();
|
||||
} 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<Kernel>(polyhedron);
|
||||
CGAL::Nef_polyhedron_3<Kernel> 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<Kernel::Point_3> points_in_face;
|
||||
CGAL::Polyhedron_3<Kernel>::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<Kernel>(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);
|
||||
|
||||
@@ -4,11 +4,39 @@
|
||||
void IfcGeom::CgalShape::Triangulate(const IfcGeom::IteratorSettings & settings, const IfcGeom::ConversionResultPlacement * place, IfcGeom::Representation::Triangulation<double>* t, int surface_style_id) const {
|
||||
cgal_shape_t s = shape_;
|
||||
const cgal_placement_t& trsf = dynamic_cast<const CgalPlacement*>(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<Kernel> polyhedron;
|
||||
s.convert_to_polyhedron(polyhedron);
|
||||
if (s.is_simple()) s.convert_to_polyhedron(polyhedron);
|
||||
else {
|
||||
std::list<cgal_face_t> face_list;
|
||||
face_list.push_back(cgal_face_t());
|
||||
std::set<CGAL::Nef_polyhedron_3<Kernel>::Halffacet_const_handle> visited_halffacets;
|
||||
for (CGAL::Nef_polyhedron_3<Kernel>::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<Kernel>::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<Kernel>::SHalfedge_const_handle first_shalfedge = current_halffacet_cycle;
|
||||
CGAL::Nef_polyhedron_3<Kernel>::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)) {
|
||||
|
||||
Reference in New Issue
Block a user