diff --git a/Linear_cell_complex/include/CGAL/Linear_cell_complex/IO/VTK.h b/Linear_cell_complex/include/CGAL/Linear_cell_complex/IO/VTK.h index 0a70ee38e22..2805f904d8d 100644 --- a/Linear_cell_complex/include/CGAL/Linear_cell_complex/IO/VTK.h +++ b/Linear_cell_complex/include/CGAL/Linear_cell_complex/IO/VTK.h @@ -423,6 +423,11 @@ bool read_lcc_from_vtk_ascii(std::istream& is, LCC& alcc, { alcc.erase_vertex_attribute(itv); } } + if(vertex_scalars!=nullptr) + { vertex_scalars->clear(); } + if(cell_scalars!=nullptr) + { cell_scalars->clear(); } + while(std::getline(is, line)) { // Read POINT_DATA scalars if present diff --git a/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_vtk_io_test.cpp b/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_vtk_io_test.cpp index 6587b9e928b..10f825f0435 100644 --- a/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_vtk_io_test.cpp +++ b/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_vtk_io_test.cpp @@ -6,62 +6,197 @@ typedef CGAL::Linear_cell_complex_for_combinatorial_map<3, 3> LCC; -int main() { +bool test_file(const char* filename) +{ LCC lcc1, lcc2; std::vector vertex_scalars1, vertex_scalars2; std::vector volume_scalars1, volume_scalars2; - const char* filename = "data/beam-with-mixed-cells.vtk"; - - - bool ok_read1 = CGAL::IO::read_VTK(lcc1, filename, - &vertex_scalars1, &volume_scalars1); - assert(ok_read1); - - - std::size_t nb_vertices = 0; - for(auto itv = lcc1.vertex_attributes().begin(), itvend = lcc1.vertex_attributes().end(); itv != itvend; ++itv) - ++nb_vertices; - if(vertex_scalars1.size() != nb_vertices) { - vertex_scalars1.resize(nb_vertices); - for(std::size_t i=0;i(i); + bool res=CGAL::IO::read_VTK(lcc1, filename); + if(!res) + { + std::cerr<<"[ERROR] LCC_vtk_io_test error read_VTK in test_file"<().begin(), - itvolend = lcc1.one_dart_per_cell<3>().end(); itvol != itvolend; ++itvol) - ++nb_volumes; + std::size_t nb_vertices=lcc1.number_of_vertex_attributes(); + vertex_scalars1.resize(nb_vertices); + for(std::size_t i=0;i(i); } - if(volume_scalars1.size() != nb_volumes) { - volume_scalars1.clear(); - volume_scalars1.reserve(nb_volumes); - for(auto itvol = lcc1.one_dart_per_cell<3>().begin(), - itvolend = lcc1.one_dart_per_cell<3>().end(); itvol != itvolend; ++itvol) { - auto d = lcc1.dart_descriptor(*itvol); - std::size_t nbv = lcc1.template one_dart_per_incident_cell<0,3>(d).size(); - volume_scalars1.push_back(nbv); - } + std::size_t nb_volumes=0; + for(auto itvol=lcc1.one_dart_per_cell<3>().begin(), + itvolend=lcc1.one_dart_per_cell<3>().end(); itvol!=itvolend; ++itvol) + { ++nb_volumes; } + + volume_scalars1.reserve(nb_volumes); + for(auto itvol=lcc1.one_dart_per_cell<3>().begin(), + itvolend=lcc1.one_dart_per_cell<3>().end(); itvol!=itvolend; ++itvol) + { + std::size_t nbv=lcc1.template one_dart_per_incident_cell<0,3>(itvol).size(); + volume_scalars1.push_back(nbv); } - - bool ok_write = CGAL::IO::write_VTK(lcc1, filename, - &vertex_scalars1, &volume_scalars1); - assert(ok_write); + res=CGAL::IO::write_VTK(lcc1, "output.vtk", + &vertex_scalars1, &volume_scalars1); + if(!res) + { + std::cerr<<"[ERROR] LCC_vtk_io_test error write_VTK in test_file"<(lcc2, filename, - &vertex_scalars2, &volume_scalars2); - assert(ok_read2); + res=CGAL::IO::read_VTK(lcc2, "output.vtk", + &vertex_scalars2, &volume_scalars2); + if(!res) + { + std::cerr<<"[ERROR] LCC_vtk_io_test error read_VTK 2 in test_file"< vertex_scalars; + std::vector volume_scalars; + + /// Read the last file generated by test_file("data/beam-with-mixed-cells.vtk") + /// i.e. beam-with-mixed-cells.vtk with point and cells scalars. + if(!CGAL::IO::read_VTK(lcc, "output.vtk", + &vertex_scalars, &volume_scalars) || + vertex_scalars.size()!=719 || volume_scalars.size()!=615) + { + std::cerr<<"[ERROR] LCC_vtk_io_test error read_VTK in test_different_scalars"<