// Copyright (c) 2019 Geometry Factory // All rights reserved. // // This file is part of CGAL (www.cgal.org) // // $URL: https://github.com/CGAL/cgal/blob/v5.1/Surface_mesh/include/CGAL/Surface_mesh/IO/3mf.h $ // $Id: 3mf.h 52164b1 2019-10-19T15:34:59+02:00 Sébastien Loriot // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial // // Author(s) : Maxime Gimeno #ifndef CGAL_SURFACE_MESH_IO_3MF_H #define CGAL_SURFACE_MESH_IO_3MF_H #include #include #include namespace CGAL{ /*! * Extracts the surface meshes from an input 3mf file and appends it to `output`. *\tparam Point the Point type of the output meshes. * \param file_name the path to the 3mf file. * \param output a `std::vector` containing the `CGAL::Surface_mesh`s that will be filled by this function. * \return the number of extracted meshes. */ template int read_3mf(const std::string& file_name, std::vector >& output) { typedef std::vector PointRange; typedef std::vector Polygon; typedef std::vector PolygonRange; typedef CGAL::Surface_mesh SMesh; typedef typename SMesh::Vertex_index Vertex_index; typedef typename SMesh::Face_index Face_index; std::vector all_points; std::vector all_polygons; std::vector names; std::vector > all_colors; int result = 0; int nb_meshes = CGAL::read_triangle_soups_from_3mf(file_name, all_points, all_polygons, all_colors, names); if(nb_meshes < 0 ) { std::cerr << "Error in reading meshes."< colors = all_colors[i]; //Create the surface mesh from scratch std::size_t n(points.size()); sm.reserve(n,0, triangles.size()); for(const Point& p : points) { sm.add_vertex(p); } for(Polygon& triangle : triangles) { std::vector face; face.reserve(triangle.size()); for(auto index : triangle) { face.push_back(Vertex_index(index)); } Face_index fi = sm.add_face(face); if(fi == sm.null_face()) { skip = true; sm.clear(); break; } } if(skip) continue; //end constructin the surface mesh from scratch CGAL::Color first = colors.front(); bool need_pmap = false; for(auto color : colors) { if (color != first) { need_pmap = true; break; } } if(need_pmap) { typename SMesh::template Property_map fcolor = sm.template add_property_map("f:color",first).first; for(std::size_t pid = 0; pid < colors.size(); ++pid) { put(fcolor, Face_index(pid), colors[pid]);//should work bc mesh is just created and shouldn't have any destroyed face. } } output.push_back(sm); ++result; } return result; } }//end CGAL #endif // CGAL_SURFACE_MESH_3MF_H