From 5373b35b9f90182727171bf2e2c9299638775ab8 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Tue, 6 Aug 2019 16:11:56 +0200 Subject: [PATCH 01/28] Start regrouping in Stream Support and robustify readers. --- Polyhedron_IO/include/CGAL/IO/OBJ_reader.h | 53 +- Polyhedron_IO/include/CGAL/IO/OFF_reader.h | 132 +--- Polyhedron_IO/include/CGAL/IO/PLY_reader.h | 327 +-------- Polyhedron_IO/include/CGAL/IO/PLY_writer.h | 149 +--- .../include/CGAL/IO/Polyhedron_scan_OFF.h | 134 +--- Polyhedron_IO/include/CGAL/IO/STL_reader.h | 352 +-------- Polyhedron_IO/include/CGAL/IO/STL_writer.h | 79 +- Polyhedron_IO/include/CGAL/IO/print_OFF.h | 77 +- .../include/CGAL/IO/print_wavefront.h | 31 +- Polyhedron_IO/include/CGAL/IO/scan_OFF.h | 46 +- .../include/CGAL/IO/File_header_OFF.h | 98 +-- .../include/CGAL/IO/File_header_OFF_impl.h | 406 ----------- .../CGAL/IO/File_header_extended_OFF.h | 138 ---- .../CGAL/IO/File_header_extended_OFF_impl.h | 213 ------ .../include/CGAL/IO/File_scanner_OFF.h | 677 +----------------- .../include/CGAL/IO/File_scanner_OFF_impl.h | 134 ---- .../include/CGAL/IO/File_writer_OFF.h | 88 +-- .../include/CGAL/IO/File_writer_OFF_impl.h | 57 -- .../include/CGAL/IO/File_writer_wavefront.h | 40 +- .../CGAL/IO/File_writer_wavefront_impl.h | 58 -- Stream_support/include/CGAL/IO/Scanner_OFF.h | 308 -------- Stream_support/include/CGAL/IO/WKT.h | 79 +- .../include/CGAL/IO/generic_copy_OFF.h | 78 +- .../test/Stream_support/test_read_WKT.cpp | 18 +- 24 files changed, 159 insertions(+), 3613 deletions(-) delete mode 100644 Stream_support/include/CGAL/IO/File_header_OFF_impl.h delete mode 100644 Stream_support/include/CGAL/IO/File_header_extended_OFF.h delete mode 100644 Stream_support/include/CGAL/IO/File_header_extended_OFF_impl.h delete mode 100644 Stream_support/include/CGAL/IO/File_scanner_OFF_impl.h delete mode 100644 Stream_support/include/CGAL/IO/File_writer_OFF_impl.h delete mode 100644 Stream_support/include/CGAL/IO/File_writer_wavefront_impl.h delete mode 100644 Stream_support/include/CGAL/IO/Scanner_OFF.h diff --git a/Polyhedron_IO/include/CGAL/IO/OBJ_reader.h b/Polyhedron_IO/include/CGAL/IO/OBJ_reader.h index 1e1d874b0cf..44de7421b66 100644 --- a/Polyhedron_IO/include/CGAL/IO/OBJ_reader.h +++ b/Polyhedron_IO/include/CGAL/IO/OBJ_reader.h @@ -20,54 +20,13 @@ #ifndef CGAL_IO_OBJ_READER_H #define CGAL_IO_OBJ_READER_H -#include -#include -#include +#include +#define CGAL_DEPRECATED_HEADER "" +#define CGAL_REPLACEMENT_HEADER "" +#include +#include +#include -namespace CGAL { - -template -bool -read_OBJ( std::istream& input, - std::vector &points, - std::vector > &faces) -{ - Point_3 p; - std::string line; - while(getline(input, line)) { - if(line[0] == 'v' && line[1] == ' ') { - std::istringstream iss(line.substr(1)); - iss >> p; - if(!iss) - return false; - points.push_back(p); - } - else if(line[0] == 'f') { - std::istringstream iss(line.substr(1)); - int i; - faces.push_back( std::vector() ); - while(iss >> i) - { - if(i < 1) - { - faces.back().push_back(points.size()+i);//negative indices are relative references - } - else { - faces.back().push_back(i-1); - } - iss.ignore(256, ' '); - } - } - else - { - //std::cerr<<"ERROR : Cannnot read line beginning with "< -#include -#include - -#include -#include -#include -#include -#include - -namespace CGAL { - - template - bool - read_OFF( std::istream& in, - std::vector< Point_3 >& points, - std::vector< Polygon_3 >& polygons, - bool /* verbose */ = false) - { - CGAL::File_scanner_OFF scanner(in); - - points.resize(scanner.size_of_vertices()); - polygons.resize(scanner.size_of_facets()); - for (std::size_t i = 0; i < scanner.size_of_vertices(); ++i) { - double x, y, z, w; - scanner.scan_vertex( x, y, z, w); - CGAL_assertion(w!=0); - IO::internal::fill_point( x/w, y/w, z/w, points[i] ); - scanner.skip_to_next_vertex( i); - } - if(!in) - return false; - - for (std::size_t i = 0; i < scanner.size_of_facets(); ++i) { - std::size_t no; - - scanner.scan_facet( no, i); - IO::internal::resize(polygons[i], no); - for(std::size_t j = 0; j < no; ++j) { - std::size_t id; - scanner.scan_facet_vertex_index(id, i); - if(id < scanner.size_of_vertices()) - { - polygons[i][j] = id; - } - else - return false; - } - } - return in.good(); - } - - template - bool - read_OFF( std::istream& in, - std::vector< Point_3 >& points, - std::vector< Polygon_3 >& polygons, - std::vector& fcolors, - std::vector& vcolors, - bool /* verbose */ = false) - { - CGAL::File_scanner_OFF scanner(in); - points.resize(scanner.size_of_vertices()); - polygons.resize(scanner.size_of_facets()); - if(scanner.has_colors()) - vcolors.resize(scanner.size_of_vertices()); - for (std::size_t i = 0; i < scanner.size_of_vertices(); ++i) { - double x, y, z, w; - scanner.scan_vertex( x, y, z, w); - CGAL_assertion(w!=0); - IO::internal::fill_point( x/w, y/w, z/w, points[i] ); - if(scanner.has_colors()) - { - unsigned char r=0, g=0, b=0; - scanner.scan_color( r, g, b); - vcolors[i] = Color_rgb(r,g,b); - } - else - scanner.skip_to_next_vertex(i); - if(!in) - return false; - } - bool has_fcolors = false; - for (std::size_t i = 0; i < scanner.size_of_facets(); ++i) { - std::size_t no; - scanner.scan_facet( no, i); - if(!in) - return false; - IO::internal::resize(polygons[i], no); - for(std::size_t j = 0; j < no; ++j) { - std::size_t id; - scanner.scan_facet_vertex_index(id, i); - if(id < scanner.size_of_vertices()) - { - polygons[i][j] = id; - } - else - { - return false; - } - } - - if(i==0) - { - std::string col; - std::getline(in, col); - std::istringstream iss(col); - char ci =' '; - if(iss >> ci){ - has_fcolors = true; - fcolors.resize(scanner.size_of_facets()); - std::istringstream iss2(col); - fcolors[i] = scanner.get_color_from_line(iss2); - } - } - else if(has_fcolors) - { - unsigned char r=0, g=0, b=0; - scanner.scan_color(r,g,b); - fcolors[i] = Color_rgb(r,g,b); - } - } - return in.good(); - } - -} // namespace CGAL - +#define CGAL_DEPRECATED_HEADER "" +#define CGAL_REPLACEMENT_HEADER "" +#include +#include +#include #endif // CGAL_IO_OFF_READER_H diff --git a/Polyhedron_IO/include/CGAL/IO/PLY_reader.h b/Polyhedron_IO/include/CGAL/IO/PLY_reader.h index 7e631d2316b..8538d3e6750 100644 --- a/Polyhedron_IO/include/CGAL/IO/PLY_reader.h +++ b/Polyhedron_IO/include/CGAL/IO/PLY_reader.h @@ -22,327 +22,12 @@ #include -namespace CGAL{ +#include - namespace internal - { - template - bool - read_PLY_faces (std::istream& in, - internal::PLY::PLY_element& element, - std::vector< Polygon_3 >& polygons, - std::vector< Color_rgb >& fcolors, - const char* vertex_indices_tag) - { - bool has_colors = false; - std::string rtag = "r", gtag = "g", btag = "b"; - if ((element.has_property("red") || element.has_property("r")) && - (element.has_property("green") || element.has_property("g")) && - (element.has_property("blue") || element.has_property("b"))) - { - has_colors = true; - if (element.has_property("red")) - { - rtag = "red"; gtag = "green"; btag = "blue"; - } - } - - for (std::size_t j = 0; j < element.number_of_items(); ++ j) - { - for (std::size_t k = 0; k < element.number_of_properties(); ++ k) - { - internal::PLY::PLY_read_number* property = element.property(k); - property->get (in); - - if (in.fail()) - return false; - } - - std::tuple, boost::uint8_t, boost::uint8_t, boost::uint8_t> new_face; - - if (has_colors) - { - PLY::process_properties (element, new_face, - std::make_pair (CGAL::make_nth_of_tuple_property_map<0>(new_face), - PLY_property >(vertex_indices_tag)), - std::make_pair (CGAL::make_nth_of_tuple_property_map<1>(new_face), - PLY_property(rtag.c_str())), - std::make_pair (CGAL::make_nth_of_tuple_property_map<2>(new_face), - PLY_property(gtag.c_str())), - std::make_pair (CGAL::make_nth_of_tuple_property_map<3>(new_face), - PLY_property(btag.c_str()))); - - fcolors.push_back (Color_rgb (get<1>(new_face), get<2>(new_face), get<3>(new_face))); - } - else - PLY::process_properties (element, new_face, - std::make_pair (CGAL::make_nth_of_tuple_property_map<0>(new_face), - PLY_property >(vertex_indices_tag))); - - polygons.push_back (Polygon_3(get<0>(new_face).size())); - for (std::size_t i = 0; i < get<0>(new_face).size(); ++ i) - polygons.back()[i] = std::size_t(get<0>(new_face)[i]); - } - - return true; - } - - } - - - template - bool - read_PLY( std::istream& in, - std::vector< Point_3 >& points, - std::vector< Polygon_3 >& polygons, - bool /* verbose */ = false) - { - if(!in) - { - std::cerr << "Error: cannot open file" << std::endl; - return false; - } - - internal::PLY::PLY_reader reader; - - if (!(reader.init (in))) - { - in.setstate(std::ios::failbit); - return false; - } - - for (std::size_t i = 0; i < reader.number_of_elements(); ++ i) - { - internal::PLY::PLY_element& element = reader.element(i); - - if (element.name() == "vertex" || element.name() == "vertices") - { - for (std::size_t j = 0; j < element.number_of_items(); ++ j) - { - for (std::size_t k = 0; k < element.number_of_properties(); ++ k) - { - internal::PLY::PLY_read_number* property = element.property(k); - property->get (in); - - if (in.fail()) - return false; - } - - Point_3 new_vertex; - - internal::PLY::process_properties (element, new_vertex, - make_ply_point_reader (CGAL::Identity_property_map())); - - points.push_back (get<0>(new_vertex)); - } - } - else if (element.name() == "face" || element.name() == "faces") - { - std::vector dummy; - - if (element.has_property > ("vertex_indices")) - internal::read_PLY_faces (in, element, polygons, dummy, "vertex_indices"); - else if (element.has_property > ("vertex_indices")) - internal::read_PLY_faces (in, element, polygons, dummy, "vertex_indices"); - else if (element.has_property > ("vertex_index")) - internal::read_PLY_faces (in, element, polygons, dummy, "vertex_index"); - else if (element.has_property > ("vertex_index")) - internal::read_PLY_faces (in, element, polygons, dummy, "vertex_index"); - else - { - std::cerr << "Error: can't find vertex indices in PLY input" << std::endl; - return false; - } - } - else // Read other elements and ignore - { - for (std::size_t j = 0; j < element.number_of_items(); ++ j) - { - for (std::size_t k = 0; k < element.number_of_properties(); ++ k) - { - internal::PLY::PLY_read_number* property = element.property(k); - property->get (in); - - if (in.fail()) - return false; - } - } - } - } - - return !in.bad(); - } - - template - bool - read_PLY( std::istream& in, - std::vector< Point_3 >& points, - std::vector< Polygon_3 >& polygons, - std::vector >& hedges, - std::vector& fcolors, - std::vector& vcolors, - std::vector >& huvs, - bool /* verbose */ = false) - { - if(!in) - { - std::cerr << "Error: cannot open file" << std::endl; - return false; - } - internal::PLY::PLY_reader reader; - - if (!(reader.init (in))) - { - in.setstate(std::ios::failbit); - return false; - } - for (std::size_t i = 0; i < reader.number_of_elements(); ++ i) - { - internal::PLY::PLY_element& element = reader.element(i); - - if (element.name() == "vertex" || element.name() == "vertices") - { - bool has_colors = false; - std::string rtag = "r", gtag = "g", btag = "b"; - if ((element.has_property("red") || element.has_property("r")) && - (element.has_property("green") || element.has_property("g")) && - (element.has_property("blue") || element.has_property("b"))) - { - has_colors = true; - if (element.has_property("red")) - { - rtag = "red"; gtag = "green"; btag = "blue"; - } - } - - for (std::size_t j = 0; j < element.number_of_items(); ++ j) - { - for (std::size_t k = 0; k < element.number_of_properties(); ++ k) - { - internal::PLY::PLY_read_number* property = element.property(k); - property->get (in); - - if (in.fail()) - return false; - } - - std::tuple new_vertex; - - if (has_colors) - { - internal::PLY::process_properties (element, new_vertex, - make_ply_point_reader (CGAL::make_nth_of_tuple_property_map<0>(new_vertex)), - std::make_pair (CGAL::make_nth_of_tuple_property_map<1>(new_vertex), - PLY_property(rtag.c_str())), - std::make_pair (CGAL::make_nth_of_tuple_property_map<2>(new_vertex), - PLY_property(gtag.c_str())), - std::make_pair (CGAL::make_nth_of_tuple_property_map<3>(new_vertex), - PLY_property(btag.c_str()))); - - vcolors.push_back (Color_rgb (get<1>(new_vertex), get<2>(new_vertex), get<3>(new_vertex))); - } - else - internal::PLY::process_properties (element, new_vertex, - make_ply_point_reader (CGAL::make_nth_of_tuple_property_map<0>(new_vertex))); - - points.push_back (get<0>(new_vertex)); - } - } - else if (element.name() == "face" || element.name() == "faces") - { - if (element.has_property > ("vertex_indices")) - internal::read_PLY_faces (in, element, polygons, fcolors, "vertex_indices"); - else if (element.has_property > ("vertex_indices")) - internal::read_PLY_faces (in, element, polygons, fcolors, "vertex_indices"); - else if (element.has_property > ("vertex_index")) - internal::read_PLY_faces (in, element, polygons, fcolors, "vertex_index"); - else if (element.has_property > ("vertex_index")) - internal::read_PLY_faces (in, element, polygons, fcolors, "vertex_index"); - else - { - std::cerr << "Error: can't find vertex indices in PLY input" << std::endl; - return false; - } - } - else if(element.name() == "halfedge" ) - { - bool has_uv = false; - std::string stag = "source", ttag = "target", utag = "u", vtag = "v"; - if ( element.has_property("source") && - element.has_property("target") && - element.has_property("u") && - element.has_property("v")) - { - has_uv = true; - } - cpp11::tuple new_hedge; - for (std::size_t j = 0; j < element.number_of_items(); ++ j) - { - for (std::size_t k = 0; k < element.number_of_properties(); ++ k) - { - internal::PLY::PLY_read_number* property = element.property(k); - property->get (in); - - if (in.eof()) - return false; - } - - if (has_uv) - { - internal::PLY::process_properties (element, new_hedge, - std::make_pair (CGAL::make_nth_of_tuple_property_map<0>(new_hedge), - PLY_property(stag.c_str())), - std::make_pair (CGAL::make_nth_of_tuple_property_map<1>(new_hedge), - PLY_property(ttag.c_str())), - std::make_pair (CGAL::make_nth_of_tuple_property_map<2>(new_hedge), - PLY_property(utag.c_str())), - std::make_pair (CGAL::make_nth_of_tuple_property_map<3>(new_hedge), - PLY_property(vtag.c_str()))); - hedges.push_back (std::make_pair(get<0>(new_hedge), get<1>(new_hedge))); - huvs.push_back (std::make_pair(get<2>(new_hedge), get<3>(new_hedge))); - } - else - internal::PLY::process_properties (element, new_hedge, - std::make_pair(CGAL::make_nth_of_tuple_property_map<0>(new_hedge), - PLY_property(stag.c_str())), - std::make_pair(CGAL::make_nth_of_tuple_property_map<1>(new_hedge), - PLY_property(ttag.c_str())) - ); - } - } - else // Read other elements and ignore - { - for (std::size_t j = 0; j < element.number_of_items(); ++ j) - { - for (std::size_t k = 0; k < element.number_of_properties(); ++ k) - { - internal::PLY::PLY_read_number* property = element.property(k); - property->get (in); - if (in.fail()) - return false; - } - } - } - } - return !in.bad(); - } - - template - bool - read_PLY( std::istream& in, - std::vector< Point_3 >& points, - std::vector< Polygon_3 >& polygons, - std::vector& fcolors, - std::vector& vcolors, - bool /* verbose */ = false) - { - std::vector > dummy_pui; - std::vector > dummy_pf; - return read_PLY(in, points, polygons, - dummy_pui, - fcolors, vcolors, - dummy_pf); - } -} // namespace CGAL +#define CGAL_DEPRECATED_HEADER "" +#define CGAL_REPLACEMENT_HEADER "" +#include +#include +#include #endif // CGAL_IO_PLY_READER_H diff --git a/Polyhedron_IO/include/CGAL/IO/PLY_writer.h b/Polyhedron_IO/include/CGAL/IO/PLY_writer.h index 052c6d196a9..04b373c8d55 100644 --- a/Polyhedron_IO/include/CGAL/IO/PLY_writer.h +++ b/Polyhedron_IO/include/CGAL/IO/PLY_writer.h @@ -22,148 +22,11 @@ #include -namespace CGAL{ - - template - bool - write_PLY(std::ostream& out, - const std::vector< Point_3 >& points, - const std::vector< Polygon_3 >& polygons, - bool /* verbose */ = false) - { - - if(!out) - { - std::cerr << "Error: cannot open file" << std::endl; - return false; - } - - // Write header - out << "ply" << std::endl - << ((get_mode(out) == IO::BINARY) ? "format binary_little_endian 1.0" : "format ascii 1.0") << std::endl - << "comment Generated by the CGAL library" << std::endl - << "element vertex " << points.size() << std::endl; - - internal::PLY::output_property_header (out, - make_ply_point_writer (CGAL::Identity_property_map())); - - out << "element face " << polygons.size() << std::endl; - - internal::PLY::output_property_header (out, - std::make_pair (CGAL::Identity_property_map(), - PLY_property >("vertex_indices"))); - - out << "end_header" << std::endl; - - for (std::size_t i = 0; i < points.size(); ++ i) - internal::PLY::output_properties (out, points.begin() + i, - make_ply_point_writer (CGAL::Identity_property_map())); - - for (std::size_t i = 0; i < polygons.size(); ++ i) - internal::PLY::output_properties (out, polygons.begin() + i, - std::make_pair (CGAL::Identity_property_map(), - PLY_property >("vertex_indices"))); - - return out.good(); - } - - template - bool - write_PLY(std::ostream& out, - const SurfaceMesh& mesh, - bool /* verbose */ = false) - { - typedef typename boost::graph_traits::face_descriptor face_descriptor; - typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; - typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; - typedef typename boost::property_map::type::value_type Point_3; - typedef typename SurfaceMesh::template Property_map > UV_map; - UV_map h_uv; - bool has_texture; - boost::tie(h_uv, has_texture) = mesh.template property_map >("h:uv"); - if(!out) - { - std::cerr << "Error: cannot open file" << std::endl; - return false; - } - - // Write header - out << "ply" << std::endl - << ((get_mode(out) == IO::BINARY) ? "format binary_little_endian 1.0" : "format ascii 1.0") << std::endl - << "comment Generated by the CGAL library" << std::endl - << "element vertex " << num_vertices(mesh) << std::endl; - - internal::PLY::output_property_header (out, - make_ply_point_writer (CGAL::Identity_property_map())); - - out << "element face " << num_faces(mesh) << std::endl; - - internal::PLY::output_property_header (out, - std::make_pair (CGAL::Identity_property_map >(), - PLY_property >("vertex_indices"))); - - if(has_texture) - { - out << "element halfedge " << num_halfedges(mesh) << std::endl; - - internal::PLY::output_property_header (out, - std::make_pair (CGAL::Identity_property_map(), - PLY_property("source"))); - - internal::PLY::output_property_header (out, - std::make_pair (CGAL::Identity_property_map(), - PLY_property("target"))); - internal::PLY::output_property_header (out, - std::make_tuple (h_uv, - PLY_property("u"), - PLY_property("v"))); - } - out << "end_header" << std::endl; - - for(vertex_descriptor vd : vertices(mesh)) - { - Point_3 p = get(get(CGAL::vertex_point, mesh), vd); - internal::PLY::output_properties (out, &p, - make_ply_point_writer (CGAL::Identity_property_map())); - } - - - std::vector polygon; - for(face_descriptor fd : faces(mesh)) - { - polygon.clear(); - for(halfedge_descriptor hd : halfedges_around_face(halfedge(fd, mesh), mesh)) - polygon.push_back (get(get(boost::vertex_index, mesh), target(hd,mesh))); - - internal::PLY::output_properties (out, &polygon, - std::make_pair (CGAL::Identity_property_map >(), - PLY_property >("vertex_indices"))); - } - - if(has_texture) - { - for(halfedge_descriptor hd : halfedges(mesh)) - { - typedef std::tuple Super_tuple; - Super_tuple t = - std::make_tuple(source(hd, mesh),target(hd, mesh), - h_uv[hd].first, - h_uv[hd].second); - - internal::PLY::output_properties (out, &t, - std::make_pair (Nth_of_tuple_property_map<0,Super_tuple>(), - PLY_property("source")), - std::make_pair (Nth_of_tuple_property_map<1,Super_tuple>(), - PLY_property("target")), - std::make_pair (Nth_of_tuple_property_map<2,Super_tuple>(), - PLY_property("u")), - std::make_pair (Nth_of_tuple_property_map<3,Super_tuple>(), - PLY_property("v"))); - } - } - return out.good(); - } - -} // namespace CGAL +#include +#define CGAL_DEPRECATED_HEADER "" +#define CGAL_REPLACEMENT_HEADER "" +#include +#include +#include #endif // CGAL_IO_PLY_WRITER_H diff --git a/Polyhedron_IO/include/CGAL/IO/Polyhedron_scan_OFF.h b/Polyhedron_IO/include/CGAL/IO/Polyhedron_scan_OFF.h index 5c27930709d..85dae1dc77c 100644 --- a/Polyhedron_IO/include/CGAL/IO/Polyhedron_scan_OFF.h +++ b/Polyhedron_IO/include/CGAL/IO/Polyhedron_scan_OFF.h @@ -15,7 +15,7 @@ // $URL$ // $Id$ // SPDX-License-Identifier: GPL-3.0+ -// +// // // Author(s) : Lutz Kettner @@ -26,134 +26,14 @@ #include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace CGAL { - -template < class HDS> -class Polyhedron_scan_OFF : public Modifier_base { -protected: - std::istream& m_in; - File_header_OFF m_file_header; -public: - - typedef HDS Halfedge_data_structure; - -// DEFINITION -// -// Polyhedron_scan_OFF is a polyhedral surface builder. -// It scans a polyhedron given in OFF from a stream and appends it -// incrementally using the incremental builder. - - Polyhedron_scan_OFF( std::istream& in, bool verbose = false) - : m_in(in), m_file_header( verbose) {} - - // Activation - void operator()( HDS& hds); - - const File_header_OFF& header() const { return m_file_header; } -}; - -template < class HDS > -void -Polyhedron_scan_OFF:: operator()( HDS& target) { - File_scanner_OFF scanner( m_in, m_file_header.verbose()); - if ( ! m_in) { - if ( scanner.verbose()) { - std::cerr << " " << std::endl; - std::cerr << "Polyhedron_scan_OFF::" << std::endl; - std::cerr << "operator(): input error: file format is not in " - "OFF." << std::endl; - } - return; - } - m_file_header = scanner; // Remember file header after return. - - Polyhedron_incremental_builder_3 B( target, scanner.verbose()); - B.begin_surface( scanner.size_of_vertices(), - scanner.size_of_facets(), - scanner.size_of_halfedges()); - - typedef typename HDS::Traits Traits; - typedef typename Traits::Point_3 Point; - - // read in all vertices - std::size_t i; - 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); - } - else - scanner.skip_to_next_vertex( i); - } - if ( ! m_in || B.error()) { - B.rollback(); - m_in.clear( std::ios::badbit); - return; - } - - // read in all facets - for ( i = 0; i < scanner.size_of_facets(); i++) { - B.begin_facet(); - std::size_t no; - scanner.scan_facet( no, i); - if( ! m_in || B.error() || no < 3) { - if ( scanner.verbose()) { - std::cerr << " " << std::endl; - std::cerr << "Polyhedron_scan_OFF::" << std::endl; - std::cerr << "operator()(): input error: facet " << i - << " has less than 3 vertices." << std::endl; - } - B.rollback(); - m_in.clear( std::ios::badbit); - return; - } - for ( std::size_t j = 0; j < no; j++) { - std::size_t index; - scanner.scan_facet_vertex_index( index, i); - B.add_vertex_to_facet( index); - } - //TO DO : Insert read color - B.end_facet(); - scanner.skip_to_next_facet( i); - } - if ( ! m_in || B.error()) { - B.rollback(); - m_in.clear( std::ios::badbit); - return; - } - if ( B.check_unconnected_vertices()) { - if ( ! B.remove_unconnected_vertices()) { - if ( scanner.verbose()) { - std::cerr << " " << std::endl; - std::cerr << "Polyhedron_scan_OFF::" << std::endl; - std::cerr << "operator()(): input error: cannot " - "successfully remove isolated vertices." - << std::endl; - } - B.rollback(); - m_in.clear( std::ios::badbit); - return; - } - } - B.end_surface(); -} - -} //namespace CGAL +#define CGAL_DEPRECATED_HEADER "" +#define CGAL_REPLACEMENT_HEADER "" +#include +#include #include #endif // CGAL_IO_POLYHEDRON_SCAN_OFF_H // // EOF // + + diff --git a/Polyhedron_IO/include/CGAL/IO/STL_reader.h b/Polyhedron_IO/include/CGAL/IO/STL_reader.h index 45f52f9cf23..c3c7ba14bcf 100644 --- a/Polyhedron_IO/include/CGAL/IO/STL_reader.h +++ b/Polyhedron_IO/include/CGAL/IO/STL_reader.h @@ -21,352 +21,12 @@ #ifndef CGAL_IO_STL_READER_H #define CGAL_IO_STL_READER_H -#include -#include +#include -#include - -#include -#include -#include -#include -#include - -namespace CGAL { - -template -bool read_ASCII_facet(std::istream& input, - std::vector& points, - std::vector& facets, - int& index, - std::map& index_map, - bool verbose = false) -{ - // Here, we have already read the word 'facet' and are looking to read till 'endfacet' - - std::string s; - std::string vertex("vertex"), - endfacet("endfacet"); - - int count = 0; - double x,y,z; - Point p; - Triangle ijk; - IO::internal::resize(ijk, 3); - - while(input >> s) - { - if(s == endfacet) - { - if(count != 3) - { - if(verbose) - std::cerr << "Error: only triangulated surfaces are supported" << std::endl; - - return false; - } - - facets.push_back(ijk); - return true; - } - else if(s == vertex) - { - if(count >= 3) - { - if(verbose) - std::cerr << "Error: only triangulated surfaces are supported" << std::endl; - - return false; - } - - if(!(input >> iformat(x) >> iformat(y) >> iformat(z))) - { - if(verbose) - std::cerr << "Error while reading point coordinates (premature end of file)" << std::endl; - - return false; - } - else - { - IO::internal::fill_point(x, y, z, p); - typename std::map::iterator iti = index_map.insert(std::make_pair(p, -1)).first; - - if(iti->second == -1) - { - ijk[count] = index; - iti->second = index++; - points.push_back(p); - } - else - { - ijk[count] = iti->second; - } - } - - ++count; - } - } - - if(verbose) - std::cerr << "Error while reading facet (premature end of file)" << std::endl; - - return false; -} - -template -bool parse_ASCII_STL(std::istream& input, - std::vector& points, - std::vector& facets, - bool verbose = false) -{ - if(verbose) - std::cout << "Parsing ASCII file..." << std::endl; - - if(!input.good()) - return true; - - // Here, we have already read the word 'solid' - - int index = 0; - std::map index_map; - - std::string s, facet("facet"), endsolid("endsolid"); - - while(input >> s) - { - if(s == facet) - { - if(!read_ASCII_facet(input, points, facets, index, index_map, verbose)) - return false; - } - else if(s == endsolid) - { - return true; - } - } - - if(verbose) - std::cerr << "Error while parsing ASCII file" << std::endl; - - return false; -} - -template -bool parse_binary_STL(std::istream& input, - std::vector& points, - std::vector& facets, - bool verbose = false) -{ - if(verbose) - std::cout << "Parsing binary file..." << std::endl; - - // Start from the beginning again to simplify things - input.clear(); - input.seekg(0, std::ios::beg); - - if(!input.good()) - return true; - - // Discard the first 80 chars (unused header) - int pos = 0; - char c; - - if(verbose) - std::cout << "header: "; - - while(pos < 80) - { - input.read(reinterpret_cast(&c), sizeof(c)); - if(!input.good()) - break; - - if(verbose) - std::cout << c; - - ++pos; - } - - if(verbose) - std::cout << std::endl; - - if(pos != 80) - return true; // empty file - - int index = 0; - std::map index_map; - - boost::uint32_t N32; - if(!(input.read(reinterpret_cast(&N32), sizeof(N32)))) - { - if(verbose) - std::cerr << "Error while reading number of facets" << std::endl; - - return false; - } - - unsigned int N = N32; - if(verbose) - std::cout << N << " facets to read" << std::endl; - - for(unsigned int i=0; i(&normal[0]), sizeof(normal[0]))) || - !(input.read(reinterpret_cast(&normal[1]), sizeof(normal[1]))) || - !(input.read(reinterpret_cast(&normal[2]), sizeof(normal[2])))) - { - if(verbose) - std::cerr << "Error while reading normal coordinates (premature end of file)" << std::endl; - - return false; - } - - Triangle ijk; - IO::internal::resize(ijk, 3); - - for(int j=0; j<3; ++j) - { - float x,y,z; - if(!(input.read(reinterpret_cast(&x), sizeof(x))) || - !(input.read(reinterpret_cast(&y), sizeof(y))) || - !(input.read(reinterpret_cast(&z), sizeof(z)))) - { - if(verbose) - std::cerr << "Error while reading vertex coordinates (premature end of file)" << std::endl; - - return false; - } - - Point p; - IO::internal::fill_point(x, y, z, p); - - typename std::map::iterator iti = index_map.insert(std::make_pair(p, -1)).first; - - if(iti->second == -1) - { - ijk[j] = index; - iti->second = index++; - points.push_back(p); - } - else - { - ijk[j] = iti->second; - } - } - - facets.push_back(ijk); - - // Read so-called attribute byte count and ignore it - char c; - if(!(input.read(reinterpret_cast(&c), sizeof(c))) || - !(input.read(reinterpret_cast(&c), sizeof(c)))) - { - if(verbose) - std::cerr << "Error while reading attribute byte count (premature end of file)" << std::endl; - - return false; - } - } - - return true; -} - -// -// Read a file with `.stl` format. -// -// \tparam Point must be a model of the concept `RandomAccessContainer` or a %CGAL point type -// \tparam Triangle must be a model of the concept `RandomAccessContainer` -// -// \param input the input stream -// \param points a container that will contain the points used in the .stl file -// \param polygons a container that will contain the triangles used in the .stl file -// \param verbose whether to enable or not a sanity log -// -// \returns `true` if the reading process went well, `false` otherwise -// -// \warning `points` and `facets` are not cleared: new points and triangles are added to the back -// of the containers. -// -// Although the STL file format uses triangles, it is convenient to be able to use vectors -// and other models of the `SequenceContainer` (instead of arrays) for the face type, -// to avoid having to convert the to apply polygon soup reparation algorithms. -template -bool read_STL(std::istream& input, - std::vector& points, - std::vector& facets, - bool verbose = false) -{ - int pos = 0; - - // Ignore all initial whitespace - unsigned char c; - - while(input.read(reinterpret_cast(&c), sizeof(c))) - { - if(!isspace(c)) - { - input.unget(); // move back to the first interesting char - break; - } - ++pos; - } - - if(!input.good()) // reached the end - return true; - - // If we have gone beyond 80 characters and have not read anything yet, - // then this must be an ASCII file. - if(pos > 80) - return parse_ASCII_STL(input, points, facets, verbose); - - // We are within the first 80 characters, both ASCII and binary are possible - - // Read the 5 first characters to check if the first word is "solid" - std::string s, solid("solid"); - - char word[5]; - if(input.read(reinterpret_cast(&word[0]), sizeof(c)) && - input.read(reinterpret_cast(&word[1]), sizeof(c)) && - input.read(reinterpret_cast(&word[2]), sizeof(c)) && - input.read(reinterpret_cast(&word[3]), sizeof(c)) && - input.read(reinterpret_cast(&word[4]), sizeof(c))) - { - s = std::string(word, 5); - pos += 5; - } - else - return true; // empty file - - // If the first word is not 'solid', the file must be binary - if(s != solid) - { - if(parse_binary_STL(input, points, facets, verbose)) - { - return true; - } - else - { - // If we failed to read it as a binary, try as ASCII just in case... - // The file does not start with 'solid' anyway, so it's fine to reset it. - input.clear(); - input.seekg(0, std::ios::beg); - return parse_ASCII_STL(input, points, facets, verbose); - } - } - - // Now, we have found the keyword "solid" which is supposed to indicate that the file is ASCII - if(parse_ASCII_STL(input, points, facets, verbose)) - { - // correctly read the input as an ASCII file - return true; - } - else // Failed to read the ASCII file - { - // It might have actually have been a binary file... ? - return parse_binary_STL(input, points, facets, verbose); - } -} - -} // namespace CGAL +#define CGAL_DEPRECATED_HEADER "" +#define CGAL_REPLACEMENT_HEADER "" +#include +#include +#include #endif // CGAL_IO_STL_READER_H diff --git a/Polyhedron_IO/include/CGAL/IO/STL_writer.h b/Polyhedron_IO/include/CGAL/IO/STL_writer.h index 8707ba4f899..a568c9995e9 100644 --- a/Polyhedron_IO/include/CGAL/IO/STL_writer.h +++ b/Polyhedron_IO/include/CGAL/IO/STL_writer.h @@ -20,79 +20,10 @@ #ifndef CGAL_IO_STL_WRITER_H #define CGAL_IO_STL_WRITER_H -#include -#include - -#include -#include - - - -namespace CGAL{ - -template -std::ostream& -write_STL(const TriangleMesh& tm, std::ostream& out) -{ - typedef typename boost::graph_traits::face_descriptor face_descriptor; - typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; - typedef typename boost::property_map::const_type Vpm; - typedef typename boost::property_traits::reference Point_3_ref; - typedef typename boost::property_traits::value_type Point_3; - typedef typename Kernel_traits::Kernel::Vector_3 Vector_3; - - Vpm vpm = get(boost::vertex_point, tm); - - if (get_mode(out) == IO::BINARY) - { - out << "FileType: Binary "; - const boost::uint32_t N32 = static_cast(faces(tm).size()); - out.write(reinterpret_cast(&N32), sizeof(N32)); - - for(face_descriptor f : faces(tm)) - { - halfedge_descriptor h = halfedge(f, tm); - Point_3_ref p = get(vpm, target(h, tm)); - Point_3_ref q = get(vpm, target(next(h, tm), tm)); - Point_3_ref r = get(vpm, source(h, tm)); - - Vector_3 n = collinear(p,q,r) ? Vector_3(1,0,0): - unit_normal(p,q,r); - - const float coords[12]={ - static_cast(n.x()), static_cast(n.y()), static_cast(n.z()), - static_cast(p.x()), static_cast(p.y()), static_cast(p.z()), - static_cast(q.x()), static_cast(q.y()), static_cast(q.z()), - static_cast(r.x()), static_cast(r.y()), static_cast(r.z()) }; - - for (int i=0; i<12; ++i) - out.write(reinterpret_cast(&coords[i]), sizeof(coords[i])); - out << " "; - } - } - else - { - out << "solid\n"; - for(face_descriptor f : faces(tm)) - { - halfedge_descriptor h = halfedge(f, tm); - Point_3_ref p = get(vpm, target(h, tm)); - Point_3_ref q = get(vpm, target(next(h, tm), tm)); - Point_3_ref r = get(vpm, source(h, tm)); - - Vector_3 n = collinear(p,q,r) ? Vector_3(1,0,0): - unit_normal(p,q,r); - out << "facet normal " << n << "\nouter loop\n"; - out << "vertex " << p << "\n"; - out << "vertex " << q << "\n"; - out << "vertex " << r << "\n"; - out << "endloop\nendfacet\n"; - } - out << "endsolid\n"; - } - return out; -} - -} // end of namespace CGAL +#define CGAL_DEPRECATED_HEADER "" +#define CGAL_REPLACEMENT_HEADER "" +#include +#include +#include #endif // CGAL_IO_STL_WRITER_H diff --git a/Polyhedron_IO/include/CGAL/IO/print_OFF.h b/Polyhedron_IO/include/CGAL/IO/print_OFF.h index 0126c5e9b12..afad74ec48d 100644 --- a/Polyhedron_IO/include/CGAL/IO/print_OFF.h +++ b/Polyhedron_IO/include/CGAL/IO/print_OFF.h @@ -15,7 +15,7 @@ // $URL$ // $Id$ // SPDX-License-Identifier: GPL-3.0+ -// +// // // Author(s) : Lutz Kettner @@ -24,77 +24,16 @@ #include +#include -#include -#include -#include -#include -#include +#define CGAL_DEPRECATED_HEADER "" +#define CGAL_REPLACEMENT_HEADER "" +#include +#include -namespace CGAL { - -template -void print_polyhedron_with_header_OFF( std::ostream& out, - const Polyhedron& P, - const File_header_OFF& header, - const Vpm& vpm) { - File_writer_OFF writer( header); - writer.header().set_polyhedral_surface( true); - writer.header().set_halfedges( P.size_of_halfedges()); - generic_print_polyhedron( out, P, writer, vpm); -} - -template -void print_polyhedron_with_header_OFF( std::ostream& out, - const Polyhedron& P, - const File_header_OFF& header) -{ - print_polyhedron_with_header_OFF(out, P, header, get(CGAL::vertex_point, P)); -} - -template -void print_polyhedron_OFF( std::ostream& out, - const Polyhedron& P, - bool verbose = false) { - File_header_OFF header( verbose); - header.set_binary( is_binary( out)); - header.set_no_comments( ! is_pretty( out)); - print_polyhedron_with_header_OFF( out, P, header); -} +#include -// Deprecated global functions, replaced with functions above - -template < class Traits, - class Items, - template < class T, class I, class A> - class HDS, class Alloc> -void -print_OFF( std::ostream& out, - const Polyhedron_3& P, - bool verbose = false) { - File_writer_OFF writer( verbose); - writer.header().set_binary( is_binary( out)); - writer.header().set_no_comments( ! is_pretty( out)); - writer.header().set_polyhedral_surface( true); - writer.header().set_halfedges( P.size_of_halfedges()); - generic_print_polyhedron( out, P, writer); -} - -template < class Traits, - class Items, - template < class T, class I, class A> - class HDS, class Alloc> -void -print_OFF( std::ostream& out, - const Polyhedron_3& P, - const File_header_OFF& header) { - File_writer_OFF writer( header); - writer.header().set_polyhedral_surface( true); - writer.header().set_halfedges( P.size_of_halfedges()); - generic_print_polyhedron( out, P, writer); -} - -} //namespace CGAL #endif // CGAL_IO_PRINT_OFF_H // // EOF // + diff --git a/Polyhedron_IO/include/CGAL/IO/print_wavefront.h b/Polyhedron_IO/include/CGAL/IO/print_wavefront.h index 1a16ecac113..ddd5dfd9eda 100644 --- a/Polyhedron_IO/include/CGAL/IO/print_wavefront.h +++ b/Polyhedron_IO/include/CGAL/IO/print_wavefront.h @@ -24,33 +24,14 @@ #include +#include -#include -#include -#include -#include +#define CGAL_DEPRECATED_HEADER "" +#define CGAL_REPLACEMENT_HEADER "" +#include +#include +#include -namespace CGAL { -template -void print_polyhedron_wavefront( std::ostream& out, const Polyhedron& P) { - File_writer_wavefront writer; - generic_print_polyhedron( out, P, writer); -} - -// Deprecated global functions, replaced with functions above - -template < class Traits, - class Items, - template < class T, class I, class A> - class HDS, class Alloc> -void -print_wavefront( std::ostream& out, - const Polyhedron_3& P) { - File_writer_wavefront writer; - generic_print_polyhedron( out, P, writer); -} - -} //namespace CGAL #endif // CGAL_IO_PRINT_WAVEFRONT_H // // EOF // diff --git a/Polyhedron_IO/include/CGAL/IO/scan_OFF.h b/Polyhedron_IO/include/CGAL/IO/scan_OFF.h index bdb73e0c47e..2b0b7e74e02 100644 --- a/Polyhedron_IO/include/CGAL/IO/scan_OFF.h +++ b/Polyhedron_IO/include/CGAL/IO/scan_OFF.h @@ -15,7 +15,7 @@ // $URL$ // $Id$ // SPDX-License-Identifier: GPL-3.0+ -// +// // // Author(s) : Lutz Kettner @@ -24,45 +24,13 @@ #include +#include -#include -#include -#include +#define CGAL_DEPRECATED_HEADER "" +#define CGAL_REPLACEMENT_HEADER "" +#include +#include " +#include -namespace CGAL { - -template < class Traits, - class Items, - template < class T, class I, class A> - class HDS, class Alloc> -void scan_OFF( std::istream& in, - Polyhedron_3& P, - File_header_OFF& header) { - // reads a polyhedron from `in' and appends it to P. - // Returns also the File_header_OFF structure of the object. - typedef Polyhedron_3 Polyhedron; - typedef typename Polyhedron::HalfedgeDS HalfedgeDS; - typedef Polyhedron_scan_OFF Scanner; - Scanner scanner( in, header.verbose()); - P.delegate(scanner); - header = scanner.header(); -} - -template < class Traits, - class Items, - template < class T, class I, class A> - class HDS, class Alloc> -void scan_OFF( std::istream& in, Polyhedron_3& P, - bool verbose = false) { - // reads a polyhedron from `in' and appends it to P. - typedef Polyhedron_3 Polyhedron; - typedef typename Polyhedron::HalfedgeDS HalfedgeDS; - typedef Polyhedron_scan_OFF Scanner; - Scanner scanner( in, verbose); - P.delegate(scanner); -} - - -} //namespace CGAL #endif // CGAL_IO_SCAN_OFF_H // // EOF // diff --git a/Stream_support/include/CGAL/IO/File_header_OFF.h b/Stream_support/include/CGAL/IO/File_header_OFF.h index 8e8c02460ae..756b16d5d2e 100644 --- a/Stream_support/include/CGAL/IO/File_header_OFF.h +++ b/Stream_support/include/CGAL/IO/File_header_OFF.h @@ -27,100 +27,14 @@ #ifndef CGAL_IO_FILE_HEADER_OFF_H #define CGAL_IO_FILE_HEADER_OFF_H 1 -#include -#include -namespace CGAL { +#include -// Info structure for OFF file headers -// =================================== -class CGAL_EXPORT File_header_OFF : public File_header_extended_OFF { -private: - // Publicly accessible file informations. - std::size_t n_vertices; - std::size_t n_facets; - bool m_skel; // SKEL format instead of OFF. - bool m_binary; // OFF in binary format. - bool m_no_comments; // no comments in output. - std::size_t m_offset; // index offset for vertices, usually 0. - - // Publicly accessible but not that well supported file informations. - bool m_colors; // COFF detected. - bool m_normals; // NOFF format stores also normals at vertices. - - // More privately used file informations to scan the file. - bool m_tag4; // 4OFF detected. - bool m_tagDim; // nOFF detected (will not be supported). - int m_dim; // dimension for nOFF (will not be supported). -public: - typedef File_header_OFF Self; - typedef File_header_extended_OFF Base; - - explicit File_header_OFF( bool verbose = false); - File_header_OFF( bool binary, bool noc, bool skel, - bool verbose = false); - //File_header_OFF( int v, int h, int f, bool verbose = false); - File_header_OFF( std::size_t v, std::size_t h, std::size_t f, - bool binary, bool noc, bool skel, - bool verbose = false); - File_header_OFF( const File_header_extended_OFF& ext_header); - File_header_OFF( const File_header_extended_OFF& ext_header, - bool binary, bool noc, bool skel); - File_header_OFF( std::size_t v, std::size_t h, std::size_t f, - const File_header_extended_OFF& ext_header); - File_header_OFF( std::size_t v, std::size_t h, std::size_t f, - const File_header_extended_OFF& ext_header, - bool binary, bool noc, bool skel); - - Self& operator= ( const Base& base) { (Base&)(*this) = base; - return *this; - } - std::size_t size_of_vertices() const { return n_vertices; } - std::size_t size_of_facets() const { return n_facets; } - - bool skel() const { return m_skel; } // SKEL format. - bool off() const { return ! m_skel; } // OFF format. - bool binary() const { return m_binary; } // binary format. - bool ascii() const { return ! m_binary; } // ASCII format. - bool no_comments() const { return m_no_comments; } - bool comments() const { return ! m_no_comments; } - - std::size_t index_offset() const { return m_offset; } - bool has_colors() const { return m_colors; } // COFF detected. - bool has_normals() const { return m_normals;} // NOFF format. - bool is_homogeneous() const { return m_tag4; } // 4OFF detected. - // nOFF detected. (will not be supported). - bool n_dimensional() const { return m_tagDim; } - // dimension for nOFF (will not be supported). - int dimension() const { return m_dim; } - - void set_vertices( std::size_t n) { n_vertices = n; } - void set_facets( std::size_t n) { n_facets = n; } - - void set_skel( bool b) { m_skel = b; } - void set_binary( bool b) { m_binary = b; } - void set_no_comments( bool b) { m_no_comments = b; } - void set_index_offset( std::size_t i) { m_offset = i; } - - void set_colors( bool b) { m_colors = b; } - void set_normals( bool b) { m_normals = b;} - void set_homogeneous( bool b) { m_tag4 = b; } - void set_dimensional( bool b) { m_tagDim = b; } - void set_dimension( int i) { m_dim = i; } - Self& operator+=( const Self& header); -}; - -// Write header. -CGAL_EXPORT std::ostream& operator<<( std::ostream& out, const File_header_OFF& h); - -// Scan header. Marks streams badbit if not in SKEL format nor in OFF. -CGAL_EXPORT std::istream& operator>>( std::istream& in, File_header_OFF& h); - -} //namespace CGAL - -#ifdef CGAL_HEADER_ONLY -#include -#endif // CGAL_HEADER_ONLY +#define CGAL_DEPRECATED_HEADER "" +#define CGAL_REPLACEMENT_HEADER "" +#include +#include +#include #endif // CGAL_IO_FILE_HEADER_OFF_H // // EOF // diff --git a/Stream_support/include/CGAL/IO/File_header_OFF_impl.h b/Stream_support/include/CGAL/IO/File_header_OFF_impl.h deleted file mode 100644 index 560dfa95aa8..00000000000 --- a/Stream_support/include/CGAL/IO/File_header_OFF_impl.h +++ /dev/null @@ -1,406 +0,0 @@ -// Copyright (c) 1997 -// Utrecht University (The Netherlands), -// ETH Zurich (Switzerland), -// INRIA Sophia-Antipolis (France), -// Max-Planck-Institute Saarbruecken (Germany), -// and Tel-Aviv University (Israel). All rights reserved. -// -// This file is part of CGAL (www.cgal.org); you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 3 of the License, -// or (at your option) any later version. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0+ -// -// -// Author(s) : Lutz Kettner - -#ifdef CGAL_HEADER_ONLY -#define CGAL_INLINE_FUNCTION inline -#else -#define CGAL_INLINE_FUNCTION -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace CGAL { - -CGAL_INLINE_FUNCTION -File_header_OFF::File_header_OFF( bool verbose) -: File_header_extended_OFF( verbose), - n_vertices(0), - n_facets(0), - m_skel(false), - m_binary(false), - m_no_comments(false), - m_offset(0), - m_colors(false), - m_normals(false), - m_tag4(false), - m_tagDim(false), - m_dim(3) -{} -CGAL_INLINE_FUNCTION -File_header_OFF::File_header_OFF( - bool binary, bool noc, bool skel, bool verbose) -: File_header_extended_OFF( verbose), - n_vertices(0), - n_facets(0), - m_skel(skel), - m_binary(binary), - m_no_comments(noc), - m_offset(0), - m_colors(false), - m_normals(false), - m_tag4(false), - m_tagDim(false), - m_dim(3) -{} -//CGAL_INLINE_FUNCTION -//File_header_OFF::File_header_OFF( int v, int h, int f, -// bool verbose) -//: File_header_extended_OFF( verbose), -// n_vertices(v), -// n_facets(f), -// m_skel(false), -// m_binary(false), -// m_no_comments(false), -// m_offset(0), -// m_colors(false), -// m_normals(false), -// m_tag4(false), -// m_tagDim(false), -// m_dim(3) -//{ -// set_halfedges(h); -//} -CGAL_INLINE_FUNCTION -File_header_OFF::File_header_OFF( std::size_t v, std::size_t h, std::size_t f, - bool binary, bool noc, bool skel, bool verbose) -: File_header_extended_OFF( verbose), - n_vertices(v), - n_facets(f), - m_skel(skel), - m_binary(binary), - m_no_comments(noc), - m_offset(0), - m_colors(false), - m_normals(false), - m_tag4(false), - m_tagDim(false), - m_dim(3) -{ - set_halfedges(h); -} -CGAL_INLINE_FUNCTION -File_header_OFF::File_header_OFF( - const File_header_extended_OFF& ext_header) -: File_header_extended_OFF( ext_header), - n_vertices(0), - n_facets(0), - m_skel(false), - m_binary(false), - m_no_comments(false), - m_offset(0), - m_colors(false), - m_normals(false), - m_tag4(false), - m_tagDim(false), - m_dim(3) -{} -CGAL_INLINE_FUNCTION -File_header_OFF::File_header_OFF( - const File_header_extended_OFF& ext_header, - bool binary, bool noc, bool skel) -: File_header_extended_OFF( ext_header), - n_vertices(0), - n_facets(0), - m_skel(skel), - m_binary(binary), - m_no_comments(noc), - m_offset(0), - m_colors(false), - m_normals(false), - m_tag4(false), - m_tagDim(false), - m_dim(3) -{} -CGAL_INLINE_FUNCTION -File_header_OFF::File_header_OFF( - std::size_t v, std::size_t h, std::size_t f, - const File_header_extended_OFF& ext_header) -: File_header_extended_OFF( ext_header), - n_vertices(v), - n_facets(f), - m_skel(false), - m_binary(false), - m_no_comments(false), - m_offset(0), - m_colors(false), - m_normals(false), - m_tag4(false), - m_tagDim(false), - m_dim(3) -{ - set_halfedges(h); -} -CGAL_INLINE_FUNCTION -File_header_OFF::File_header_OFF( - std::size_t v, std::size_t h, std::size_t f, - const File_header_extended_OFF& ext_header, - bool binary, bool noc, bool skel) -: File_header_extended_OFF( ext_header), - n_vertices(v), - n_facets(f), - m_skel(skel), - m_binary(binary), - m_no_comments(noc), - m_offset(0), - m_colors(false), - m_normals(false), - m_tag4(false), - m_tagDim(false), - m_dim(3) -{ - set_halfedges(h); -} - -CGAL_INLINE_FUNCTION -File_header_OFF& File_header_OFF:: -operator+=( const File_header_OFF& header) { - (File_header_extended_OFF&)(*this) = header; - n_vertices += header.n_vertices; - n_facets += header.n_facets; - return *this; -} - -// Write header. -CGAL_INLINE_FUNCTION -std::ostream& operator<<( std::ostream& out, const File_header_OFF& h) { - if ( h.comments()) { - out << "# Output of a CGAL tool\n"; - out << static_cast( h); - } - if ( h.has_normals()) - out << 'N'; - if ( h.skel()) - out << "SKEL"; - else - out << "OFF"; - if ( h.binary()) { - out << " BINARY\n"; - I_Binary_write_big_endian_integer32( out, static_cast(h.size_of_vertices())); - I_Binary_write_big_endian_integer32( out, static_cast(h.size_of_facets())); - if ( h.off()) - I_Binary_write_big_endian_integer32( out, 0); - } else { - out << '\n'; - out << h.size_of_vertices() << ' '<< h.size_of_facets(); - if ( h.off()) - out << " 0"; - if ( h.comments()) { - out << "\n\n# " << h.size_of_vertices() << " vertices\n"; - out << "# ------------------------------------------\n"; - } - out << std::endl; - } - return out; -} - -// Scan header. Marks streams badbit if not in SKEL format nor in OFF. -CGAL_INLINE_FUNCTION -std::istream& operator>>( std::istream& in, File_header_OFF& h) { - // read in the first character and scan for comments, `OFF', or `NOFF', - // or `SKEL', or `4SKEL'. - h.set_off_header( false); - char c; - while ( (in >> c) && c == '#') { - if ( in.get(c) && c == 'C' && - in.get(c) && c == 'B' && - in.get(c) && c == 'P') { - in >> static_cast( h); - } else if ( c != '\n') - in >> skip_until_EOL; - } - if ( ! in) - return in; - h.set_skel( false); - h.set_binary( false); - h.set_index_offset( 1); - h.set_colors( false); - h.set_normals( false); - h.set_homogeneous( false); - h.set_dimensional( false); - h.set_dimension( 3); - - const int max_keyword = 42; - char keyword[max_keyword] = ""; - int i = 0; - keyword[i++] = c; - while( i < max_keyword - 1 && in.get(c) && std::isalnum(c)) - keyword[i++] = c; - keyword[i] = '\0'; - if ( i < 2 || (std::isdigit(keyword[0]) && keyword[0] != '4') - || std::isdigit(keyword[1])) { - h.set_vertices( std::atoi( keyword)); - } else { - h.set_index_offset( 0); - int j = 0; - if ( j < i && keyword[j] == 'C') { - h.set_colors( true); - j++; - } - if ( j < i && keyword[j] == 'N') { - h.set_normals( true); - j++; - } - if ( j < i && keyword[j] == '4') { - h.set_homogeneous( true); - j++; - } - if ( j < i && keyword[j] == 'n') { - h.set_dimensional( true); - j++; - } - if ( i-j != 3 || keyword[j] != 'O' - || keyword[j+1] != 'F' - || keyword[j+2] != 'F') { - if ( i-j != 4 || keyword[j] != 'S' - || keyword[j+1] != 'K' - || keyword[j+2] != 'E' - || keyword[j+3] != 'L') { - in.clear( std::ios::badbit); - if ( h.verbose()) { - std::cerr << " " << std::endl; - std::cerr << "error: File_header_OFF: " - "wrong format: neither OFF nor SKEL." - << std::endl; - } - return in; - } else { - h.set_skel( true); - } - } - in >> skip_comment_OFF >> c; - if ( std::isdigit(c)) { - in.putback(c); - int n; - in >> n; - h.set_vertices(n); - } else { - i = 0; - keyword[i++] = c; - while( i < max_keyword - 1 && in.get(c) && - std::isalnum(c)) - keyword[i++] = c; - keyword[i] = '\0'; - if ( std::strcmp( keyword, "BINARY") == 0) { - h.set_binary( true); - if ( c != '\n') - in >> skip_until_EOL; - } else { - in.clear( std::ios::badbit); - if ( h.verbose()) { - std::cerr << " " << std::endl; - std::cerr << "error: File_header_OFF(): " - "wrong format: neither OFF nor SKEL." - << std::endl; - } - return in; - } - } - } - // Read remaining size value(s). - int n_h; - if ( h.binary()) { - boost::int32_t a, b, c; - I_Binary_read_big_endian_integer32( in, a); - if ( h.n_dimensional()) { - h.set_dimension( a); - I_Binary_read_big_endian_integer32( in, a); - } - I_Binary_read_big_endian_integer32( in, b); - if ( h.off()) - I_Binary_read_big_endian_integer32( in, c); - else - c = 0; - h.set_vertices( a); - if (b<0){ - in.clear( std::ios::badbit ); - if ( h.verbose()) { - std::cerr << " " << std::endl; - std::cerr << "error: File_header_OFF(): File contains < 0 facets." - << std::endl; - } - return in; - } - h.set_facets( b); - n_h = c; - } else { - int n; - if ( h.n_dimensional()) { - h.set_dimension( static_cast(h.size_of_vertices())); - in >> n; - h.set_vertices(n); - } - in >> n; - if (n < 0){ - in.clear( std::ios::badbit ); - if ( h.verbose()) { - std::cerr << " " << std::endl; - std::cerr << "error: File_header_OFF(): File contains < 0 facets." - << std::endl; - } - return in; - } - h.set_facets(n); - if ( h.off()) - in >> n_h; - else - n_h = 0; - } - if ( n_h == 0) - h.set_index_offset( 0); - if ( ! in ) { - return in; - } - if ( h.size_of_halfedges() == 0) { - // be careful, because border edges count twice - h.set_halfedges( 2 * n_h); - // check against the Eulerian equation for connected planar graphs. - // We do not know the number of holes we must represent as dummy - // facets and we do not know the genus of the surface. - // So we add 12 and a factor of 5 percent. - if ( h.size_of_halfedges() == 0 - || double(h.size_of_halfedges()) > double(h.size_of_vertices() - + h.size_of_facets() - 2 + 12) * 2.1 - || h.size_of_halfedges() < (h.size_of_vertices() - + h.size_of_facets() - 2) * 2 - ) - h.set_halfedges( int( double(h.size_of_vertices() + - h.size_of_facets() - 2 + 12) * 2.1 - ) - ); - } - h.set_off_header( h.off()); - return in; -} - -} //namespace CGAL -// EOF // diff --git a/Stream_support/include/CGAL/IO/File_header_extended_OFF.h b/Stream_support/include/CGAL/IO/File_header_extended_OFF.h deleted file mode 100644 index da8555d60d8..00000000000 --- a/Stream_support/include/CGAL/IO/File_header_extended_OFF.h +++ /dev/null @@ -1,138 +0,0 @@ -// Copyright (c) 1997 -// Utrecht University (The Netherlands), -// ETH Zurich (Switzerland), -// INRIA Sophia-Antipolis (France), -// Max-Planck-Institute Saarbruecken (Germany), -// and Tel-Aviv University (Israel). All rights reserved. -// -// This file is part of CGAL (www.cgal.org); you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 3 of the License, -// or (at your option) any later version. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0+ -// -// -// Author(s) : Lutz Kettner - - -#ifndef CGAL_IO_FILE_HEADER_EXTENDED_OFF_H -#define CGAL_IO_FILE_HEADER_EXTENDED_OFF_H 1 - -#include - -#include -#include - - -namespace CGAL { - -class CGAL_EXPORT File_header_extended_OFF { - bool m_verbose; // Print error messages if true. - bool m_polyhedral_surface; - std::size_t m_halfedges; - bool m_triangulated; - bool m_non_empty_facets; - bool m_terrain; - bool m_normalized_to_sphere; - double m_radius; - bool m_rounded; - int m_rounded_bits; - bool m_off_header; -public: - typedef File_header_extended_OFF Self; - File_header_extended_OFF( bool verbose = false) - : m_verbose ( verbose), - m_polyhedral_surface ( false), - m_halfedges ( 0), - m_triangulated ( false), - m_non_empty_facets ( false), - m_terrain ( false), - m_normalized_to_sphere ( false), - m_radius ( 0.0), - m_rounded ( false), - m_rounded_bits ( 0), - m_off_header ( true) - {} - // Access: - bool verbose() const { return m_verbose; } - bool polyhedral_surface() const { return m_polyhedral_surface; } - std::size_t halfedges() const { return m_halfedges; } - std::size_t size_of_halfedges() const { return m_halfedges; } - bool triangulated() const { return m_triangulated; } - bool non_empty_facets() const { return m_non_empty_facets; } - bool terrain() const { return m_terrain; } - bool normalized_to_sphere() const { return m_normalized_to_sphere; } - double radius() const { return m_radius; } - bool rounded() const { return m_rounded; } - int rounded_bits() const { return m_rounded_bits; } - bool off_header() const { return m_off_header; } - // Derived predicates about the file format. - bool is_OFF() const { return m_off_header; } - bool is_POL() const; - bool is_CBP() const; - bool is_TRN() const; - int is_CBPn() const; - int is_TRNn() const; - // The proper file suffix with respect to file format. - std::string suffix() const; - // The proper format name. - std::string format_name() const; - // Set values: - void set_verbose( bool b) { m_verbose = b; } - void set_polyhedral_surface( bool b) { m_polyhedral_surface = b; } - void set_halfedges( std::size_t h) { m_halfedges = h; } - void set_triangulated( bool b) { m_triangulated = b; } - void set_non_empty_facets( bool b) { m_non_empty_facets = b; } - void set_terrain( bool b) { m_terrain = b; } - void set_normalized_to_sphere( bool b) { m_normalized_to_sphere = b;} - void set_radius( double d) { m_radius = d; } - void set_rounded( bool b) { m_rounded = b; } - void set_rounded_bits( int i) { m_rounded_bits = i; } - void set_off_header( bool b) { m_off_header = b; } - Self& operator+=( const Self& header); // union of two headers -}; - -// Write extended header incl. CGAL/ENDCBP keywords. -std::ostream& operator<<( std::ostream& out, - const File_header_extended_OFF& h); - -// Scan extended header. The CBP keyword must be read already. -std::istream& operator>>( std::istream& in, File_header_extended_OFF& h); - -// istream modifier skips chars until end of line. -inline std::istream& skip_until_EOL( std::istream& in) { - if(in.eof()){ - return in; - } - char c; - while ( in.get(c) && c != '\n') - ; - return in; -} - -// istream modifier that checks for OFF comments and removes them. -inline std::istream& skip_comment_OFF( std::istream& in) { - char c; - while( (in >> c) && c == '#') - in >> skip_until_EOL; - in.putback(c); - return in; -} - -} //namespace CGAL - -#ifdef CGAL_HEADER_ONLY -#include -#endif // CGAL_HEADER_ONLY - -#endif // CGAL_IO_FILE_HEADER_EXTENDED_OFF_H // -// EOF // diff --git a/Stream_support/include/CGAL/IO/File_header_extended_OFF_impl.h b/Stream_support/include/CGAL/IO/File_header_extended_OFF_impl.h deleted file mode 100644 index cb174391fed..00000000000 --- a/Stream_support/include/CGAL/IO/File_header_extended_OFF_impl.h +++ /dev/null @@ -1,213 +0,0 @@ -// Copyright (c) 1997 -// Utrecht University (The Netherlands), -// ETH Zurich (Switzerland), -// INRIA Sophia-Antipolis (France), -// Max-Planck-Institute Saarbruecken (Germany), -// and Tel-Aviv University (Israel). All rights reserved. -// -// This file is part of CGAL (www.cgal.org); you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 3 of the License, -// or (at your option) any later version. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0+ -// -// -// Author(s) : Lutz Kettner - -#ifdef CGAL_HEADER_ONLY -#define CGAL_INLINE_FUNCTION inline -#else -#define CGAL_INLINE_FUNCTION -#endif - -#include -#include - -#include -#include -#include -#include -#include -#include - - -namespace CGAL { - -CGAL_INLINE_FUNCTION -bool File_header_extended_OFF:: -is_POL() const { - return is_OFF() && polyhedral_surface(); -} - -CGAL_INLINE_FUNCTION -bool File_header_extended_OFF:: -is_CBP() const { - return is_POL() && triangulated() && non_empty_facets() && - normalized_to_sphere() && radius() <= 1.0; -} - -CGAL_INLINE_FUNCTION -bool File_header_extended_OFF:: -is_TRN() const { return is_CBP() && terrain(); } - -CGAL_INLINE_FUNCTION -int File_header_extended_OFF:: -is_CBPn() const { - if ( is_POL() && triangulated() && non_empty_facets() && - normalized_to_sphere() && rounded() && - (radius() <= double( 1l << rounded_bits()))) - return rounded_bits(); - else - return 0; -} - -CGAL_INLINE_FUNCTION -int File_header_extended_OFF:: -is_TRNn() const { return ( terrain() ? is_CBPn() : 0); } - - -// The proper file suffix with respect to file format. -CGAL_INLINE_FUNCTION -std::string File_header_extended_OFF:: -suffix() const { - if ( is_TRNn()) { - std::ostringstream out; - out << "trn" << m_rounded_bits << '\0'; - return out.str(); - } - if ( is_TRN()) - return std::string("trn"); - if ( is_CBPn()) { - std::ostringstream out; - out << "cbp" << m_rounded_bits << '\0'; - return out.str(); - } - if ( is_CBP()) - return std::string("cbp"); - if ( is_POL()) - return std::string("pol"); - return std::string("off"); -} - -// The proper format name. -CGAL_INLINE_FUNCTION -std::string File_header_extended_OFF:: -format_name() const { - if ( is_TRNn()) { - std::ostringstream out; - out << "TRN" << m_rounded_bits << '\0'; - return out.str(); - } - if ( is_TRN()) - return std::string("TRN"); - if ( is_CBPn()) { - std::ostringstream out; - out << "CBP" << m_rounded_bits << '\0'; - return out.str(); - } - if ( is_CBP()) - return std::string("CBP"); - if ( is_POL()) - return std::string("POL"); - return std::string("OFF"); -} - -CGAL_INLINE_FUNCTION -File_header_extended_OFF& File_header_extended_OFF:: -operator+=( const File_header_extended_OFF& header) { - m_verbose = m_verbose || header.m_verbose; - m_polyhedral_surface = m_polyhedral_surface && - header.m_polyhedral_surface; - m_halfedges += header.m_halfedges; - m_triangulated = m_triangulated && header.m_triangulated; - m_non_empty_facets = m_non_empty_facets && - header.m_non_empty_facets; - m_terrain = m_terrain && header.m_terrain; - m_normalized_to_sphere = m_normalized_to_sphere && - header.m_normalized_to_sphere; - m_radius = (std::max)(m_radius, header.m_radius); - m_rounded = m_rounded && header.m_rounded; - m_rounded_bits = (std::max)( m_rounded_bits, - header.m_rounded_bits); - m_off_header = m_off_header && header.m_off_header; - return *this; -} - -#define CGAL_OUT(item) out << "# " #item " " << h.item() << '\n' -#define CGAL_OUTBOOL(item) out << "# " #item " " <<(h.item() ? '1':'0') << '\n' - -// Write extended header incl. CGAL/ENDCBP keywords. -CGAL_INLINE_FUNCTION -std::ostream& operator<<( std::ostream& out, - const File_header_extended_OFF& h) { - out << "#CBP\n"; - CGAL_OUTBOOL( polyhedral_surface); - CGAL_OUT( halfedges); - CGAL_OUTBOOL( triangulated); - CGAL_OUTBOOL( non_empty_facets); - CGAL_OUTBOOL( terrain); - CGAL_OUTBOOL( normalized_to_sphere); - CGAL_OUT( radius); - CGAL_OUTBOOL( rounded); - CGAL_OUT( rounded_bits); - out << "# ENDCBP\n" << std::endl; - return out; -} -#undef CGAL_OUT -#undef OUTBOOL - -#define CGAL_IN(item,type) \ - else if ( std::strcmp( keyword, #item) == 0) { \ - type t; \ - in >> t; \ - h.set_##item( t); \ - } - -#define CGAL_INBOOL(item) \ - else if ( std::strcmp( keyword, #item) == 0) { \ - in >> c; \ - h.set_##item( c == '1'); \ - } - -// Scan extended header. The CBP keyword must be read already. -CGAL_INLINE_FUNCTION -std::istream& operator>>( std::istream& in, File_header_extended_OFF& h) { - const int max_keyword = 42; - char c; - char keyword[max_keyword] = ""; - in >> keyword; - while ( in && std::strcmp( keyword, "ENDCBP") != 0) { - if ( std::strcmp( keyword, "#") == 0) - ; - CGAL_INBOOL( polyhedral_surface) - CGAL_IN( halfedges, int) - CGAL_INBOOL( triangulated) - CGAL_INBOOL( non_empty_facets) - CGAL_INBOOL( terrain) - CGAL_INBOOL( normalized_to_sphere) - CGAL_IN( radius, double) - CGAL_INBOOL( rounded) - CGAL_IN( rounded_bits, int) - else if ( h.verbose()) { - std::cerr << "warning: File_header_extended_OFF: unknown key '" - << keyword << "'." << std::endl; - } - in >> keyword; - } - in >> skip_until_EOL >> skip_comment_OFF; - return in; -} -#undef CGAL_IN -#undef CGAL_INBOOL - -} //namespace CGAL -// EOF // diff --git a/Stream_support/include/CGAL/IO/File_scanner_OFF.h b/Stream_support/include/CGAL/IO/File_scanner_OFF.h index 93197d60ba8..85657df703a 100644 --- a/Stream_support/include/CGAL/IO/File_scanner_OFF.h +++ b/Stream_support/include/CGAL/IO/File_scanner_OFF.h @@ -28,679 +28,10 @@ #include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -namespace CGAL { - -class CGAL_EXPORT File_scanner_OFF : public File_header_OFF { - std::istream& m_in; - bool normals_read; - void skip_comment() { m_in >> skip_comment_OFF; } -public: - File_scanner_OFF( std::istream& in, bool verbose = false) - : File_header_OFF(verbose), m_in(in), normals_read(false) { - in >> static_cast( *this); - } - File_scanner_OFF( std::istream& in, const File_header_OFF& header) - : File_header_OFF(header), m_in(in), normals_read(false) {} - - std::istream& in() { return m_in; } - - // The scan_vertex() routine is provided for multiple - // coordinate types to support parameterized polytopes. - void scan_vertex( float& x, float& y, float& z) { - if ( binary()) { - I_Binary_read_big_endian_float32( m_in, x); - I_Binary_read_big_endian_float32( m_in, y); - I_Binary_read_big_endian_float32( m_in, z); - if ( is_homogeneous()) { - float w; - I_Binary_read_big_endian_float32( m_in, w); - x /= w; - y /= w; - z /= w; - } - } else { - skip_comment(); - m_in >> iformat(x) >> iformat(y) >> iformat(z); - if ( is_homogeneous()) { - float w; - m_in >> iformat(w); - x /= w; - y /= w; - z /= w; - } - } - } - void scan_vertex( double& x, double& y, double& z) { - if ( binary()) { - float f; - I_Binary_read_big_endian_float32( m_in, f); - x = f; - I_Binary_read_big_endian_float32( m_in, f); - y = f; - I_Binary_read_big_endian_float32( m_in, f); - z = f; - if ( is_homogeneous()) { - I_Binary_read_big_endian_float32( m_in, f); - x /= f; - y /= f; - z /= f; - } - } else { - skip_comment(); - m_in >> iformat(x) >> iformat(y) >> iformat(z); - if ( is_homogeneous()) { - double w; - m_in >> iformat(w); - x /= w; - y /= w; - z /= w; - } - } - } - void scan_vertex( int& x, int& y, int& z) { - if ( binary()) { - float fx, fy, fz; - I_Binary_read_big_endian_float32( m_in, fx); - I_Binary_read_big_endian_float32( m_in, fy); - I_Binary_read_big_endian_float32( m_in, fz); - if ( is_homogeneous()) { - float fw; - I_Binary_read_big_endian_float32( m_in, fw); - x = int( fx / fw); - y = int( fy / fw); - z = int( fz / fw); - } else { - x = int(fx); - y = int(fy); - z = int(fz); - } - } else { - skip_comment(); - if ( is_homogeneous()) { - double fx, fy, fz, fw; - m_in >> iformat(fx) >> iformat(fy) >> iformat(fz) >> iformat(fw); - x = int( fx / fw); - y = int( fy / fw); - z = int( fz / fw); - } else { - double d; - m_in >> iformat(d); - x = int(d); - m_in >> iformat(d); - y = int(d); - m_in >> iformat(d); - z = int(d); - } - } - } - - void scan_vertex( float& x, float& y, float& z, float& w) { - w = 1; - if ( binary()) { - I_Binary_read_big_endian_float32( m_in, x); - I_Binary_read_big_endian_float32( m_in, y); - I_Binary_read_big_endian_float32( m_in, z); - if ( is_homogeneous()) - I_Binary_read_big_endian_float32( m_in, w); - } else { - skip_comment(); - m_in >> iformat(x) >> iformat(y) >> iformat(z); - if ( is_homogeneous()) - m_in >> iformat(w); - } - } - void scan_vertex( double& x, double& y, double& z, double& w) { - w = 1; - if ( binary()) { - float f; - I_Binary_read_big_endian_float32( m_in, f); - x = f; - I_Binary_read_big_endian_float32( m_in, f); - y = f; - I_Binary_read_big_endian_float32( m_in, f); - z = f; - if ( is_homogeneous()) { - I_Binary_read_big_endian_float32( m_in, f); - w = f; - } - } else { - skip_comment(); - m_in >> iformat(x); - m_in >> iformat(y); - m_in >> iformat(z); - if ( is_homogeneous()) - m_in >> iformat(w); - } - } - void scan_vertex( int& x, int& y, int& z, int& w) { - w = 1; - if ( binary()) { - float f; - I_Binary_read_big_endian_float32( m_in, f); - x = int(f); - I_Binary_read_big_endian_float32( m_in, f); - y = int(f); - I_Binary_read_big_endian_float32( m_in, f); - z = int(f); - if ( is_homogeneous()) { - I_Binary_read_big_endian_float32( m_in, f); - w = int(f); - } - } else { - skip_comment(); - double d; - m_in >> iformat(d); - x = int(d); - m_in >> iformat(d); - y = int(d); - m_in >> iformat(d); - z = int(d); - if ( is_homogeneous()) { - m_in >> iformat(d); - w = int(d); - } - } - } - - void scan_normal( float& x, float& y, float& z) { - if ( has_normals()) { - normals_read = true; - if ( binary()) { - I_Binary_read_big_endian_float32( m_in, x); - I_Binary_read_big_endian_float32( m_in, y); - I_Binary_read_big_endian_float32( m_in, z); - if ( is_homogeneous()) { - float w; - I_Binary_read_big_endian_float32( m_in, w); - x /= w; - y /= w; - z /= w; - } - } else { - m_in >> iformat(x) >> iformat(y) >> iformat(z); - if ( is_homogeneous()) { - float w; - m_in >> iformat(w); - x /= w; - y /= w; - z /= w; - } - } - } - } - void scan_normal( double& x, double& y, double& z) { - if ( has_normals()) { - normals_read = true; - if ( binary()) { - float fx, fy, fz; - I_Binary_read_big_endian_float32( m_in, fx); - I_Binary_read_big_endian_float32( m_in, fy); - I_Binary_read_big_endian_float32( m_in, fz); - if ( is_homogeneous()) { - float fw; - I_Binary_read_big_endian_float32( m_in, fw); - x = fx / fw; - y = fy / fw; - z = fz / fw; - } else { - x = fx; - y = fy; - z = fz; - } - } else { - if ( is_homogeneous()) { - float fx, fy, fz, fw; - m_in >> iformat(fx) >> iformat(fy) >> iformat(fz) >> iformat(fw); - x = fx / fw; - y = fy / fw; - z = fz / fw; - } else - m_in >> iformat(x) >> iformat(y) >> iformat(z); - } - } - } - void scan_normal( int& x, int& y, int& z) { - if ( has_normals()) { - normals_read = true; - if ( binary()) { - float fx, fy, fz; - I_Binary_read_big_endian_float32( m_in, fx); - I_Binary_read_big_endian_float32( m_in, fy); - I_Binary_read_big_endian_float32( m_in, fz); - if ( is_homogeneous()) { - float fw; - I_Binary_read_big_endian_float32( m_in, fw); - x = int( fx / fw); - y = int( fy / fw); - z = int( fz / fw); - } else { - x = int(fx); - y = int(fy); - z = int(fz); - } - } else { - if ( is_homogeneous()) { - float fx, fy, fz, fw; - m_in >> iformat(fx) >> iformat(fy) >> iformat(fz) >> iformat(fw); - x = int( fx / fw); - y = int( fy / fw); - z = int( fz / fw); - } else { - double d; - m_in >> iformat(d); - x = int(d); - m_in >> iformat(d); - y = int(d); - m_in >> iformat(d); - z = int(d); - } - } - } - } - - void scan_normal( float& x, float& y, float& z, float& w) { - w = 1; - if ( has_normals()) { - normals_read = true; - if ( binary()) { - I_Binary_read_big_endian_float32( m_in, x); - I_Binary_read_big_endian_float32( m_in, y); - I_Binary_read_big_endian_float32( m_in, z); - if ( is_homogeneous()) - I_Binary_read_big_endian_float32( m_in, w); - } else { - m_in >> iformat(x) >> iformat(y) >> iformat(z); - if ( is_homogeneous()) - m_in >> iformat(w); - } - } - } - void scan_normal( double& x, double& y, double& z, double& w) { - w = 1; - if ( has_normals()) { - normals_read = true; - if ( binary()) { - float f; - I_Binary_read_big_endian_float32( m_in, f); - x = f; - I_Binary_read_big_endian_float32( m_in, f); - y = f; - I_Binary_read_big_endian_float32( m_in, f); - z = f; - if ( is_homogeneous()) { - I_Binary_read_big_endian_float32( m_in, f); - w = f; - } - } else { - m_in >> iformat(x) >> iformat(y) >> iformat(z); - if ( is_homogeneous()) - m_in >> iformat(w); - } - } - } - void scan_normal( int& x, int& y, int& z, int& w) { - w = 1; - if ( has_normals()) { - normals_read = true; - if ( binary()) { - float f; - I_Binary_read_big_endian_float32( m_in, f); - x = int(f); - I_Binary_read_big_endian_float32( m_in, f); - y = int(f); - I_Binary_read_big_endian_float32( m_in, f); - z = int(f); - if ( is_homogeneous()) { - I_Binary_read_big_endian_float32( m_in, f); - w = int(f); - } - } else { - double d; - m_in >> iformat(d); - x = int(d); - m_in >> iformat(d); - y = int(d); - m_in >> iformat(d); - z = int(d); - if ( is_homogeneous()) { - m_in >> iformat(d); - w = int(d); - } - } - } - } - - static const Color& get_indexed_color(int id) - { - static const Color color[149] = { - Color(255, 255, 255, 191), - Color(255, 255, 255, 191), - Color(255, 255, 255, 191), - Color(255, 255, 255, 191), - Color(255, 255, 255, 191), - Color(255, 255, 255, 191), - Color(178, 38, 25, 191), - Color(51, 51, 204, 191), - Color(229, 153, 5, 191), - Color(25, 76, 204, 191), - Color(25, 178, 51, 191), - Color(204, 204, 102, 191), - Color(178, 178, 0, 191), - Color(178, 0, 178, 191), - Color(0, 178, 178, 191), - Color(229, 0, 51, 191), - Color(51, 229, 0, 191), - Color(0, 51, 229, 191), - Color(191, 191, 191, 191), - Color(204, 102, 0, 191), - Color(204, 102, 0, 191), - Color(0, 102, 204, 191), - Color(0, 102, 204, 191), - Color(0, 204, 102, 191), - Color(0, 204, 102, 191), - Color(102, 0, 204, 191), - Color(102, 0, 204, 191), - Color(204, 0, 102, 191), - Color(204, 0, 102, 191), - Color(178, 127, 51, 191), - Color(178, 127, 51, 191), - Color(178, 178, 0, 191), - Color(178, 0, 178, 191), - Color(0, 178, 178, 191), - Color(229, 0, 0, 191), - Color(0, 229, 0, 191), - Color(0, 0, 229, 191), - Color(191, 191, 191, 191), - Color(204, 102, 0, 191), - Color(102, 204, 0, 191), - Color(0, 102, 204, 191), - Color(0, 204, 102, 191), - Color(102, 0, 204, 191), - Color(204, 0, 102, 191), - Color(178, 178, 0, 191), - Color(178, 0, 178, 191), - Color(0, 178, 178, 191), - Color(229, 0, 0, 191), - Color(0, 229, 0, 191), - Color(0, 0, 229, 191), - Color(191, 191, 191, 191), - Color(204, 102, 0, 191), - Color(102, 204, 0, 191), - Color(0, 102, 204, 191), - Color(0, 204, 102, 191), - Color(102, 0, 204, 191), - Color(204, 0, 102, 191), - Color(178, 178, 0, 191), - Color(178, 0, 178, 191), - Color(0, 178, 178, 191), - Color(229, 0, 0, 191), - Color(0, 229, 0, 191), - Color(0, 0, 229, 191), - Color(191, 191, 191, 191), - Color(204, 102, 0, 191), - Color(102, 204, 0, 191), - Color(0, 102, 204, 191), - Color(0, 204, 102, 191), - Color(102, 0, 204, 191), - Color(204, 0, 102, 191), - Color(255, 255, 255, 191), - Color(255, 255, 255, 191), - Color(255, 255, 255, 191), - Color(255, 255, 255, 191), - Color(255, 255, 255, 191), - Color(255, 255, 255, 191), - Color(12, 76, 25, 191), - Color(178, 2, 25, 191), - Color(51, 12, 153, 191), - Color(229, 229, 5, 191), - Color(0, 51, 102, 191), - Color(25, 102, 102, 191), - Color(204, 204, 204, 191), - Color(178, 178, 0, 191), - Color(178, 178, 0, 191), - Color(178, 0, 178, 191), - Color(178, 0, 178, 191), - Color(0, 178, 178, 191), - Color(0, 178, 178, 191), - Color(229, 0, 0, 191), - Color(229, 0, 0, 191), - Color(0, 229, 0, 191), - Color(0, 229, 0, 191), - Color(0, 0, 229, 191), - Color(0, 0, 229, 191), - Color(191, 191, 191, 191), - Color(191, 191, 191, 191), - Color(204, 102, 0, 191), - Color(204, 102, 0, 191), - Color(0, 102, 204, 191), - Color(0, 102, 204, 191), - Color(0, 204, 102, 191), - Color(0, 204, 102, 191), - Color(102, 0, 204, 191), - Color(102, 0, 204, 191), - Color(204, 0, 102, 191), - Color(204, 0, 102, 191), - Color(178, 127, 51, 191), - Color(178, 127, 51, 191), - Color(178, 178, 0, 191), - Color(178, 0, 178, 191), - Color(0, 178, 178, 191), - Color(229, 0, 0, 191), - Color(0, 229, 0, 191), - Color(0, 0, 229, 191), - Color(191, 191, 191, 191), - Color(204, 102, 0, 191), - Color(102, 204, 0, 191), - Color(0, 102, 204, 191), - Color(0, 204, 102, 191), - Color(102, 0, 204, 191), - Color(204, 0, 102, 191), - Color(178, 178, 0, 191), - Color(178, 0, 178, 191), - Color(0, 178, 178, 191), - Color(229, 0, 0, 191), - Color(0, 229, 0, 191), - Color(0, 0, 229, 191), - Color(191, 191, 191, 191), - Color(204, 102, 0, 191), - Color(102, 204, 0, 191), - Color(0, 102, 204, 191), - Color(0, 204, 102, 191), - Color(102, 0, 204, 191), - Color(204, 0, 102, 191), - Color(178, 178, 0, 191), - Color(178, 0, 178, 191), - Color(0, 178, 178, 191), - Color(229, 0, 0, 191), - Color(0, 229, 0, 191), - Color(0, 0, 229, 191), - Color(191, 191, 191, 191), - Color(204, 102, 0, 191), - Color(102, 204, 0, 191), - Color(0, 102, 204, 191), - Color(0, 204, 102, 191), - Color(102, 0, 204, 191), - Color(204, 0, 102, 191), - Color(120, 120, 120, 120) }; - if(id > 148) id =148; - return color[id]; - } - - static CGAL::Color get_color_from_line(std::istream &is) - { - - std::string color_info; - bool is_float = false; - - std::string col; - //get the line content - std::getline(is, col); - //split it into strings - std::istringstream iss(col); - //holds the rgb values - unsigned char rgb[3]; - int index =0; - //split the string into numbers - while(iss>>color_info){ - //stop if comment is read - if(color_info.at(0) == '#') - break; - //detect if the value is float - for(int c = 0; c(color_info.length()); c++) - { - if(color_info.at(c) == '.') - { - is_float = true; - break; - } - } - //if the value is of float type, convert it into an int - if(is_float) - rgb[index] = static_cast(atof(color_info.c_str())*255); - //else stores the value - else - rgb[index] = static_cast(atoi(color_info.c_str())); - index++; - if(index == 3) - break; - } - CGAL::Color color; - //if there were only one number, fetch the color in the color map - if(index<2) - color = get_indexed_color(rgb[0]); - //else create the coor with the 3 values; - else - color = CGAL::Color(rgb[0], rgb[1], rgb[2]); - return color; - } - - void scan_color( unsigned char& r, unsigned char& g, unsigned char& b) { - if ( binary()) { - float fr, fg, fb; - I_Binary_read_big_endian_float32( m_in, fr); - I_Binary_read_big_endian_float32( m_in, fg); - I_Binary_read_big_endian_float32( m_in, fb); - r = (unsigned char)(fr); - g = (unsigned char)(fg); - b = (unsigned char)(fb); - - } else { - CGAL::Color color = get_color_from_line(m_in); - r = color.red(); - g = color.green(); - b = color.blue(); - } - } - - void skip_to_next_vertex( std::size_t current_vertex); - - void scan_facet( std::size_t& size, std::size_t CGAL_assertion_code(current_facet)) { - CGAL_assertion( current_facet < size_of_facets()); - if ( binary()){ - boost::int32_t i32; - I_Binary_read_big_endian_integer32( m_in, i32); - size = i32; - } else { - skip_comment(); - m_in >> size; - } - } - - void scan_facet_vertex_index( std::size_t& index, - std::size_t current_facet) { - if ( binary()){ - boost::int32_t i32; - I_Binary_read_big_endian_integer32( m_in, i32); - index = i32; - } else - m_in >> index; - - if( m_in.fail()) { - if ( verbose()) { - std::cerr << " " << std::endl; - std::cerr << "File_scanner_OFF::" << std::endl; - std::cerr << "scan_facet_vertex_index(): input error: " - "cannot read OFF file beyond facet " - << current_facet << "." << std::endl; - } - set_off_header( false); - return; - } - bool error = index < index_offset(); - index -= index_offset(); - - if(error || (index >= size_of_vertices())) { - m_in.clear( std::ios::failbit); - if ( verbose()) { - std::cerr << " " << std::endl; - std::cerr << "File_scanner_OFF::" << std::endl; - std::cerr << "scan_facet_vertex_index(): input error: " - "facet " << current_facet << ": vertex index " - << index + index_offset() << ": is out of range." - << std::endl; - } - set_off_header( false); - return; - } - } - - void skip_to_next_facet( std::size_t current_facet); -}; - -template < class Point> inline -Point& -file_scan_vertex( File_scanner_OFF& scanner, Point& p) { - typedef typename Point::R R; - typedef typename R::RT RT; - double x, y, z, w; - scanner.scan_vertex( x, y, z, w); - if ( w == 1) - p = Point( RT(x), RT(y), RT(z)); - else - p = Point( RT(x), RT(y), RT(z), RT(w)); - return p; -} - -template < class T_Color> inline -T_Color& -file_scan_color( File_scanner_OFF& scanner, T_Color& c) { - unsigned char r, g, b; - scanner.scan_color(r,g,b); - c = T_Color(r,g,b); - return c; -} - -template < class Vector> inline -Vector& -file_scan_normal( File_scanner_OFF& scanner, Vector& v) { - typedef typename Vector::R R; - typedef typename R::RT RT; - double x, y, z, w; - scanner.scan_normal( x, y, z, w); - if ( w == 1) - v = Vector( RT(x), RT(y), RT(z)); - else - v = Vector( RT(x), RT(y), RT(z), RT(w)); - return v; -} - -} //namespace CGAL - -#ifdef CGAL_HEADER_ONLY -#include -#endif // CGAL_HEADER_ONLY - +#define CGAL_DEPRECATED_HEADER "" +#define CGAL_REPLACEMENT_HEADER "" +#include +#include #include #endif // CGAL_IO_FILE_SCANNER_OFF_H // diff --git a/Stream_support/include/CGAL/IO/File_scanner_OFF_impl.h b/Stream_support/include/CGAL/IO/File_scanner_OFF_impl.h deleted file mode 100644 index 12eb77254f6..00000000000 --- a/Stream_support/include/CGAL/IO/File_scanner_OFF_impl.h +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright (c) 1997 -// Utrecht University (The Netherlands), -// ETH Zurich (Switzerland), -// INRIA Sophia-Antipolis (France), -// Max-Planck-Institute Saarbruecken (Germany), -// and Tel-Aviv University (Israel). All rights reserved. -// -// This file is part of CGAL (www.cgal.org); you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 3 of the License, -// or (at your option) any later version. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0+ -// -// -// Author(s) : Lutz Kettner - -#ifdef CGAL_HEADER_ONLY -#define CGAL_INLINE_FUNCTION inline -#else -#define CGAL_INLINE_FUNCTION -#endif - -#include -#include -#include -#include -#include - -namespace CGAL { - -CGAL_INLINE_FUNCTION -void -File_scanner_OFF:: -skip_to_next_vertex( std::size_t current_vertex) { - CGAL_assertion( current_vertex < size_of_vertices()); - if ( binary()) { - float f; - if ( has_normals() && ! normals_read) { - I_Binary_read_big_endian_float32( m_in, f); - I_Binary_read_big_endian_float32( m_in, f); - I_Binary_read_big_endian_float32( m_in, f); - if ( is_homogeneous()) - I_Binary_read_big_endian_float32( m_in, f); - } - if ( has_colors()) { - // It is not well stated in the Geomview manual - // how color is coded following a vertex. It is - // parsed similar to the optional color for facets. - boost::int32_t k; - I_Binary_read_big_endian_integer32( m_in, k); - if (k<0 || k>4) { - m_in.clear( std::ios::badbit); - if ( verbose()) { - std::cerr << " " << std::endl; - std::cerr << "File_scanner_OFF::" << std::endl; - std::cerr << "skip_to_next_vertex(): input error: bad " - " number of color indices at vertex " - << current_vertex << "." << std::endl; - } - set_off_header( false); - return; - } - while (k--) { - float dummy; - I_Binary_read_big_endian_float32( m_in, dummy); - } - } - } else { - if ( has_normals() && ! normals_read) { - double dummy; - if ( is_homogeneous()) { - m_in >> dummy >> dummy >> dummy >> dummy; - } else { - m_in >> dummy >> dummy >> dummy; - } - } - if ( has_colors()) { // skip color entries (1 to 4) - m_in >> skip_until_EOL; - } - } - if( ! m_in) { - if ( verbose()) { - std::cerr << " " << std::endl; - std::cerr << "File_scanner_OFF::" << std::endl; - std::cerr << "skip_to_next_vertex(): input error: cannot read " - "OFF file beyond vertex " << current_vertex << "." - << std::endl; - } - set_off_header( false); - return; - } - normals_read = false; -} - -CGAL_INLINE_FUNCTION -void -File_scanner_OFF:: -skip_to_next_facet( std::size_t current_facet) { - // Take care of trailing informations like color triples. - if ( binary()) { - boost::int32_t k; - I_Binary_read_big_endian_integer32( m_in, k); - if (k<0 || k>4) { - m_in.clear( std::ios::badbit); - if ( verbose()) { - std::cerr << " " << std::endl; - std::cerr << "File_scanner_OFF::" << std::endl; - std::cerr << "skip_to_next_facet(): input error: bad " - "number of color indices at vertex " - << current_facet << "." << std::endl; - } - set_off_header( false); - return; - } - while (k--) { - float dummy; - I_Binary_read_big_endian_float32( m_in, dummy); - } - } else { - m_in >> skip_until_EOL; - } -} - -} //namespace CGAL -// EOF // diff --git a/Stream_support/include/CGAL/IO/File_writer_OFF.h b/Stream_support/include/CGAL/IO/File_writer_OFF.h index bb49a8c93a8..17328f8e7b5 100644 --- a/Stream_support/include/CGAL/IO/File_writer_OFF.h +++ b/Stream_support/include/CGAL/IO/File_writer_OFF.h @@ -26,89 +26,13 @@ #ifndef CGAL_IO_FILE_WRITER_OFF_H #define CGAL_IO_FILE_WRITER_OFF_H 1 -#include -#include -#include -#include +#include -namespace CGAL { - -class CGAL_EXPORT File_writer_OFF { - std::ostream* m_out; - File_header_OFF m_header; -public: - File_writer_OFF( bool verbose = false) : m_header( verbose) {} - File_writer_OFF( const File_header_OFF& h) : m_header( h) {} - - std::ostream& out() { return *m_out; } - File_header_OFF& header() { return m_header; } - const File_header_OFF& header() const { return m_header; } - - void write_header( std::ostream& out, - std::size_t vertices, - std::size_t halfedges, - std::size_t facets, - bool normals = false); - void write_footer() { - if ( m_header.ascii() && m_header.comments()) - out() << "\n\n# End of OFF #"; - out() << std::endl; - } - void write_vertex( const double& x, const double& y, const double& z) { - if ( m_header.binary()) { - I_Binary_write_big_endian_float32( out(), float(x)); - I_Binary_write_big_endian_float32( out(), float(y)); - I_Binary_write_big_endian_float32( out(), float(z)); - } else { - out() << '\n' << x << ' ' << y << ' ' << z; - } - } - void write_normal( const double& x, const double& y, const double& z) { - if ( m_header.binary()) { - I_Binary_write_big_endian_float32( out(), float(x)); - I_Binary_write_big_endian_float32( out(), float(y)); - I_Binary_write_big_endian_float32( out(), float(z)); - } else { - out() << ' ' << ' ' << x << ' ' << y << ' ' << z; - } - } - void write_facet_header() { - if ( m_header.ascii()) { - if ( m_header.no_comments()) - out() << '\n'; - else { - out() << "\n\n# " << m_header.size_of_facets() - << " facets\n"; - out() << "# ------------------------------------------" - "\n\n"; - } - } - } - void write_facet_begin( std::size_t no) { - if ( m_header.binary()) - I_Binary_write_big_endian_integer32( out(), static_cast(no)); - else - out() << no << ' '; - } - void write_facet_vertex_index( std::size_t index) { - if ( m_header.binary()) - I_Binary_write_big_endian_integer32( out(), static_cast(index)); - else - out() << ' ' << index; - } - void write_facet_end() { - if ( m_header.binary()) - I_Binary_write_big_endian_integer32( out(), 0); - else - out() << '\n'; - } -}; - -} //namespace CGAL - -#ifdef CGAL_HEADER_ONLY -#include -#endif // CGAL_HEADER_ONLY +#define CGAL_DEPRECATED_HEADER "" +#define CGAL_REPLACEMENT_HEADER "" +#include +#include +#include #endif // CGAL_IO_FILE_WRITER_OFF_H // // EOF // diff --git a/Stream_support/include/CGAL/IO/File_writer_OFF_impl.h b/Stream_support/include/CGAL/IO/File_writer_OFF_impl.h deleted file mode 100644 index 216953e9036..00000000000 --- a/Stream_support/include/CGAL/IO/File_writer_OFF_impl.h +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) 1997 -// Utrecht University (The Netherlands), -// ETH Zurich (Switzerland), -// INRIA Sophia-Antipolis (France), -// Max-Planck-Institute Saarbruecken (Germany), -// and Tel-Aviv University (Israel). All rights reserved. -// -// This file is part of CGAL (www.cgal.org); you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 3 of the License, -// or (at your option) any later version. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0+ -// -// -// Author(s) : Lutz Kettner - -#ifdef CGAL_HEADER_ONLY -#define CGAL_INLINE_FUNCTION inline -#else -#define CGAL_INLINE_FUNCTION -#endif - -#include -#include -#include - -namespace CGAL { - -CGAL_INLINE_FUNCTION -void -File_writer_OFF:: -write_header( std::ostream& o, - std::size_t vertices, - std::size_t halfedges, - std::size_t facets, - bool normals) { - m_out = &o; - m_header.set_vertices( vertices); - // Don't. This halfdges aren't trusted: - // m_header.set_halfedges( halfedges); - (void)halfedges; - m_header.set_facets( facets); - m_header.set_normals( normals); - // Print header. - out() << m_header; -} -} //namespace CGAL -// EOF // diff --git a/Stream_support/include/CGAL/IO/File_writer_wavefront.h b/Stream_support/include/CGAL/IO/File_writer_wavefront.h index 941173989ae..30e8bdfbaf5 100644 --- a/Stream_support/include/CGAL/IO/File_writer_wavefront.h +++ b/Stream_support/include/CGAL/IO/File_writer_wavefront.h @@ -26,41 +26,13 @@ #ifndef CGAL_IO_FILE_WRITER_WAVEFRONT_H #define CGAL_IO_FILE_WRITER_WAVEFRONT_H 1 -#include -#include -#include +#include -namespace CGAL { - -class CGAL_EXPORT File_writer_wavefront { - std::ostream* m_out; - std::size_t m_facets; -public: - std::ostream& out() const { return *m_out; } - void write_header( std::ostream& out, - std::size_t vertices, - std::size_t halfedges, - std::size_t facets); - void write_footer() const { - out() << "\n# End of Wavefront obj format #" << std::endl; - } - void write_vertex( const double& x, const double& y, const double& z) { - out() << "v " << x << ' ' << y << ' ' << z << '\n'; - } - void write_facet_header() { - out() << "\n# " << m_facets << " facets\n"; - out() << "# ------------------------------------------\n\n"; - } - void write_facet_begin( std::size_t) { out() << "f "; } - void write_facet_vertex_index( std::size_t idx) { out() << ' ' << idx+1; } - void write_facet_end() { out() << '\n'; } -}; - -} //namespace CGAL - -#ifdef CGAL_HEADER_ONLY -#include -#endif // CGAL_HEADER_ONLY +#define CGAL_DEPRECATED_HEADER "" +#define CGAL_REPLACEMENT_HEADER "" +#include +#include +#include #endif // CGAL_IO_FILE_WRITER_WAVEFRONT_H // // EOF // diff --git a/Stream_support/include/CGAL/IO/File_writer_wavefront_impl.h b/Stream_support/include/CGAL/IO/File_writer_wavefront_impl.h deleted file mode 100644 index 745bbb1acd1..00000000000 --- a/Stream_support/include/CGAL/IO/File_writer_wavefront_impl.h +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 1997 -// Utrecht University (The Netherlands), -// ETH Zurich (Switzerland), -// INRIA Sophia-Antipolis (France), -// Max-Planck-Institute Saarbruecken (Germany), -// and Tel-Aviv University (Israel). All rights reserved. -// -// This file is part of CGAL (www.cgal.org); you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 3 of the License, -// or (at your option) any later version. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0+ -// -// -// Author(s) : Lutz Kettner - -#ifdef CGAL_HEADER_ONLY -#define CGAL_INLINE_FUNCTION inline -#else -#define CGAL_INLINE_FUNCTION -#endif - -#include -#include -#include - -namespace CGAL { - -CGAL_INLINE_FUNCTION -void -File_writer_wavefront:: -write_header( std::ostream& o, - std::size_t vertices, - std::size_t halfedges, - std::size_t facets){ - m_out = &o; - m_facets = facets; - // Print header. - out() << "# file written from a CGAL tool in Wavefront obj format\n"; - out() << "# " << vertices << " vertices\n"; - out() << "# " << halfedges << " halfedges\n"; - out() << "# " << facets << " facets\n\n"; - - out() << "\n# " << vertices << " vertices\n"; - out() << "# ------------------------------------------\n\n"; -} - -} //namespace CGAL -// EOF // diff --git a/Stream_support/include/CGAL/IO/Scanner_OFF.h b/Stream_support/include/CGAL/IO/Scanner_OFF.h deleted file mode 100644 index 6a7550829fe..00000000000 --- a/Stream_support/include/CGAL/IO/Scanner_OFF.h +++ /dev/null @@ -1,308 +0,0 @@ -// Copyright (c) 1997,2005 -// Utrecht University (The Netherlands), -// ETH Zurich (Switzerland), -// INRIA Sophia-Antipolis (France), -// Max-Planck-Institute Saarbruecken (Germany), -// and Tel-Aviv University (Israel). All rights reserved. -// -// This file is part of CGAL (www.cgal.org); you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 3 of the License, -// or (at your option) any later version. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0+ -// -// -// Author(s) : Lutz Kettner -// Ralf Osbild - -#ifndef CGAL_IO_SCANNER_OFF_H -#define CGAL_IO_SCANNER_OFF_H 1 - -#include -#include -#include -#include -#include -#include - -namespace CGAL { - -// The Facet_iterator's value type is vector -// that contains the vertex indices. - -template -class I_Scanner_OFF_vertex_iterator -{ -public: - typedef std::input_iterator_tag iterator_category; - typedef Pt value_type; - typedef std::ptrdiff_t difference_type; - typedef const Pt* pointer; - typedef const Pt& reference; -private: - File_scanner_OFF* m_scan; - std::size_t m_cnt; - Pt m_point; - - void next_vertex() { - CGAL_assertion( m_scan != nullptr); - if ( m_cnt < m_scan->size_of_vertices()) { - file_scan_vertex( *m_scan, m_point); - m_scan->skip_to_next_vertex( m_cnt); - ++m_cnt; - } else - m_cnt = m_scan->size_of_vertices() + 1; - } -public: - typedef Pt Point; - typedef File_scanner_OFF Scanner; - typedef I_Scanner_OFF_vertex_iterator Self; - - I_Scanner_OFF_vertex_iterator(std::size_t cnt) : m_scan(0), m_cnt(cnt+1) {} - I_Scanner_OFF_vertex_iterator( Scanner& s, int cnt) - : m_scan(&s), m_cnt(cnt) - { - next_vertex(); - } - std::size_t count() const { return m_cnt; } - bool operator==( const Self& i) const { return m_cnt == i.m_cnt; } - bool operator!=( const Self& i) const { return m_cnt != i.m_cnt; } - Self& operator++() { - next_vertex(); - return *this; - } - Self operator++(int) { - Self tmp = *this; - ++(*this); - return tmp; - } - const Point& operator*() const { - CGAL_assertion( m_scan != nullptr); - return m_point; - } - const Point* operator->() const { return & operator*(); } -}; - -template -class I_Scanner_OFF_vertex_and_normals_iterator -{ -public: - typedef Pt Point; - typedef Nrm Normal; - typedef File_scanner_OFF Scanner; - typedef I_Scanner_OFF_vertex_and_normals_iterator Self; - - typedef std::input_iterator_tag iterator_category; - typedef std::pair value_type; - typedef std::ptrdiff_t difference_type; - typedef const value_type* pointer; - typedef const value_type& reference; -private: - File_scanner_OFF* m_scan; - std::size_t m_cnt; - value_type m_current; - - - void next() { - CGAL_assertion( m_scan != nullptr); - if ( m_cnt < m_scan->size_of_vertices()) { - file_scan_vertex( *m_scan, m_current.first); - if ( m_scan->has_normals()) - file_scan_normal( *m_scan, m_current.second); - m_scan->skip_to_next_vertex( m_cnt); - ++m_cnt; - } else - m_cnt = m_scan->size_of_vertices() + 1; - } -public: - - I_Scanner_OFF_vertex_and_normals_iterator( int cnt) - : m_scan(0), m_cnt(cnt+1) {} - I_Scanner_OFF_vertex_and_normals_iterator( Scanner& s, int cnt) - : m_scan(&s), m_cnt(cnt) - { - next(); - } - std::size_t count() const { return m_cnt; } - bool operator==( const Self& i) const { return m_cnt == i.m_cnt; } - bool operator!=( const Self& i) const { return m_cnt != i.m_cnt; } - Self& operator++() { - next(); - return *this; - } - Self operator++(int) { - Self tmp = *this; - ++(*this); - return tmp; - } - reference operator*() const { - CGAL_assertion( m_scan != nullptr); - return m_current; - } - pointer operator->() const { return & operator*(); } -}; - -class I_Scanner_OFF_facet_iterator -{ -public: - typedef std::input_iterator_tag iterator_category; - typedef std::vector value_type; - typedef std::ptrdiff_t difference_type; - typedef value_type* pointer; - typedef value_type& reference; -private: - File_scanner_OFF* m_scan; - std::size_t m_cnt; - value_type m_indices; - - void next_facet() { - CGAL_assertion( m_scan != nullptr); - if ( m_cnt < m_scan->size_of_facets()) { - m_indices.erase( m_indices.begin(), m_indices.end()); - std::size_t no; - m_scan->scan_facet( no, m_cnt); - m_indices.reserve( no); - std::size_t index = (std::numeric_limits::max)(); - // A huge value helps to detect a potential - // error in the function scan_facet_vertex_index - for (std::size_t i = 0; i < no; ++i) { - m_scan->scan_facet_vertex_index( index, m_cnt); - m_indices.push_back( index); - } - m_scan->skip_to_next_facet( m_cnt); - ++ m_cnt; - } else - m_cnt = m_scan->size_of_facets() + 1; - } -public: - value_type::size_type size_of_indices () const // RO - { return m_indices.size(); } - typedef value_type::size_type indices_size_type; // RO -public: - typedef File_scanner_OFF Scanner; - typedef I_Scanner_OFF_facet_iterator Self; - typedef value_type::iterator iterator; - - I_Scanner_OFF_facet_iterator( std::size_t cnt) : m_scan(0), m_cnt(cnt+1) {} - I_Scanner_OFF_facet_iterator( Scanner& s, std::size_t cnt) - : m_scan(&s), m_cnt(cnt) - { - next_facet(); - } - std::size_t count() const { return m_cnt; } - bool operator==( const Self& i) const { return m_cnt == i.m_cnt; } - bool operator!=( const Self& i) const { return m_cnt != i.m_cnt; } - Self& operator++() { - next_facet(); - return *this; - } - Self operator++(int) { - Self tmp = *this; - ++(*this); - return tmp; - } - value_type& operator*() { - CGAL_assertion( m_scan != nullptr); - return m_indices; - } - const value_type& operator*() const { - CGAL_assertion( m_scan != nullptr); - return m_indices; - } - value_type* operator->() { return & operator*(); } - const value_type* operator->() const { return & operator*(); } -}; - - -// The distance function is implemented to work in -// constant time for both iterators. - -template inline -void distance( const I_Scanner_OFF_vertex_iterator& first, - const I_Scanner_OFF_vertex_iterator& last, - Distance& n) { - n = Distance( last.count() - first.count()); -} -template inline -void distance( const I_Scanner_OFF_facet_iterator& first, - const I_Scanner_OFF_facet_iterator& last, - Distance& n) { - n = Distance( last.count() - first.count()); -} -template inline -std::ptrdiff_t distance( const I_Scanner_OFF_vertex_iterator& first, - const I_Scanner_OFF_vertex_iterator& last) { - return last.count() - first.count(); -} - -inline -std::ptrdiff_t distance( const I_Scanner_OFF_facet_iterator& first, - const I_Scanner_OFF_facet_iterator& last) { - return last.count() - first.count(); -} - - -template -class Scanner_OFF { - File_scanner_OFF m_scan; -public: - typedef typename Kernel::Point_3 Point; - typedef Point Pt; - typedef typename Kernel::Vector_3 Normal; - typedef Scanner_OFF Self; - typedef I_Scanner_OFF_vertex_iterator Vertex_iterator; - typedef I_Scanner_OFF_vertex_and_normals_iterator - Vertex_and_normals_iterator; - typedef I_Scanner_OFF_facet_iterator Facet_iterator; - typedef I_Scanner_OFF_facet_iterator::iterator Index_iterator; - - Scanner_OFF( std::istream& in, bool verbose = false) - : m_scan( in, verbose) {} - Scanner_OFF( std::istream& in, const File_header_OFF& header) - : m_scan( in, header) {} - - std::size_t size_of_vertices() const { return m_scan.size_of_vertices(); } - std::size_t size_of_halfedges() const { return m_scan.size_of_halfedges();} - std::size_t size_of_facets() const { return m_scan.size_of_facets(); } - - bool verbose() const { return m_scan.verbose(); } - bool skel() const { return m_scan.skel(); } - bool off() const { return m_scan.off(); } - bool binary() const { return m_scan.binary(); } - bool ascii() const { return m_scan.ascii(); } - - bool has_colors() const { return m_scan.has_colors(); } - bool has_normals() const { return m_scan.has_normals(); } - - File_header_OFF& header() { return m_scan; } - const File_header_OFF& - header() const { return m_scan; } - - Vertex_iterator vertices_begin(){ return Vertex_iterator( m_scan,0);} - Vertex_iterator vertices_end() { - return Vertex_iterator( size_of_vertices()); - } - Facet_iterator facets_begin() { return Facet_iterator( m_scan,0); } - Facet_iterator facets_end() { - return Facet_iterator( size_of_facets()); - } - Vertex_and_normals_iterator vertices_and_normals_begin(){ - return Vertex_and_normals_iterator( m_scan,0); - } - Vertex_and_normals_iterator vertices_and_normals_end() { - return Vertex_and_normals_iterator( size_of_vertices()); - } -}; - -} //namespace CGAL -#endif // CGAL_IO_SCANNER_OFF_H // -// EOF // diff --git a/Stream_support/include/CGAL/IO/WKT.h b/Stream_support/include/CGAL/IO/WKT.h index 536a4386d19..127b0985131 100644 --- a/Stream_support/include/CGAL/IO/WKT.h +++ b/Stream_support/include/CGAL/IO/WKT.h @@ -46,14 +46,14 @@ namespace CGAL{ template -std::istream& +bool read_point_WKT( std::istream& in, Point& point) { if(!in) { std::cerr << "Error: cannot open file" << std::endl; - return in; + return false; } std::string line; @@ -65,22 +65,28 @@ read_point_WKT( std::istream& in, if(type.substr(0, 5).compare("POINT")==0) { - boost::geometry::read_wkt(line, point); + try{ + boost::geometry::read_wkt(line, point); + } catch(...) + { + std::cerr<<"error."< -std::istream& +bool read_multi_point_WKT( std::istream& in, MultiPoint& mp) { if(!in) { std::cerr << "Error: cannot open file" << std::endl; - return in; + return false; } internal::Geometry_container gc(mp); std::string line; @@ -92,23 +98,28 @@ read_multi_point_WKT( std::istream& in, if(type.substr(0, 10).compare("MULTIPOINT")==0) { - boost::geometry::read_wkt(line, gc); + try{ + boost::geometry::read_wkt(line, gc); + } catch(...){ + std::cerr<<"error."< -std::istream& +bool read_linestring_WKT( std::istream& in, LineString& polyline) { if(!in) { std::cerr << "Error: cannot open file" << std::endl; - return in; + return false; } internal::Geometry_container gc(polyline); std::string line; @@ -120,22 +131,27 @@ read_linestring_WKT( std::istream& in, if(type.substr(0, 10).compare("LINESTRING")==0) { - boost::geometry::read_wkt(line, gc); + try{ + boost::geometry::read_wkt(line, gc); + } catch(...){ + std::cerr<<"error."< -std::istream& +bool read_multi_linestring_WKT( std::istream& in, MultiLineString& mls) { if(!in) { std::cerr << "Error: cannot open file" << std::endl; - return in; + return false; } typedef typename MultiLineString::value_type PointRange; typedef internal::Geometry_container LineString; @@ -151,7 +167,12 @@ read_multi_linestring_WKT( std::istream& in, if(type.substr(0, 15).compare("MULTILINESTRING")==0) { - boost::geometry::read_wkt(line, gc); + try{ + boost::geometry::read_wkt(line, gc); + } catch(...){ + std::cerr<<"error."< -std::istream& +bool read_polygon_WKT( std::istream& in, Polygon& polygon ) @@ -171,7 +192,7 @@ read_polygon_WKT( std::istream& in, if(!in) { std::cerr << "Error: cannot open file" << std::endl; - return in; + return false; } std::string line; @@ -183,15 +204,20 @@ read_polygon_WKT( std::istream& in, if(type.substr(0, 7).compare("POLYGON")==0) { - boost::geometry::read_wkt(line, polygon); + try{ + boost::geometry::read_wkt(line, polygon); + } catch(...){ + std::cerr<<"error."< -std::istream& +bool read_multi_polygon_WKT( std::istream& in, MultiPolygon& polygons ) @@ -199,7 +225,7 @@ read_multi_polygon_WKT( std::istream& in, if(!in) { std::cerr << "Error: cannot open file" << std::endl; - return in; + return false; } internal::Geometry_container gc(polygons); std::string line; @@ -211,11 +237,16 @@ read_multi_polygon_WKT( std::istream& in, if(type.substr(0, 12).compare("MULTIPOLYGON")==0) { - boost::geometry::read_wkt(line, gc); + try{ + boost::geometry::read_wkt(line, gc); + } catch(...){ + std::cerr<<"error."< diff --git a/Stream_support/include/CGAL/IO/generic_copy_OFF.h b/Stream_support/include/CGAL/IO/generic_copy_OFF.h index a2185e51ff8..e722e840dbe 100644 --- a/Stream_support/include/CGAL/IO/generic_copy_OFF.h +++ b/Stream_support/include/CGAL/IO/generic_copy_OFF.h @@ -26,78 +26,14 @@ #ifndef CGAL_IO_GENERIC_COPY_OFF_H #define CGAL_IO_GENERIC_COPY_OFF_H 1 -#include -#include -#include -#include -#include -namespace CGAL { +#include -template -void -generic_copy_OFF( File_scanner_OFF& scanner, - std::ostream& out, - Writer& writer) { - std::istream& in = scanner.in(); - // scans a polyhedral surface in OFF from `in' and writes it - // to `out' in the format provided by `writer'. - if ( ! in) { - if ( scanner.verbose()) { - std::cerr << " " << std::endl; - std::cerr << "generic_copy_OFF(): " - "input error: file format is not in OFF." - << std::endl; - } - return; - } +#define CGAL_DEPRECATED_HEADER "" +#define CGAL_REPLACEMENT_HEADER "" +#include +#include +#include - // Print header. Number of halfedges is only trusted if it is - // a polyhedral surface. - writer.write_header( out, - scanner.size_of_vertices(), - scanner.polyhedral_surface() ? - scanner.size_of_halfedges() : 0, - scanner.size_of_facets()); - - // read in all vertices - double x, y, z; // Point coordinates. - std::size_t i; - for ( i = 0; i < scanner.size_of_vertices(); i++) { - scanner.scan_vertex( x, y, z); - writer.write_vertex( x, y, z); - scanner.skip_to_next_vertex( i); - } - - // read in all facets - writer.write_facet_header(); - for ( i = 0; i < scanner.size_of_facets(); i++) { - if ( ! in) - return; - std::size_t no; - scanner.scan_facet( no, i); - writer.write_facet_begin( no); - for ( std::size_t j = 0; j < no; j++) { - std::size_t index; - scanner.scan_facet_vertex_index( index, i); - writer.write_facet_vertex_index( index); - } - writer.write_facet_end(); - scanner.skip_to_next_facet( i); - } - writer.write_footer(); -} - -template -void -generic_copy_OFF( std::istream& in, std::ostream& out, Writer& writer, - bool verbose = false) { - // scans a polyhedral surface in OFF from `in' and writes it - // to `out' in the format provided by `writer'. - File_scanner_OFF scanner( in, verbose); - generic_copy_OFF( scanner, out, writer); -} - -} //namespace CGAL -#endif // CGAL_IO_GENERIC_COPY_OFF_H // +#endif // CGAL_IO_OFF_GENERIC_COPY_OFF_H // // EOF // diff --git a/Stream_support/test/Stream_support/test_read_WKT.cpp b/Stream_support/test/Stream_support/test_read_WKT.cpp index 0b550d76f34..5728ac3f41c 100644 --- a/Stream_support/test/Stream_support/test_read_WKT.cpp +++ b/Stream_support/test/Stream_support/test_read_WKT.cpp @@ -28,42 +28,48 @@ int main() Point p; { std::ifstream in("data/point.wkt"); - CGAL::read_point_WKT(in, p); + if(! CGAL::read_point_WKT(in, p)) + return 1; in.close(); CGAL_assertion(p == Point(2,3)); } { std::ifstream in("data/linestring.wkt"); Linestring ls; - CGAL::read_linestring_WKT(in, ls); + if(!CGAL::read_linestring_WKT(in, ls)) + return 1; in.close(); CGAL_assertion(ls.size() == 3); } { Polygon poly; std::ifstream in("data/polygon.wkt"); - CGAL::read_polygon_WKT(in, poly); + if(!CGAL::read_polygon_WKT(in, poly)) + return 1; in.close(); CGAL_assertion(poly.outer_boundary().size() == 3); } { MultiPoint pees; std::ifstream in("data/multipoint.wkt"); - CGAL::read_multi_point_WKT(in, pees); + if(!CGAL::read_multi_point_WKT(in, pees)) + return 1; in.close(); CGAL_assertion(pees.size() == 4); } { std::ifstream in("data/multilinestring.wkt"); MultiLinestring mls; - CGAL::read_multi_linestring_WKT(in, mls); + if(!CGAL::read_multi_linestring_WKT(in, mls)) + return 1; in.close(); CGAL_assertion(mls.size() == 2); } { MultiPolygon polies; std::ifstream in("data/multipolygon.wkt"); - CGAL::read_multi_polygon_WKT(in, polies); + if(!CGAL::read_multi_polygon_WKT(in, polies)) + return 1; in.close(); CGAL_assertion(polies.size() == 2); } From 0a38d237646ed4a2543f351d84a4b9f289a4299f Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Wed, 7 Aug 2019 15:12:50 +0200 Subject: [PATCH 02/28] Add all missing files. Enable the STL_reader to read multiple "solid"s in a same soup. --- .../CGAL/IO/OBJ/File_writer_wavefront.h | 66 ++ .../CGAL/IO/OBJ/File_writer_wavefront_impl.h | 58 ++ .../include/CGAL/IO/OBJ/OBJ_reader.h | 86 +++ .../include/CGAL/IO/OBJ/print_wavefront.h | 56 ++ Stream_support/include/CGAL/IO/OFF.h | 59 ++ .../include/CGAL/IO/OFF/File_header_OFF.h | 126 ++++ .../CGAL/IO/OFF/File_header_OFF_impl.h | 406 ++++++++++ .../CGAL/IO/OFF/File_header_extended_OFF.h | 138 ++++ .../IO/OFF/File_header_extended_OFF_impl.h | 213 ++++++ .../include/CGAL/IO/OFF/File_scanner_OFF.h | 707 ++++++++++++++++++ .../CGAL/IO/OFF/File_scanner_OFF_impl.h | 134 ++++ .../include/CGAL/IO/OFF/File_writer_OFF.h | 114 +++ .../CGAL/IO/OFF/File_writer_OFF_impl.h | 57 ++ .../include/CGAL/IO/OFF/OFF_reader.h | 150 ++++ .../include/CGAL/IO/OFF/Polyhedron_scan_OFF.h | 159 ++++ .../include/CGAL/IO/OFF/Scanner_OFF.h | 308 ++++++++ .../include/CGAL/IO/OFF/generic_copy_OFF.h | 103 +++ .../include/CGAL/IO/OFF/print_OFF.h | 100 +++ Stream_support/include/CGAL/IO/OFF/scan_OFF.h | 68 ++ .../include/CGAL/IO/PLY/PLY_reader.h | 348 +++++++++ .../include/CGAL/IO/PLY/PLY_writer.h | 169 +++++ .../include/CGAL/IO/STL/STL_reader.h | 385 ++++++++++ .../include/CGAL/IO/STL/STL_writer.h | 98 +++ .../CGAL/IO/VRML/Polyhedron_VRML_1_ostream.h | 32 + .../CGAL/IO/VRML/Polyhedron_VRML_2_ostream.h | 51 ++ .../include/CGAL/IO/VRML/print_VRML_1.h | 53 ++ .../include/CGAL/IO/VRML/print_VRML_2.h | 53 ++ 27 files changed, 4297 insertions(+) create mode 100644 Stream_support/include/CGAL/IO/OBJ/File_writer_wavefront.h create mode 100644 Stream_support/include/CGAL/IO/OBJ/File_writer_wavefront_impl.h create mode 100644 Stream_support/include/CGAL/IO/OBJ/OBJ_reader.h create mode 100644 Stream_support/include/CGAL/IO/OBJ/print_wavefront.h create mode 100644 Stream_support/include/CGAL/IO/OFF.h create mode 100644 Stream_support/include/CGAL/IO/OFF/File_header_OFF.h create mode 100644 Stream_support/include/CGAL/IO/OFF/File_header_OFF_impl.h create mode 100644 Stream_support/include/CGAL/IO/OFF/File_header_extended_OFF.h create mode 100644 Stream_support/include/CGAL/IO/OFF/File_header_extended_OFF_impl.h create mode 100644 Stream_support/include/CGAL/IO/OFF/File_scanner_OFF.h create mode 100644 Stream_support/include/CGAL/IO/OFF/File_scanner_OFF_impl.h create mode 100644 Stream_support/include/CGAL/IO/OFF/File_writer_OFF.h create mode 100644 Stream_support/include/CGAL/IO/OFF/File_writer_OFF_impl.h create mode 100644 Stream_support/include/CGAL/IO/OFF/OFF_reader.h create mode 100644 Stream_support/include/CGAL/IO/OFF/Polyhedron_scan_OFF.h create mode 100644 Stream_support/include/CGAL/IO/OFF/Scanner_OFF.h create mode 100644 Stream_support/include/CGAL/IO/OFF/generic_copy_OFF.h create mode 100644 Stream_support/include/CGAL/IO/OFF/print_OFF.h create mode 100644 Stream_support/include/CGAL/IO/OFF/scan_OFF.h create mode 100644 Stream_support/include/CGAL/IO/PLY/PLY_reader.h create mode 100644 Stream_support/include/CGAL/IO/PLY/PLY_writer.h create mode 100644 Stream_support/include/CGAL/IO/STL/STL_reader.h create mode 100644 Stream_support/include/CGAL/IO/STL/STL_writer.h create mode 100644 Stream_support/include/CGAL/IO/VRML/Polyhedron_VRML_1_ostream.h create mode 100644 Stream_support/include/CGAL/IO/VRML/Polyhedron_VRML_2_ostream.h create mode 100644 Stream_support/include/CGAL/IO/VRML/print_VRML_1.h create mode 100644 Stream_support/include/CGAL/IO/VRML/print_VRML_2.h diff --git a/Stream_support/include/CGAL/IO/OBJ/File_writer_wavefront.h b/Stream_support/include/CGAL/IO/OBJ/File_writer_wavefront.h new file mode 100644 index 00000000000..fed6e243c82 --- /dev/null +++ b/Stream_support/include/CGAL/IO/OBJ/File_writer_wavefront.h @@ -0,0 +1,66 @@ +// Copyright (c) 1997 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// +// Author(s) : Lutz Kettner + +#ifndef CGAL_IO_OBJ_FILE_WRITER_WAVEFRONT_H +#define CGAL_IO_OBJ_FILE_WRITER_WAVEFRONT_H 1 + +#include +#include +#include + +namespace CGAL { + +class CGAL_EXPORT File_writer_wavefront { + std::ostream* m_out; + std::size_t m_facets; +public: + std::ostream& out() const { return *m_out; } + void write_header( std::ostream& out, + std::size_t vertices, + std::size_t halfedges, + std::size_t facets); + void write_footer() const { + out() << "\n# End of Wavefront obj format #" << std::endl; + } + void write_vertex( const double& x, const double& y, const double& z) { + out() << "v " << x << ' ' << y << ' ' << z << '\n'; + } + void write_facet_header() { + out() << "\n# " << m_facets << " facets\n"; + out() << "# ------------------------------------------\n\n"; + } + void write_facet_begin( std::size_t) { out() << "f "; } + void write_facet_vertex_index( std::size_t idx) { out() << ' ' << idx+1; } + void write_facet_end() { out() << '\n'; } +}; + +} //namespace CGAL + +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + +#endif // CGAL_IO_OBJ_FILE_WRITER_WAVEFRONT_H // +// EOF // diff --git a/Stream_support/include/CGAL/IO/OBJ/File_writer_wavefront_impl.h b/Stream_support/include/CGAL/IO/OBJ/File_writer_wavefront_impl.h new file mode 100644 index 00000000000..ddea81642d5 --- /dev/null +++ b/Stream_support/include/CGAL/IO/OBJ/File_writer_wavefront_impl.h @@ -0,0 +1,58 @@ +// Copyright (c) 1997 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// +// Author(s) : Lutz Kettner + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include +#include +#include + +namespace CGAL { + +CGAL_INLINE_FUNCTION +void +File_writer_wavefront:: +write_header( std::ostream& o, + std::size_t vertices, + std::size_t halfedges, + std::size_t facets){ + m_out = &o; + m_facets = facets; + // Print header. + out() << "# file written from a CGAL tool in Wavefront obj format\n"; + out() << "# " << vertices << " vertices\n"; + out() << "# " << halfedges << " halfedges\n"; + out() << "# " << facets << " facets\n\n"; + + out() << "\n# " << vertices << " vertices\n"; + out() << "# ------------------------------------------\n\n"; +} + +} //namespace CGAL +// EOF // diff --git a/Stream_support/include/CGAL/IO/OBJ/OBJ_reader.h b/Stream_support/include/CGAL/IO/OBJ/OBJ_reader.h new file mode 100644 index 00000000000..660917d8681 --- /dev/null +++ b/Stream_support/include/CGAL/IO/OBJ/OBJ_reader.h @@ -0,0 +1,86 @@ +// Copyright (c) 2016 GeometryFactory +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// Author(s) : Andreas Fabri and Maxime Gimeno + +#ifndef CGAL_IO_OBJ_OBJ_READER_H +#define CGAL_IO_OBJ_OBJ_READER_H + +#include +#include +#include +#include + + +namespace CGAL { + +template +bool +read_OBJ( std::istream& input, + std::vector &points, + std::vector > &faces) +{ + int mini(1), + maxi(-INT_MAX); + Point_3 p; + std::string line; + while(getline(input, line)) { + if(line[0] == 'v' && line[1] == ' ') { + std::istringstream iss(line.substr(1)); + iss >> p; + if(!iss) + return false; + points.push_back(p); + } + else if(line[0] == 'f') { + std::istringstream iss(line.substr(1)); + int i; + faces.push_back( std::vector() ); + while(iss >> i) + { + if(i < 1) + { + faces.back().push_back(points.size()+i);//negative indices are relative references + if(i maxi) + maxi = i-1; + } + iss.ignore(256, ' '); + } + if(!iss.good() && !iss.eof()) + return false; + } + else + { + //std::cerr<<"ERROR : Cannnot read line beginning with "< points.size() || mini < -static_cast(points.size())){ + std::cerr<<"a face index is invalid "< + +#ifndef CGAL_IO_OBJ_PRINT_WAVEFRONT_H +#define CGAL_IO_OBJ_PRINT_WAVEFRONT_H 1 + +#include + + +#include +#include +#include +#include + +namespace CGAL { + +template +void print_polyhedron_wavefront( std::ostream& out, const Polyhedron& P) { + File_writer_wavefront writer; + generic_print_polyhedron( out, P, writer); +} + +// Deprecated global functions, replaced with functions above + +template < class Traits, + class Items, + template < class T, class I, class A> + class HDS, class Alloc> +void +print_wavefront( std::ostream& out, + const Polyhedron_3& P) { + File_writer_wavefront writer; + generic_print_polyhedron( out, P, writer); +} + +} //namespace CGAL +#endif // CGAL_IO_OBJ_PRINT_WAVEFRONT_H // +// EOF // diff --git a/Stream_support/include/CGAL/IO/OFF.h b/Stream_support/include/CGAL/IO/OFF.h new file mode 100644 index 00000000000..25d50a96444 --- /dev/null +++ b/Stream_support/include/CGAL/IO/OFF.h @@ -0,0 +1,59 @@ +// Copyright (c) 2015 GeometryFactory +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// Author(s) : Laurent Rineau and Sebastien Loriot + +#ifndef CGAL_IO_OFF_H +#define CGAL_IO_OFF_H + +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace CGAL { + +template +bool +read_OFF( std::istream& in, + std::vector< Point_3 >& points, + std::vector< Polygon_3 >& polygons, + bool /* verbose */ = false) +{ + return OFF_internal::read_OFF(in, points, polygons); +} + +template +bool +read_OFF( std::istream& in, + std::vector< Point_3 >& points, + std::vector< Polygon_3 >& polygons, + std::vector& fcolors, + std::vector& vcolors, + bool /* verbose */ = false) +{ + return OFF_internal::read_OFF(in, points, polygons, fcolors, vcolors); +} + +} // namespace CGAL + +#endif // CGAL_IO_OFF_H diff --git a/Stream_support/include/CGAL/IO/OFF/File_header_OFF.h b/Stream_support/include/CGAL/IO/OFF/File_header_OFF.h new file mode 100644 index 00000000000..802404c2ec0 --- /dev/null +++ b/Stream_support/include/CGAL/IO/OFF/File_header_OFF.h @@ -0,0 +1,126 @@ +// Copyright (c) 1997 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// +// Author(s) : Lutz Kettner + + +#ifndef CGAL_IO_OFF_FILE_HEADER_OFF_H +#define CGAL_IO_OFF_FILE_HEADER_OFF_H 1 + +#include +#include + +namespace CGAL { + +// Info structure for OFF file headers +// =================================== +class CGAL_EXPORT File_header_OFF : public File_header_extended_OFF { +private: + // Publicly accessible file informations. + std::size_t n_vertices; + std::size_t n_facets; + bool m_skel; // SKEL format instead of OFF. + bool m_binary; // OFF in binary format. + bool m_no_comments; // no comments in output. + std::size_t m_offset; // index offset for vertices, usually 0. + + // Publicly accessible but not that well supported file informations. + bool m_colors; // COFF detected. + bool m_normals; // NOFF format stores also normals at vertices. + + // More privately used file informations to scan the file. + bool m_tag4; // 4OFF detected. + bool m_tagDim; // nOFF detected (will not be supported). + int m_dim; // dimension for nOFF (will not be supported). +public: + typedef File_header_OFF Self; + typedef File_header_extended_OFF Base; + + explicit File_header_OFF( bool verbose = false); + File_header_OFF( bool binary, bool noc, bool skel, + bool verbose = false); + //File_header_OFF( int v, int h, int f, bool verbose = false); + File_header_OFF( std::size_t v, std::size_t h, std::size_t f, + bool binary, bool noc, bool skel, + bool verbose = false); + File_header_OFF( const File_header_extended_OFF& ext_header); + File_header_OFF( const File_header_extended_OFF& ext_header, + bool binary, bool noc, bool skel); + File_header_OFF( std::size_t v, std::size_t h, std::size_t f, + const File_header_extended_OFF& ext_header); + File_header_OFF( std::size_t v, std::size_t h, std::size_t f, + const File_header_extended_OFF& ext_header, + bool binary, bool noc, bool skel); + + Self& operator= ( const Base& base) { (Base&)(*this) = base; + return *this; + } + std::size_t size_of_vertices() const { return n_vertices; } + std::size_t size_of_facets() const { return n_facets; } + + bool skel() const { return m_skel; } // SKEL format. + bool off() const { return ! m_skel; } // OFF format. + bool binary() const { return m_binary; } // binary format. + bool ascii() const { return ! m_binary; } // ASCII format. + bool no_comments() const { return m_no_comments; } + bool comments() const { return ! m_no_comments; } + + std::size_t index_offset() const { return m_offset; } + bool has_colors() const { return m_colors; } // COFF detected. + bool has_normals() const { return m_normals;} // NOFF format. + bool is_homogeneous() const { return m_tag4; } // 4OFF detected. + // nOFF detected. (will not be supported). + bool n_dimensional() const { return m_tagDim; } + // dimension for nOFF (will not be supported). + int dimension() const { return m_dim; } + + void set_vertices( std::size_t n) { n_vertices = n; } + void set_facets( std::size_t n) { n_facets = n; } + + void set_skel( bool b) { m_skel = b; } + void set_binary( bool b) { m_binary = b; } + void set_no_comments( bool b) { m_no_comments = b; } + void set_index_offset( std::size_t i) { m_offset = i; } + + void set_colors( bool b) { m_colors = b; } + void set_normals( bool b) { m_normals = b;} + void set_homogeneous( bool b) { m_tag4 = b; } + void set_dimensional( bool b) { m_tagDim = b; } + void set_dimension( int i) { m_dim = i; } + Self& operator+=( const Self& header); +}; + +// Write header. +CGAL_EXPORT std::ostream& operator<<( std::ostream& out, const File_header_OFF& h); + +// Scan header. Marks streams badbit if not in SKEL format nor in OFF. +CGAL_EXPORT std::istream& operator>>( std::istream& in, File_header_OFF& h); + +} //namespace CGAL + +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + +#endif // CGAL_IO_OFF_FILE_HEADER_OFF_H // +// EOF // diff --git a/Stream_support/include/CGAL/IO/OFF/File_header_OFF_impl.h b/Stream_support/include/CGAL/IO/OFF/File_header_OFF_impl.h new file mode 100644 index 00000000000..3572261bd7a --- /dev/null +++ b/Stream_support/include/CGAL/IO/OFF/File_header_OFF_impl.h @@ -0,0 +1,406 @@ +// Copyright (c) 1997 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// +// Author(s) : Lutz Kettner + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace CGAL { + +CGAL_INLINE_FUNCTION +File_header_OFF::File_header_OFF( bool verbose) +: File_header_extended_OFF( verbose), + n_vertices(0), + n_facets(0), + m_skel(false), + m_binary(false), + m_no_comments(false), + m_offset(0), + m_colors(false), + m_normals(false), + m_tag4(false), + m_tagDim(false), + m_dim(3) +{} +CGAL_INLINE_FUNCTION +File_header_OFF::File_header_OFF( + bool binary, bool noc, bool skel, bool verbose) +: File_header_extended_OFF( verbose), + n_vertices(0), + n_facets(0), + m_skel(skel), + m_binary(binary), + m_no_comments(noc), + m_offset(0), + m_colors(false), + m_normals(false), + m_tag4(false), + m_tagDim(false), + m_dim(3) +{} +//CGAL_INLINE_FUNCTION +//File_header_OFF::File_header_OFF( int v, int h, int f, +// bool verbose) +//: File_header_extended_OFF( verbose), +// n_vertices(v), +// n_facets(f), +// m_skel(false), +// m_binary(false), +// m_no_comments(false), +// m_offset(0), +// m_colors(false), +// m_normals(false), +// m_tag4(false), +// m_tagDim(false), +// m_dim(3) +//{ +// set_halfedges(h); +//} +CGAL_INLINE_FUNCTION +File_header_OFF::File_header_OFF( std::size_t v, std::size_t h, std::size_t f, + bool binary, bool noc, bool skel, bool verbose) +: File_header_extended_OFF( verbose), + n_vertices(v), + n_facets(f), + m_skel(skel), + m_binary(binary), + m_no_comments(noc), + m_offset(0), + m_colors(false), + m_normals(false), + m_tag4(false), + m_tagDim(false), + m_dim(3) +{ + set_halfedges(h); +} +CGAL_INLINE_FUNCTION +File_header_OFF::File_header_OFF( + const File_header_extended_OFF& ext_header) +: File_header_extended_OFF( ext_header), + n_vertices(0), + n_facets(0), + m_skel(false), + m_binary(false), + m_no_comments(false), + m_offset(0), + m_colors(false), + m_normals(false), + m_tag4(false), + m_tagDim(false), + m_dim(3) +{} +CGAL_INLINE_FUNCTION +File_header_OFF::File_header_OFF( + const File_header_extended_OFF& ext_header, + bool binary, bool noc, bool skel) +: File_header_extended_OFF( ext_header), + n_vertices(0), + n_facets(0), + m_skel(skel), + m_binary(binary), + m_no_comments(noc), + m_offset(0), + m_colors(false), + m_normals(false), + m_tag4(false), + m_tagDim(false), + m_dim(3) +{} +CGAL_INLINE_FUNCTION +File_header_OFF::File_header_OFF( + std::size_t v, std::size_t h, std::size_t f, + const File_header_extended_OFF& ext_header) +: File_header_extended_OFF( ext_header), + n_vertices(v), + n_facets(f), + m_skel(false), + m_binary(false), + m_no_comments(false), + m_offset(0), + m_colors(false), + m_normals(false), + m_tag4(false), + m_tagDim(false), + m_dim(3) +{ + set_halfedges(h); +} +CGAL_INLINE_FUNCTION +File_header_OFF::File_header_OFF( + std::size_t v, std::size_t h, std::size_t f, + const File_header_extended_OFF& ext_header, + bool binary, bool noc, bool skel) +: File_header_extended_OFF( ext_header), + n_vertices(v), + n_facets(f), + m_skel(skel), + m_binary(binary), + m_no_comments(noc), + m_offset(0), + m_colors(false), + m_normals(false), + m_tag4(false), + m_tagDim(false), + m_dim(3) +{ + set_halfedges(h); +} + +CGAL_INLINE_FUNCTION +File_header_OFF& File_header_OFF:: +operator+=( const File_header_OFF& header) { + (File_header_extended_OFF&)(*this) = header; + n_vertices += header.n_vertices; + n_facets += header.n_facets; + return *this; +} + +// Write header. +CGAL_INLINE_FUNCTION +std::ostream& operator<<( std::ostream& out, const File_header_OFF& h) { + if ( h.comments()) { + out << "# Output of a CGAL tool\n"; + out << static_cast( h); + } + if ( h.has_normals()) + out << 'N'; + if ( h.skel()) + out << "SKEL"; + else + out << "OFF"; + if ( h.binary()) { + out << " BINARY\n"; + I_Binary_write_big_endian_integer32( out, static_cast(h.size_of_vertices())); + I_Binary_write_big_endian_integer32( out, static_cast(h.size_of_facets())); + if ( h.off()) + I_Binary_write_big_endian_integer32( out, 0); + } else { + out << '\n'; + out << h.size_of_vertices() << ' '<< h.size_of_facets(); + if ( h.off()) + out << " 0"; + if ( h.comments()) { + out << "\n\n# " << h.size_of_vertices() << " vertices\n"; + out << "# ------------------------------------------\n"; + } + out << std::endl; + } + return out; +} + +// Scan header. Marks streams badbit if not in SKEL format nor in OFF. +CGAL_INLINE_FUNCTION +std::istream& operator>>( std::istream& in, File_header_OFF& h) { + // read in the first character and scan for comments, `OFF', or `NOFF', + // or `SKEL', or `4SKEL'. + h.set_off_header( false); + char c; + while ( (in >> c) && c == '#') { + if ( in.get(c) && c == 'C' && + in.get(c) && c == 'B' && + in.get(c) && c == 'P') { + in >> static_cast( h); + } else if ( c != '\n') + in >> skip_until_EOL; + } + if ( ! in) + return in; + h.set_skel( false); + h.set_binary( false); + h.set_index_offset( 1); + h.set_colors( false); + h.set_normals( false); + h.set_homogeneous( false); + h.set_dimensional( false); + h.set_dimension( 3); + + const int max_keyword = 42; + char keyword[max_keyword] = ""; + int i = 0; + keyword[i++] = c; + while( i < max_keyword - 1 && in.get(c) && std::isalnum(c)) + keyword[i++] = c; + keyword[i] = '\0'; + if ( i < 2 || (std::isdigit(keyword[0]) && keyword[0] != '4') + || std::isdigit(keyword[1])) { + h.set_vertices( std::atoi( keyword)); + } else { + h.set_index_offset( 0); + int j = 0; + if ( j < i && keyword[j] == 'C') { + h.set_colors( true); + j++; + } + if ( j < i && keyword[j] == 'N') { + h.set_normals( true); + j++; + } + if ( j < i && keyword[j] == '4') { + h.set_homogeneous( true); + j++; + } + if ( j < i && keyword[j] == 'n') { + h.set_dimensional( true); + j++; + } + if ( i-j != 3 || keyword[j] != 'O' + || keyword[j+1] != 'F' + || keyword[j+2] != 'F') { + if ( i-j != 4 || keyword[j] != 'S' + || keyword[j+1] != 'K' + || keyword[j+2] != 'E' + || keyword[j+3] != 'L') { + in.clear( std::ios::badbit); + if ( h.verbose()) { + std::cerr << " " << std::endl; + std::cerr << "error: File_header_OFF: " + "wrong format: neither OFF nor SKEL." + << std::endl; + } + return in; + } else { + h.set_skel( true); + } + } + in >> skip_comment_OFF >> c; + if ( std::isdigit(c)) { + in.putback(c); + int n; + in >> n; + h.set_vertices(n); + } else { + i = 0; + keyword[i++] = c; + while( i < max_keyword - 1 && in.get(c) && + std::isalnum(c)) + keyword[i++] = c; + keyword[i] = '\0'; + if ( std::strcmp( keyword, "BINARY") == 0) { + h.set_binary( true); + if ( c != '\n') + in >> skip_until_EOL; + } else { + in.clear( std::ios::badbit); + if ( h.verbose()) { + std::cerr << " " << std::endl; + std::cerr << "error: File_header_OFF(): " + "wrong format: neither OFF nor SKEL." + << std::endl; + } + return in; + } + } + } + // Read remaining size value(s). + int n_h; + if ( h.binary()) { + boost::int32_t a, b, c; + I_Binary_read_big_endian_integer32( in, a); + if ( h.n_dimensional()) { + h.set_dimension( a); + I_Binary_read_big_endian_integer32( in, a); + } + I_Binary_read_big_endian_integer32( in, b); + if ( h.off()) + I_Binary_read_big_endian_integer32( in, c); + else + c = 0; + h.set_vertices( a); + if (b<0){ + in.clear( std::ios::badbit ); + if ( h.verbose()) { + std::cerr << " " << std::endl; + std::cerr << "error: File_header_OFF(): File contains < 0 facets." + << std::endl; + } + return in; + } + h.set_facets( b); + n_h = c; + } else { + int n; + if ( h.n_dimensional()) { + h.set_dimension( static_cast(h.size_of_vertices())); + in >> n; + h.set_vertices(n); + } + in >> n; + if (n < 0){ + in.clear( std::ios::badbit ); + if ( h.verbose()) { + std::cerr << " " << std::endl; + std::cerr << "error: File_header_OFF(): File contains < 0 facets." + << std::endl; + } + return in; + } + h.set_facets(n); + if ( h.off()) + in >> n_h; + else + n_h = 0; + } + if ( n_h == 0) + h.set_index_offset( 0); + if ( ! in ) { + return in; + } + if ( h.size_of_halfedges() == 0) { + // be careful, because border edges count twice + h.set_halfedges( 2 * n_h); + // check against the Eulerian equation for connected planar graphs. + // We do not know the number of holes we must represent as dummy + // facets and we do not know the genus of the surface. + // So we add 12 and a factor of 5 percent. + if ( h.size_of_halfedges() == 0 + || double(h.size_of_halfedges()) > double(h.size_of_vertices() + + h.size_of_facets() - 2 + 12) * 2.1 + || h.size_of_halfedges() < (h.size_of_vertices() + + h.size_of_facets() - 2) * 2 + ) + h.set_halfedges( int( double(h.size_of_vertices() + + h.size_of_facets() - 2 + 12) * 2.1 + ) + ); + } + h.set_off_header( h.off()); + return in; +} + +} //namespace CGAL +// EOF // diff --git a/Stream_support/include/CGAL/IO/OFF/File_header_extended_OFF.h b/Stream_support/include/CGAL/IO/OFF/File_header_extended_OFF.h new file mode 100644 index 00000000000..204a7444c9f --- /dev/null +++ b/Stream_support/include/CGAL/IO/OFF/File_header_extended_OFF.h @@ -0,0 +1,138 @@ +// Copyright (c) 1997 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// +// Author(s) : Lutz Kettner + + +#ifndef CGAL_IO_OFF_FILE_HEADER_EXTENDED_OFF_H +#define CGAL_IO_OFF_FILE_HEADER_EXTENDED_OFF_H 1 + +#include + +#include +#include + + +namespace CGAL { + +class CGAL_EXPORT File_header_extended_OFF { + bool m_verbose; // Print error messages if true. + bool m_polyhedral_surface; + std::size_t m_halfedges; + bool m_triangulated; + bool m_non_empty_facets; + bool m_terrain; + bool m_normalized_to_sphere; + double m_radius; + bool m_rounded; + int m_rounded_bits; + bool m_off_header; +public: + typedef File_header_extended_OFF Self; + File_header_extended_OFF( bool verbose = false) + : m_verbose ( verbose), + m_polyhedral_surface ( false), + m_halfedges ( 0), + m_triangulated ( false), + m_non_empty_facets ( false), + m_terrain ( false), + m_normalized_to_sphere ( false), + m_radius ( 0.0), + m_rounded ( false), + m_rounded_bits ( 0), + m_off_header ( true) + {} + // Access: + bool verbose() const { return m_verbose; } + bool polyhedral_surface() const { return m_polyhedral_surface; } + std::size_t halfedges() const { return m_halfedges; } + std::size_t size_of_halfedges() const { return m_halfedges; } + bool triangulated() const { return m_triangulated; } + bool non_empty_facets() const { return m_non_empty_facets; } + bool terrain() const { return m_terrain; } + bool normalized_to_sphere() const { return m_normalized_to_sphere; } + double radius() const { return m_radius; } + bool rounded() const { return m_rounded; } + int rounded_bits() const { return m_rounded_bits; } + bool off_header() const { return m_off_header; } + // Derived predicates about the file format. + bool is_OFF() const { return m_off_header; } + bool is_POL() const; + bool is_CBP() const; + bool is_TRN() const; + int is_CBPn() const; + int is_TRNn() const; + // The proper file suffix with respect to file format. + std::string suffix() const; + // The proper format name. + std::string format_name() const; + // Set values: + void set_verbose( bool b) { m_verbose = b; } + void set_polyhedral_surface( bool b) { m_polyhedral_surface = b; } + void set_halfedges( std::size_t h) { m_halfedges = h; } + void set_triangulated( bool b) { m_triangulated = b; } + void set_non_empty_facets( bool b) { m_non_empty_facets = b; } + void set_terrain( bool b) { m_terrain = b; } + void set_normalized_to_sphere( bool b) { m_normalized_to_sphere = b;} + void set_radius( double d) { m_radius = d; } + void set_rounded( bool b) { m_rounded = b; } + void set_rounded_bits( int i) { m_rounded_bits = i; } + void set_off_header( bool b) { m_off_header = b; } + Self& operator+=( const Self& header); // union of two headers +}; + +// Write extended header incl. CGAL/ENDCBP keywords. +std::ostream& operator<<( std::ostream& out, + const File_header_extended_OFF& h); + +// Scan extended header. The CBP keyword must be read already. +std::istream& operator>>( std::istream& in, File_header_extended_OFF& h); + +// istream modifier skips chars until end of line. +inline std::istream& skip_until_EOL( std::istream& in) { + if(in.eof()){ + return in; + } + char c; + while ( in.get(c) && c != '\n') + ; + return in; +} + +// istream modifier that checks for OFF comments and removes them. +inline std::istream& skip_comment_OFF( std::istream& in) { + char c; + while( (in >> c) && c == '#') + in >> skip_until_EOL; + in.putback(c); + return in; +} + +} //namespace CGAL + +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + +#endif // CGAL_IO_OFF_FILE_HEADER_EXTENDED_OFF_H // +// EOF // diff --git a/Stream_support/include/CGAL/IO/OFF/File_header_extended_OFF_impl.h b/Stream_support/include/CGAL/IO/OFF/File_header_extended_OFF_impl.h new file mode 100644 index 00000000000..b61623d88e6 --- /dev/null +++ b/Stream_support/include/CGAL/IO/OFF/File_header_extended_OFF_impl.h @@ -0,0 +1,213 @@ +// Copyright (c) 1997 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// +// Author(s) : Lutz Kettner + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include +#include + +#include +#include +#include +#include +#include +#include + + +namespace CGAL { + +CGAL_INLINE_FUNCTION +bool File_header_extended_OFF:: +is_POL() const { + return is_OFF() && polyhedral_surface(); +} + +CGAL_INLINE_FUNCTION +bool File_header_extended_OFF:: +is_CBP() const { + return is_POL() && triangulated() && non_empty_facets() && + normalized_to_sphere() && radius() <= 1.0; +} + +CGAL_INLINE_FUNCTION +bool File_header_extended_OFF:: +is_TRN() const { return is_CBP() && terrain(); } + +CGAL_INLINE_FUNCTION +int File_header_extended_OFF:: +is_CBPn() const { + if ( is_POL() && triangulated() && non_empty_facets() && + normalized_to_sphere() && rounded() && + (radius() <= double( 1l << rounded_bits()))) + return rounded_bits(); + else + return 0; +} + +CGAL_INLINE_FUNCTION +int File_header_extended_OFF:: +is_TRNn() const { return ( terrain() ? is_CBPn() : 0); } + + +// The proper file suffix with respect to file format. +CGAL_INLINE_FUNCTION +std::string File_header_extended_OFF:: +suffix() const { + if ( is_TRNn()) { + std::ostringstream out; + out << "trn" << m_rounded_bits << '\0'; + return out.str(); + } + if ( is_TRN()) + return std::string("trn"); + if ( is_CBPn()) { + std::ostringstream out; + out << "cbp" << m_rounded_bits << '\0'; + return out.str(); + } + if ( is_CBP()) + return std::string("cbp"); + if ( is_POL()) + return std::string("pol"); + return std::string("off"); +} + +// The proper format name. +CGAL_INLINE_FUNCTION +std::string File_header_extended_OFF:: +format_name() const { + if ( is_TRNn()) { + std::ostringstream out; + out << "TRN" << m_rounded_bits << '\0'; + return out.str(); + } + if ( is_TRN()) + return std::string("TRN"); + if ( is_CBPn()) { + std::ostringstream out; + out << "CBP" << m_rounded_bits << '\0'; + return out.str(); + } + if ( is_CBP()) + return std::string("CBP"); + if ( is_POL()) + return std::string("POL"); + return std::string("OFF"); +} + +CGAL_INLINE_FUNCTION +File_header_extended_OFF& File_header_extended_OFF:: +operator+=( const File_header_extended_OFF& header) { + m_verbose = m_verbose || header.m_verbose; + m_polyhedral_surface = m_polyhedral_surface && + header.m_polyhedral_surface; + m_halfedges += header.m_halfedges; + m_triangulated = m_triangulated && header.m_triangulated; + m_non_empty_facets = m_non_empty_facets && + header.m_non_empty_facets; + m_terrain = m_terrain && header.m_terrain; + m_normalized_to_sphere = m_normalized_to_sphere && + header.m_normalized_to_sphere; + m_radius = (std::max)(m_radius, header.m_radius); + m_rounded = m_rounded && header.m_rounded; + m_rounded_bits = (std::max)( m_rounded_bits, + header.m_rounded_bits); + m_off_header = m_off_header && header.m_off_header; + return *this; +} + +#define CGAL_OUT(item) out << "# " #item " " << h.item() << '\n' +#define CGAL_OUTBOOL(item) out << "# " #item " " <<(h.item() ? '1':'0') << '\n' + +// Write extended header incl. CGAL/ENDCBP keywords. +CGAL_INLINE_FUNCTION +std::ostream& operator<<( std::ostream& out, + const File_header_extended_OFF& h) { + out << "#CBP\n"; + CGAL_OUTBOOL( polyhedral_surface); + CGAL_OUT( halfedges); + CGAL_OUTBOOL( triangulated); + CGAL_OUTBOOL( non_empty_facets); + CGAL_OUTBOOL( terrain); + CGAL_OUTBOOL( normalized_to_sphere); + CGAL_OUT( radius); + CGAL_OUTBOOL( rounded); + CGAL_OUT( rounded_bits); + out << "# ENDCBP\n" << std::endl; + return out; +} +#undef CGAL_OUT +#undef OUTBOOL + +#define CGAL_IN(item,type) \ + else if ( std::strcmp( keyword, #item) == 0) { \ + type t; \ + in >> t; \ + h.set_##item( t); \ + } + +#define CGAL_INBOOL(item) \ + else if ( std::strcmp( keyword, #item) == 0) { \ + in >> c; \ + h.set_##item( c == '1'); \ + } + +// Scan extended header. The CBP keyword must be read already. +CGAL_INLINE_FUNCTION +std::istream& operator>>( std::istream& in, File_header_extended_OFF& h) { + const int max_keyword = 42; + char c; + char keyword[max_keyword] = ""; + in >> keyword; + while ( in && std::strcmp( keyword, "ENDCBP") != 0) { + if ( std::strcmp( keyword, "#") == 0) + ; + CGAL_INBOOL( polyhedral_surface) + CGAL_IN( halfedges, int) + CGAL_INBOOL( triangulated) + CGAL_INBOOL( non_empty_facets) + CGAL_INBOOL( terrain) + CGAL_INBOOL( normalized_to_sphere) + CGAL_IN( radius, double) + CGAL_INBOOL( rounded) + CGAL_IN( rounded_bits, int) + else if ( h.verbose()) { + std::cerr << "warning: File_header_extended_OFF: unknown key '" + << keyword << "'." << std::endl; + } + in >> keyword; + } + in >> skip_until_EOL >> skip_comment_OFF; + return in; +} +#undef CGAL_IN +#undef CGAL_INBOOL + +} //namespace CGAL +// EOF // diff --git a/Stream_support/include/CGAL/IO/OFF/File_scanner_OFF.h b/Stream_support/include/CGAL/IO/OFF/File_scanner_OFF.h new file mode 100644 index 00000000000..2a6d5267f29 --- /dev/null +++ b/Stream_support/include/CGAL/IO/OFF/File_scanner_OFF.h @@ -0,0 +1,707 @@ +// Copyright (c) 1997 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// +// Author(s) : Lutz Kettner + +#ifndef CGAL_IO_OFF_FILE_SCANNER_OFF_H +#define CGAL_IO_OFF_FILE_SCANNER_OFF_H 1 + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace CGAL { + +class CGAL_EXPORT File_scanner_OFF : public File_header_OFF { + std::istream& m_in; + bool normals_read; + void skip_comment() { m_in >> skip_comment_OFF; } +public: + File_scanner_OFF( std::istream& in, bool verbose = false) + : File_header_OFF(verbose), m_in(in), normals_read(false) { + in >> static_cast( *this); + } + File_scanner_OFF( std::istream& in, const File_header_OFF& header) + : File_header_OFF(header), m_in(in), normals_read(false) {} + + std::istream& in() { return m_in; } + + // The scan_vertex() routine is provided for multiple + // coordinate types to support parameterized polytopes. + void scan_vertex( float& x, float& y, float& z) { + if ( binary()) { + I_Binary_read_big_endian_float32( m_in, x); + I_Binary_read_big_endian_float32( m_in, y); + I_Binary_read_big_endian_float32( m_in, z); + if ( is_homogeneous()) { + float w; + I_Binary_read_big_endian_float32( m_in, w); + x /= w; + y /= w; + z /= w; + } + } else { + skip_comment(); + m_in >> iformat(x) >> iformat(y) >> iformat(z); + if ( is_homogeneous()) { + float w; + m_in >> iformat(w); + x /= w; + y /= w; + z /= w; + } + } + } + void scan_vertex( double& x, double& y, double& z) { + if ( binary()) { + float f; + I_Binary_read_big_endian_float32( m_in, f); + x = f; + I_Binary_read_big_endian_float32( m_in, f); + y = f; + I_Binary_read_big_endian_float32( m_in, f); + z = f; + if ( is_homogeneous()) { + I_Binary_read_big_endian_float32( m_in, f); + x /= f; + y /= f; + z /= f; + } + } else { + skip_comment(); + m_in >> iformat(x) >> iformat(y) >> iformat(z); + if ( is_homogeneous()) { + double w; + m_in >> iformat(w); + x /= w; + y /= w; + z /= w; + } + } + } + void scan_vertex( int& x, int& y, int& z) { + if ( binary()) { + float fx, fy, fz; + I_Binary_read_big_endian_float32( m_in, fx); + I_Binary_read_big_endian_float32( m_in, fy); + I_Binary_read_big_endian_float32( m_in, fz); + if ( is_homogeneous()) { + float fw; + I_Binary_read_big_endian_float32( m_in, fw); + x = int( fx / fw); + y = int( fy / fw); + z = int( fz / fw); + } else { + x = int(fx); + y = int(fy); + z = int(fz); + } + } else { + skip_comment(); + if ( is_homogeneous()) { + double fx, fy, fz, fw; + m_in >> iformat(fx) >> iformat(fy) >> iformat(fz) >> iformat(fw); + x = int( fx / fw); + y = int( fy / fw); + z = int( fz / fw); + } else { + double d; + m_in >> iformat(d); + x = int(d); + m_in >> iformat(d); + y = int(d); + m_in >> iformat(d); + z = int(d); + } + } + } + + void scan_vertex( float& x, float& y, float& z, float& w) { + w = 1; + if ( binary()) { + I_Binary_read_big_endian_float32( m_in, x); + I_Binary_read_big_endian_float32( m_in, y); + I_Binary_read_big_endian_float32( m_in, z); + if ( is_homogeneous()) + I_Binary_read_big_endian_float32( m_in, w); + } else { + skip_comment(); + m_in >> iformat(x) >> iformat(y) >> iformat(z); + if ( is_homogeneous()) + m_in >> iformat(w); + } + } + void scan_vertex( double& x, double& y, double& z, double& w) { + w = 1; + if ( binary()) { + float f; + I_Binary_read_big_endian_float32( m_in, f); + x = f; + I_Binary_read_big_endian_float32( m_in, f); + y = f; + I_Binary_read_big_endian_float32( m_in, f); + z = f; + if ( is_homogeneous()) { + I_Binary_read_big_endian_float32( m_in, f); + w = f; + } + } else { + skip_comment(); + m_in >> iformat(x); + m_in >> iformat(y); + m_in >> iformat(z); + if ( is_homogeneous()) + m_in >> iformat(w); + } + } + void scan_vertex( int& x, int& y, int& z, int& w) { + w = 1; + if ( binary()) { + float f; + I_Binary_read_big_endian_float32( m_in, f); + x = int(f); + I_Binary_read_big_endian_float32( m_in, f); + y = int(f); + I_Binary_read_big_endian_float32( m_in, f); + z = int(f); + if ( is_homogeneous()) { + I_Binary_read_big_endian_float32( m_in, f); + w = int(f); + } + } else { + skip_comment(); + double d; + m_in >> iformat(d); + x = int(d); + m_in >> iformat(d); + y = int(d); + m_in >> iformat(d); + z = int(d); + if ( is_homogeneous()) { + m_in >> iformat(d); + w = int(d); + } + } + } + + void scan_normal( float& x, float& y, float& z) { + if ( has_normals()) { + normals_read = true; + if ( binary()) { + I_Binary_read_big_endian_float32( m_in, x); + I_Binary_read_big_endian_float32( m_in, y); + I_Binary_read_big_endian_float32( m_in, z); + if ( is_homogeneous()) { + float w; + I_Binary_read_big_endian_float32( m_in, w); + x /= w; + y /= w; + z /= w; + } + } else { + m_in >> iformat(x) >> iformat(y) >> iformat(z); + if ( is_homogeneous()) { + float w; + m_in >> iformat(w); + x /= w; + y /= w; + z /= w; + } + } + } + } + void scan_normal( double& x, double& y, double& z) { + if ( has_normals()) { + normals_read = true; + if ( binary()) { + float fx, fy, fz; + I_Binary_read_big_endian_float32( m_in, fx); + I_Binary_read_big_endian_float32( m_in, fy); + I_Binary_read_big_endian_float32( m_in, fz); + if ( is_homogeneous()) { + float fw; + I_Binary_read_big_endian_float32( m_in, fw); + x = fx / fw; + y = fy / fw; + z = fz / fw; + } else { + x = fx; + y = fy; + z = fz; + } + } else { + if ( is_homogeneous()) { + float fx, fy, fz, fw; + m_in >> iformat(fx) >> iformat(fy) >> iformat(fz) >> iformat(fw); + x = fx / fw; + y = fy / fw; + z = fz / fw; + } else + m_in >> iformat(x) >> iformat(y) >> iformat(z); + } + } + } + void scan_normal( int& x, int& y, int& z) { + if ( has_normals()) { + normals_read = true; + if ( binary()) { + float fx, fy, fz; + I_Binary_read_big_endian_float32( m_in, fx); + I_Binary_read_big_endian_float32( m_in, fy); + I_Binary_read_big_endian_float32( m_in, fz); + if ( is_homogeneous()) { + float fw; + I_Binary_read_big_endian_float32( m_in, fw); + x = int( fx / fw); + y = int( fy / fw); + z = int( fz / fw); + } else { + x = int(fx); + y = int(fy); + z = int(fz); + } + } else { + if ( is_homogeneous()) { + float fx, fy, fz, fw; + m_in >> iformat(fx) >> iformat(fy) >> iformat(fz) >> iformat(fw); + x = int( fx / fw); + y = int( fy / fw); + z = int( fz / fw); + } else { + double d; + m_in >> iformat(d); + x = int(d); + m_in >> iformat(d); + y = int(d); + m_in >> iformat(d); + z = int(d); + } + } + } + } + + void scan_normal( float& x, float& y, float& z, float& w) { + w = 1; + if ( has_normals()) { + normals_read = true; + if ( binary()) { + I_Binary_read_big_endian_float32( m_in, x); + I_Binary_read_big_endian_float32( m_in, y); + I_Binary_read_big_endian_float32( m_in, z); + if ( is_homogeneous()) + I_Binary_read_big_endian_float32( m_in, w); + } else { + m_in >> iformat(x) >> iformat(y) >> iformat(z); + if ( is_homogeneous()) + m_in >> iformat(w); + } + } + } + void scan_normal( double& x, double& y, double& z, double& w) { + w = 1; + if ( has_normals()) { + normals_read = true; + if ( binary()) { + float f; + I_Binary_read_big_endian_float32( m_in, f); + x = f; + I_Binary_read_big_endian_float32( m_in, f); + y = f; + I_Binary_read_big_endian_float32( m_in, f); + z = f; + if ( is_homogeneous()) { + I_Binary_read_big_endian_float32( m_in, f); + w = f; + } + } else { + m_in >> iformat(x) >> iformat(y) >> iformat(z); + if ( is_homogeneous()) + m_in >> iformat(w); + } + } + } + void scan_normal( int& x, int& y, int& z, int& w) { + w = 1; + if ( has_normals()) { + normals_read = true; + if ( binary()) { + float f; + I_Binary_read_big_endian_float32( m_in, f); + x = int(f); + I_Binary_read_big_endian_float32( m_in, f); + y = int(f); + I_Binary_read_big_endian_float32( m_in, f); + z = int(f); + if ( is_homogeneous()) { + I_Binary_read_big_endian_float32( m_in, f); + w = int(f); + } + } else { + double d; + m_in >> iformat(d); + x = int(d); + m_in >> iformat(d); + y = int(d); + m_in >> iformat(d); + z = int(d); + if ( is_homogeneous()) { + m_in >> iformat(d); + w = int(d); + } + } + } + } + + static const Color& get_indexed_color(int id) + { + static const Color color[149] = { + Color(255, 255, 255, 191), + Color(255, 255, 255, 191), + Color(255, 255, 255, 191), + Color(255, 255, 255, 191), + Color(255, 255, 255, 191), + Color(255, 255, 255, 191), + Color(178, 38, 25, 191), + Color(51, 51, 204, 191), + Color(229, 153, 5, 191), + Color(25, 76, 204, 191), + Color(25, 178, 51, 191), + Color(204, 204, 102, 191), + Color(178, 178, 0, 191), + Color(178, 0, 178, 191), + Color(0, 178, 178, 191), + Color(229, 0, 51, 191), + Color(51, 229, 0, 191), + Color(0, 51, 229, 191), + Color(191, 191, 191, 191), + Color(204, 102, 0, 191), + Color(204, 102, 0, 191), + Color(0, 102, 204, 191), + Color(0, 102, 204, 191), + Color(0, 204, 102, 191), + Color(0, 204, 102, 191), + Color(102, 0, 204, 191), + Color(102, 0, 204, 191), + Color(204, 0, 102, 191), + Color(204, 0, 102, 191), + Color(178, 127, 51, 191), + Color(178, 127, 51, 191), + Color(178, 178, 0, 191), + Color(178, 0, 178, 191), + Color(0, 178, 178, 191), + Color(229, 0, 0, 191), + Color(0, 229, 0, 191), + Color(0, 0, 229, 191), + Color(191, 191, 191, 191), + Color(204, 102, 0, 191), + Color(102, 204, 0, 191), + Color(0, 102, 204, 191), + Color(0, 204, 102, 191), + Color(102, 0, 204, 191), + Color(204, 0, 102, 191), + Color(178, 178, 0, 191), + Color(178, 0, 178, 191), + Color(0, 178, 178, 191), + Color(229, 0, 0, 191), + Color(0, 229, 0, 191), + Color(0, 0, 229, 191), + Color(191, 191, 191, 191), + Color(204, 102, 0, 191), + Color(102, 204, 0, 191), + Color(0, 102, 204, 191), + Color(0, 204, 102, 191), + Color(102, 0, 204, 191), + Color(204, 0, 102, 191), + Color(178, 178, 0, 191), + Color(178, 0, 178, 191), + Color(0, 178, 178, 191), + Color(229, 0, 0, 191), + Color(0, 229, 0, 191), + Color(0, 0, 229, 191), + Color(191, 191, 191, 191), + Color(204, 102, 0, 191), + Color(102, 204, 0, 191), + Color(0, 102, 204, 191), + Color(0, 204, 102, 191), + Color(102, 0, 204, 191), + Color(204, 0, 102, 191), + Color(255, 255, 255, 191), + Color(255, 255, 255, 191), + Color(255, 255, 255, 191), + Color(255, 255, 255, 191), + Color(255, 255, 255, 191), + Color(255, 255, 255, 191), + Color(12, 76, 25, 191), + Color(178, 2, 25, 191), + Color(51, 12, 153, 191), + Color(229, 229, 5, 191), + Color(0, 51, 102, 191), + Color(25, 102, 102, 191), + Color(204, 204, 204, 191), + Color(178, 178, 0, 191), + Color(178, 178, 0, 191), + Color(178, 0, 178, 191), + Color(178, 0, 178, 191), + Color(0, 178, 178, 191), + Color(0, 178, 178, 191), + Color(229, 0, 0, 191), + Color(229, 0, 0, 191), + Color(0, 229, 0, 191), + Color(0, 229, 0, 191), + Color(0, 0, 229, 191), + Color(0, 0, 229, 191), + Color(191, 191, 191, 191), + Color(191, 191, 191, 191), + Color(204, 102, 0, 191), + Color(204, 102, 0, 191), + Color(0, 102, 204, 191), + Color(0, 102, 204, 191), + Color(0, 204, 102, 191), + Color(0, 204, 102, 191), + Color(102, 0, 204, 191), + Color(102, 0, 204, 191), + Color(204, 0, 102, 191), + Color(204, 0, 102, 191), + Color(178, 127, 51, 191), + Color(178, 127, 51, 191), + Color(178, 178, 0, 191), + Color(178, 0, 178, 191), + Color(0, 178, 178, 191), + Color(229, 0, 0, 191), + Color(0, 229, 0, 191), + Color(0, 0, 229, 191), + Color(191, 191, 191, 191), + Color(204, 102, 0, 191), + Color(102, 204, 0, 191), + Color(0, 102, 204, 191), + Color(0, 204, 102, 191), + Color(102, 0, 204, 191), + Color(204, 0, 102, 191), + Color(178, 178, 0, 191), + Color(178, 0, 178, 191), + Color(0, 178, 178, 191), + Color(229, 0, 0, 191), + Color(0, 229, 0, 191), + Color(0, 0, 229, 191), + Color(191, 191, 191, 191), + Color(204, 102, 0, 191), + Color(102, 204, 0, 191), + Color(0, 102, 204, 191), + Color(0, 204, 102, 191), + Color(102, 0, 204, 191), + Color(204, 0, 102, 191), + Color(178, 178, 0, 191), + Color(178, 0, 178, 191), + Color(0, 178, 178, 191), + Color(229, 0, 0, 191), + Color(0, 229, 0, 191), + Color(0, 0, 229, 191), + Color(191, 191, 191, 191), + Color(204, 102, 0, 191), + Color(102, 204, 0, 191), + Color(0, 102, 204, 191), + Color(0, 204, 102, 191), + Color(102, 0, 204, 191), + Color(204, 0, 102, 191), + Color(120, 120, 120, 120) }; + if(id > 148) id =148; + return color[id]; + } + + static CGAL::Color get_color_from_line(std::istream &is) + { + + std::string color_info; + bool is_float = false; + + std::string col; + //get the line content + std::getline(is, col); + //split it into strings + std::istringstream iss(col); + //holds the rgb values + unsigned char rgb[3]; + int index =0; + //split the string into numbers + while(iss>>color_info){ + //stop if comment is read + if(color_info.at(0) == '#') + break; + //detect if the value is float + for(int c = 0; c(color_info.length()); c++) + { + if(color_info.at(c) == '.') + { + is_float = true; + break; + } + } + //if the value is of float type, convert it into an int + if(is_float) + rgb[index] = static_cast(atof(color_info.c_str())*255); + //else stores the value + else + rgb[index] = static_cast(atoi(color_info.c_str())); + index++; + if(index == 3) + break; + } + CGAL::Color color; + //if there were only one number, fetch the color in the color map + if(index<2) + color = get_indexed_color(rgb[0]); + //else create the coor with the 3 values; + else + color = CGAL::Color(rgb[0], rgb[1], rgb[2]); + return color; + } + + void scan_color( unsigned char& r, unsigned char& g, unsigned char& b) { + if ( binary()) { + float fr, fg, fb; + I_Binary_read_big_endian_float32( m_in, fr); + I_Binary_read_big_endian_float32( m_in, fg); + I_Binary_read_big_endian_float32( m_in, fb); + r = (unsigned char)(fr); + g = (unsigned char)(fg); + b = (unsigned char)(fb); + + } else { + CGAL::Color color = get_color_from_line(m_in); + r = color.red(); + g = color.green(); + b = color.blue(); + } + } + + void skip_to_next_vertex( std::size_t current_vertex); + + void scan_facet( std::size_t& size, std::size_t CGAL_assertion_code(current_facet)) { + CGAL_assertion( current_facet < size_of_facets()); + if ( binary()){ + boost::int32_t i32; + I_Binary_read_big_endian_integer32( m_in, i32); + size = i32; + } else { + skip_comment(); + m_in >> size; + } + } + + void scan_facet_vertex_index( std::size_t& index, + std::size_t current_facet) { + if ( binary()){ + boost::int32_t i32; + I_Binary_read_big_endian_integer32( m_in, i32); + index = i32; + } else + m_in >> index; + + if( m_in.fail()) { + if ( verbose()) { + std::cerr << " " << std::endl; + std::cerr << "File_scanner_OFF::" << std::endl; + std::cerr << "scan_facet_vertex_index(): input error: " + "cannot read OFF file beyond facet " + << current_facet << "." << std::endl; + } + set_off_header( false); + return; + } + bool error = index < index_offset(); + index -= index_offset(); + + if(error || (index >= size_of_vertices())) { + m_in.clear( std::ios::failbit); + if ( verbose()) { + std::cerr << " " << std::endl; + std::cerr << "File_scanner_OFF::" << std::endl; + std::cerr << "scan_facet_vertex_index(): input error: " + "facet " << current_facet << ": vertex index " + << index + index_offset() << ": is out of range." + << std::endl; + } + set_off_header( false); + return; + } + } + + void skip_to_next_facet( std::size_t current_facet); +}; + +template < class Point> inline +Point& +file_scan_vertex( File_scanner_OFF& scanner, Point& p) { + typedef typename Point::R R; + typedef typename R::RT RT; + double x, y, z, w; + scanner.scan_vertex( x, y, z, w); + if ( w == 1) + p = Point( RT(x), RT(y), RT(z)); + else + p = Point( RT(x), RT(y), RT(z), RT(w)); + return p; +} + +template < class T_Color> inline +T_Color& +file_scan_color( File_scanner_OFF& scanner, T_Color& c) { + unsigned char r, g, b; + scanner.scan_color(r,g,b); + c = T_Color(r,g,b); + return c; +} + +template < class Vector> inline +Vector& +file_scan_normal( File_scanner_OFF& scanner, Vector& v) { + typedef typename Vector::R R; + typedef typename R::RT RT; + double x, y, z, w; + scanner.scan_normal( x, y, z, w); + if ( w == 1) + v = Vector( RT(x), RT(y), RT(z)); + else + v = Vector( RT(x), RT(y), RT(z), RT(w)); + return v; +} + +} //namespace CGAL + +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + +#include + +#endif // CGAL_IO_OFF_FILE_SCANNER_OFF_H // +// EOF // diff --git a/Stream_support/include/CGAL/IO/OFF/File_scanner_OFF_impl.h b/Stream_support/include/CGAL/IO/OFF/File_scanner_OFF_impl.h new file mode 100644 index 00000000000..749d56d5686 --- /dev/null +++ b/Stream_support/include/CGAL/IO/OFF/File_scanner_OFF_impl.h @@ -0,0 +1,134 @@ +// Copyright (c) 1997 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// +// Author(s) : Lutz Kettner + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include +#include +#include +#include +#include + +namespace CGAL { + +CGAL_INLINE_FUNCTION +void +File_scanner_OFF:: +skip_to_next_vertex( std::size_t current_vertex) { + CGAL_assertion( current_vertex < size_of_vertices()); + if ( binary()) { + float f; + if ( has_normals() && ! normals_read) { + I_Binary_read_big_endian_float32( m_in, f); + I_Binary_read_big_endian_float32( m_in, f); + I_Binary_read_big_endian_float32( m_in, f); + if ( is_homogeneous()) + I_Binary_read_big_endian_float32( m_in, f); + } + if ( has_colors()) { + // It is not well stated in the Geomview manual + // how color is coded following a vertex. It is + // parsed similar to the optional color for facets. + boost::int32_t k; + I_Binary_read_big_endian_integer32( m_in, k); + if (k<0 || k>4) { + m_in.clear( std::ios::badbit); + if ( verbose()) { + std::cerr << " " << std::endl; + std::cerr << "File_scanner_OFF::" << std::endl; + std::cerr << "skip_to_next_vertex(): input error: bad " + " number of color indices at vertex " + << current_vertex << "." << std::endl; + } + set_off_header( false); + return; + } + while (k--) { + float dummy; + I_Binary_read_big_endian_float32( m_in, dummy); + } + } + } else { + if ( has_normals() && ! normals_read) { + double dummy; + if ( is_homogeneous()) { + m_in >> dummy >> dummy >> dummy >> dummy; + } else { + m_in >> dummy >> dummy >> dummy; + } + } + if ( has_colors()) { // skip color entries (1 to 4) + m_in >> skip_until_EOL; + } + } + if( ! m_in) { + if ( verbose()) { + std::cerr << " " << std::endl; + std::cerr << "File_scanner_OFF::" << std::endl; + std::cerr << "skip_to_next_vertex(): input error: cannot read " + "OFF file beyond vertex " << current_vertex << "." + << std::endl; + } + set_off_header( false); + return; + } + normals_read = false; +} + +CGAL_INLINE_FUNCTION +void +File_scanner_OFF:: +skip_to_next_facet( std::size_t current_facet) { + // Take care of trailing informations like color triples. + if ( binary()) { + boost::int32_t k; + I_Binary_read_big_endian_integer32( m_in, k); + if (k<0 || k>4) { + m_in.clear( std::ios::badbit); + if ( verbose()) { + std::cerr << " " << std::endl; + std::cerr << "File_scanner_OFF::" << std::endl; + std::cerr << "skip_to_next_facet(): input error: bad " + "number of color indices at vertex " + << current_facet << "." << std::endl; + } + set_off_header( false); + return; + } + while (k--) { + float dummy; + I_Binary_read_big_endian_float32( m_in, dummy); + } + } else { + m_in >> skip_until_EOL; + } +} + +} //namespace CGAL +// EOF // diff --git a/Stream_support/include/CGAL/IO/OFF/File_writer_OFF.h b/Stream_support/include/CGAL/IO/OFF/File_writer_OFF.h new file mode 100644 index 00000000000..38d55622d64 --- /dev/null +++ b/Stream_support/include/CGAL/IO/OFF/File_writer_OFF.h @@ -0,0 +1,114 @@ +// Copyright (c) 1997 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// +// Author(s) : Lutz Kettner + +#ifndef CGAL_IO_OFF_FILE_WRITER_OFF_H +#define CGAL_IO_OFF_FILE_WRITER_OFF_H 1 + +#include +#include +#include +#include + +namespace CGAL { + +class CGAL_EXPORT File_writer_OFF { + std::ostream* m_out; + File_header_OFF m_header; +public: + File_writer_OFF( bool verbose = false) : m_header( verbose) {} + File_writer_OFF( const File_header_OFF& h) : m_header( h) {} + + std::ostream& out() { return *m_out; } + File_header_OFF& header() { return m_header; } + const File_header_OFF& header() const { return m_header; } + + void write_header( std::ostream& out, + std::size_t vertices, + std::size_t halfedges, + std::size_t facets, + bool normals = false); + void write_footer() { + if ( m_header.ascii() && m_header.comments()) + out() << "\n\n# End of OFF #"; + out() << std::endl; + } + void write_vertex( const double& x, const double& y, const double& z) { + if ( m_header.binary()) { + I_Binary_write_big_endian_float32( out(), float(x)); + I_Binary_write_big_endian_float32( out(), float(y)); + I_Binary_write_big_endian_float32( out(), float(z)); + } else { + out() << '\n' << x << ' ' << y << ' ' << z; + } + } + void write_normal( const double& x, const double& y, const double& z) { + if ( m_header.binary()) { + I_Binary_write_big_endian_float32( out(), float(x)); + I_Binary_write_big_endian_float32( out(), float(y)); + I_Binary_write_big_endian_float32( out(), float(z)); + } else { + out() << ' ' << ' ' << x << ' ' << y << ' ' << z; + } + } + void write_facet_header() { + if ( m_header.ascii()) { + if ( m_header.no_comments()) + out() << '\n'; + else { + out() << "\n\n# " << m_header.size_of_facets() + << " facets\n"; + out() << "# ------------------------------------------" + "\n\n"; + } + } + } + void write_facet_begin( std::size_t no) { + if ( m_header.binary()) + I_Binary_write_big_endian_integer32( out(), static_cast(no)); + else + out() << no << ' '; + } + void write_facet_vertex_index( std::size_t index) { + if ( m_header.binary()) + I_Binary_write_big_endian_integer32( out(), static_cast(index)); + else + out() << ' ' << index; + } + void write_facet_end() { + if ( m_header.binary()) + I_Binary_write_big_endian_integer32( out(), 0); + else + out() << '\n'; + } +}; + +} //namespace CGAL + +#ifdef CGAL_HEADER_ONLY +#include +#endif // CGAL_HEADER_ONLY + +#endif // CGAL_IO_OFF_FILE_WRITER_OFF_H // +// EOF // diff --git a/Stream_support/include/CGAL/IO/OFF/File_writer_OFF_impl.h b/Stream_support/include/CGAL/IO/OFF/File_writer_OFF_impl.h new file mode 100644 index 00000000000..546f340c59e --- /dev/null +++ b/Stream_support/include/CGAL/IO/OFF/File_writer_OFF_impl.h @@ -0,0 +1,57 @@ +// Copyright (c) 1997 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// +// Author(s) : Lutz Kettner + +#ifdef CGAL_HEADER_ONLY +#define CGAL_INLINE_FUNCTION inline +#else +#define CGAL_INLINE_FUNCTION +#endif + +#include +#include +#include + +namespace CGAL { + +CGAL_INLINE_FUNCTION +void +File_writer_OFF:: +write_header( std::ostream& o, + std::size_t vertices, + std::size_t halfedges, + std::size_t facets, + bool normals) { + m_out = &o; + m_header.set_vertices( vertices); + // Don't. This halfdges aren't trusted: + // m_header.set_halfedges( halfedges); + (void)halfedges; + m_header.set_facets( facets); + m_header.set_normals( normals); + // Print header. + out() << m_header; +} +} //namespace CGAL +// EOF // diff --git a/Stream_support/include/CGAL/IO/OFF/OFF_reader.h b/Stream_support/include/CGAL/IO/OFF/OFF_reader.h new file mode 100644 index 00000000000..f85dc2cfa7b --- /dev/null +++ b/Stream_support/include/CGAL/IO/OFF/OFF_reader.h @@ -0,0 +1,150 @@ + +// Copyright (c) 2015 GeometryFactory +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// Author(s) : Laurent Rineau and Sebastien Loriot + +#ifndef CGAL_IO_OFF_OFF_READER_H +#define CGAL_IO_OFF_OFF_READER_H + +#include +#include + +#include +#include +#include +#include +#include + +namespace CGAL { +namespace OFF_internal { +template +bool +read_OFF( std::istream& in, + std::vector< Point_3 >& points, + std::vector< Polygon_3 >& polygons, + bool /* verbose */ = false) +{ + CGAL::File_scanner_OFF scanner(in); + + points.resize(scanner.size_of_vertices()); + polygons.resize(scanner.size_of_facets()); + for (std::size_t i = 0; i < scanner.size_of_vertices(); ++i) { + double x, y, z, w; + scanner.scan_vertex( x, y, z, w); + CGAL_assertion(w!=0); + IO::internal::fill_point( x/w, y/w, z/w, points[i] ); + scanner.skip_to_next_vertex( i); + } + if(!in) + return false; + + for (std::size_t i = 0; i < scanner.size_of_facets(); ++i) { + std::size_t no; + + scanner.scan_facet( no, i); + IO::internal::resize(polygons[i], no); + for(std::size_t j = 0; j < no; ++j) { + std::size_t id; + scanner.scan_facet_vertex_index(id, i); + if(id < scanner.size_of_vertices()) + { + polygons[i][j] = id; + } + else + return false; + } + } + return in.good(); +} + +template +bool +read_OFF( std::istream& in, + std::vector< Point_3 >& points, + std::vector< Polygon_3 >& polygons, + std::vector& fcolors, + std::vector& vcolors, + bool /* verbose */ = false) +{ + CGAL::File_scanner_OFF scanner(in); + points.resize(scanner.size_of_vertices()); + polygons.resize(scanner.size_of_facets()); + if(scanner.has_colors()) + vcolors.resize(scanner.size_of_vertices()); + for (std::size_t i = 0; i < scanner.size_of_vertices(); ++i) { + double x, y, z, w; + scanner.scan_vertex( x, y, z, w); + CGAL_assertion(w!=0); + IO::internal::fill_point( x/w, y/w, z/w, points[i] ); + if(scanner.has_colors()) + { + unsigned char r=0, g=0, b=0; + scanner.scan_color( r, g, b); + vcolors[i] = Color_rgb(r,g,b); + } + else + scanner.skip_to_next_vertex(i); + if(!in) + return false; + } + bool has_fcolors = false; + for (std::size_t i = 0; i < scanner.size_of_facets(); ++i) { + std::size_t no; + scanner.scan_facet( no, i); + if(!in) + return false; + IO::internal::resize(polygons[i], no); + for(std::size_t j = 0; j < no; ++j) { + std::size_t id; + scanner.scan_facet_vertex_index(id, i); + if(id < scanner.size_of_vertices()) + { + polygons[i][j] = id; + } + else + { + return false; + } + } + + if(i==0) + { + std::string col; + std::getline(in, col); + std::istringstream iss(col); + char ci =' '; + if(iss >> ci){ + has_fcolors = true; + fcolors.resize(scanner.size_of_facets()); + std::istringstream iss2(col); + fcolors[i] = scanner.get_color_from_line(iss2); + } + } + else if(has_fcolors) + { + unsigned char r=0, g=0, b=0; + scanner.scan_color(r,g,b); + fcolors[i] = Color_rgb(r,g,b); + } + } + return in.good(); +} +} +} // namespace CGAL + +#endif // CGAL_IO_OFF_OFF_READER_H diff --git a/Stream_support/include/CGAL/IO/OFF/Polyhedron_scan_OFF.h b/Stream_support/include/CGAL/IO/OFF/Polyhedron_scan_OFF.h new file mode 100644 index 00000000000..1799bd810f5 --- /dev/null +++ b/Stream_support/include/CGAL/IO/OFF/Polyhedron_scan_OFF.h @@ -0,0 +1,159 @@ +// Copyright (c) 1997 ETH Zurich (Switzerland). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0+ +// +// +// Author(s) : Lutz Kettner + +#ifndef CGAL_IO_OFF_POLYHEDRON_SCAN_OFF_H +#define CGAL_IO_OFF_POLYHEDRON_SCAN_OFF_H 1 + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace CGAL { + +template < class HDS> +class Polyhedron_scan_OFF : public Modifier_base { +protected: + std::istream& m_in; + File_header_OFF m_file_header; +public: + + typedef HDS Halfedge_data_structure; + +// DEFINITION +// +// Polyhedron_scan_OFF is a polyhedral surface builder. +// It scans a polyhedron given in OFF from a stream and appends it +// incrementally using the incremental builder. + + Polyhedron_scan_OFF( std::istream& in, bool verbose = false) + : m_in(in), m_file_header( verbose) {} + + // Activation + void operator()( HDS& hds); + + const File_header_OFF& header() const { return m_file_header; } +}; + +template < class HDS > +void +Polyhedron_scan_OFF:: operator()( HDS& target) { + File_scanner_OFF scanner( m_in, m_file_header.verbose()); + if ( ! m_in) { + if ( scanner.verbose()) { + std::cerr << " " << std::endl; + std::cerr << "Polyhedron_scan_OFF::" << std::endl; + std::cerr << "operator(): input error: file format is not in " + "OFF." << std::endl; + } + return; + } + m_file_header = scanner; // Remember file header after return. + + Polyhedron_incremental_builder_3 B( target, scanner.verbose()); + B.begin_surface( scanner.size_of_vertices(), + scanner.size_of_facets(), + scanner.size_of_halfedges()); + + typedef typename HDS::Traits Traits; + typedef typename Traits::Point_3 Point; + + // read in all vertices + std::size_t i; + 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); + } + else + scanner.skip_to_next_vertex( i); + } + if ( ! m_in || B.error()) { + B.rollback(); + m_in.clear( std::ios::badbit); + return; + } + + // read in all facets + for ( i = 0; i < scanner.size_of_facets(); i++) { + B.begin_facet(); + std::size_t no; + scanner.scan_facet( no, i); + if( ! m_in || B.error() || no < 3) { + if ( scanner.verbose()) { + std::cerr << " " << std::endl; + std::cerr << "Polyhedron_scan_OFF::" << std::endl; + std::cerr << "operator()(): input error: facet " << i + << " has less than 3 vertices." << std::endl; + } + B.rollback(); + m_in.clear( std::ios::badbit); + return; + } + for ( std::size_t j = 0; j < no; j++) { + std::size_t index; + scanner.scan_facet_vertex_index( index, i); + B.add_vertex_to_facet( index); + } + //TO DO : Insert read color + B.end_facet(); + scanner.skip_to_next_facet( i); + } + if ( ! m_in || B.error()) { + B.rollback(); + m_in.clear( std::ios::badbit); + return; + } + if ( B.check_unconnected_vertices()) { + if ( ! B.remove_unconnected_vertices()) { + if ( scanner.verbose()) { + std::cerr << " " << std::endl; + std::cerr << "Polyhedron_scan_OFF::" << std::endl; + std::cerr << "operator()(): input error: cannot " + "successfully remove isolated vertices." + << std::endl; + } + B.rollback(); + m_in.clear( std::ios::badbit); + return; + } + } + B.end_surface(); +} + +} //namespace CGAL + +#include + +#endif // CGAL_IO_OFF_POLYHEDRON_SCAN_OFF_H // +// EOF // diff --git a/Stream_support/include/CGAL/IO/OFF/Scanner_OFF.h b/Stream_support/include/CGAL/IO/OFF/Scanner_OFF.h new file mode 100644 index 00000000000..38ad1787b5b --- /dev/null +++ b/Stream_support/include/CGAL/IO/OFF/Scanner_OFF.h @@ -0,0 +1,308 @@ +// Copyright (c) 1997,2005 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// +// Author(s) : Lutz Kettner +// Ralf Osbild + +#ifndef CGAL_IO_OFF_SCANNER_OFF_H +#define CGAL_IO_OFF_SCANNER_OFF_H 1 + +#include +#include +#include +#include +#include +#include + +namespace CGAL { + +// The Facet_iterator's value type is vector +// that contains the vertex indices. + +template +class I_Scanner_OFF_vertex_iterator +{ +public: + typedef std::input_iterator_tag iterator_category; + typedef Pt value_type; + typedef std::ptrdiff_t difference_type; + typedef const Pt* pointer; + typedef const Pt& reference; +private: + File_scanner_OFF* m_scan; + std::size_t m_cnt; + Pt m_point; + + void next_vertex() { + CGAL_assertion( m_scan != nullptr); + if ( m_cnt < m_scan->size_of_vertices()) { + file_scan_vertex( *m_scan, m_point); + m_scan->skip_to_next_vertex( m_cnt); + ++m_cnt; + } else + m_cnt = m_scan->size_of_vertices() + 1; + } +public: + typedef Pt Point; + typedef File_scanner_OFF Scanner; + typedef I_Scanner_OFF_vertex_iterator Self; + + I_Scanner_OFF_vertex_iterator(std::size_t cnt) : m_scan(0), m_cnt(cnt+1) {} + I_Scanner_OFF_vertex_iterator( Scanner& s, int cnt) + : m_scan(&s), m_cnt(cnt) + { + next_vertex(); + } + std::size_t count() const { return m_cnt; } + bool operator==( const Self& i) const { return m_cnt == i.m_cnt; } + bool operator!=( const Self& i) const { return m_cnt != i.m_cnt; } + Self& operator++() { + next_vertex(); + return *this; + } + Self operator++(int) { + Self tmp = *this; + ++(*this); + return tmp; + } + const Point& operator*() const { + CGAL_assertion( m_scan != nullptr); + return m_point; + } + const Point* operator->() const { return & operator*(); } +}; + +template +class I_Scanner_OFF_vertex_and_normals_iterator +{ +public: + typedef Pt Point; + typedef Nrm Normal; + typedef File_scanner_OFF Scanner; + typedef I_Scanner_OFF_vertex_and_normals_iterator Self; + + typedef std::input_iterator_tag iterator_category; + typedef std::pair value_type; + typedef std::ptrdiff_t difference_type; + typedef const value_type* pointer; + typedef const value_type& reference; +private: + File_scanner_OFF* m_scan; + std::size_t m_cnt; + value_type m_current; + + + void next() { + CGAL_assertion( m_scan != nullptr); + if ( m_cnt < m_scan->size_of_vertices()) { + file_scan_vertex( *m_scan, m_current.first); + if ( m_scan->has_normals()) + file_scan_normal( *m_scan, m_current.second); + m_scan->skip_to_next_vertex( m_cnt); + ++m_cnt; + } else + m_cnt = m_scan->size_of_vertices() + 1; + } +public: + + I_Scanner_OFF_vertex_and_normals_iterator( int cnt) + : m_scan(0), m_cnt(cnt+1) {} + I_Scanner_OFF_vertex_and_normals_iterator( Scanner& s, int cnt) + : m_scan(&s), m_cnt(cnt) + { + next(); + } + std::size_t count() const { return m_cnt; } + bool operator==( const Self& i) const { return m_cnt == i.m_cnt; } + bool operator!=( const Self& i) const { return m_cnt != i.m_cnt; } + Self& operator++() { + next(); + return *this; + } + Self operator++(int) { + Self tmp = *this; + ++(*this); + return tmp; + } + reference operator*() const { + CGAL_assertion( m_scan != nullptr); + return m_current; + } + pointer operator->() const { return & operator*(); } +}; + +class I_Scanner_OFF_facet_iterator +{ +public: + typedef std::input_iterator_tag iterator_category; + typedef std::vector value_type; + typedef std::ptrdiff_t difference_type; + typedef value_type* pointer; + typedef value_type& reference; +private: + File_scanner_OFF* m_scan; + std::size_t m_cnt; + value_type m_indices; + + void next_facet() { + CGAL_assertion( m_scan != nullptr); + if ( m_cnt < m_scan->size_of_facets()) { + m_indices.erase( m_indices.begin(), m_indices.end()); + std::size_t no; + m_scan->scan_facet( no, m_cnt); + m_indices.reserve( no); + std::size_t index = (std::numeric_limits::max)(); + // A huge value helps to detect a potential + // error in the function scan_facet_vertex_index + for (std::size_t i = 0; i < no; ++i) { + m_scan->scan_facet_vertex_index( index, m_cnt); + m_indices.push_back( index); + } + m_scan->skip_to_next_facet( m_cnt); + ++ m_cnt; + } else + m_cnt = m_scan->size_of_facets() + 1; + } +public: + value_type::size_type size_of_indices () const // RO + { return m_indices.size(); } + typedef value_type::size_type indices_size_type; // RO +public: + typedef File_scanner_OFF Scanner; + typedef I_Scanner_OFF_facet_iterator Self; + typedef value_type::iterator iterator; + + I_Scanner_OFF_facet_iterator( std::size_t cnt) : m_scan(0), m_cnt(cnt+1) {} + I_Scanner_OFF_facet_iterator( Scanner& s, std::size_t cnt) + : m_scan(&s), m_cnt(cnt) + { + next_facet(); + } + std::size_t count() const { return m_cnt; } + bool operator==( const Self& i) const { return m_cnt == i.m_cnt; } + bool operator!=( const Self& i) const { return m_cnt != i.m_cnt; } + Self& operator++() { + next_facet(); + return *this; + } + Self operator++(int) { + Self tmp = *this; + ++(*this); + return tmp; + } + value_type& operator*() { + CGAL_assertion( m_scan != nullptr); + return m_indices; + } + const value_type& operator*() const { + CGAL_assertion( m_scan != nullptr); + return m_indices; + } + value_type* operator->() { return & operator*(); } + const value_type* operator->() const { return & operator*(); } +}; + + +// The distance function is implemented to work in +// constant time for both iterators. + +template inline +void distance( const I_Scanner_OFF_vertex_iterator& first, + const I_Scanner_OFF_vertex_iterator& last, + Distance& n) { + n = Distance( last.count() - first.count()); +} +template inline +void distance( const I_Scanner_OFF_facet_iterator& first, + const I_Scanner_OFF_facet_iterator& last, + Distance& n) { + n = Distance( last.count() - first.count()); +} +template inline +std::ptrdiff_t distance( const I_Scanner_OFF_vertex_iterator& first, + const I_Scanner_OFF_vertex_iterator& last) { + return last.count() - first.count(); +} + +inline +std::ptrdiff_t distance( const I_Scanner_OFF_facet_iterator& first, + const I_Scanner_OFF_facet_iterator& last) { + return last.count() - first.count(); +} + + +template +class Scanner_OFF { + File_scanner_OFF m_scan; +public: + typedef typename Kernel::Point_3 Point; + typedef Point Pt; + typedef typename Kernel::Vector_3 Normal; + typedef Scanner_OFF Self; + typedef I_Scanner_OFF_vertex_iterator Vertex_iterator; + typedef I_Scanner_OFF_vertex_and_normals_iterator + Vertex_and_normals_iterator; + typedef I_Scanner_OFF_facet_iterator Facet_iterator; + typedef I_Scanner_OFF_facet_iterator::iterator Index_iterator; + + Scanner_OFF( std::istream& in, bool verbose = false) + : m_scan( in, verbose) {} + Scanner_OFF( std::istream& in, const File_header_OFF& header) + : m_scan( in, header) {} + + std::size_t size_of_vertices() const { return m_scan.size_of_vertices(); } + std::size_t size_of_halfedges() const { return m_scan.size_of_halfedges();} + std::size_t size_of_facets() const { return m_scan.size_of_facets(); } + + bool verbose() const { return m_scan.verbose(); } + bool skel() const { return m_scan.skel(); } + bool off() const { return m_scan.off(); } + bool binary() const { return m_scan.binary(); } + bool ascii() const { return m_scan.ascii(); } + + bool has_colors() const { return m_scan.has_colors(); } + bool has_normals() const { return m_scan.has_normals(); } + + File_header_OFF& header() { return m_scan; } + const File_header_OFF& + header() const { return m_scan; } + + Vertex_iterator vertices_begin(){ return Vertex_iterator( m_scan,0);} + Vertex_iterator vertices_end() { + return Vertex_iterator( size_of_vertices()); + } + Facet_iterator facets_begin() { return Facet_iterator( m_scan,0); } + Facet_iterator facets_end() { + return Facet_iterator( size_of_facets()); + } + Vertex_and_normals_iterator vertices_and_normals_begin(){ + return Vertex_and_normals_iterator( m_scan,0); + } + Vertex_and_normals_iterator vertices_and_normals_end() { + return Vertex_and_normals_iterator( size_of_vertices()); + } +}; + +} //namespace CGAL +#endif // CGAL_IO_OFF_SCANNER_OFF_H // +// EOF // diff --git a/Stream_support/include/CGAL/IO/OFF/generic_copy_OFF.h b/Stream_support/include/CGAL/IO/OFF/generic_copy_OFF.h new file mode 100644 index 00000000000..7bc1fae0e3f --- /dev/null +++ b/Stream_support/include/CGAL/IO/OFF/generic_copy_OFF.h @@ -0,0 +1,103 @@ +// Copyright (c) 1997 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// +// Author(s) : Lutz Kettner + +#ifndef CGAL_IO_OFF_GENERIC_COPY_OFF_H +#define CGAL_IO_OFF_GENERIC_COPY_OFF_H 1 + +#include +#include +#include +#include +#include + +namespace CGAL { + +template +void +generic_copy_OFF( File_scanner_OFF& scanner, + std::ostream& out, + Writer& writer) { + std::istream& in = scanner.in(); + // scans a polyhedral surface in OFF from `in' and writes it + // to `out' in the format provided by `writer'. + if ( ! in) { + if ( scanner.verbose()) { + std::cerr << " " << std::endl; + std::cerr << "generic_copy_OFF(): " + "input error: file format is not in OFF." + << std::endl; + } + return; + } + + // Print header. Number of halfedges is only trusted if it is + // a polyhedral surface. + writer.write_header( out, + scanner.size_of_vertices(), + scanner.polyhedral_surface() ? + scanner.size_of_halfedges() : 0, + scanner.size_of_facets()); + + // read in all vertices + double x, y, z; // Point coordinates. + std::size_t i; + for ( i = 0; i < scanner.size_of_vertices(); i++) { + scanner.scan_vertex( x, y, z); + writer.write_vertex( x, y, z); + scanner.skip_to_next_vertex( i); + } + + // read in all facets + writer.write_facet_header(); + for ( i = 0; i < scanner.size_of_facets(); i++) { + if ( ! in) + return; + std::size_t no; + scanner.scan_facet( no, i); + writer.write_facet_begin( no); + for ( std::size_t j = 0; j < no; j++) { + std::size_t index; + scanner.scan_facet_vertex_index( index, i); + writer.write_facet_vertex_index( index); + } + writer.write_facet_end(); + scanner.skip_to_next_facet( i); + } + writer.write_footer(); +} + +template +void +generic_copy_OFF( std::istream& in, std::ostream& out, Writer& writer, + bool verbose = false) { + // scans a polyhedral surface in OFF from `in' and writes it + // to `out' in the format provided by `writer'. + File_scanner_OFF scanner( in, verbose); + generic_copy_OFF( scanner, out, writer); +} + +} //namespace CGAL +#endif // CGAL_IO_OFF_GENERIC_COPY_OFF_H // +// EOF // diff --git a/Stream_support/include/CGAL/IO/OFF/print_OFF.h b/Stream_support/include/CGAL/IO/OFF/print_OFF.h new file mode 100644 index 00000000000..1daef06ec94 --- /dev/null +++ b/Stream_support/include/CGAL/IO/OFF/print_OFF.h @@ -0,0 +1,100 @@ +// Copyright (c) 1997 ETH Zurich (Switzerland). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0+ +// +// +// Author(s) : Lutz Kettner + +#ifndef CGAL_IO_OFF_PRINT_OFF_H +#define CGAL_IO_OFF_PRINT_OFF_H 1 + +#include + + +#include +#include +#include +#include +#include + +namespace CGAL { + +template +void print_polyhedron_with_header_OFF( std::ostream& out, + const Polyhedron& P, + const File_header_OFF& header, + const Vpm& vpm) { + File_writer_OFF writer( header); + writer.header().set_polyhedral_surface( true); + writer.header().set_halfedges( P.size_of_halfedges()); + generic_print_polyhedron( out, P, writer, vpm); +} + +template +void print_polyhedron_with_header_OFF( std::ostream& out, + const Polyhedron& P, + const File_header_OFF& header) +{ + print_polyhedron_with_header_OFF(out, P, header, get(CGAL::vertex_point, P)); +} + +template +void print_polyhedron_OFF( std::ostream& out, + const Polyhedron& P, + bool verbose = false) { + File_header_OFF header( verbose); + header.set_binary( is_binary( out)); + header.set_no_comments( ! is_pretty( out)); + print_polyhedron_with_header_OFF( out, P, header); +} + + +// Deprecated global functions, replaced with functions above + +template < class Traits, + class Items, + template < class T, class I, class A> + class HDS, class Alloc> +void +print_OFF( std::ostream& out, + const Polyhedron_3& P, + bool verbose = false) { + File_writer_OFF writer( verbose); + writer.header().set_binary( is_binary( out)); + writer.header().set_no_comments( ! is_pretty( out)); + writer.header().set_polyhedral_surface( true); + writer.header().set_halfedges( P.size_of_halfedges()); + generic_print_polyhedron( out, P, writer); +} + +template < class Traits, + class Items, + template < class T, class I, class A> + class HDS, class Alloc> +void +print_OFF( std::ostream& out, + const Polyhedron_3& P, + const File_header_OFF& header) { + File_writer_OFF writer( header); + writer.header().set_polyhedral_surface( true); + writer.header().set_halfedges( P.size_of_halfedges()); + generic_print_polyhedron( out, P, writer); +} + +} //namespace CGAL +#endif // CGAL_IO_OFF_PRINT_OFF_H // +// EOF // diff --git a/Stream_support/include/CGAL/IO/OFF/scan_OFF.h b/Stream_support/include/CGAL/IO/OFF/scan_OFF.h new file mode 100644 index 00000000000..b8a6ca7f9b4 --- /dev/null +++ b/Stream_support/include/CGAL/IO/OFF/scan_OFF.h @@ -0,0 +1,68 @@ +// Copyright (c) 1997 ETH Zurich (Switzerland). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0+ +// +// +// Author(s) : Lutz Kettner + +#ifndef CGAL_IO_OFF_SCAN_OFF_H +#define CGAL_IO_OFF_SCAN_OFF_H 1 + +#include + + +#include +#include +#include + +namespace CGAL { + +template < class Traits, + class Items, + template < class T, class I, class A> + class HDS, class Alloc> +void scan_OFF( std::istream& in, + Polyhedron_3& P, + File_header_OFF& header) { + // reads a polyhedron from `in' and appends it to P. + // Returns also the File_header_OFF structure of the object. + typedef Polyhedron_3 Polyhedron; + typedef typename Polyhedron::HalfedgeDS HalfedgeDS; + typedef Polyhedron_scan_OFF Scanner; + Scanner scanner( in, header.verbose()); + P.delegate(scanner); + header = scanner.header(); +} + +template < class Traits, + class Items, + template < class T, class I, class A> + class HDS, class Alloc> +void scan_OFF( std::istream& in, Polyhedron_3& P, + bool verbose = false) { + // reads a polyhedron from `in' and appends it to P. + typedef Polyhedron_3 Polyhedron; + typedef typename Polyhedron::HalfedgeDS HalfedgeDS; + typedef Polyhedron_scan_OFF Scanner; + Scanner scanner( in, verbose); + P.delegate(scanner); +} + + +} //namespace CGAL +#endif // CGAL_IO_OFF_SCAN_OFF_H // +// EOF // diff --git a/Stream_support/include/CGAL/IO/PLY/PLY_reader.h b/Stream_support/include/CGAL/IO/PLY/PLY_reader.h new file mode 100644 index 00000000000..f238b5756cf --- /dev/null +++ b/Stream_support/include/CGAL/IO/PLY/PLY_reader.h @@ -0,0 +1,348 @@ +// Copyright (c) 2017 GeometryFactory +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// Author(s) : Simon Giraudot + +#ifndef CGAL_IO_PLY_PLY_READER_H +#define CGAL_IO_PLY_PLY_READER_H + +#include + +namespace CGAL{ + + namespace internal + { + template + bool + read_PLY_faces (std::istream& in, + internal::PLY::PLY_element& element, + std::vector< Polygon_3 >& polygons, + std::vector< Color_rgb >& fcolors, + const char* vertex_indices_tag) + { + bool has_colors = false; + std::string rtag = "r", gtag = "g", btag = "b"; + if ((element.has_property("red") || element.has_property("r")) && + (element.has_property("green") || element.has_property("g")) && + (element.has_property("blue") || element.has_property("b"))) + { + has_colors = true; + if (element.has_property("red")) + { + rtag = "red"; gtag = "green"; btag = "blue"; + } + } + + for (std::size_t j = 0; j < element.number_of_items(); ++ j) + { + for (std::size_t k = 0; k < element.number_of_properties(); ++ k) + { + internal::PLY::PLY_read_number* property = element.property(k); + property->get (in); + + if (in.fail()) + return false; + } + + std::tuple, boost::uint8_t, boost::uint8_t, boost::uint8_t> new_face; + + if (has_colors) + { + PLY::process_properties (element, new_face, + std::make_pair (CGAL::make_nth_of_tuple_property_map<0>(new_face), + PLY_property >(vertex_indices_tag)), + std::make_pair (CGAL::make_nth_of_tuple_property_map<1>(new_face), + PLY_property(rtag.c_str())), + std::make_pair (CGAL::make_nth_of_tuple_property_map<2>(new_face), + PLY_property(gtag.c_str())), + std::make_pair (CGAL::make_nth_of_tuple_property_map<3>(new_face), + PLY_property(btag.c_str()))); + + fcolors.push_back (Color_rgb (get<1>(new_face), get<2>(new_face), get<3>(new_face))); + } + else + PLY::process_properties (element, new_face, + std::make_pair (CGAL::make_nth_of_tuple_property_map<0>(new_face), + PLY_property >(vertex_indices_tag))); + + polygons.push_back (Polygon_3(get<0>(new_face).size())); + for (std::size_t i = 0; i < get<0>(new_face).size(); ++ i) + polygons.back()[i] = std::size_t(get<0>(new_face)[i]); + } + + return true; + } + + } + + + template + bool + read_PLY( std::istream& in, + std::vector< Point_3 >& points, + std::vector< Polygon_3 >& polygons, + bool /* verbose */ = false) + { + if(!in) + { + std::cerr << "Error: cannot open file" << std::endl; + return false; + } + + internal::PLY::PLY_reader reader; + + if (!(reader.init (in))) + { + in.setstate(std::ios::failbit); + return false; + } + + for (std::size_t i = 0; i < reader.number_of_elements(); ++ i) + { + internal::PLY::PLY_element& element = reader.element(i); + + if (element.name() == "vertex" || element.name() == "vertices") + { + for (std::size_t j = 0; j < element.number_of_items(); ++ j) + { + for (std::size_t k = 0; k < element.number_of_properties(); ++ k) + { + internal::PLY::PLY_read_number* property = element.property(k); + property->get (in); + + if (in.fail()) + return false; + } + + Point_3 new_vertex; + + internal::PLY::process_properties (element, new_vertex, + make_ply_point_reader (CGAL::Identity_property_map())); + + points.push_back (get<0>(new_vertex)); + } + } + else if (element.name() == "face" || element.name() == "faces") + { + std::vector dummy; + + if (element.has_property > ("vertex_indices")) + internal::read_PLY_faces (in, element, polygons, dummy, "vertex_indices"); + else if (element.has_property > ("vertex_indices")) + internal::read_PLY_faces (in, element, polygons, dummy, "vertex_indices"); + else if (element.has_property > ("vertex_index")) + internal::read_PLY_faces (in, element, polygons, dummy, "vertex_index"); + else if (element.has_property > ("vertex_index")) + internal::read_PLY_faces (in, element, polygons, dummy, "vertex_index"); + else + { + std::cerr << "Error: can't find vertex indices in PLY input" << std::endl; + return false; + } + } + else // Read other elements and ignore + { + for (std::size_t j = 0; j < element.number_of_items(); ++ j) + { + for (std::size_t k = 0; k < element.number_of_properties(); ++ k) + { + internal::PLY::PLY_read_number* property = element.property(k); + property->get (in); + + if (in.fail()) + return false; + } + } + } + } + + return !in.bad(); + } + + template + bool + read_PLY( std::istream& in, + std::vector< Point_3 >& points, + std::vector< Polygon_3 >& polygons, + std::vector >& hedges, + std::vector& fcolors, + std::vector& vcolors, + std::vector >& huvs, + bool /* verbose */ = false) + { + if(!in) + { + std::cerr << "Error: cannot open file" << std::endl; + return false; + } + internal::PLY::PLY_reader reader; + + if (!(reader.init (in))) + { + in.setstate(std::ios::failbit); + return false; + } + for (std::size_t i = 0; i < reader.number_of_elements(); ++ i) + { + internal::PLY::PLY_element& element = reader.element(i); + + if (element.name() == "vertex" || element.name() == "vertices") + { + bool has_colors = false; + std::string rtag = "r", gtag = "g", btag = "b"; + if ((element.has_property("red") || element.has_property("r")) && + (element.has_property("green") || element.has_property("g")) && + (element.has_property("blue") || element.has_property("b"))) + { + has_colors = true; + if (element.has_property("red")) + { + rtag = "red"; gtag = "green"; btag = "blue"; + } + } + + for (std::size_t j = 0; j < element.number_of_items(); ++ j) + { + for (std::size_t k = 0; k < element.number_of_properties(); ++ k) + { + internal::PLY::PLY_read_number* property = element.property(k); + property->get (in); + + if (in.fail()) + return false; + } + + std::tuple new_vertex; + + if (has_colors) + { + internal::PLY::process_properties (element, new_vertex, + make_ply_point_reader (CGAL::make_nth_of_tuple_property_map<0>(new_vertex)), + std::make_pair (CGAL::make_nth_of_tuple_property_map<1>(new_vertex), + PLY_property(rtag.c_str())), + std::make_pair (CGAL::make_nth_of_tuple_property_map<2>(new_vertex), + PLY_property(gtag.c_str())), + std::make_pair (CGAL::make_nth_of_tuple_property_map<3>(new_vertex), + PLY_property(btag.c_str()))); + + vcolors.push_back (Color_rgb (get<1>(new_vertex), get<2>(new_vertex), get<3>(new_vertex))); + } + else + internal::PLY::process_properties (element, new_vertex, + make_ply_point_reader (CGAL::make_nth_of_tuple_property_map<0>(new_vertex))); + + points.push_back (get<0>(new_vertex)); + } + } + else if (element.name() == "face" || element.name() == "faces") + { + if (element.has_property > ("vertex_indices")) + internal::read_PLY_faces (in, element, polygons, fcolors, "vertex_indices"); + else if (element.has_property > ("vertex_indices")) + internal::read_PLY_faces (in, element, polygons, fcolors, "vertex_indices"); + else if (element.has_property > ("vertex_index")) + internal::read_PLY_faces (in, element, polygons, fcolors, "vertex_index"); + else if (element.has_property > ("vertex_index")) + internal::read_PLY_faces (in, element, polygons, fcolors, "vertex_index"); + else + { + std::cerr << "Error: can't find vertex indices in PLY input" << std::endl; + return false; + } + } + else if(element.name() == "halfedge" ) + { + bool has_uv = false; + std::string stag = "source", ttag = "target", utag = "u", vtag = "v"; + if ( element.has_property("source") && + element.has_property("target") && + element.has_property("u") && + element.has_property("v")) + { + has_uv = true; + } + cpp11::tuple new_hedge; + for (std::size_t j = 0; j < element.number_of_items(); ++ j) + { + for (std::size_t k = 0; k < element.number_of_properties(); ++ k) + { + internal::PLY::PLY_read_number* property = element.property(k); + property->get (in); + + if (in.eof()) + return false; + } + + if (has_uv) + { + internal::PLY::process_properties (element, new_hedge, + std::make_pair (CGAL::make_nth_of_tuple_property_map<0>(new_hedge), + PLY_property(stag.c_str())), + std::make_pair (CGAL::make_nth_of_tuple_property_map<1>(new_hedge), + PLY_property(ttag.c_str())), + std::make_pair (CGAL::make_nth_of_tuple_property_map<2>(new_hedge), + PLY_property(utag.c_str())), + std::make_pair (CGAL::make_nth_of_tuple_property_map<3>(new_hedge), + PLY_property(vtag.c_str()))); + hedges.push_back (std::make_pair(get<0>(new_hedge), get<1>(new_hedge))); + huvs.push_back (std::make_pair(get<2>(new_hedge), get<3>(new_hedge))); + } + else + internal::PLY::process_properties (element, new_hedge, + std::make_pair(CGAL::make_nth_of_tuple_property_map<0>(new_hedge), + PLY_property(stag.c_str())), + std::make_pair(CGAL::make_nth_of_tuple_property_map<1>(new_hedge), + PLY_property(ttag.c_str())) + ); + } + } + else // Read other elements and ignore + { + for (std::size_t j = 0; j < element.number_of_items(); ++ j) + { + for (std::size_t k = 0; k < element.number_of_properties(); ++ k) + { + internal::PLY::PLY_read_number* property = element.property(k); + property->get (in); + if (in.fail()) + return false; + } + } + } + } + return !in.bad(); + } + + template + bool + read_PLY( std::istream& in, + std::vector< Point_3 >& points, + std::vector< Polygon_3 >& polygons, + std::vector& fcolors, + std::vector& vcolors, + bool /* verbose */ = false) + { + std::vector > dummy_pui; + std::vector > dummy_pf; + return read_PLY(in, points, polygons, + dummy_pui, + fcolors, vcolors, + dummy_pf); + } +} // namespace CGAL + +#endif // CGAL_IO_PLY_PLY_READER_H diff --git a/Stream_support/include/CGAL/IO/PLY/PLY_writer.h b/Stream_support/include/CGAL/IO/PLY/PLY_writer.h new file mode 100644 index 00000000000..0b394008634 --- /dev/null +++ b/Stream_support/include/CGAL/IO/PLY/PLY_writer.h @@ -0,0 +1,169 @@ +// Copyright (c) 2017 GeometryFactory +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// Author(s) : Simon Giraudot + +#ifndef CGAL_IO_PLY_PLY_WRITER_H +#define CGAL_IO_PLY_PLY_WRITER_H + +#include + +namespace CGAL{ + + template + bool + write_PLY(std::ostream& out, + const std::vector< Point_3 >& points, + const std::vector< Polygon_3 >& polygons, + bool /* verbose */ = false) + { + + if(!out) + { + std::cerr << "Error: cannot open file" << std::endl; + return false; + } + + // Write header + out << "ply" << std::endl + << ((get_mode(out) == IO::BINARY) ? "format binary_little_endian 1.0" : "format ascii 1.0") << std::endl + << "comment Generated by the CGAL library" << std::endl + << "element vertex " << points.size() << std::endl; + + internal::PLY::output_property_header (out, + make_ply_point_writer (CGAL::Identity_property_map())); + + out << "element face " << polygons.size() << std::endl; + + internal::PLY::output_property_header (out, + std::make_pair (CGAL::Identity_property_map(), + PLY_property >("vertex_indices"))); + + out << "end_header" << std::endl; + + for (std::size_t i = 0; i < points.size(); ++ i) + internal::PLY::output_properties (out, points.begin() + i, + make_ply_point_writer (CGAL::Identity_property_map())); + + for (std::size_t i = 0; i < polygons.size(); ++ i) + internal::PLY::output_properties (out, polygons.begin() + i, + std::make_pair (CGAL::Identity_property_map(), + PLY_property >("vertex_indices"))); + + return out.good(); + } + + template + bool + write_PLY(std::ostream& out, + const SurfaceMesh& mesh, + bool /* verbose */ = false) + { + typedef typename boost::graph_traits::face_descriptor face_descriptor; + typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; + typedef typename boost::property_map::type::value_type Point_3; + typedef typename SurfaceMesh::template Property_map > UV_map; + UV_map h_uv; + bool has_texture; + boost::tie(h_uv, has_texture) = mesh.template property_map >("h:uv"); + if(!out) + { + std::cerr << "Error: cannot open file" << std::endl; + return false; + } + + // Write header + out << "ply" << std::endl + << ((get_mode(out) == IO::BINARY) ? "format binary_little_endian 1.0" : "format ascii 1.0") << std::endl + << "comment Generated by the CGAL library" << std::endl + << "element vertex " << num_vertices(mesh) << std::endl; + + internal::PLY::output_property_header (out, + make_ply_point_writer (CGAL::Identity_property_map())); + + out << "element face " << num_faces(mesh) << std::endl; + + internal::PLY::output_property_header (out, + std::make_pair (CGAL::Identity_property_map >(), + PLY_property >("vertex_indices"))); + + if(has_texture) + { + out << "element halfedge " << num_halfedges(mesh) << std::endl; + + internal::PLY::output_property_header (out, + std::make_pair (CGAL::Identity_property_map(), + PLY_property("source"))); + + internal::PLY::output_property_header (out, + std::make_pair (CGAL::Identity_property_map(), + PLY_property("target"))); + internal::PLY::output_property_header (out, + std::make_tuple (h_uv, + PLY_property("u"), + PLY_property("v"))); + } + out << "end_header" << std::endl; + + for(vertex_descriptor vd : vertices(mesh)) + { + Point_3 p = get(get(CGAL::vertex_point, mesh), vd); + internal::PLY::output_properties (out, &p, + make_ply_point_writer (CGAL::Identity_property_map())); + } + + + std::vector polygon; + for(face_descriptor fd : faces(mesh)) + { + polygon.clear(); + for(halfedge_descriptor hd : halfedges_around_face(halfedge(fd, mesh), mesh)) + polygon.push_back (get(get(boost::vertex_index, mesh), target(hd,mesh))); + + internal::PLY::output_properties (out, &polygon, + std::make_pair (CGAL::Identity_property_map >(), + PLY_property >("vertex_indices"))); + } + + if(has_texture) + { + for(halfedge_descriptor hd : halfedges(mesh)) + { + typedef std::tuple Super_tuple; + Super_tuple t = + std::make_tuple(source(hd, mesh),target(hd, mesh), + h_uv[hd].first, + h_uv[hd].second); + + internal::PLY::output_properties (out, &t, + std::make_pair (Nth_of_tuple_property_map<0,Super_tuple>(), + PLY_property("source")), + std::make_pair (Nth_of_tuple_property_map<1,Super_tuple>(), + PLY_property("target")), + std::make_pair (Nth_of_tuple_property_map<2,Super_tuple>(), + PLY_property("u")), + std::make_pair (Nth_of_tuple_property_map<3,Super_tuple>(), + PLY_property("v"))); + } + } + return out.good(); + } + +} // namespace CGAL + +#endif // CGAL_IO_PLY_PLY_WRITER_H diff --git a/Stream_support/include/CGAL/IO/STL/STL_reader.h b/Stream_support/include/CGAL/IO/STL/STL_reader.h new file mode 100644 index 00000000000..e4056a99c0f --- /dev/null +++ b/Stream_support/include/CGAL/IO/STL/STL_reader.h @@ -0,0 +1,385 @@ +// Copyright (c) 2015 GeometryFactory +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// Author(s) : Andreas Fabri, +// Mael Rouxel-Labbé + +#ifndef CGAL_IO_STL_STL_READER_H +#define CGAL_IO_STL_STL_READER_H + +#include +#include + +#include + +#include +#include +#include +#include +#include + +namespace CGAL { + +template +bool read_ASCII_facet(std::istream& input, + std::vector& points, + std::vector& facets, + int& index, + std::map& index_map, + bool verbose = false) +{ + // Here, we have already read the word 'facet' and are looking to read till 'endfacet' + + std::string s; + std::string vertex("vertex"), + endfacet("endfacet"); + + int count = 0; + double x,y,z; + Point p; + Triangle ijk; + IO::internal::resize(ijk, 3); + + while(input >> s) + { + if(s == endfacet) + { + if(count != 3) + { + if(verbose) + std::cerr << "Error: only triangulated surfaces are supported" << std::endl; + + return false; + } + + facets.push_back(ijk); + return true; + } + else if(s == vertex) + { + if(count >= 3) + { + if(verbose) + std::cerr << "Error: only triangulated surfaces are supported" << std::endl; + + return false; + } + + if(!(input >> iformat(x) >> iformat(y) >> iformat(z))) + { + if(verbose) + std::cerr << "Error while reading point coordinates (premature end of file)" << std::endl; + + return false; + } + else + { + IO::internal::fill_point(x, y, z, p); + typename std::map::iterator iti = index_map.insert(std::make_pair(p, -1)).first; + + if(iti->second == -1) + { + ijk[count] = index; + iti->second = index++; + points.push_back(p); + } + else + { + ijk[count] = iti->second; + } + } + + ++count; + } + } + + if(verbose) + std::cerr << "Error while reading facet (premature end of file)" << std::endl; + + return false; +} + +template +bool parse_ASCII_STL(std::istream& input, + std::vector& points, + std::vector& facets, + bool verbose = false) +{ + if(verbose) + std::cout << "Parsing ASCII file..." << std::endl; + + if(!input.good()) + return true; + + // Here, we have already read the word 'solid' + + int index = 0; + std::map index_map; + + std::string s, facet("facet"), endsolid("endsolid"), solid("solid"); + bool in_solid(false); + while(input >> s) + { + if(s == solid) + { + if(in_solid) + { + break; + } + in_solid = true; + } + if(s == facet) + { + if(!read_ASCII_facet(input, points, facets, index, index_map, verbose)) + return false; + } + else if(s == endsolid) + { + in_solid = false; + } + } + + if(in_solid){ + if(verbose) + std::cerr << "Error while parsing ASCII file" << std::endl; + + return false; + } + return true; +} + +template +bool parse_binary_STL(std::istream& input, + std::vector& points, + std::vector& facets, + bool verbose = false) +{ + if(verbose) + std::cout << "Parsing binary file..." << std::endl; + + // Start from the beginning again to simplify things + input.clear(); + input.seekg(0, std::ios::beg); + + if(!input.good()) + return true; + + // Discard the first 80 chars (unused header) + int pos = 0; + char c; + + if(verbose) + std::cout << "header: "; + + while(pos < 80) + { + input.read(reinterpret_cast(&c), sizeof(c)); + if(!input.good()) + break; + + if(verbose) + std::cout << c; + + ++pos; + } + + if(verbose) + std::cout << std::endl; + + if(pos != 80) + return true; // empty file + + int index = 0; + std::map index_map; + + boost::uint32_t N32; + if(!(input.read(reinterpret_cast(&N32), sizeof(N32)))) + { + if(verbose) + std::cerr << "Error while reading number of facets" << std::endl; + + return false; + } + + unsigned int N = N32; + if(verbose) + std::cout << N << " facets to read" << std::endl; + + for(unsigned int i=0; i(&normal[0]), sizeof(normal[0]))) || + !(input.read(reinterpret_cast(&normal[1]), sizeof(normal[1]))) || + !(input.read(reinterpret_cast(&normal[2]), sizeof(normal[2])))) + { + if(verbose) + std::cerr << "Error while reading normal coordinates (premature end of file)" << std::endl; + + return false; + } + + Triangle ijk; + IO::internal::resize(ijk, 3); + + for(int j=0; j<3; ++j) + { + float x,y,z; + if(!(input.read(reinterpret_cast(&x), sizeof(x))) || + !(input.read(reinterpret_cast(&y), sizeof(y))) || + !(input.read(reinterpret_cast(&z), sizeof(z)))) + { + if(verbose) + std::cerr << "Error while reading vertex coordinates (premature end of file)" << std::endl; + + return false; + } + + Point p; + IO::internal::fill_point(x, y, z, p); + + typename std::map::iterator iti = index_map.insert(std::make_pair(p, -1)).first; + + if(iti->second == -1) + { + ijk[j] = index; + iti->second = index++; + points.push_back(p); + } + else + { + ijk[j] = iti->second; + } + } + + facets.push_back(ijk); + + // Read so-called attribute byte count and ignore it + char c; + if(!(input.read(reinterpret_cast(&c), sizeof(c))) || + !(input.read(reinterpret_cast(&c), sizeof(c)))) + { + if(verbose) + std::cerr << "Error while reading attribute byte count (premature end of file)" << std::endl; + + return false; + } + } + + return true; +} + +// +// Read a file with `.stl` format. +// +// \tparam Point must be a model of the concept `RandomAccessContainer` or a %CGAL point type +// \tparam Triangle must be a model of the concept `RandomAccessContainer` +// +// \param input the input stream +// \param points a container that will contain the points used in the .stl file +// \param polygons a container that will contain the triangles used in the .stl file +// \param verbose whether to enable or not a sanity log +// +// \returns `true` if the reading process went well, `false` otherwise +// +// \warning `points` and `facets` are not cleared: new points and triangles are added to the back +// of the containers. +// +// Although the STL file format uses triangles, it is convenient to be able to use vectors +// and other models of the `SequenceContainer` (instead of arrays) for the face type, +// to avoid having to convert the to apply polygon soup reparation algorithms. +template +bool read_STL(std::istream& input, + std::vector& points, + std::vector& facets, + bool verbose = false) +{ + int pos = 0; + + // Ignore all initial whitespace + unsigned char c; + + while(input.read(reinterpret_cast(&c), sizeof(c))) + { + if(!isspace(c)) + { + input.unget(); // move back to the first interesting char + break; + } + ++pos; + } + + if(!input.good()) // reached the end + return true; + + // If we have gone beyond 80 characters and have not read anything yet, + // then this must be an ASCII file. + if(pos > 80) + return parse_ASCII_STL(input, points, facets, verbose); + + // We are within the first 80 characters, both ASCII and binary are possible + + // Read the 5 first characters to check if the first word is "solid" + std::string s, solid("solid"); + + char word[5]; + if(input.read(reinterpret_cast(&word[0]), sizeof(c)) && + input.read(reinterpret_cast(&word[1]), sizeof(c)) && + input.read(reinterpret_cast(&word[2]), sizeof(c)) && + input.read(reinterpret_cast(&word[3]), sizeof(c)) && + input.read(reinterpret_cast(&word[4]), sizeof(c))) + { + s = std::string(word, 5); + pos += 5; + } + else + return true; // empty file + + // If the first word is not 'solid', the file must be binary + if(s != solid) + { + if(parse_binary_STL(input, points, facets, verbose)) + { + return true; + } + else + { + // If we failed to read it as a binary, try as ASCII just in case... + // The file does not start with 'solid' anyway, so it's fine to reset it. + input.clear(); + input.seekg(0, std::ios::beg); + return parse_ASCII_STL(input, points, facets, verbose); + } + } + + // Now, we have found the keyword "solid" which is supposed to indicate that the file is ASCII + input.clear(); + input.seekg(0, std::ios::beg); //the parser needs to read all "solid" to work correctly. + if(parse_ASCII_STL(input, points, facets, verbose)) + { + // correctly read the input as an ASCII file + return true; + } + else // Failed to read the ASCII file + { + // It might have actually have been a binary file... ? + return parse_binary_STL(input, points, facets, verbose); + } +} + +} // namespace CGAL + +#endif // CGAL_IO_STL_STL_READER_H diff --git a/Stream_support/include/CGAL/IO/STL/STL_writer.h b/Stream_support/include/CGAL/IO/STL/STL_writer.h new file mode 100644 index 00000000000..6bf46b593d1 --- /dev/null +++ b/Stream_support/include/CGAL/IO/STL/STL_writer.h @@ -0,0 +1,98 @@ +// Copyright (c) 2017 GeometryFactory +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// Author(s) : Sebastien Loriot + +#ifndef CGAL_IO_STL_STL_WRITER_H +#define CGAL_IO_STL_STL_WRITER_H + +#include +#include + +#include +#include + + + +namespace CGAL{ + +template +std::ostream& +write_STL(const TriangleMesh& tm, std::ostream& out) +{ + typedef typename boost::graph_traits::face_descriptor face_descriptor; + typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; + typedef typename boost::property_map::const_type Vpm; + typedef typename boost::property_traits::reference Point_3_ref; + typedef typename boost::property_traits::value_type Point_3; + typedef typename Kernel_traits::Kernel::Vector_3 Vector_3; + + Vpm vpm = get(boost::vertex_point, tm); + + if (get_mode(out) == IO::BINARY) + { + out << "FileType: Binary "; + const boost::uint32_t N32 = static_cast(faces(tm).size()); + out.write(reinterpret_cast(&N32), sizeof(N32)); + + for(face_descriptor f : faces(tm)) + { + halfedge_descriptor h = halfedge(f, tm); + Point_3_ref p = get(vpm, target(h, tm)); + Point_3_ref q = get(vpm, target(next(h, tm), tm)); + Point_3_ref r = get(vpm, source(h, tm)); + + Vector_3 n = collinear(p,q,r) ? Vector_3(1,0,0): + unit_normal(p,q,r); + + const float coords[12]={ + static_cast(n.x()), static_cast(n.y()), static_cast(n.z()), + static_cast(p.x()), static_cast(p.y()), static_cast(p.z()), + static_cast(q.x()), static_cast(q.y()), static_cast(q.z()), + static_cast(r.x()), static_cast(r.y()), static_cast(r.z()) }; + + for (int i=0; i<12; ++i) + out.write(reinterpret_cast(&coords[i]), sizeof(coords[i])); + out << " "; + } + } + else + { + out << "solid\n"; + for(face_descriptor f : faces(tm)) + { + halfedge_descriptor h = halfedge(f, tm); + Point_3_ref p = get(vpm, target(h, tm)); + Point_3_ref q = get(vpm, target(next(h, tm), tm)); + Point_3_ref r = get(vpm, source(h, tm)); + + Vector_3 n = collinear(p,q,r) ? Vector_3(1,0,0): + unit_normal(p,q,r); + out << "facet normal " << n << "\nouter loop\n"; + out << "vertex " << p << "\n"; + out << "vertex " << q << "\n"; + out << "vertex " << r << "\n"; + out << "endloop\nendfacet\n"; + } + out << "endsolid\n"; + } + return out; +} + +} // end of namespace CGAL + +#endif // CGAL_IO_STL_STL_WRITER_H diff --git a/Stream_support/include/CGAL/IO/VRML/Polyhedron_VRML_1_ostream.h b/Stream_support/include/CGAL/IO/VRML/Polyhedron_VRML_1_ostream.h new file mode 100644 index 00000000000..feab1e5a9a6 --- /dev/null +++ b/Stream_support/include/CGAL/IO/VRML/Polyhedron_VRML_1_ostream.h @@ -0,0 +1,32 @@ +// Copyright (c) 1997 ETH Zurich (Switzerland). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0+ +// +// +// Author(s) : Lutz Kettner + +#ifndef CGAL_IO_POLYHEDRON_VRML_1_OSTREAM_H +#define CGAL_IO_POLYHEDRON_VRML_1_OSTREAM_H 1 + +#include + + +#include +#include + +#endif // CGAL_IO_POLYHEDRON_VRML_1_OSTREAM_H // +// EOF // diff --git a/Stream_support/include/CGAL/IO/VRML/Polyhedron_VRML_2_ostream.h b/Stream_support/include/CGAL/IO/VRML/Polyhedron_VRML_2_ostream.h new file mode 100644 index 00000000000..a105cd1534e --- /dev/null +++ b/Stream_support/include/CGAL/IO/VRML/Polyhedron_VRML_2_ostream.h @@ -0,0 +1,51 @@ +// Copyright (c) 1997 ETH Zurich (Switzerland). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0+ +// +// +// Author(s) : Lutz Kettner + +#ifndef CGAL_IO_POLYHEDRON_VRML_2_OSTREAM_H +#define CGAL_IO_POLYHEDRON_VRML_2_OSTREAM_H 1 + +#include + + +#include +#include +#include +#include +#include +#include + +namespace CGAL { + +template < class Traits, + class Items, + template < class T, class I, class A> + class HDS, class Alloc> +VRML_2_ostream& +operator<<( VRML_2_ostream& out, + const Polyhedron_3& P) { + File_writer_VRML_2 writer; + generic_print_polyhedron( out.os(), P, writer); + return out; +} + +} //namespace CGAL +#endif // CGAL_IO_POLYHEDRON_VRML_2_OSTREAM_H // +// EOF // diff --git a/Stream_support/include/CGAL/IO/VRML/print_VRML_1.h b/Stream_support/include/CGAL/IO/VRML/print_VRML_1.h new file mode 100644 index 00000000000..1ae8b90deed --- /dev/null +++ b/Stream_support/include/CGAL/IO/VRML/print_VRML_1.h @@ -0,0 +1,53 @@ +// Copyright (c) 1997 ETH Zurich (Switzerland). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0+ +// +// +// Author(s) : Lutz Kettner + +#ifndef CGAL_IO_PRINT_VRML_1_H +#define CGAL_IO_PRINT_VRML_1_H 1 + +#include + + +#include + +namespace CGAL { + +template +void print_polyhedron_VRML_1( std::ostream& out, const Polyhedron& P) { + VRML_1_ostream os( out); + os << P; +} + +// Deprecated global functions, replaced with functions above + +template < class Traits, + class Items, + template < class T, class I, class A> + class HDS, class Alloc> +void +print_VRML_1( std::ostream& out, + const Polyhedron_3& P) { + VRML_1_ostream os( out); + os << P; +} + +} //namespace CGAL +#endif // CGAL_IO_PRINT_VRML_1_H // +// EOF // diff --git a/Stream_support/include/CGAL/IO/VRML/print_VRML_2.h b/Stream_support/include/CGAL/IO/VRML/print_VRML_2.h new file mode 100644 index 00000000000..a960bbea40a --- /dev/null +++ b/Stream_support/include/CGAL/IO/VRML/print_VRML_2.h @@ -0,0 +1,53 @@ +// Copyright (c) 1997 ETH Zurich (Switzerland). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0+ +// +// +// Author(s) : Lutz Kettner + +#ifndef CGAL_IO_PRINT_VRML_2_H +#define CGAL_IO_PRINT_VRML_2_H 1 + +#include + + +#include + +namespace CGAL { + +template +void print_polyhedron_VRML_2( std::ostream& out, const Polyhedron& P) { + VRML_2_ostream os( out); + os << P; +} + +// Deprecated global functions, replaced with functions above + +template < class Traits, + class Items, + template < class T, class I, class A> + class HDS, class Alloc> +void +print_VRML_2( std::ostream& out, + const Polyhedron_3& P) { + VRML_2_ostream os( out); + os << P; +} + +} //namespace CGAL +#endif // CGAL_IO_PRINT_VRML_2_H // +// EOF // From 914c37b72f81548425833fbbbcf873be6b242311 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Wed, 7 Aug 2019 15:25:26 +0200 Subject: [PATCH 03/28] Move OFF files from Polyhedron_IO to Polyhedron/include/CGAL/IO --- .../include/CGAL/IO/Polyhedron_scan_OFF.h | 39 ----- Polyhedron_IO/include/CGAL/IO/print_OFF.h | 39 ----- Polyhedron_IO/include/CGAL/IO/scan_OFF.h | 36 ---- .../include/CGAL/IO/OFF/Polyhedron_scan_OFF.h | 159 ------------------ .../include/CGAL/IO/OFF/print_OFF.h | 100 ----------- Stream_support/include/CGAL/IO/OFF/scan_OFF.h | 68 -------- 6 files changed, 441 deletions(-) delete mode 100644 Polyhedron_IO/include/CGAL/IO/Polyhedron_scan_OFF.h delete mode 100644 Polyhedron_IO/include/CGAL/IO/print_OFF.h delete mode 100644 Polyhedron_IO/include/CGAL/IO/scan_OFF.h delete mode 100644 Stream_support/include/CGAL/IO/OFF/Polyhedron_scan_OFF.h delete mode 100644 Stream_support/include/CGAL/IO/OFF/print_OFF.h delete mode 100644 Stream_support/include/CGAL/IO/OFF/scan_OFF.h diff --git a/Polyhedron_IO/include/CGAL/IO/Polyhedron_scan_OFF.h b/Polyhedron_IO/include/CGAL/IO/Polyhedron_scan_OFF.h deleted file mode 100644 index 85dae1dc77c..00000000000 --- a/Polyhedron_IO/include/CGAL/IO/Polyhedron_scan_OFF.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) 1997 ETH Zurich (Switzerland). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org). -// You can redistribute it and/or modify it under the terms of the GNU -// General Public License as published by the Free Software Foundation, -// either version 3 of the License, or (at your option) any later version. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: GPL-3.0+ -// -// -// Author(s) : Lutz Kettner - -#ifndef CGAL_IO_POLYHEDRON_SCAN_OFF_H -#define CGAL_IO_POLYHEDRON_SCAN_OFF_H 1 - -#include - -#include - -#define CGAL_DEPRECATED_HEADER "" -#define CGAL_REPLACEMENT_HEADER "" -#include -#include - -#include - -#endif // CGAL_IO_POLYHEDRON_SCAN_OFF_H // -// EOF // - - diff --git a/Polyhedron_IO/include/CGAL/IO/print_OFF.h b/Polyhedron_IO/include/CGAL/IO/print_OFF.h deleted file mode 100644 index afad74ec48d..00000000000 --- a/Polyhedron_IO/include/CGAL/IO/print_OFF.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) 1997 ETH Zurich (Switzerland). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org). -// You can redistribute it and/or modify it under the terms of the GNU -// General Public License as published by the Free Software Foundation, -// either version 3 of the License, or (at your option) any later version. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: GPL-3.0+ -// -// -// Author(s) : Lutz Kettner - -#ifndef CGAL_IO_PRINT_OFF_H -#define CGAL_IO_PRINT_OFF_H 1 - -#include - -#include - -#define CGAL_DEPRECATED_HEADER "" -#define CGAL_REPLACEMENT_HEADER "" -#include -#include - -#include - - -#endif // CGAL_IO_PRINT_OFF_H // -// EOF // - diff --git a/Polyhedron_IO/include/CGAL/IO/scan_OFF.h b/Polyhedron_IO/include/CGAL/IO/scan_OFF.h deleted file mode 100644 index 2b0b7e74e02..00000000000 --- a/Polyhedron_IO/include/CGAL/IO/scan_OFF.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 1997 ETH Zurich (Switzerland). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org). -// You can redistribute it and/or modify it under the terms of the GNU -// General Public License as published by the Free Software Foundation, -// either version 3 of the License, or (at your option) any later version. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: GPL-3.0+ -// -// -// Author(s) : Lutz Kettner - -#ifndef CGAL_IO_SCAN_OFF_H -#define CGAL_IO_SCAN_OFF_H 1 - -#include - -#include - -#define CGAL_DEPRECATED_HEADER "" -#define CGAL_REPLACEMENT_HEADER "" -#include -#include " -#include - -#endif // CGAL_IO_SCAN_OFF_H // -// EOF // diff --git a/Stream_support/include/CGAL/IO/OFF/Polyhedron_scan_OFF.h b/Stream_support/include/CGAL/IO/OFF/Polyhedron_scan_OFF.h deleted file mode 100644 index 1799bd810f5..00000000000 --- a/Stream_support/include/CGAL/IO/OFF/Polyhedron_scan_OFF.h +++ /dev/null @@ -1,159 +0,0 @@ -// Copyright (c) 1997 ETH Zurich (Switzerland). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org). -// You can redistribute it and/or modify it under the terms of the GNU -// General Public License as published by the Free Software Foundation, -// either version 3 of the License, or (at your option) any later version. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: GPL-3.0+ -// -// -// Author(s) : Lutz Kettner - -#ifndef CGAL_IO_OFF_POLYHEDRON_SCAN_OFF_H -#define CGAL_IO_OFF_POLYHEDRON_SCAN_OFF_H 1 - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace CGAL { - -template < class HDS> -class Polyhedron_scan_OFF : public Modifier_base { -protected: - std::istream& m_in; - File_header_OFF m_file_header; -public: - - typedef HDS Halfedge_data_structure; - -// DEFINITION -// -// Polyhedron_scan_OFF is a polyhedral surface builder. -// It scans a polyhedron given in OFF from a stream and appends it -// incrementally using the incremental builder. - - Polyhedron_scan_OFF( std::istream& in, bool verbose = false) - : m_in(in), m_file_header( verbose) {} - - // Activation - void operator()( HDS& hds); - - const File_header_OFF& header() const { return m_file_header; } -}; - -template < class HDS > -void -Polyhedron_scan_OFF:: operator()( HDS& target) { - File_scanner_OFF scanner( m_in, m_file_header.verbose()); - if ( ! m_in) { - if ( scanner.verbose()) { - std::cerr << " " << std::endl; - std::cerr << "Polyhedron_scan_OFF::" << std::endl; - std::cerr << "operator(): input error: file format is not in " - "OFF." << std::endl; - } - return; - } - m_file_header = scanner; // Remember file header after return. - - Polyhedron_incremental_builder_3 B( target, scanner.verbose()); - B.begin_surface( scanner.size_of_vertices(), - scanner.size_of_facets(), - scanner.size_of_halfedges()); - - typedef typename HDS::Traits Traits; - typedef typename Traits::Point_3 Point; - - // read in all vertices - std::size_t i; - 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); - } - else - scanner.skip_to_next_vertex( i); - } - if ( ! m_in || B.error()) { - B.rollback(); - m_in.clear( std::ios::badbit); - return; - } - - // read in all facets - for ( i = 0; i < scanner.size_of_facets(); i++) { - B.begin_facet(); - std::size_t no; - scanner.scan_facet( no, i); - if( ! m_in || B.error() || no < 3) { - if ( scanner.verbose()) { - std::cerr << " " << std::endl; - std::cerr << "Polyhedron_scan_OFF::" << std::endl; - std::cerr << "operator()(): input error: facet " << i - << " has less than 3 vertices." << std::endl; - } - B.rollback(); - m_in.clear( std::ios::badbit); - return; - } - for ( std::size_t j = 0; j < no; j++) { - std::size_t index; - scanner.scan_facet_vertex_index( index, i); - B.add_vertex_to_facet( index); - } - //TO DO : Insert read color - B.end_facet(); - scanner.skip_to_next_facet( i); - } - if ( ! m_in || B.error()) { - B.rollback(); - m_in.clear( std::ios::badbit); - return; - } - if ( B.check_unconnected_vertices()) { - if ( ! B.remove_unconnected_vertices()) { - if ( scanner.verbose()) { - std::cerr << " " << std::endl; - std::cerr << "Polyhedron_scan_OFF::" << std::endl; - std::cerr << "operator()(): input error: cannot " - "successfully remove isolated vertices." - << std::endl; - } - B.rollback(); - m_in.clear( std::ios::badbit); - return; - } - } - B.end_surface(); -} - -} //namespace CGAL - -#include - -#endif // CGAL_IO_OFF_POLYHEDRON_SCAN_OFF_H // -// EOF // diff --git a/Stream_support/include/CGAL/IO/OFF/print_OFF.h b/Stream_support/include/CGAL/IO/OFF/print_OFF.h deleted file mode 100644 index 1daef06ec94..00000000000 --- a/Stream_support/include/CGAL/IO/OFF/print_OFF.h +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright (c) 1997 ETH Zurich (Switzerland). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org). -// You can redistribute it and/or modify it under the terms of the GNU -// General Public License as published by the Free Software Foundation, -// either version 3 of the License, or (at your option) any later version. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: GPL-3.0+ -// -// -// Author(s) : Lutz Kettner - -#ifndef CGAL_IO_OFF_PRINT_OFF_H -#define CGAL_IO_OFF_PRINT_OFF_H 1 - -#include - - -#include -#include -#include -#include -#include - -namespace CGAL { - -template -void print_polyhedron_with_header_OFF( std::ostream& out, - const Polyhedron& P, - const File_header_OFF& header, - const Vpm& vpm) { - File_writer_OFF writer( header); - writer.header().set_polyhedral_surface( true); - writer.header().set_halfedges( P.size_of_halfedges()); - generic_print_polyhedron( out, P, writer, vpm); -} - -template -void print_polyhedron_with_header_OFF( std::ostream& out, - const Polyhedron& P, - const File_header_OFF& header) -{ - print_polyhedron_with_header_OFF(out, P, header, get(CGAL::vertex_point, P)); -} - -template -void print_polyhedron_OFF( std::ostream& out, - const Polyhedron& P, - bool verbose = false) { - File_header_OFF header( verbose); - header.set_binary( is_binary( out)); - header.set_no_comments( ! is_pretty( out)); - print_polyhedron_with_header_OFF( out, P, header); -} - - -// Deprecated global functions, replaced with functions above - -template < class Traits, - class Items, - template < class T, class I, class A> - class HDS, class Alloc> -void -print_OFF( std::ostream& out, - const Polyhedron_3& P, - bool verbose = false) { - File_writer_OFF writer( verbose); - writer.header().set_binary( is_binary( out)); - writer.header().set_no_comments( ! is_pretty( out)); - writer.header().set_polyhedral_surface( true); - writer.header().set_halfedges( P.size_of_halfedges()); - generic_print_polyhedron( out, P, writer); -} - -template < class Traits, - class Items, - template < class T, class I, class A> - class HDS, class Alloc> -void -print_OFF( std::ostream& out, - const Polyhedron_3& P, - const File_header_OFF& header) { - File_writer_OFF writer( header); - writer.header().set_polyhedral_surface( true); - writer.header().set_halfedges( P.size_of_halfedges()); - generic_print_polyhedron( out, P, writer); -} - -} //namespace CGAL -#endif // CGAL_IO_OFF_PRINT_OFF_H // -// EOF // diff --git a/Stream_support/include/CGAL/IO/OFF/scan_OFF.h b/Stream_support/include/CGAL/IO/OFF/scan_OFF.h deleted file mode 100644 index b8a6ca7f9b4..00000000000 --- a/Stream_support/include/CGAL/IO/OFF/scan_OFF.h +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) 1997 ETH Zurich (Switzerland). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org). -// You can redistribute it and/or modify it under the terms of the GNU -// General Public License as published by the Free Software Foundation, -// either version 3 of the License, or (at your option) any later version. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: GPL-3.0+ -// -// -// Author(s) : Lutz Kettner - -#ifndef CGAL_IO_OFF_SCAN_OFF_H -#define CGAL_IO_OFF_SCAN_OFF_H 1 - -#include - - -#include -#include -#include - -namespace CGAL { - -template < class Traits, - class Items, - template < class T, class I, class A> - class HDS, class Alloc> -void scan_OFF( std::istream& in, - Polyhedron_3& P, - File_header_OFF& header) { - // reads a polyhedron from `in' and appends it to P. - // Returns also the File_header_OFF structure of the object. - typedef Polyhedron_3 Polyhedron; - typedef typename Polyhedron::HalfedgeDS HalfedgeDS; - typedef Polyhedron_scan_OFF Scanner; - Scanner scanner( in, header.verbose()); - P.delegate(scanner); - header = scanner.header(); -} - -template < class Traits, - class Items, - template < class T, class I, class A> - class HDS, class Alloc> -void scan_OFF( std::istream& in, Polyhedron_3& P, - bool verbose = false) { - // reads a polyhedron from `in' and appends it to P. - typedef Polyhedron_3 Polyhedron; - typedef typename Polyhedron::HalfedgeDS HalfedgeDS; - typedef Polyhedron_scan_OFF Scanner; - Scanner scanner( in, verbose); - P.delegate(scanner); -} - - -} //namespace CGAL -#endif // CGAL_IO_OFF_SCAN_OFF_H // -// EOF // From 8f793736c73d4c9867821d019b5c91faa5a8d571 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Wed, 7 Aug 2019 16:00:47 +0200 Subject: [PATCH 04/28] Move LGPL stuff to Stream_support, and Polyhedron_IO GPL stuff to Polyhedron/include/CGAL/IO. Deprecate headers that need it. As a consequence, Inventor and Polyhedron_IO are entirely deprecated. --- .../CGAL/IO/Alpha_shape_3_VRML_2_ostream.h | 81 +---- Inventor/include/CGAL/IO/Inventor_ostream.h | 108 +----- Inventor/include/CGAL/IO/VRML_1_ostream.h | 82 +---- Inventor/include/CGAL/IO/VRML_2_ostream.h | 295 +--------------- .../CGAL/IO/Polyhedron_VRML_1_ostream.h | 0 .../CGAL/IO/Polyhedron_VRML_2_ostream.h | 0 .../CGAL/IO/Polyhedron_builder_from_STL.h | 4 +- .../CGAL/IO/Polyhedron_geomview_ostream.h | 0 .../CGAL/IO/Polyhedron_inventor_ostream.h | 0 .../include/CGAL/IO/Polyhedron_iostream.h | 0 .../include/CGAL/IO/Polyhedron_scan_OFF.h | 159 +++++++++ .../CGAL/IO/generic_print_polyhedron.h | 0 Polyhedron/include/CGAL/IO/print_OFF.h | 100 ++++++ .../include/CGAL/IO/print_VRML_1.h | 0 .../include/CGAL/IO/print_VRML_2.h | 0 .../include/CGAL/IO/print_inventor.h | 0 .../include/CGAL/IO}/print_wavefront.h | 6 +- Polyhedron/include/CGAL/IO/scan_OFF.h | 68 ++++ .../include/CGAL/IO/print_wavefront.h | 37 -- .../IO/VRML/Alpha_shape_3_VRML_2_ostream.h | 104 ++++++ .../include/CGAL/IO/VRML/Inventor_ostream.h | 135 ++++++++ .../CGAL/IO/VRML/Polyhedron_VRML_1_ostream.h | 32 -- .../CGAL/IO/VRML/Polyhedron_VRML_2_ostream.h | 51 --- .../include/CGAL/IO/VRML/VRML_1_ostream.h | 109 ++++++ .../include/CGAL/IO/VRML/VRML_2_ostream.h | 321 ++++++++++++++++++ .../include/CGAL/IO/VRML/print_VRML_1.h | 53 --- .../include/CGAL/IO/VRML/print_VRML_2.h | 53 --- .../include/CGAL/IO/reader_helpers.h | 0 28 files changed, 1026 insertions(+), 772 deletions(-) rename {Polyhedron_IO => Polyhedron}/include/CGAL/IO/Polyhedron_VRML_1_ostream.h (100%) rename {Polyhedron_IO => Polyhedron}/include/CGAL/IO/Polyhedron_VRML_2_ostream.h (100%) rename {Polyhedron_IO => Polyhedron}/include/CGAL/IO/Polyhedron_builder_from_STL.h (96%) rename {Polyhedron_IO => Polyhedron}/include/CGAL/IO/Polyhedron_geomview_ostream.h (100%) rename {Polyhedron_IO => Polyhedron}/include/CGAL/IO/Polyhedron_inventor_ostream.h (100%) rename {Polyhedron_IO => Polyhedron}/include/CGAL/IO/Polyhedron_iostream.h (100%) create mode 100644 Polyhedron/include/CGAL/IO/Polyhedron_scan_OFF.h rename {Polyhedron_IO => Polyhedron}/include/CGAL/IO/generic_print_polyhedron.h (100%) create mode 100644 Polyhedron/include/CGAL/IO/print_OFF.h rename {Polyhedron_IO => Polyhedron}/include/CGAL/IO/print_VRML_1.h (100%) rename {Polyhedron_IO => Polyhedron}/include/CGAL/IO/print_VRML_2.h (100%) rename {Polyhedron_IO => Polyhedron}/include/CGAL/IO/print_inventor.h (100%) rename {Stream_support/include/CGAL/IO/OBJ => Polyhedron/include/CGAL/IO}/print_wavefront.h (92%) create mode 100644 Polyhedron/include/CGAL/IO/scan_OFF.h delete mode 100644 Polyhedron_IO/include/CGAL/IO/print_wavefront.h create mode 100644 Stream_support/include/CGAL/IO/VRML/Alpha_shape_3_VRML_2_ostream.h create mode 100644 Stream_support/include/CGAL/IO/VRML/Inventor_ostream.h delete mode 100644 Stream_support/include/CGAL/IO/VRML/Polyhedron_VRML_1_ostream.h delete mode 100644 Stream_support/include/CGAL/IO/VRML/Polyhedron_VRML_2_ostream.h create mode 100644 Stream_support/include/CGAL/IO/VRML/VRML_1_ostream.h create mode 100644 Stream_support/include/CGAL/IO/VRML/VRML_2_ostream.h delete mode 100644 Stream_support/include/CGAL/IO/VRML/print_VRML_1.h delete mode 100644 Stream_support/include/CGAL/IO/VRML/print_VRML_2.h rename {Polyhedron_IO => Stream_support}/include/CGAL/IO/reader_helpers.h (100%) diff --git a/Inventor/include/CGAL/IO/Alpha_shape_3_VRML_2_ostream.h b/Inventor/include/CGAL/IO/Alpha_shape_3_VRML_2_ostream.h index 8c2364b3c58..25357db6695 100644 --- a/Inventor/include/CGAL/IO/Alpha_shape_3_VRML_2_ostream.h +++ b/Inventor/include/CGAL/IO/Alpha_shape_3_VRML_2_ostream.h @@ -24,81 +24,12 @@ #ifndef CGAL_ALPHA_SHAPE_3_VRML_2_OSTREAM_H #define CGAL_ALPHA_SHAPE_3_VRML_2_OSTREAM_H +#include -#include -#include - -#ifdef CGAL_ALPHA_SHAPE_3_H -namespace CGAL { - -template -VRML_2_ostream& -operator<<(VRML_2_ostream& os, - Alpha_shape_3
&as) -{ - // Finite vertices coordinates. - Alpha_shape_3
::Alpha_shape_vertices_iterator Vlist_it, - Vlist_begin = as.alpha_shape_vertices_begin(), - Vlist_end = as.alpha_shape_vertices_end(); - - std::map::Vertex_handle, int> V; - int number_of_vertex = 0; - for( Vlist_it = Vlist_begin; Vlist_it != Vlist_end; Vlist_it++) { - V[*Vlist_it] = number_of_vertex++; - } - - typename Alpha_shape_3
::Alpha_shape_facets_iterator Flist_it, - Flist_begin = as.alpha_shape_facets_begin(), - Flist_end = as.alpha_shape_facets_end(); - - std::map::Facet, int> F; - int number_of_facets = 0; - for( Flist_it = Flist_begin; Flist_it != Flist_end; Flist_it++) { - F[*Flist_it] = number_of_facets++; - } - - const char *Indent = " "; - os << " Group {\n" - " children [\n" - " Shape {\n" - " appearance USE A1\n" - " geometry\n" - " IndexedFaceSet {\n" - " coord Coordinate {\n" - " point [ \n" - << Indent << " "; - for( Vlist_it = Vlist_begin; Vlist_it != Vlist_end; Vlist_it++) { - os << CGAL::to_double((*Vlist_it)->point().x()) << " "; - os << CGAL::to_double((*Vlist_it)->point().y()) << " "; - os << CGAL::to_double((*Vlist_it)->point().z()) << ",\n" << Indent << " "; - } - os << "\n ]\n" - " } # coord\n" - " solid FALSE\n" - << Indent << "coordIndex [\n"; - // Finite facets indices. - for( Flist_it = Flist_begin; Flist_it != Flist_end; Flist_it++){ - os << Indent << " "; - for (int i=0; i<4; i++) - if (i != (*Flist_it).second){ - os << V[(*Flist_it).first->vertex(i)]; - os << ", "; - } - if (Flist_it != Flist_end) - os << "-1,\n"; - else - os << "-1 \n"; - } - os << Indent << "]\n"; - " } #IndexedFaceSet\n" - " } #Shape\n" - " ] #children\n" - " } #Group\n"; - - return os; -} - -} //namespace CGAL -#endif // CGAL_ALPHA_SHAPE_3_H +#define CGAL_DEPRECATED_HEADER "" +#define CGAL_REPLACEMENT_HEADER "" +#include +#include +#include #endif CGAL_ALPHA_SHAPE_3_VRML_2_OSTREAM_H diff --git a/Inventor/include/CGAL/IO/Inventor_ostream.h b/Inventor/include/CGAL/IO/Inventor_ostream.h index 1450cce7199..4ab2f32ee02 100644 --- a/Inventor/include/CGAL/IO/Inventor_ostream.h +++ b/Inventor/include/CGAL/IO/Inventor_ostream.h @@ -28,108 +28,12 @@ #ifndef CGAL_IO_INVENTOR_OSTREAM_H #define CGAL_IO_INVENTOR_OSTREAM_H -#include -#include +#include -// OpenInventor and VRML 1.0 are quite similar formats, so -// output operators could be shared if they use the following -// base class, which is common for both output streams. - -namespace CGAL { - -class Inventor_ostream_base { -private: - std::ostream* m_os; -public: - Inventor_ostream_base() : m_os(0) {} - Inventor_ostream_base(std::ostream& o) : m_os(&o) {} - ~Inventor_ostream_base() { close(); } - void open(std::ostream& o) { m_os = &o; } - void close() { - if ( m_os) - os() << std::endl; - m_os = 0; - } - explicit operator bool () - { - return m_os && !m_os->fail(); - } - - std::ostream& os() { - // The behaviour if m_os == 0 could be changed to return - // cerr or a file handle to /dev/null. The latter one would - // mimick the behaviour that one can still use a stream with - // an invalid stream, but without producing any output. - CGAL_assertion( m_os != 0 ); - return *m_os; - } -}; - - -class Inventor_ostream : public Inventor_ostream_base -{ -public: - Inventor_ostream() {} - Inventor_ostream(std::ostream& o) : Inventor_ostream_base(o) { - header(); - } - void open(std::ostream& o) { - Inventor_ostream_base::open(o); - header(); - } -private: - void header() { - os() << "#Inventor V2.0 ascii" << std::endl; - os() << "# File written with the help of the CGAL Library" - << std::endl; - } -}; - -} //namespace CGAL -#endif // CGAL_IO_INVENTOR_OSTREAM_H - - -#ifdef CGAL_TETRAHEDRON_3_H -#ifndef CGAL_INVENTOR_TETRAHEDRON_3 -#define CGAL_INVENTOR_TETRAHEDRON_3 - -namespace CGAL { - -template -Inventor_ostream& -operator<<(Inventor_ostream& os, - const Tetrahedron_3 &t) -{ - const char *Indent = " "; - os.os() << "\n Separator {"; - os.os() << "\n Coordinate3 { \n" - << Indent << "point [\n" - << Indent << " " - << CGAL::to_double(t[0].x()) << " " - << CGAL::to_double(t[0].y()) << " " - << CGAL::to_double(t[0].z()) << " ,\n" - << Indent << " " - << CGAL::to_double(t[1].x()) << " " - << CGAL::to_double(t[1].y()) << " " - << CGAL::to_double(t[1].z()) << " ,\n" - << Indent << " " - << CGAL::to_double(t[2].x()) << " " - << CGAL::to_double(t[2].y()) << " " - << CGAL::to_double(t[2].z()) << " ,\n" - << Indent << " " - << CGAL::to_double(t[3].x()) << " " - << CGAL::to_double(t[3].y()) << " " - << CGAL::to_double(t[3].z()) << " ]" - << "\n } #Coordinate3" ; - os.os() << "\n IndexedFaceSet {" - << Indent << "coordIndex [ 0,1,2,-1, 1,3,2,-1,\n" - << Indent << " 0,2,3,-1, 0,3,1,-1 ]\n" - << "\n } #IndexedFaceSet" - << "\n } #Separator\n"; - return os; -} - -} //namespace CGAL +#define CGAL_DEPRECATED_HEADER "" +#define CGAL_REPLACEMENT_HEADER "" +#include +#include +#include #endif // CGAL_INVENTOR_TETRAHEDRON_3 -#endif // CGAL_TETRAHEDRON_3_H diff --git a/Inventor/include/CGAL/IO/VRML_1_ostream.h b/Inventor/include/CGAL/IO/VRML_1_ostream.h index cc2c60ad823..06f38ef0a69 100644 --- a/Inventor/include/CGAL/IO/VRML_1_ostream.h +++ b/Inventor/include/CGAL/IO/VRML_1_ostream.h @@ -28,82 +28,12 @@ #ifndef CGAL_IO_VRML_1_OSTREAM_H #define CGAL_IO_VRML_1_OSTREAM_H -#include -#include +#include -// Declare the common base class for OpenInventor and VRML 1.0 format. -#include - -// OpenInventor and VRML 1.0 are quite similar formats, so -// output operators could be shared if they use the common -// base class Inventor_ostream_base, which is common for -// both output streams. - -namespace CGAL { - -class VRML_1_ostream : public Inventor_ostream_base { -public: - VRML_1_ostream() {} - VRML_1_ostream(std::ostream& o) : Inventor_ostream_base(o) { - header(); - } - void open(std::ostream& o) { - Inventor_ostream_base::open(o); - header(); - } -private: - void header() { - os() << "#VRML V1.0 ascii" << std::endl; - os() << "# File written with the help of the CGAL Library" - << std::endl; - } -}; - -} //namespace CGAL - -#endif // CGAL_IO_VRML_1_OSTREAM_H - -#ifdef CGAL_TETRAHEDRON_3_H -#ifndef CGAL_IO_VRML_1_TETRAHEDRON_3 -#define CGAL_IO_VRML_1_TETRAHEDRON_3 - -namespace CGAL { - -template -VRML_1_ostream& -operator<<(VRML_1_ostream& os, - const Tetrahedron_3 &t) -{ - const char *Indent = " "; - os.os() << "\n Separator {"; - os.os() << "\n Coordinate3 { \n" - << Indent << "point [\n" - << Indent << " " - << CGAL::to_double(t[0].x()) << " " - << CGAL::to_double(t[0].y()) << " " - << CGAL::to_double(t[0].z()) << " ,\n" - << Indent << " " - << CGAL::to_double(t[1].x()) << " " - << CGAL::to_double(t[1].y()) << " " - << CGAL::to_double(t[1].z()) << " ,\n" - << Indent << " " - << CGAL::to_double(t[2].x()) << " " - << CGAL::to_double(t[2].y()) << " " - << CGAL::to_double(t[2].z()) << " ,\n" - << Indent << " " - << CGAL::to_double(t[3].x()) << " " - << CGAL::to_double(t[3].y()) << " " - << CGAL::to_double(t[3].z()) << " ]" - << "\n } #Coordinate3" ; - os.os() << "\n IndexedFaceSet {" - << Indent << "coordIndex [ 0,1,2,-1, 1,3,2,-1,\n" - << Indent << " 0,2,3,-1, 0,3,1,-1 ]\n" - << "\n } #IndexedFaceSet" - << "\n } #Separator\n"; - return os; -} - -} //namespace CGAL +#define CGAL_DEPRECATED_HEADER "" +#define CGAL_REPLACEMENT_HEADER "" +#include +#include " +#include #endif // CGAL_IO_VRML_1_TETRAHEDRON_3 -#endif // CGAL_TETRAHEDRON_3_H diff --git a/Inventor/include/CGAL/IO/VRML_2_ostream.h b/Inventor/include/CGAL/IO/VRML_2_ostream.h index e30becf40bd..e2ca31e4f77 100644 --- a/Inventor/include/CGAL/IO/VRML_2_ostream.h +++ b/Inventor/include/CGAL/IO/VRML_2_ostream.h @@ -27,295 +27,12 @@ #ifndef CGAL_IO_VRML_2_OSTREAM_H #define CGAL_IO_VRML_2_OSTREAM_H +#include -#include -#include - -namespace CGAL { - -class VRML_2_ostream { -public: - VRML_2_ostream() : m_os(0) {} - VRML_2_ostream(std::ostream& o) : m_os(&o) { header();} - ~VRML_2_ostream() { close(); } - void open(std::ostream& o) { m_os = &o; header(); } - void close() { - if ( m_os) - footer(); - m_os = 0; - } - explicit operator bool () { - return m_os && !m_os->fail(); - } - std::ostream& os() { - // The behaviour if m_os == 0 could be changed to return - // cerr or a file handle to /dev/null. The latter one would - // mimick the behaviour that one can still use a stream with - // an invalid stream, but without producing any output. - CGAL_assertion( m_os != 0 ); - return *m_os; - } -private: - void header() { - os() << "#VRML V2.0 utf8\n" - "# File written with the help of the CGAL Library\n" - "#-- Begin of file header\n" - "Group {\n" - " children [\n" - " Shape {\n" - " appearance DEF A1 Appearance {\n" - " material Material {\n" - " diffuseColor .6 .5 .9\n" - " }\n }\n" - " appearance\n" - " Appearance {\n" - " material DEF Material Material {}\n" - " }\n" - " geometry nullptr\n" - " }\n" - " #-- End of file header" << std::endl; - } - void footer() { - os() << " #-- Begin of file footer\n" - " ]\n" - "}\n" - "#-- End of file footer" << std::endl; - } - std::ostream* m_os; -}; - -inline -VRML_2_ostream& -operator<<(VRML_2_ostream& os, - const char* s) -{ - os.os() << s; - return os; -} - -inline -VRML_2_ostream& -operator<<(VRML_2_ostream& os, - const double& d) -{ - os.os() << d; - return os; -} - -} //namespace CGAL - -#endif // CGAL_IO_VRML_2_OSTREAM_H - -#ifdef CGAL_TETRAHEDRON_3_H -#ifndef CGAL_IO_VRML_2_TETRAHEDRON_3 -#define CGAL_IO_VRML_2_TETRAHEDRON_3 - -namespace CGAL { - -template -VRML_2_ostream& -operator<<(VRML_2_ostream& os, - const Tetrahedron_3 &t) -{ - const char *Indent = " "; - os << " Group {\n" - " children [\n" - " Shape {\n" - " appearance\n" - " Appearance {\n" - " material USE Material\n" - " } #Appearance\n" - " geometry\n" - " IndexedFaceSet {\n" - " coord Coordinate {\n" - " point [ \n" - << Indent << " " - << CGAL::to_double(t[0].x()) << " " - << CGAL::to_double(t[0].y()) << " " - << CGAL::to_double(t[0].z()) << " ,\n" - << Indent << " " - << CGAL::to_double(t[1].x()) << " " - << CGAL::to_double(t[1].y()) << " " - << CGAL::to_double(t[1].z()) << " ,\n" - << Indent << " " - << CGAL::to_double(t[2].x()) << " " - << CGAL::to_double(t[2].y()) << " " - << CGAL::to_double(t[2].z()) << " ,\n" - << Indent << " " - << CGAL::to_double(t[3].x()) << " " - << CGAL::to_double(t[3].y()) << " " - << CGAL::to_double(t[3].z()) << - "\n ]\n" - " }\n" - " solid FALSE\n" - << Indent << "coordIndex [ 0,1,2,-1, 1,3,2,-1,\n" - << Indent << " 0,2,3,-1, 0,3,1,-1 ]\n" - " } #IndexedFaceSet\n" - " } #Shape\n" - " ] #children\n" - " } #Group\n"; - return os; -} - -} //namespace CGAL - -#endif // CGAL_IO_VRML_2_TETRAHEDRON_3 -#endif // CGAL_TETRAHEDRON_3_H - -#ifdef CGAL_POINT_3_H -#ifndef CGAL_IO_VRML_2_POINT_3 -#define CGAL_IO_VRML_2_POINT_3 - -namespace CGAL { - -template -VRML_2_ostream& -operator<<(VRML_2_ostream& os, - const Point_3 &p) -{ - const char *Indent = " "; - os << " Group {\n" - " children [\n" - " Shape {\n" - " appearance USE A1\n" - " geometry\n" - " PointSet {\n" - " coord Coordinate {\n" - " point [ "; - os << CGAL::to_double(p.x()) << " " << CGAL::to_double(p.y()) - << " " << CGAL::to_double(p.z()) << " ]\n"; - os << Indent << "}\n"; - os << Indent << "} # PointSet\n"; - os << " } #Shape\n" - " ] #children\n" - " } #Group\n"; - return os; -} - -} //namespace CGAL - -#endif // CGAL_IO_VRML_2_POINT_3 -#endif // CGAL_POINT_3_H - - - -#ifdef CGAL_TRIANGLE_3_H -#ifndef CGAL_IO_VRML_2_TRIANGLE_3 -#define CGAL_IO_VRML_2_TRIANGLE_3 - -namespace CGAL { - -template -VRML_2_ostream& -operator<<(VRML_2_ostream& os, - const Triangle_3 &t) -{ - const char *Indent = " "; - os << " Group {\n" - " children [\n" - " Shape {\n" - " appearance USE A1\n" - " geometry\n" - " IndexedLineSet {\n" - " coord Coordinate {\n" - " point [ \n"; - os << Indent ; - os << CGAL::to_double(t[0].x()) << " " << CGAL::to_double(t[0].y()) - << " " << CGAL::to_double(t[0].z()) << ",\n"; - os << Indent; - os << CGAL::to_double(t[1].x()) << " " << CGAL::to_double(t[1].y()) - << " " << CGAL::to_double(t[1].z()) << ",\n"; - os << Indent; - os << CGAL::to_double(t[2].x()) << " " << CGAL::to_double(t[2].y()) - << " " << CGAL::to_double(t[2].z()) << " ]\n"; - os << Indent << "}\n" << Indent << "coordIndex [ 0 1, 1 2, 2 0 -1 ]\n"; - os << Indent << "} # IndexedLineSet\n"; - os << " } #Shape\n" - " ] #children\n" - " } #Group\n"; - return os; -} - -} //namespace CGAL - -#endif // CGAL_IO_VRML_2_TRIANGLE_3 -#endif // CGAL_TRIANGLE_3_H - - -#ifdef CGAL_SEGMENT_3_H -#ifndef CGAL_IO_VRML_2_SEGMENT_3 -#define CGAL_IO_VRML_2_SEGMENT_3 - -namespace CGAL { - -template -VRML_2_ostream& -operator<<(VRML_2_ostream& os, - const Segment_3 &s) -{ - const char *Indent = " "; - os << " Group {\n" - " children [\n" - " Shape {\n" - " appearance USE A1\n" - " geometry\n" - " IndexedLineSet {\n" - " coord Coordinate {\n" - " point [ \n"; - os << Indent << CGAL::to_double(s.source().x()); - os << " " << CGAL::to_double(s.source().y()) - << " " << CGAL::to_double(s.source().z()) << ",\n"; - os << Indent; - os << CGAL::to_double(s.target().x()) - << " " << CGAL::to_double(s.target().y()) - << " " << CGAL::to_double(s.target().z()) << " ]\n"; - os << Indent << "}\n" << Indent << "coordIndex [ 0 1 -1 ]\n"; - os << Indent << "} # IndexedLineSet\n"; - os << " } #Shape\n" - " ] #children\n" - " } #Group\n"; - - return os; -} - -} //namespace CGAL +#define CGAL_DEPRECATED_HEADER "" +#define CGAL_REPLACEMENT_HEADER "" +#include +#include +#include #endif // CGAL_IO_VRML_2_SEGMENT_3 -#endif // CGAL_SEGMENT_3_H - -#ifdef CGAL_SPHERE_3_H -#ifndef CGAL_IO_VRML_2_SPHERE_3 -#define CGAL_IO_VRML_2_SPHERE_3 - -namespace CGAL { - -template -VRML_2_ostream& -operator<<(VRML_2_ostream& os, - const Sphere_3 &s) -{ - os << " Group {\n" - " children [\n" - " Transform {\n" - " translation "; - os << CGAL::to_double(s.center().x()) << " " - << CGAL::to_double(s.center().y()) << " " - << CGAL::to_double(s.center().z()) << "\n"; - os << " children Shape {\n" - " appearance USE A1\n" - " geometry\n" - " Sphere { " - "radius "; - os << std::sqrt(CGAL::to_double(s.squared_radius())) <<" }\n"; - os << " } #children Shape\n" - " } # Transform\n" - " ] #children\n" - " } #Group\n"; - - return os; -} - -} //namespace CGAL - -#endif // CGAL_IO_VRML_2_SEGMENT_3 -#endif // CGAL_SPHERE_3_H diff --git a/Polyhedron_IO/include/CGAL/IO/Polyhedron_VRML_1_ostream.h b/Polyhedron/include/CGAL/IO/Polyhedron_VRML_1_ostream.h similarity index 100% rename from Polyhedron_IO/include/CGAL/IO/Polyhedron_VRML_1_ostream.h rename to Polyhedron/include/CGAL/IO/Polyhedron_VRML_1_ostream.h diff --git a/Polyhedron_IO/include/CGAL/IO/Polyhedron_VRML_2_ostream.h b/Polyhedron/include/CGAL/IO/Polyhedron_VRML_2_ostream.h similarity index 100% rename from Polyhedron_IO/include/CGAL/IO/Polyhedron_VRML_2_ostream.h rename to Polyhedron/include/CGAL/IO/Polyhedron_VRML_2_ostream.h diff --git a/Polyhedron_IO/include/CGAL/IO/Polyhedron_builder_from_STL.h b/Polyhedron/include/CGAL/IO/Polyhedron_builder_from_STL.h similarity index 96% rename from Polyhedron_IO/include/CGAL/IO/Polyhedron_builder_from_STL.h rename to Polyhedron/include/CGAL/IO/Polyhedron_builder_from_STL.h index da9dd7ebcbc..de3717e0063 100644 --- a/Polyhedron_IO/include/CGAL/IO/Polyhedron_builder_from_STL.h +++ b/Polyhedron/include/CGAL/IO/Polyhedron_builder_from_STL.h @@ -13,13 +13,15 @@ // // $URL$ // $Id$ -// SPDX-License-Identifier: LGPL-3.0+ +// SPDX-License-Identifier: GPL-3.0+ // // Author(s) : Andreas Fabri #ifndef CGAL_IO_POLYHEDRON_STL_BUILDER_H #define CGAL_IO_POLYHEDRON_STL_BUILDER_H +#include + #include #include #include diff --git a/Polyhedron_IO/include/CGAL/IO/Polyhedron_geomview_ostream.h b/Polyhedron/include/CGAL/IO/Polyhedron_geomview_ostream.h similarity index 100% rename from Polyhedron_IO/include/CGAL/IO/Polyhedron_geomview_ostream.h rename to Polyhedron/include/CGAL/IO/Polyhedron_geomview_ostream.h diff --git a/Polyhedron_IO/include/CGAL/IO/Polyhedron_inventor_ostream.h b/Polyhedron/include/CGAL/IO/Polyhedron_inventor_ostream.h similarity index 100% rename from Polyhedron_IO/include/CGAL/IO/Polyhedron_inventor_ostream.h rename to Polyhedron/include/CGAL/IO/Polyhedron_inventor_ostream.h diff --git a/Polyhedron_IO/include/CGAL/IO/Polyhedron_iostream.h b/Polyhedron/include/CGAL/IO/Polyhedron_iostream.h similarity index 100% rename from Polyhedron_IO/include/CGAL/IO/Polyhedron_iostream.h rename to Polyhedron/include/CGAL/IO/Polyhedron_iostream.h diff --git a/Polyhedron/include/CGAL/IO/Polyhedron_scan_OFF.h b/Polyhedron/include/CGAL/IO/Polyhedron_scan_OFF.h new file mode 100644 index 00000000000..11ddaab4f2e --- /dev/null +++ b/Polyhedron/include/CGAL/IO/Polyhedron_scan_OFF.h @@ -0,0 +1,159 @@ +// Copyright (c) 1997 ETH Zurich (Switzerland). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0+ +// +// +// Author(s) : Lutz Kettner + +#ifndef CGAL_IO_POLYHEDRON_SCAN_OFF_H +#define CGAL_IO_POLYHEDRON_SCAN_OFF_H 1 + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace CGAL { + +template < class HDS> +class Polyhedron_scan_OFF : public Modifier_base { +protected: + std::istream& m_in; + File_header_OFF m_file_header; +public: + + typedef HDS Halfedge_data_structure; + +// DEFINITION +// +// Polyhedron_scan_OFF is a polyhedral surface builder. +// It scans a polyhedron given in OFF from a stream and appends it +// incrementally using the incremental builder. + + Polyhedron_scan_OFF( std::istream& in, bool verbose = false) + : m_in(in), m_file_header( verbose) {} + + // Activation + void operator()( HDS& hds); + + const File_header_OFF& header() const { return m_file_header; } +}; + +template < class HDS > +void +Polyhedron_scan_OFF:: operator()( HDS& target) { + File_scanner_OFF scanner( m_in, m_file_header.verbose()); + if ( ! m_in) { + if ( scanner.verbose()) { + std::cerr << " " << std::endl; + std::cerr << "Polyhedron_scan_OFF::" << std::endl; + std::cerr << "operator(): input error: file format is not in " + "OFF." << std::endl; + } + return; + } + m_file_header = scanner; // Remember file header after return. + + Polyhedron_incremental_builder_3 B( target, scanner.verbose()); + B.begin_surface( scanner.size_of_vertices(), + scanner.size_of_facets(), + scanner.size_of_halfedges()); + + typedef typename HDS::Traits Traits; + typedef typename Traits::Point_3 Point; + + // read in all vertices + std::size_t i; + 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); + } + else + scanner.skip_to_next_vertex( i); + } + if ( ! m_in || B.error()) { + B.rollback(); + m_in.clear( std::ios::badbit); + return; + } + + // read in all facets + for ( i = 0; i < scanner.size_of_facets(); i++) { + B.begin_facet(); + std::size_t no; + scanner.scan_facet( no, i); + if( ! m_in || B.error() || no < 3) { + if ( scanner.verbose()) { + std::cerr << " " << std::endl; + std::cerr << "Polyhedron_scan_OFF::" << std::endl; + std::cerr << "operator()(): input error: facet " << i + << " has less than 3 vertices." << std::endl; + } + B.rollback(); + m_in.clear( std::ios::badbit); + return; + } + for ( std::size_t j = 0; j < no; j++) { + std::size_t index; + scanner.scan_facet_vertex_index( index, i); + B.add_vertex_to_facet( index); + } + //TO DO : Insert read color + B.end_facet(); + scanner.skip_to_next_facet( i); + } + if ( ! m_in || B.error()) { + B.rollback(); + m_in.clear( std::ios::badbit); + return; + } + if ( B.check_unconnected_vertices()) { + if ( ! B.remove_unconnected_vertices()) { + if ( scanner.verbose()) { + std::cerr << " " << std::endl; + std::cerr << "Polyhedron_scan_OFF::" << std::endl; + std::cerr << "operator()(): input error: cannot " + "successfully remove isolated vertices." + << std::endl; + } + B.rollback(); + m_in.clear( std::ios::badbit); + return; + } + } + B.end_surface(); +} + +} //namespace CGAL + +#include + +#endif // CGAL_IO_POLYHEDRON_SCAN_OFF_H // +// EOF // diff --git a/Polyhedron_IO/include/CGAL/IO/generic_print_polyhedron.h b/Polyhedron/include/CGAL/IO/generic_print_polyhedron.h similarity index 100% rename from Polyhedron_IO/include/CGAL/IO/generic_print_polyhedron.h rename to Polyhedron/include/CGAL/IO/generic_print_polyhedron.h diff --git a/Polyhedron/include/CGAL/IO/print_OFF.h b/Polyhedron/include/CGAL/IO/print_OFF.h new file mode 100644 index 00000000000..348dfc7979d --- /dev/null +++ b/Polyhedron/include/CGAL/IO/print_OFF.h @@ -0,0 +1,100 @@ +// Copyright (c) 1997 ETH Zurich (Switzerland). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0+ +// +// +// Author(s) : Lutz Kettner + +#ifndef CGAL_IO_PRINT_OFF_H +#define CGAL_IO_PRINT_OFF_H 1 + +#include + + +#include +#include +#include +#include +#include + +namespace CGAL { + +template +void print_polyhedron_with_header_OFF( std::ostream& out, + const Polyhedron& P, + const File_header_OFF& header, + const Vpm& vpm) { + File_writer_OFF writer( header); + writer.header().set_polyhedral_surface( true); + writer.header().set_halfedges( P.size_of_halfedges()); + generic_print_polyhedron( out, P, writer, vpm); +} + +template +void print_polyhedron_with_header_OFF( std::ostream& out, + const Polyhedron& P, + const File_header_OFF& header) +{ + print_polyhedron_with_header_OFF(out, P, header, get(CGAL::vertex_point, P)); +} + +template +void print_polyhedron_OFF( std::ostream& out, + const Polyhedron& P, + bool verbose = false) { + File_header_OFF header( verbose); + header.set_binary( is_binary( out)); + header.set_no_comments( ! is_pretty( out)); + print_polyhedron_with_header_OFF( out, P, header); +} + + +// Deprecated global functions, replaced with functions above + +template < class Traits, + class Items, + template < class T, class I, class A> + class HDS, class Alloc> +void +print_OFF( std::ostream& out, + const Polyhedron_3& P, + bool verbose = false) { + File_writer_OFF writer( verbose); + writer.header().set_binary( is_binary( out)); + writer.header().set_no_comments( ! is_pretty( out)); + writer.header().set_polyhedral_surface( true); + writer.header().set_halfedges( P.size_of_halfedges()); + generic_print_polyhedron( out, P, writer); +} + +template < class Traits, + class Items, + template < class T, class I, class A> + class HDS, class Alloc> +void +print_OFF( std::ostream& out, + const Polyhedron_3& P, + const File_header_OFF& header) { + File_writer_OFF writer( header); + writer.header().set_polyhedral_surface( true); + writer.header().set_halfedges( P.size_of_halfedges()); + generic_print_polyhedron( out, P, writer); +} + +} //namespace CGAL +#endif // CGAL_IO_PRINT_OFF_H // +// EOF // diff --git a/Polyhedron_IO/include/CGAL/IO/print_VRML_1.h b/Polyhedron/include/CGAL/IO/print_VRML_1.h similarity index 100% rename from Polyhedron_IO/include/CGAL/IO/print_VRML_1.h rename to Polyhedron/include/CGAL/IO/print_VRML_1.h diff --git a/Polyhedron_IO/include/CGAL/IO/print_VRML_2.h b/Polyhedron/include/CGAL/IO/print_VRML_2.h similarity index 100% rename from Polyhedron_IO/include/CGAL/IO/print_VRML_2.h rename to Polyhedron/include/CGAL/IO/print_VRML_2.h diff --git a/Polyhedron_IO/include/CGAL/IO/print_inventor.h b/Polyhedron/include/CGAL/IO/print_inventor.h similarity index 100% rename from Polyhedron_IO/include/CGAL/IO/print_inventor.h rename to Polyhedron/include/CGAL/IO/print_inventor.h diff --git a/Stream_support/include/CGAL/IO/OBJ/print_wavefront.h b/Polyhedron/include/CGAL/IO/print_wavefront.h similarity index 92% rename from Stream_support/include/CGAL/IO/OBJ/print_wavefront.h rename to Polyhedron/include/CGAL/IO/print_wavefront.h index ae98a78d3ed..4ebfbcebd43 100644 --- a/Stream_support/include/CGAL/IO/OBJ/print_wavefront.h +++ b/Polyhedron/include/CGAL/IO/print_wavefront.h @@ -19,8 +19,8 @@ // // Author(s) : Lutz Kettner -#ifndef CGAL_IO_OBJ_PRINT_WAVEFRONT_H -#define CGAL_IO_OBJ_PRINT_WAVEFRONT_H 1 +#ifndef CGAL_IO_PRINT_WAVEFRONT_H +#define CGAL_IO_PRINT_WAVEFRONT_H 1 #include @@ -52,5 +52,5 @@ print_wavefront( std::ostream& out, } } //namespace CGAL -#endif // CGAL_IO_OBJ_PRINT_WAVEFRONT_H // +#endif // CGAL_IO_PRINT_WAVEFRONT_H // // EOF // diff --git a/Polyhedron/include/CGAL/IO/scan_OFF.h b/Polyhedron/include/CGAL/IO/scan_OFF.h new file mode 100644 index 00000000000..51cca1d8214 --- /dev/null +++ b/Polyhedron/include/CGAL/IO/scan_OFF.h @@ -0,0 +1,68 @@ +// Copyright (c) 1997 ETH Zurich (Switzerland). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0+ +// +// +// Author(s) : Lutz Kettner + +#ifndef CGAL_IO_SCAN_OFF_H +#define CGAL_IO_SCAN_OFF_H 1 + +#include + + +#include +#include +#include + +namespace CGAL { + +template < class Traits, + class Items, + template < class T, class I, class A> + class HDS, class Alloc> +void scan_OFF( std::istream& in, + Polyhedron_3& P, + File_header_OFF& header) { + // reads a polyhedron from `in' and appends it to P. + // Returns also the File_header_OFF structure of the object. + typedef Polyhedron_3 Polyhedron; + typedef typename Polyhedron::HalfedgeDS HalfedgeDS; + typedef Polyhedron_scan_OFF Scanner; + Scanner scanner( in, header.verbose()); + P.delegate(scanner); + header = scanner.header(); +} + +template < class Traits, + class Items, + template < class T, class I, class A> + class HDS, class Alloc> +void scan_OFF( std::istream& in, Polyhedron_3& P, + bool verbose = false) { + // reads a polyhedron from `in' and appends it to P. + typedef Polyhedron_3 Polyhedron; + typedef typename Polyhedron::HalfedgeDS HalfedgeDS; + typedef Polyhedron_scan_OFF Scanner; + Scanner scanner( in, verbose); + P.delegate(scanner); +} + + +} //namespace CGAL +#endif // CGAL_IO_SCAN_OFF_H // +// EOF // diff --git a/Polyhedron_IO/include/CGAL/IO/print_wavefront.h b/Polyhedron_IO/include/CGAL/IO/print_wavefront.h deleted file mode 100644 index ddd5dfd9eda..00000000000 --- a/Polyhedron_IO/include/CGAL/IO/print_wavefront.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 1997 ETH Zurich (Switzerland). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org). -// You can redistribute it and/or modify it under the terms of the GNU -// General Public License as published by the Free Software Foundation, -// either version 3 of the License, or (at your option) any later version. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: GPL-3.0+ -// -// -// Author(s) : Lutz Kettner - -#ifndef CGAL_IO_PRINT_WAVEFRONT_H -#define CGAL_IO_PRINT_WAVEFRONT_H 1 - -#include - -#include - -#define CGAL_DEPRECATED_HEADER "" -#define CGAL_REPLACEMENT_HEADER "" -#include -#include -#include - - -#endif // CGAL_IO_PRINT_WAVEFRONT_H // -// EOF // diff --git a/Stream_support/include/CGAL/IO/VRML/Alpha_shape_3_VRML_2_ostream.h b/Stream_support/include/CGAL/IO/VRML/Alpha_shape_3_VRML_2_ostream.h new file mode 100644 index 00000000000..d515b3bbcea --- /dev/null +++ b/Stream_support/include/CGAL/IO/VRML/Alpha_shape_3_VRML_2_ostream.h @@ -0,0 +1,104 @@ +// Copyright (c) 1997 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// Author(s) : Andreas Fabri + +#ifndef CGAL_IO_VRML_ALPHA_SHAPE_3_VRML_2_OSTREAM_H +#define CGAL_IO_VRML_ALPHA_SHAPE_3_VRML_2_OSTREAM_H + +#include +#include + +#ifdef CGAL_ALPHA_SHAPE_3_H +namespace CGAL { + +template +VRML_2_ostream& +operator<<(VRML_2_ostream& os, + Alpha_shape_3
&as) +{ + // Finite vertices coordinates. + Alpha_shape_3
::Alpha_shape_vertices_iterator Vlist_it, + Vlist_begin = as.alpha_shape_vertices_begin(), + Vlist_end = as.alpha_shape_vertices_end(); + + std::map::Vertex_handle, int> V; + int number_of_vertex = 0; + for( Vlist_it = Vlist_begin; Vlist_it != Vlist_end; Vlist_it++) { + V[*Vlist_it] = number_of_vertex++; + } + + typename Alpha_shape_3
::Alpha_shape_facets_iterator Flist_it, + Flist_begin = as.alpha_shape_facets_begin(), + Flist_end = as.alpha_shape_facets_end(); + + std::map::Facet, int> F; + int number_of_facets = 0; + for( Flist_it = Flist_begin; Flist_it != Flist_end; Flist_it++) { + F[*Flist_it] = number_of_facets++; + } + + const char *Indent = " "; + os << " Group {\n" + " children [\n" + " Shape {\n" + " appearance USE A1\n" + " geometry\n" + " IndexedFaceSet {\n" + " coord Coordinate {\n" + " point [ \n" + << Indent << " "; + for( Vlist_it = Vlist_begin; Vlist_it != Vlist_end; Vlist_it++) { + os << CGAL::to_double((*Vlist_it)->point().x()) << " "; + os << CGAL::to_double((*Vlist_it)->point().y()) << " "; + os << CGAL::to_double((*Vlist_it)->point().z()) << ",\n" << Indent << " "; + } + os << "\n ]\n" + " } # coord\n" + " solid FALSE\n" + << Indent << "coordIndex [\n"; + // Finite facets indices. + for( Flist_it = Flist_begin; Flist_it != Flist_end; Flist_it++){ + os << Indent << " "; + for (int i=0; i<4; i++) + if (i != (*Flist_it).second){ + os << V[(*Flist_it).first->vertex(i)]; + os << ", "; + } + if (Flist_it != Flist_end) + os << "-1,\n"; + else + os << "-1 \n"; + } + os << Indent << "]\n"; + " } #IndexedFaceSet\n" + " } #Shape\n" + " ] #children\n" + " } #Group\n"; + + return os; +} + +} //namespace CGAL +#endif // CGAL_ALPHA_SHAPE_3_H + +#endif CGAL_IO_VRML_ALPHA_SHAPE_3_VRML_2_OSTREAM_H diff --git a/Stream_support/include/CGAL/IO/VRML/Inventor_ostream.h b/Stream_support/include/CGAL/IO/VRML/Inventor_ostream.h new file mode 100644 index 00000000000..427006e158b --- /dev/null +++ b/Stream_support/include/CGAL/IO/VRML/Inventor_ostream.h @@ -0,0 +1,135 @@ +// Copyright (c) 1997 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// Author(s) : Andreas Fabri +// Lutz Kettner +// Herve Bronnimann +// Mariette Yvinec + +#ifndef CGAL_IO_VRML_INVENTOR_OSTREAM_H +#define CGAL_IO_VRML_INVENTOR_OSTREAM_H + +#include +#include + +// OpenInventor and VRML 1.0 are quite similar formats, so +// output operators could be shared if they use the following +// base class, which is common for both output streams. + +namespace CGAL { + +class Inventor_ostream_base { +private: + std::ostream* m_os; +public: + Inventor_ostream_base() : m_os(0) {} + Inventor_ostream_base(std::ostream& o) : m_os(&o) {} + ~Inventor_ostream_base() { close(); } + void open(std::ostream& o) { m_os = &o; } + void close() { + if ( m_os) + os() << std::endl; + m_os = 0; + } + explicit operator bool () + { + return m_os && !m_os->fail(); + } + + std::ostream& os() { + // The behaviour if m_os == 0 could be changed to return + // cerr or a file handle to /dev/null. The latter one would + // mimick the behaviour that one can still use a stream with + // an invalid stream, but without producing any output. + CGAL_assertion( m_os != 0 ); + return *m_os; + } +}; + + +class Inventor_ostream : public Inventor_ostream_base +{ +public: + Inventor_ostream() {} + Inventor_ostream(std::ostream& o) : Inventor_ostream_base(o) { + header(); + } + void open(std::ostream& o) { + Inventor_ostream_base::open(o); + header(); + } +private: + void header() { + os() << "#Inventor V2.0 ascii" << std::endl; + os() << "# File written with the help of the CGAL Library" + << std::endl; + } +}; + +} //namespace CGAL +#endif // CGAL_IO_INVENTOR_OSTREAM_H + + +#ifdef CGAL_TETRAHEDRON_3_H +#ifndef CGAL_INVENTOR_TETRAHEDRON_3 +#define CGAL_INVENTOR_TETRAHEDRON_3 + +namespace CGAL { + +template +Inventor_ostream& +operator<<(Inventor_ostream& os, + const Tetrahedron_3 &t) +{ + const char *Indent = " "; + os.os() << "\n Separator {"; + os.os() << "\n Coordinate3 { \n" + << Indent << "point [\n" + << Indent << " " + << CGAL::to_double(t[0].x()) << " " + << CGAL::to_double(t[0].y()) << " " + << CGAL::to_double(t[0].z()) << " ,\n" + << Indent << " " + << CGAL::to_double(t[1].x()) << " " + << CGAL::to_double(t[1].y()) << " " + << CGAL::to_double(t[1].z()) << " ,\n" + << Indent << " " + << CGAL::to_double(t[2].x()) << " " + << CGAL::to_double(t[2].y()) << " " + << CGAL::to_double(t[2].z()) << " ,\n" + << Indent << " " + << CGAL::to_double(t[3].x()) << " " + << CGAL::to_double(t[3].y()) << " " + << CGAL::to_double(t[3].z()) << " ]" + << "\n } #Coordinate3" ; + os.os() << "\n IndexedFaceSet {" + << Indent << "coordIndex [ 0,1,2,-1, 1,3,2,-1,\n" + << Indent << " 0,2,3,-1, 0,3,1,-1 ]\n" + << "\n } #IndexedFaceSet" + << "\n } #Separator\n"; + return os; +} + +} //namespace CGAL + +#endif // CGAL_TETRAHEDRON_3_H +#endif // CGAL_VRML_INVENTOR_TETRAHEDRON_3 diff --git a/Stream_support/include/CGAL/IO/VRML/Polyhedron_VRML_1_ostream.h b/Stream_support/include/CGAL/IO/VRML/Polyhedron_VRML_1_ostream.h deleted file mode 100644 index feab1e5a9a6..00000000000 --- a/Stream_support/include/CGAL/IO/VRML/Polyhedron_VRML_1_ostream.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 1997 ETH Zurich (Switzerland). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org). -// You can redistribute it and/or modify it under the terms of the GNU -// General Public License as published by the Free Software Foundation, -// either version 3 of the License, or (at your option) any later version. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: GPL-3.0+ -// -// -// Author(s) : Lutz Kettner - -#ifndef CGAL_IO_POLYHEDRON_VRML_1_OSTREAM_H -#define CGAL_IO_POLYHEDRON_VRML_1_OSTREAM_H 1 - -#include - - -#include -#include - -#endif // CGAL_IO_POLYHEDRON_VRML_1_OSTREAM_H // -// EOF // diff --git a/Stream_support/include/CGAL/IO/VRML/Polyhedron_VRML_2_ostream.h b/Stream_support/include/CGAL/IO/VRML/Polyhedron_VRML_2_ostream.h deleted file mode 100644 index a105cd1534e..00000000000 --- a/Stream_support/include/CGAL/IO/VRML/Polyhedron_VRML_2_ostream.h +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) 1997 ETH Zurich (Switzerland). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org). -// You can redistribute it and/or modify it under the terms of the GNU -// General Public License as published by the Free Software Foundation, -// either version 3 of the License, or (at your option) any later version. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: GPL-3.0+ -// -// -// Author(s) : Lutz Kettner - -#ifndef CGAL_IO_POLYHEDRON_VRML_2_OSTREAM_H -#define CGAL_IO_POLYHEDRON_VRML_2_OSTREAM_H 1 - -#include - - -#include -#include -#include -#include -#include -#include - -namespace CGAL { - -template < class Traits, - class Items, - template < class T, class I, class A> - class HDS, class Alloc> -VRML_2_ostream& -operator<<( VRML_2_ostream& out, - const Polyhedron_3& P) { - File_writer_VRML_2 writer; - generic_print_polyhedron( out.os(), P, writer); - return out; -} - -} //namespace CGAL -#endif // CGAL_IO_POLYHEDRON_VRML_2_OSTREAM_H // -// EOF // diff --git a/Stream_support/include/CGAL/IO/VRML/VRML_1_ostream.h b/Stream_support/include/CGAL/IO/VRML/VRML_1_ostream.h new file mode 100644 index 00000000000..34c4f3e73bb --- /dev/null +++ b/Stream_support/include/CGAL/IO/VRML/VRML_1_ostream.h @@ -0,0 +1,109 @@ +// Copyright (c) 1997 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// Author(s) : Andreas Fabri +// Lutz Kettner +// Herve Bronnimann +// Mariette Yvinec + +#ifndef CGAL_IO_VRML_VRML_1_OSTREAM_H +#define CGAL_IO_VRML_VRML_1_OSTREAM_H + +#include +#include + +// Declare the common base class for OpenInventor and VRML 1.0 format. +#include + +// OpenInventor and VRML 1.0 are quite similar formats, so +// output operators could be shared if they use the common +// base class Inventor_ostream_base, which is common for +// both output streams. + +namespace CGAL { + +class VRML_1_ostream : public Inventor_ostream_base { +public: + VRML_1_ostream() {} + VRML_1_ostream(std::ostream& o) : Inventor_ostream_base(o) { + header(); + } + void open(std::ostream& o) { + Inventor_ostream_base::open(o); + header(); + } +private: + void header() { + os() << "#VRML V1.0 ascii" << std::endl; + os() << "# File written with the help of the CGAL Library" + << std::endl; + } +}; + +} //namespace CGAL + +#endif // CGAL_IO_VRML_1_OSTREAM_H + +#ifdef CGAL_TETRAHEDRON_3_H +#ifndef CGAL_IO_VRML_1_TETRAHEDRON_3 +#define CGAL_IO_VRML_1_TETRAHEDRON_3 + +namespace CGAL { + +template +VRML_1_ostream& +operator<<(VRML_1_ostream& os, + const Tetrahedron_3 &t) +{ + const char *Indent = " "; + os.os() << "\n Separator {"; + os.os() << "\n Coordinate3 { \n" + << Indent << "point [\n" + << Indent << " " + << CGAL::to_double(t[0].x()) << " " + << CGAL::to_double(t[0].y()) << " " + << CGAL::to_double(t[0].z()) << " ,\n" + << Indent << " " + << CGAL::to_double(t[1].x()) << " " + << CGAL::to_double(t[1].y()) << " " + << CGAL::to_double(t[1].z()) << " ,\n" + << Indent << " " + << CGAL::to_double(t[2].x()) << " " + << CGAL::to_double(t[2].y()) << " " + << CGAL::to_double(t[2].z()) << " ,\n" + << Indent << " " + << CGAL::to_double(t[3].x()) << " " + << CGAL::to_double(t[3].y()) << " " + << CGAL::to_double(t[3].z()) << " ]" + << "\n } #Coordinate3" ; + os.os() << "\n IndexedFaceSet {" + << Indent << "coordIndex [ 0,1,2,-1, 1,3,2,-1,\n" + << Indent << " 0,2,3,-1, 0,3,1,-1 ]\n" + << "\n } #IndexedFaceSet" + << "\n } #Separator\n"; + return os; +} + +} //namespace CGAL + +#endif // CGAL_TETRAHEDRON_3_H +#endif // CGAL_IO_VRML_VRML_1_TETRAHEDRON_3 diff --git a/Stream_support/include/CGAL/IO/VRML/VRML_2_ostream.h b/Stream_support/include/CGAL/IO/VRML/VRML_2_ostream.h new file mode 100644 index 00000000000..ddbd27c7d69 --- /dev/null +++ b/Stream_support/include/CGAL/IO/VRML/VRML_2_ostream.h @@ -0,0 +1,321 @@ +// Copyright (c) 1997 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// Author(s) : Andreas Fabri +// Lutz Kettner +// Herve Bronnimann +// Mariette Yvinec + +#ifndef CGAL_IO_VRML_VRML_2_OSTREAM_H +#define CGAL_IO_VRML_VRML_2_OSTREAM_H + +#include +#include + +namespace CGAL { + +class VRML_2_ostream { +public: + VRML_2_ostream() : m_os(0) {} + VRML_2_ostream(std::ostream& o) : m_os(&o) { header();} + ~VRML_2_ostream() { close(); } + void open(std::ostream& o) { m_os = &o; header(); } + void close() { + if ( m_os) + footer(); + m_os = 0; + } + explicit operator bool () { + return m_os && !m_os->fail(); + } + std::ostream& os() { + // The behaviour if m_os == 0 could be changed to return + // cerr or a file handle to /dev/null. The latter one would + // mimick the behaviour that one can still use a stream with + // an invalid stream, but without producing any output. + CGAL_assertion( m_os != 0 ); + return *m_os; + } +private: + void header() { + os() << "#VRML V2.0 utf8\n" + "# File written with the help of the CGAL Library\n" + "#-- Begin of file header\n" + "Group {\n" + " children [\n" + " Shape {\n" + " appearance DEF A1 Appearance {\n" + " material Material {\n" + " diffuseColor .6 .5 .9\n" + " }\n }\n" + " appearance\n" + " Appearance {\n" + " material DEF Material Material {}\n" + " }\n" + " geometry nullptr\n" + " }\n" + " #-- End of file header" << std::endl; + } + void footer() { + os() << " #-- Begin of file footer\n" + " ]\n" + "}\n" + "#-- End of file footer" << std::endl; + } + std::ostream* m_os; +}; + +inline +VRML_2_ostream& +operator<<(VRML_2_ostream& os, + const char* s) +{ + os.os() << s; + return os; +} + +inline +VRML_2_ostream& +operator<<(VRML_2_ostream& os, + const double& d) +{ + os.os() << d; + return os; +} + +} //namespace CGAL + +#endif // CGAL_IO_VRML_2_OSTREAM_H + +#ifdef CGAL_TETRAHEDRON_3_H +#ifndef CGAL_IO_VRML_2_TETRAHEDRON_3 +#define CGAL_IO_VRML_2_TETRAHEDRON_3 + +namespace CGAL { + +template +VRML_2_ostream& +operator<<(VRML_2_ostream& os, + const Tetrahedron_3 &t) +{ + const char *Indent = " "; + os << " Group {\n" + " children [\n" + " Shape {\n" + " appearance\n" + " Appearance {\n" + " material USE Material\n" + " } #Appearance\n" + " geometry\n" + " IndexedFaceSet {\n" + " coord Coordinate {\n" + " point [ \n" + << Indent << " " + << CGAL::to_double(t[0].x()) << " " + << CGAL::to_double(t[0].y()) << " " + << CGAL::to_double(t[0].z()) << " ,\n" + << Indent << " " + << CGAL::to_double(t[1].x()) << " " + << CGAL::to_double(t[1].y()) << " " + << CGAL::to_double(t[1].z()) << " ,\n" + << Indent << " " + << CGAL::to_double(t[2].x()) << " " + << CGAL::to_double(t[2].y()) << " " + << CGAL::to_double(t[2].z()) << " ,\n" + << Indent << " " + << CGAL::to_double(t[3].x()) << " " + << CGAL::to_double(t[3].y()) << " " + << CGAL::to_double(t[3].z()) << + "\n ]\n" + " }\n" + " solid FALSE\n" + << Indent << "coordIndex [ 0,1,2,-1, 1,3,2,-1,\n" + << Indent << " 0,2,3,-1, 0,3,1,-1 ]\n" + " } #IndexedFaceSet\n" + " } #Shape\n" + " ] #children\n" + " } #Group\n"; + return os; +} + +} //namespace CGAL + +#endif // CGAL_IO_VRML_2_TETRAHEDRON_3 +#endif // CGAL_TETRAHEDRON_3_H + +#ifdef CGAL_POINT_3_H +#ifndef CGAL_IO_VRML_2_POINT_3 +#define CGAL_IO_VRML_2_POINT_3 + +namespace CGAL { + +template +VRML_2_ostream& +operator<<(VRML_2_ostream& os, + const Point_3 &p) +{ + const char *Indent = " "; + os << " Group {\n" + " children [\n" + " Shape {\n" + " appearance USE A1\n" + " geometry\n" + " PointSet {\n" + " coord Coordinate {\n" + " point [ "; + os << CGAL::to_double(p.x()) << " " << CGAL::to_double(p.y()) + << " " << CGAL::to_double(p.z()) << " ]\n"; + os << Indent << "}\n"; + os << Indent << "} # PointSet\n"; + os << " } #Shape\n" + " ] #children\n" + " } #Group\n"; + return os; +} + +} //namespace CGAL + +#endif // CGAL_IO_VRML_2_POINT_3 +#endif // CGAL_POINT_3_H + + + +#ifdef CGAL_TRIANGLE_3_H +#ifndef CGAL_IO_VRML_2_TRIANGLE_3 +#define CGAL_IO_VRML_2_TRIANGLE_3 + +namespace CGAL { + +template +VRML_2_ostream& +operator<<(VRML_2_ostream& os, + const Triangle_3 &t) +{ + const char *Indent = " "; + os << " Group {\n" + " children [\n" + " Shape {\n" + " appearance USE A1\n" + " geometry\n" + " IndexedLineSet {\n" + " coord Coordinate {\n" + " point [ \n"; + os << Indent ; + os << CGAL::to_double(t[0].x()) << " " << CGAL::to_double(t[0].y()) + << " " << CGAL::to_double(t[0].z()) << ",\n"; + os << Indent; + os << CGAL::to_double(t[1].x()) << " " << CGAL::to_double(t[1].y()) + << " " << CGAL::to_double(t[1].z()) << ",\n"; + os << Indent; + os << CGAL::to_double(t[2].x()) << " " << CGAL::to_double(t[2].y()) + << " " << CGAL::to_double(t[2].z()) << " ]\n"; + os << Indent << "}\n" << Indent << "coordIndex [ 0 1, 1 2, 2 0 -1 ]\n"; + os << Indent << "} # IndexedLineSet\n"; + os << " } #Shape\n" + " ] #children\n" + " } #Group\n"; + return os; +} + +} //namespace CGAL + +#endif // CGAL_IO_VRML_2_TRIANGLE_3 +#endif // CGAL_TRIANGLE_3_H + + +#ifdef CGAL_SEGMENT_3_H +#ifndef CGAL_IO_VRML_2_SEGMENT_3 +#define CGAL_IO_VRML_2_SEGMENT_3 + +namespace CGAL { + +template +VRML_2_ostream& +operator<<(VRML_2_ostream& os, + const Segment_3 &s) +{ + const char *Indent = " "; + os << " Group {\n" + " children [\n" + " Shape {\n" + " appearance USE A1\n" + " geometry\n" + " IndexedLineSet {\n" + " coord Coordinate {\n" + " point [ \n"; + os << Indent << CGAL::to_double(s.source().x()); + os << " " << CGAL::to_double(s.source().y()) + << " " << CGAL::to_double(s.source().z()) << ",\n"; + os << Indent; + os << CGAL::to_double(s.target().x()) + << " " << CGAL::to_double(s.target().y()) + << " " << CGAL::to_double(s.target().z()) << " ]\n"; + os << Indent << "}\n" << Indent << "coordIndex [ 0 1 -1 ]\n"; + os << Indent << "} # IndexedLineSet\n"; + os << " } #Shape\n" + " ] #children\n" + " } #Group\n"; + + return os; +} + +} //namespace CGAL + +#endif // CGAL_IO_VRML_2_SEGMENT_3 +#endif // CGAL_SEGMENT_3_H + +#ifdef CGAL_SPHERE_3_H +#ifndef CGAL_IO_VRML_2_SPHERE_3 +#define CGAL_IO_VRML_2_SPHERE_3 + +namespace CGAL { + +template +VRML_2_ostream& +operator<<(VRML_2_ostream& os, + const Sphere_3 &s) +{ + os << " Group {\n" + " children [\n" + " Transform {\n" + " translation "; + os << CGAL::to_double(s.center().x()) << " " + << CGAL::to_double(s.center().y()) << " " + << CGAL::to_double(s.center().z()) << "\n"; + os << " children Shape {\n" + " appearance USE A1\n" + " geometry\n" + " Sphere { " + "radius "; + os << std::sqrt(CGAL::to_double(s.squared_radius())) <<" }\n"; + os << " } #children Shape\n" + " } # Transform\n" + " ] #children\n" + " } #Group\n"; + + return os; +} + +} //namespace CGAL + +#endif // CGAL_IO_VRML_VRML_2_SEGMENT_3 +#endif // CGAL_SPHERE_3_H diff --git a/Stream_support/include/CGAL/IO/VRML/print_VRML_1.h b/Stream_support/include/CGAL/IO/VRML/print_VRML_1.h deleted file mode 100644 index 1ae8b90deed..00000000000 --- a/Stream_support/include/CGAL/IO/VRML/print_VRML_1.h +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) 1997 ETH Zurich (Switzerland). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org). -// You can redistribute it and/or modify it under the terms of the GNU -// General Public License as published by the Free Software Foundation, -// either version 3 of the License, or (at your option) any later version. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: GPL-3.0+ -// -// -// Author(s) : Lutz Kettner - -#ifndef CGAL_IO_PRINT_VRML_1_H -#define CGAL_IO_PRINT_VRML_1_H 1 - -#include - - -#include - -namespace CGAL { - -template -void print_polyhedron_VRML_1( std::ostream& out, const Polyhedron& P) { - VRML_1_ostream os( out); - os << P; -} - -// Deprecated global functions, replaced with functions above - -template < class Traits, - class Items, - template < class T, class I, class A> - class HDS, class Alloc> -void -print_VRML_1( std::ostream& out, - const Polyhedron_3& P) { - VRML_1_ostream os( out); - os << P; -} - -} //namespace CGAL -#endif // CGAL_IO_PRINT_VRML_1_H // -// EOF // diff --git a/Stream_support/include/CGAL/IO/VRML/print_VRML_2.h b/Stream_support/include/CGAL/IO/VRML/print_VRML_2.h deleted file mode 100644 index a960bbea40a..00000000000 --- a/Stream_support/include/CGAL/IO/VRML/print_VRML_2.h +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) 1997 ETH Zurich (Switzerland). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org). -// You can redistribute it and/or modify it under the terms of the GNU -// General Public License as published by the Free Software Foundation, -// either version 3 of the License, or (at your option) any later version. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: GPL-3.0+ -// -// -// Author(s) : Lutz Kettner - -#ifndef CGAL_IO_PRINT_VRML_2_H -#define CGAL_IO_PRINT_VRML_2_H 1 - -#include - - -#include - -namespace CGAL { - -template -void print_polyhedron_VRML_2( std::ostream& out, const Polyhedron& P) { - VRML_2_ostream os( out); - os << P; -} - -// Deprecated global functions, replaced with functions above - -template < class Traits, - class Items, - template < class T, class I, class A> - class HDS, class Alloc> -void -print_VRML_2( std::ostream& out, - const Polyhedron_3& P) { - VRML_2_ostream os( out); - os << P; -} - -} //namespace CGAL -#endif // CGAL_IO_PRINT_VRML_2_H // -// EOF // diff --git a/Polyhedron_IO/include/CGAL/IO/reader_helpers.h b/Stream_support/include/CGAL/IO/reader_helpers.h similarity index 100% rename from Polyhedron_IO/include/CGAL/IO/reader_helpers.h rename to Stream_support/include/CGAL/IO/reader_helpers.h From 4aed6a9a54548c1baee51abe41d29db98baa0cff Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Wed, 7 Aug 2019 16:41:44 +0200 Subject: [PATCH 05/28] move WKT traits files and make a GOCAD reader and writer from the one in the demo. --- .../Polyhedron/Plugins/IO/GOCAD_io_plugin.cpp | 2 +- Stream_support/include/CGAL/IO/GOCAD.h | 44 +++++++++++++++++++ .../include/CGAL/IO/GOCAD/GOCAD_internals.h | 34 +++++++++++--- Stream_support/include/CGAL/IO/WKT.h | 14 +++--- .../CGAL/IO/{ => WKT}/traits_linestring.h | 8 ++-- .../IO/{ => WKT}/traits_multilinestring.h | 4 +- .../CGAL/IO/{ => WKT}/traits_multipoint.h | 4 +- .../CGAL/IO/{ => WKT}/traits_multipolygon.h | 4 +- .../include/CGAL/IO/{ => WKT}/traits_point.h | 4 +- .../CGAL/IO/{ => WKT}/traits_point_3.h | 4 +- .../CGAL/IO/{ => WKT}/traits_polygon.h | 4 +- 11 files changed, 97 insertions(+), 29 deletions(-) create mode 100644 Stream_support/include/CGAL/IO/GOCAD.h rename Polyhedron/demo/Polyhedron/include/CGAL/gocad_io.h => Stream_support/include/CGAL/IO/GOCAD/GOCAD_internals.h (81%) rename Stream_support/include/CGAL/IO/{ => WKT}/traits_linestring.h (93%) rename Stream_support/include/CGAL/IO/{ => WKT}/traits_multilinestring.h (93%) rename Stream_support/include/CGAL/IO/{ => WKT}/traits_multipoint.h (93%) rename Stream_support/include/CGAL/IO/{ => WKT}/traits_multipolygon.h (93%) rename Stream_support/include/CGAL/IO/{ => WKT}/traits_point.h (96%) rename Stream_support/include/CGAL/IO/{ => WKT}/traits_point_3.h (96%) rename Stream_support/include/CGAL/IO/{ => WKT}/traits_polygon.h (97%) diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/GOCAD_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/IO/GOCAD_io_plugin.cpp index 9aca2423ca0..e19781bc7cc 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/GOCAD_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/GOCAD_io_plugin.cpp @@ -3,7 +3,7 @@ #include "Kernel_type.h" #include "Scene.h" #include "SMesh_type.h" -#include +#include #include #include #include diff --git a/Stream_support/include/CGAL/IO/GOCAD.h b/Stream_support/include/CGAL/IO/GOCAD.h new file mode 100644 index 00000000000..cbce12b6785 --- /dev/null +++ b/Stream_support/include/CGAL/IO/GOCAD.h @@ -0,0 +1,44 @@ +// Copyright (c) 2019 GeometryFactory +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// Author(s) : Maxime Gimeno + +#ifndef CGAL_IO_GOCAD_H +#define CGAL_IO_GOCAD_H + +#include +#include +#include + +namespace CGAL{ +template +bool +read_gocad(FaceGraph& facegraph, std::istream& in, std::string& name, std::string& color) +{ + return GOCAD_internal::read_gocad(facegraph, in, name, color); +} + +template +bool +write_gocad(FaceGraph& facegraph, std::ostream& os, const std::string& name) +{ + return GOCAD_internal::write_gocad(facegraph, os, name); +} + +}//end CGAL + +#endif //CGAL_IO_GOCAD_H diff --git a/Polyhedron/demo/Polyhedron/include/CGAL/gocad_io.h b/Stream_support/include/CGAL/IO/GOCAD/GOCAD_internals.h similarity index 81% rename from Polyhedron/demo/Polyhedron/include/CGAL/gocad_io.h rename to Stream_support/include/CGAL/IO/GOCAD/GOCAD_internals.h index ef4a23e11a9..befbbefedb9 100644 --- a/Polyhedron/demo/Polyhedron/include/CGAL/gocad_io.h +++ b/Stream_support/include/CGAL/IO/GOCAD/GOCAD_internals.h @@ -1,14 +1,35 @@ -#ifndef CGAL_GOCAD_IO_H -#define CGAL_GOCAD_IO_H +// Copyright (c) 2019 GeometryFactory +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// Author(s) : Maxime Gimeno + +#ifndef CGAL_IO_GOCAD_GOCAD_INTERNALS_H +#define CGAL_IO_GOCAD_GOCAD_INTERNALS_H #include #include #include -#include -#include #include +#include #include +namespace CGAL{ + +namespace GOCAD_internal { template class Build_from_gocad_BGL { @@ -160,4 +181,7 @@ write_gocad(FaceGraph& polyhedron, std::ostream& os, const std::string& name) return true; } -#endif // CGAL_GOCAD_IO_H +}//end GOCAD_internal +}//end CGAL +#endif // CGAL_IO_GOCAD_GOCAD_INTERNALS_H + diff --git a/Stream_support/include/CGAL/IO/WKT.h b/Stream_support/include/CGAL/IO/WKT.h index 127b0985131..362399251cf 100644 --- a/Stream_support/include/CGAL/IO/WKT.h +++ b/Stream_support/include/CGAL/IO/WKT.h @@ -34,13 +34,13 @@ #include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include namespace CGAL{ diff --git a/Stream_support/include/CGAL/IO/traits_linestring.h b/Stream_support/include/CGAL/IO/WKT/traits_linestring.h similarity index 93% rename from Stream_support/include/CGAL/IO/traits_linestring.h rename to Stream_support/include/CGAL/IO/WKT/traits_linestring.h index 1bc756762b3..81c5bb141d5 100644 --- a/Stream_support/include/CGAL/IO/traits_linestring.h +++ b/Stream_support/include/CGAL/IO/WKT/traits_linestring.h @@ -17,10 +17,10 @@ // SPDX-License-Identifier: LGPL-3.0+ // // Author(s) : Maxime Gimeno -#if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500) -#ifndef CGAL_IO_TRAITS_LINESTRING_H -#define CGAL_IO_TRAITS_LINESTRING_H +#ifndef CGAL_IO_WKT_TRAITS_LINESTRING_H +#define CGAL_IO_WKT_TRAITS_LINESTRING_H +#if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500) #include #include #include @@ -35,5 +35,5 @@ template< typename R> struct tag= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500) #include #include diff --git a/Stream_support/include/CGAL/IO/traits_multipoint.h b/Stream_support/include/CGAL/IO/WKT/traits_multipoint.h similarity index 93% rename from Stream_support/include/CGAL/IO/traits_multipoint.h rename to Stream_support/include/CGAL/IO/WKT/traits_multipoint.h index 7d899439d95..a3f1b07e0dd 100644 --- a/Stream_support/include/CGAL/IO/traits_multipoint.h +++ b/Stream_support/include/CGAL/IO/WKT/traits_multipoint.h @@ -18,8 +18,8 @@ // // Author(s) : Maxime Gimeno -#ifndef CGAL_IO_TRAITS_MULTIPOINT_H -#define CGAL_IO_TRAITS_MULTIPOINT_H +#ifndef CGAL_IO_WKT_TRAITS_MULTIPOINT_H +#define CGAL_IO_WKT_TRAITS_MULTIPOINT_H #if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500) #include #include diff --git a/Stream_support/include/CGAL/IO/traits_multipolygon.h b/Stream_support/include/CGAL/IO/WKT/traits_multipolygon.h similarity index 93% rename from Stream_support/include/CGAL/IO/traits_multipolygon.h rename to Stream_support/include/CGAL/IO/WKT/traits_multipolygon.h index 543f75e290f..ef06d639ca7 100644 --- a/Stream_support/include/CGAL/IO/traits_multipolygon.h +++ b/Stream_support/include/CGAL/IO/WKT/traits_multipolygon.h @@ -18,8 +18,8 @@ // // Author(s) : Maxime Gimeno -#ifndef CGAL_IO_TRAITS_MULTIPOLYGON_H -#define CGAL_IO_TRAITS_MULTIPOLYGON_H +#ifndef CGAL_IO_WKT_TRAITS_MULTIPOLYGON_H +#define CGAL_IO_WKT_TRAITS_MULTIPOLYGON_H #if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500) #include #include diff --git a/Stream_support/include/CGAL/IO/traits_point.h b/Stream_support/include/CGAL/IO/WKT/traits_point.h similarity index 96% rename from Stream_support/include/CGAL/IO/traits_point.h rename to Stream_support/include/CGAL/IO/WKT/traits_point.h index 2775774f129..a2c2da9338b 100644 --- a/Stream_support/include/CGAL/IO/traits_point.h +++ b/Stream_support/include/CGAL/IO/WKT/traits_point.h @@ -18,8 +18,8 @@ // // Author(s) : Maxime Gimeno -#ifndef CGAL_IO_TRAITS_POINT_H -#define CGAL_IO_TRAITS_POINT_H +#ifndef CGAL_IO_WKT_TRAITS_POINT_H +#define CGAL_IO_WKT_TRAITS_POINT_H #if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500) #include #include diff --git a/Stream_support/include/CGAL/IO/traits_point_3.h b/Stream_support/include/CGAL/IO/WKT/traits_point_3.h similarity index 96% rename from Stream_support/include/CGAL/IO/traits_point_3.h rename to Stream_support/include/CGAL/IO/WKT/traits_point_3.h index 4132d1af77a..aff0404b406 100644 --- a/Stream_support/include/CGAL/IO/traits_point_3.h +++ b/Stream_support/include/CGAL/IO/WKT/traits_point_3.h @@ -18,8 +18,8 @@ // // Author(s) : Maxime Gimeno -#ifndef CGAL_IO_TRAITS_POINT_3_H -#define CGAL_IO_TRAITS_POINT_3_H +#ifndef CGAL_IO_WKT_TRAITS_POINT_3_H +#define CGAL_IO_WKT_TRAITS_POINT_3_H #if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500) #include #include diff --git a/Stream_support/include/CGAL/IO/traits_polygon.h b/Stream_support/include/CGAL/IO/WKT/traits_polygon.h similarity index 97% rename from Stream_support/include/CGAL/IO/traits_polygon.h rename to Stream_support/include/CGAL/IO/WKT/traits_polygon.h index 9ce365ada84..3117462e895 100644 --- a/Stream_support/include/CGAL/IO/traits_polygon.h +++ b/Stream_support/include/CGAL/IO/WKT/traits_polygon.h @@ -18,8 +18,8 @@ // // Author(s) : Maxime Gimeno -#ifndef CGAL_IO_TRAITS_POLYGON_H -#define CGAL_IO_TRAITS_POLYGON_H +#ifndef CGAL_IO_WKT_TRAITS_POLYGON_H +#define CGAL_IO_WKT_TRAITS_POLYGON_H #if BOOST_VERSION >= 105600 && (! defined(BOOST_GCC) || BOOST_GCC >= 40500) #include #include From 137b0c076fa40fa0ce4d63d0ef74da2e329b6d57 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Thu, 8 Aug 2019 09:32:48 +0200 Subject: [PATCH 06/28] Add a test for GOCAD IO --- .../CGAL/IO/Polyhedron_builder_from_STL.h | 8 +- .../test/Stream_support/test_gocad.cpp | 88 +++++++++++++++++++ 2 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 Stream_support/test/Stream_support/test_gocad.cpp diff --git a/Polyhedron/include/CGAL/IO/Polyhedron_builder_from_STL.h b/Polyhedron/include/CGAL/IO/Polyhedron_builder_from_STL.h index de3717e0063..6d611fca315 100644 --- a/Polyhedron/include/CGAL/IO/Polyhedron_builder_from_STL.h +++ b/Polyhedron/include/CGAL/IO/Polyhedron_builder_from_STL.h @@ -1,9 +1,9 @@ // Copyright (c) 2015 GeometryFactory // -// This file is part of CGAL (www.cgal.org); you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 3 of the License, -// or (at your option) any later version. +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. // // Licensees holding a valid commercial license may use this file in // accordance with the commercial license agreement provided with the software. diff --git a/Stream_support/test/Stream_support/test_gocad.cpp b/Stream_support/test/Stream_support/test_gocad.cpp new file mode 100644 index 00000000000..e9d32a5fa83 --- /dev/null +++ b/Stream_support/test/Stream_support/test_gocad.cpp @@ -0,0 +1,88 @@ + +#include +#include +#include +#include +#include + +#include +#include +#include + +template +bool test_io() +{ + FaceGraph fg; + /*const char* tet = "GOCAD TSurf 1 \n" + "HEADER { \n" + "name:Tetrahedron \n" + "*border:on \n" + "*border*bstone:on \n" + "} \n" + "GOCAD_ORIGINAL_COORDINATE_SYSTEM\n" + "NAME Default \n" + "AXIS_NAME \"X\" \"Y\" \"Z\" \n" + "AXIS_UNIT \"m\" \"m\" \"m\" \n" + "ZPOSITIVE Elevation \n" + "END_ORIGINAL_COORDINATE_SYSTEM \n" + "TFACE \n" + "VRTX 0 0 0 0 \n" + "VRTX 1 1 0 0 \n" + "VRTX 2 0 1 0 \n" + "VRTX 3 0 0 1 \n" + "TRGL 0 2 1 \n" + "TRGL 2 0 3 \n" + "TRGL 1 2 3 \n" + "TRGL 0 1 3 \n" + "END \n";*/ + CGAL::make_tetrahedron(Point(0, 0, 0), Point(1, 1, 0), + Point(2, 0, 1), Point(3, 0, 0), fg); + std::ostringstream out; + out << fg; + if(out.fail()) + { + std::cerr<<"Tetrahedron writing failed."<> fg2; + + if(in.fail()){ + std::cerr<<"Tetrahedron reading failed."<, Epick::Point_3>()) + { + return 1; + } + if(!test_io,Epeck::Point_3>()) + { + return 1; + } + if(!test_io, Epick::Point_3>()) + { + return 1; + } + if(!test_io, Epeck::Point_3>()) + { + return 1; + } + return 0; +} From 9c794aa2289036a01a964c3751c7951cd269a866 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Thu, 8 Aug 2019 10:23:09 +0200 Subject: [PATCH 07/28] Fix GOCAD reader to not duplicate vertices --- .../include/CGAL/IO/GOCAD/GOCAD_internals.h | 16 +++++-- .../test/Stream_support/test_gocad.cpp | 46 ++++++++----------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/Stream_support/include/CGAL/IO/GOCAD/GOCAD_internals.h b/Stream_support/include/CGAL/IO/GOCAD/GOCAD_internals.h index befbbefedb9..843f5f6434b 100644 --- a/Stream_support/include/CGAL/IO/GOCAD/GOCAD_internals.h +++ b/Stream_support/include/CGAL/IO/GOCAD/GOCAD_internals.h @@ -55,14 +55,22 @@ public: void operator()( Facegraph& graph) { read(is, meshPoints, mesh); + typedef typename boost::graph_traits::vertex_descriptor + vertex_descriptor; + + std::vector vertices(meshPoints.size()); + for(std::size_t id = 0; id < meshPoints.size(); ++id) + { + vertices[id] = add_vertex( meshPoints[id], graph); + } // graph.begin_surface( meshPoints.size(), mesh.size()); typedef typename Points_3::size_type size_type; for(size_type i=0; i < mesh.size(); i++){ - std::array::vertex_descriptor, 3> face; - face[0] = add_vertex( meshPoints[mesh[i].template get<0>()],graph); - face[1] = add_vertex( meshPoints[mesh[i].template get<1>()],graph); - face[2] = add_vertex( meshPoints[mesh[i].template get<2>()],graph); + std::array face; + face[0] = vertices[mesh[i].template get<0>()]; + face[1] = vertices[mesh[i].template get<1>()]; + face[2] = vertices[mesh[i].template get<2>()]; CGAL::Euler::add_face(face, graph); } diff --git a/Stream_support/test/Stream_support/test_gocad.cpp b/Stream_support/test/Stream_support/test_gocad.cpp index e9d32a5fa83..db85bddc8cd 100644 --- a/Stream_support/test/Stream_support/test_gocad.cpp +++ b/Stream_support/test/Stream_support/test_gocad.cpp @@ -8,37 +8,16 @@ #include #include #include +#include template bool test_io() { FaceGraph fg; - /*const char* tet = "GOCAD TSurf 1 \n" - "HEADER { \n" - "name:Tetrahedron \n" - "*border:on \n" - "*border*bstone:on \n" - "} \n" - "GOCAD_ORIGINAL_COORDINATE_SYSTEM\n" - "NAME Default \n" - "AXIS_NAME \"X\" \"Y\" \"Z\" \n" - "AXIS_UNIT \"m\" \"m\" \"m\" \n" - "ZPOSITIVE Elevation \n" - "END_ORIGINAL_COORDINATE_SYSTEM \n" - "TFACE \n" - "VRTX 0 0 0 0 \n" - "VRTX 1 1 0 0 \n" - "VRTX 2 0 1 0 \n" - "VRTX 3 0 0 1 \n" - "TRGL 0 2 1 \n" - "TRGL 2 0 3 \n" - "TRGL 1 2 3 \n" - "TRGL 0 1 3 \n" - "END \n";*/ CGAL::make_tetrahedron(Point(0, 0, 0), Point(1, 1, 0), Point(2, 0, 1), Point(3, 0, 0), fg); std::ostringstream out; - out << fg; + CGAL::write_gocad(fg, out, "tetrahedron"); if(out.fail()) { std::cerr<<"Tetrahedron writing failed."<> fg2; + std::string name, color; + CGAL::read_gocad(fg2, in, name, color); + if(name != "tetrahedron"){ + std::cerr<<"reading error: tetrahedron != "<::type VPMap; + VPMap vpmap = get(CGAL::vertex_point, polyhedron); + std::map::vertex_descriptor, int> id_map; + { + typename boost::graph_traits::vertex_iterator it, end; + it = vertices(polyhedron).begin(); + end = vertices(polyhedron).end(); + int i=0; + for(; it != end; ++it){ + id_map[*it] = i; + os << "VRTX " << i << " " << get(vpmap, *it) << "\n"; + ++i; + } + } + + { + typename boost::graph_traits::face_iterator it, end; + it = faces(polyhedron).begin(); + end = faces(polyhedron).end(); + for(; it != end; ++it){ + os << "TRGL " << id_map[target(prev(halfedge(*it, polyhedron), polyhedron), polyhedron)] << " " + << id_map[target(halfedge(*it, polyhedron), polyhedron)] << " " + << id_map[target(next(halfedge(*it, polyhedron), polyhedron), polyhedron)] << "\n"; + } + } + + os << "END" << std::endl; + + return true; +} + + } // namespace CGAL + #endif // CGAL_BOOST_GRAPH_IO_H diff --git a/Stream_support/include/CGAL/IO/GOCAD.h b/Stream_support/include/CGAL/IO/GOCAD.h deleted file mode 100644 index cbce12b6785..00000000000 --- a/Stream_support/include/CGAL/IO/GOCAD.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2019 GeometryFactory -// -// This file is part of CGAL (www.cgal.org); you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 3 of the License, -// or (at your option) any later version. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0+ -// -// Author(s) : Maxime Gimeno - -#ifndef CGAL_IO_GOCAD_H -#define CGAL_IO_GOCAD_H - -#include -#include -#include - -namespace CGAL{ -template -bool -read_gocad(FaceGraph& facegraph, std::istream& in, std::string& name, std::string& color) -{ - return GOCAD_internal::read_gocad(facegraph, in, name, color); -} - -template -bool -write_gocad(FaceGraph& facegraph, std::ostream& os, const std::string& name) -{ - return GOCAD_internal::write_gocad(facegraph, os, name); -} - -}//end CGAL - -#endif //CGAL_IO_GOCAD_H diff --git a/Stream_support/include/CGAL/IO/GOCAD/Build_from_gocad.h b/Stream_support/include/CGAL/IO/GOCAD/Build_from_gocad.h new file mode 100644 index 00000000000..d2bb22c0821 --- /dev/null +++ b/Stream_support/include/CGAL/IO/GOCAD/Build_from_gocad.h @@ -0,0 +1,111 @@ +// Copyright (c) 2019 GeometryFactory +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// Author(s) : Maxime Gimeno + +#ifndef CGAL_IO_GOCAD_BUILD_FROM_GOCAD_H +#define CGAL_IO_GOCAD_BUILD_FROM_GOCAD_H + +#include +#include +#include +#include +#include + +namespace CGAL{ + +namespace GOCAD_internal { +template +class Build_from_gocad +{ +protected: + typedef P Point_3; + typedef std::deque Points_3; + typedef boost::tuple Facet; + typedef std::deque Surface; + +public: + std::string name, color; + Build_from_gocad(std::istream& is_) + : is(is_), counter(0) + {} + + void do_construct(){} //specific to Facegraph (declared in BGL) + void + read(std::istream& input, Points_3& points, Surface& surface, int offset = 0) + { + char c; + std::string s, tface("TFACE"); + int i,j,k; + Point_3 p; + bool vertices_read = false; + while(input >> s){ + if(s == tface){ + break; + } + std::string::size_type idx; + + if((idx = s.find("name")) != std::string::npos){ + std::istringstream str(s.substr(idx+5)); + str >> name; + } + if((idx = s.find("color")) != std::string::npos){ + std::istringstream str(s.substr(idx+6)); + str >> color; + } + } + std::getline(input, s); + + while(input.get(c)){ + if((c == 'V')||(c == 'P')){ + input >> s >> i >> p; + if(! vertices_read){ + vertices_read = true; + offset -= i; // Some files start with index 0 others with 1 + } + + points.push_back(p); + + } else if(vertices_read && (c == 'T')){ + input >> c >> c >> c >> i >> j >> k; + surface.push_back(boost::make_tuple(offset+i, offset+j, offset+k)); + } else if(c == 'E'){ + break; + } + std::getline(input, s); + } + } + + void operator()( Facegraph& graph) + { + read(this->is, this->meshPoints, this->mesh); + static_cast(this)->do_construct(graph); + } + +protected: + std::istream& is; + int counter; + Points_3 meshPoints; + Surface mesh; +}; + + + +}//end GOCAD_internal +}//end CGAL +#endif // CGAL_IO_GOCAD_BUILD_FROM_GOCAD_H + diff --git a/Stream_support/include/CGAL/IO/GOCAD/GOCAD_internals.h b/Stream_support/include/CGAL/IO/GOCAD/GOCAD_internals.h deleted file mode 100644 index 843f5f6434b..00000000000 --- a/Stream_support/include/CGAL/IO/GOCAD/GOCAD_internals.h +++ /dev/null @@ -1,195 +0,0 @@ -// Copyright (c) 2019 GeometryFactory -// -// This file is part of CGAL (www.cgal.org); you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 3 of the License, -// or (at your option) any later version. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0+ -// -// Author(s) : Maxime Gimeno - -#ifndef CGAL_IO_GOCAD_GOCAD_INTERNALS_H -#define CGAL_IO_GOCAD_GOCAD_INTERNALS_H - -#include -#include -#include -#include -#include -#include - -namespace CGAL{ - -namespace GOCAD_internal { -template -class Build_from_gocad_BGL -{ - typedef P Point_3; - typedef std::deque Points_3; - typedef boost::tuple Facet; - typedef std::deque Surface; - - std::istream& is; - int counter; - Points_3 meshPoints; - Surface mesh; - -public: - - std::string name, color; - - - Build_from_gocad_BGL(std::istream& is_) - : is(is_), counter(0) - {} - - void operator()( Facegraph& graph) { - read(is, meshPoints, mesh); - - typedef typename boost::graph_traits::vertex_descriptor - vertex_descriptor; - - std::vector vertices(meshPoints.size()); - for(std::size_t id = 0; id < meshPoints.size(); ++id) - { - vertices[id] = add_vertex( meshPoints[id], graph); - } -// graph.begin_surface( meshPoints.size(), mesh.size()); - typedef typename Points_3::size_type size_type; - - for(size_type i=0; i < mesh.size(); i++){ - std::array face; - face[0] = vertices[mesh[i].template get<0>()]; - face[1] = vertices[mesh[i].template get<1>()]; - face[2] = vertices[mesh[i].template get<2>()]; - - CGAL::Euler::add_face(face, graph); - } - } - - void - read(std::istream& input, Points_3& points, Surface& surface, int offset = 0) - { - char c; - std::string s, tface("TFACE"); - int i,j,k; - Point_3 p; - bool vertices_read = false; - while(input >> s){ - if(s == tface){ - break; - } - std::string::size_type idx; - - if((idx = s.find("name")) != std::string::npos){ - std::istringstream str(s.substr(idx+5)); - str >> name; - } - if((idx = s.find("color")) != std::string::npos){ - std::istringstream str(s.substr(idx+6)); - str >> color; - } - } - std::getline(input, s); - - while(input.get(c)){ - if((c == 'V')||(c == 'P')){ - input >> s >> i >> p; - if(! vertices_read){ - vertices_read = true; - offset -= i; // Some files start with index 0 others with 1 - } - - points.push_back(p); - - } else if(vertices_read && (c == 'T')){ - input >> c >> c >> c >> i >> j >> k; - surface.push_back(boost::make_tuple(offset+i, offset+j, offset+k)); - } else if(c == 'E'){ - break; - } - std::getline(input, s); - } - } - -}; - -template -bool -read_gocad(FaceGraph& polyhedron, std::istream& in, std::string& name, std::string& color) -{ - //typedef typename Polyhedron::HalfedgeDS HDS; - typedef typename boost::property_traits::type>::value_type Point_3; - - Build_from_gocad_BGL builder(in); - builder(polyhedron); - name=builder.name; - color=builder.color; - - return in.good() && polyhedron.is_valid(); -} - -template -bool -write_gocad(FaceGraph& polyhedron, std::ostream& os, const std::string& name) -{ - os << "GOCAD TSurf 1\n" - "HEADER {\n" - "name:"; - os << name << std::endl; - os << "*border:on\n" - "*border*bstone:on\n" - "}\n" - "GOCAD_ORIGINAL_COORDINATE_SYSTEM\n" - "NAME Default\n" - "AXIS_NAME \"X\" \"Y\" \"Z\"\n" - "AXIS_UNIT \"m\" \"m\" \"m\"\n" - "ZPOSITIVE Elevation\n" - "END_ORIGINAL_COORDINATE_SYSTEM\n" - "TFACE\n"; - - os.precision(16); - typedef typename boost::property_map::type VPMap; - VPMap vpmap = get(CGAL::vertex_point, polyhedron); - std::map::vertex_descriptor, int> id_map; - { - typename boost::graph_traits::vertex_iterator it, end; - it = vertices(polyhedron).begin(); - end = vertices(polyhedron).end(); - int i=0; - for(; it != end; ++it){ - id_map[*it] = i; - os << "VRTX " << i << " " << get(vpmap, *it) << "\n"; - ++i; - } - } - - { - typename boost::graph_traits::face_iterator it, end; - it = faces(polyhedron).begin(); - end = faces(polyhedron).end(); - for(; it != end; ++it){ - os << "TRGL " << id_map[target(prev(halfedge(*it, polyhedron), polyhedron), polyhedron)] << " " - << id_map[target(halfedge(*it, polyhedron), polyhedron)] << " " - << id_map[target(next(halfedge(*it, polyhedron), polyhedron), polyhedron)] << "\n"; - } - } - - os << "END" << std::endl; - - return true; -} - -}//end GOCAD_internal -}//end CGAL -#endif // CGAL_IO_GOCAD_GOCAD_INTERNALS_H - diff --git a/Stream_support/test/Stream_support/test_gocad.cpp b/Stream_support/test/Stream_support/test_gocad.cpp index db85bddc8cd..dfa0cc9c6d0 100644 --- a/Stream_support/test/Stream_support/test_gocad.cpp +++ b/Stream_support/test/Stream_support/test_gocad.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include #include From 88b5d1916aa81b3c560363d7436922dc23205d98 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Thu, 8 Aug 2019 15:20:44 +0200 Subject: [PATCH 09/28] some fixes in write_vtp and add read_vtp in BGL --- BGL/include/CGAL/boost/graph/io.h | 258 +++++++++++------- BGL/test/BGL/CMakeLists.txt | 22 +- BGL/test/BGL/test_bgl_read_write.cpp | 77 ++++++ .../demo/Polyhedron/Plugins/IO/CMakeLists.txt | 2 +- .../Polyhedron/Plugins/IO/VTK_io_plugin.cpp | 141 +--------- 5 files changed, 267 insertions(+), 233 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/io.h b/BGL/include/CGAL/boost/graph/io.h index 934faf0fd5b..ddbeb1676a4 100644 --- a/BGL/include/CGAL/boost/graph/io.h +++ b/BGL/include/CGAL/boost/graph/io.h @@ -33,6 +33,9 @@ #include #include #include +#ifdef CGAL_USE_VTK +#include +#endif #include #include @@ -403,6 +406,112 @@ bool write_inp(std::ostream& os, return write_inp(os, g, name, type, parameters::all_default()); } +namespace GOCAD_internal{ +//Use CRTP to gain access to the protected members without getters/setters. +template +class GOCAD_builder : public Build_from_gocad > +{ + typedef GOCAD_builder Self; + typedef Build_from_gocad Base; + typedef typename Base::Point_3 Point_3; + typedef typename Base::Points_3 Points_3; + typedef typename Base::Facet Facet; + typedef typename Base::Surface Surface; +public: + GOCAD_builder(std::istream& is_) + :Base(is_){} + void do_construct(Facegraph& graph) + { + typedef typename boost::graph_traits::vertex_descriptor + vertex_descriptor; + + std::vector vertices(this->meshPoints.size()); + for(std::size_t id = 0; id < this->meshPoints.size(); ++id) + { + vertices[id] = add_vertex( this->meshPoints[id], graph); + } + // graph.begin_surface( meshPoints.size(), mesh.size()); + typedef typename Points_3::size_type size_type; + + for(size_type i=0; i < this->mesh.size(); i++){ + std::array face; + face[0] = vertices[this->mesh[i].template get<0>()]; + face[1] = vertices[this->mesh[i].template get<1>()]; + face[2] = vertices[this->mesh[i].template get<2>()]; + + CGAL::Euler::add_face(face, graph); + } + } +}; +}//end GOCAD_internal + +template +bool +read_gocad(FaceGraph& face_graph, std::istream& in, std::string& name, std::string& color) +{ + //typedef typename Polyhedron::HalfedgeDS HDS; + typedef typename boost::property_traits::type>::value_type Point_3; + + GOCAD_internal::GOCAD_builder builder(in); + builder(face_graph); + name=builder.name; + color=builder.color; + + return in.good() && face_graph.is_valid(); +} + +//todo : better management of the id_map +template +bool +write_gocad(FaceGraph& face_graph, std::ostream& os, const std::string& name) +{ + os << "GOCAD TSurf 1\n" + "HEADER {\n" + "name:"; + os << name << std::endl; + os << "*border:on\n" + "*border*bstone:on\n" + "}\n" + "GOCAD_ORIGINAL_COORDINATE_SYSTEM\n" + "NAME Default\n" + "AXIS_NAME \"X\" \"Y\" \"Z\"\n" + "AXIS_UNIT \"m\" \"m\" \"m\"\n" + "ZPOSITIVE Elevation\n" + "END_ORIGINAL_COORDINATE_SYSTEM\n" + "TFACE\n"; + + os.precision(16); + typedef typename boost::property_map::type VPMap; + VPMap vpmap = get(CGAL::vertex_point, face_graph); + std::map::vertex_descriptor, int> id_map; + { + typename boost::graph_traits::vertex_iterator it, end; + it = vertices(face_graph).begin(); + end = vertices(face_graph).end(); + int i=0; + for(; it != end; ++it){ + id_map[*it] = i; + os << "VRTX " << i << " " << get(vpmap, *it) << "\n"; + ++i; + } + } + + { + typename boost::graph_traits::face_iterator it, end; + it = faces(face_graph).begin(); + end = faces(face_graph).end(); + for(; it != end; ++it){ + os << "TRGL " << id_map[target(prev(halfedge(*it, face_graph), face_graph), face_graph)] << " " + << id_map[target(halfedge(*it, face_graph), face_graph)] << " " + << id_map[target(next(halfedge(*it, face_graph), face_graph), face_graph)] << "\n"; + } + } + + os << "END" << std::endl; + + return true; +} + namespace internal { namespace write_vtp { @@ -433,7 +542,7 @@ write_polys(std::ostream& os, offsets.push_back(off); for(vertex_descriptor v : vertices_around_face(halfedge(*fit, mesh), mesh)) - connectivity_table.push_back(V[v]); + connectivity_table.push_back(get(V, v)); } write_vector(os,connectivity_table); write_vector(os,offsets); @@ -483,7 +592,7 @@ write_polys_tag(std::ostream& os, { for(vertex_descriptor v : vertices_around_face(halfedge(*fit, mesh), mesh)) - os << V[v] << " "; + os << get(V, v) << " "; } os << " \n"; } @@ -674,112 +783,69 @@ void write_vtp(std::ostream& os, write_vtp(os, mesh, CGAL::parameters::all_default()); } -namespace GOCAD_internal{ -//Use CRTP to gain access to the protected members without getters/setters. -template -class GOCAD_builder : public Build_from_gocad > -{ - typedef GOCAD_builder Self; - typedef Build_from_gocad Base; - typedef typename Base::Point_3 Point_3; - typedef typename Base::Points_3 Points_3; - typedef typename Base::Facet Facet; - typedef typename Base::Surface Surface; -public: - GOCAD_builder(std::istream& is_) - :Base(is_){} - void do_construct(Facegraph& graph) - { - typedef typename boost::graph_traits::vertex_descriptor - vertex_descriptor; - - std::vector vertices(this->meshPoints.size()); - for(std::size_t id = 0; id < this->meshPoints.size(); ++id) - { - vertices[id] = add_vertex( this->meshPoints[id], graph); - } - // graph.begin_surface( meshPoints.size(), mesh.size()); - typedef typename Points_3::size_type size_type; - - for(size_type i=0; i < this->mesh.size(); i++){ - std::array face; - face[0] = vertices[this->mesh[i].template get<0>()]; - face[1] = vertices[this->mesh[i].template get<1>()]; - face[2] = vertices[this->mesh[i].template get<2>()]; - - CGAL::Euler::add_face(face, graph); - } - } -}; -}//end GOCAD_internal +#ifdef CGAL_USE_VTK +namespace VTK_internal{ template -bool -read_gocad(FaceGraph& polyhedron, std::istream& in, std::string& name, std::string& color) +bool vtkPointSet_to_polygon_mesh(vtkPointSet* poly_data, + FaceGraph& face_graph) { - //typedef typename Polyhedron::HalfedgeDS HDS; - typedef typename boost::property_traits::type>::value_type Point_3; - - GOCAD_internal::GOCAD_builder builder(in); - builder(polyhedron); - name=builder.name; - color=builder.color; - - return in.good() && polyhedron.is_valid(); -} - -template -bool -write_gocad(FaceGraph& polyhedron, std::ostream& os, const std::string& name) -{ - os << "GOCAD TSurf 1\n" - "HEADER {\n" - "name:"; - os << name << std::endl; - os << "*border:on\n" - "*border*bstone:on\n" - "}\n" - "GOCAD_ORIGINAL_COORDINATE_SYSTEM\n" - "NAME Default\n" - "AXIS_NAME \"X\" \"Y\" \"Z\"\n" - "AXIS_UNIT \"m\" \"m\" \"m\"\n" - "ZPOSITIVE Elevation\n" - "END_ORIGINAL_COORDINATE_SYSTEM\n" - "TFACE\n"; - - os.precision(16); typedef typename boost::property_map::type VPMap; - VPMap vpmap = get(CGAL::vertex_point, polyhedron); - std::map::vertex_descriptor, int> id_map; + typedef typename boost::property_map_value::type Point_3; + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; + + VPMap vpmap = get(CGAL::vertex_point, face_graph); + + // get nb of points and cells + vtkIdType nb_points = poly_data->GetNumberOfPoints(); + vtkIdType nb_cells = poly_data->GetNumberOfCells(); + //extract points + std::vector vertex_map(nb_points); + for (vtkIdType i = 0; i::vertex_iterator it, end; - it = vertices(polyhedron).begin(); - end = vertices(polyhedron).end(); - int i=0; - for(; it != end; ++it){ - id_map[*it] = i; - os << "VRTX " << i << " " << get(vpmap, *it) << "\n"; - ++i; - } + double coords[3]; + poly_data->GetPoint(i, coords); + + vertex_descriptor v = add_vertex(face_graph); + put(vpmap, v, Point_3(coords[0], coords[1], coords[2])); + vertex_map[i]=v; } + //extract cells + for (vtkIdType i = 0; i::face_iterator it, end; - it = faces(polyhedron).begin(); - end = faces(polyhedron).end(); - for(; it != end; ++it){ - os << "TRGL " << id_map[target(prev(halfedge(*it, polyhedron), polyhedron), polyhedron)] << " " - << id_map[target(halfedge(*it, polyhedron), polyhedron)] << " " - << id_map[target(next(halfedge(*it, polyhedron), polyhedron), polyhedron)] << "\n"; + int cell_type = poly_data->GetCellType(i); + if(cell_type != 5 + && cell_type != 7 + && cell_type != 9) //only supported cells are triangles, quads and polygons + continue; + vtkCell* cell_ptr = poly_data->GetCell(i); + + vtkIdType nb_vertices = cell_ptr->GetNumberOfPoints(); + if (nb_vertices < 3) + return false; + std::vector vr(nb_vertices); + for (vtkIdType k=0; kGetPointId(k); + vr[k]=vertex_map[id]; } + + CGAL::Euler::add_face(vr, face_graph); } - - os << "END" << std::endl; - return true; } - - +} //end VTK_internal +template +bool read_vtp(const char* filename, FaceGraph& face_graph) +{ + vtkSmartPointer data; + if(!CGAL::read_vtp_file(filename, data)) + { + return false; + } + return VTK_internal::vtkPointSet_to_polygon_mesh(data, face_graph); +} +#endif //CGAL_USE_VTK } // namespace CGAL diff --git a/BGL/test/BGL/CMakeLists.txt b/BGL/test/BGL/CMakeLists.txt index e7209f704d9..eb4e88f3be4 100644 --- a/BGL/test/BGL/CMakeLists.txt +++ b/BGL/test/BGL/CMakeLists.txt @@ -10,7 +10,8 @@ project( BGL_Tests ) # CGAL and its components find_package( CGAL QUIET COMPONENTS ) - +find_package(VTK QUIET COMPONENTS + vtkCommonCore vtkIOCore vtkIOLegacy vtkIOXML vtkFiltersCore vtkFiltersSources) if ( NOT CGAL_FOUND ) message(STATUS "This project requires the CGAL library, and will not be compiled.") @@ -32,11 +33,10 @@ if ( OpenMesh_FOUND ) include( UseOpenMesh ) add_definitions( -DCGAL_USE_OPENMESH ) else() - message(STATUS "Examples that use OpenMesh will not be compiled.") + message(STATUS "Tests that use OpenMesh will not be compiled.") endif() - # include for local package # Creating entries for all .cpp/.C files with "main" routine @@ -108,3 +108,19 @@ if(OpenMesh_FOUND) target_link_libraries( test_Properties PRIVATE ${OPENMESH_LIBRARIES}) target_link_libraries( test_bgl_read_write PRIVATE ${OPENMESH_LIBRARIES}) endif() +if (VTK_FOUND) + if(VTK_USE_FILE) + include(${VTK_USE_FILE}) + endif() + if ("${VTK_VERSION_MAJOR}" GREATER "5" OR VTK_VERSION VERSION_GREATER 5) + if(TARGET VTK::CommonCore) + set(VTK_LIBRARIES VTK::CommonCore VTK::IOCore VTK::IOLegacy VTK::IOXML VTK::FiltersCore VTK::FiltersSources) + endif() + if(VTK_LIBRARIES) + add_definitions(-DCGAL_USE_VTK) + target_link_libraries( test_bgl_read_write PRIVATE ${VTK_LIBRARIES}) + else() + message(STATUS "Tests that use VTK will not be compiled.") + endif() + endif() +endif() #VTK_FOUND diff --git a/BGL/test/BGL/test_bgl_read_write.cpp b/BGL/test/BGL/test_bgl_read_write.cpp index 894b772a610..5b1e78967e8 100644 --- a/BGL/test/BGL/test_bgl_read_write.cpp +++ b/BGL/test/BGL/test_bgl_read_write.cpp @@ -7,6 +7,7 @@ #include #include +#include #if defined(CGAL_USE_OPENMESH) @@ -47,6 +48,74 @@ void test_bgl_read_write(const char* filename) CGAL::write_off(std::cout, sm); } +#ifdef CGAL_USE_VTK +template +bool test_bgl_vtp() +{ + Mesh fg; + CGAL::make_tetrahedron(Point(0, 0, 0), Point(1, 1, 0), + Point(2, 0, 1), Point(3, 0, 0), fg); + + std::ofstream os("tetrahedron.vtp"); + CGAL::write_vtp(os, fg); + if(!os) + { + std::cerr<<"vtp writing failed."<1)?argv[1]:"data/prim.off"; @@ -58,6 +127,14 @@ int main(int argc, char** argv) #ifdef CGAL_USE_OPENMESH test_bgl_read_write(filename); #endif +#ifdef CGAL_USE_VTK + if(!test_bgl_vtp()) + return 1; + if(!test_bgl_vtp()) + return 1; + if(!test_bgl_vtp()) + return 1; +#endif return EXIT_SUCCESS; } diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/CMakeLists.txt b/Polyhedron/demo/Polyhedron/Plugins/IO/CMakeLists.txt index 616414c3f4d..8ca46a36441 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/CMakeLists.txt +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/CMakeLists.txt @@ -44,7 +44,7 @@ if (VTK_FOUND) polyhedron_demo_plugin(vtk_plugin VTK_io_plugin KEYWORDS IO Mesh_3) target_link_libraries(vtk_plugin PUBLIC scene_surface_mesh_item scene_polylines_item scene_c3t3_item scene_points_with_normal_item ${VTK_LIBRARIES}) - + add_definitions(-DCGAL_USE_VTK) else() message(STATUS "NOTICE : the vtk IO plugin needs VTK libraries and will not be compiled.") endif() diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp index b21c1a21d5d..9528dae9545 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #include #include @@ -88,98 +89,6 @@ CGAL::vertex_point_t>::type>::value_type Point; namespace CGAL{ - class ErrorObserverVtk : public vtkCommand - { - public: - ErrorObserverVtk() : - Error(false), - Warning(false), - ErrorMessage(""), - WarningMessage("") {} - static ErrorObserverVtk *New() { return new ErrorObserverVtk; } - - bool GetError() const { return this->Error; } - bool GetWarning() const { return this->Warning; } - std::string GetErrorMessage() { return ErrorMessage; } - std::string GetWarningMessage() { return WarningMessage; } - - void Clear() - { - this->Error = false; - this->Warning = false; - this->ErrorMessage = ""; - this->WarningMessage = ""; - } - virtual void Execute(vtkObject *vtkNotUsed(caller), - unsigned long event, - void *calldata) - { - switch (event) - { - case vtkCommand::ErrorEvent: - ErrorMessage = static_cast(calldata); - this->Error = true; - break; - case vtkCommand::WarningEvent: - WarningMessage = static_cast(calldata); - this->Warning = true; - break; - } - } - - private: - bool Error; - bool Warning; - std::string ErrorMessage; - std::string WarningMessage; - }; - - template - bool vtkPointSet_to_polygon_mesh(vtkPointSet* poly_data, - TM& tmesh) - { - typedef typename boost::property_map::type VPMap; - typedef typename boost::property_map_value::type Point_3; - typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; - - VPMap vpmap = get(CGAL::vertex_point, tmesh); - - // get nb of points and cells - vtkIdType nb_points = poly_data->GetNumberOfPoints(); - vtkIdType nb_cells = poly_data->GetNumberOfCells(); - - //extract points - std::vector vertex_map(nb_points); - for (vtkIdType i = 0; iGetPoint(i, coords); - - vertex_descriptor v = add_vertex(tmesh); - put(vpmap, v, Point_3(coords[0], coords[1], coords[2])); - vertex_map[i]=v; - } - - //extract cells - for (vtkIdType i = 0; iGetCellType(i) != 5 - && poly_data->GetCellType(i) != 7 - && poly_data->GetCellType(i) != 9) //only supported cells are triangles, quads and polygons - continue; - vtkCell* cell_ptr = poly_data->GetCell(i); - - vtkIdType nb_vertices = cell_ptr->GetNumberOfPoints(); - if (nb_vertices < 3) - return false; - std::vector vr(nb_vertices); - for (vtkIdType k=0; kGetPointId(k)]; - - CGAL::Euler::add_face(vr, tmesh); - } - return true; - } template void extract_segments_from_vtkPointSet(vtkPointSet* poly_data, @@ -363,19 +272,6 @@ public: bool canLoad(QFileInfo) const { return true; } - template - vtkSmartPointer - read_vtk_file(const std::string& input_filename, - vtkSmartPointer errorObserver) - { - vtkSmartPointer reader = vtkSmartPointer::New(); - reader->AddObserver(vtkCommand::ErrorEvent, errorObserver); - reader->AddObserver(vtkCommand::WarningEvent, errorObserver); - reader->SetFileName(input_filename.data()); - reader->Update(); - return reader; - } - QList load(QFileInfo fileinfo, bool& ok, bool add_to_scene) { std::string extension=fileinfo.suffix().toLower().toStdString(); @@ -401,20 +297,21 @@ public: } vtkSmartPointer data; - vtkSmartPointer obs = - vtkSmartPointer::New(); + vtkSmartPointer obs = + vtkSmartPointer::New(); if (extension=="vtp") - data = read_vtk_file(fname,obs) + data = CGAL::VTK_internal::read_vtk_file(fname,obs) ->GetOutput(); else if (extension=="vtu") - data = read_vtk_file(fname,obs) + data = CGAL::VTK_internal:: + read_vtk_file(fname,obs) ->GetOutput(); else{ //read non-XML data vtkSmartPointer reader = - read_vtk_file(fname,obs); + CGAL::VTK_internal::read_vtk_file(fname,obs); data = vtkPolyData::SafeDownCast(reader->GetOutput()); if (!data) data = vtkUnstructuredGrid::SafeDownCast(reader->GetOutput()); @@ -442,28 +339,6 @@ public: msgBox.setIcon(QMessageBox::Warning); msgBox.exec(); } - if (obs->GetError()) - { - QMessageBox msgBox; - msgBox.setText("This type of data can't be opened"); - msgBox.setInformativeText(QString("VTK error message :\n") - .append(QString(obs->GetErrorMessage().data()))); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setIcon(QMessageBox::Critical); - msgBox.exec(); - ok = false; - return QList(); - } - if (obs->GetWarning()) - { - QMessageBox msgBox; - msgBox.setText("This file generates a warning"); - msgBox.setInformativeText(QString("VTK warning message :\n") - .append(QString(obs->GetWarningMessage().data()))); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setIcon(QMessageBox::Warning); - msgBox.exec(); - } //check celltypes bool is_polygon_mesh(false), @@ -490,7 +365,7 @@ public: if(is_polygon_mesh) { FaceGraph* poly = new FaceGraph(); - if (CGAL::vtkPointSet_to_polygon_mesh(data, *poly)) + if (CGAL::VTK_internal::vtkPointSet_to_polygon_mesh(data, *poly)) { Scene_facegraph_item* poly_item = new Scene_facegraph_item(poly); if(group) From c15dd227e044a10ed1523bba80c3e03db36aea0f Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Fri, 9 Aug 2019 10:39:03 +0200 Subject: [PATCH 10/28] move test_gocad to BGL test. --- BGL/test/BGL/test_bgl_read_write.cpp | 52 +++++++++++- .../test/Stream_support/test_gocad.cpp | 80 ------------------- 2 files changed, 51 insertions(+), 81 deletions(-) delete mode 100644 Stream_support/test/Stream_support/test_gocad.cpp diff --git a/BGL/test/BGL/test_bgl_read_write.cpp b/BGL/test/BGL/test_bgl_read_write.cpp index 5b1e78967e8..c1c1b3f2953 100644 --- a/BGL/test/BGL/test_bgl_read_write.cpp +++ b/BGL/test/BGL/test_bgl_read_write.cpp @@ -116,6 +116,51 @@ bool test_bgl_vtp() } #endif +template +bool test_gocad() +{ + 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; + CGAL::write_gocad(fg, out, "tetrahedron"); + if(out.fail()) + { + std::cerr<<"Tetrahedron writing failed."<(filename); test_bgl_read_write(filename); test_bgl_read_write(filename); - + if(!test_gocad()) + return 1; + if(!test_gocad()) + return 1; + if(!test_gocad()) + return 1; #ifdef CGAL_USE_OPENMESH test_bgl_read_write(filename); #endif diff --git a/Stream_support/test/Stream_support/test_gocad.cpp b/Stream_support/test/Stream_support/test_gocad.cpp deleted file mode 100644 index dfa0cc9c6d0..00000000000 --- a/Stream_support/test/Stream_support/test_gocad.cpp +++ /dev/null @@ -1,80 +0,0 @@ - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -template -bool test_io() -{ - 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; - CGAL::write_gocad(fg, out, "tetrahedron"); - if(out.fail()) - { - std::cerr<<"Tetrahedron writing failed."<(faces(tm).size()); + out.write(reinterpret_cast(&N32), sizeof(N32)); + + for(face_descriptor f : faces(tm)) + { + halfedge_descriptor h = halfedge(f, tm); + Point_3_ref p = get(vpm, target(h, tm)); + Point_3_ref q = get(vpm, target(next(h, tm), tm)); + Point_3_ref r = get(vpm, source(h, tm)); + + Vector_3 n = collinear(p,q,r) ? Vector_3(1,0,0): + unit_normal(p,q,r); + + const float coords[12]={ + static_cast(n.x()), static_cast(n.y()), static_cast(n.z()), + static_cast(p.x()), static_cast(p.y()), static_cast(p.z()), + static_cast(q.x()), static_cast(q.y()), static_cast(q.z()), + static_cast(r.x()), static_cast(r.y()), static_cast(r.z()) }; + + for (int i=0; i<12; ++i) + out.write(reinterpret_cast(&coords[i]), sizeof(coords[i])); + out << " "; + } + } + else + { + out << "solid\n"; + for(face_descriptor f : faces(tm)) + { + halfedge_descriptor h = halfedge(f, tm); + Point_3_ref p = get(vpm, target(h, tm)); + Point_3_ref q = get(vpm, target(next(h, tm), tm)); + Point_3_ref r = get(vpm, source(h, tm)); + + Vector_3 n = collinear(p,q,r) ? Vector_3(1,0,0): + unit_normal(p,q,r); + out << "facet normal " << n << "\nouter loop\n"; + out << "vertex " << p << "\n"; + out << "vertex " << q << "\n"; + out << "vertex " << r << "\n"; + out << "endloop\nendfacet\n"; + } + out << "endsolid\n"; + } + return out; +} + } // namespace CGAL diff --git a/BGL/test/BGL/test_bgl_read_write.cpp b/BGL/test/BGL/test_bgl_read_write.cpp index c1c1b3f2953..bb3811c3393 100644 --- a/BGL/test/BGL/test_bgl_read_write.cpp +++ b/BGL/test/BGL/test_bgl_read_write.cpp @@ -18,6 +18,7 @@ #endif #include +#include #include #include diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/CMakeLists.txt b/Polyhedron/demo/Polyhedron/Plugins/IO/CMakeLists.txt index 8ca46a36441..48220216e21 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/CMakeLists.txt +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/CMakeLists.txt @@ -44,7 +44,7 @@ if (VTK_FOUND) polyhedron_demo_plugin(vtk_plugin VTK_io_plugin KEYWORDS IO Mesh_3) target_link_libraries(vtk_plugin PUBLIC scene_surface_mesh_item scene_polylines_item scene_c3t3_item scene_points_with_normal_item ${VTK_LIBRARIES}) - add_definitions(-DCGAL_USE_VTK) + target_compile_definitions(vtk_plugin PRIVATE -DCGAL_USE_VTK) else() message(STATUS "NOTICE : the vtk IO plugin needs VTK libraries and will not be compiled.") endif() diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/STL_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/IO/STL_io_plugin.cpp index 66d08020a49..d1d879bd5b4 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/STL_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/STL_io_plugin.cpp @@ -8,8 +8,8 @@ #include #include -#include -#include +#include +#include #include diff --git a/Polyhedron_IO/include/CGAL/IO/STL_writer.h b/Polyhedron_IO/include/CGAL/IO/STL_writer.h index a568c9995e9..b873edde233 100644 --- a/Polyhedron_IO/include/CGAL/IO/STL_writer.h +++ b/Polyhedron_IO/include/CGAL/IO/STL_writer.h @@ -21,9 +21,9 @@ #define CGAL_IO_STL_WRITER_H #define CGAL_DEPRECATED_HEADER "" -#define CGAL_REPLACEMENT_HEADER "" +#define CGAL_REPLACEMENT_HEADER "" #include -#include +#include #include #endif // CGAL_IO_STL_WRITER_H diff --git a/Stream_support/include/CGAL/IO/STL/STL_writer.h b/Stream_support/include/CGAL/IO/STL/STL_writer.h index 6bf46b593d1..3189628414b 100644 --- a/Stream_support/include/CGAL/IO/STL/STL_writer.h +++ b/Stream_support/include/CGAL/IO/STL/STL_writer.h @@ -21,40 +21,35 @@ #define CGAL_IO_STL_STL_WRITER_H #include -#include +#include #include -#include namespace CGAL{ -template +template std::ostream& -write_STL(const TriangleMesh& tm, std::ostream& out) +write_STL(const std::vector& points, + const std::vector& facets, + std::ostream& out) { - typedef typename boost::graph_traits::face_descriptor face_descriptor; - typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; - typedef typename boost::property_map::const_type Vpm; - typedef typename boost::property_traits::reference Point_3_ref; - typedef typename boost::property_traits::value_type Point_3; - typedef typename Kernel_traits::Kernel::Vector_3 Vector_3; + typedef typename CGAL::Kernel_traits::Kernel K; + typedef typename K::Vector_3 Vector_3; - Vpm vpm = get(boost::vertex_point, tm); if (get_mode(out) == IO::BINARY) { out << "FileType: Binary "; - const boost::uint32_t N32 = static_cast(faces(tm).size()); + const boost::uint32_t N32 = static_cast(facets.size()); out.write(reinterpret_cast(&N32), sizeof(N32)); - for(face_descriptor f : faces(tm)) + for(auto face : facets) { - halfedge_descriptor h = halfedge(f, tm); - Point_3_ref p = get(vpm, target(h, tm)); - Point_3_ref q = get(vpm, target(next(h, tm), tm)); - Point_3_ref r = get(vpm, source(h, tm)); + const Point& p = points[face[0]]; + const Point& q = points[face[1]]; + const Point& r = points[face[2]]; Vector_3 n = collinear(p,q,r) ? Vector_3(1,0,0): unit_normal(p,q,r); @@ -73,12 +68,11 @@ write_STL(const TriangleMesh& tm, std::ostream& out) else { out << "solid\n"; - for(face_descriptor f : faces(tm)) + for(auto face : facets) { - halfedge_descriptor h = halfedge(f, tm); - Point_3_ref p = get(vpm, target(h, tm)); - Point_3_ref q = get(vpm, target(next(h, tm), tm)); - Point_3_ref r = get(vpm, source(h, tm)); + const Point& p = points[face[0]]; + const Point& q = points[face[1]]; + const Point& r = points[face[2]]; Vector_3 n = collinear(p,q,r) ? Vector_3(1,0,0): unit_normal(p,q,r); diff --git a/Stream_support/include/CGAL/IO/reader_helpers.h b/Stream_support/include/CGAL/IO/reader_helpers.h index 62e465a7e07..92e46137965 100644 --- a/Stream_support/include/CGAL/IO/reader_helpers.h +++ b/Stream_support/include/CGAL/IO/reader_helpers.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include diff --git a/Stream_support/test/Stream_support/test_STL.cpp b/Stream_support/test/Stream_support/test_STL.cpp new file mode 100644 index 00000000000..6243d12d65f --- /dev/null +++ b/Stream_support/test/Stream_support/test_STL.cpp @@ -0,0 +1,58 @@ +#include +#include +#include + +#include +#include +#include + +int main () +{ + typedef CGAL::Exact_predicates_inexact_constructions_kernel K; + typedef K::Point_3 Point; + typedef std::vector Polygon; + //make a tetrahedorn soup. + std::vector ps(4); + ps[0] = Point(0,0,0); ps[1] = Point(1,0,0); + ps[2] = Point(0,1,0); ps[3] = Point(0,0,1); + std::vector faces(4); + + faces[0].push_back(0); + faces[0].push_back(2); + faces[0].push_back(1); + + faces[1].push_back(0); + faces[1].push_back(3); + faces[1].push_back(2); + + faces[2].push_back(1); + faces[2].push_back(2); + faces[2].push_back(3); + + faces[3].push_back(0); + faces[3].push_back(1); + faces[3].push_back(3); + + std::ofstream os("tetra.stl"); + CGAL::write_STL(ps, faces, os); + if(!os) + { + std::cerr<<"error during STL writing."< Date: Fri, 9 Aug 2019 13:53:33 +0200 Subject: [PATCH 12/28] - Unify the Facegraph builders (GOCAD and STL for now) - Make a BGL STL_reader - Add a test for it. --- BGL/include/CGAL/boost/graph/io.h | 125 +++++++++++++++++- BGL/test/BGL/test_bgl_read_write.cpp | 51 ++++++- .../include/CGAL/IO/GOCAD/Build_from_gocad.h | 111 ---------------- .../include/CGAL/IO/STL/STL_reader.h | 36 +++-- .../CGAL/internal/Generic_facegraph_builder.h | 69 ++++++++++ 5 files changed, 257 insertions(+), 135 deletions(-) delete mode 100644 Stream_support/include/CGAL/IO/GOCAD/Build_from_gocad.h create mode 100644 Stream_support/include/CGAL/internal/Generic_facegraph_builder.h diff --git a/BGL/include/CGAL/boost/graph/io.h b/BGL/include/CGAL/boost/graph/io.h index a6f28a93809..24b022ce92d 100644 --- a/BGL/include/CGAL/boost/graph/io.h +++ b/BGL/include/CGAL/boost/graph/io.h @@ -39,7 +39,8 @@ #include #endif #include -#include +#include +#include namespace CGAL { /*! @@ -411,10 +412,10 @@ bool write_inp(std::ostream& os, namespace GOCAD_internal{ //Use CRTP to gain access to the protected members without getters/setters. template -class GOCAD_builder : public Build_from_gocad > +class GOCAD_builder : public CGAL::internal::IO::Generic_facegraph_builder > { typedef GOCAD_builder Self; - typedef Build_from_gocad Base; + typedef CGAL::internal::IO::Generic_facegraph_builder Base; typedef typename Base::Point_3 Point_3; typedef typename Base::Points_3 Points_3; typedef typename Base::Facet Facet; @@ -437,13 +438,64 @@ public: for(size_type i=0; i < this->mesh.size(); i++){ std::array face; - face[0] = vertices[this->mesh[i].template get<0>()]; - face[1] = vertices[this->mesh[i].template get<1>()]; - face[2] = vertices[this->mesh[i].template get<2>()]; + face[0] = vertices[this->mesh[i][0]]; + face[1] = vertices[this->mesh[i][1]]; + face[2] = vertices[this->mesh[i][2]]; CGAL::Euler::add_face(face, graph); } } + + void + read(std::istream& input, Points_3& points, Surface& surface) + { + int offset = 0; + char c; + std::string s, tface("TFACE"); + int i,j,k; + Point_3 p; + bool vertices_read = false; + while(input >> s){ + if(s == tface){ + break; + } + std::string::size_type idx; + + if((idx = s.find("name")) != std::string::npos){ + std::istringstream str(s.substr(idx+5)); + str >> this->name; + } + if((idx = s.find("color")) != std::string::npos){ + std::istringstream str(s.substr(idx+6)); + str >> this->color; + } + } + std::getline(input, s); + + while(input.get(c)){ + if((c == 'V')||(c == 'P')){ + input >> s >> i >> p; + if(! vertices_read){ + vertices_read = true; + offset -= i; // Some files start with index 0 others with 1 + } + + points.push_back(p); + + } else if(vertices_read && (c == 'T')){ + input >> c >> c >> c >> i >> j >> k; + typename Base::Facet new_face(3); + new_face[0] = offset+i; + new_face[1] = offset+j; + new_face[2] = offset+k; + surface.push_back(new_face); + } else if(c == 'E'){ + break; + } + std::getline(input, s); + } + } + }; }//end GOCAD_internal @@ -912,6 +964,67 @@ write_STL(const TriangleMesh& tm, std::ostream& out) return out; } + +namespace STL_internal +{ +//Use CRTP to gain access to the protected members without getters/setters. +template +class STL_builder : public CGAL::internal::IO::Generic_facegraph_builder > +{ + typedef STL_builder Self; + typedef CGAL::internal::IO::Generic_facegraph_builder Base; + typedef typename Base::Point_3 Point_3; + typedef typename Base::Points_3 Points_3; + typedef typename Base::Facet Facet; + typedef typename Base::Surface Surface; +public: + STL_builder(std::istream& is_) + :Base(is_){} + void do_construct(Facegraph& graph) + { + typedef typename boost::graph_traits::vertex_descriptor + vertex_descriptor; + + std::vector vertices(this->meshPoints.size()); + for(std::size_t id = 0; id < this->meshPoints.size(); ++id) + { + vertices[id] = add_vertex( this->meshPoints[id], graph); + } + // graph.begin_surface( meshPoints.size(), mesh.size()); + typedef typename Points_3::size_type size_type; + + for(size_type i=0; i < this->mesh.size(); i++){ + std::array face; + face[0] = vertices[this->mesh[i][0]]; + face[1] = vertices[this->mesh[i][1]]; + face[2] = vertices[this->mesh[i][2]]; + + CGAL::Euler::add_face(face, graph); + } + } + + void + read(std::istream& input, Points_3& points, Surface& surface) + { + read_STL(input, points, surface); + } + +}; +} // end STL_internal +template +bool +read_STL(TriangleMesh& tm, std::istream& in) +{ + //typedef typename Polyhedron::HalfedgeDS HDS; + typedef typename boost::property_traits::type>::value_type Point_3; + + STL_internal::STL_builder builder(in); + builder(tm); + bool ok = in.good() || in.eof(); + ok &= tm.is_valid(); + return ok; +} + } // namespace CGAL diff --git a/BGL/test/BGL/test_bgl_read_write.cpp b/BGL/test/BGL/test_bgl_read_write.cpp index bb3811c3393..9eb69c2cc06 100644 --- a/BGL/test/BGL/test_bgl_read_write.cpp +++ b/BGL/test/BGL/test_bgl_read_write.cpp @@ -162,22 +162,65 @@ bool test_gocad() return true; } +template +bool test_STL() +{ + 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; + CGAL::write_STL(fg, out); + if(out.fail()) + { + std::cerr<<"Tetrahedron writing failed."<(filename); test_bgl_read_write(filename); test_bgl_read_write(filename); +#ifdef CGAL_USE_OPENMESH + test_bgl_read_write(filename); +#endif + //GOCAD if(!test_gocad()) return 1; if(!test_gocad()) return 1; if(!test_gocad()) return 1; -#ifdef CGAL_USE_OPENMESH - test_bgl_read_write(filename); -#endif + //STL + if(!test_STL()) + return 1; + if(!test_STL()) + return 1; + if(!test_STL()) + return 1; + //VTP #ifdef CGAL_USE_VTK if(!test_bgl_vtp()) return 1; diff --git a/Stream_support/include/CGAL/IO/GOCAD/Build_from_gocad.h b/Stream_support/include/CGAL/IO/GOCAD/Build_from_gocad.h deleted file mode 100644 index d2bb22c0821..00000000000 --- a/Stream_support/include/CGAL/IO/GOCAD/Build_from_gocad.h +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (c) 2019 GeometryFactory -// -// This file is part of CGAL (www.cgal.org); you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 3 of the License, -// or (at your option) any later version. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0+ -// -// Author(s) : Maxime Gimeno - -#ifndef CGAL_IO_GOCAD_BUILD_FROM_GOCAD_H -#define CGAL_IO_GOCAD_BUILD_FROM_GOCAD_H - -#include -#include -#include -#include -#include - -namespace CGAL{ - -namespace GOCAD_internal { -template -class Build_from_gocad -{ -protected: - typedef P Point_3; - typedef std::deque Points_3; - typedef boost::tuple Facet; - typedef std::deque Surface; - -public: - std::string name, color; - Build_from_gocad(std::istream& is_) - : is(is_), counter(0) - {} - - void do_construct(){} //specific to Facegraph (declared in BGL) - void - read(std::istream& input, Points_3& points, Surface& surface, int offset = 0) - { - char c; - std::string s, tface("TFACE"); - int i,j,k; - Point_3 p; - bool vertices_read = false; - while(input >> s){ - if(s == tface){ - break; - } - std::string::size_type idx; - - if((idx = s.find("name")) != std::string::npos){ - std::istringstream str(s.substr(idx+5)); - str >> name; - } - if((idx = s.find("color")) != std::string::npos){ - std::istringstream str(s.substr(idx+6)); - str >> color; - } - } - std::getline(input, s); - - while(input.get(c)){ - if((c == 'V')||(c == 'P')){ - input >> s >> i >> p; - if(! vertices_read){ - vertices_read = true; - offset -= i; // Some files start with index 0 others with 1 - } - - points.push_back(p); - - } else if(vertices_read && (c == 'T')){ - input >> c >> c >> c >> i >> j >> k; - surface.push_back(boost::make_tuple(offset+i, offset+j, offset+k)); - } else if(c == 'E'){ - break; - } - std::getline(input, s); - } - } - - void operator()( Facegraph& graph) - { - read(this->is, this->meshPoints, this->mesh); - static_cast(this)->do_construct(graph); - } - -protected: - std::istream& is; - int counter; - Points_3 meshPoints; - Surface mesh; -}; - - - -}//end GOCAD_internal -}//end CGAL -#endif // CGAL_IO_GOCAD_BUILD_FROM_GOCAD_H - diff --git a/Stream_support/include/CGAL/IO/STL/STL_reader.h b/Stream_support/include/CGAL/IO/STL/STL_reader.h index e4056a99c0f..f5249ae6cee 100644 --- a/Stream_support/include/CGAL/IO/STL/STL_reader.h +++ b/Stream_support/include/CGAL/IO/STL/STL_reader.h @@ -34,19 +34,22 @@ namespace CGAL { -template +template bool read_ASCII_facet(std::istream& input, - std::vector& points, - std::vector& facets, + PointRange& points, + TriangleRange& facets, int& index, - std::map& index_map, + IndexMap& index_map, bool verbose = false) { + typedef typename PointRange::value_type Point; + typedef typename TriangleRange::value_type Triangle; + // Here, we have already read the word 'facet' and are looking to read till 'endfacet' std::string s; std::string vertex("vertex"), - endfacet("endfacet"); + endfacet("endfacet"); int count = 0; double x,y,z; @@ -113,12 +116,14 @@ bool read_ASCII_facet(std::istream& input, return false; } -template +template bool parse_ASCII_STL(std::istream& input, - std::vector& points, - std::vector& facets, + PointRange& points, + TriangleRange& facets, bool verbose = false) { + typedef typename PointRange::value_type Point; + typedef typename TriangleRange::value_type Triangle; if(verbose) std::cout << "Parsing ASCII file..." << std::endl; @@ -162,12 +167,15 @@ bool parse_ASCII_STL(std::istream& input, return true; } -template +template bool parse_binary_STL(std::istream& input, - std::vector& points, - std::vector& facets, + PointRange& points, + TriangleRange& facets, bool verbose = false) { + typedef typename PointRange::value_type Point; + typedef typename TriangleRange::value_type Triangle; + if(verbose) std::cout << "Parsing binary file..." << std::endl; @@ -301,10 +309,10 @@ bool parse_binary_STL(std::istream& input, // Although the STL file format uses triangles, it is convenient to be able to use vectors // and other models of the `SequenceContainer` (instead of arrays) for the face type, // to avoid having to convert the to apply polygon soup reparation algorithms. -template +template bool read_STL(std::istream& input, - std::vector& points, - std::vector& facets, + PointRange& points, + TriangleRange& facets, bool verbose = false) { int pos = 0; diff --git a/Stream_support/include/CGAL/internal/Generic_facegraph_builder.h b/Stream_support/include/CGAL/internal/Generic_facegraph_builder.h new file mode 100644 index 00000000000..fa69b3a16a9 --- /dev/null +++ b/Stream_support/include/CGAL/internal/Generic_facegraph_builder.h @@ -0,0 +1,69 @@ +// Copyright (c) 2019 GeometryFactory +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// Author(s) : Maxime Gimeno + +#ifndef CGAL_INTERNAL_IO_GENERIC_FACEGRAPH_BUILDER_H +#define CGAL_INTERNAL_IO_GENERIC_FACEGRAPH_BUILDER_H + +#include +#include +#include +#include +#include + +namespace CGAL{ + +namespace internal { +namespace IO{ +template +class Generic_facegraph_builder +{ +protected: + typedef P Point_3; + typedef std::deque Points_3; + typedef std::vector Facet; + typedef std::deque Surface; + +public: + std::string name, color; + Generic_facegraph_builder(std::istream& is_) + : is(is_), counter(0) + {} + + void do_construct(){} //specific to Facegraph (declared in BGL) + void + read(std::istream&, Points_3&, Surface&) {} + + void operator()( Facegraph& graph) + { + static_cast(this)->read(this->is, this->meshPoints, this->mesh); + static_cast(this)->do_construct(graph); + } + +protected: + std::istream& is; + int counter; + Points_3 meshPoints; + Surface mesh; +}; + + +} //end IO +}//end internal +}//end CGAL +#endif // CGAL_INTERNAL_IO_GENERIC_FACEGRAPH_BUILDER_H From ee7e16f2a30a3a8c2031afed8681fc4bab3c2e72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Mon, 9 Sep 2019 12:45:44 +0200 Subject: [PATCH 13/28] Minor Stream_support's doc changes --- .../doc/Stream_support/IOstream.txt | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/Stream_support/doc/Stream_support/IOstream.txt b/Stream_support/doc/Stream_support/IOstream.txt index d651f21ac55..5ebf2ebcd5a 100644 --- a/Stream_support/doc/Stream_support/IOstream.txt +++ b/Stream_support/doc/Stream_support/IOstream.txt @@ -1,7 +1,7 @@ namespace CGAL { /*! -\mainpage User Manual +\mainpage User Manual \anchor Chapter_IO_Streams \anchor Chapter_operator_for_IO_streams \cgalAutoToc @@ -12,8 +12,8 @@ All classes in the \cgal kernel provide input and output operators for IO streams. Classes external to \cgal are also supported, by means of `oformat()` (Section \ref seciofornoncgaltypes "IO for Non CGAL Types"). The basic task of such an operator is to produce a representation of an object that can be written as a sequence of -characters on devices as a console, a file, or a pipe. In \cgal we distinguish between a raw ascii, a raw binary and a -pretty printing format. +characters on devices as a console, a file, or a pipe. In \cgal we distinguish between a raw ascii, +a raw binary, and a pretty printing format. \code{.cpp} enum Mode {ASCII = 0, BINARY, PRETTY}; @@ -43,7 +43,7 @@ IO::Mode set_binary_mode(std::ios& s); IO::Mode set_pretty_mode(std::ios& s); \endcode -The following functions allow to test whether a stream is in a certain mode. +The following functions enable testing whether a stream is in a certain mode. \code{.cpp} IO::Mode get_mode(std::ios& s); bool is_ascii(std::ios& s); @@ -140,7 +140,9 @@ main() \subsection IOstreamUsingOutputFormatting Using Output Formatting -To ensure that non-\cgal types are formatted correctly (i.e., respecting `IO::Mode`), `oformat()` can be used. For types with a `Output_rep` specialization, the respective output routine of `Output_rep` will be called by `oformat()`. Otherwise, the stream output operator will be called. +To ensure that non-\cgal types are formatted correctly (i.e., respecting `IO::Mode`), `oformat()` can be used. +For types with a `Output_rep` specialization, the respective output routine of `Output_rep` +will be called by `oformat()`. Otherwise, the stream output operator will be called. Example -------------- @@ -149,7 +151,7 @@ Example std::cout << CGAL::oformat( myobject ); \endcode -Optional, you can provide a second template parameter `F` as a formatting tag: +Optionally, you can provide a second template parameter `F` as a formatting tag: Example -------------- @@ -172,7 +174,7 @@ stream output operator. Instead of putting `T` directly into an output stream, `T` is wrapped into an output representation `Output_rep`. For -convenience, a function `oformat()` exists which constructs an instance +convenience, a function `oformat()` exists, which constructs an instance of `Output_rep`. If you do not specialize `Output_rep` for `T`, `T`'s @@ -234,10 +236,10 @@ and `YELLOW`. \section IOstreamStream Stream Support Three classes are provided by \cgal as adaptors to input and output stream -iterators. The class `Istream_iterator` is an input iterator adaptor and -is particularly useful for classes that are similar but not compatible to -`std::istream`. Similarly, the class `Ostream_iterator` is an output -iterator adaptor. The class `Verbose_ostream` can be used as an output +iterators. The class `Istream_iterator` is an input iterator adaptor and +is particularly useful for classes that are similar but not compatible to +`std::istream`. Similarly, the class `Ostream_iterator` is an output +iterator adaptor. The class `Verbose_ostream` can be used as an output stream. The stream output operator `<<` is defined for any type. The class stores in an internal state a stream and whether the @@ -251,7 +253,7 @@ the state is inactive, nothing happens. WKT stands for Well Known Text and it is a text markup language for representing vector geometry objects on a geographical map. See the wikipedia page for details. -CGAL supports a subset of WKT types: point, multipoint, linestring, multilinestring, polygon and multipolygon. +CGAL supports a subset of WKT types: point, multipoint, linestring, multilinestring, polygon and multipolygon. Free functions are provided for reading and writing several \cgal types in those WKT types, namely: - `CGAL::Point_2` @@ -268,14 +270,14 @@ looking like this: - - - - - + + + + + \cgalExample{Stream_support/read_xml.cpp} -*/ +*/ } /* namespace CGAL */ From 1847cb4078c2848b41c9e27ba5343870b68c6314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Mon, 9 Sep 2019 15:17:57 +0200 Subject: [PATCH 14/28] Use letters that better reflect the template parameter --- BGL/doc/BGL/PackageDescription.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BGL/doc/BGL/PackageDescription.txt b/BGL/doc/BGL/PackageDescription.txt index 287b2662399..d9bc3e5f5be 100644 --- a/BGL/doc/BGL/PackageDescription.txt +++ b/BGL/doc/BGL/PackageDescription.txt @@ -588,9 +588,9 @@ model, the properties they support, and any possible caveats that a user might encounter. - \link BGLSMGT `boost::graph_traits< CGAL::Surface_mesh

>` \endlink -- \link BGLPolyGT `boost::graph_traits< CGAL::Polyhedron_3 >` \endlink +- \link BGLPolyGT `boost::graph_traits< CGAL::Polyhedron_3 >` \endlink - \link BGLLCCGT `boost::graph_traits< CGAL::Linear_cell_complex_for_combinatorial_map<...> >` \endlink -- \link BGLSeam_meshGT `boost::graph_traits< CGAL::Seam_mesh >` \endlink +- \link BGLSeam_meshGT `boost::graph_traits< CGAL::Seam_mesh >` \endlink - \link BGLT2GT `boost::graph_traits< CGAL::Triangulation_2 >` \endlink - \link BGLArgtGT `boost::graph_traits< CGAL::Arrangement_2 >` \endlink - \link BGLOMPAK `boost::graph_traits >` \endlink From fad7f62375020a1a1de403baa132d36080f35c50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Mon, 9 Sep 2019 16:44:04 +0200 Subject: [PATCH 15/28] WIP on file formats documentation --- .../File_formats/Supported_file_formats.txt | 68 +++++++ .../doc/Stream_support/IOstream.txt | 166 +++++++++++------- 2 files changed, 175 insertions(+), 59 deletions(-) create mode 100644 Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt diff --git a/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt b/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt new file mode 100644 index 00000000000..5bfbf8c9ef7 --- /dev/null +++ b/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt @@ -0,0 +1,68 @@ +/*! + +\page IOStreamSupportedFileFormats Supported File Formats + +\cgal provides a large number of data structures and algorithms dedicated to +various applications. This page lists the various supported file formats +and the data structures offered by \cgal that may be used to read and write files of +this specific format. + +- \ref IOStreamOFF +- \ref IOStreamPLY +- \ref IOStreamSTL + +\section IOStreamOFF Object File Format (OFF) +The `OFF` file format can be used to represent collections of planar polygons with possibly shared vertices. +Although it can be as light as providing points and faces described by IDs, the format also allows +users to provide more properties such as associating normals or colors to vertices. +A precise specification of the format is available at geomview.org. + +\subsection IOStreamOFFInput Reading OFF files +Objects represented in the `.OFF` format can be imported into \cgal's working environment +using the following data structures and functions. + +[Put important remarks such as "we do not support the normal (NOFF) specification".] +[^ this should not crash if e.g. user is passing a COFF to read_OFF] +[or "Properties such as the colors or normals are not imported when calling `read_OFF()` and users +that wish to associate such properties should do blablabla (read_OFF_with_properties)."] + +- CGAL::Surface_mesh (read_OFF()), a halfedge data structure allowing to represent polyhedral surfaces +- CGAL::Polyhedron_3 (read_OFF()), a halfedge data structure, which restricts the class of representable surfaces + to orientable 2-manifolds. +- CGAL::Linear_cell_complex (read_OFF_LCC()), blablabla +- ... + +\subsection IOStreamOFFOutput Writing OFF files +The following \cgal data structures can be exported into the `OFF` file format: + +again, remarks: "Note that we do not support exporting to STOFF." + +- CGAL::Surface_mesh (write_OFF) +- CGAL::Polyhedron_3 (write_OFF) +- CGAL::Linear_cell_complex (write_OFF_LCC) +- ... + +\section IOStreamPLY Polygon File Format (PLY) +Conceived to store the data obtained during 3D scans, the `PLY` file format stores objects +as a simple list of polygons, etc. + +- CGAL::Surface_mesh, + - Input: read_PLY() + - Output: write_PLY() +- CGAL::Point_set_3, a collection of points with dynamically associated properties + - Input: + + +\section IOStreamSTL blab blabla (STL) + +\subsection IOStreamSTLInput Reading STL files +... + +\subsection IOStreamSTLOutput Writing STL files + +Note that the STL file format exports triangular faces as geometric triangles and thus +lose combinatorial information. + +\subsection etc etc + +*/ diff --git a/Stream_support/doc/Stream_support/IOstream.txt b/Stream_support/doc/Stream_support/IOstream.txt index 5ebf2ebcd5a..aa5255a966c 100644 --- a/Stream_support/doc/Stream_support/IOstream.txt +++ b/Stream_support/doc/Stream_support/IOstream.txt @@ -8,8 +8,104 @@ namespace CGAL { \authors Andreas Fabri, Geert-Jan Giezeman, Lutz Kettner, and Maxime Gimeno +\section IOstreamIntro Introduction + +CGAL algorithms and data structures are usually part of a pipeline of algorithms. +Everything is not entirely self-contained. +Need a way to import and export data to known file formats. +Can in addition enhance the existing stream system coming with the STL. + +We first explain which file formats are supported for various types of structures in CGAL. +Then we explain how to customize your stream to read and write objects that do not necessarily already +have an existing overload. + +Supported file formats are listed on the \link IOStreamSupportedFileFormats following page\endlink. + +\section IOstreamSupportedFormats Importing and Exporting Data + +CGAL algorithms work on different types of data structures, such as point sets ([link to some +point set packages]), polygon soups and polygon meshes ([link to some BGL/PMP]), and ... . + +\subsection IOstreamPolygonMeshIO Polygon Mesh IO + +TODO: +- Definition of a (3D) polygon mesh and pointer to the actual definition (make it something official in + the user manual of the BGL rather than hidden in the documentation of is_valid_polygon_mesh()). + +- Make a nicer table not using Markdown (header is not just the first line, but both the formats + and the subcategories (ascii/binary) + +- In the table below, if the READER/WRITER/BINARY etc. does not exist, put a red cross. Otherwise, + put a link to the documentation of the function. + +- Each category (OFF, STL, OBJ) in the table is a link towards a page which describes the format (see example + for OFF). + +- This table assumes that the functions in the table are BGL functions that can be used with either + Surface_mesh or Polyhedron_3. + +

+| | OFF || STL || OBJ || PLY || etc. || +| :----: | :----: | :----: | :----: | :----: | :----: | :----: | :----: | :----: | :----: | :----: | +| | ACSII | BINARY | ACSII | BINARY | ACSII | BINARY | ACSII | BINARY | ACSII | BINARY | +| Export | write_off [LINK] | | | | | | | | | | +| Import | read_off [LINK] | read_off [LINK] | | | | | | | | | +
+ +\subsection IOstreamPolygonSoupIO Polygon Soup IO +A polygon soup is a set of polygons with no global combinatorial information, etc. + +TODO, same as above + +\subsection IOstreamPointSetIO Point Set IO +Definition from the package. + +TODO, same as above + +\subsection IOstreamWKT Simple 2D Geometry IO + +`WKT` stands for Well Known Text and it is a text markup language for representing +vector geometry objects on a geographical map. See the +wikipedia page for details. +CGAL supports a subset of WKT types: point, multipoint, linestring, multilinestring, polygon and multipolygon. +Free functions are provided for reading and writing several \cgal types using these WKT types, namely: +- `CGAL::Point_2` +- `CGAL::Point_3` +- `CGAL::Polygon_with_holes_2` +- random access range of the above types. + +\subsection IOstreamOtherIO Other Data Structures + +[For data structures that have documented IO which is too specific, it should be documented +within their user manual. These structures can then be listed here, with a note pointing to +their respective IO sections in their respective user manual] + +\subsection IOstreamOther Reading Unsupported Formats + +If %CGAL does not support the file format of your data, the +`boost::property_tree` +might come in handy if your data has a simple-enough structure. +The following small example shows how to parse an XML file, +which might look as follows: + +\code{.xml} + + + + + + + + +\endcode + +\cgalExample{Stream_support/read_xml.cpp} + +\section IOstreamIO IO Streams + All classes in the \cgal kernel provide input and output operators for -IO streams. Classes external to \cgal are also supported, by means of `oformat()` (Section \ref seciofornoncgaltypes "IO for Non CGAL Types"). +IO streams. Classes external to \cgal are also supported, by means of `oformat()` +(Section \ref seciofornoncgaltypes "IO for Non CGAL Types"). The basic task of such an operator is to produce a representation of an object that can be written as a sequence of characters on devices as a console, a file, or a pipe. In \cgal we distinguish between a raw ascii, @@ -36,14 +132,13 @@ is in Ascii mode. \cgal provides the following functions to modify the mode of an IO stream. \code{.cpp} - IO::Mode set_mode(std::ios& s, IO::Mode m); IO::Mode set_ascii_mode(std::ios& s); IO::Mode set_binary_mode(std::ios& s); IO::Mode set_pretty_mode(std::ios& s); \endcode -The following functions enable testing whether a stream is in a certain mode. +The following functions enable testing whether a stream is in a certain mode: \code{.cpp} IO::Mode get_mode(std::ios& s); bool is_ascii(std::ios& s); @@ -51,13 +146,14 @@ bool is_binary(std::ios& s); bool is_pretty(std::ios& s); \endcode -\section IOstreamOutput Output Operator +\subsection IOstreamOutput Output Operator \cgal defines output operators for classes that are derived from the class `ostream`. This allows to write to ostreams as `std::cout` or `std::cerr`, as well as to `std::ostringstream` and `std::ofstream`. -The output operator is defined for all classes in the \cgal `Kernel` and for the class `Color` as well. +The output operator is defined for all classes in the \cgal `Kernel` and for the class `Color` (see +Section \ref IOstreamColors) as well. Let `os` be an output stream. \code{.cpp} @@ -65,9 +161,6 @@ Let `os` be an output stream. ostream& operator<<(ostream& os, Class c); \endcode - -\subsection IOstreamExample Example - \code{.cpp} #include #include @@ -94,7 +187,7 @@ int main() } \endcode -\section IOstreamInput Input Operator +\subsection IOstreamInput Input Operator \cgal defines input operators for classes that are derived from the class `istream`. This allows to read from istreams @@ -107,8 +200,6 @@ Let `is` be an input stream. istream& operator>>(istream& is, Class c); \endcode -\subsection IOstreamExample_1 Example - \code{.cpp} #include #include @@ -136,26 +227,19 @@ main() } \endcode -\section seciofornoncgaltypes IO for Non-CGAL Types +\subsection seciofornoncgaltypes IO for Non-CGAL Types -\subsection IOstreamUsingOutputFormatting Using Output Formatting +\subsubsection IOstreamUsingOutputFormatting Using Output Formatting To ensure that non-\cgal types are formatted correctly (i.e., respecting `IO::Mode`), `oformat()` can be used. For types with a `Output_rep` specialization, the respective output routine of `Output_rep` will be called by `oformat()`. Otherwise, the stream output operator will be called. -Example --------------- - \code{.cpp} std::cout << CGAL::oformat( myobject ); \endcode Optionally, you can provide a second template parameter `F` as a formatting tag: - -Example --------------- - \code{.cpp} std::cout << CGAL::oformat( myobject, My_formatting_tag() ); \endcode @@ -163,7 +247,7 @@ std::cout << CGAL::oformat( myobject, My_formatting_tag() ); For a list of formatting tags supported by the type `T`, please refer to the documentation of the respective type. -\subsection IOstreamCustomizingOutputFormatting Customizing Output Formatting +\subsubsection IOstreamCustomizingOutputFormatting Customizing Output Formatting In some situations, you want to control the output formatting for a type `T`. For external types (third party libraries etc.), @@ -188,9 +272,6 @@ tag). The second template parameter defaults to `Null_tag` and means For example, specializing `Output_rep` for `CORE::BigRat` (without a formatting tag parameter) could look like this: -Example --------------- - \code{.cpp} template class Output_rep< ::CORE::BigRat, F> { @@ -219,7 +300,7 @@ public: }; \endcode -\section IOstreamColors Colors +\subsection IOstreamColors Colors An object of the class `Color` is a color available for drawing operations in many \cgal output streams. @@ -231,9 +312,7 @@ There are a 11 predefined `Color` constants available: `DEEPBLUE`, `BLUE`, `PURPLE`, `VIOLET`, `ORANGE`, and `YELLOW`. - - -\section IOstreamStream Stream Support +\subsection IOstreamStream Stream Support Three classes are provided by \cgal as adaptors to input and output stream iterators. The class `Istream_iterator` is an input iterator adaptor and @@ -247,37 +326,6 @@ output is active or not. If the state is active, the stream output operator `<<` uses the internal stream to output its argument. If the state is inactive, nothing happens. - -\section IOstreamWKT WKT Support - -WKT stands for Well Known Text and it is a text markup language for representing -vector geometry objects on a geographical map. See the -wikipedia page for details. -CGAL supports a subset of WKT types: point, multipoint, linestring, multilinestring, polygon and multipolygon. -Free functions are provided for reading and writing several \cgal types -in those WKT types, namely: -- `CGAL::Point_2` -- `CGAL::Point_3` -- `CGAL::Polygon_with_holes_2` -- random access range of the above types. - -\section IOstreamXML Reading Adhoc XML - -In case you have to read data in a simple xml file with a simple structure, without existing I/O libraries -the `boost::property_tree` comes in handy. -The following small example shows how to parse a file -looking like this: - - - - - - - - - - -\cgalExample{Stream_support/read_xml.cpp} */ } /* namespace CGAL */ From 22b8e0ccb89355aa179703a4b5d50a110ab45b41 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Tue, 17 Sep 2019 14:32:40 +0200 Subject: [PATCH 16/28] Add some IO sections --- Mesh_2/doc/Mesh_2/Mesh_2.txt | 4 +++- .../Point_set_processing_3.txt | 2 ++ Polyhedron/doc/Polyhedron/Polyhedron.txt | 3 +++ .../File_formats/Supported_file_formats.txt | 3 +++ Stream_support/doc/Stream_support/IOstream.txt | 17 +++++++++++++++++ Stream_support/doc/Stream_support/dependencies | 1 + Surface_mesh/doc/Surface_mesh/Surface_mesh.txt | 3 +++ 7 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Mesh_2/doc/Mesh_2/Mesh_2.txt b/Mesh_2/doc/Mesh_2/Mesh_2.txt index 64012f69e97..3709fa6a895 100644 --- a/Mesh_2/doc/Mesh_2/Mesh_2.txt +++ b/Mesh_2/doc/Mesh_2/Mesh_2.txt @@ -327,7 +327,9 @@ in the Reference Manual. \cgalExample{Mesh_2/mesh_optimization.cpp} - +\section secMesh_2_IO Input/Output +It is possible to export the result of a meshing in VTU, using the function `write_vtu()`. +For more information about this format, see \ref IOStreamVTK. */ } /* namespace CGAL */ diff --git a/Point_set_processing_3/doc/Point_set_processing_3/Point_set_processing_3.txt b/Point_set_processing_3/doc/Point_set_processing_3/Point_set_processing_3.txt index 275ecf450fb..205dc7b8114 100644 --- a/Point_set_processing_3/doc/Point_set_processing_3/Point_set_processing_3.txt +++ b/Point_set_processing_3/doc/Point_set_processing_3/Point_set_processing_3.txt @@ -240,6 +240,8 @@ container. \cgalExample{Point_set_processing_3/read_las_example.cpp} +\sa \ref IOstreamPointSetIO + \section Point_set_processing_3Spacing Average Spacing Function `compute_average_spacing()` computes the average diff --git a/Polyhedron/doc/Polyhedron/Polyhedron.txt b/Polyhedron/doc/Polyhedron/Polyhedron.txt index c5ba15dd26b..d6c118b7a8e 100644 --- a/Polyhedron/doc/Polyhedron/Polyhedron.txt +++ b/Polyhedron/doc/Polyhedron/Polyhedron.txt @@ -363,6 +363,9 @@ restrictions on these formats. They must represent a permissible polyhedral surface, e.g., a 2-manifold and no isolated vertices, see Section \ref sectionPolyIntro. +For more information, you can see the \ref IOstreamPolygonMeshIO +section. + Some example programs around the different file formats are provided in the distribution under examples/Polyhedron_IO/ and demo/Polyhedron_IO/. We show an example converting OFF input diff --git a/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt b/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt index 5bfbf8c9ef7..17615b754a4 100644 --- a/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt +++ b/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt @@ -55,6 +55,7 @@ as a simple list of polygons, etc. \section IOStreamSTL blab blabla (STL) + \subsection IOStreamSTLInput Reading STL files ... @@ -65,4 +66,6 @@ lose combinatorial information. \subsection etc etc +\section IOStreamVTK VTK Formats (VTK VTU VTP) +blah blah */ diff --git a/Stream_support/doc/Stream_support/IOstream.txt b/Stream_support/doc/Stream_support/IOstream.txt index aa5255a966c..5645edbede4 100644 --- a/Stream_support/doc/Stream_support/IOstream.txt +++ b/Stream_support/doc/Stream_support/IOstream.txt @@ -80,6 +80,23 @@ Free functions are provided for reading and writing several \cgal types using th within their user manual. These structures can then be listed here, with a note pointing to their respective IO sections in their respective user manual] +- Alpha_shapes_3 +- Arrangement_on_surface_2 +- Boolean_set_operations_2 +- Circular_kernel_2 +- Convex_hull_2 +- \ref secMesh_2_IO for Mesh 2 +- Mesh_3 +- Nef_2 +- Nef_3 +- Poisson_surface_reconstruction_3 +- Straight_skeleton_2 +- Surface_mesher +- Triangulation +- Triangulation_2 +- Triangulation_3 + + \subsection IOstreamOther Reading Unsupported Formats If %CGAL does not support the file format of your data, the diff --git a/Stream_support/doc/Stream_support/dependencies b/Stream_support/doc/Stream_support/dependencies index 87c938201ca..1e765930d2d 100644 --- a/Stream_support/doc/Stream_support/dependencies +++ b/Stream_support/doc/Stream_support/dependencies @@ -1,4 +1,5 @@ Manual +Mesh_2 Kernel_23 STL_Extension Geomview diff --git a/Surface_mesh/doc/Surface_mesh/Surface_mesh.txt b/Surface_mesh/doc/Surface_mesh/Surface_mesh.txt index 754f49ac762..b055211bc38 100644 --- a/Surface_mesh/doc/Surface_mesh/Surface_mesh.txt +++ b/Surface_mesh/doc/Surface_mesh/Surface_mesh.txt @@ -302,6 +302,9 @@ this boils down to an identity function as vertices \em are indices. \cgalExample{Surface_mesh/sm_bgl.cpp} +\section sectionSurfaceMesh_IO Surface Mesh IO + +See the \ref IOstreamPolygonMeshIO section for more info. \section sectionSurfaceMesh_memory Memory Management From e5a0ddb7ba2fa5bed52b7efe05e472782083bcb9 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Wed, 18 Sep 2019 14:45:38 +0200 Subject: [PATCH 17/28] Add skeleton for some formats and list DS with documented IO in IOStream.txt --- .../doc/Alpha_shapes_3/Alpha_shapes_3.txt | 4 ++++ Mesh_3/doc/Mesh_3/CGAL/IO/File_avizo.h | 12 +++++++++++ Mesh_3/doc/Mesh_3/CGAL/IO/File_tetgen.h | 19 +++++++++++++++++ Mesh_3/doc/Mesh_3/Mesh_3.txt | 9 ++++++++ Mesh_3/include/CGAL/IO/File_avizo.h | 1 + Mesh_3/include/CGAL/IO/File_maya.h | 5 ----- Mesh_3/include/CGAL/IO/File_medit.h | 1 + Mesh_3/include/CGAL/IO/File_tetgen.h | 9 -------- .../File_formats/Supported_file_formats.txt | 15 ++++++++++++- .../doc/Stream_support/IOstream.txt | 21 ++++++------------- .../doc/Stream_support/dependencies | 6 ++++++ ...Complex_2_in_triangulation_3_file_writer.h | 1 + .../doc/Surface_mesher/Surface_mesher.txt | 5 +++++ .../CGAL/Triangulation_off_ostream.h | 11 ++++++++++ .../doc/Triangulation/Triangulation.txt | 5 +++++ 15 files changed, 94 insertions(+), 30 deletions(-) create mode 100644 Mesh_3/doc/Mesh_3/CGAL/IO/File_avizo.h create mode 100644 Mesh_3/doc/Mesh_3/CGAL/IO/File_tetgen.h create mode 100644 Triangulation/doc/Triangulation/CGAL/Triangulation_off_ostream.h diff --git a/Alpha_shapes_3/doc/Alpha_shapes_3/Alpha_shapes_3.txt b/Alpha_shapes_3/doc/Alpha_shapes_3/Alpha_shapes_3.txt index af4ba205b19..db529f4a991 100644 --- a/Alpha_shapes_3/doc/Alpha_shapes_3/Alpha_shapes_3.txt +++ b/Alpha_shapes_3/doc/Alpha_shapes_3/Alpha_shapes_3.txt @@ -192,6 +192,10 @@ the vertices, edges, facets and cells of the different types (`EXTERIOR`, `SINGULAR`, `REGULAR` or `INTERIOR`). +\subsection AlphaShape3DIO Input/Output +It is possible to export a 3D alpha shape to a `std::ostream` or to a `Geomview_stream` +using the `operator<<`. More information in the references of `Alpha_shape_3`. + \section AlphaShape3D_ConceptAndModels Concepts and Models We currently do not specify concepts for the underlying triangulation diff --git a/Mesh_3/doc/Mesh_3/CGAL/IO/File_avizo.h b/Mesh_3/doc/Mesh_3/CGAL/IO/File_avizo.h new file mode 100644 index 00000000000..49bc065510e --- /dev/null +++ b/Mesh_3/doc/Mesh_3/CGAL/IO/File_avizo.h @@ -0,0 +1,12 @@ +namespace CGAL{ + /** + * @brief outputs mesh to avizo format + * @param os the stream + * @param c3t3 the mesh + * \see \ref IOStreamAvizo + */ +template +void +output_to_avizo(std::ostream& os, + const C3T3& c3t3); +} diff --git a/Mesh_3/doc/Mesh_3/CGAL/IO/File_tetgen.h b/Mesh_3/doc/Mesh_3/CGAL/IO/File_tetgen.h new file mode 100644 index 00000000000..817f71555d3 --- /dev/null +++ b/Mesh_3/doc/Mesh_3/CGAL/IO/File_tetgen.h @@ -0,0 +1,19 @@ +namespace CGAL{ +/** + * \ingroup PkgMesh3IOFunctions + * @brief outputs mesh to tetgen format + * @param filename the path to the output file + * @param c3t3 the mesh + * @param rebind if true, labels of cells are rebinded into [1..nb_of_labels] + * @param show_patches if true, patches are labeled with different labels than + * cells. If false, each surface facet is written twice, using label of + * each adjacent cell. + * \see \ref IOStreamtetgen + */ +template +void +output_to_tetgen(std::string filename, + const C3T3& c3t3, + bool rebind = false, + bool show_patches = false); +} diff --git a/Mesh_3/doc/Mesh_3/Mesh_3.txt b/Mesh_3/doc/Mesh_3/Mesh_3.txt index 269b5d18e28..666e8839787 100644 --- a/Mesh_3/doc/Mesh_3/Mesh_3.txt +++ b/Mesh_3/doc/Mesh_3/Mesh_3.txt @@ -547,6 +547,15 @@ To control the number of threads used, the user may use the tbb::task_scheduler_ See the TBB documentation for more details. +\section Mesh_3_section_io Input/Output +Several formats are supported for writing a mesh: + - VTU, with `CGAL::output_to_vtu()` + - Avizo with `CGAL::output_to_avizo()` + - Medit with `CGAL::output_to_medit()` + - Tetgen with `CGAL::output_to_tetgen()` + + + \section Mesh_3_section_examples Examples \subsection Mesh_33DDomainsBoundedbyIsosurfaces 3D Domains Bounded by Isosurfaces diff --git a/Mesh_3/include/CGAL/IO/File_avizo.h b/Mesh_3/include/CGAL/IO/File_avizo.h index e5eb15f519d..132d47b85b1 100644 --- a/Mesh_3/include/CGAL/IO/File_avizo.h +++ b/Mesh_3/include/CGAL/IO/File_avizo.h @@ -155,6 +155,7 @@ output_to_avizo(std::ostream& os, * @brief outputs mesh to avizo format * @param os the stream * @param c3t3 the mesh + * \see \ref IOStreamAvizo */ template void diff --git a/Mesh_3/include/CGAL/IO/File_maya.h b/Mesh_3/include/CGAL/IO/File_maya.h index 87a43587bd1..945f9710919 100644 --- a/Mesh_3/include/CGAL/IO/File_maya.h +++ b/Mesh_3/include/CGAL/IO/File_maya.h @@ -34,11 +34,6 @@ #include namespace CGAL { - -//------------------------------------------------------- -// IO functions -//------------------------------------------------------- - template void output_to_maya(std::ostream& os, diff --git a/Mesh_3/include/CGAL/IO/File_medit.h b/Mesh_3/include/CGAL/IO/File_medit.h index 9337f8f1287..622476f97ee 100644 --- a/Mesh_3/include/CGAL/IO/File_medit.h +++ b/Mesh_3/include/CGAL/IO/File_medit.h @@ -878,6 +878,7 @@ output_to_medit(std::ostream& os, * @param show_patches if true, patches are labeled with different labels than * cells. If false, each surface facet is written twice, using label of * each adjacent cell. + * \see \ref IOStreamMedit */ template void diff --git a/Mesh_3/include/CGAL/IO/File_tetgen.h b/Mesh_3/include/CGAL/IO/File_tetgen.h index 53b9dbcc02d..73192a8cf47 100644 --- a/Mesh_3/include/CGAL/IO/File_tetgen.h +++ b/Mesh_3/include/CGAL/IO/File_tetgen.h @@ -198,15 +198,6 @@ output_to_tetgen(std::string filename, -/** - * @brief outputs mesh to tetgen format - * @param os the stream - * @param c3t3 the mesh - * @param rebind if true, labels of cells are rebinded into [1..nb_of_labels] - * @param show_patches if true, patches are labeled with different labels than - * cells. If false, each surface facet is written twice, using label of - * each adjacent cell. - */ template void output_to_tetgen(std::string filename, diff --git a/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt b/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt index 17615b754a4..54ef20473c5 100644 --- a/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt +++ b/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt @@ -67,5 +67,18 @@ lose combinatorial information. \subsection etc etc \section IOStreamVTK VTK Formats (VTK VTU VTP) -blah blah +TODO + +\section IOStreamAvizo Avizo Format +TODO + +\section IOStreamMaya Maya Format +TODO + +\section IOStreamMedit Medit Format +TODO + +\section IOStreamtetgen Tetgen Format +TODO + */ diff --git a/Stream_support/doc/Stream_support/IOstream.txt b/Stream_support/doc/Stream_support/IOstream.txt index 5645edbede4..efa863a1948 100644 --- a/Stream_support/doc/Stream_support/IOstream.txt +++ b/Stream_support/doc/Stream_support/IOstream.txt @@ -80,22 +80,13 @@ Free functions are provided for reading and writing several \cgal types using th within their user manual. These structures can then be listed here, with a note pointing to their respective IO sections in their respective user manual] -- Alpha_shapes_3 -- Arrangement_on_surface_2 -- Boolean_set_operations_2 -- Circular_kernel_2 -- Convex_hull_2 +- \ref AlphaShape3DIO for 3D Alpha Shapes. +- \ref arr_secio for 2D Arrangements - \ref secMesh_2_IO for Mesh 2 -- Mesh_3 -- Nef_2 -- Nef_3 -- Poisson_surface_reconstruction_3 -- Straight_skeleton_2 -- Surface_mesher -- Triangulation -- Triangulation_2 -- Triangulation_3 - +- \ref Mesh_3_section_io for Mesh_3 +- \ref Nef_3File for Nef_polyhedron_3 +- \ref Surface_mesherIO for 3D Surface Mesh +- \ref TriangulationSecIO for Triangulation \subsection IOstreamOther Reading Unsupported Formats diff --git a/Stream_support/doc/Stream_support/dependencies b/Stream_support/doc/Stream_support/dependencies index 1e765930d2d..4cd1cb948ac 100644 --- a/Stream_support/doc/Stream_support/dependencies +++ b/Stream_support/doc/Stream_support/dependencies @@ -1,8 +1,14 @@ +Alpha_shapes_3 +Arrangement_on_surface_2 Manual Mesh_2 +Mesh_3 +Nef_3 Kernel_23 STL_Extension Geomview Surface_mesh +Surface_mesher +Triangulation Polyhedron Polygon diff --git a/Surface_mesher/doc/Surface_mesher/CGAL/IO/Complex_2_in_triangulation_3_file_writer.h b/Surface_mesher/doc/Surface_mesher/CGAL/IO/Complex_2_in_triangulation_3_file_writer.h index 8e20411609e..1990e7decfb 100644 --- a/Surface_mesher/doc/Surface_mesher/CGAL/IO/Complex_2_in_triangulation_3_file_writer.h +++ b/Surface_mesher/doc/Surface_mesher/CGAL/IO/Complex_2_in_triangulation_3_file_writer.h @@ -20,6 +20,7 @@ In case the surface is manifold the triangles can be oriented. \returns `true` if the surface could be written to the stream. +\see \ref IOStreamOFF \sa `CGAL::output_surface_facets_to_polyhedron()` */ diff --git a/Surface_mesher/doc/Surface_mesher/Surface_mesher.txt b/Surface_mesher/doc/Surface_mesher/Surface_mesher.txt index 98298214bc4..9921831a337 100644 --- a/Surface_mesher/doc/Surface_mesher/Surface_mesher.txt +++ b/Surface_mesher/doc/Surface_mesher/Surface_mesher.txt @@ -158,6 +158,11 @@ of the traits class. This initial set of points is required to include at least one point on each connected component of the surface to be meshed. +\section Surface_mesherIO Input/Output +It is possible to output a surface mesh to the OFF format. using the function +`CGAL::output_surface_facets_to_off()`. + + \section Surface_mesherExamples Examples \anchor SurfaceMesher_section_example diff --git a/Triangulation/doc/Triangulation/CGAL/Triangulation_off_ostream.h b/Triangulation/doc/Triangulation/CGAL/Triangulation_off_ostream.h new file mode 100644 index 00000000000..2f961f88bf7 --- /dev/null +++ b/Triangulation/doc/Triangulation/CGAL/Triangulation_off_ostream.h @@ -0,0 +1,11 @@ +namespace CGAL{ +/*! + *Exports `tr` to `os` in the OFF format. + * \see \ref IOStreamOFF + */ +template < class GT, class TDS > +std::ostream & +export_triangulation_to_off(std::ostream & os, + const Triangulation & tr, + bool in_3D_export_surface_only = false); +} diff --git a/Triangulation/doc/Triangulation/Triangulation.txt b/Triangulation/doc/Triangulation/Triangulation.txt index c3cf1c75e4e..1878f88fff0 100644 --- a/Triangulation/doc/Triangulation/Triangulation.txt +++ b/Triangulation/doc/Triangulation/Triangulation.txt @@ -566,6 +566,11 @@ Performance of the insertion of 1000 points in a Delaunay triangulation. Running time wrt. number of maximal simplices, for dimensions for 2 to 12. \cgalFigureEnd +\section TriangulationSecIO Input/Output + +It is possible to export a Triangulation to the OFF format with the function +`CGAL::export_triangulation_to_off()`. + \section TriangulationSecDesign Design and Implementation History Starting with the version 2.3 of \cgal, a package written by Susan Hert and Michael Seel From 41d5f6fab0e87344bfe3fbe884a7d8cf0edffe0c Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Wed, 18 Sep 2019 16:06:28 +0200 Subject: [PATCH 18/28] WIP Supported file formats --- Mesh_3/include/CGAL/IO/File_tetgen.h | 2 +- .../File_formats/Supported_file_formats.txt | 56 ++++++++++++++++--- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/Mesh_3/include/CGAL/IO/File_tetgen.h b/Mesh_3/include/CGAL/IO/File_tetgen.h index 73192a8cf47..ff3570c366e 100644 --- a/Mesh_3/include/CGAL/IO/File_tetgen.h +++ b/Mesh_3/include/CGAL/IO/File_tetgen.h @@ -137,7 +137,7 @@ output_to_tetgen(std::string filename, // Elements //------------------------------------------------------- - std::string elem_filename = filename + ".elem"; + std::string elem_filename = filename + ".ele"; std::ofstream elem_stream(elem_filename.c_str()); elem_stream << std::setprecision(17); diff --git a/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt b/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt index 54ef20473c5..577bf797d55 100644 --- a/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt +++ b/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt @@ -10,6 +10,11 @@ this specific format. - \ref IOStreamOFF - \ref IOStreamPLY - \ref IOStreamSTL +- \ref IOStreamVTK +- \ref IOStreamAvizo +- \ref IOStreamMedit +- \ref IOStreamTetgen + \section IOStreamOFF Object File Format (OFF) The `OFF` file format can be used to represent collections of planar polygons with possibly shared vertices. @@ -67,18 +72,55 @@ lose combinatorial information. \subsection etc etc \section IOStreamVTK VTK Formats (VTK VTU VTP) -TODO +The VTK libraries use different file formats to handle data structures. +The VTU and VTP formats are XML formats specific to respectively Unstructured Grid and PolyData. +A precise specification of the format is available at + vtk.org. + +\subsection IOStreamVTKInput Reading VTK files +Objects represented in the different`.VTP` formats can be imported into \cgal's working environment +using the following data structures and functions. +- CGAL::Surface_mesh +- CGAL::Polyhedron_3 +using the function `CGAL::read_vtp()`, in the condition that CGAL has been configured +with the VTK libraries. + + +\subsection IOStreamVTKOutput Writing VTK files +The following \cgal data structures can be exported into the `.VTP` file format: +- CGAL::Surface_mesh +- CGAL::Polyhedron_3 +using the function `CGAL::write_vtp()`. +The following \cgal data structures can be exported into the `.VTU` file format: +- CGAL::Mesh_complex_3_in_triangulation_3 using `CGAL::output_to_vtu()`. +- CGAL::Constrained_Delaunay_triangulation_2 using the function `CGAL::write_vtu()` + \section IOStreamAvizo Avizo Format -TODO +The `.am` files are used by Avizo to read 3D geometry. + +\subsection IOStreamtAvizoOutput Writing Avizo files +Only the `CGAL::Mesh_complex_3_in_triangulation_3` \cgal data structure can be exported into `.am` +This can be done using the function `CGAL::output_to_avizo()` -\section IOStreamMaya Maya Format -TODO \section IOStreamMedit Medit Format -TODO +The `.mesh` Medit file format is a format used by the Medit software. In CGAL, +it is mostly used to represent 3D meshes. +A precise specification of the format is available in this report, +in the appendices (section 7.2.1, page 36). -\section IOStreamtetgen Tetgen Format -TODO +\subsection IOStreamtMeditOutput Writing Medit files +Only the `CGAL::Mesh_complex_3_in_triangulation_3` \cgal data structure can be exported into `.mesh` +This can be done using the function `CGAL::output_to_medit()` + +\section IOStreamTetgen Tetgen Format +The `Tetgen` file formatscan be used to represent lists of nodes, edges, faces, ... +A precise specification of the format is available at wias-berlin.de. + +\subsection IOStreamttegenOutput Writing Tetgen files +Only the `CGAL::Mesh_complex_3_in_triangulation_3` \cgal data structure can be exported into some of the Tetgen file formats, +naming `.node`, `.ele` and `.face` +This can be done using the function `CGAL::output_to_tegen()` */ From c8c46d6f00b3823253315c672cdcff46b412b321 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Thu, 19 Sep 2019 13:27:06 +0200 Subject: [PATCH 19/28] Finished the `Supported file formats` page --- BGL/include/CGAL/boost/graph/io.h | 30 +++++- Mesh_3/doc/Mesh_3/CGAL/IO/File_avizo.h | 5 +- Mesh_3/doc/Mesh_3/CGAL/IO/File_tetgen.h | 4 +- .../doc/Stream_support/CGAL/STL_writer.h | 19 ++++ .../File_formats/Supported_file_formats.txt | 101 ++++++++++++------ .../doc/Stream_support/PackageDescription.txt | 3 + .../doc/Stream_support/dependencies | 12 ++- .../include/CGAL/IO/STL/STL_reader.h | 20 +--- .../include/CGAL/IO/STL/STL_writer.h | 7 +- Surface_mesh/include/CGAL/Surface_mesh/IO.h | 2 - 10 files changed, 135 insertions(+), 68 deletions(-) create mode 100644 Stream_support/doc/Stream_support/CGAL/STL_writer.h diff --git a/BGL/include/CGAL/boost/graph/io.h b/BGL/include/CGAL/boost/graph/io.h index 24b022ce92d..b561b6efe9d 100644 --- a/BGL/include/CGAL/boost/graph/io.h +++ b/BGL/include/CGAL/boost/graph/io.h @@ -767,7 +767,7 @@ write_polys_points(std::ostream& os, } // end namespace CGAL::internal::write_vtp } // end namespace CGAL::internal -/*!\ingroup PkgBGLIOFct +/*! \ingroup PkgBGLIOFct * * \brief writes a triangulated surface mesh in the `PolyData` XML format. * @@ -889,6 +889,7 @@ bool vtkPointSet_to_polygon_mesh(vtkPointSet* poly_data, return true; } } //end VTK_internal + template bool read_vtp(const char* filename, FaceGraph& face_graph) { @@ -901,6 +902,27 @@ bool read_vtp(const char* filename, FaceGraph& face_graph) } #endif //CGAL_USE_VTK +#ifdef DOXYGEN_RUNNING +/*! \ingroup PkgBGLIOFct + * \brief reads a PolyData in the VTP foramt into a triangulated surface mesh. + * + * \tparam FaceGraph a model of `FaceListGraph`. + * + * \param filename the path to the file that will be read. + * \param face_graph the output mesh. + * + * \pre \cgal needs to be configured with the VTK Libraries for this function to be available. + */ +template +bool read_vtp(const char* filename, FaceGraph& face_graph); + +#endif + +/*! + \ingroup PkgBGLIOFct + writes the graph `tm` in the stream `out` in the STL format. + \pre The graph must contain only triangle faces. + */ template std::ostream& write_STL(const TriangleMesh& tm, std::ostream& out) @@ -1011,6 +1033,12 @@ public: }; } // end STL_internal + +/*! + \ingroup PkgBGLIOFct + reads the graph `tm` from the stream `in` in the STL format. + \pre The data must represent a 2-manifold + */ template bool read_STL(TriangleMesh& tm, std::istream& in) diff --git a/Mesh_3/doc/Mesh_3/CGAL/IO/File_avizo.h b/Mesh_3/doc/Mesh_3/CGAL/IO/File_avizo.h index 49bc065510e..94c1c3684a6 100644 --- a/Mesh_3/doc/Mesh_3/CGAL/IO/File_avizo.h +++ b/Mesh_3/doc/Mesh_3/CGAL/IO/File_avizo.h @@ -1,8 +1,9 @@ namespace CGAL{ - /** +/** + * \ingroup PkgMesh3IOFunctions * @brief outputs mesh to avizo format * @param os the stream - * @param c3t3 the mesh + * @param c3t3 the mesh complex * \see \ref IOStreamAvizo */ template diff --git a/Mesh_3/doc/Mesh_3/CGAL/IO/File_tetgen.h b/Mesh_3/doc/Mesh_3/CGAL/IO/File_tetgen.h index 817f71555d3..b142b41f0c7 100644 --- a/Mesh_3/doc/Mesh_3/CGAL/IO/File_tetgen.h +++ b/Mesh_3/doc/Mesh_3/CGAL/IO/File_tetgen.h @@ -1,14 +1,14 @@ namespace CGAL{ /** * \ingroup PkgMesh3IOFunctions - * @brief outputs mesh to tetgen format + * @brief outputs a mesh complex to tetgen format * @param filename the path to the output file * @param c3t3 the mesh * @param rebind if true, labels of cells are rebinded into [1..nb_of_labels] * @param show_patches if true, patches are labeled with different labels than * cells. If false, each surface facet is written twice, using label of * each adjacent cell. - * \see \ref IOStreamtetgen + * \see \ref IOStreamTetgen */ template void diff --git a/Stream_support/doc/Stream_support/CGAL/STL_writer.h b/Stream_support/doc/Stream_support/CGAL/STL_writer.h new file mode 100644 index 00000000000..edfd56da643 --- /dev/null +++ b/Stream_support/doc/Stream_support/CGAL/STL_writer.h @@ -0,0 +1,19 @@ +namespace CGAL{ +//! \ingroup IOstreamFunctions +/// Writes a soup into a file in the `.stl` format. +/// +/// \tparam PointRange must be a model of the concept `RandomAccessContainer` or a %CGAL point type +/// \tparam TriangleRange must be a model of the concept `RandomAccessContainer` +/// with a `value_type` being a model of the concept `RandomAccessContainer`, with +/// a `value_type` begin `std::size_t`. +/// +/// \param out the output stream +/// \param points a container that contains the points of the soup. +/// \param facets a container that contains the triangles of the soup +/// +template +std::ostream& +write_STL(const PointRange& points, + const TriangleRange& facets, + std::ostream& out); +} diff --git a/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt b/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt index 577bf797d55..740780196c7 100644 --- a/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt +++ b/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt @@ -26,74 +26,105 @@ A precise specification of the format is available at &, const std::string&)), a halfedge data structure allowing to represent polyhedral surfaces -- CGAL::Surface_mesh (read_OFF()), a halfedge data structure allowing to represent polyhedral surfaces -- CGAL::Polyhedron_3 (read_OFF()), a halfedge data structure, which restricts the class of representable surfaces +- CGAL::Polyhedron_3 (\ref read_off( std::istream&, Polyhedron_3&)), a halfedge data structure, which restricts the class of representable surfaces to orientable 2-manifolds. -- CGAL::Linear_cell_complex (read_OFF_LCC()), blablabla -- ... + +- Any structure that is a model of the concept `FaceGraph` (read_off(std::istream&,FaceGraph&,NamedParameters)) + +- CGAL::Point_set_3 (operator>>(std::istream&,CGAL::Point_set_3&) + +As documented in the functions above, the only property that we support is the color, +and it is only supported for the CGAL::Surface_mesh. \subsection IOStreamOFFOutput Writing OFF files The following \cgal data structures can be exported into the `OFF` file format: -again, remarks: "Note that we do not support exporting to STOFF." +- CGAL::Surface_mesh (write_off(std::ostream&, const Surface_mesh

&, const NamedParameters&)) +- Any structure that is a model of the concept `FaceGraph` (write_off(std::ostream&,const FaceGraph&,const NamedParameters&)) +- CGAL::Point_set_3 (\ref write_off_point_set()) -- CGAL::Surface_mesh (write_OFF) -- CGAL::Polyhedron_3 (write_OFF) -- CGAL::Linear_cell_complex (write_OFF_LCC) -- ... +Note that we only support OFF, and COFF for CGAL::Surface_mesh. \section IOStreamPLY Polygon File Format (PLY) Conceived to store the data obtained during 3D scans, the `PLY` file format stores objects as a simple list of polygons, etc. +A precise specification of those formats is available at + paulbourke.net. -- CGAL::Surface_mesh, - - Input: read_PLY() - - Output: write_PLY() -- CGAL::Point_set_3, a collection of points with dynamically associated properties - - Input: - +\subsection IOStreamPLYInput Reading PLY files +Objects represented in the `.PLY` format can be imported into \cgal's working environment +using the following data structures and functions. +- CGAL::Surface_mesh (read_ply()) +- CGAL::Point_set_3 (operator>>(std::istream&,CGAL::Point_set_3&) a collection of points with dynamically associated properties -\section IOStreamSTL blab blabla (STL) +\subsection IOStreamPLYOutput Writing PLY files +The following \cgal data structures can be exported into the `PLY` file format: +- CGAL::Surface_mesh (write_ply()) +- CGAL::Point_set_3 (operator<<(std::ostream&,const CGAL::Point_set_3&)) +\section IOStreamSTL Standard Triangle Language (STL) + STL is a file format native to the stereolithography CAD software created by + 3D Systems.STL files describe the surface geometry of a three-dimensional object. + A precise specification of those formats is available at + fabbers.com. + \subsection IOStreamSTLInput Reading STL files -... +Objects represented in the `.STL` format can be imported into \cgal's working environment +using any data structure that is a model of the `FaceGraph` concept, using \ref CGAL::read_STL(); + +In addition, if the data cannot be read in a `FaceGraph` because of bad orientation or +manifoldness, the function \link IOstreamFunctions `CGAL::read_STL(std::istream&,PointRange&,TriangleRange&,bool)` \endlink +allows to load data directly in a soup of triangles. From there, you can use \ref PMPRepairing +functions to construct a valid PolygonMesh. \subsection IOStreamSTLOutput Writing STL files +Similarly, any data structure that is a model of the `FaceGraph` concept can be exported +as a `.STL` file using \ref CGAL::write_STL(const TriangleMesh&, std::ostream&). + +Polygon soups can also be exported using the function \link IOstreamFunctions `CGAL::write_STL(const PointRange&,const TriangleRange&,std::ostream&)`. \endlink Note that the STL file format exports triangular faces as geometric triangles and thus lose combinatorial information. -\subsection etc etc -\section IOStreamVTK VTK Formats (VTK VTU VTP) -The VTK libraries use different file formats to handle data structures. -The VTU and VTP formats are XML formats specific to respectively Unstructured Grid and PolyData. -A precise specification of the format is available at +\section IOStreamVTK VTK Formats (VTU VTP) +The VTK libraries use different file formats to handle data structures, but we only support two: +- The `VTU` format can be used to store am unordered collection of 3D cells, like tetrahedra, + but also points, triangles, lines, ... In the VTK Libraries, + it is the format reserved to store `Unstructured Grids`, and in \cgal, + we use it to store triangulations(2D and 3D). + +- The `VTP` format can be used to store collections of points, lines and triangles. + In the VTK Libraries,it is the format + reserved to store `PolyData`., and in CGAL, we use it to store Polygon Meshes. + +A precise specification of those formats is available at vtk.org. \subsection IOStreamVTKInput Reading VTK files -Objects represented in the different`.VTP` formats can be imported into \cgal's working environment +Objects represented in the `VTP` format can be imported into \cgal's working environment using the following data structures and functions. - CGAL::Surface_mesh - CGAL::Polyhedron_3 -using the function `CGAL::read_vtp()`, in the condition that CGAL has been configured + +using the function \ref CGAL::read_vtp(), in the condition that CGAL has been configured with the VTK libraries. + \subsection IOStreamVTKOutput Writing VTK files The following \cgal data structures can be exported into the `.VTP` file format: - CGAL::Surface_mesh - CGAL::Polyhedron_3 -using the function `CGAL::write_vtp()`. + +using the function \ref CGAL::write_vtp(). + The following \cgal data structures can be exported into the `.VTU` file format: -- CGAL::Mesh_complex_3_in_triangulation_3 using `CGAL::output_to_vtu()`. -- CGAL::Constrained_Delaunay_triangulation_2 using the function `CGAL::write_vtu()` +- CGAL::Mesh_complex_3_in_triangulation_3 using \ref CGAL::output_to_vtu()`. +- CGAL::Constrained_Delaunay_triangulation_2 using the function \ref CGAL::write_vtu() \section IOStreamAvizo Avizo Format @@ -101,7 +132,7 @@ The `.am` files are used by Avizo to read 3D geometry. \subsection IOStreamtAvizoOutput Writing Avizo files Only the `CGAL::Mesh_complex_3_in_triangulation_3` \cgal data structure can be exported into `.am` -This can be done using the function `CGAL::output_to_avizo()` +This can be done using the function \ref CGAL::output_to_avizo() \section IOStreamMedit Medit Format @@ -112,15 +143,15 @@ in the appendices (section 7.2.1, page 36). \subsection IOStreamtMeditOutput Writing Medit files Only the `CGAL::Mesh_complex_3_in_triangulation_3` \cgal data structure can be exported into `.mesh` -This can be done using the function `CGAL::output_to_medit()` +This can be done using the function \ref CGAL::output_to_medit() \section IOStreamTetgen Tetgen Format The `Tetgen` file formatscan be used to represent lists of nodes, edges, faces, ... A precise specification of the format is available at wias-berlin.de. -\subsection IOStreamttegenOutput Writing Tetgen files +\subsection IOStreamTetgenOutput Writing Tetgen files Only the `CGAL::Mesh_complex_3_in_triangulation_3` \cgal data structure can be exported into some of the Tetgen file formats, naming `.node`, `.ele` and `.face` -This can be done using the function `CGAL::output_to_tegen()` +This can be done using the function \ref CGAL::output_to_tetgen() */ diff --git a/Stream_support/doc/Stream_support/PackageDescription.txt b/Stream_support/doc/Stream_support/PackageDescription.txt index 3b131dd7dc2..9d414cb39ba 100644 --- a/Stream_support/doc/Stream_support/PackageDescription.txt +++ b/Stream_support/doc/Stream_support/PackageDescription.txt @@ -1,6 +1,8 @@ /// \defgroup PkgStreamSupportRef IO Streams Reference /// \defgroup IOstreamOperators Stream Operators /// \ingroup PkgStreamSupportRef +/// \defgroup IOstreamFunctions I/O Functions +/// \ingroup PkgStreamSupportRef /*! \addtogroup PkgStreamSupportRef \cgalPkgDescriptionBegin{IO Streams,PkgStreamSupport} @@ -41,6 +43,7 @@ the printing mode. - \link IOstreamOperators `CGAL::operator<<()` \endlink - `CGAL::iformat()` - `CGAL::oformat()` +- `CGAL::read_STL()` \cgalCRPSection{WKT I/O Functions} - `CGAL::read_point_WKT()` diff --git a/Stream_support/doc/Stream_support/dependencies b/Stream_support/doc/Stream_support/dependencies index 4cd1cb948ac..3bf83e90123 100644 --- a/Stream_support/doc/Stream_support/dependencies +++ b/Stream_support/doc/Stream_support/dependencies @@ -1,14 +1,18 @@ Alpha_shapes_3 Arrangement_on_surface_2 +BGL +Geomview +Kernel_23 Manual Mesh_2 Mesh_3 Nef_3 -Kernel_23 +Polyhedron +Polygon +Polygon_mesh_processing +Point_set_3 STL_Extension -Geomview Surface_mesh Surface_mesher Triangulation -Polyhedron -Polygon +Triangulation_2 diff --git a/Stream_support/include/CGAL/IO/STL/STL_reader.h b/Stream_support/include/CGAL/IO/STL/STL_reader.h index f5249ae6cee..fecd024610d 100644 --- a/Stream_support/include/CGAL/IO/STL/STL_reader.h +++ b/Stream_support/include/CGAL/IO/STL/STL_reader.h @@ -290,25 +290,7 @@ bool parse_binary_STL(std::istream& input, return true; } -// -// Read a file with `.stl` format. -// -// \tparam Point must be a model of the concept `RandomAccessContainer` or a %CGAL point type -// \tparam Triangle must be a model of the concept `RandomAccessContainer` -// -// \param input the input stream -// \param points a container that will contain the points used in the .stl file -// \param polygons a container that will contain the triangles used in the .stl file -// \param verbose whether to enable or not a sanity log -// -// \returns `true` if the reading process went well, `false` otherwise -// -// \warning `points` and `facets` are not cleared: new points and triangles are added to the back -// of the containers. -// -// Although the STL file format uses triangles, it is convenient to be able to use vectors -// and other models of the `SequenceContainer` (instead of arrays) for the face type, -// to avoid having to convert the to apply polygon soup reparation algorithms. + template bool read_STL(std::istream& input, PointRange& points, diff --git a/Stream_support/include/CGAL/IO/STL/STL_writer.h b/Stream_support/include/CGAL/IO/STL/STL_writer.h index 3189628414b..7d7d63d8df2 100644 --- a/Stream_support/include/CGAL/IO/STL/STL_writer.h +++ b/Stream_support/include/CGAL/IO/STL/STL_writer.h @@ -29,12 +29,13 @@ namespace CGAL{ -template +template std::ostream& -write_STL(const std::vector& points, - const std::vector& facets, +write_STL(const PointRange& points, + const TriangleRange& facets, std::ostream& out) { + typedef typename PointRange::value_type Point; typedef typename CGAL::Kernel_traits::Kernel K; typedef typename K::Vector_3 Vector_3; diff --git a/Surface_mesh/include/CGAL/Surface_mesh/IO.h b/Surface_mesh/include/CGAL/Surface_mesh/IO.h index a6e6d7a24bb..27e6ab8f1c5 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/IO.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/IO.h @@ -242,7 +242,6 @@ bool read_off_ascii(Surface_mesh& mesh, } } -#if 0 /// \addtogroup PkgSurfaceMeshIO /// /// I/O functionality for `Surface_mesh`. The top-level functions @@ -263,7 +262,6 @@ bool read_off_ascii(Surface_mesh& mesh, /// /// @returns `true`, if reading succeeded, `false` otherwise /// -#endif template bool read_off(Surface_mesh& mesh, const std::string& filename) { From 78672a034df5267097726fca3505ee71169ce62f Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Thu, 19 Sep 2019 13:50:16 +0200 Subject: [PATCH 20/28] better display of other data structures --- Stream_support/doc/Stream_support/IOstream.txt | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/Stream_support/doc/Stream_support/IOstream.txt b/Stream_support/doc/Stream_support/IOstream.txt index efa863a1948..9a9071febab 100644 --- a/Stream_support/doc/Stream_support/IOstream.txt +++ b/Stream_support/doc/Stream_support/IOstream.txt @@ -76,17 +76,13 @@ Free functions are provided for reading and writing several \cgal types using th \subsection IOstreamOtherIO Other Data Structures -[For data structures that have documented IO which is too specific, it should be documented -within their user manual. These structures can then be listed here, with a note pointing to -their respective IO sections in their respective user manual] - -- \ref AlphaShape3DIO for 3D Alpha Shapes. -- \ref arr_secio for 2D Arrangements -- \ref secMesh_2_IO for Mesh 2 -- \ref Mesh_3_section_io for Mesh_3 -- \ref Nef_3File for Nef_polyhedron_3 -- \ref Surface_mesherIO for 3D Surface Mesh -- \ref TriangulationSecIO for Triangulation +- \ref AlphaShape3DIO "3D Alpha Shapes". +- \ref arr_secio "2D Arrangements" +- \ref secMesh_2_IO "2D Conforming Triangulations and Meshes" +- \ref Mesh_3_section_io "3D Mesh Generation" +- \ref Nef_3File "3D Boolean Operations on Nef Polyhedra" +- \ref Surface_mesherIO "3D Surface Mesh" +- \ref TriangulationSecIO "Triangulation" \subsection IOstreamOther Reading Unsupported Formats From c022bb2fafc260a336093a619c9f18f25ec7b61e Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Thu, 19 Sep 2019 15:59:15 +0200 Subject: [PATCH 21/28] WIP tables and missing formats --- BGL/include/CGAL/boost/graph/io.h | 75 ++++++++++++++++++- .../Polyhedron/Plugins/IO/GOCAD_io_plugin.cpp | 2 +- .../File_formats/Supported_file_formats.txt | 23 +++++- .../doc/Stream_support/IOstream.txt | 58 +++++++++----- 4 files changed, 138 insertions(+), 20 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/io.h b/BGL/include/CGAL/boost/graph/io.h index b561b6efe9d..d672f280c00 100644 --- a/BGL/include/CGAL/boost/graph/io.h +++ b/BGL/include/CGAL/boost/graph/io.h @@ -41,6 +41,7 @@ #include #include #include +#include namespace CGAL { /*! @@ -904,7 +905,7 @@ bool read_vtp(const char* filename, FaceGraph& face_graph) #ifdef DOXYGEN_RUNNING /*! \ingroup PkgBGLIOFct - * \brief reads a PolyData in the VTP foramt into a triangulated surface mesh. + * \brief reads a PolyData in the VTP format into a triangulated surface mesh. * * \tparam FaceGraph a model of `FaceListGraph`. * @@ -1053,6 +1054,78 @@ read_STL(TriangleMesh& tm, std::istream& in) return ok; } + + + + + + +namespace OBJ_internal +{ +//Use CRTP to gain access to the protected members without getters/setters. +template +class OBJ_builder : public CGAL::internal::IO::Generic_facegraph_builder > +{ + typedef OBJ_builder Self; + typedef CGAL::internal::IO::Generic_facegraph_builder Base; + typedef typename Base::Point_3 Point_3; + typedef typename Base::Points_3 Points_3; + typedef typename Base::Facet Facet; + typedef typename Base::Surface Surface; +public: + OBJ_builder(std::istream& is_) + :Base(is_){} + void do_construct(Facegraph& graph) + { + typedef typename boost::graph_traits::vertex_descriptor + vertex_descriptor; + + std::vector vertices(this->meshPoints.size()); + for(std::size_t id = 0; id < this->meshPoints.size(); ++id) + { + vertices[id] = add_vertex( this->meshPoints[id], graph); + } + // graph.begin_surface( meshPoints.size(), mesh.size()); + typedef typename Points_3::size_type size_type; + + for(size_type i=0; i < this->mesh.size(); i++){ + std::vector face; + for(std::size_t j=0; j< this->mesh[i].size(); ++j) + face[j] = vertices[this->mesh[i][j]]; + + CGAL::Euler::add_face(face, graph); + } + } + + void + read(std::istream& input, Points_3& points, Surface& surface) + { + read_OBJ(input, points, surface); + } + +}; +} // end STL_internal + +/*! + \ingroup PkgBGLIOFct + reads the graph `tm` from the stream `in` in the OBJ format. + \pre The data must represent a 2-manifold + */ +template +bool +read_OBJ(TriangleMesh& tm, std::istream& in) +{ + //typedef typename Polyhedron::HalfedgeDS HDS; + typedef typename boost::property_traits::type>::value_type Point_3; + + OBJ_internal::OBJ_builder builder(in); + builder(tm); + bool ok = in.good() || in.eof(); + ok &= tm.is_valid(); + return ok; +} + + } // namespace CGAL diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/GOCAD_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/IO/GOCAD_io_plugin.cpp index e19781bc7cc..2612aef2a89 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/GOCAD_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/GOCAD_io_plugin.cpp @@ -3,12 +3,12 @@ #include "Kernel_type.h" #include "Scene.h" #include "SMesh_type.h" -#include #include #include #include #include #include +#include #include #include diff --git a/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt b/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt index 740780196c7..d49769704d0 100644 --- a/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt +++ b/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt @@ -8,13 +8,16 @@ and the data structures offered by \cgal that may be used to read and write file this specific format. - \ref IOStreamOFF +- \ref IOStreamOBJ - \ref IOStreamPLY - \ref IOStreamSTL - \ref IOStreamVTK - \ref IOStreamAvizo - \ref IOStreamMedit - \ref IOStreamTetgen - +TODO: +GOCAD +OBJ implem \section IOStreamOFF Object File Format (OFF) The `OFF` file format can be used to represent collections of planar polygons with possibly shared vertices. @@ -47,6 +50,24 @@ The following \cgal data structures can be exported into the `OFF` file format: Note that we only support OFF, and COFF for CGAL::Surface_mesh. + +\section IOStreamOBJ Wavefront (OBJ) +The OBJ file format is a simple data-format that represents 3D geometry. +Vertices are stored in a counter-clockwise order by default, making explicit declaration of face normals unnecessary. +A precise specification of the format is available here. + +\subsection IOStreamOBJInput Reading OBJ files +Objects represented in the `.OBJ` format can be imported into \cgal's working environment +using the following data structures and functions. + +- Any structure that is a model of the concept `FaceGraph` () + +\subsection IOStreamOBJOutput Writing OBJ files +The following \cgal data structures can be exported into the `OBJ` file format: + +- Any structure that is a model of the concept `FaceGraph` (write_off(std::ostream&,const FaceGraph&,const NamedParameters&)) + + \section IOStreamPLY Polygon File Format (PLY) Conceived to store the data obtained during 3D scans, the `PLY` file format stores objects as a simple list of polygons, etc. diff --git a/Stream_support/doc/Stream_support/IOstream.txt b/Stream_support/doc/Stream_support/IOstream.txt index 9a9071febab..00ff615b0e6 100644 --- a/Stream_support/doc/Stream_support/IOstream.txt +++ b/Stream_support/doc/Stream_support/IOstream.txt @@ -23,17 +23,14 @@ Supported file formats are listed on the \link IOStreamSupportedFileFormats foll \section IOstreamSupportedFormats Importing and Exporting Data -CGAL algorithms work on different types of data structures, such as point sets ([link to some -point set packages]), polygon soups and polygon meshes ([link to some BGL/PMP]), and ... . +CGAL algorithms work on different types of data structures, such as \ref Chapter_Point_Set_3 "point sets", + \ref PolygonSoups "polygon soups" or \ref PMPDef "polygon meshes". \subsection IOstreamPolygonMeshIO Polygon Mesh IO +Basically, a Polygon Mesh is a 3D structure that refines the concept of `FaceGraph` +with some other restrictions. A more precise definition can be found \ref PMPDef "here". TODO: -- Definition of a (3D) polygon mesh and pointer to the actual definition (make it something official in - the user manual of the BGL rather than hidden in the documentation of is_valid_polygon_mesh()). - -- Make a nicer table not using Markdown (header is not just the first line, but both the formats - and the subcategories (ascii/binary) - In the table below, if the READER/WRITER/BINARY etc. does not exist, put a red cross. Otherwise, put a link to the documentation of the function. @@ -41,17 +38,44 @@ TODO: - Each category (OFF, STL, OBJ) in the table is a link towards a page which describes the format (see example for OFF). -- This table assumes that the functions in the table are BGL functions that can be used with either - Surface_mesh or Polyhedron_3. - -

-| | OFF || STL || OBJ || PLY || etc. || -| :----: | :----: | :----: | :----: | :----: | :----: | :----: | :----: | :----: | :----: | :----: | -| | ACSII | BINARY | ACSII | BINARY | ACSII | BINARY | ACSII | BINARY | ACSII | BINARY | -| Export | write_off [LINK] | | | | | | | | | | -| Import | read_off [LINK] | read_off [LINK] | | | | | | | | | -
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
OFFSTLVTPOBJ
ASCIIASCIIASCII BINARYASCII BINARY
Export\ref write_off(std::ostream&,const FaceGraph&,const NamedParameters&) "CGAL::write_off()"\ref CGAL::write_STL(const TriangleMesh&, std::ostream&) "CGAL::write_STL()"\ref CGAL::write_vtp()\ref CGAL::write_vtp()write_obj()write_obj()
Import\ref read_off(std::istream&,FaceGraph&,NamedParameters) "CGAL::read_off()"\ref CGAL::read_STL()\ref CGAL::read_vtp()\ref CGAL::read_vtp()read_obj()read_obj()
+The table above only lists the functions that work with any Polygon Mesh. +More functions are available for more specific classes, and they can be found +\link IOStreamSupportedFileFormats here\endlink. \subsection IOstreamPolygonSoupIO Polygon Soup IO A polygon soup is a set of polygons with no global combinatorial information, etc. From 01c7259d0d727dcb2cf33d692624d1f02dcf7eb8 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Tue, 24 Sep 2019 13:42:38 +0200 Subject: [PATCH 22/28] Fixing read_OBJ() --- BGL/include/CGAL/boost/graph/io.h | 16 +++++++++++++++- .../demo/Polyhedron/Scene_surface_mesh_item.cpp | 14 +++++++++----- .../File_formats/Supported_file_formats.txt | 15 ++++++++++++++- Stream_support/include/CGAL/IO/OBJ/OBJ_reader.h | 9 ++++++--- .../CGAL/internal/Generic_facegraph_builder.h | 2 +- 5 files changed, 45 insertions(+), 11 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/io.h b/BGL/include/CGAL/boost/graph/io.h index d672f280c00..d427953bc4f 100644 --- a/BGL/include/CGAL/boost/graph/io.h +++ b/BGL/include/CGAL/boost/graph/io.h @@ -500,6 +500,15 @@ public: }; }//end GOCAD_internal +/*! + \ingroup PkgBGLIOFct + reads the graph `face_graph` from data in the TS format. + `name` and `color` will be filled according to the values contained in the file. + + \pre The data must represent a 2-manifold + \attention The graph `face_graph` is not cleared, and the data from the stream are added. + \see \ref IOStreamGocad + */ template bool read_gocad(FaceGraph& face_graph, std::istream& in, std::string& name, std::string& color) @@ -515,7 +524,11 @@ read_gocad(FaceGraph& face_graph, std::istream& in, std::string& name, std::stri return in.good() && face_graph.is_valid(); } -//todo : better management of the id_map +/*! + \ingroup PkgBGLIOFct + writes the graph `face_graph` in the TS format into `os`. `name` is the + mandatory name that will be assigned to `face_graph`in the file. + */ template bool write_gocad(FaceGraph& face_graph, std::ostream& os, const std::string& name) @@ -1109,6 +1122,7 @@ public: /*! \ingroup PkgBGLIOFct reads the graph `tm` from the stream `in` in the OBJ format. + \returns `true` if the resulting mesh is valid. \pre The data must represent a 2-manifold */ template diff --git a/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp b/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp index 4b80cdaee92..277d37b3778 100644 --- a/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -1487,12 +1488,15 @@ bool Scene_surface_mesh_item::load_obj(std::istream& in) { typedef SMesh::Point Point; - std::vector points; - std::vector > faces; - bool failed = !CGAL::read_OBJ(in,points,faces); + bool failed = !CGAL::read_OBJ(*d->smesh_, in); + if(failed){ + std::vector points; + std::vector > faces; + failed = !CGAL::read_OBJ(in,points,faces); - CGAL::Polygon_mesh_processing::orient_polygon_soup(points,faces); - CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh(points,faces,*(d->smesh_)); + CGAL::Polygon_mesh_processing::orient_polygon_soup(points,faces); + CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh(points,faces,*(d->smesh_)); + } if ( (! failed) && !isEmpty() ) { invalidate(ALL); diff --git a/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt b/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt index d49769704d0..9fff7c3d5bd 100644 --- a/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt +++ b/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt @@ -15,8 +15,8 @@ this specific format. - \ref IOStreamAvizo - \ref IOStreamMedit - \ref IOStreamTetgen +- \ref IOStreamGocad TODO: -GOCAD OBJ implem \section IOStreamOFF Object File Format (OFF) @@ -175,4 +175,17 @@ A precise specification of the format is available at here. + +\subsection IOStreamGocadInput Reading Gocad files +Objects represented in the `.ts` format can be imported into \cgal's working environment +using any structure that is a model of the concept `FaceGraph`, and the function `read_gocad()`. + +\subsection IOStreamGocadOutput Writing Gocad files + Any structure that is a model of the concept `FaceGraph` can be exported into the `.ts` file format + using the function `write_gocad()` + */ diff --git a/Stream_support/include/CGAL/IO/OBJ/OBJ_reader.h b/Stream_support/include/CGAL/IO/OBJ/OBJ_reader.h index 660917d8681..c8b35d5c454 100644 --- a/Stream_support/include/CGAL/IO/OBJ/OBJ_reader.h +++ b/Stream_support/include/CGAL/IO/OBJ/OBJ_reader.h @@ -28,12 +28,15 @@ namespace CGAL { -template +//Points_3 a RandomAccessContainer of Point_3, +//Faces a RandomAccessContainer of RandomAccessContainer of std::size_t +template bool read_OBJ( std::istream& input, - std::vector &points, - std::vector > &faces) + Points_3 &points, + Faces &faces) { + typedef typename Points_3::value_type Point_3; int mini(1), maxi(-INT_MAX); Point_3 p; diff --git a/Stream_support/include/CGAL/internal/Generic_facegraph_builder.h b/Stream_support/include/CGAL/internal/Generic_facegraph_builder.h index fa69b3a16a9..95205e005f7 100644 --- a/Stream_support/include/CGAL/internal/Generic_facegraph_builder.h +++ b/Stream_support/include/CGAL/internal/Generic_facegraph_builder.h @@ -36,7 +36,7 @@ class Generic_facegraph_builder protected: typedef P Point_3; typedef std::deque Points_3; - typedef std::vector Facet; + typedef std::vector Facet; typedef std::deque Surface; public: From 0372d7713e3ddebd4ccdc9cd881a7b7d8565712f Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Tue, 24 Sep 2019 15:07:24 +0200 Subject: [PATCH 23/28] bglize the OBJ I/O --- BGL/include/CGAL/boost/graph/io.h | 49 +++++++++++++++++-- BGL/test/BGL/test_Surface_mesh.cpp | 2 +- .../Polyhedron/Scene_surface_mesh_item.cpp | 5 +- 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/io.h b/BGL/include/CGAL/boost/graph/io.h index d427953bc4f..bbfa783c843 100644 --- a/BGL/include/CGAL/boost/graph/io.h +++ b/BGL/include/CGAL/boost/graph/io.h @@ -42,6 +42,7 @@ #include #include #include +#include namespace CGAL { /*! @@ -1098,12 +1099,11 @@ public: { vertices[id] = add_vertex( this->meshPoints[id], graph); } - // graph.begin_surface( meshPoints.size(), mesh.size()); typedef typename Points_3::size_type size_type; for(size_type i=0; i < this->mesh.size(); i++){ - std::vector face; - for(std::size_t j=0; j< this->mesh[i].size(); ++j) + std::vector face(this->mesh[i].size()); + for(std::size_t j=0; j< face.size(); ++j) face[j] = vertices[this->mesh[i][j]]; CGAL::Euler::add_face(face, graph); @@ -1139,7 +1139,50 @@ read_OBJ(TriangleMesh& tm, std::istream& in) return ok; } +template +bool +write_OBJ(const FaceGraph& face_graph, std::ostream& os) +{ + // writes M to `out' in the format provided by `writer'. + CGAL::File_writer_wavefront writer; + typedef typename boost::graph_traits::vertex_iterator VCI; + typedef typename boost::graph_traits::face_iterator FCI; + typedef typename boost::property_map::type VPmap; + VPmap map = get(CGAL::vertex_point, face_graph); + // Print header. + writer.write_header( os, + num_vertices(face_graph), + num_halfedges(face_graph), + num_faces(face_graph)); + std::map::vertex_descriptor, std::size_t> index_map; + auto hint = index_map.begin(); + std::size_t id = 0; + + for( VCI vi = vertices(face_graph).begin(); vi != vertices(face_graph).end(); ++vi) { + writer.write_vertex( ::CGAL::to_double( get(map, *vi).x()), + ::CGAL::to_double( get(map, *vi).y()), + ::CGAL::to_double( get(map, *vi).z())); + + hint = index_map.insert(hint, std::make_pair(*vi, id++)); + } + + writer.write_facet_header(); + for( FCI fi = faces(face_graph).begin(); fi != faces(face_graph).end(); ++fi) { + CGAL::Halfedge_around_face_circulator hc(halfedge(*fi, face_graph), face_graph); + auto hc_end = hc; + std::size_t n = circulator_size( hc); + CGAL_assertion( n >= 3); + writer.write_facet_begin( n); + do { + writer.write_facet_vertex_index(index_map[target(*hc, face_graph)]); + ++hc; + } while( hc != hc_end); + writer.write_facet_end(); + } + writer.write_footer(); + return os.good(); +} } // namespace CGAL diff --git a/BGL/test/BGL/test_Surface_mesh.cpp b/BGL/test/BGL/test_Surface_mesh.cpp index 927f8e9c290..45490b84f79 100644 --- a/BGL/test/BGL/test_Surface_mesh.cpp +++ b/BGL/test/BGL/test_Surface_mesh.cpp @@ -7,7 +7,7 @@ BOOST_AUTO_TEST_CASE( edges_test ) edge_iterator eb, ee; vertex_iterator vb, ve; - Surface_fixture f; + Surface_fixtu re f; boost::tie(eb, ee) = edges(f.m); boost::tie(vb, ve) = vertices(f.m); BOOST_CHECK(std::distance(eb, ee) == 7); diff --git a/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp b/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp index 277d37b3778..9f0f9b7acc1 100644 --- a/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp @@ -1508,9 +1508,8 @@ Scene_surface_mesh_item::load_obj(std::istream& in) bool Scene_surface_mesh_item::save_obj(std::ostream& out) const { - CGAL::File_writer_wavefront writer; - CGAL::generic_print_surface_mesh(out, *(d->smesh_), writer); - return out.good(); + + return CGAL::write_OBJ(*d->smesh_, out); } void From e8ae9c36ebab68aaa74392ce4cda3fe766560cf7 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Tue, 24 Sep 2019 15:37:36 +0200 Subject: [PATCH 24/28] more doc --- BGL/include/CGAL/boost/graph/io.h | 18 ++++++++++++- .../File_formats/Supported_file_formats.txt | 27 ++++++++++++++----- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/io.h b/BGL/include/CGAL/boost/graph/io.h index bbfa783c843..7bba3230d86 100644 --- a/BGL/include/CGAL/boost/graph/io.h +++ b/BGL/include/CGAL/boost/graph/io.h @@ -54,6 +54,7 @@ namespace CGAL { * If this parameter is omitted, an internal property map for * `CGAL::vertex_point_t` should be available in `FaceGraph`\cgalParamEnd * \cgalNamedParamsEnd + * \see \ref IOStreamWRL */ template bool write_wrl(std::ostream& os, @@ -139,6 +140,7 @@ bool write_wrl(std::ostream& os, * \cgalNamedParamsEnd \sa Overloads of this function for specific models of the concept `FaceGraph`. + \see \ref IOStreamOFF */ template @@ -180,7 +182,7 @@ bool write_off(std::ostream& os, \ingroup PkgBGLIOFct writes the graph `g` in the OFF format into a file named `fname`. \sa Overloads of this function for specific models of the concept `FaceGraph`. - + \see \ref IOStreamOFF */ template bool write_off(const char* fname, @@ -259,6 +261,7 @@ inline std::string next_non_comment(std::istream& is) \sa Overloads of this function for specific models of the concept `FaceGraph`. \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 @@ -332,6 +335,7 @@ bool read_off(std::istream& is, \sa Overloads of this function for specific models of the concept `FaceGraph`. \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 @@ -529,6 +533,7 @@ read_gocad(FaceGraph& face_graph, std::istream& in, std::string& name, std::stri \ingroup PkgBGLIOFct writes the graph `face_graph` in the TS format into `os`. `name` is the mandatory name that will be assigned to `face_graph`in the file. + \see \ref IOStreamGocad */ template bool @@ -807,6 +812,7 @@ write_polys_points(std::ostream& os, * `CGAL::vertex_index_t` must be available in `TriangleMesh`. * \cgalParamEnd * \cgalNamedParamsEnd + * \see \ref IOStreamVTK */ template @@ -937,6 +943,7 @@ bool read_vtp(const char* filename, FaceGraph& face_graph); \ingroup PkgBGLIOFct writes the graph `tm` in the stream `out` in the STL format. \pre The graph must contain only triangle faces. + \see \ref IOStreamSTL */ template std::ostream& @@ -1052,7 +1059,9 @@ public: /*! \ingroup PkgBGLIOFct reads the graph `tm` from the stream `in` in the STL format. + \returns `true` if the resulting mesh is valid. \pre The data must represent a 2-manifold + \see \ref IOStreamSTL */ template bool @@ -1124,6 +1133,7 @@ public: reads the graph `tm` from the stream `in` in the OBJ format. \returns `true` if the resulting mesh is valid. \pre The data must represent a 2-manifold + \see \ref IOStreamOBJ */ template bool @@ -1139,6 +1149,12 @@ read_OBJ(TriangleMesh& tm, std::istream& in) return ok; } +/*! + \ingroup PkgBGLIOFct + writes the graph `face_graph` in the OBJ format. + \returns `true` if writing was successful. + \see \ref IOStreamOBJ + */ template bool write_OBJ(const FaceGraph& face_graph, std::ostream& os) diff --git a/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt b/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt index 9fff7c3d5bd..59783527e8d 100644 --- a/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt +++ b/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt @@ -16,8 +16,8 @@ this specific format. - \ref IOStreamMedit - \ref IOStreamTetgen - \ref IOStreamGocad -TODO: -OBJ implem +- \ref IOStreamOBJ +- \ref IOStreamWRL \section IOStreamOFF Object File Format (OFF) The `OFF` file format can be used to represent collections of planar polygons with possibly shared vertices. @@ -58,14 +58,13 @@ A precise specification of the format is available here. + +\subsection IOStreamtWRLOutput Writing WRL files +Any structure that is a model of the concept `FaceGraph` can be exported into the `.wrl` file format +using the `write_wrl()` function. + */ From d08a64c199d8a6c11e961a1123dc0612cde08192 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Tue, 24 Sep 2019 15:52:57 +0200 Subject: [PATCH 25/28] complete tables --- Stream_support/doc/Stream_support/IOstream.txt | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Stream_support/doc/Stream_support/IOstream.txt b/Stream_support/doc/Stream_support/IOstream.txt index 00ff615b0e6..d768b2b3366 100644 --- a/Stream_support/doc/Stream_support/IOstream.txt +++ b/Stream_support/doc/Stream_support/IOstream.txt @@ -44,14 +44,18 @@ TODO: OFF STL VTP - OBJ + OBJ + GOCAD + WRL ASCII ASCII ASCII BINARY - ASCII BINARY + BINARY + ASCII + ASCII Export @@ -59,8 +63,9 @@ TODO: \ref CGAL::write_STL(const TriangleMesh&, std::ostream&) "CGAL::write_STL()" \ref CGAL::write_vtp() \ref CGAL::write_vtp() - write_obj() - write_obj() + `write_OBJ()` + `write_gocad()` + `write_wrl()` Import @@ -68,8 +73,9 @@ TODO: \ref CGAL::read_STL() \ref CGAL::read_vtp() \ref CGAL::read_vtp() - read_obj() - read_obj() + `read_OBJ()` + `read_gocad()` + From 5a03f5d7c73f82f5f421f0d329bdd55718f15241 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Wed, 25 Sep 2019 15:52:18 +0200 Subject: [PATCH 26/28] Continue working on the table --- .../doc/resources/1.8.13/stylesheet.css | 41 ++++++++++++++- .../doc/resources/1.8.14/stylesheet.css | 39 ++++++++++++++- .../doc/resources/1.8.4/stylesheet.css | 37 ++++++++++++++ .../doc/Stream_support/CGAL/IO/OFF.h | 24 +++++++++ .../doc/Stream_support/CGAL/IO/STL_reader.h | 28 +++++++++++ .../Stream_support/CGAL/{ => IO}/STL_writer.h | 4 +- .../doc/Stream_support/IOstream.txt | 50 +++++++++++++------ Stream_support/include/CGAL/IO/OFF.h | 38 +++++++++++++- .../test/Stream_support/data/cube.off | 22 ++++++++ .../Stream_support/test_read_write_OFF.cpp | 25 ++++++++++ 10 files changed, 285 insertions(+), 23 deletions(-) create mode 100644 Stream_support/doc/Stream_support/CGAL/IO/OFF.h create mode 100644 Stream_support/doc/Stream_support/CGAL/IO/STL_reader.h rename Stream_support/doc/Stream_support/CGAL/{ => IO}/STL_writer.h (86%) create mode 100644 Stream_support/test/Stream_support/data/cube.off create mode 100644 Stream_support/test/Stream_support/test_read_write_OFF.cpp diff --git a/Documentation/doc/resources/1.8.13/stylesheet.css b/Documentation/doc/resources/1.8.13/stylesheet.css index 4f1ab9195b4..6e884a89edc 100644 --- a/Documentation/doc/resources/1.8.13/stylesheet.css +++ b/Documentation/doc/resources/1.8.13/stylesheet.css @@ -150,11 +150,11 @@ a.elRef { } a.code, a.code:visited, a.line, a.line:visited { - color: #4665A2; + color: #4665A2; } a.codeRef, a.codeRef:visited, a.lineRef, a.lineRef:visited { - color: #4665A2; + color: #4665A2; } /* @end */ @@ -896,6 +896,42 @@ table.doxtable th { padding-top: 5px; } +table.iotable caption { + caption-side: top; +} + +table.iotable { + border-collapse:collapse; + margin-top: 4px; + margin-bottom: 4px; +} + +table.iotable td, table.iotable th { + border: 1px solid #2D4068; + padding: 3px 7px 2px; +} + +table.iotable th a,table.iotable th a:visited { +color: #FFFFFF; +text-decoration: underline; +} + +table.iotable th { + background-color: #374F7F; + color: #FFFFFF; + font-size: 110%; + padding-bottom: 4px; + padding-top: 5px; +} + + +table.iotable th a, table.iotable th a:visited { + +font-weight: bold; +color: #FFFFFF; +text-decoration: underline; +} + table.fieldtable { /*width: 100%;*/ margin-bottom: 10px; @@ -909,6 +945,7 @@ table.fieldtable { box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.15); } + .fieldtable td, .fieldtable th { padding: 3px 7px 2px; } diff --git a/Documentation/doc/resources/1.8.14/stylesheet.css b/Documentation/doc/resources/1.8.14/stylesheet.css index 4f1ab9195b4..3831f9f051f 100644 --- a/Documentation/doc/resources/1.8.14/stylesheet.css +++ b/Documentation/doc/resources/1.8.14/stylesheet.css @@ -154,7 +154,7 @@ a.code, a.code:visited, a.line, a.line:visited { } a.codeRef, a.codeRef:visited, a.lineRef, a.lineRef:visited { - color: #4665A2; + color: #4665A2; } /* @end */ @@ -896,6 +896,43 @@ table.doxtable th { padding-top: 5px; } +table.iotable caption { + caption-side: top; +} + +table.iotable { + border-collapse:collapse; + margin-top: 4px; + margin-bottom: 4px; +} + +table.iotable td, table.iotable th { + border: 1px solid #2D4068; + padding: 3px 7px 2px; +} + +table.iotable th a,table.iotable th a:visited { +color: #FFFFFF; +text-decoration: underline; +} + +table.iotable th { + background-color: #374F7F; + color: #FFFFFF; + font-size: 110%; + padding-bottom: 4px; + padding-top: 5px; +} + + +table.iotable th a, table.iotable th a:visited { + +font-weight: bold; +color: #FFFFFF; +text-decoration: underline; +} + + table.fieldtable { /*width: 100%;*/ margin-bottom: 10px; diff --git a/Documentation/doc/resources/1.8.4/stylesheet.css b/Documentation/doc/resources/1.8.4/stylesheet.css index dc14a84c031..94cf9752917 100644 --- a/Documentation/doc/resources/1.8.4/stylesheet.css +++ b/Documentation/doc/resources/1.8.4/stylesheet.css @@ -762,6 +762,43 @@ table.doxtable th { padding-top: 5px; } +table.iotable caption { + caption-side: top; +} + +table.iotable { + border-collapse:collapse; + margin-top: 4px; + margin-bottom: 4px; +} + +table.iotable td, table.iotable th { + border: 1px solid #2D4068; + padding: 3px 7px 2px; +} + +table.iotable th a,table.iotable th a:visited { +color: #FFFFFF; +text-decoration: underline; +} + +table.iotable th { + background-color: #374F7F; + color: #FFFFFF; + font-size: 110%; + padding-bottom: 4px; + padding-top: 5px; +} + + +table.iotable th a, table.iotable th a:visited { + +font-weight: bold; +color: #FFFFFF; +text-decoration: underline; +} + + table.fieldtable { width: 100%; margin-bottom: 10px; diff --git a/Stream_support/doc/Stream_support/CGAL/IO/OFF.h b/Stream_support/doc/Stream_support/CGAL/IO/OFF.h new file mode 100644 index 00000000000..fe2380d340d --- /dev/null +++ b/Stream_support/doc/Stream_support/CGAL/IO/OFF.h @@ -0,0 +1,24 @@ +namespace CGAL{ +/*! + * \ingroup IOstreamFunctions + * writes the content of `in` in `points` and `polygons`, in the OFF format. + * \see \ref IOStreamOFF + */ +template +bool +read_OFF( std::istream& in, + std::vector< Point_3 >& points, + std::vector< Polygon_3 >& polygons, + bool /* verbose */ = false); + +/*! + * \ingroup IOstreamFunctions + * writes the content of `points` and `polygons` in `out`, in the OFF format. + * \see \ref IOStreamOFF + */ +template +bool +write_OFF(std::ostream& out, + std::vector< Point_3 >& points, + std::vector< Polygon_3 >& polygons); +} diff --git a/Stream_support/doc/Stream_support/CGAL/IO/STL_reader.h b/Stream_support/doc/Stream_support/CGAL/IO/STL_reader.h new file mode 100644 index 00000000000..a6d49380c9d --- /dev/null +++ b/Stream_support/doc/Stream_support/CGAL/IO/STL_reader.h @@ -0,0 +1,28 @@ +namespace CGAL{ +//! \ingroup IOstreamFunctions +/// Reads a file with `.stl` format. +/// +/// \tparam PointRange must be a model of the concept `RandomAccessContainer` or a %CGAL point type +/// \tparam TriangleRange must be a model of the concept `RandomAccessContainer` +/// with a `value_type` being a model of the concept `RandomAccessContainer`, with +/// a `value_type` begin `std::size_t`. +/// +/// \param input the input stream +/// \param points a container that will contain the points used in the .stl file +/// \param facets a container that will contain the triangles used in the .stl file +/// \param verbose whether to enable or not a sanity log +/// +/// \returns `true` if the reading process went well, `false` otherwise +/// +/// \warning `points` and `facets` are not cleared: new points and triangles are added to the back +/// of the containers. +/// +/// Although the STL file format uses triangles, it is convenient to be able to use vectors +/// and other models of the `SequenceContainer` (instead of arrays) for the face type, +/// to avoid having to convert the to apply polygon soup reparation algorithms. +template +bool read_STL(std::istream& input, + PointRange& points, + TriangleRange& facets, + bool verbose = false); +} diff --git a/Stream_support/doc/Stream_support/CGAL/STL_writer.h b/Stream_support/doc/Stream_support/CGAL/IO/STL_writer.h similarity index 86% rename from Stream_support/doc/Stream_support/CGAL/STL_writer.h rename to Stream_support/doc/Stream_support/CGAL/IO/STL_writer.h index edfd56da643..369ac7ee67a 100644 --- a/Stream_support/doc/Stream_support/CGAL/STL_writer.h +++ b/Stream_support/doc/Stream_support/CGAL/IO/STL_writer.h @@ -13,7 +13,5 @@ namespace CGAL{ /// template std::ostream& -write_STL(const PointRange& points, - const TriangleRange& facets, - std::ostream& out); +write_STL(const PointRange& points, const TriangleRange& facets, std::ostream& out); } diff --git a/Stream_support/doc/Stream_support/IOstream.txt b/Stream_support/doc/Stream_support/IOstream.txt index d768b2b3366..0a291717a23 100644 --- a/Stream_support/doc/Stream_support/IOstream.txt +++ b/Stream_support/doc/Stream_support/IOstream.txt @@ -30,23 +30,15 @@ CGAL algorithms work on different types of data structures, such as \ref Chapter Basically, a Polygon Mesh is a 3D structure that refines the concept of `FaceGraph` with some other restrictions. A more precise definition can be found \ref PMPDef "here". -TODO: - -- In the table below, if the READER/WRITER/BINARY etc. does not exist, put a red cross. Otherwise, - put a link to the documentation of the function. - -- Each category (OFF, STL, OBJ) in the table is a link towards a page which describes the format (see example - for OFF). - - +
- - - - - - + + + + + + @@ -87,6 +79,34 @@ A polygon soup is a set of polygons with no global combinatorial information, et TODO, same as above +
OFFSTLVTPOBJGOCADWRL\ref IOStreamOFF "OFF"\ref IOStreamSTL "STL"\ref IOStreamVTK "VTP"\ref IOStreamOBJ "OBJ"\ref IOStreamGocad "GOCAD"\ref IOStreamWRL "WRL"
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
\ref IOStreamOFF "OFF"\ref IOStreamSTL "STL"\ref IOStreamVTK "VTP"\ref IOStreamOBJ "OBJ"\ref IOStreamWRL "WRL"
ASCIIASCIIASCII BINARYBINARYASCII
Exportwrite_OFF() \ref IOstreamFunctions "write_STL()"
Importread_OFF()\ref IOstreamFunctions "read_STL()"
\subsection IOstreamPointSetIO Point Set IO Definition from the package. diff --git a/Stream_support/include/CGAL/IO/OFF.h b/Stream_support/include/CGAL/IO/OFF.h index 25d50a96444..71dcc7ceb7e 100644 --- a/Stream_support/include/CGAL/IO/OFF.h +++ b/Stream_support/include/CGAL/IO/OFF.h @@ -21,8 +21,9 @@ #define CGAL_IO_OFF_H #include -#include +#include #include +#include #include #include @@ -31,7 +32,6 @@ #include namespace CGAL { - template bool read_OFF( std::istream& in, @@ -54,6 +54,40 @@ read_OFF( std::istream& in, return OFF_internal::read_OFF(in, points, polygons, fcolors, vcolors); } +template +bool +write_OFF(std::ostream& out, + std::vector< Point_3 >& points, + std::vector< Polygon_3 >& polygons) +{ + CGAL::File_writer_OFF writer; + writer.write_header(out, + points.size(), + 0, + polygons.size()); + for(std::size_t i = 0, end = points.size(); + i < end; ++i) + { + const Point_3& p = points[i]; + writer.write_vertex( p.x(), p.y(), p.z() ); + } + writer.write_facet_header(); + for(std::size_t i = 0, end = polygons.size(); + i < end; ++i) + { + Polygon_3& polygon = polygons[i]; + const std::size_t size = polygon.size(); + writer.write_facet_begin(size); + for(std::size_t j = 0; j < size; ++j) { + writer.write_facet_vertex_index(polygon[j]); + } + writer.write_facet_end(); + } + writer.write_footer(); + + return (bool) out; +} + } // namespace CGAL #endif // CGAL_IO_OFF_H diff --git a/Stream_support/test/Stream_support/data/cube.off b/Stream_support/test/Stream_support/data/cube.off new file mode 100644 index 00000000000..b1afa5a6858 --- /dev/null +++ b/Stream_support/test/Stream_support/data/cube.off @@ -0,0 +1,22 @@ +OFF +8 12 0 +-1 -1 -1 +-1 1 -1 +1 1 -1 +1 -1 -1 +-1 -1 1 +-1 1 1 +1 1 1 +1 -1 1 +3 0 1 3 +3 3 1 2 +3 0 4 1 +3 1 4 5 +3 3 2 7 +3 7 2 6 +3 4 0 3 +3 7 4 3 +3 6 4 7 +3 6 5 4 +3 1 5 6 +3 2 1 6 diff --git a/Stream_support/test/Stream_support/test_read_write_OFF.cpp b/Stream_support/test/Stream_support/test_read_write_OFF.cpp new file mode 100644 index 00000000000..c0c935dd363 --- /dev/null +++ b/Stream_support/test/Stream_support/test_read_write_OFF.cpp @@ -0,0 +1,25 @@ +#include +#include + +#include + +#include +#include + +typedef CGAL::Simple_cartesian Kernel; +typedef Kernel::Point_3 Point; +typedef std::vector Face; +int main() +{ + std::ifstream in("data/cube.off"); + std::vector points; + std::vector faces; + CGAL::read_OFF(in, points, faces); + in.close(); + assert(points.size() == 8); + assert(faces.size() == 12); + + assert(CGAL::write_OFF(std::cout, points, faces)); + + return 0; +} From 38b6923cac49e8eac582b5cafeb2b11bb129c0b9 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Thu, 26 Sep 2019 14:16:22 +0200 Subject: [PATCH 27/28] Finished ? --- .../Stream_support/CGAL/IO/OBJ/OBJ_reader.h | 11 +++ .../doc/Stream_support/CGAL/IO/STL_reader.h | 28 ------- .../doc/Stream_support/CGAL/IO/STL_writer.h | 17 ---- .../File_formats/Supported_file_formats.txt | 22 ++++- .../doc/Stream_support/IOstream.txt | 81 +++++++++++++++---- 5 files changed, 97 insertions(+), 62 deletions(-) create mode 100644 Stream_support/doc/Stream_support/CGAL/IO/OBJ/OBJ_reader.h delete mode 100644 Stream_support/doc/Stream_support/CGAL/IO/STL_reader.h delete mode 100644 Stream_support/doc/Stream_support/CGAL/IO/STL_writer.h diff --git a/Stream_support/doc/Stream_support/CGAL/IO/OBJ/OBJ_reader.h b/Stream_support/doc/Stream_support/CGAL/IO/OBJ/OBJ_reader.h new file mode 100644 index 00000000000..d1fb46c8981 --- /dev/null +++ b/Stream_support/doc/Stream_support/CGAL/IO/OBJ/OBJ_reader.h @@ -0,0 +1,11 @@ +namespace CGAL { + +//! \ingroup IOstreamFunctions +///reads a file in .obj format. +///\tparam Points_3 a RandomAccessContainer of Point_3, +///\tparam Faces a RandomAccessContainer of RandomAccessContainer of std::size_t +/// \see IOStreamOBJ +template +bool +read_OBJ(std::istream& input, Points_3 &points, Faces &faces); +} diff --git a/Stream_support/doc/Stream_support/CGAL/IO/STL_reader.h b/Stream_support/doc/Stream_support/CGAL/IO/STL_reader.h deleted file mode 100644 index a6d49380c9d..00000000000 --- a/Stream_support/doc/Stream_support/CGAL/IO/STL_reader.h +++ /dev/null @@ -1,28 +0,0 @@ -namespace CGAL{ -//! \ingroup IOstreamFunctions -/// Reads a file with `.stl` format. -/// -/// \tparam PointRange must be a model of the concept `RandomAccessContainer` or a %CGAL point type -/// \tparam TriangleRange must be a model of the concept `RandomAccessContainer` -/// with a `value_type` being a model of the concept `RandomAccessContainer`, with -/// a `value_type` begin `std::size_t`. -/// -/// \param input the input stream -/// \param points a container that will contain the points used in the .stl file -/// \param facets a container that will contain the triangles used in the .stl file -/// \param verbose whether to enable or not a sanity log -/// -/// \returns `true` if the reading process went well, `false` otherwise -/// -/// \warning `points` and `facets` are not cleared: new points and triangles are added to the back -/// of the containers. -/// -/// Although the STL file format uses triangles, it is convenient to be able to use vectors -/// and other models of the `SequenceContainer` (instead of arrays) for the face type, -/// to avoid having to convert the to apply polygon soup reparation algorithms. -template -bool read_STL(std::istream& input, - PointRange& points, - TriangleRange& facets, - bool verbose = false); -} diff --git a/Stream_support/doc/Stream_support/CGAL/IO/STL_writer.h b/Stream_support/doc/Stream_support/CGAL/IO/STL_writer.h deleted file mode 100644 index 369ac7ee67a..00000000000 --- a/Stream_support/doc/Stream_support/CGAL/IO/STL_writer.h +++ /dev/null @@ -1,17 +0,0 @@ -namespace CGAL{ -//! \ingroup IOstreamFunctions -/// Writes a soup into a file in the `.stl` format. -/// -/// \tparam PointRange must be a model of the concept `RandomAccessContainer` or a %CGAL point type -/// \tparam TriangleRange must be a model of the concept `RandomAccessContainer` -/// with a `value_type` being a model of the concept `RandomAccessContainer`, with -/// a `value_type` begin `std::size_t`. -/// -/// \param out the output stream -/// \param points a container that contains the points of the soup. -/// \param facets a container that contains the triangles of the soup -/// -template -std::ostream& -write_STL(const PointRange& points, const TriangleRange& facets, std::ostream& out); -} diff --git a/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt b/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt index 59783527e8d..0265dd4709c 100644 --- a/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt +++ b/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt @@ -11,12 +11,12 @@ this specific format. - \ref IOStreamOBJ - \ref IOStreamPLY - \ref IOStreamSTL +- \ref IOStreamXYZ - \ref IOStreamVTK - \ref IOStreamAvizo - \ref IOStreamMedit - \ref IOStreamTetgen - \ref IOStreamGocad -- \ref IOStreamOBJ - \ref IOStreamWRL \section IOStreamOFF Object File Format (OFF) @@ -38,6 +38,8 @@ using the following data structures and functions. - CGAL::Point_set_3 (operator>>(std::istream&,CGAL::Point_set_3&) +Polygon soups can also be imported using the function read_OFF(). + As documented in the functions above, the only property that we support is the color, and it is only supported for the CGAL::Surface_mesh. @@ -48,6 +50,7 @@ The following \cgal data structures can be exported into the `OFF` file format: - Any structure that is a model of the concept `FaceGraph` (write_off(std::ostream&,const FaceGraph&,const NamedParameters&)) - CGAL::Point_set_3 (\ref write_off_point_set()) +Polygon soups can also be exported using the function write_OFF(). Note that we only support OFF, and COFF for CGAL::Surface_mesh. @@ -60,7 +63,7 @@ A precise specification of the format is available >(std::istream&,CGAL::Point_set_3&) a collection of points with dynamically associated properties +- CGAL::Point_set_3 (operator>>(std::istream&,CGAL::Point_set_3&))a collection of points with dynamically associated properties \subsection IOStreamPLYOutput Writing PLY files The following \cgal data structures can be exported into the `PLY` file format: @@ -109,6 +112,19 @@ Polygon soups can also be exported using the function \link IOstreamFunctions `C Note that the STL file format exports triangular faces as geometric triangles and thus lose combinatorial information. +\section IOStreamXYZ XYZ (or PWN) +The `XYZ` format is a non standard format regularly used to described point sets. +each line represent a point, and is composed of its coordinates and other properties. +We only support coordinates and normals (in that case the standard extension in CGAL +is .pwn for points with normals.) + +\subsection IOStreamZYZInput Reading XYZ files +Objects represented in the `.XYZ` or `.PWN` format can be imported into \cgal's working environment +using the CGAL::Point_set_3 and the function read_xyz_point_set(). + +\subsection IOStreamXYZOutput Writing XYZ files +The CGAL::Point_set_3 can be exported into a `XYZ` or a `PWN` file using the function +write_xyz_point_set(). \section IOStreamVTK VTK Formats (VTU VTP) The VTK libraries use different file formats to handle data structures, but we only support two: diff --git a/Stream_support/doc/Stream_support/IOstream.txt b/Stream_support/doc/Stream_support/IOstream.txt index 0a291717a23..ed09e42f9c2 100644 --- a/Stream_support/doc/Stream_support/IOstream.txt +++ b/Stream_support/doc/Stream_support/IOstream.txt @@ -67,7 +67,7 @@ with some other restrictions. A more precise definition can be found \ref PMPDef \ref CGAL::read_vtp() `read_OBJ()` `read_gocad()` - + n/a @@ -75,42 +75,67 @@ The table above only lists the functions that work with any Polygon Mesh. More functions are available for more specific classes, and they can be found \link IOStreamSupportedFileFormats here\endlink. \subsection IOstreamPolygonSoupIO Polygon Soup IO -A polygon soup is a set of polygons with no global combinatorial information, etc. - -TODO, same as above +A polygon soup is a set of polygons with no global combinatorial information, +stored in a two containers: one storing the points, and the other one storing +their indices per face (i.e a vector of 3 integers represent a triangle face). - - + + + + + + + + + + + + + + + + + + + +
\ref IOStreamOFF "OFF" \ref IOStreamSTL "STL"\ref IOStreamVTK "VTP" \ref IOStreamOBJ "OBJ"\ref IOStreamWRL "WRL"
ASCIIASCIIBINARY
Exportwrite_OFF() \ref IOstreamFunctions "write_STL()" n/a
Importread_OFF()\ref IOstreamFunctions "read_STL()"\ref IOstreamFunctions "read_OBJ()"
+\subsection IOstreamPointSetIO Point Set IO +The CGAL::Point_set_3 is a vector based data structure that contains +a default property (named point) for the coordinates of the points, +and is able to work with dynamic properties. + + + + + + + - - - + + - + +
\ref IOStreamOFF "OFF"\ref IOStreamXYZ "XYZ"\ref IOStreamPLY "PLY"
ASCII ASCII ASCII BINARYBINARYASCII
Export write_OFF() \ref IOstreamFunctions "write_STL()" write_xyz_point_set()operator<<(std::ostream&,const CGAL::Point_set_3&)write_ply_point_set()
Import read_OFF()\ref IOstreamFunctions "read_STL()"read_xyz_point_set()operator>>(std::istream&,CGAL::Point_set_3&)operator>>(std::istream&,CGAL::Point_set_3&)
-\subsection IOstreamPointSetIO Point Set IO -Definition from the package. - -TODO, same as above \subsection IOstreamWKT Simple 2D Geometry IO @@ -124,6 +149,34 @@ Free functions are provided for reading and writing several \cgal types using th - `CGAL::Polygon_with_holes_2` - random access range of the above types. +You can find more information about WKT \ref PkgStreamSupportRef "here", but +here is a table to summarize the most useful functions : + + + + + + + + + + + + + + + + + + + + + + + + +
PointsPolylinesPolygonsEverything
Importread_multi_point_WKT()read_multi_linestring_WKT()read_multi_polygon_WKT()read_WKT()
Exportwrite_multi_point_WKT()write_multi_linestring_WKT()write_multi_polygon_WKT()n/a
+ \subsection IOstreamOtherIO Other Data Structures - \ref AlphaShape3DIO "3D Alpha Shapes". From 80b7a5575cf6c7bb178d050919fd911b61c6a186 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Fri, 27 Sep 2019 10:35:39 +0200 Subject: [PATCH 28/28] Empty Polyhedron_IO. --- .../examples/Polyhedron}/iv2off.cin | 0 .../examples/Polyhedron}/iv2off.cpp | 0 .../examples/Polyhedron}/off2iv.cin | 0 .../examples/Polyhedron}/off2iv.cpp | 0 .../examples/Polyhedron}/off2off.cin | 0 .../examples/Polyhedron}/off2off.cpp | 0 .../examples/Polyhedron}/off2stl.cin | 0 .../examples/Polyhedron}/off2stl.cpp | 0 .../examples/Polyhedron}/off2vrml.cin | 0 .../examples/Polyhedron}/off2vrml.cpp | 0 .../examples/Polyhedron}/off2wav.cin | 0 .../examples/Polyhedron}/off2wav.cpp | 0 .../examples/Polyhedron}/off_bbox.cin | 0 .../examples/Polyhedron}/off_bbox.cpp | 0 .../examples/Polyhedron}/off_glue.cin | 0 .../examples/Polyhedron}/off_glue.cpp | 0 .../examples/Polyhedron}/off_transform.cin | 0 .../examples/Polyhedron}/off_transform.cpp | 0 .../examples/Polyhedron}/polyhedron2vrml.cin | 0 .../examples/Polyhedron}/polyhedron2vrml.cpp | 0 .../examples/Polyhedron}/polyhedron_copy.cin | 0 .../examples/Polyhedron}/polyhedron_copy.cpp | 0 .../Polyhedron}/data/ascii-tetrahedron.stl | 0 .../data/binary-tetrahedron-nice-header.stl | Bin ...nary-tetrahedron-non-standard-header-1.stl | Bin ...nary-tetrahedron-non-standard-header-2.stl | Bin ...nary-tetrahedron-non-standard-header-3.stl | Bin ...nary-tetrahedron-non-standard-header-4.stl | Bin ...nary-tetrahedron-non-standard-header-5.stl | Bin .../test/Polyhedron}/data/cube.stl | Bin .../test/Polyhedron}/data/triangle.stl | 0 .../test/Polyhedron}/stl2off.cpp | 0 .../test/Polyhedron}/test_polyhedron_io.cpp | 0 .../demo/Polyhedron_IO/CMakeLists.txt | 27 -- Polyhedron_IO/demo/Polyhedron_IO/README | 18 - .../demo/Polyhedron_IO/geomview_demo.cpp | 58 --- .../demo/Polyhedron_IO/viewpoint2off.cpp | 357 ------------------ .../examples/Polyhedron_IO/CMakeLists.txt | 24 -- .../test/Polyhedron_IO/CMakeLists.txt | 24 -- .../include/CGAL/IO/STL/STL_reader.h | 11 +- .../examples/Triangulation_2}/terr_trian.cin | 0 .../examples/Triangulation_2}/terr_trian.cpp | 0 .../triangulation_print_OFF.h | 0 43 files changed, 7 insertions(+), 512 deletions(-) rename {Polyhedron_IO/examples/Polyhedron_IO => Polyhedron/examples/Polyhedron}/iv2off.cin (100%) rename {Polyhedron_IO/examples/Polyhedron_IO => Polyhedron/examples/Polyhedron}/iv2off.cpp (100%) rename {Polyhedron_IO/examples/Polyhedron_IO => Polyhedron/examples/Polyhedron}/off2iv.cin (100%) rename {Polyhedron_IO/examples/Polyhedron_IO => Polyhedron/examples/Polyhedron}/off2iv.cpp (100%) rename {Polyhedron_IO/examples/Polyhedron_IO => Polyhedron/examples/Polyhedron}/off2off.cin (100%) rename {Polyhedron_IO/examples/Polyhedron_IO => Polyhedron/examples/Polyhedron}/off2off.cpp (100%) rename {Polyhedron_IO/examples/Polyhedron_IO => Polyhedron/examples/Polyhedron}/off2stl.cin (100%) rename {Polyhedron_IO/examples/Polyhedron_IO => Polyhedron/examples/Polyhedron}/off2stl.cpp (100%) rename {Polyhedron_IO/examples/Polyhedron_IO => Polyhedron/examples/Polyhedron}/off2vrml.cin (100%) rename {Polyhedron_IO/examples/Polyhedron_IO => Polyhedron/examples/Polyhedron}/off2vrml.cpp (100%) rename {Polyhedron_IO/examples/Polyhedron_IO => Polyhedron/examples/Polyhedron}/off2wav.cin (100%) rename {Polyhedron_IO/examples/Polyhedron_IO => Polyhedron/examples/Polyhedron}/off2wav.cpp (100%) rename {Polyhedron_IO/examples/Polyhedron_IO => Polyhedron/examples/Polyhedron}/off_bbox.cin (100%) rename {Polyhedron_IO/examples/Polyhedron_IO => Polyhedron/examples/Polyhedron}/off_bbox.cpp (100%) rename {Polyhedron_IO/examples/Polyhedron_IO => Polyhedron/examples/Polyhedron}/off_glue.cin (100%) rename {Polyhedron_IO/examples/Polyhedron_IO => Polyhedron/examples/Polyhedron}/off_glue.cpp (100%) rename {Polyhedron_IO/examples/Polyhedron_IO => Polyhedron/examples/Polyhedron}/off_transform.cin (100%) rename {Polyhedron_IO/examples/Polyhedron_IO => Polyhedron/examples/Polyhedron}/off_transform.cpp (100%) rename {Polyhedron_IO/examples/Polyhedron_IO => Polyhedron/examples/Polyhedron}/polyhedron2vrml.cin (100%) rename {Polyhedron_IO/examples/Polyhedron_IO => Polyhedron/examples/Polyhedron}/polyhedron2vrml.cpp (100%) rename {Polyhedron_IO/examples/Polyhedron_IO => Polyhedron/examples/Polyhedron}/polyhedron_copy.cin (100%) rename {Polyhedron_IO/examples/Polyhedron_IO => Polyhedron/examples/Polyhedron}/polyhedron_copy.cpp (100%) rename {Polyhedron_IO/test/Polyhedron_IO => Polyhedron/test/Polyhedron}/data/ascii-tetrahedron.stl (100%) rename {Polyhedron_IO/test/Polyhedron_IO => Polyhedron/test/Polyhedron}/data/binary-tetrahedron-nice-header.stl (100%) rename {Polyhedron_IO/test/Polyhedron_IO => Polyhedron/test/Polyhedron}/data/binary-tetrahedron-non-standard-header-1.stl (100%) rename {Polyhedron_IO/test/Polyhedron_IO => Polyhedron/test/Polyhedron}/data/binary-tetrahedron-non-standard-header-2.stl (100%) rename {Polyhedron_IO/test/Polyhedron_IO => Polyhedron/test/Polyhedron}/data/binary-tetrahedron-non-standard-header-3.stl (100%) rename {Polyhedron_IO/test/Polyhedron_IO => Polyhedron/test/Polyhedron}/data/binary-tetrahedron-non-standard-header-4.stl (100%) rename {Polyhedron_IO/test/Polyhedron_IO => Polyhedron/test/Polyhedron}/data/binary-tetrahedron-non-standard-header-5.stl (100%) rename {Polyhedron_IO/test/Polyhedron_IO => Polyhedron/test/Polyhedron}/data/cube.stl (100%) rename {Polyhedron_IO/test/Polyhedron_IO => Polyhedron/test/Polyhedron}/data/triangle.stl (100%) rename {Polyhedron_IO/test/Polyhedron_IO => Polyhedron/test/Polyhedron}/stl2off.cpp (100%) rename {Polyhedron_IO/test/Polyhedron_IO => Polyhedron/test/Polyhedron}/test_polyhedron_io.cpp (100%) delete mode 100644 Polyhedron_IO/demo/Polyhedron_IO/CMakeLists.txt delete mode 100644 Polyhedron_IO/demo/Polyhedron_IO/README delete mode 100644 Polyhedron_IO/demo/Polyhedron_IO/geomview_demo.cpp delete mode 100644 Polyhedron_IO/demo/Polyhedron_IO/viewpoint2off.cpp delete mode 100644 Polyhedron_IO/examples/Polyhedron_IO/CMakeLists.txt delete mode 100644 Polyhedron_IO/test/Polyhedron_IO/CMakeLists.txt rename {Polyhedron_IO/examples/Polyhedron_IO => Triangulation_2/examples/Triangulation_2}/terr_trian.cin (100%) rename {Polyhedron_IO/examples/Polyhedron_IO => Triangulation_2/examples/Triangulation_2}/terr_trian.cpp (100%) rename {Polyhedron_IO/examples/Polyhedron_IO => Triangulation_2/examples/Triangulation_2}/triangulation_print_OFF.h (100%) diff --git a/Polyhedron_IO/examples/Polyhedron_IO/iv2off.cin b/Polyhedron/examples/Polyhedron/iv2off.cin similarity index 100% rename from Polyhedron_IO/examples/Polyhedron_IO/iv2off.cin rename to Polyhedron/examples/Polyhedron/iv2off.cin diff --git a/Polyhedron_IO/examples/Polyhedron_IO/iv2off.cpp b/Polyhedron/examples/Polyhedron/iv2off.cpp similarity index 100% rename from Polyhedron_IO/examples/Polyhedron_IO/iv2off.cpp rename to Polyhedron/examples/Polyhedron/iv2off.cpp diff --git a/Polyhedron_IO/examples/Polyhedron_IO/off2iv.cin b/Polyhedron/examples/Polyhedron/off2iv.cin similarity index 100% rename from Polyhedron_IO/examples/Polyhedron_IO/off2iv.cin rename to Polyhedron/examples/Polyhedron/off2iv.cin diff --git a/Polyhedron_IO/examples/Polyhedron_IO/off2iv.cpp b/Polyhedron/examples/Polyhedron/off2iv.cpp similarity index 100% rename from Polyhedron_IO/examples/Polyhedron_IO/off2iv.cpp rename to Polyhedron/examples/Polyhedron/off2iv.cpp diff --git a/Polyhedron_IO/examples/Polyhedron_IO/off2off.cin b/Polyhedron/examples/Polyhedron/off2off.cin similarity index 100% rename from Polyhedron_IO/examples/Polyhedron_IO/off2off.cin rename to Polyhedron/examples/Polyhedron/off2off.cin diff --git a/Polyhedron_IO/examples/Polyhedron_IO/off2off.cpp b/Polyhedron/examples/Polyhedron/off2off.cpp similarity index 100% rename from Polyhedron_IO/examples/Polyhedron_IO/off2off.cpp rename to Polyhedron/examples/Polyhedron/off2off.cpp diff --git a/Polyhedron_IO/examples/Polyhedron_IO/off2stl.cin b/Polyhedron/examples/Polyhedron/off2stl.cin similarity index 100% rename from Polyhedron_IO/examples/Polyhedron_IO/off2stl.cin rename to Polyhedron/examples/Polyhedron/off2stl.cin diff --git a/Polyhedron_IO/examples/Polyhedron_IO/off2stl.cpp b/Polyhedron/examples/Polyhedron/off2stl.cpp similarity index 100% rename from Polyhedron_IO/examples/Polyhedron_IO/off2stl.cpp rename to Polyhedron/examples/Polyhedron/off2stl.cpp diff --git a/Polyhedron_IO/examples/Polyhedron_IO/off2vrml.cin b/Polyhedron/examples/Polyhedron/off2vrml.cin similarity index 100% rename from Polyhedron_IO/examples/Polyhedron_IO/off2vrml.cin rename to Polyhedron/examples/Polyhedron/off2vrml.cin diff --git a/Polyhedron_IO/examples/Polyhedron_IO/off2vrml.cpp b/Polyhedron/examples/Polyhedron/off2vrml.cpp similarity index 100% rename from Polyhedron_IO/examples/Polyhedron_IO/off2vrml.cpp rename to Polyhedron/examples/Polyhedron/off2vrml.cpp diff --git a/Polyhedron_IO/examples/Polyhedron_IO/off2wav.cin b/Polyhedron/examples/Polyhedron/off2wav.cin similarity index 100% rename from Polyhedron_IO/examples/Polyhedron_IO/off2wav.cin rename to Polyhedron/examples/Polyhedron/off2wav.cin diff --git a/Polyhedron_IO/examples/Polyhedron_IO/off2wav.cpp b/Polyhedron/examples/Polyhedron/off2wav.cpp similarity index 100% rename from Polyhedron_IO/examples/Polyhedron_IO/off2wav.cpp rename to Polyhedron/examples/Polyhedron/off2wav.cpp diff --git a/Polyhedron_IO/examples/Polyhedron_IO/off_bbox.cin b/Polyhedron/examples/Polyhedron/off_bbox.cin similarity index 100% rename from Polyhedron_IO/examples/Polyhedron_IO/off_bbox.cin rename to Polyhedron/examples/Polyhedron/off_bbox.cin diff --git a/Polyhedron_IO/examples/Polyhedron_IO/off_bbox.cpp b/Polyhedron/examples/Polyhedron/off_bbox.cpp similarity index 100% rename from Polyhedron_IO/examples/Polyhedron_IO/off_bbox.cpp rename to Polyhedron/examples/Polyhedron/off_bbox.cpp diff --git a/Polyhedron_IO/examples/Polyhedron_IO/off_glue.cin b/Polyhedron/examples/Polyhedron/off_glue.cin similarity index 100% rename from Polyhedron_IO/examples/Polyhedron_IO/off_glue.cin rename to Polyhedron/examples/Polyhedron/off_glue.cin diff --git a/Polyhedron_IO/examples/Polyhedron_IO/off_glue.cpp b/Polyhedron/examples/Polyhedron/off_glue.cpp similarity index 100% rename from Polyhedron_IO/examples/Polyhedron_IO/off_glue.cpp rename to Polyhedron/examples/Polyhedron/off_glue.cpp diff --git a/Polyhedron_IO/examples/Polyhedron_IO/off_transform.cin b/Polyhedron/examples/Polyhedron/off_transform.cin similarity index 100% rename from Polyhedron_IO/examples/Polyhedron_IO/off_transform.cin rename to Polyhedron/examples/Polyhedron/off_transform.cin diff --git a/Polyhedron_IO/examples/Polyhedron_IO/off_transform.cpp b/Polyhedron/examples/Polyhedron/off_transform.cpp similarity index 100% rename from Polyhedron_IO/examples/Polyhedron_IO/off_transform.cpp rename to Polyhedron/examples/Polyhedron/off_transform.cpp diff --git a/Polyhedron_IO/examples/Polyhedron_IO/polyhedron2vrml.cin b/Polyhedron/examples/Polyhedron/polyhedron2vrml.cin similarity index 100% rename from Polyhedron_IO/examples/Polyhedron_IO/polyhedron2vrml.cin rename to Polyhedron/examples/Polyhedron/polyhedron2vrml.cin diff --git a/Polyhedron_IO/examples/Polyhedron_IO/polyhedron2vrml.cpp b/Polyhedron/examples/Polyhedron/polyhedron2vrml.cpp similarity index 100% rename from Polyhedron_IO/examples/Polyhedron_IO/polyhedron2vrml.cpp rename to Polyhedron/examples/Polyhedron/polyhedron2vrml.cpp diff --git a/Polyhedron_IO/examples/Polyhedron_IO/polyhedron_copy.cin b/Polyhedron/examples/Polyhedron/polyhedron_copy.cin similarity index 100% rename from Polyhedron_IO/examples/Polyhedron_IO/polyhedron_copy.cin rename to Polyhedron/examples/Polyhedron/polyhedron_copy.cin diff --git a/Polyhedron_IO/examples/Polyhedron_IO/polyhedron_copy.cpp b/Polyhedron/examples/Polyhedron/polyhedron_copy.cpp similarity index 100% rename from Polyhedron_IO/examples/Polyhedron_IO/polyhedron_copy.cpp rename to Polyhedron/examples/Polyhedron/polyhedron_copy.cpp diff --git a/Polyhedron_IO/test/Polyhedron_IO/data/ascii-tetrahedron.stl b/Polyhedron/test/Polyhedron/data/ascii-tetrahedron.stl similarity index 100% rename from Polyhedron_IO/test/Polyhedron_IO/data/ascii-tetrahedron.stl rename to Polyhedron/test/Polyhedron/data/ascii-tetrahedron.stl diff --git a/Polyhedron_IO/test/Polyhedron_IO/data/binary-tetrahedron-nice-header.stl b/Polyhedron/test/Polyhedron/data/binary-tetrahedron-nice-header.stl similarity index 100% rename from Polyhedron_IO/test/Polyhedron_IO/data/binary-tetrahedron-nice-header.stl rename to Polyhedron/test/Polyhedron/data/binary-tetrahedron-nice-header.stl diff --git a/Polyhedron_IO/test/Polyhedron_IO/data/binary-tetrahedron-non-standard-header-1.stl b/Polyhedron/test/Polyhedron/data/binary-tetrahedron-non-standard-header-1.stl similarity index 100% rename from Polyhedron_IO/test/Polyhedron_IO/data/binary-tetrahedron-non-standard-header-1.stl rename to Polyhedron/test/Polyhedron/data/binary-tetrahedron-non-standard-header-1.stl diff --git a/Polyhedron_IO/test/Polyhedron_IO/data/binary-tetrahedron-non-standard-header-2.stl b/Polyhedron/test/Polyhedron/data/binary-tetrahedron-non-standard-header-2.stl similarity index 100% rename from Polyhedron_IO/test/Polyhedron_IO/data/binary-tetrahedron-non-standard-header-2.stl rename to Polyhedron/test/Polyhedron/data/binary-tetrahedron-non-standard-header-2.stl diff --git a/Polyhedron_IO/test/Polyhedron_IO/data/binary-tetrahedron-non-standard-header-3.stl b/Polyhedron/test/Polyhedron/data/binary-tetrahedron-non-standard-header-3.stl similarity index 100% rename from Polyhedron_IO/test/Polyhedron_IO/data/binary-tetrahedron-non-standard-header-3.stl rename to Polyhedron/test/Polyhedron/data/binary-tetrahedron-non-standard-header-3.stl diff --git a/Polyhedron_IO/test/Polyhedron_IO/data/binary-tetrahedron-non-standard-header-4.stl b/Polyhedron/test/Polyhedron/data/binary-tetrahedron-non-standard-header-4.stl similarity index 100% rename from Polyhedron_IO/test/Polyhedron_IO/data/binary-tetrahedron-non-standard-header-4.stl rename to Polyhedron/test/Polyhedron/data/binary-tetrahedron-non-standard-header-4.stl diff --git a/Polyhedron_IO/test/Polyhedron_IO/data/binary-tetrahedron-non-standard-header-5.stl b/Polyhedron/test/Polyhedron/data/binary-tetrahedron-non-standard-header-5.stl similarity index 100% rename from Polyhedron_IO/test/Polyhedron_IO/data/binary-tetrahedron-non-standard-header-5.stl rename to Polyhedron/test/Polyhedron/data/binary-tetrahedron-non-standard-header-5.stl diff --git a/Polyhedron_IO/test/Polyhedron_IO/data/cube.stl b/Polyhedron/test/Polyhedron/data/cube.stl similarity index 100% rename from Polyhedron_IO/test/Polyhedron_IO/data/cube.stl rename to Polyhedron/test/Polyhedron/data/cube.stl diff --git a/Polyhedron_IO/test/Polyhedron_IO/data/triangle.stl b/Polyhedron/test/Polyhedron/data/triangle.stl similarity index 100% rename from Polyhedron_IO/test/Polyhedron_IO/data/triangle.stl rename to Polyhedron/test/Polyhedron/data/triangle.stl diff --git a/Polyhedron_IO/test/Polyhedron_IO/stl2off.cpp b/Polyhedron/test/Polyhedron/stl2off.cpp similarity index 100% rename from Polyhedron_IO/test/Polyhedron_IO/stl2off.cpp rename to Polyhedron/test/Polyhedron/stl2off.cpp diff --git a/Polyhedron_IO/test/Polyhedron_IO/test_polyhedron_io.cpp b/Polyhedron/test/Polyhedron/test_polyhedron_io.cpp similarity index 100% rename from Polyhedron_IO/test/Polyhedron_IO/test_polyhedron_io.cpp rename to Polyhedron/test/Polyhedron/test_polyhedron_io.cpp diff --git a/Polyhedron_IO/demo/Polyhedron_IO/CMakeLists.txt b/Polyhedron_IO/demo/Polyhedron_IO/CMakeLists.txt deleted file mode 100644 index 642f5f5b4b1..00000000000 --- a/Polyhedron_IO/demo/Polyhedron_IO/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -# Created by the script cgal_create_cmake_script -# This is the CMake script for compiling a CGAL application. - - -cmake_minimum_required(VERSION 3.1...3.15) -project( Polyhedron_IO_Demo ) - -if(NOT POLICY CMP0070 AND POLICY CMP0053) - # Only set CMP0053 to OLD with CMake<3.10, otherwise there is a warning. - cmake_policy(SET CMP0053 OLD) -endif() - -set_property(DIRECTORY PROPERTY CGAL_NO_TESTING TRUE) - -find_package(CGAL QUIET) - -if ( CGAL_FOUND ) - - create_single_source_cgal_program( "geomview_demo.cpp" ) - create_single_source_cgal_program( "viewpoint2off.cpp" ) - -else() - - message(STATUS "This program requires the CGAL library, and will not be compiled.") - -endif() - diff --git a/Polyhedron_IO/demo/Polyhedron_IO/README b/Polyhedron_IO/demo/Polyhedron_IO/README deleted file mode 100644 index 48ffa839448..00000000000 --- a/Polyhedron_IO/demo/Polyhedron_IO/README +++ /dev/null @@ -1,18 +0,0 @@ -demo/Polyhedron_IO/README -------------------------- - -viewpoint2off.C - - A demo program that converts geometry files in Viewpoint - Data Labs mesh format into OFF files. Type 'make viewpoint2off' - to compile it. See http://www.viewpoint.com/ - - It is in the demo directory since no viewpoint example - data is provided. - -geomview_demo.C - - Displays a polyhedron from CGAL in Geomview using - CGAL::Geomview_stream. Type 'make geomview_demo' to compile it. - -Lutz Kettner diff --git a/Polyhedron_IO/demo/Polyhedron_IO/geomview_demo.cpp b/Polyhedron_IO/demo/Polyhedron_IO/geomview_demo.cpp deleted file mode 100644 index 7ab19eccca2..00000000000 --- a/Polyhedron_IO/demo/Polyhedron_IO/geomview_demo.cpp +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 2002 Max Planck Institut fuer Informatik (Germany). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org). -// You can redistribute it and/or modify it under the terms of the GNU -// General Public License as published by the Free Software Foundation, -// either version 3 of the License, or (at your option) any later version. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: GPL-3.0+ -// -// -// Author(s) : Lutz Kettner - -#include - -#ifdef _MSC_VER - -#include - -int main() { - std::cout << "Geomview doesn't work on Windows, so no demo." << std::endl; - return 0; -} -#else // can have Geomeview - -#include -#include -#include - -typedef CGAL::Cartesian Kernel; -typedef Kernel::Point_3 Point; -typedef CGAL::Polyhedron_3 Polyhedron; - -int main() { - Point p( 1.0, 0.0, 0.0); - Point q( 0.0, 1.0, 0.0); - Point r( 0.0, 0.0, 1.0); - Point s( 0.0, 0.0, 0.0); - Polyhedron P; - P.make_tetrahedron( p,q,r,s); - CGAL::Geomview_stream geo; - geo << CGAL::green() << P; - - // wait for a mouse click. - Point click; - geo >> click; - return 0; -} - -#endif diff --git a/Polyhedron_IO/demo/Polyhedron_IO/viewpoint2off.cpp b/Polyhedron_IO/demo/Polyhedron_IO/viewpoint2off.cpp deleted file mode 100644 index 6d94eef8ea1..00000000000 --- a/Polyhedron_IO/demo/Polyhedron_IO/viewpoint2off.cpp +++ /dev/null @@ -1,357 +0,0 @@ -// Copyright (c) 2002 Max Planck Institut fuer Informatik (Germany). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org). -// You can redistribute it and/or modify it under the terms of the GNU -// General Public License as published by the Free Software Foundation, -// either version 3 of the License, or (at your option) any later version. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: GPL-3.0+ -// -// -// Author(s) : Lutz Kettner - -// Copies from Viewpoint ASCII format into OFF format. -// ============================================================================ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -typedef CGAL::Cartesian Kernel; -typedef Kernel::Point_3 Point; -typedef vector Point_vector; -typedef vector Facet; -typedef vector Facet_vector; - -bool verbose = false; -bool binary = false; -bool skel = false; -bool noc = false; -bool binary_mesh = false; -bool ascii_mesh = false; -bool normals_file = false; -bool no_normals = false; - -const char* normals_filename = 0; - -// main function with standard unix commandline arguments -// ------------------------------------------------------ -int main( int argc, char **argv) { -#if CGAL_CFG_INCOMPLETE_TYPE_BUG_5 - Point _work_around_incomplete_type; -#endif // CGAL_CFG_INCOMPLETE_TYPE_BUG_5 - int n = 0; - char *filename[3]; - bool help = false; - for ( int i = 1; i < argc; i++) { - // check commandline options - if ( strcmp( "-v", argv[i]) == 0) - verbose = true; - else if ( strcmp( "-b", argv[i]) == 0) - binary = true; - else if ( strcmp( "-skel", argv[i]) == 0) - skel = true; - else if ( strcmp( "-noc", argv[i]) == 0) - noc = true; - else if ( strcmp( "-mesh", argv[i]) == 0) - binary_mesh = true; - else if ( strcmp( "-ascii", argv[i]) == 0) - ascii_mesh = true; - else if ( strcmp( "-no_normals", argv[i]) == 0) - no_normals = true; - else if ( strcmp( "-normals", argv[i]) == 0) { - normals_file = true; - i++; - if ( i < argc) { - normals_filename = argv[i]; - } else { - cerr << argv[0] << ": error: -normals need a filename as " - "parameter." << endl; - help = true; - } - } else if ( (strcmp( "-h", argv[i]) == 0) || - (strcmp( "-help", argv[i]) == 0)) - help = true; - else if ( n < 3 ) { - filename[n ++] = argv[i]; - } else { - ++n; - break; - } - } - if ((n < 1) || (n > 3) || help) { - if ( ! help) - cerr << "Error: in parameter list" << endl; - cerr << "Usage: " << argv[0] - << " [] []" << endl; - cerr << " or: " << argv[0] - << " [] []" << endl; - cerr << " convert an object from Viewpoint formats into OFF." - << endl; - cerr << " -mesh forces input to be read from mesh file." - << endl; - cerr << " -ascii forces input to be read from ascii mesh file." - << endl; - cerr << " -normals reads normals file (in " - "polygon format)." << endl; - cerr << " -no_normals ignore normals." << endl; - cerr << " -b binary output (default is ASCII)." << endl; - cerr << " -skel Geomview SKEL format." << endl; - cerr << " -noc no comments in file." << endl; - cerr << " -v verbose." << endl; - exit( ! help); - } - - CGAL::Verbose_ostream vout( verbose); - vout << argv[0] << ": verbosity on." << endl; - - ifstream in( filename[0]); - if ( ! in) { - cerr << argv[0] << ": error: cannot open file '"<< filename[0] - << "' for reading." < '9') - binary_mesh = 1; - in.putback(c); - boost::int32_t number; - if ( ! binary_mesh) { - in >> number; - if ( number != 1) - ascii_mesh = 1; - } - if ( binary_mesh) { - vout << "Scanning Viewpoint binary mesh data file ..." << endl; - CGAL::I_Binary_read_big_endian_integer32( in, number); - int tmesh = 0; - while( in) { - tmesh ++; - for ( int j = 0; j < number; j++) { - if ( j > 1) { - facets.push_back( Facet()); - Facet& facet = (*(facets.end() - 1)); - facet.push_back( points.size()); - if (j & 1) { - facet.push_back( points.size()-2); - facet.push_back( points.size()-1); - } else { - facet.push_back( points.size()-1); - facet.push_back( points.size()-2); - } - } - // Scan vertex coordinates. - CGAL::I_Binary_read_big_endian_float32( in, x); - CGAL::I_Binary_read_big_endian_float32( in, y); - CGAL::I_Binary_read_big_endian_float32( in, z); - points.push_back( Point( x, y, z)); - } - for ( int k = 0; k < number; k++) { - // Scan vertex normal. - CGAL::I_Binary_read_big_endian_float32( in, x); - CGAL::I_Binary_read_big_endian_float32( in, y); - CGAL::I_Binary_read_big_endian_float32( in, z); - if ( ! no_normals) - normals.push_back( Point( x, y, z)); - } - CGAL::I_Binary_read_big_endian_integer32( in, number); - } - in.close(); - vout << points.size() << " vertex coordinates read." << endl; - vout << facets.size() << " facets read." << endl; - vout << tmesh << " triangle meshes read." << endl; - } else if ( ascii_mesh) { - vout << "Scanning Viewpoint ASCII mesh data file ..." << endl; - int tmesh = 0; - while( in) { - tmesh ++; - for ( int j = 0; j < number; j++) { - if ( j > 1) { - facets.push_back( Facet()); - Facet& facet = (*(facets.end() - 1)); - facet.push_back( points.size()); - if (j & 1) { - facet.push_back( points.size()-2); - facet.push_back( points.size()-1); - } else { - facet.push_back( points.size()-1); - facet.push_back( points.size()-2); - } - } - // Scan vertex coordinates. - in >> x >> y >> z; - points.push_back( Point( x, y, z)); - } - for ( int k = 0; k < number; k++) { - // Scan vertex normal. - in >> x >> y >> z; - if ( ! no_normals) - normals.push_back( Point( x, y, z)); - } - in >> number; - } - in.close(); - vout << points.size() << " vertex coordinates read." << endl; - vout << facets.size() << " facets read." << endl; - vout << tmesh << " triangle meshes read." << endl; - } else { - vout << "Scanning Viewpoint polygon data files ..." << endl; - vout << " ... start with coordinates file ..." << endl; - if ( n < 2) { - cerr << argv[0] << ": error: two input filenames needed." << endl; - exit( 1); - } - while( in) { - in >> c >> x >> d >> y >> e >> z; - if ( ! in || (size_t)number != (points.size() + 1) || - c != ',' || d != ',' || e != ',') { - cerr << argv[0] << ": error: cannot read line " - << points.size() + 1 << " from file '" << filename[0] - << "'." <> number; - } - in.close(); - vout << points.size() << " vertex coordinates read." << endl; - - if ( normals_file && ! no_normals) { - vout << " ... next is normals file ..." << endl; - in.open( normals_filename); - if ( ! in) { - cerr << argv[0] << ": error: cannot open file '" - << normals_filename << "' for reading." <> x; - while( in) { - in >> y >> z; - if ( ! in ) { - cerr << argv[0] << ": error: cannot read line " - << points.size() + 1 << " from file '" - << normals_filename << "'." <> x; - } - in.close(); - vout << normals.size() << " normals read." << endl; - if ( normals.size() != points.size()) { - cerr << argv[0] << ": error: number of points and normals " - "differ." << endl; - exit( 1); - } - } - - vout << " ... next is element file ..." << endl; - in.open( filename[1]); - if ( ! in) { - cerr << argv[0] << ": error: cannot open file '"<< filename[1] - << "' for reading." <> part_name; - while( in) { - in.get(c); - facets.push_back( Facet()); - Facet& facet = (*(facets.end() - 1)); - while( c == ' ') { - in >> number; - if ( number < 1 || (size_t)number > points.size()) { - cerr << argv[0] << ": error: parsing line " - << facets.size() << " from file '" << filename[1] - << "': index " << number << " is out of range." - << endl; - exit( 1); - } - facet.push_back( number - 1); - in.get(c); - } - in >> part_name; - } - in.close(); - vout << facets.size() << " facets read." << endl; - } - - const char* oname = "cout"; - ostream* p_out = &cout; - ofstream out; - if ( n > 2) { - out.open( filename[2]); - p_out = &out; - oname = filename[2]; - } - if ( (ascii_mesh || binary_mesh) && n > 1) { - out.open( filename[1]); - p_out = &out; - oname = filename[1]; - } - if ( !*p_out) { - cerr << argv[0] << ": error: cannot open file '"<< oname - << "' for writing." <0); - Point_vector::iterator norm = normals.begin(); - for ( Point_vector::iterator p = points.begin(); p != points.end(); ++p) { - writer.write_vertex( (*p).x(), (*p).y(), (*p).z()); - if ( normals.size()>0) { - writer.write_normal( (*norm).x(), (*norm).y(), (*norm).z()); - ++norm; - } - } - writer.write_facet_header(); - for ( Facet_vector::iterator fc = facets.begin(); fc!=facets.end(); ++fc) { - writer.write_facet_begin( (*fc).size()); - for ( Facet::iterator fi = (*fc).begin(); fi != (*fc).end(); ++fi) { - writer.write_facet_vertex_index( *fi); - } - writer.write_facet_end(); - } - writer.write_footer(); - vout << " .... done." << endl; - if ( !*p_out) { - cerr << argv[0] << " write error: while writing file '"<< oname - << "'." << endl; - exit( 1); - } - return 0; -} -// EOF // diff --git a/Polyhedron_IO/examples/Polyhedron_IO/CMakeLists.txt b/Polyhedron_IO/examples/Polyhedron_IO/CMakeLists.txt deleted file mode 100644 index 1de0b8a91f5..00000000000 --- a/Polyhedron_IO/examples/Polyhedron_IO/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -# Created by the script cgal_create_cmake_script -# This is the CMake script for compiling a CGAL application. - - -cmake_minimum_required(VERSION 3.1...3.15) -project( Polyhedron_IO_Examples ) - - -find_package(CGAL QUIET) - -if ( CGAL_FOUND ) - - # create a target per cppfile - file(GLOB cppfiles RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) - foreach(cppfile ${cppfiles}) - create_single_source_cgal_program( "${cppfile}" ) - endforeach() - -else() - - message(STATUS "This program requires the CGAL library, and will not be compiled.") - -endif() - diff --git a/Polyhedron_IO/test/Polyhedron_IO/CMakeLists.txt b/Polyhedron_IO/test/Polyhedron_IO/CMakeLists.txt deleted file mode 100644 index ac42c32b8d0..00000000000 --- a/Polyhedron_IO/test/Polyhedron_IO/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -# Created by the script cgal_create_cmake_script -# This is the CMake script for compiling a CGAL application. - - -cmake_minimum_required(VERSION 3.1...3.15) -project( Polyhedron_IO_Tests ) - - -find_package(CGAL QUIET) - -if ( CGAL_FOUND ) - - # create a target per cppfile - file(GLOB cppfiles RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) - foreach(cppfile ${cppfiles}) - create_single_source_cgal_program( "${cppfile}" ) - endforeach() - -else() - - message(STATUS "This program requires the CGAL library, and will not be compiled.") - -endif() - diff --git a/Stream_support/include/CGAL/IO/STL/STL_reader.h b/Stream_support/include/CGAL/IO/STL/STL_reader.h index fecd024610d..2d1ca0972fa 100644 --- a/Stream_support/include/CGAL/IO/STL/STL_reader.h +++ b/Stream_support/include/CGAL/IO/STL/STL_reader.h @@ -323,14 +323,15 @@ bool read_STL(std::istream& input, // We are within the first 80 characters, both ASCII and binary are possible // Read the 5 first characters to check if the first word is "solid" - std::string s, solid("solid"); + std::string s; - char word[5]; + char word[6]; if(input.read(reinterpret_cast(&word[0]), sizeof(c)) && input.read(reinterpret_cast(&word[1]), sizeof(c)) && input.read(reinterpret_cast(&word[2]), sizeof(c)) && input.read(reinterpret_cast(&word[3]), sizeof(c)) && - input.read(reinterpret_cast(&word[4]), sizeof(c))) + input.read(reinterpret_cast(&word[4]), sizeof(c)) && + input.read(reinterpret_cast(&word[5]), sizeof(c))) { s = std::string(word, 5); pos += 5; @@ -339,7 +340,9 @@ bool read_STL(std::istream& input, return true; // empty file // If the first word is not 'solid', the file must be binary - if(s != solid) + if(s != "solid" + || (word[5] !='\n' + && word[5] != ' ')) { if(parse_binary_STL(input, points, facets, verbose)) { diff --git a/Polyhedron_IO/examples/Polyhedron_IO/terr_trian.cin b/Triangulation_2/examples/Triangulation_2/terr_trian.cin similarity index 100% rename from Polyhedron_IO/examples/Polyhedron_IO/terr_trian.cin rename to Triangulation_2/examples/Triangulation_2/terr_trian.cin diff --git a/Polyhedron_IO/examples/Polyhedron_IO/terr_trian.cpp b/Triangulation_2/examples/Triangulation_2/terr_trian.cpp similarity index 100% rename from Polyhedron_IO/examples/Polyhedron_IO/terr_trian.cpp rename to Triangulation_2/examples/Triangulation_2/terr_trian.cpp diff --git a/Polyhedron_IO/examples/Polyhedron_IO/triangulation_print_OFF.h b/Triangulation_2/examples/Triangulation_2/triangulation_print_OFF.h similarity index 100% rename from Polyhedron_IO/examples/Polyhedron_IO/triangulation_print_OFF.h rename to Triangulation_2/examples/Triangulation_2/triangulation_print_OFF.h