OpenMesh
IOManager.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 // Implements the OpenMesh IOManager singleton
47 //
48 //=============================================================================
49 
50 #ifndef __IOMANAGER_HH__
51 #define __IOMANAGER_HH__
52 
53 
54 //=== INCLUDES ================================================================
55 
56 
57 // STL
58 #include <iosfwd>
59 #include <sstream>
60 #include <string>
61 #include <set>
62 
63 // OpenMesh
64 #include <OpenMesh/Core/System/config.h>
65 #include <OpenMesh/Core/IO/Options.hh>
66 #include <OpenMesh/Core/IO/reader/BaseReader.hh>
67 #include <OpenMesh/Core/IO/writer/BaseWriter.hh>
68 #include <OpenMesh/Core/IO/importer/BaseImporter.hh>
69 #include <OpenMesh/Core/IO/exporter/BaseExporter.hh>
70 #include <OpenMesh/Core/Utils/SingletonT.hh>
71 
72 
73 //== NAMESPACES ===============================================================
74 
75 
76 namespace OpenMesh {
77 namespace IO {
78 
79 
80 //=== IMPLEMENTATION ==========================================================
81 
82 
102 class OPENMESHDLLEXPORT _IOManager_
103 {
104 private:
105 
107  _IOManager_() {}
108 
110  ~_IOManager_() {};
111 
115  friend OPENMESHDLLEXPORT _IOManager_& IOManager();
116 
117 public:
118 
125  bool read(const std::string& _filename,
126  BaseImporter& _bi,
127  Options& _opt);
128 
135  bool read(std::istream& _filename,
136  const std::string& _ext,
137  BaseImporter& _bi,
138  Options& _opt);
139 
140 
147  bool write(const std::string& _filename,
148  BaseExporter& _be,
150  std::streamsize _precision = 6);
151 
158  bool write(std::ostream& _filename,
159  const std::string& _ext,
160  BaseExporter& _be,
162  std::streamsize _precision = 6);
163 
164 
166  bool can_read( const std::string& _format ) const;
167 
169  bool can_write( const std::string& _format ) const;
170 
171 
172  size_t binary_size(const std::string& _format,
173  BaseExporter& _be,
174  Options _opt = Options::Default)
175  {
176  const BaseWriter *bw = find_writer(_format);
177  return bw ? bw->binary_size(_be,_opt) : 0;
178  }
179 
180 
181 
182 public: //-- QT convenience function ------------------------------------------
183 
184 
189  const std::string& qt_read_filters() const { return read_filters_; }
190 
191 
196  const std::string& qt_write_filters() const { return write_filters_; }
197 
198 
199 
200 private:
201 
202  // collect all readable file extensions
203  void update_read_filters();
204 
205 
206  // collect all writeable file extensions
207  void update_write_filters();
208 
209 
210 
211 public: //-- SYSTEM PART------------------------------------------------------
212 
213 
218  {
219  reader_modules_.insert(_bl);
220  update_read_filters();
221  return true;
222  }
223 
224 
225 
230  {
231  writer_modules_.insert(_bw);
232  update_write_filters();
233  return true;
234  }
235 
236 
237 private:
238 
239  const BaseWriter *find_writer(const std::string& _format);
240 
241  // stores registered reader modules
242  std::set<BaseReader*> reader_modules_;
243 
244  // stores registered writer modules
245  std::set<BaseWriter*> writer_modules_;
246 
247  // input filters (e.g. for Qt file dialog)
248  std::string read_filters_;
249 
250  // output filters (e.g. for Qt file dialog)
251  std::string write_filters_;
252 };
253 
254 
255 //=============================================================================
256 
257 
258 //_IOManager_* __IOManager_instance; Causes memory leak, as destructor is never called
259 
260 OPENMESHDLLEXPORT _IOManager_& IOManager();
261 
262 //=============================================================================
263 } // namespace IO
264 } // namespace OpenMesh
265 //=============================================================================
266 #endif
267 //=============================================================================
No options.
Definition: Options.hh:99
size_t binary_size(const Mesh &_mesh, const std::string &_ext, Options _opt=Options::Default)
Get binary size of data.
Definition: MeshIO.hh:268
virtual size_t binary_size(BaseExporter &, Options) const
Returns expected size of file if binary format is supported else 0.
Definition: BaseWriter.hh:128
const std::string & qt_read_filters() const
Returns all readable file extension + descriptions in one string.
Definition: IOManager.hh:189
const std::string & qt_write_filters() const
Returns all writeable file extension + descriptions in one string.
Definition: IOManager.hh:196
Base class for exporter modules.
Definition: BaseExporter.hh:84
bool register_module(BaseReader *_bl)
Registers a new reader module.
Definition: IOManager.hh:217
Set options for reader/writer modules.
Definition: Options.hh:90
Base class for all writer modules.
Definition: BaseWriter.hh:83
Base class for importer modules.
Definition: BaseImporter.hh:83
bool register_module(BaseWriter *_bw)
Registers a new writer module.
Definition: IOManager.hh:229
This is the real IOManager class that is later encapsulated by SingletonT to enforce its uniqueness...
Definition: IOManager.hh:102
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
Base class for reader modules.
Definition: BaseReader.hh:86

Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .