Switched back to Polyhedron_3 for shapes. Should be checked.

This commit is contained in:
Ken Arroyo Ohori
2017-03-23 19:49:15 -06:00
parent 4061f93560
commit 12967790ba
7 changed files with 63 additions and 100 deletions
@@ -5,41 +5,8 @@ void IfcGeom::CgalShape::Triangulate(const IfcGeom::IteratorSettings & settings,
cgal_shape_t s = shape_;
const cgal_placement_t& trsf = dynamic_cast<const CgalPlacement*>(place)->trsf();
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;
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)) {
if (place != NULL) for (auto &vertex: vertices(s)) {
vertex->point() = vertex->point().transform(trsf);
}
@@ -53,7 +20,7 @@ void IfcGeom::CgalShape::Triangulate(const IfcGeom::IteratorSettings & settings,
boost::associative_property_map<std::map<cgal_vertex_descriptor_t, Kernel::Vector_3>> vertex_normals_map(vertex_normals);
std::map<cgal_face_descriptor_t, Kernel::Vector_3> face_normals;
boost::associative_property_map<std::map<cgal_face_descriptor_t, Kernel::Vector_3>> face_normals_map(face_normals);
if (CGAL::Polygon_mesh_processing::triangulate_faces(polyhedron)) {
if (CGAL::Polygon_mesh_processing::triangulate_faces(s)) {
// std::cout << "Triangulated model: " << s.size_of_facets() << " facets and " << s.size_of_vertices() << " vertices" << std::endl;
} else {
Logger::Message(Logger::LOG_ERROR, "Failed to triangulate shape");
@@ -65,9 +32,9 @@ void IfcGeom::CgalShape::Triangulate(const IfcGeom::IteratorSettings & settings,
// fafter << s << std::endl;
// fafter.close();
CGAL::Polygon_mesh_processing::compute_normals(polyhedron, vertex_normals_map, face_normals_map);
CGAL::Polygon_mesh_processing::compute_normals(s, vertex_normals_map, face_normals_map);
for (auto &face: faces(polyhedron)) {
for (auto &face: faces(s)) {
if (!face->is_triangle()) {
std::cout << "Warning: non-triangular face!" << std::endl;
continue;