OpenMesh
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 
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 // -------------------- check include order
55 #if defined (OPENMESH_TRIMESH_ARRAY_KERNEL_HH) || \
56  defined (OPENMESH_POLYMESH_ARRAY_KERNEL_HH)
57 
58  // Issue warning if MeshIO was not included before Mesh Type
59  // Nobody knows why this order was enforced.
60  // If somebody encounters an error resulting from a wrong order, please report it to the OpenMesh developers.
61  // If we don't here about any errors, this check will be removed
62  // @TODO: Remove after reasonable time
63  #ifdef WIN32
64  #pragma message("MeshIO.hh was included after Mesh Type. You may ignore this warning. Please report errors resulting ifrom this order to the developers!")
65  #else
66  #warning "MeshIO.hh was included after Mesh Type. You may ignore this warning. Please report errors resulting from this order to the developers!"
67  #endif
68 
69 #endif
70 
71 // -------------------- OpenMesh
72 #include <OpenMesh/Core/IO/SR_store.hh>
73 #include <OpenMesh/Core/IO/IOManager.hh>
74 #include <OpenMesh/Core/IO/importer/ImporterT.hh>
75 #include <OpenMesh/Core/IO/exporter/ExporterT.hh>
76 
77 
78 //== NAMESPACES ==============================================================
79 
80 namespace OpenMesh {
81 namespace IO {
82 
83 
84 //=== IMPLEMENTATION ==========================================================
85 
86 
92 
93 
94 //-----------------------------------------------------------------------------
95 
96 
110 template <class Mesh>
111 bool
113  const std::string& _filename)
114 {
115  Options opt;
116  return read_mesh(_mesh, _filename, opt, true);
117 }
118 
119 
140 template <class Mesh>
141 bool
143  const std::string& _filename,
144  Options& _opt,
145  bool _clear = true)
146 {
147  if (_clear) _mesh.clear();
148  ImporterT<Mesh> importer(_mesh);
149  return IOManager().read(_filename, importer, _opt);
150 }
151 
152 
172 template <class Mesh>
173 bool
175  std::istream& _is,
176  const std::string& _ext,
177  Options& _opt,
178  bool _clear = true)
179 {
180  if (_clear) _mesh.clear();
181  ImporterT<Mesh> importer(_mesh);
182  return IOManager().read(_is,_ext, importer, _opt);
183 }
184 
185 
186 
187 //-----------------------------------------------------------------------------
188 
189 
206 template <class Mesh>
207 bool write_mesh(const Mesh& _mesh,
208  const std::string& _filename,
209  Options _opt = Options::Default,
210  std::streamsize _precision = 6)
211 {
212  ExporterT<Mesh> exporter(_mesh);
213  return IOManager().write(_filename, exporter, _opt, _precision);
214 }
215 
216 
217 //-----------------------------------------------------------------------------
218 
219 
238 template <class Mesh>
239 bool write_mesh(const Mesh& _mesh,
240  std::ostream& _os,
241  const std::string& _ext,
242  Options _opt = Options::Default,
243  std::streamsize _precision = 6)
244 {
245  ExporterT<Mesh> exporter(_mesh);
246  return IOManager().write(_os,_ext, exporter, _opt, _precision);
247 }
248 
249 
250 //-----------------------------------------------------------------------------
251 
267 template <class Mesh>
268 size_t binary_size(const Mesh& _mesh,
269  const std::string& _ext,
270  Options _opt = Options::Default)
271 {
272  ExporterT<Mesh> exporter(_mesh);
273  return IOManager().binary_size(_ext, exporter, _opt);
274 }
275 
276 
277 //-----------------------------------------------------------------------------
278 
280 
281 
282 //=============================================================================
283 } // namespace IO
284 } // namespace OpenMesh
285 //=============================================================================
286 #if defined(OM_STATIC_BUILD) || defined(ARCH_DARWIN)
287 # include <OpenMesh/Core/IO/IOInstances.hh>
288 #endif
289 //=============================================================================
290 #endif
291 //=============================================================================
This class template provides an importer module for OpenMesh meshes.
Definition: ImporterT.hh:80
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
Definition: MeshIO.hh:112
bool read(const std::string &_filename, BaseImporter &_bi, Options &_opt)
Read a mesh from file _filename.
Definition: IOManager.cc:87
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
Set options for reader/writer modules.
Definition: Options.hh:90
No options.
Definition: Options.hh:99
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
Polygonal mesh based on the ArrayKernel.
Definition: PolyMesh_ArrayKernelT.hh:94
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:207
size_t binary_size(const Mesh &_mesh, const std::string &_ext, Options _opt=Options::Default)
Get binary size of data.
Definition: MeshIO.hh:268
This class template provides an exporter module for OpenMesh meshes.
Definition: ExporterT.hh:82

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