diff --git a/src/ifcconvert/WavefrontObjSerializer.cpp b/src/ifcconvert/WavefrontObjSerializer.cpp index 54fd609265..52881e858f 100644 --- a/src/ifcconvert/WavefrontObjSerializer.cpp +++ b/src/ifcconvert/WavefrontObjSerializer.cpp @@ -108,6 +108,7 @@ void WaveFrontOBJSerializer::write(const IfcGeom::TriangulationElement* const bool has_uvs = !mesh.uvs().empty(); const bool has_normals = !mesh.normals().empty(); +// std::cout << mesh.faces().size() << " vertices in face mesh" << std::endl; for ( std::vector::const_iterator it = mesh.faces().begin(); it != mesh.faces().end(); ) { const int material_id = *(material_it++); diff --git a/src/ifcgeom/kernels/cgal/CgalConversionFunctions.cpp b/src/ifcgeom/kernels/cgal/CgalConversionFunctions.cpp index 6919a9319f..4121a7c783 100644 --- a/src/ifcgeom/kernels/cgal/CgalConversionFunctions.cpp +++ b/src/ifcgeom/kernels/cgal/CgalConversionFunctions.cpp @@ -70,10 +70,19 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcExtrudedAreaSolid *l, cgal top_face.outer.push_back(*vertex+dir); } face_list.push_back(top_face); + // Naive creation cgal_shape_t polyhedron = CGAL::Polyhedron_3(); PolyhedronBuilder builder(&face_list); polyhedron.delegate(builder); + // 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 (!CGAL::Polygon_mesh_processing::is_outward_oriented(polyhedron)) { + CGAL::Polygon_mesh_processing::reverse_face_orientations(polyhedron); + } +// std::cout << "After: " << polyhedron.size_of_vertices() << " vertices and " << polyhedron.size_of_facets() << " facets" << std::endl; + shape = polyhedron; return true; } @@ -84,6 +93,7 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcCartesianPoint* l, cgal_po point = Kernel::Point_3(xyz.size() ? (xyz[0]*getValue(GV_LENGTH_UNIT)) : 0.0f, xyz.size() > 1 ? (xyz[1]*getValue(GV_LENGTH_UNIT)) : 0.0f, xyz.size() > 2 ? (xyz[2]*getValue(GV_LENGTH_UNIT)) : 0.0f); +// std::cout << "Converted Point(" << point << ")" << std::endl; return true; } else { throw std::runtime_error("Point without 3 coordinates"); diff --git a/src/ifcgeom/kernels/cgal/CgalConversionResult.cpp b/src/ifcgeom/kernels/cgal/CgalConversionResult.cpp index ebb7bb9c9c..59225e53f0 100644 --- a/src/ifcgeom/kernels/cgal/CgalConversionResult.cpp +++ b/src/ifcgeom/kernels/cgal/CgalConversionResult.cpp @@ -4,6 +4,8 @@ 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; // Apply transformation if (place != NULL) for (auto &vertex: vertices(s)) { @@ -15,17 +17,15 @@ void IfcGeom::CgalShape::Triangulate(const IfcGeom::IteratorSettings & settings, boost::associative_property_map> vertex_normals_map(vertex_normals); std::map face_normals; boost::associative_property_map> face_normals_map(face_normals); - try { - CGAL::Polygon_mesh_processing::triangulate_faces(s); - CGAL::Polygon_mesh_processing::compute_normals(s, vertex_normals_map, face_normals_map); - } catch (...) { - - // TODO: Catch outside - // Logger::Message(Logger::LOG_ERROR,"Failed to triangulate shape:",ifc_file->entityById(_id)->entity); + 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"); return; } + CGAL::Polygon_mesh_processing::compute_normals(s, vertex_normals_map, face_normals_map); + // Iterates over the faces of the shape int num_faces = 0, num_vertices = 0; for (auto &face: faces(s)) { @@ -43,4 +43,6 @@ void IfcGeom::CgalShape::Triangulate(const IfcGeom::IteratorSettings & settings, t->material_ids().push_back(surface_style_id); ++num_faces; } + +// std::cout << num_faces << " faces" << std::endl; } diff --git a/src/ifcgeom/kernels/cgal/CgalEntityMapping.cpp b/src/ifcgeom/kernels/cgal/CgalEntityMapping.cpp index 996926c978..802af766c2 100644 --- a/src/ifcgeom/kernels/cgal/CgalEntityMapping.cpp +++ b/src/ifcgeom/kernels/cgal/CgalEntityMapping.cpp @@ -129,13 +129,27 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcConnectedFaceSet* l, cgal_ continue; } +// std::cout << "Face in ConnectedFaceSet: " << std::endl; +// for (auto &point: face.outer) { +// std::cout << "\tPoint(" << point << ")" << std::endl; +// } + face_list.push_back(face); } + // Naive creation cgal_shape_t polyhedron = CGAL::Polyhedron_3(); PolyhedronBuilder builder(&face_list); polyhedron.delegate(builder); + // 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 (!CGAL::Polygon_mesh_processing::is_outward_oriented(polyhedron)) { + CGAL::Polygon_mesh_processing::reverse_face_orientations(polyhedron); + } +// std::cout << "After: " << polyhedron.size_of_vertices() << " vertices and " << polyhedron.size_of_facets() << " facets" << std::endl; + shape = polyhedron; return true; } @@ -189,6 +203,12 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcFace* l, cgal_face_t& face } face = mf; + +// std::cout << "Face: " << std::endl; +// for (auto &point: face.outer) { +// std::cout << "\tPoint(" << point << ")" << std::endl; +// } + return true; } @@ -225,6 +245,12 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcPolyLoop* l, cgal_wire_t& } result = polygon; + +// std::cout << "PolyLoop: " << std::endl; +// for (auto &point: polygon) { +// std::cout << "\tPoint(" << point << ")" << std::endl; +// } + return true; } diff --git a/src/ifcgeom/kernels/cgal/CgalKernel.h b/src/ifcgeom/kernels/cgal/CgalKernel.h index 596fcacf4e..4e82272375 100644 --- a/src/ifcgeom/kernels/cgal/CgalKernel.h +++ b/src/ifcgeom/kernels/cgal/CgalKernel.h @@ -43,6 +43,8 @@ if ( it != cache.T.end() ) { e = it->second; return true; } #include #include #include +#include +#include #include #include @@ -72,27 +74,23 @@ public: } void operator()(CGAL::Polyhedron_3::HalfedgeDS &hds) { - std::map points_map; + std::list points; std::list> facet_vertices; CGAL::Polyhedron_incremental_builder_3::HalfedgeDS> builder(hds, true); for (auto &face: *face_list) { facet_vertices.push_back(std::list()); for (auto &point: face.outer) { - if (points_map.count(point) == 0) { - facet_vertices.back().push_back(points_map.size()); - points_map[point] = points_map.size(); - } else { - facet_vertices.back().push_back(points_map[point]); - } + facet_vertices.back().push_back(points.size()); + points.push_back(point); } } - builder.begin_surface(points_map.size(), facet_vertices.size()); + builder.begin_surface(points.size(), facet_vertices.size()); - for (auto &point: points_map) { -// std::cout << "Adding point " << point.first << std::endl; - builder.add_vertex(point.first); + for (auto &point: points) { +// std::cout << "Adding point " << point << std::endl; + builder.add_vertex(point); } for (auto &facet: facet_vertices) {