diff --git a/BGL/test/BGL/data/full.off b/BGL/test/BGL/data/full.off new file mode 100644 index 00000000000..1bbef04a906 --- /dev/null +++ b/BGL/test/BGL/data/full.off @@ -0,0 +1,12 @@ +STCNOFF +4 4 0 + +0 0 0 -1 0 0 255 0 0 0 0 +1 0 0 1 0 0 0 255 0 1 0 +0 1 0 0 1 0 0 0 255 0.5 0.5 +0 0 1 0 0 1 255 0 0 1 1 + +3 0 1 2 255 0 0 +3 3 1 0 0 255 0 +3 3 2 1 0 0 255 +3 3 0 2 255 0 255 diff --git a/BGL/test/BGL/test_bgl_read_write.cpp b/BGL/test/BGL/test_bgl_read_write.cpp index a34305bdba1..7e8084ba305 100644 --- a/BGL/test/BGL/test_bgl_read_write.cpp +++ b/BGL/test/BGL/test_bgl_read_write.cpp @@ -74,7 +74,7 @@ void fill_soup(PointRange& points, PolygonRange& polygons) } template -void test_bgl_read_write(const char* filename) +void test_bgl_OFF(const char* filename) { Mesh sm; std::ifstream in(filename); @@ -82,7 +82,39 @@ void test_bgl_read_write(const char* filename) CGAL::write_OFF(std::cout, sm); } -void test_bgl_soup_off(const char* filename) +//todo check the result. +template +void test_bgl_NCSTOFF() +{ + Mesh fg; + std::ifstream in("data/full.off"); + typedef typename boost::property_map >::type VertexNormalMap; + VertexNormalMap vnm = get(CGAL::dynamic_vertex_property_t(), fg); + + typedef typename boost::property_map >::type VertexColorMap; + VertexColorMap vcm = get(CGAL::dynamic_vertex_property_t(), fg); + + typedef typename boost::property_map >::type VertexTextureMap; + VertexTextureMap vtm = get(CGAL::dynamic_vertex_property_t(), fg); + + typedef typename boost::property_map >::type FaceColorMap; + FaceColorMap fcm = get(CGAL::dynamic_face_property_t(), fg); + + + bool ok = CGAL::read_OFF(in,fg, CGAL::parameters::vertex_normal_map(vnm) + .vertex_color_map(vcm) + .vertex_texture_map(vtm) + .face_color_map(fcm)); + CGAL_assertion(ok); + + ok = CGAL::write_OFF(std::cout, fg, CGAL::parameters::vertex_normal_map(vnm) + .vertex_color_map(vcm) + .vertex_texture_map(vtm) + .face_color_map(fcm)); + CGAL_assertion(ok); +} + +void test_soup_off(const char* filename) { std::vector points; std::vector > polygons; @@ -421,17 +453,24 @@ bool test_PLY(bool binary = false) //todo tests with all NPs and without NP for all tests int main(int argc, char** argv) { - -/* const char* filename=(argc>1) ? argv[1] : "data/prim.off"; +/* + const char* filename=(argc>1) ? argv[1] : "data/prim.off"; // OFF - test_bgl_read_write(filename); - test_bgl_read_write(filename); - test_bgl_read_write(filename); - test_bgl_soup_off(filename); + test_bgl_OFF(filename); + test_bgl_OFF(filename); + test_bgl_OFF(filename); #ifdef CGAL_USE_OPENMESH - test_bgl_read_write(filename); + 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); + // OBJ test_bgl_OBJ(); test_bgl_OBJ(); @@ -441,7 +480,6 @@ int main(int argc, char** argv) test_bgl_OBJ(); #endif - /* //PLY if(!test_PLY()) return 1; diff --git a/Linear_cell_complex/include/CGAL/boost/graph/properties_Linear_cell_complex_for_combinatorial_map.h b/Linear_cell_complex/include/CGAL/boost/graph/properties_Linear_cell_complex_for_combinatorial_map.h index ec796d51725..582d7d956b8 100644 --- a/Linear_cell_complex/include/CGAL/boost/graph/properties_Linear_cell_complex_for_combinatorial_map.h +++ b/Linear_cell_complex/include/CGAL/boost/graph/properties_Linear_cell_complex_for_combinatorial_map.h @@ -17,6 +17,7 @@ #include #include #include +#include #define CGAL_LCC_ARGS unsigned int d_, unsigned int ambient_dim, \ @@ -185,7 +186,6 @@ struct LCC_property_map typedef type const_type; }; }; - template <> struct LCC_property_map { @@ -197,8 +197,6 @@ struct LCC_property_map typedef type const_type; }; }; - - template <> struct LCC_property_map { @@ -210,7 +208,6 @@ struct LCC_property_map typedef type const_type; }; }; - template <> struct LCC_property_map { @@ -237,7 +234,6 @@ get(boost::halfedge_external_index_t, CGAL_LCC_TYPE const&) return typename boost::property_map:: const_type(halfedges(ncmap).begin(), halfedges(ncmap).end(), num_halfedges(ncmap)); } - template typename boost::property_map::const_type get(boost::vertex_external_index_t, CGAL_LCC_TYPE const&) @@ -246,7 +242,6 @@ get(boost::vertex_external_index_t, CGAL_LCC_TYPE const&) return typename boost::property_map:: const_type(vertices(ncmap).begin(), vertices(ncmap).end(), num_vertices(ncmap)); } - template typename boost::property_map::const_type get(boost::edge_external_index_t, CGAL_LCC_TYPE const&) @@ -254,7 +249,6 @@ get(boost::edge_external_index_t, CGAL_LCC_TYPE const&) return typename boost::property_map:: const_type(const_cast(cmap)); } - template typename boost::property_map::const_type get(boost::face_external_index_t, CGAL_LCC_TYPE const&) @@ -273,7 +267,6 @@ get(boost::edge_index_t, CGAL_LCC_TYPE const& cmap) return typename boost::property_map:: const_type(const_cast(cmap)); } - template typename boost::property_map::const_type get(boost::halfedge_index_t, CGAL_LCC_TYPE const& cmap) @@ -281,7 +274,6 @@ get(boost::halfedge_index_t, CGAL_LCC_TYPE const& cmap) return typename boost::property_map:: const_type(const_cast(cmap)); } - template typename boost::property_map::const_type get(boost::vertex_index_t, CGAL_LCC_TYPE const& cmap) @@ -289,7 +281,6 @@ get(boost::vertex_index_t, CGAL_LCC_TYPE const& cmap) return typename boost::property_map:: const_type(const_cast(cmap)); } - template typename boost::property_map::const_type get(boost::face_index_t, CGAL_LCC_TYPE const& cmap) @@ -297,7 +288,6 @@ get(boost::face_index_t, CGAL_LCC_TYPE const& cmap) return typename boost::property_map:: const_type(const_cast(cmap)); } - */ /*template @@ -326,7 +316,6 @@ get(boost::halfedge_external_index_t, CGAL_LCC_TYPE&) return typename boost::property_map:: type(halfedges(cmap).begin(), halfedges(cmap).end(), num_halfedges(cmap)); } - template typename boost::property_map::type get(boost::vertex_external_index_t, CGAL_LCC_TYPE&) @@ -334,7 +323,6 @@ get(boost::vertex_external_index_t, CGAL_LCC_TYPE&) return typename boost::property_map:: type(vertices(cmap).begin(), vertices(cmap).end(), num_vertices(cmap)); } - template typename boost::property_map::type get(boost::edge_external_index_t, CGAL_LCC_TYPE& cmap) @@ -342,8 +330,6 @@ get(boost::edge_external_index_t, CGAL_LCC_TYPE& cmap) return typename boost::property_map:: type(const_cast(cmap)); } - - template typename boost::property_map::type get(boost::face_external_index_t, CGAL_LCC_TYPE&) @@ -402,6 +388,76 @@ struct property_map } // namespace boost +// dynamic property map ambiguity resolution +#define CGAL_LCC_DYNAMIC_PMAP_SPEC(TAG, DESC) \ +namespace boost { \ +template \ + class CMap, \ + class Storage_,\ + class T>\ +struct property_map< \ + CGAL::Linear_cell_complex_for_combinatorial_map,\ + TAG > \ +{\ + typedef CGAL::Linear_cell_complex_for_combinatorial_map\ + LCC;\ + typedef typename boost::graph_traits::DESC DESC;\ + typedef CGAL::internal::Dynamic_property_map type;\ + typedef type const_type;\ +};\ +} \ +\ +namespace CGAL { \ +template \ + class CMap, \ + class Storage_,\ + class T> \ +typename boost::property_map< \ + Linear_cell_complex_for_combinatorial_map, \ + TAG >::const_type \ +get(TAG, const Linear_cell_complex_for_combinatorial_map&) \ +{ \ + typedef Linear_cell_complex_for_combinatorial_map LCC;\ + typedef typename boost::graph_traits::DESC DESC; \ + return internal::Dynamic_property_map();\ +} \ +\ +template \ + class CMap, \ + class Storage_,\ + class T> \ +typename boost::property_map< \ + Linear_cell_complex_for_combinatorial_map, \ + TAG >::type \ +get(TAG, Linear_cell_complex_for_combinatorial_map&) \ +{ \ + typedef Linear_cell_complex_for_combinatorial_map LCC;\ + typedef typename boost::graph_traits::DESC DESC; \ + return internal::Dynamic_property_map();\ +} \ +} + +CGAL_LCC_DYNAMIC_PMAP_SPEC(CGAL::dynamic_vertex_property_t, vertex_descriptor) +CGAL_LCC_DYNAMIC_PMAP_SPEC(CGAL::dynamic_halfedge_property_t, halfedge_descriptor) +CGAL_LCC_DYNAMIC_PMAP_SPEC(CGAL::dynamic_edge_property_t, edge_descriptor) +CGAL_LCC_DYNAMIC_PMAP_SPEC(CGAL::dynamic_face_property_t, face_descriptor) + +#undef CGAL_LCC_DYNAMIC_PMAP_SPEC + + +#undef CGAL_NAME_LCC_ARGS #undef CGAL_LCC_ARGS #undef CGAL_LCC_TYPE diff --git a/Stream_support/include/CGAL/IO/OFF.h b/Stream_support/include/CGAL/IO/OFF.h index 0e70bc19d1d..bab3d078033 100644 --- a/Stream_support/include/CGAL/IO/OFF.h +++ b/Stream_support/include/CGAL/IO/OFF.h @@ -143,7 +143,8 @@ bool read_OFF(std::istream& is, } } - return !is.fail(); + bool res = !is.fail(); + return res; } } // namespace internal diff --git a/Stream_support/include/CGAL/IO/OFF/File_scanner_OFF.h b/Stream_support/include/CGAL/IO/OFF/File_scanner_OFF.h index abfe51bc295..b72389f3d76 100644 --- a/Stream_support/include/CGAL/IO/OFF/File_scanner_OFF.h +++ b/Stream_support/include/CGAL/IO/OFF/File_scanner_OFF.h @@ -3,14 +3,14 @@ // ETH Zurich (Switzerland), // INRIA Sophia-Antipolis (France), // Max-Planck-Institute Saarbruecken (Germany), -// and Tel-Aviv University (Israel). All rights reserved. +// and Tel-Aviv University (Israel). All rights reserved. // // This file is part of CGAL (www.cgal.org); // // $URL$ // $Id$ // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial -// +// // // Author(s) : Lutz Kettner @@ -247,14 +247,79 @@ public: void scan_texture(float& x, float& y, float& w) { - // @ todo - CGAL_assertion(false); + if(has_textures()) + { + if(binary()) + { + float fx, fy; + I_Binary_read_big_endian_float32(m_in, fx); + I_Binary_read_big_endian_float32(m_in, fy); + if(is_homogeneous()) + { + float fw; + I_Binary_read_big_endian_float32(m_in, fw); + x = fx / fw; + y = fy / fw; + } else + { + x = fx; + y = fy; + } + } + else + { + if(is_homogeneous()) + { + float fx, fy, fw; + m_in >> iformat(fx) >> iformat(fy) >> iformat(fw); + x = fx / fw; + y = fy / fw; + } + else + { + m_in >> iformat(x) >> iformat(y); + } + } + } } void scan_texture(double& x, double& y, double& w) { - // @ todo - CGAL_assertion(false); + w=1; + if(has_textures()) + { + if(binary()) + { + float fx, fy; + I_Binary_read_big_endian_float32(m_in, fx); + I_Binary_read_big_endian_float32(m_in, fy); + if(is_homogeneous()) + { + float fw; + I_Binary_read_big_endian_float32(m_in, fw); + x = fx / fw; + y = fy / fw; + } else + { + x = fx; + y = fy; + } + } + else + { + if(is_homogeneous()) + { + float fx, fy, fw; + m_in >> iformat(fx) >> iformat(fy) >> iformat(fw); + x = fx / fw; + y = fy / fw; + } + else + { + m_in >> iformat(x) >> iformat(y); + } + } + } } @@ -635,6 +700,7 @@ public: std::string col; //get the line content + std::streampos position = is.tellg(); std::getline(is, col); //split it into strings std::istringstream iss(col); @@ -663,6 +729,7 @@ public: else rgb[index] = static_cast(atoi(color_info.c_str())); + position += (color_info.length()+ index)*sizeof(char); //index indicates the number of whitespaces read. ++index; if(index == 3) break; @@ -675,7 +742,7 @@ public: //else create the coor with the 3 values; else color = CGAL::Color(rgb[0], rgb[1], rgb[2]); - + is.seekg(position); return color; }