Developer Documentation
BaseWriter.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 the baseclass for IOManager writer modules
48 //
49 //=============================================================================
50 
51 
52 #ifndef __BASEWRITER_HH__
53 #define __BASEWRITER_HH__
54 
55 
56 //=== INCLUDES ================================================================
57 
58 
59 // STD C++
60 #include <iosfwd>
61 #include <string>
62 
63 // OpenMesh
65 #include <OpenMesh/Core/IO/Options.hh>
66 #include <OpenMesh/Core/IO/exporter/BaseExporter.hh>
67 
68 
69 //== NAMESPACES ===============================================================
70 
71 
72 namespace OpenMesh {
73 namespace IO {
74 
75 
76 //=== IMPLEMENTATION ==========================================================
77 
78 
83 class OPENMESHDLLEXPORT BaseWriter
84 {
85 public:
86 
87  typedef unsigned int Option;
88 
90  virtual ~BaseWriter() {};
91 
93  virtual std::string get_description() const = 0;
94 
96  virtual std::string get_extensions() const = 0;
97 
103  virtual bool can_u_write(const std::string& _filename) const;
104 
111  virtual bool write(const std::string& _filename,
112  BaseExporter& _be,
113  Options _opt,
114  std::streamsize _precision = 6) const = 0;
115 
122  virtual bool write(std::ostream& _os,
123  BaseExporter& _be,
124  Options _opt,
125  std::streamsize _precision = 6) const = 0;
126 
128  virtual size_t binary_size(BaseExporter&, Options) const { return 0; }
129 
130 
131 
132 protected:
133 
134  bool check(BaseExporter& _be, Options _opt) const
135  {
136  // Check for all Options. When we want to write them (_opt.check() ) , they have to be available ( has_ )
137  // Converts to not A (write them) or B (available)
138  return ( !_opt.check(Options::VertexNormal ) || _be.has_vertex_normals())
139  && ( !_opt.check(Options::VertexTexCoord)|| _be.has_vertex_texcoords())
140  && ( !_opt.check(Options::VertexColor) || _be.has_vertex_colors())
141  && ( !_opt.check(Options::FaceNormal) || _be.has_face_normals())
142  && ( !_opt.check(Options::FaceColor) || _be.has_face_colors());
143  }
144 };
145 
146 
147 //=============================================================================
148 } // namespace IO
149 } // namespace OpenMesh
150 //=============================================================================
151 #endif
152 //=============================================================================
virtual size_t binary_size(BaseExporter &, Options) const
Returns expected size of file if binary format is supported else 0.
Definition: BaseWriter.hh:128
Has (r) / store (w) vertex colors.
Definition: Options.hh:105
Has (r) / store (w) face colors.
Definition: Options.hh:109
virtual ~BaseWriter()
Destructor.
Definition: BaseWriter.hh:90
Set options for reader/writer modules.
Definition: Options.hh:90
Has (r) / store (w) vertex normals.
Definition: Options.hh:104
Has (r) / store (w) face normals.
Definition: Options.hh:108
Has (r) / store (w) texture coordinates.
Definition: Options.hh:106