OpenMesh
Options.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 #ifndef OPENMESH_IO_OPTIONS_HH
51 #define OPENMESH_IO_OPTIONS_HH
52 
53 
54 //=== INCLUDES ================================================================
55 
56 
57 // OpenMesh
58 #include <OpenMesh/Core/System/config.h>
59 
60 
61 //== NAMESPACES ==============================================================
62 
63 
64 namespace OpenMesh {
65 namespace IO {
66 
67 
68 //=== IMPLEMENTATION ==========================================================
69 
70 
75 
76 
77 //-----------------------------------------------------------------------------
78 
95 class Options
96 {
97 public:
98  typedef int enum_type;
99  typedef enum_type value_type;
100 
103  enum Flag {
104  Default = 0x0000,
105  Binary = 0x0001,
106  MSB = 0x0002,
107  LSB = 0x0004,
108  Swap = 0x0008,
109  VertexNormal = 0x0010,
110  VertexColor = 0x0020,
111  VertexTexCoord = 0x0040,
112  EdgeColor = 0x0080,
113  FaceNormal = 0x0100,
114  FaceColor = 0x0200,
115  FaceTexCoord = 0x0400,
116  ColorAlpha = 0x0800,
117  ColorFloat = 0x1000,
118  Custom = 0x2000
119  };
120 
121 public:
122 
124  Options() : flags_( Default )
125  { }
126 
127 
129  Options(const Options& _opt) : flags_(_opt.flags_)
130  { }
131 
132 
134  Options(Flag _flg) : flags_( _flg)
135  { }
136 
137 
139  Options(const value_type _flgs) : flags_( _flgs)
140  { }
141 
142 
143  ~Options()
144  { }
145 
147  void cleanup(void)
148  { flags_ = Default; }
149 
151  void clear(void)
152  { flags_ = 0; }
153 
155  bool is_empty(void) const { return !flags_; }
156 
157 public:
158 
159 
161 
163  Options& operator = ( const Options& _rhs )
164  { flags_ = _rhs.flags_; return *this; }
165 
166  Options& operator = ( const value_type _rhs )
167  { flags_ = _rhs; return *this; }
168 
170 
171 
173 
175  Options& operator -= ( const value_type _rhs )
176  { flags_ &= ~_rhs; return *this; }
177 
178  Options& unset( const value_type _rhs)
179  { return (*this -= _rhs); }
180 
182 
183 
184 
186 
188  Options& operator += ( const value_type _rhs )
189  { flags_ |= _rhs; return *this; }
190 
191  Options& set( const value_type _rhs)
192  { return (*this += _rhs); }
193 
195 
196 public:
197 
198 
199  // Check if an option or several options are set.
200  bool check(const value_type _rhs) const
201  {
202  return (flags_ & _rhs)==_rhs;
203  }
204 
205  bool is_binary() const { return check(Binary); }
206  bool vertex_has_normal() const { return check(VertexNormal); }
207  bool vertex_has_color() const { return check(VertexColor); }
208  bool vertex_has_texcoord() const { return check(VertexTexCoord); }
209  bool edge_has_color() const { return check(EdgeColor); }
210  bool face_has_normal() const { return check(FaceNormal); }
211  bool face_has_color() const { return check(FaceColor); }
212  bool face_has_texcoord() const { return check(FaceTexCoord); }
213  bool color_has_alpha() const { return check(ColorAlpha); }
214  bool color_is_float() const { return check(ColorFloat); }
215 
216 
218  bool operator == (const value_type _rhs) const
219  { return flags_ == _rhs; }
220 
221 
223  bool operator != (const value_type _rhs) const
224  { return flags_ != _rhs; }
225 
226 
228  operator value_type () const { return flags_; }
229 
230 private:
231 
232  bool operator && (const value_type _rhs) const;
233 
234  value_type flags_;
235 };
236 
237 //-----------------------------------------------------------------------------
238 
239 
240 
241 
243 
244 
245 //=============================================================================
246 } // namespace IO
247 } // namespace OpenMesh
248 //=============================================================================
249 #endif
250 //=============================================================================
void cleanup(void)
Restore state after default constructor.
Definition: Options.hh:147
Flag
Definitions of Options for reading and writing.
Definition: Options.hh:103
void clear(void)
Clear all bits.
Definition: Options.hh:151
Has (r) / store (w) face colors.
Definition: Options.hh:114
Has (r) custom properties (currently only implemented in PLY Reader ASCII version) ...
Definition: Options.hh:118
Options & unset(const value_type _rhs)
Unset options defined in _rhs.
Definition: Options.hh:178
bool operator==(const value_type _rhs) const
Returns true if _rhs has the same options enabled.
Definition: Options.hh:218
Has (r) / store (w) face normals.
Definition: Options.hh:113
bool is_empty(void) const
Returns true if all bits are zero.
Definition: Options.hh:155
Has (r) / store (w) float values for colors (currently only implemented for PLY and OFF files) ...
Definition: Options.hh:117
Options(Flag _flg)
Initializing constructor setting a single option.
Definition: Options.hh:134
Assume big endian byte ordering.
Definition: Options.hh:106
Swap byte order in binary mode.
Definition: Options.hh:108
Has (r) / store (w) vertex normals.
Definition: Options.hh:109
Set options for reader/writer modules.
Definition: Options.hh:95
Options & operator+=(const value_type _rhs)
Set options defined in _rhs.
Definition: Options.hh:188
No options.
Definition: Options.hh:104
Options(const Options &_opt)
Copy constructor.
Definition: Options.hh:129
Has (r) / store (w) texture coordinates.
Definition: Options.hh:111
Set binary mode for r/w.
Definition: Options.hh:105
Assume little endian byte ordering.
Definition: Options.hh:107
Has (r) / store (w) alpha values for colors.
Definition: Options.hh:116
Has (r) / store (w) face texture coordinates.
Definition: Options.hh:115
Options()
Default constructor.
Definition: Options.hh:124
Options & operator-=(const value_type _rhs)
Unset options defined in _rhs.
Definition: Options.hh:175
Options(const value_type _flgs)
Initializing constructor setting multiple options.
Definition: Options.hh:139
bool operator!=(const value_type _rhs) const
Returns true if _rhs does not have the same options enabled.
Definition: Options.hh:223
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
Options & operator=(const Options &_rhs)
Copy options defined in _rhs.
Definition: Options.hh:163
Has (r) / store (w) edge colors.
Definition: Options.hh:112
Has (r) / store (w) vertex colors.
Definition: Options.hh:110

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