File: File_binary_mesh_3.h

package info (click to toggle)
cgal 6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144,912 kB
  • sloc: cpp: 810,858; ansic: 208,477; sh: 493; python: 411; makefile: 286; javascript: 174
file content (116 lines) | stat: -rw-r--r-- 2,921 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright (c) 2012  GeometryFactory Sarl (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
//
// $URL: https://github.com/CGAL/cgal/blob/v6.1/SMDS_3/include/CGAL/IO/File_binary_mesh_3.h $
// $Id: include/CGAL/IO/File_binary_mesh_3.h b26b07a1242 $
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
//
//
// Author(s)     : Laurent Rineau

#ifndef CGAL_IO_FILE_BINARY_MESH_3_H
#define CGAL_IO_FILE_BINARY_MESH_3_H

#include <CGAL/license/SMDS_3.h>


#include <iostream>
#include <string>
#include <limits>
#include <CGAL/SMDS_3/io_signature.h>

namespace CGAL {

namespace IO {

  /**
   * @ingroup PkgSMDS3IOFunctions
   * @brief outputs a mesh complex to the CGAL binary file format (`.binary.cgal`).
   *
   * @tparam C3T3 Type of mesh complex, model of `MeshComplex_3InTriangulation_3`
   *
   * @param os the output stream, opened in binary mode
   * @param c3t3 the mesh complex
   *
   * @sa `CGAL::IO::load_binary_file()`
   */
template <class C3T3>
bool
save_binary_file(std::ostream& os,
                 const C3T3& c3t3
#ifdef DOXYGEN_RUNNING
                 )
#else
               , bool binary = true)
#endif
{
  if(binary) os << "binary ";
  os << "CGAL c3t3 " << CGAL::Get_io_signature<C3T3>()() << "\n";
  if(binary) {
    CGAL::IO::set_binary_mode(os);
  } else {
    CGAL::IO::set_ascii_mode(os);
    os.precision(std::numeric_limits<double>::max_digits10);
  }
  return !!(os << c3t3);
  // call operator!() twice, because operator bool() is C++11
}

/**
 * @ingroup PkgSMDS3IOFunctions
 * @brief loads a mesh complex from a file written in CGAL binary file format (`.binary.cgal`).
 *
 * @tparam C3T3 Type of mesh complex, model of `MeshComplex_3InTriangulation_3`
 *
 * @param is the input stream, opened in binary mode
 * @param c3t3 the mesh complex
 *
 * @sa `CGAL::IO::save_binary_file()`
 */
template <class C3T3>
bool load_binary_file(std::istream& is, C3T3& c3t3)
{
  std::string s;
  if(!(is >> s)) return false;
  bool binary = (s == "binary");
  if(binary) {
    if(!(is >> s)) return false;
  }
  if (s != "CGAL" ||
      !(is >> s) ||
      s != "c3t3")
  {
    return false;
  }
  std::getline(is, s);
  if(!s.empty()) {
    if(s[s.size()-1] == '\r') { // deal with Windows EOL
      s.resize(s.size() - 1);
    }
    if(s != std::string(" ") + CGAL::Get_io_signature<C3T3>()()) {
      std::cerr << "load_binary_file:"
                << "\n  expected format: " << CGAL::Get_io_signature<C3T3>()()
                << "\n       got format:" << s << std::endl;
      return false;
    }
  }
  if(binary) CGAL::IO::set_binary_mode(is);
  is >> c3t3;
  return !!is;
  // call operator!() twice, because operator bool() is C++11
}

} // end namespace IO

#ifndef CGAL_NO_DEPRECATED_CODE
namespace Mesh_3 {
using IO::save_binary_file;
using IO::load_binary_file;
}
#endif

} // end namespace CGAL

#endif // CGAL_IO_FILE_BINARY_MESH_3_H