diff --git a/Surface_mesh/test/Surface_mesh/sm_ply_io.cpp b/Surface_mesh/test/Surface_mesh/sm_ply_io.cpp index f2889f912bd..ddcda054507 100644 --- a/Surface_mesh/test/Surface_mesh/sm_ply_io.cpp +++ b/Surface_mesh/test/Surface_mesh/sm_ply_io.cpp @@ -43,5 +43,92 @@ int main() // CGAL::IO::set_binary_mode(out); CGAL::IO::write_PLY(out, mesh); + // extra test for read/write of properties + mesh = SMesh(); + in.close(); + in.open(CGAL::data_file_path("meshes/colored_tetra.ply")); + CGAL::IO::read_PLY(in, mesh); + float fvalue=1001; + auto v_uvmap = mesh.add_property_map>("v:uv").first; + auto v_umap = mesh.add_property_map("v:u").first; + auto v_vmap = mesh.add_property_map("v:v").first; + for (SMesh::Vertex_index v : vertices(mesh)) + { + v_uvmap[v]={fvalue, -fvalue}; + v_umap[v]=fvalue; + v_vmap[v]=-fvalue; + ++fvalue; + } + + double dvalue=2001; + auto f_uvmap = mesh.add_property_map>("f:uv").first; + auto f_umap = mesh.add_property_map("f:u").first; + auto f_vmap = mesh.add_property_map("f:v").first; + for (SMesh::Face_index f : faces(mesh)) + { + f_uvmap[f]={dvalue, -dvalue}; + f_umap[f]=dvalue; + f_vmap[f]=-dvalue; + ++dvalue; + } + + out.close(); + out.open("out_ascii.ply"); + CGAL::IO::write_PLY(out, mesh); + out.close(); + out.open("out_binary.ply"); + CGAL::IO::set_binary_mode(out); + CGAL::IO::write_PLY(out, mesh); + out.close(); + mesh.clear(); + + const std::array fnames = {"out_ascii.ply", "out_binary.ply"}; + for (std::string fn : fnames) + { + std::cout << "Reading " << fn << "\n"; + in.close(); + in.open(fn); + SMesh mesh_bis; + CGAL::IO::read_PLY(in, mesh_bis); + + assert((mesh_bis.property_map("v:u").second)); + assert((mesh_bis.property_map("v:v").second)); + assert((mesh_bis.property_map>("v:uv").second)); + + v_uvmap = mesh_bis.property_map>("v:uv").first; + v_umap = mesh_bis.property_map("v:u").first; + v_vmap = mesh_bis.property_map("v:v").first; + + fvalue=1001; + for (SMesh::Vertex_index v : vertices(mesh_bis)) + { + assert(v_uvmap[v].size()==2); + assert(v_uvmap[v][0]==fvalue); + assert(v_uvmap[v][1]==-fvalue); + assert(v_umap[v]==fvalue); + assert(v_vmap[v]==-fvalue); + ++fvalue; + } + + assert((mesh_bis.property_map("f:u").second)); + assert((mesh_bis.property_map("f:v").second)); + assert((mesh_bis.property_map>("f:uv").second)); + + f_uvmap = mesh_bis.property_map>("f:uv").first; + f_umap = mesh_bis.property_map("f:u").first; + f_vmap = mesh_bis.property_map("f:v").first; + + dvalue=2001; + for (SMesh::Face_index f : faces(mesh_bis)) + { + assert(f_uvmap[f].size()==2); + assert(f_uvmap[f][0]==dvalue); + assert(f_uvmap[f][1]==-dvalue); + assert(f_umap[f]==dvalue); + assert(f_vmap[f]==-dvalue); + ++dvalue; + } + } + return 0; }