From 31b9e81e6d31e33d9418b8ff413152150c8ffef7 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Tue, 26 Apr 2016 10:21:28 +0200 Subject: [PATCH] Fix for the polyhedron readOFF with colors --- .../include/CGAL/IO/Polyhedron_scan_OFF.h | 5 +- .../test/Surface_mesh/sm_open_colored_off.cpp | 58 +++++++++++++++++++ .../Fast_sdf_calculation_test.cpp | 2 +- .../test/Surface_mesh_segmentation/Utils.h | 9 ++- 4 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 Surface_mesh/test/Surface_mesh/sm_open_colored_off.cpp diff --git a/Polyhedron_IO/include/CGAL/IO/Polyhedron_scan_OFF.h b/Polyhedron_IO/include/CGAL/IO/Polyhedron_scan_OFF.h index 399c2daef77..a04b4ba2ee9 100644 --- a/Polyhedron_IO/include/CGAL/IO/Polyhedron_scan_OFF.h +++ b/Polyhedron_IO/include/CGAL/IO/Polyhedron_scan_OFF.h @@ -84,13 +84,14 @@ Polyhedron_scan_OFF:: operator()( HDS& target) { for ( i = 0; i < scanner.size_of_vertices(); i++) { Point p; file_scan_vertex( scanner, p); + B.add_vertex( p); if(scanner.has_colors()) { Color c; file_scan_color(scanner, c); } - B.add_vertex( p); - scanner.skip_to_next_vertex( i); + else + scanner.skip_to_next_vertex( i); } if ( ! m_in || B.error()) { B.rollback(); diff --git a/Surface_mesh/test/Surface_mesh/sm_open_colored_off.cpp b/Surface_mesh/test/Surface_mesh/sm_open_colored_off.cpp new file mode 100644 index 00000000000..b76191918d7 --- /dev/null +++ b/Surface_mesh/test/Surface_mesh/sm_open_colored_off.cpp @@ -0,0 +1,58 @@ +#include +#include +#include +#include +#include +typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; +typedef Kernel::Point_3 Point; +typedef CGAL::Surface_mesh SMesh; +typedef boost::graph_traits::face_descriptor face_descriptor; +typedef boost::graph_traits::vertex_descriptor vertex_descriptor; + + +void OpenOFF(int i) +{ + std::string path; + switch(i) + { + case 1: + path = "test1.off"; + break; + case 2: + path = "test2.off"; + break; + case 3: + path = "test3.off"; + break; + } + std::ifstream in(path.c_str()); + SMesh surface_mesh; + in >> surface_mesh; + CGAL_assertion(in && !surface_mesh.is_empty()); + + + SMesh::Property_map fcolors = + surface_mesh.property_map("f:color").first; + + SMesh::Property_map vcolors = + surface_mesh.property_map("v:color").first; + CGAL::Color c = fcolors[*(surface_mesh.faces().begin())]; + CGAL_assertion(c== CGAL::Color(229,0,0)); + c = fcolors[*(--surface_mesh.faces().end())]; + CGAL_assertion(c== CGAL::Color(0,0,229)); + + c = vcolors[*(surface_mesh.vertices().begin())]; + CGAL_assertion((c== CGAL::Color(229,0,0))); + c = vcolors[*(--surface_mesh.vertices().end())]; + CGAL_assertion((c== CGAL::Color(0,0,229))); +} + + +int main() +{ + OpenOFF(1); + OpenOFF(2); + OpenOFF(3); + std::cerr << "done" << std::endl; + return 0; +} diff --git a/Surface_mesh_segmentation/test/Surface_mesh_segmentation/Fast_sdf_calculation_test.cpp b/Surface_mesh_segmentation/test/Surface_mesh_segmentation/Fast_sdf_calculation_test.cpp index 3b1c54d11cd..e7096d3aef6 100644 --- a/Surface_mesh_segmentation/test/Surface_mesh_segmentation/Fast_sdf_calculation_test.cpp +++ b/Surface_mesh_segmentation/test/Surface_mesh_segmentation/Fast_sdf_calculation_test.cpp @@ -20,7 +20,7 @@ typedef CGAL::Polyhedron_3 Polyhedron; int main(void) { Polyhedron mesh; - if( !read_to_polyhedron("./data/cactus.off", mesh) ) { return 1; } + if( !read_to_polyhedron("../Surface_mesh_segmentation/data/cactus.off", mesh) ) { return 1; } typedef std::map Facet_double_map; Facet_double_map internal_map; diff --git a/Surface_mesh_segmentation/test/Surface_mesh_segmentation/Utils.h b/Surface_mesh_segmentation/test/Surface_mesh_segmentation/Utils.h index 62f47f16a55..5b4e879a259 100644 --- a/Surface_mesh_segmentation/test/Surface_mesh_segmentation/Utils.h +++ b/Surface_mesh_segmentation/test/Surface_mesh_segmentation/Utils.h @@ -6,7 +6,14 @@ bool read_to_polyhedron(const char* file_name, Polyhedron& mesh) { std::ifstream input(file_name); - if ( !input || !(input >> mesh) || mesh.empty() ){ + bool ok = true; + if(!input) + ok = false; + else if(!(input>>mesh)) + ok = false; + else if(mesh.empty()) + ok = false; + if ( !ok ){ std::cerr << "Problem occured while reading off file"; return false; }