1 // Copyright (c) 1997
2 // Utrecht University (The Netherlands),
3 // ETH Zurich (Switzerland),
4 // INRIA Sophia-Antipolis (France),
5 // Max-Planck-Institute Saarbruecken (Germany),
6 // and Tel-Aviv University (Israel). All rights reserved.
7 //
8 // This file is part of CGAL (www.cgal.org)
9 //
10 // $URL: https://github.com/CGAL/cgal/blob/v5.3/Stream_support/include/CGAL/IO/OFF/File_header_extended_OFF.h $
11 // $Id: File_header_extended_OFF.h 580a1ef 2020-05-22T15:31:50+02:00 Mael Rouxel-Labbé
12 // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
13 //
14 //
15 // Author(s) : Lutz Kettner <kettner@mpi-sb.mpg.de>
16
17
18 #ifndef CGAL_IO_OFF_FILE_HEADER_EXTENDED_OFF_H
19 #define CGAL_IO_OFF_FILE_HEADER_EXTENDED_OFF_H 1
20
21 #include <CGAL/config.h>
22
23 #include <iostream>
24 #include <string>
25
26
27 namespace CGAL {
28
29 class CGAL_EXPORT File_header_extended_OFF {
30 bool m_verbose; // Print error messages if true.
31 bool m_polyhedral_surface;
32 std::size_t m_halfedges;
33 bool m_triangulated;
34 bool m_non_empty_facets;
35 bool m_terrain;
36 bool m_normalized_to_sphere;
37 double m_radius;
38 bool m_rounded;
39 int m_rounded_bits;
40 bool m_off_header;
41 public:
42 typedef File_header_extended_OFF Self;
43 File_header_extended_OFF( bool verbose = false)
m_verbose(verbose)44 : m_verbose ( verbose),
45 m_polyhedral_surface ( false),
46 m_halfedges ( 0),
47 m_triangulated ( false),
48 m_non_empty_facets ( false),
49 m_terrain ( false),
50 m_normalized_to_sphere ( false),
51 m_radius ( 0.0),
52 m_rounded ( false),
53 m_rounded_bits ( 0),
54 m_off_header ( true)
55 {}
56 // Access:
verbose()57 bool verbose() const { return m_verbose; }
polyhedral_surface()58 bool polyhedral_surface() const { return m_polyhedral_surface; }
halfedges()59 std::size_t halfedges() const { return m_halfedges; }
size_of_halfedges()60 std::size_t size_of_halfedges() const { return m_halfedges; }
triangulated()61 bool triangulated() const { return m_triangulated; }
non_empty_facets()62 bool non_empty_facets() const { return m_non_empty_facets; }
terrain()63 bool terrain() const { return m_terrain; }
normalized_to_sphere()64 bool normalized_to_sphere() const { return m_normalized_to_sphere; }
radius()65 double radius() const { return m_radius; }
rounded()66 bool rounded() const { return m_rounded; }
rounded_bits()67 int rounded_bits() const { return m_rounded_bits; }
off_header()68 bool off_header() const { return m_off_header; }
69 // Derived predicates about the file format.
is_OFF()70 bool is_OFF() const { return m_off_header; }
71 bool is_POL() const;
72 bool is_CBP() const;
73 bool is_TRN() const;
74 int is_CBPn() const;
75 int is_TRNn() const;
76 // The proper file suffix with respect to file format.
77 std::string suffix() const;
78 // The proper format name.
79 std::string format_name() const;
80 // Set values:
set_verbose(bool b)81 void set_verbose( bool b) { m_verbose = b; }
set_polyhedral_surface(bool b)82 void set_polyhedral_surface( bool b) { m_polyhedral_surface = b; }
set_halfedges(std::size_t h)83 void set_halfedges( std::size_t h) { m_halfedges = h; }
set_triangulated(bool b)84 void set_triangulated( bool b) { m_triangulated = b; }
set_non_empty_facets(bool b)85 void set_non_empty_facets( bool b) { m_non_empty_facets = b; }
set_terrain(bool b)86 void set_terrain( bool b) { m_terrain = b; }
set_normalized_to_sphere(bool b)87 void set_normalized_to_sphere( bool b) { m_normalized_to_sphere = b;}
set_radius(double d)88 void set_radius( double d) { m_radius = d; }
set_rounded(bool b)89 void set_rounded( bool b) { m_rounded = b; }
set_rounded_bits(int i)90 void set_rounded_bits( int i) { m_rounded_bits = i; }
set_off_header(bool b)91 void set_off_header( bool b) { m_off_header = b; }
92 Self& operator+=( const Self& header); // union of two headers
93 };
94
95 // Write extended header incl. CGAL/ENDCBP keywords.
96 std::ostream& operator<<( std::ostream& out,
97 const File_header_extended_OFF& h);
98
99 // Scan extended header. The CBP keyword must be read already.
100 std::istream& operator>>( std::istream& in, File_header_extended_OFF& h);
101
102 // istream modifier skips chars until end of line.
skip_until_EOL(std::istream & in)103 inline std::istream& skip_until_EOL( std::istream& in) {
104 if(in.eof()){
105 return in;
106 }
107 char c;
108 while ( in.get(c) && c != '\n')
109 ;
110 return in;
111 }
112
113 // istream modifier that checks for OFF comments and removes them.
skip_comment_OFF(std::istream & in)114 inline std::istream& skip_comment_OFF( std::istream& in) {
115 char c;
116 while( (in >> c) && c == '#')
117 in >> skip_until_EOL;
118 in.putback(c);
119 return in;
120 }
121
122 } //namespace CGAL
123
124 #ifdef CGAL_HEADER_ONLY
125 #include <CGAL/IO/OFF/File_header_extended_OFF_impl.h>
126 #endif // CGAL_HEADER_ONLY
127
128 #endif // CGAL_IO_OFF_FILE_HEADER_EXTENDED_OFF_H //
129 // EOF //
130