From f3dfd786e559b86b5ea7db898cd0aa5e8866d7f7 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Tue, 17 Mar 2020 16:49:27 +0100 Subject: [PATCH] remove the UV parts of the BGL write_PLY and add NPs for the vpm and vimap. Missing doc. Also fix the STL_ASCII reader. --- .../graph/IO/Generic_facegraph_printer.h | 4 +- BGL/include/CGAL/boost/graph/IO/PLY.h | 102 ++++++++---------- BGL/test/BGL/test_bgl_read_write.cpp | 27 ++++- .../include/CGAL/IO/STL/STL_reader.h | 2 +- 4 files changed, 75 insertions(+), 60 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/IO/Generic_facegraph_printer.h b/BGL/include/CGAL/boost/graph/IO/Generic_facegraph_printer.h index 82c365890f4..1de06a246bf 100644 --- a/BGL/include/CGAL/boost/graph/IO/Generic_facegraph_printer.h +++ b/BGL/include/CGAL/boost/graph/IO/Generic_facegraph_printer.h @@ -42,14 +42,14 @@ public: const NamedParameters& np) { typedef typename CGAL::GetVertexPointMap::const_type VPM; - typedef typename boost::property_traits::reference Point_ref; + typedef typename boost::property_traits::reference Point_ref; typedef typename Polygon_mesh_processing::GetK::Kernel Kernel; typedef typename Kernel::Vector_3 Vector; typedef typename Kernel::Point_2 Texture; typedef CGAL::Color Color; - typedef typename CGAL::GetVertexPointMap::type VPM; + //typedef typename CGAL::GetVertexPointMap::type VPM; typedef typename internal_np::Lookup_named_param_def< internal_np::vertex_normal_map_t, NamedParameters, diff --git a/BGL/include/CGAL/boost/graph/IO/PLY.h b/BGL/include/CGAL/boost/graph/IO/PLY.h index bd2b6940be7..77cc26f2dbc 100644 --- a/BGL/include/CGAL/boost/graph/IO/PLY.h +++ b/BGL/include/CGAL/boost/graph/IO/PLY.h @@ -20,23 +20,25 @@ #include namespace CGAL { - -template +/*! + *TODO + */ +template bool write_PLY(std::ostream& out, - const FaceGraph& mesh) + const FaceGraph& mesh, + const NamedParameters& np, + const std::string& comments = std::string()) { typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; typedef typename boost::graph_traits::face_descriptor face_descriptor; + typedef typename CGAL::GetInitializedVertexIndexMap::const_type VIMap; + typedef typename GetVertexPointMap::const_type Vpm; + typedef typename Vpm::value_type Point_3; - typedef typename boost::property_map::type::value_type Point_3; - - // @fixme - typedef typename FaceGraph::template Property_map > UV_map; - - UV_map h_uv; - bool has_texture; - boost::tie(h_uv, has_texture) = mesh.template property_map >("h:uv"); + VIMap vim = CGAL::get_initialized_vertex_index_map(mesh, np); + Vpm vpm = parameters::choose_parameter(parameters::get_parameter(np, internal_np::vertex_point), + get_const_property_map(boost::vertex_point, mesh)); if(!out.good()) { @@ -47,33 +49,32 @@ bool write_PLY(std::ostream& out, // Write header out << "ply" << std::endl << ((get_mode(out) == IO::BINARY) ? "format binary_little_endian 1.0" : "format ascii 1.0") << std::endl - << "comment Generated by the CGAL library" << std::endl - << "element vertex " << num_vertices(mesh) << std::endl; + << "comment Generated by the CGAL library" << std::endl; + if(comments != std::string()) + { + std::istringstream iss(comments); + std::string line; + while(getline(iss, line)) + { + if(line != "Generated by the CGAL library") // Avoid repeating the line if multiple savings + out << "comment " << line << std::endl; + } + } + + out << "element vertex " << num_vertices(mesh) << std::endl; IO::internal::output_property_header(out, make_ply_point_writer (CGAL::Identity_property_map())); out << "element face " << num_faces(mesh) << std::endl; + IO::internal::output_property_header( + out, std::make_pair(CGAL::Identity_property_map >(), + PLY_property >("vertex_indices"))); - IO::internal::output_property_header(out, std::make_pair(CGAL::Identity_property_map >(), - PLY_property >("vertex_indices"))); - - if(has_texture) - { - out << "element halfedge " << num_halfedges(mesh) << std::endl; - - IO::internal::output_property_header(out, std::make_pair(CGAL::Identity_property_map(), - PLY_property("source"))); - IO::internal::output_property_header(out, std::make_pair(CGAL::Identity_property_map(), - PLY_property("target"))); - IO::internal::output_property_header(out, std::make_tuple(h_uv, - PLY_property("u"), - PLY_property("v"))); - } out << "end_header" << std::endl; for(vertex_descriptor vd : vertices(mesh)) { - Point_3 p = get(get(CGAL::vertex_point, mesh), vd); + Point_3 p = get(vpm, vd); IO::internal::output_properties(out, &p, make_ply_point_writer (CGAL::Identity_property_map())); } @@ -82,38 +83,29 @@ bool write_PLY(std::ostream& out, { polygon.clear(); for(halfedge_descriptor hd : halfedges_around_face(halfedge(fd, mesh), mesh)) - polygon.push_back(get(get(boost::vertex_index, mesh), target(hd,mesh))); - + polygon.push_back(get(vim, target(hd,mesh))); IO::internal::output_properties(out, &polygon, - std::make_pair(CGAL::Identity_property_map >(), - PLY_property >("vertex_indices"))); - } - - if(has_texture) - { - for(halfedge_descriptor hd : halfedges(mesh)) - { - typedef std::tuple Super_tuple; - Super_tuple t = std::make_tuple(source(hd, mesh),target(hd, mesh), - h_uv[hd].first, - h_uv[hd].second); - - IO::internal::output_properties(out, &t, - std::make_pair(Nth_of_tuple_property_map<0,Super_tuple>(), - PLY_property("source")), - std::make_pair(Nth_of_tuple_property_map<1,Super_tuple>(), - PLY_property("target")), - std::make_pair(Nth_of_tuple_property_map<2,Super_tuple>(), - PLY_property("u")), - std::make_pair(Nth_of_tuple_property_map<3,Super_tuple>(), - PLY_property("v"))); - } + std::make_pair(CGAL::Identity_property_map >(), + PLY_property >("vertex_indices"))); } return out.good(); } -// @fixme add overloads +template +bool write_PLY(std::ostream& out, + const FaceGraph& mesh, + const NamedParameters& np) +{ + return write_PLY(out, mesh, np, ""); +} + +template +bool write_PLY(std::ostream& out, + const FaceGraph& mesh) +{ + return write_PLY(out, mesh, parameters::all_default(), ""); +} } // namespace CGAL diff --git a/BGL/test/BGL/test_bgl_read_write.cpp b/BGL/test/BGL/test_bgl_read_write.cpp index 74ec9ebee8b..49d241c4c6b 100644 --- a/BGL/test/BGL/test_bgl_read_write.cpp +++ b/BGL/test/BGL/test_bgl_read_write.cpp @@ -9,6 +9,8 @@ #include #include +#include + #if defined(CGAL_USE_OPENMESH) #include @@ -195,10 +197,31 @@ bool test_STL() return true; } + +template +bool test_PLY() +{ + FaceGraph fg; + CGAL::make_tetrahedron(Point(0, 0, 0), Point(1, 1, 0), + Point(2, 0, 1), Point(3, 0, 0), fg); + std::ostringstream out; + CGAL::write_PLY(out, fg); + if(out.fail()) + { + std::cerr<<"Tetrahedron writing failed."<1) ? argv[1] : "data/prim.off"; - +/* + //PLY + test_PLY(); + test_PLY(); // OFF test_bgl_read_write(filename); test_bgl_read_write(filename); @@ -214,7 +237,7 @@ int main(int argc, char** argv) return 1; if(!test_gocad()) return 1; - +*/ // STL if(!test_STL()) return 1; diff --git a/Stream_support/include/CGAL/IO/STL/STL_reader.h b/Stream_support/include/CGAL/IO/STL/STL_reader.h index 72a7b1c5828..5112cd1e8a0 100644 --- a/Stream_support/include/CGAL/IO/STL/STL_reader.h +++ b/Stream_support/include/CGAL/IO/STL/STL_reader.h @@ -159,7 +159,7 @@ bool parse_ASCII_STL(std::istream& is, return false; } - return !is.fail(); + return !in_solid; } template