OpenMesh
OpenMesh/Core/IO/MeshIO.hh
00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                               OpenMesh                                    *
00004  *      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openmesh.org                                *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------* 
00008  *  This file is part of OpenMesh.                                           *
00009  *                                                                           *
00010  *  OpenMesh is free software: you can redistribute it and/or modify         * 
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenMesh is distributed in the hope that it will be useful,              *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenMesh.  If not,                                    *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/ 
00034 
00035 /*===========================================================================*\
00036  *                                                                           *             
00037  *   $Revision: 425 $                                                         *
00038  *   $Date: 2011-10-10 14:31:03 +0200 (Mo, 10 Okt 2011) $                   *
00039  *                                                                           *
00040 \*===========================================================================*/
00041 
00042 
00043 #ifndef OM_MESHIO_HH
00044 #define OM_MESHIO_HH
00045 
00046 
00047 //=== INCLUDES ================================================================
00048 
00049 // -------------------- system settings
00050 #include <OpenMesh/Core/System/config.h>
00051 // -------------------- check include order
00052 #if defined (OPENMESH_TRIMESH_ARRAY_KERNEL_HH) || \
00053     defined (OPENMESH_POLYMESH_ARRAY_KERNEL_HH)
00054 #  error "Include MeshIO.hh before including a mesh type!"
00055 #endif
00056 // -------------------- OpenMesh
00057 #include <OpenMesh/Core/IO/SR_store.hh>
00058 #include <OpenMesh/Core/IO/IOManager.hh>
00059 #include <OpenMesh/Core/IO/importer/ImporterT.hh>
00060 #include <OpenMesh/Core/IO/exporter/ExporterT.hh>
00061 
00062 
00063 //== NAMESPACES ==============================================================
00064 
00065 namespace OpenMesh {
00066 namespace IO   {
00067 
00068 
00069 //=== IMPLEMENTATION ==========================================================
00070 
00071 
00077 
00078 
00079 //-----------------------------------------------------------------------------
00080 
00081 
00097 template <class Mesh>
00098 bool 
00099 read_mesh(Mesh&         _mesh,
00100           const std::string&  _filename, 
00101           bool                _clear = true) 
00102 {
00103   Options opt;
00104   return read_mesh(_mesh, _filename, opt, _clear);
00105 }
00106 
00107 
00125 template <class Mesh>
00126 bool 
00127 read_mesh(Mesh&         _mesh,
00128           const std::string&  _filename, 
00129           Options&            _opt, 
00130           bool                _clear = true) 
00131 {
00132   if (_clear) _mesh.clear();
00133   ImporterT<Mesh> importer(_mesh);
00134   return IOManager().read(_filename, importer, _opt); 
00135 }
00136 
00137 
00157 template <class Mesh>
00158 bool 
00159 read_mesh(Mesh&         _mesh,
00160           std::istream&       _is,
00161           const std::string&  _ext,
00162           Options&            _opt, 
00163           bool                _clear = true) 
00164 {
00165   if (_clear) _mesh.clear();
00166   ImporterT<Mesh> importer(_mesh);
00167   return IOManager().read(_is,_ext, importer, _opt); 
00168 }
00169 
00170 
00171 
00172 //-----------------------------------------------------------------------------
00173 
00174 
00190 template <class Mesh>
00191 bool write_mesh(const Mesh&        _mesh, 
00192                 const std::string& _filename,
00193                 Options            _opt = Options::Default) 
00194 { 
00195   ExporterT<Mesh> exporter(_mesh);
00196   return IOManager().write(_filename, exporter, _opt); 
00197 }
00198 
00199 
00200 //-----------------------------------------------------------------------------
00201 
00202 
00220 template <class Mesh>
00221 bool write_mesh(const Mesh&        _mesh, 
00222                             std::ostream&      _os,
00223                             const std::string& _ext,
00224                 Options            _opt = Options::Default) 
00225 { 
00226   ExporterT<Mesh> exporter(_mesh);
00227   return IOManager().write(_os,_ext, exporter, _opt); 
00228 }
00229 
00230 
00231 //-----------------------------------------------------------------------------
00232 
00248 template <class Mesh>
00249 size_t binary_size(const Mesh&        _mesh, 
00250                    const std::string& _ext,
00251                    Options            _opt = Options::Default)
00252 {
00253   ExporterT<Mesh> exporter(_mesh);
00254   return IOManager().binary_size(_ext, exporter, _opt);
00255 }
00256 
00257 
00258 //-----------------------------------------------------------------------------
00259 
00261 
00262 
00263 //=============================================================================
00264 } // namespace IO
00265 } // namespace OpenMesh
00266 //=============================================================================
00267 #if defined(OM_STATIC_BUILD) || defined(ARCH_DARWIN)
00268 #  include <OpenMesh/Core/IO/IOInstances.hh>
00269 #endif
00270 //=============================================================================
00271 #endif
00272 //=============================================================================