diff --git a/BGL/include/CGAL/boost/graph/IO/GOCAD.h b/BGL/include/CGAL/boost/graph/IO/GOCAD.h index 1f2ed4feff2..00e3c9911d7 100644 --- a/BGL/include/CGAL/boost/graph/IO/GOCAD.h +++ b/BGL/include/CGAL/boost/graph/IO/GOCAD.h @@ -46,7 +46,6 @@ class GOCAD_builder public: GOCAD_builder(std::istream& is_) : Base(is_) { } - // Implementation of the two functions required by the generic builder bool read(std::istream& input, Point_container& points, Face_container& faces) diff --git a/BGL/include/CGAL/boost/graph/IO/OBJ.h b/BGL/include/CGAL/boost/graph/IO/OBJ.h index 59fd1f0b9ac..a97df16a3a5 100644 --- a/BGL/include/CGAL/boost/graph/IO/OBJ.h +++ b/BGL/include/CGAL/boost/graph/IO/OBJ.h @@ -51,7 +51,6 @@ class OBJ_builder public: OBJ_builder(std::istream& is_) : Base(is_) { } - // Implementation of the two functions required by the generic builder bool read(std::istream& input, Point_container& points, Face_container& faces) { return read_OBJ(input, points, faces); diff --git a/BGL/include/CGAL/boost/graph/IO/OFF.h b/BGL/include/CGAL/boost/graph/IO/OFF.h index 590fce8c091..62209d5e232 100644 --- a/BGL/include/CGAL/boost/graph/IO/OFF.h +++ b/BGL/include/CGAL/boost/graph/IO/OFF.h @@ -11,6 +11,9 @@ #ifndef CGAL_BGL_IO_OFF_H #define CGAL_BGL_IO_OFF_H +#include +#include + #include #include #include @@ -32,32 +35,28 @@ namespace CGAL { namespace IO { namespace internal { -namespace read_off_tools { -inline bool is_whitespace(const std::string& s) +// Use CRTP to gain access to the protected members without getters/setters. +template +class OFF_builder + : public Generic_facegraph_builder > { - for(unsigned int i=0; i Self; + typedef Generic_facegraph_builder Base; + + typedef typename Base::Point_container Point_container; + typedef typename Base::Face Face; + typedef typename Base::Face_container Face_container; + +public: + OFF_builder(std::istream& is_) : Base(is_) { } + + bool read(std::istream& input, Point_container& points, Face_container& faces) { - if(s[i] != ' ' && s[i] != '\t') - return false; + return read_OFF(input, points, faces); } +}; - return true; -} - -inline std::string next_non_comment(std::istream& is) -{ - std::string line; - do - { - std::getline(is, line); - } - while(line[0] == '#' || is_whitespace(line)); - - return line; -} - -} // namespace read_off_tools } // namespace internal } // namespace IO @@ -76,80 +75,18 @@ inline std::string next_non_comment(std::istream& is) \pre The data must represent a 2-manifold - \attention The graph `g` is not cleared, and the data from the stream are added. - \see \ref IOStreamOFF */ template -bool read_OFF(std::istream& is, +bool read_OFF(std::istream& in, FaceGraph& g, const CGAL_BGL_NP_CLASS& np) { - typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; - typedef typename boost::graph_traits::vertices_size_type vertices_size_type; - typedef typename boost::graph_traits::face_descriptor face_descriptor; - typedef typename boost::graph_traits::faces_size_type faces_size_type; + typedef typename CGAL::GetVertexPointMap::type VPM; + typedef typename boost::property_traits::value_type Point; - typedef typename CGAL::GetVertexPointMap::type VPM; - typedef typename boost::property_traits::value_type Point; - - using namespace IO::internal::read_off_tools; - - using parameters::choose_parameter; - using parameters::get_parameter; - - VPM vpm = choose_parameter(get_parameter(np, internal_np::vertex_point), - get_property_map(CGAL::vertex_point, g)); - - vertices_size_type nv, nvf; - faces_size_type nf; - int ignore; - - std::string line = next_non_comment(is); - { - std::istringstream iss(line); - std::string off; - iss >> off; - CGAL_assertion( off == "OFF" || off == "COFF"); - } - - line = next_non_comment(is); - { - std::istringstream iss(line); - iss >> nv >> nf >> ignore; - } - - std::vector vertices(nv); - Point p; - - for(vertices_size_type i=0; i> p; - vertices[i] = add_vertex(g); - put(vpm, vertices[i], p); - } - - for(faces_size_type i=0; i> nvf; - std::vector face(nvf); - for(vertices_size_type j=0; j> fvi; - face[j] = vertices[fvi]; - } - - face_descriptor f = CGAL::Euler::add_face(face, g); - if(f == boost::graph_traits::null_face()) - return false; - } - - return true; + IO::internal::OFF_builder builder(in); + return builder(g, np); } /*! diff --git a/Stream_support/include/CGAL/IO/OFF.h b/Stream_support/include/CGAL/IO/OFF.h index ca3203699e6..e33d96bf31f 100644 --- a/Stream_support/include/CGAL/IO/OFF.h +++ b/Stream_support/include/CGAL/IO/OFF.h @@ -23,6 +23,10 @@ namespace CGAL { +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////// +/// Read + /*! * \ingroup IOstreamFunctions * @@ -46,16 +50,16 @@ bool read_OFF(std::istream& in, if(scanner.has_colors()) vcolors.resize(scanner.size_of_vertices()); - for(std::size_t i = 0; i < scanner.size_of_vertices(); ++i) + for(std::size_t i=0; i