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_impl.h $
11 // $Id: File_header_extended_OFF_impl.h ae75594 2021-03-10T13:54:09+01:00 Maxime Gimeno
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 #ifdef CGAL_HEADER_ONLY
18 #define CGAL_INLINE_FUNCTION inline
19 #else
20 #define CGAL_INLINE_FUNCTION
21 #endif
22 
23 #include <CGAL/IO/OFF/File_header_extended_OFF.h>
24 #include <CGAL/basic.h>
25 
26 #include <cstdlib>
27 #include <cctype>
28 #include <cstring>
29 #include <iostream>
30 #include <sstream>
31 #include <algorithm>
32 
33 
34 namespace CGAL {
35 
36 CGAL_INLINE_FUNCTION
37 bool File_header_extended_OFF::
is_POL()38 is_POL()  const {
39     return is_OFF() && polyhedral_surface();
40 }
41 
42 CGAL_INLINE_FUNCTION
43 bool File_header_extended_OFF::
is_CBP()44 is_CBP()  const {
45     return is_POL() && triangulated() && non_empty_facets() &&
46         normalized_to_sphere() && radius() <= 1.0;
47 }
48 
49 CGAL_INLINE_FUNCTION
50 bool File_header_extended_OFF::
is_TRN()51 is_TRN()  const { return is_CBP() && terrain(); }
52 
53 CGAL_INLINE_FUNCTION
54 int  File_header_extended_OFF::
is_CBPn()55 is_CBPn() const {
56     if ( is_POL() && triangulated() && non_empty_facets() &&
57          normalized_to_sphere() && rounded() &&
58          (radius() <= double( 1l << rounded_bits())))
59         return rounded_bits();
60     else
61         return 0;
62 }
63 
64 CGAL_INLINE_FUNCTION
65 int  File_header_extended_OFF::
is_TRNn()66 is_TRNn() const { return ( terrain() ? is_CBPn() : 0); }
67 
68 
69 // The proper file suffix with respect to file format.
70 CGAL_INLINE_FUNCTION
71 std::string File_header_extended_OFF::
suffix()72 suffix() const {
73     if ( is_TRNn()) {
74         std::ostringstream out;
75         out << "trn" << m_rounded_bits << '\0';
76         return out.str();
77     }
78     if ( is_TRN())
79         return std::string("trn");
80     if ( is_CBPn()) {
81         std::ostringstream out;
82         out << "cbp" << m_rounded_bits << '\0';
83         return out.str();
84     }
85     if ( is_CBP())
86         return std::string("cbp");
87     if ( is_POL())
88         return std::string("pol");
89     return std::string("off");
90 }
91 
92 // The proper format name.
93 CGAL_INLINE_FUNCTION
94 std::string File_header_extended_OFF::
format_name()95 format_name() const {
96     if ( is_TRNn()) {
97         std::ostringstream out;
98         out << "TRN" << m_rounded_bits << '\0';
99         return out.str();
100     }
101     if ( is_TRN())
102         return std::string("TRN");
103     if ( is_CBPn()) {
104         std::ostringstream out;
105         out << "CBP" << m_rounded_bits << '\0';
106         return out.str();
107     }
108     if ( is_CBP())
109         return std::string("CBP");
110     if ( is_POL())
111         return std::string("POL");
112     return std::string("OFF");
113 }
114 
115 CGAL_INLINE_FUNCTION
116 File_header_extended_OFF& File_header_extended_OFF::
117 operator+=( const File_header_extended_OFF& header) {
118     m_verbose              = m_verbose || header.m_verbose;
119     m_polyhedral_surface   = m_polyhedral_surface &&
120                              header.m_polyhedral_surface;
121     m_halfedges           += header.m_halfedges;
122     m_triangulated         = m_triangulated && header.m_triangulated;
123     m_non_empty_facets     = m_non_empty_facets &&
124                              header.m_non_empty_facets;
125     m_terrain              = m_terrain && header.m_terrain;
126     m_normalized_to_sphere = m_normalized_to_sphere &&
127                              header.m_normalized_to_sphere;
128     m_radius               = (std::max)(m_radius, header.m_radius);
129     m_rounded              = m_rounded && header.m_rounded;
130     m_rounded_bits         = (std::max)( m_rounded_bits,
131                                        header.m_rounded_bits);
132     m_off_header           = m_off_header && header.m_off_header;
133     return *this;
134 }
135 
136 } //namespace CGAL
137 // EOF //
138