OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
IOManager.hh
1 /*===========================================================================*\
2  * *
3  * OpenMesh *
4  * Copyright (C) 2001-2014 by Computer Graphics Group, RWTH Aachen *
5  * www.openmesh.org *
6  * *
7  *---------------------------------------------------------------------------*
8  * This file is part of OpenMesh. *
9  * *
10  * OpenMesh is free software: you can redistribute it and/or modify *
11  * it under the terms of the GNU Lesser General Public License as *
12  * published by the Free Software Foundation, either version 3 of *
13  * the License, or (at your option) any later version with the *
14  * following exceptions: *
15  * *
16  * If other files instantiate templates or use macros *
17  * or inline functions from this file, or you compile this file and *
18  * link it with other files to produce an executable, this file does *
19  * not by itself cause the resulting executable to be covered by the *
20  * GNU Lesser General Public License. This exception does not however *
21  * invalidate any other reasons why the executable file might be *
22  * covered by the GNU Lesser General Public License. *
23  * *
24  * OpenMesh is distributed in the hope that it will be useful, *
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27  * GNU Lesser General Public License for more details. *
28  * *
29  * You should have received a copy of the GNU LesserGeneral Public *
30  * License along with OpenMesh. If not, *
31  * see <http://www.gnu.org/licenses/>. *
32  * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36  * *
37  * $Revision: 990 $ *
38  * $Date: 2014-02-05 10:01:07 +0100 (Mi, 05 Feb 2014) $ *
39  * *
40 \*===========================================================================*/
41 
42 //=============================================================================
43 //
44 // Implements the OpenMesh IOManager singleton
45 //
46 //=============================================================================
47 
48 #ifndef __IOMANAGER_HH__
49 #define __IOMANAGER_HH__
50 
51 
52 //=== INCLUDES ================================================================
53 
54 
55 // STL
56 #include <iostream>
57 #include <sstream>
58 #include <string>
59 #include <set>
60 
61 // OpenMesh
62 #include <OpenMesh/Core/System/config.h>
63 #include <OpenMesh/Core/IO/Options.hh>
64 #include <OpenMesh/Core/IO/reader/BaseReader.hh>
65 #include <OpenMesh/Core/IO/writer/BaseWriter.hh>
66 #include <OpenMesh/Core/IO/importer/BaseImporter.hh>
67 #include <OpenMesh/Core/IO/exporter/BaseExporter.hh>
68 #include <OpenMesh/Core/Utils/SingletonT.hh>
69 
70 
71 //== NAMESPACES ===============================================================
72 
73 
74 namespace OpenMesh {
75 namespace IO {
76 
77 
78 //=== IMPLEMENTATION ==========================================================
79 
80 
100 class OPENMESHDLLEXPORT _IOManager_
101 {
102 private:
103 
105  _IOManager_() {}
106 
108  ~_IOManager_() {};
109 
113  friend OPENMESHDLLEXPORT _IOManager_& IOManager();
114 
115 public:
116 
123  bool read(const std::string& _filename,
124  BaseImporter& _bi,
125  Options& _opt);
126 
133  bool read(std::istream& _filename,
134  const std::string& _ext,
135  BaseImporter& _bi,
136  Options& _opt);
137 
138 
145  bool write(const std::string& _filename,
146  BaseExporter& _be,
148  std::streamsize _precision = 6);
149 
156  bool write(std::ostream& _filename,
157  const std::string& _ext,
158  BaseExporter& _be,
160  std::streamsize _precision = 6);
161 
162 
164  bool can_read( const std::string& _format ) const;
165 
167  bool can_write( const std::string& _format ) const;
168 
169 
170  size_t binary_size(const std::string& _format,
171  BaseExporter& _be,
172  Options _opt = Options::Default)
173  {
174  const BaseWriter *bw = find_writer(_format);
175  return bw ? bw->binary_size(_be,_opt) : 0;
176  }
177 
178 
179 
180 public: //-- QT convenience function ------------------------------------------
181 
182 
187  const std::string& qt_read_filters() const { return read_filters_; }
188 
189 
194  const std::string& qt_write_filters() const { return write_filters_; }
195 
196 
197 
198 private:
199 
200  // collect all readable file extensions
201  void update_read_filters();
202 
203 
204  // collect all writeable file extensions
205  void update_write_filters();
206 
207 
208 
209 public: //-- SYSTEM PART------------------------------------------------------
210 
211 
216  {
217  reader_modules_.insert(_bl);
218  update_read_filters();
219  return true;
220  }
221 
222 
223 
228  {
229  writer_modules_.insert(_bw);
230  update_write_filters();
231  return true;
232  }
233 
234 
235 private:
236 
237  const BaseWriter *find_writer(const std::string& _format);
238 
239  // stores registered reader modules
240  std::set<BaseReader*> reader_modules_;
241 
242  // stores registered writer modules
243  std::set<BaseWriter*> writer_modules_;
244 
245  // input filters (e.g. for Qt file dialog)
246  std::string read_filters_;
247 
248  // output filters (e.g. for Qt file dialog)
249  std::string write_filters_;
250 };
251 
252 
253 //=============================================================================
254 
255 
256 //_IOManager_* __IOManager_instance; Causes memory leak, as destructor is never called
257 
258 OPENMESHDLLEXPORT _IOManager_& IOManager();
259 
260 //=============================================================================
261 } // namespace IO
262 } // namespace OpenMesh
263 //=============================================================================
264 #endif
265 //=============================================================================
Base class for reader modules.
Definition: BaseReader.hh:86
Base class for importer modules.
Definition: BaseImporter.hh:81
No options.
Definition: Options.hh:97
Set options for reader/writer modules.
Definition: Options.hh:88
const std::string & qt_read_filters() const
Returns all readable file extension + descriptions in one string.
Definition: IOManager.hh:187
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:56
const std::string & qt_write_filters() const
Returns all writeable file extension + descriptions in one string.
Definition: IOManager.hh:194
size_t binary_size(const Mesh &_mesh, const std::string &_ext, Options _opt=Options::Default)
Get binary size of data.
Definition: MeshIO.hh:253
bool register_module(BaseReader *_bl)
Registers a new reader module.
Definition: IOManager.hh:215
Base class for exporter modules.
Definition: BaseExporter.hh:82
Base class for all writer modules.
Definition: BaseWriter.hh:81
This is the real IOManager class that is later encapsulated by SingletonT to enforce its uniqueness...
Definition: IOManager.hh:100
bool register_module(BaseWriter *_bw)
Registers a new writer module.
Definition: IOManager.hh:227
virtual size_t binary_size(BaseExporter &, Options) const
Returns expected size of file if binary format is supported else 0.
Definition: BaseWriter.hh:122

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