OpenMesh: OpenMesh/Core/IO/reader/OMReader.hh Source File

| OpenMesh

OMReader.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 //=============================================================================
51 //
52 // Implements a reader module for OFF files
53 //
54 //=============================================================================
55
56
57 #ifndef __OMREADER_HH__
58 #define __OMREADER_HH__
59
60
61 //=== INCLUDES ================================================================
62
63 // OpenMesh
64 #include <OpenMesh/Core/System/config.h>
65 #include <OpenMesh/Core/Utils/SingletonT.hh>
66 #include <OpenMesh/Core/IO/OMFormat.hh>
67 #include <OpenMesh/Core/IO/IOManager.hh>
68 #include <OpenMesh/Core/IO/importer/BaseImporter.hh>
69 #include <OpenMesh/Core/IO/reader/BaseReader.hh>
70
71 // STD C++
72 #include <iosfwd>
73 #include <string>
74
75
76 //== NAMESPACES ===============================================================
77
78
79 namespace OpenMesh {
80 namespace IO {
81
82
83 //== IMPLEMENTATION ===========================================================
84
85
90 class OPENMESHDLLEXPORT _OMReader_ : public BaseReader
91 {
92 public:
93
94 _OMReader_();
95 virtual ~_OMReader_() { }
96
97 std::string get_description() const { return "OpenMesh File Format"; }
98 std::string get_extensions() const { return "om"; }
99 std::string get_magic() const { return "OM"; }
100
101 bool read(const std::string& _filename,
102 BaseImporter& _bi,
103 Options& _opt );
104
106 bool read(std::istream& _is,
107 BaseImporter& _bi,
108 Options& _opt );
109
110 virtual bool can_u_read(const std::string& _filename) const;
111 virtual bool can_u_read(std::istream& _is) const;
112
113
114 private:
115
116 bool supports( const OMFormat::uint8 version ) const;
117
118 bool read_ascii(std::istream& _is, BaseImporter& _bi, Options& _opt) const;
119 bool read_binary(std::istream& _is, BaseImporter& _bi, Options& _opt) const;
120
121 typedef OMFormat::Header Header;
122 typedef OMFormat::Chunk::Header ChunkHeader;
123 typedef OMFormat::Chunk::PropertyName PropertyName;
124
125 // initialized/updated by read_binary*/read_ascii*
126 mutable size_t bytes_;
127 mutable Options fileOptions_;
128 mutable Header header_;
129 mutable ChunkHeader chunk_header_;
130 mutable PropertyName property_name_;
131
132 bool read_binary_vertex_chunk( std::istream &_is,
133 BaseImporter &_bi,
134 Options &_opt,
135 bool _swap) const;
136
137 bool read_binary_face_chunk( std::istream &_is,
138 BaseImporter &_bi,
139 Options &_opt,
140 bool _swap) const;
141
142 bool read_binary_edge_chunk( std::istream &_is,
143 BaseImporter &_bi,
144 Options &_opt,
145 bool _swap) const;
146
147 bool read_binary_halfedge_chunk( std::istream &_is,
148 BaseImporter &_bi,
149 Options &_opt,
150 bool _swap) const;
151
152 bool read_binary_mesh_chunk( std::istream &_is,
153 BaseImporter &_bi,
154 Options &_opt,
155 bool _swap) const;
156
157 size_t restore_binary_custom_data( std::istream& _is,
158 BaseProperty* _bp,
159 size_t _n_elem,
160 bool _swap) const;
161
162 };
163
164
165 //== TYPE DEFINITION ==========================================================
166
167
169 extern _OMReader_ __OMReaderInstance;
170 OPENMESHDLLEXPORT _OMReader_& OMReader();
171
172
173 //=============================================================================
174 } // namespace IO
175 } // namespace OpenMesh
176 //=============================================================================
177 #endif
178 //=============================================================================
OpenMesh::IO::BaseReader
Base class for reader modules.
Definition: BaseReader.hh:94
OpenMesh::IO::__OMReaderInstance
_OMReader_ __OMReaderInstance
Declare the single entity of the OM reader.
Definition: OMReader.cc:77
OpenMesh::IO::_OMReader_::get_magic
std::string get_magic() const
Return magic bits used to determine file format.
Definition: OMReader.hh:99
OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
OpenMesh::IO::_OMReader_::get_description
std::string get_description() const
Returns a brief description of the file type that can be parsed.
Definition: OMReader.hh:97
OpenMesh::IO::_OMReader_::get_extensions
std::string get_extensions() const
Returns a string with the accepted file extensions separated by a whitespace and in small caps...
Definition: OMReader.hh:98
OpenMesh::BaseProperty
Abstract class defining the basic interface of a dynamic property.
Definition: BaseProperty.hh:65
OpenMesh::IO::Options
Set options for reader/writer modules.
Definition: Options.hh:95
OpenMesh::IO::BaseImporter
Base class for importer modules.
Definition: BaseImporter.hh:88
OpenMesh::IO::_OMReader_
Implementation of the OM format reader.
Definition: OMReader.hh:90