OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MeshIO.hh
1 /* ========================================================================= *
2  * *
3  * OpenMesh *
4  * Copyright (c) 2001-2015, 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  * $Revision$ *
45  * $Date$ *
46  * *
47 \*===========================================================================*/
48 
49 
50 #ifndef OM_MESHIO_HH
51 #define OM_MESHIO_HH
52 
53 
54 //=== INCLUDES ================================================================
55 
56 // -------------------- system settings
57 #include <OpenMesh/Core/System/config.h>
58 // -------------------- check include order
59 #if defined (OPENMESH_TRIMESH_ARRAY_KERNEL_HH) || \
60  defined (OPENMESH_POLYMESH_ARRAY_KERNEL_HH)
61 # error "Include MeshIO.hh before including a mesh type!"
62 #endif
63 // -------------------- OpenMesh
64 #include <OpenMesh/Core/IO/SR_store.hh>
65 #include <OpenMesh/Core/IO/IOManager.hh>
66 #include <OpenMesh/Core/IO/importer/ImporterT.hh>
67 #include <OpenMesh/Core/IO/exporter/ExporterT.hh>
68 
69 
70 //== NAMESPACES ==============================================================
71 
72 namespace OpenMesh {
73 namespace IO {
74 
75 
76 //=== IMPLEMENTATION ==========================================================
77 
78 
84 
85 
86 //-----------------------------------------------------------------------------
87 
88 
102 template <class Mesh>
103 bool
104 read_mesh(Mesh& _mesh,
105  const std::string& _filename)
106 {
107  Options opt;
108  return read_mesh(_mesh, _filename, opt, true);
109 }
110 
111 
132 template <class Mesh>
133 bool
134 read_mesh(Mesh& _mesh,
135  const std::string& _filename,
136  Options& _opt,
137  bool _clear = true)
138 {
139  if (_clear) _mesh.clear();
140  ImporterT<Mesh> importer(_mesh);
141  return IOManager().read(_filename, importer, _opt);
142 }
143 
144 
164 template <class Mesh>
165 bool
166 read_mesh(Mesh& _mesh,
167  std::istream& _is,
168  const std::string& _ext,
169  Options& _opt,
170  bool _clear = true)
171 {
172  if (_clear) _mesh.clear();
173  ImporterT<Mesh> importer(_mesh);
174  return IOManager().read(_is,_ext, importer, _opt);
175 }
176 
177 
178 
179 //-----------------------------------------------------------------------------
180 
181 
198 template <class Mesh>
199 bool write_mesh(const Mesh& _mesh,
200  const std::string& _filename,
201  Options _opt = Options::Default,
202  std::streamsize _precision = 6)
203 {
204  ExporterT<Mesh> exporter(_mesh);
205  return IOManager().write(_filename, exporter, _opt, _precision);
206 }
207 
208 
209 //-----------------------------------------------------------------------------
210 
211 
230 template <class Mesh>
231 bool write_mesh(const Mesh& _mesh,
232  std::ostream& _os,
233  const std::string& _ext,
234  Options _opt = Options::Default,
235  std::streamsize _precision = 6)
236 {
237  ExporterT<Mesh> exporter(_mesh);
238  return IOManager().write(_os,_ext, exporter, _opt, _precision);
239 }
240 
241 
242 //-----------------------------------------------------------------------------
243 
259 template <class Mesh>
260 size_t binary_size(const Mesh& _mesh,
261  const std::string& _ext,
262  Options _opt = Options::Default)
263 {
264  ExporterT<Mesh> exporter(_mesh);
265  return IOManager().binary_size(_ext, exporter, _opt);
266 }
267 
268 
269 //-----------------------------------------------------------------------------
270 
272 
273 
274 //=============================================================================
275 } // namespace IO
276 } // namespace OpenMesh
277 //=============================================================================
278 #if defined(OM_STATIC_BUILD) || defined(ARCH_DARWIN)
279 # include <OpenMesh/Core/IO/IOInstances.hh>
280 #endif
281 //=============================================================================
282 #endif
283 //=============================================================================
This class template provides an importer module for OpenMesh meshes.
Definition: ImporterT.hh:85
Set options for reader/writer modules.
Definition: Options.hh:95
bool read(const std::string &_filename, BaseImporter &_bi, Options &_opt)
Read a mesh from file _filename.
Definition: IOManager.cc:92
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
Definition: MeshIO.hh:104
No options.
Definition: Options.hh:104
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:148
This class template provides an exporter module for OpenMesh meshes.
Definition: ExporterT.hh:87
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:199
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
size_t binary_size(const Mesh &_mesh, const std::string &_ext, Options _opt=Options::Default)
Get binary size of data.
Definition: MeshIO.hh:260

Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .