OpenMesh
|
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: 362 $ * 00038 * $Date: 2011-01-26 10:21:12 +0100 (Mi, 26 Jan 2011) $ * 00039 * * 00040 \*===========================================================================*/ 00041 00042 00043 //============================================================================= 00044 // 00045 // Implements a reader module for OFF files 00046 // 00047 //============================================================================= 00048 00049 00050 #ifndef __OMREADER_HH__ 00051 #define __OMREADER_HH__ 00052 00053 00054 //=== INCLUDES ================================================================ 00055 00056 // OpenMesh 00057 #include <OpenMesh/Core/System/config.h> 00058 #include <OpenMesh/Core/Utils/SingletonT.hh> 00059 #include <OpenMesh/Core/IO/OMFormat.hh> 00060 #include <OpenMesh/Core/IO/IOManager.hh> 00061 #include <OpenMesh/Core/IO/importer/BaseImporter.hh> 00062 #include <OpenMesh/Core/IO/reader/BaseReader.hh> 00063 00064 // STD C++ 00065 #include <iostream> 00066 #include <string> 00067 00068 00069 //== NAMESPACES =============================================================== 00070 00071 00072 namespace OpenMesh { 00073 namespace IO { 00074 00075 00076 //== IMPLEMENTATION =========================================================== 00077 00078 00083 class _OMReader_ : public BaseReader 00084 { 00085 public: 00086 00087 _OMReader_(); 00088 virtual ~_OMReader_() { } 00089 00090 std::string get_description() const { return "OpenMesh File Format"; } 00091 std::string get_extensions() const { return "om"; } 00092 std::string get_magic() const { return "OM"; } 00093 00094 bool read(const std::string& _filename, 00095 BaseImporter& _bi, 00096 Options& _opt ); 00097 00099 bool read(std::istream& _is, 00100 BaseImporter& _bi, 00101 Options& _opt ); 00102 00103 virtual bool can_u_read(const std::string& _filename) const; 00104 virtual bool can_u_read(std::istream& _is) const; 00105 00106 00107 private: 00108 00109 bool supports( const OMFormat::uint8 version ) const; 00110 00111 bool read_ascii(std::istream& _is, BaseImporter& _bi, Options& _opt) const; 00112 bool read_binary(std::istream& _is, BaseImporter& _bi, Options& _opt) const; 00113 00114 typedef OMFormat::Header Header; 00115 typedef OMFormat::Chunk::Header ChunkHeader; 00116 typedef OMFormat::Chunk::PropertyName PropertyName; 00117 00118 // initialized/updated by read_binary*/read_ascii* 00119 mutable size_t bytes_; 00120 mutable Header header_; 00121 mutable ChunkHeader chunk_header_; 00122 mutable PropertyName property_name_; 00123 00124 bool read_binary_vertex_chunk( std::istream &_is, 00125 BaseImporter &_bi, 00126 Options &_opt, 00127 bool _swap) const; 00128 00129 bool read_binary_face_chunk( std::istream &_is, 00130 BaseImporter &_bi, 00131 Options &_opt, 00132 bool _swap) const; 00133 00134 bool read_binary_edge_chunk( std::istream &_is, 00135 BaseImporter &_bi, 00136 Options &_opt, 00137 bool _swap) const; 00138 00139 bool read_binary_halfedge_chunk( std::istream &_is, 00140 BaseImporter &_bi, 00141 Options &_opt, 00142 bool _swap) const; 00143 00144 bool read_binary_mesh_chunk( std::istream &_is, 00145 BaseImporter &_bi, 00146 Options &_opt, 00147 bool _swap) const; 00148 00149 size_t restore_binary_custom_data( std::istream& _is, 00150 BaseProperty* _bp, 00151 size_t _n_elem, 00152 bool _swap) const; 00153 00154 }; 00155 00156 00157 //== TYPE DEFINITION ========================================================== 00158 00159 00161 extern _OMReader_ __OMReaderInstance; 00162 _OMReader_& OMReader(); 00163 00164 00165 //============================================================================= 00166 } // namespace IO 00167 } // namespace OpenMesh 00168 //============================================================================= 00169 #endif 00170 //=============================================================================