OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  * $Revision$ *
45  * $Date$ *
46  * *
47 \*===========================================================================*/
48 
49 //=============================================================================
50 //
51 // Implements the OpenMesh IOManager singleton
52 //
53 //=============================================================================
54 
55 #ifndef __IOMANAGER_HH__
56 #define __IOMANAGER_HH__
57 
58 
59 //=== INCLUDES ================================================================
60 
61 
62 // STL
63 #include <iosfwd>
64 #include <sstream>
65 #include <string>
66 #include <set>
67 
68 // OpenMesh
69 #include <OpenMesh/Core/System/config.h>
70 #include <OpenMesh/Core/IO/Options.hh>
71 #include <OpenMesh/Core/IO/reader/BaseReader.hh>
72 #include <OpenMesh/Core/IO/writer/BaseWriter.hh>
73 #include <OpenMesh/Core/IO/importer/BaseImporter.hh>
74 #include <OpenMesh/Core/IO/exporter/BaseExporter.hh>
75 #include <OpenMesh/Core/Utils/SingletonT.hh>
76 
77 
78 //== NAMESPACES ===============================================================
79 
80 
81 namespace OpenMesh {
82 namespace IO {
83 
84 
85 //=== IMPLEMENTATION ==========================================================
86 
87 
107 class OPENMESHDLLEXPORT _IOManager_
108 {
109 private:
110 
112  _IOManager_() {}
113 
115  ~_IOManager_() {};
116 
120  friend OPENMESHDLLEXPORT _IOManager_& IOManager();
121 
122 public:
123 
130  bool read(const std::string& _filename,
131  BaseImporter& _bi,
132  Options& _opt);
133 
140  bool read(std::istream& _filename,
141  const std::string& _ext,
142  BaseImporter& _bi,
143  Options& _opt);
144 
145 
152  bool write(const std::string& _filename,
153  BaseExporter& _be,
155  std::streamsize _precision = 6);
156 
163  bool write(std::ostream& _filename,
164  const std::string& _ext,
165  BaseExporter& _be,
167  std::streamsize _precision = 6);
168 
169 
171  bool can_read( const std::string& _format ) const;
172 
174  bool can_write( const std::string& _format ) const;
175 
176 
177  size_t binary_size(const std::string& _format,
178  BaseExporter& _be,
179  Options _opt = Options::Default)
180  {
181  const BaseWriter *bw = find_writer(_format);
182  return bw ? bw->binary_size(_be,_opt) : 0;
183  }
184 
185 
186 
187 public: //-- QT convenience function ------------------------------------------
188 
189 
194  const std::string& qt_read_filters() const { return read_filters_; }
195 
196 
201  const std::string& qt_write_filters() const { return write_filters_; }
202 
203 
204 
205 private:
206 
207  // collect all readable file extensions
208  void update_read_filters();
209 
210 
211  // collect all writeable file extensions
212  void update_write_filters();
213 
214 
215 
216 public: //-- SYSTEM PART------------------------------------------------------
217 
218 
223  {
224  reader_modules_.insert(_bl);
225  update_read_filters();
226  return true;
227  }
228 
229 
230 
235  {
236  writer_modules_.insert(_bw);
237  update_write_filters();
238  return true;
239  }
240 
241 
242 private:
243 
244  const BaseWriter *find_writer(const std::string& _format);
245 
246  // stores registered reader modules
247  std::set<BaseReader*> reader_modules_;
248 
249  // stores registered writer modules
250  std::set<BaseWriter*> writer_modules_;
251 
252  // input filters (e.g. for Qt file dialog)
253  std::string read_filters_;
254 
255  // output filters (e.g. for Qt file dialog)
256  std::string write_filters_;
257 };
258 
259 
260 //=============================================================================
261 
262 
263 //_IOManager_* __IOManager_instance; Causes memory leak, as destructor is never called
264 
265 OPENMESHDLLEXPORT _IOManager_& IOManager();
266 
267 //=============================================================================
268 } // namespace IO
269 } // namespace OpenMesh
270 //=============================================================================
271 #endif
272 //=============================================================================
virtual size_t binary_size(BaseExporter &, Options) const
Returns expected size of file if binary format is supported else 0.
Definition: BaseWriter.hh:133
size_t binary_size(const Mesh &_mesh, const std::string &_ext, Options _opt=Options::Default)
Get binary size of data.
Definition: MeshIO.hh:260
Set options for reader/writer modules.
Definition: Options.hh:95
bool register_module(BaseReader *_bl)
Registers a new reader module.
Definition: IOManager.hh:222
Base class for reader modules.
Definition: BaseReader.hh:94
No options.
Definition: Options.hh:104
Base class for all writer modules.
Definition: BaseWriter.hh:88
bool register_module(BaseWriter *_bw)
Registers a new writer module.
Definition: IOManager.hh:234
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
Base class for importer modules.
Definition: BaseImporter.hh:88
Base class for exporter modules.
Definition: BaseExporter.hh:89
const std::string & qt_read_filters() const
Returns all readable file extension + descriptions in one string.
Definition: IOManager.hh:194
const std::string & qt_write_filters() const
Returns all writeable file extension + descriptions in one string.
Definition: IOManager.hh:201
This is the real IOManager class that is later encapsulated by SingletonT to enforce its uniqueness...
Definition: IOManager.hh:107

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