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  * $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 
59 // -------------------- check include order
60 #if defined (OPENMESH_TRIMESH_ARRAY_KERNEL_HH) || \
61  defined (OPENMESH_POLYMESH_ARRAY_KERNEL_HH)
62 
63  // Issue warning if MeshIO was not included before Mesh Type
64  // Nobody knows why this order was enforced.
65  // If somebody encounters an error resulting from a wrong order, please report it to the OpenMesh developers.
66  // If we don't here about any errors, this check will be removed
67  // @TODO: Remove after reasonable time
68  #ifdef WIN32
69  #pragma message("MeshIO.hh was included after Mesh Type. You may ignore this warning. Please report errors resulting ifrom this order to the developers!")
70  #else
71  #warning "MeshIO.hh was included after Mesh Type. You may ignore this warning. Please report errors resulting from this order to the developers!"
72  #endif
73 
74 #endif
75 
76 // -------------------- OpenMesh
77 #include <OpenMesh/Core/IO/SR_store.hh>
78 #include <OpenMesh/Core/IO/IOManager.hh>
79 #include <OpenMesh/Core/IO/importer/ImporterT.hh>
80 #include <OpenMesh/Core/IO/exporter/ExporterT.hh>
81 
82 
83 //== NAMESPACES ==============================================================
84 
85 namespace OpenMesh {
86 namespace IO {
87 
88 
89 //=== IMPLEMENTATION ==========================================================
90 
91 
97 
98 
99 //-----------------------------------------------------------------------------
100 
101 
115 template <class Mesh>
116 bool
117 read_mesh(Mesh& _mesh,
118  const std::string& _filename)
119 {
120  Options opt;
121  return read_mesh(_mesh, _filename, opt, true);
122 }
123 
124 
145 template <class Mesh>
146 bool
147 read_mesh(Mesh& _mesh,
148  const std::string& _filename,
149  Options& _opt,
150  bool _clear = true)
151 {
152  if (_clear) _mesh.clear();
153  ImporterT<Mesh> importer(_mesh);
154  return IOManager().read(_filename, importer, _opt);
155 }
156 
157 
177 template <class Mesh>
178 bool
179 read_mesh(Mesh& _mesh,
180  std::istream& _is,
181  const std::string& _ext,
182  Options& _opt,
183  bool _clear = true)
184 {
185  if (_clear) _mesh.clear();
186  ImporterT<Mesh> importer(_mesh);
187  return IOManager().read(_is,_ext, importer, _opt);
188 }
189 
190 
191 
192 //-----------------------------------------------------------------------------
193 
194 
211 template <class Mesh>
212 bool write_mesh(const Mesh& _mesh,
213  const std::string& _filename,
214  Options _opt = Options::Default,
215  std::streamsize _precision = 6)
216 {
217  ExporterT<Mesh> exporter(_mesh);
218  return IOManager().write(_filename, exporter, _opt, _precision);
219 }
220 
221 
222 //-----------------------------------------------------------------------------
223 
224 
243 template <class Mesh>
244 bool write_mesh(const Mesh& _mesh,
245  std::ostream& _os,
246  const std::string& _ext,
247  Options _opt = Options::Default,
248  std::streamsize _precision = 6)
249 {
250  ExporterT<Mesh> exporter(_mesh);
251  return IOManager().write(_os,_ext, exporter, _opt, _precision);
252 }
253 
254 
255 //-----------------------------------------------------------------------------
256 
272 template <class Mesh>
273 size_t binary_size(const Mesh& _mesh,
274  const std::string& _ext,
275  Options _opt = Options::Default)
276 {
277  ExporterT<Mesh> exporter(_mesh);
278  return IOManager().binary_size(_ext, exporter, _opt);
279 }
280 
281 
282 //-----------------------------------------------------------------------------
283 
285 
286 
287 //=============================================================================
288 } // namespace IO
289 } // namespace OpenMesh
290 //=============================================================================
291 #if defined(OM_STATIC_BUILD) || defined(ARCH_DARWIN)
292 # include <OpenMesh/Core/IO/IOInstances.hh>
293 #endif
294 //=============================================================================
295 #endif
296 //=============================================================================
size_t binary_size(const Mesh &_mesh, const std::string &_ext, Options _opt=Options::Default)
Get binary size of data.
Definition: MeshIO.hh:273
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
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:212
This class template provides an exporter module for OpenMesh meshes.
Definition: ExporterT.hh:87
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 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:117

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