Fix for the polyhedron readOFF with colors

This commit is contained in:
Maxime Gimeno 2016-04-26 10:21:28 +02:00
parent 2f780958d8
commit 31b9e81e6d
4 changed files with 70 additions and 4 deletions

View File

@ -84,13 +84,14 @@ Polyhedron_scan_OFF<HDS>:: operator()( HDS& target) {
for ( i = 0; i < scanner.size_of_vertices(); i++) { for ( i = 0; i < scanner.size_of_vertices(); i++) {
Point p; Point p;
file_scan_vertex( scanner, p); file_scan_vertex( scanner, p);
B.add_vertex( p);
if(scanner.has_colors()) if(scanner.has_colors())
{ {
Color c; Color c;
file_scan_color(scanner, c); file_scan_color(scanner, c);
} }
B.add_vertex( p); else
scanner.skip_to_next_vertex( i); scanner.skip_to_next_vertex( i);
} }
if ( ! m_in || B.error()) { if ( ! m_in || B.error()) {
B.rollback(); B.rollback();

View File

@ -0,0 +1,58 @@
#include <CGAL/Surface_mesh/Surface_mesh.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <cstring>
#include <iostream>
#include <fstream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::Point_3 Point;
typedef CGAL::Surface_mesh<Point> SMesh;
typedef boost::graph_traits<SMesh>::face_descriptor face_descriptor;
typedef boost::graph_traits<SMesh>::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<face_descriptor, CGAL::Color> fcolors =
surface_mesh.property_map<face_descriptor, CGAL::Color >("f:color").first;
SMesh::Property_map<vertex_descriptor, CGAL::Color> vcolors =
surface_mesh.property_map<vertex_descriptor, CGAL::Color >("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;
}

View File

@ -20,7 +20,7 @@ typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
int main(void) int main(void)
{ {
Polyhedron mesh; 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<Polyhedron::Facet_const_handle, double> Facet_double_map; typedef std::map<Polyhedron::Facet_const_handle, double> Facet_double_map;
Facet_double_map internal_map; Facet_double_map internal_map;

View File

@ -6,7 +6,14 @@ bool read_to_polyhedron(const char* file_name, Polyhedron& mesh)
{ {
std::ifstream input(file_name); 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"; std::cerr << "Problem occured while reading off file";
return false; return false;
} }