00001 /*===========================================================================*\ 00002 * * 00003 * OpenMesh * 00004 * Copyright (C) 2001-2010 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: 325 $ * 00038 * $Date: 2010-06-17 12:45:58 +0200 (Do, 17 Jun 2010) $ * 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 00084 template <class Mesh> 00085 bool 00086 read_mesh(Mesh& _mesh, 00087 const std::string& _filename, 00088 bool _clear = true) 00089 { 00090 Options opt; 00091 return read_mesh(_mesh, _filename, opt, _clear); 00092 } 00093 00094 00097 template <class Mesh> 00098 bool 00099 read_mesh(Mesh& _mesh, 00100 const std::string& _filename, 00101 Options& _opt, 00102 bool _clear = true) 00103 { 00104 if (_clear) _mesh.clear(); 00105 ImporterT<Mesh> importer(_mesh); 00106 return IOManager().read(_filename, importer, _opt); 00107 } 00108 00109 00112 template <class Mesh> 00113 bool 00114 read_mesh(Mesh& _mesh, 00115 std::istream& _is, 00116 const std::string& _ext, 00117 Options& _opt, 00118 bool _clear = true) 00119 { 00120 if (_clear) _mesh.clear(); 00121 ImporterT<Mesh> importer(_mesh); 00122 return IOManager().read(_is,_ext, importer, _opt); 00123 } 00124 00125 00126 00127 //----------------------------------------------------------------------------- 00128 00129 00132 template <class Mesh> 00133 bool write_mesh(const Mesh& _mesh, const std::string& _filename, 00134 Options _opt = Options::Default) 00135 { 00136 ExporterT<Mesh> exporter(_mesh); 00137 return IOManager().write(_filename, exporter, _opt); 00138 } 00139 00140 00141 //----------------------------------------------------------------------------- 00142 00143 00146 template <class Mesh> 00147 bool write_mesh(const Mesh& _mesh, 00148 std::ostream& _os, 00149 const std::string& _ext, 00150 Options _opt = Options::Default) 00151 { 00152 ExporterT<Mesh> exporter(_mesh); 00153 return IOManager().write(_os,_ext, exporter, _opt); 00154 } 00155 00156 00157 //----------------------------------------------------------------------------- 00158 00159 00160 template <class Mesh> 00161 size_t binary_size(const Mesh& _mesh, const std::string& _format, 00162 Options _opt = Options::Default) 00163 { 00164 ExporterT<Mesh> exporter(_mesh); 00165 return IOManager().binary_size(_format, exporter, _opt); 00166 } 00167 00168 00169 //----------------------------------------------------------------------------- 00170 00172 00173 00174 //============================================================================= 00175 } // namespace IO 00176 } // namespace OpenMesh 00177 //============================================================================= 00178 #if defined(OM_STATIC_BUILD) || defined(ARCH_DARWIN) 00179 # include <OpenMesh/Core/IO/IOInstances.hh> 00180 #endif 00181 //============================================================================= 00182 #endif 00183 //=============================================================================