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 //============================================================================= 46 // 47 // Implements a reader module for OFF files 48 // 49 //============================================================================= 50 51 52 #ifndef __OMREADER_HH__ 53 #define __OMREADER_HH__ 54 55 56 //=== INCLUDES ================================================================ 57 58 // OpenMesh 59 #include <OpenMesh/Core/System/config.h> 60 #include <OpenMesh/Core/Utils/SingletonT.hh> 61 #include <OpenMesh/Core/IO/OMFormat.hh> 62 #include <OpenMesh/Core/IO/IOManager.hh> 63 #include <OpenMesh/Core/IO/importer/BaseImporter.hh> 64 #include <OpenMesh/Core/IO/reader/BaseReader.hh> 65 66 // STD C++ 67 #include <iosfwd> 68 #include <string> 69 70 71 //== NAMESPACES =============================================================== 72 73 74 namespace OpenMesh { 75 namespace IO { 76 77 78 //== IMPLEMENTATION =========================================================== 79 80 81 /** 82 Implementation of the OM format reader. This class is singleton'ed by 83 SingletonT to OMReader. 84 */ 85 class OPENMESHDLLEXPORT _OMReader_ : public BaseReader 86 { 87 public: 88 89 _OMReader_(); ~_OMReader_()90 virtual ~_OMReader_() { } 91 get_description() const92 std::string get_description() const override { return "OpenMesh File Format"; } get_extensions() const93 std::string get_extensions() const override { return "om"; } get_magic() const94 std::string get_magic() const override { return "OM"; } 95 96 bool read(const std::string& _filename, 97 BaseImporter& _bi, 98 Options& _opt ) override; 99 100 //! Stream Reader for std::istream input in binary format 101 bool read(std::istream& _is, 102 BaseImporter& _bi, 103 Options& _opt ) override; 104 105 virtual bool can_u_read(const std::string& _filename) const override; 106 virtual bool can_u_read(std::istream& _is) const; 107 108 109 private: 110 111 bool supports( const OMFormat::uint8 version ) const; 112 113 bool read_ascii(std::istream& _is, BaseImporter& _bi, Options& _opt) const; 114 bool read_binary(std::istream& _is, BaseImporter& _bi, Options& _opt) const; 115 116 typedef OMFormat::Header Header; 117 typedef OMFormat::Chunk::Header ChunkHeader; 118 typedef OMFormat::Chunk::PropertyName PropertyName; 119 120 // initialized/updated by read_binary*/read_ascii* 121 mutable size_t bytes_; 122 mutable Options fileOptions_; 123 mutable Header header_; 124 mutable ChunkHeader chunk_header_; 125 mutable PropertyName property_name_; 126 127 bool read_binary_vertex_chunk( std::istream &_is, 128 BaseImporter &_bi, 129 Options &_opt, 130 bool _swap) const; 131 132 bool read_binary_face_chunk( std::istream &_is, 133 BaseImporter &_bi, 134 Options &_opt, 135 bool _swap) const; 136 137 bool read_binary_edge_chunk( std::istream &_is, 138 BaseImporter &_bi, 139 Options &_opt, 140 bool _swap) const; 141 142 bool read_binary_halfedge_chunk( std::istream &_is, 143 BaseImporter &_bi, 144 Options &_opt, 145 bool _swap) const; 146 147 bool read_binary_mesh_chunk( std::istream &_is, 148 BaseImporter &_bi, 149 Options &_opt, 150 bool _swap) const; 151 152 size_t restore_binary_custom_data( std::istream& _is, 153 BaseProperty* _bp, 154 size_t _n_elem, 155 bool _swap) const; 156 157 }; 158 159 160 //== TYPE DEFINITION ========================================================== 161 162 163 /// Declare the single entity of the OM reader. 164 extern _OMReader_ __OMReaderInstance; 165 OPENMESHDLLEXPORT _OMReader_& OMReader(); 166 167 168 //============================================================================= 169 } // namespace IO 170 } // namespace OpenMesh 171 //============================================================================= 172 #endif 173 //============================================================================= 174