diff --git a/BGL/test/BGL/test_bgl_read_write.cpp b/BGL/test/BGL/test_bgl_read_write.cpp index 7e8084ba305..47a242d66f8 100644 --- a/BGL/test/BGL/test_bgl_read_write.cpp +++ b/BGL/test/BGL/test_bgl_read_write.cpp @@ -84,7 +84,7 @@ void test_bgl_OFF(const char* filename) //todo check the result. template -void test_bgl_NCSTOFF() +void test_bgl_OFF_with_np() { Mesh fg; std::ifstream in("data/full.off"); @@ -140,6 +140,40 @@ bool test_bgl_OBJ() return true; } +template +bool test_bgl_OBJ_with_np() +{ + Mesh fg, fg2; + CGAL::make_tetrahedron(Point(0, 0, 0), Point(1, 1, 0), + Point(2, 0, 1), Point(3, 0, 0), fg); + typedef typename boost::property_map >::type VertexNormalMap; + VertexNormalMap vnm = get(CGAL::dynamic_vertex_property_t(), fg); + VertexNormalMap vnm2 = get(CGAL::dynamic_vertex_property_t(), fg2); + + + for(const auto& v : vertices(fg)) + put(vnm, v, Kernel::Vector_3(0.0,1.0,0.0)); + std::ostringstream out; + CGAL::write_OBJ(out, fg, CGAL::parameters::vertex_normal_map(vnm)); + std::istringstream in( out.str()); + + CGAL::read_OBJ(in, fg2, CGAL::parameters::vertex_normal_map(vnm2)); + + CGAL_assertion(num_vertices(fg2) == 4); + CGAL_assertion(num_faces(fg2) == 4); + typename boost::graph_traits::vertex_iterator vit, vit2; + for( vit = vertices(fg).begin(), vit2 = vertices(fg2).begin(); + vit != vertices(fg).end(), vit2 != vertices(fg2).end(); + ++vit, ++vit2) + { + CGAL_assertion(get(vnm, *vit) == get(vnm2, *vit2)); + } + + return true; +} + + + void test_bgl_soup_obj() { std::vector points; @@ -386,7 +420,39 @@ bool test_STL() template -bool test_PLY(bool binary = false) +bool test_bgl_PLY(bool binary = false) +{ + 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; + + if(binary) + CGAL::set_mode(out, CGAL::IO::BINARY); + + CGAL::write_PLY(out, fg, "hello"); + if(out.fail()) + { + std::cerr<<"Tetrahedron writing failed."< +bool test_bgl_PLY_with_np(bool binary) { FaceGraph fg; CGAL::make_tetrahedron(Point(0, 0, 0), Point(1, 1, 0), @@ -450,26 +516,28 @@ bool test_PLY(bool binary = false) return true; } + //todo tests with all NPs and without NP for all tests +//todo Polyhedron read_OFF NPs int main(int argc, char** argv) { -/* const char* filename=(argc>1) ? argv[1] : "data/prim.off"; + /* // OFF test_bgl_OFF(filename); test_bgl_OFF(filename); test_bgl_OFF(filename); #ifdef CGAL_USE_OPENMESH test_bgl_OFF(filename); -#endif*/ - //polyhedron's overload doesn't care for any np that is not vpm - //test_bgl_NCSTOFF(); - test_bgl_NCSTOFF(); - test_bgl_NCSTOFF(); -#ifdef CGAL_USE_OPENMESH - test_bgl_NCSTOFF(); #endif - /* test_soup_off(filename); + //polyhedron's overload doesn't care for any np that is not vpm + test_bgl_OFF_with_np(); + test_bgl_OFF_with_np(); + test_bgl_OFF_with_np(); +#ifdef CGAL_USE_OPENMESH + test_bgl_OFF_with_np(); +#endif + test_soup_off(filename); // OBJ test_bgl_OBJ(); @@ -480,15 +548,34 @@ int main(int argc, char** argv) test_bgl_OBJ(); #endif + test_bgl_OBJ_with_np(); + test_bgl_OBJ_with_np(); + test_bgl_OBJ_with_np(); +#ifdef CGAL_USE_OPENMESH + test_bgl_OBJ_with_np(); +#endif + + //PLY - if(!test_PLY()) + if(!test_bgl_PLY()) return 1; - if(!test_PLY(true)) + if(!test_bgl_PLY(true)) return 1; - if(!test_PLY()) + if(!test_bgl_PLY()) return 1; - if(!test_PLY(true)) + if(!test_bgl_PLY(true)) return 1; + + if(!test_bgl_PLY_with_np(false)) + return 1; + if(!test_bgl_PLY_with_np(true)) + return 1; + if(!test_bgl_PLY_with_np(false)) + return 1; + if(!test_bgl_PLY_with_np(true)) + return 1; + + */ // GOCAD if(!test_gocad()) return 1; @@ -498,8 +585,7 @@ int main(int argc, char** argv) return 1; if(!test_soup_gocad()) return 1; - - +/* // STL if(!test_STL()) return 1; diff --git a/Polyhedron/include/CGAL/IO/Polyhedron_scan_OFF.h b/Polyhedron/include/CGAL/IO/Polyhedron_scan_OFF.h index ed38003078e..5be74b909eb 100644 --- a/Polyhedron/include/CGAL/IO/Polyhedron_scan_OFF.h +++ b/Polyhedron/include/CGAL/IO/Polyhedron_scan_OFF.h @@ -90,10 +90,7 @@ void Polyhedron_scan_OFF:: operator()(HDS& target) Color c; file_scan_color(scanner, c); } - else - { scanner.skip_to_next_vertex(i); - } } if(!m_in || B.error()) diff --git a/Stream_support/include/CGAL/IO/OBJ.h b/Stream_support/include/CGAL/IO/OBJ.h index 7d9995fa2c6..15c19b2f167 100644 --- a/Stream_support/include/CGAL/IO/OBJ.h +++ b/Stream_support/include/CGAL/IO/OBJ.h @@ -86,7 +86,9 @@ bool read_OBJ(std::istream& is, } else if(line[0] == 'v' && line[1] == 'n' && line[2] == ' ') { - std::istringstream iss(line.substr(1)); + std::istringstream iss(line); + std::string dummy; + iss >> dummy; double nx, ny, nz; // @fixme double? if(iss >> nx >> ny >> nz) *vn_out++ = Normal(nx, ny, nz); // @fixme check that every vertex has a normal? diff --git a/Stream_support/include/CGAL/IO/OFF.h b/Stream_support/include/CGAL/IO/OFF.h index bab3d078033..8d7e55abd17 100644 --- a/Stream_support/include/CGAL/IO/OFF.h +++ b/Stream_support/include/CGAL/IO/OFF.h @@ -150,23 +150,6 @@ bool read_OFF(std::istream& is, } // namespace internal } // namespace IO -/*! - * \ingroup IOstreamFunctions - * - * reads the content of `is` into `points` and `polygons`, in the OFF format. - * - * \cgalNamedParamsBegin - \cgalParamBegin{vertex_normal_map} the property map with the normals associated to the vertices of `g`.\cgalParamEnd - - \cgalParamBegin{vertex_color_map} the property map with the colors associated to the vertices of `g`.\cgalParamEnd - - \cgalParamBegin{vertex_texture_map} the property map with the textures associated to the vertices of `g`.\cgalParamEnd - - \cgalParamBegin{face_color_map} the property map with the colors associated to the faces of `g`.\cgalParamEnd - \cgalNamedParamsEnd - * - * \see \ref IOStreamOFF - */ template bool read_OFF(std::istream& is, PointRange& points, @@ -187,23 +170,6 @@ bool read_OFF(std::istream& is, CGAL::Emptyset_iterator())); } -/*! - * \ingroup IOstreamFunctions - * - * reads the content of the file `fname` into `points` and `polygons`, in the OFF format. - * - * * \cgalNamedParamsBegin - \cgalParamBegin{vertex_normal_map} the property map with the normals associated to the vertices of `g`.\cgalParamEnd - - \cgalParamBegin{vertex_color_map} the property map with the colors associated to the vertices of `g`.\cgalParamEnd - - \cgalParamBegin{vertex_texture_map} the property map with the textures associated to the vertices of `g`.\cgalParamEnd - - \cgalParamBegin{face_color_map} the property map with the colors associated to the faces of `g`.\cgalParamEnd - \cgalNamedParamsEnd - * - * \see \ref IOStreamOFF - */ template bool read_OFF(const char* fname, PointRange& points, @@ -220,12 +186,28 @@ bool read_OFF(const std::string& fname, PointRange& points, PolygonRange& polygo return read_OFF(fname.c_str(), points, polygons, np); } +/*! + * \ingroup IOstreamFunctions + * + * reads the content of `is` into `points` and `polygons`, in the OFF format. + * + * + * \see \ref IOStreamOFF + */ template bool read_OFF(std::istream& is, PointRange& points, PolygonRange& polygons) { return read_OFF(is, points, polygons, parameters::all_default()); } +/*! + * \ingroup IOstreamFunctions + * + * reads the content of the file `fname` into `points` and `polygons`, in the OFF format. + * + * + * \see \ref IOStreamOFF + */ template bool read_OFF(const char* fname, PointRange& points, PolygonRange& polygons) { @@ -242,13 +224,7 @@ bool read_OFF(const std::string& fname, PointRange& points, PolygonRange& polygo //////////////////////////////////////////////////////////////////////////////////////////////////// /// Write -/*! - * \ingroup IOstreamFunctions - * - * writes the content of `points` and `polygons` in `out`, in the OFF format. - * - * \see \ref IOStreamOFF - */ + template bool write_OFF(std::ostream& os, const PointRange& points, @@ -259,6 +235,13 @@ bool write_OFF(std::ostream& os, return writer(points, polygons); } +/*! + * \ingroup IOstreamFunctions + * + * writes the content of `points` and `polygons` in `out`, in the OFF format. + * + * \see \ref IOStreamOFF + */ template bool write_OFF(std::ostream& os, const PointRange& points, @@ -267,13 +250,6 @@ bool write_OFF(std::ostream& os, return write_OFF(os, points, polygons, parameters::all_default()); } -/*! - * \ingroup IOstreamFunctions - * - * writes the content of `points` and `polygons` in the file `fname`, in the OFF format. - * - * \see \ref IOStreamOFF - */ template bool write_OFF(const char* fname, const PointRange& points, @@ -285,6 +261,13 @@ bool write_OFF(const char* fname, return writer(points, polygons, np); } +/*! + * \ingroup IOstreamFunctions + * + * writes the content of `points` and `polygons` in the file `fname`, in the OFF format. + * + * \see \ref IOStreamOFF + */ template bool write_OFF(const char* fname, const PointRange& points,