OpenMesh
MeshIO.hh
1/* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2025, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openmesh.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenMesh. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 * ========================================================================= */
41
42
43
44
45#ifndef OM_MESHIO_HH
46#define OM_MESHIO_HH
47
48
49//=== INCLUDES ================================================================
50
51// -------------------- system settings
52#include <OpenMesh/Core/System/config.h>
53
54// -------------------- OpenMesh
55#include <OpenMesh/Core/IO/SR_store.hh>
56#include <OpenMesh/Core/IO/IOManager.hh>
57#include <OpenMesh/Core/IO/importer/ImporterT.hh>
58#include <OpenMesh/Core/IO/exporter/ExporterT.hh>
59
60
61//== NAMESPACES ==============================================================
62
63namespace OpenMesh {
64namespace IO {
65
66
67//=== IMPLEMENTATION ==========================================================
68
69
75
76
77//-----------------------------------------------------------------------------
78
79
93template <class Mesh>
94bool
96 const std::string& _filename)
97{
98 Options opt;
99 return read_mesh(_mesh, _filename, opt, true);
100}
101
102
123template <class Mesh>
124bool
126 const std::string& _filename,
127 Options& _opt,
128 bool _clear = true)
129{
130 if (_clear) _mesh.clear();
131 ImporterT<Mesh> importer(_mesh);
132 return IOManager().read(_filename, importer, _opt);
133}
134
135
155template <class Mesh>
156bool
158 std::istream& _is,
159 const std::string& _ext,
160 Options& _opt,
161 bool _clear = true)
162{
163 if (_clear) _mesh.clear();
164 ImporterT<Mesh> importer(_mesh);
165 return IOManager().read(_is,_ext, importer, _opt);
166}
167
168
169
170//-----------------------------------------------------------------------------
171
172
189template <class Mesh>
190bool write_mesh(const Mesh& _mesh,
191 const std::string& _filename,
193 std::streamsize _precision = 6)
194{
195 ExporterT<Mesh> exporter(_mesh);
196 return IOManager().write(_filename, exporter, _opt, _precision);
197}
198
199
200//-----------------------------------------------------------------------------
201
202
221template <class Mesh>
222bool write_mesh(const Mesh& _mesh,
223 std::ostream& _os,
224 const std::string& _ext,
226 std::streamsize _precision = 6)
227{
228 ExporterT<Mesh> exporter(_mesh);
229 return IOManager().write(_os,_ext, exporter, _opt, _precision);
230}
231
232
233//-----------------------------------------------------------------------------
234
250template <class Mesh>
251size_t binary_size(const Mesh& _mesh,
252 const std::string& _ext,
254{
255 ExporterT<Mesh> exporter(_mesh);
256 return IOManager().binary_size(_ext, exporter, _opt);
257}
258
259
260//-----------------------------------------------------------------------------
261
263
264
265//=============================================================================
266} // namespace IO
267} // namespace OpenMesh
268//=============================================================================
269#if defined(OM_STATIC_BUILD) || defined(ARCH_DARWIN)
270# include <OpenMesh/Core/IO/IOInstances.hh>
271#endif
272//=============================================================================
273#endif
274//=============================================================================
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
size_t binary_size(const Mesh &_mesh, const std::string &_ext, Options _opt=Options::Default)
Get binary size of data.
Definition: MeshIO.hh:251
bool write_mesh(const Mesh &_mesh, const std::string &_filename, Options _opt=Options::Default, std::streamsize _precision=6)
Write a mesh to the file _filename.
Definition: MeshIO.hh:190
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
Definition: MeshIO.hh:95
This class template provides an exporter module for OpenMesh meshes.
Definition: ExporterT.hh:85
This class template provides an importer module for OpenMesh meshes.
Definition: ImporterT.hh:81
bool write(const std::string &_filename, BaseExporter &_be, Options _opt=Options::Default, std::streamsize _precision=6)
Write a mesh to file _filename.
Definition: IOManager.cc:143
bool read(const std::string &_filename, BaseImporter &_bi, Options &_opt)
Read a mesh from file _filename.
Definition: IOManager.cc:87
Set options for reader/writer modules.
Definition: Options.hh:92
@ Default
By default write persistent custom properties.
Definition: Options.hh:117
Polygonal mesh based on the ArrayKernel.
Definition: PolyMesh_ArrayKernelT.hh:96

Project OpenMesh, ©  Visual Computing Institute, RWTH Aachen. Documentation generated using doxygen .