Developer Documentation
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 
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
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 
85 class OPENMESHDLLEXPORT _OMReader_ : public BaseReader
86 {
87 public:
88 
89  _OMReader_();
90  virtual ~_OMReader_() { }
91 
92  std::string get_description() const override { return "OpenMesh File Format"; }
93  std::string get_extensions() const override { return "om"; }
94  std::string get_magic() const override { return "OM"; }
95 
96  bool read(const std::string& _filename,
97  BaseImporter& _bi,
98  Options& _opt ) override;
99 
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 
165 OPENMESHDLLEXPORT _OMReader_& OMReader();
166 
167 
168 //=============================================================================
169 } // namespace IO
170 } // namespace OpenMesh
171 //=============================================================================
172 #endif
173 //=============================================================================
_OMReader_ __OMReaderInstance
Declare the single entity of the OM reader.
Definition: OMReader.cc:73
std::string get_magic() const override
Return magic bits used to determine file format.
Definition: OMReader.hh:94
std::string get_extensions() const override
Definition: OMReader.hh:93
Set options for reader/writer modules.
Definition: Options.hh:90
std::string get_description() const override
Returns a brief description of the file type that can be parsed.
Definition: OMReader.hh:92