OpenMesh
Options.hh
1 /* ========================================================================= *
2  * *
3  * OpenMesh *
4  * Copyright (c) 2001-2022, 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 #ifndef OPENMESH_IO_OPTIONS_HH
46 #define OPENMESH_IO_OPTIONS_HH
47 
48 
49 //=== INCLUDES ================================================================
50 
51 
52 // OpenMesh
53 #include <OpenMesh/Core/System/config.h>
54 
55 
56 //== NAMESPACES ==============================================================
57 
58 
59 namespace OpenMesh {
60 namespace IO {
61 
62 
63 //=== IMPLEMENTATION ==========================================================
64 
65 
70 
71 
72 //-----------------------------------------------------------------------------
73 
90 class Options
91 {
92 public:
93  typedef int enum_type;
94  typedef enum_type value_type;
95 
98  enum Flag {
99  Default = 0x0000,
100  Binary = 0x0001,
101  MSB = 0x0002,
102  LSB = 0x0004,
103  Swap = 0x0008,
104  VertexNormal = 0x0010,
105  VertexColor = 0x0020,
106  VertexTexCoord = 0x0040,
107  EdgeColor = 0x0080,
108  FaceNormal = 0x0100,
109  FaceColor = 0x0200,
110  FaceTexCoord = 0x0400,
111  ColorAlpha = 0x0800,
112  ColorFloat = 0x1000,
113  Custom = 0x2000,
114  Status = 0x4000,
115  TexCoordST = 0x8000
116  };
117 
118 public:
119 
121  Options() : flags_( Default )
122  { }
123 
124 
126  Options(const Options& _opt) : flags_(_opt.flags_)
127  { }
128 
129 
131  Options(Flag _flg) : flags_( _flg)
132  { }
133 
134 
136  Options(const value_type _flgs) : flags_( _flgs)
137  { }
138 
139 
140  ~Options()
141  { }
142 
144  void cleanup(void)
145  { flags_ = Default; }
146 
148  void clear(void)
149  { flags_ = 0; }
150 
152  bool is_empty(void) const { return !flags_; }
153 
154 public:
155 
156 
158 
160  Options& operator = ( const Options& _rhs )
161  { flags_ = _rhs.flags_; return *this; }
162 
163  Options& operator = ( const value_type _rhs )
164  { flags_ = _rhs; return *this; }
165 
167 
168 
170 
172  Options& operator -= ( const value_type _rhs )
173  { flags_ &= ~_rhs; return *this; }
174 
175  Options& unset( const value_type _rhs)
176  { return (*this -= _rhs); }
177 
179 
180 
181 
183 
185  Options& operator += ( const value_type _rhs )
186  { flags_ |= _rhs; return *this; }
187 
188  Options& set( const value_type _rhs)
189  { return (*this += _rhs); }
190 
192 
193 public:
194 
195 
196  // Check if an option or several options are set.
197  bool check(const value_type _rhs) const
198  {
199  return (flags_ & _rhs)==_rhs;
200  }
201 
202  bool is_binary() const { return check(Binary); }
203  bool vertex_has_normal() const { return check(VertexNormal); }
204  bool vertex_has_color() const { return check(VertexColor); }
205  bool vertex_has_texcoord() const { return check(VertexTexCoord); }
206  bool vertex_has_status() const { return check(Status); }
207  bool edge_has_color() const { return check(EdgeColor); }
208  bool edge_has_status() const { return check(Status); }
209  bool halfedge_has_status() const { return check(Status); }
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 face_has_status() const { return check(Status); }
214  bool color_has_alpha() const { return check(ColorAlpha); }
215  bool color_is_float() const { return check(ColorFloat); }
216  bool use_st_coordinates() const { return check(TexCoordST); }
217 
218 
220  bool operator == (const value_type _rhs) const
221  { return flags_ == _rhs; }
222 
223 
225  bool operator != (const value_type _rhs) const
226  { return flags_ != _rhs; }
227 
228 
230  operator value_type () const { return flags_; }
231 
232 private:
233 
234  bool operator && (const value_type _rhs) const;
235 
236  value_type flags_;
237 };
238 
239 //-----------------------------------------------------------------------------
240 
241 
242 
243 
245 
246 
247 //=============================================================================
248 } // namespace IO
249 } // namespace OpenMesh
250 //=============================================================================
251 #endif
252 //=============================================================================
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
Set options for reader/writer modules.
Definition: Options.hh:91
Options(const value_type _flgs)
Initializing constructor setting multiple options.
Definition: Options.hh:136
bool operator!=(const value_type _rhs) const
Returns true if _rhs does not have the same options enabled.
Definition: Options.hh:225
void cleanup(void)
Restore state after default constructor.
Definition: Options.hh:144
bool is_empty(void) const
Returns true if all bits are zero.
Definition: Options.hh:152
bool operator==(const value_type _rhs) const
Returns true if _rhs has the same options enabled.
Definition: Options.hh:220
void clear(void)
Clear all bits.
Definition: Options.hh:148
Options()
Default constructor.
Definition: Options.hh:121
Flag
Definitions of Options for reading and writing.
Definition: Options.hh:98
@ ColorFloat
Has (r) / store (w) float values for colors (currently only implemented for PLY and OFF files)
Definition: Options.hh:112
@ FaceNormal
Has (r) / store (w) face normals.
Definition: Options.hh:108
@ TexCoordST
Write texture coordinates as ST instead of UV.
Definition: Options.hh:115
@ Swap
Swap byte order in binary mode.
Definition: Options.hh:103
@ FaceColor
Has (r) / store (w) face colors.
Definition: Options.hh:109
@ FaceTexCoord
Has (r) / store (w) face texture coordinates.
Definition: Options.hh:110
@ MSB
Assume big endian byte ordering.
Definition: Options.hh:101
@ Binary
Set binary mode for r/w.
Definition: Options.hh:100
@ Default
No options.
Definition: Options.hh:99
@ Status
Has (r) / store (w) status properties.
Definition: Options.hh:114
@ ColorAlpha
Has (r) / store (w) alpha values for colors.
Definition: Options.hh:111
@ LSB
Assume little endian byte ordering.
Definition: Options.hh:102
@ VertexNormal
Has (r) / store (w) vertex normals.
Definition: Options.hh:104
@ VertexTexCoord
Has (r) / store (w) texture coordinates.
Definition: Options.hh:106
@ EdgeColor
Has (r) / store (w) edge colors.
Definition: Options.hh:107
@ VertexColor
Has (r) / store (w) vertex colors.
Definition: Options.hh:105
@ Custom
Has (r) custom properties (currently only implemented in PLY Reader ASCII version)
Definition: Options.hh:113
Options & operator+=(const value_type _rhs)
Set options defined in _rhs.
Definition: Options.hh:185
Options(Flag _flg)
Initializing constructor setting a single option.
Definition: Options.hh:131
Options & operator-=(const value_type _rhs)
Unset options defined in _rhs.
Definition: Options.hh:172
Options(const Options &_opt)
Copy constructor.
Definition: Options.hh:126
Options & operator=(const Options &_rhs)
Copy options defined in _rhs.
Definition: Options.hh:160

Project OpenMesh, ©  Visual Computing Institute, RWTH Aachen. Documentation generated using doxygen .