Options.hh 9.23 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1
/* ========================================================================= *
Jan Möbius's avatar
Jan Möbius committed
2
3
 *                                                                           *
 *                               OpenMesh                                    *
Jan Möbius's avatar
Jan Möbius committed
4
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
Jan Möbius's avatar
Typo    
Jan Möbius committed
5
 *           Department of Computer Graphics and Multimedia                  *
Jan Möbius's avatar
Jan Möbius committed
6
7
 *                          All rights reserved.                             *
 *                            www.openmesh.org                               *
Jan Möbius's avatar
Jan Möbius committed
8
 *                                                                           *
9
 *---------------------------------------------------------------------------*
Jan Möbius's avatar
Jan Möbius committed
10
11
 * This file is part of OpenMesh.                                            *
 *---------------------------------------------------------------------------*
Jan Möbius's avatar
Jan Möbius committed
12
 *                                                                           *
Jan Möbius's avatar
Jan Möbius committed
13
14
15
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
Jan Möbius's avatar
Jan Möbius committed
16
 *                                                                           *
Jan Möbius's avatar
Jan Möbius committed
17
18
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
Jan Möbius's avatar
Jan Möbius committed
19
 *                                                                           *
Jan Möbius's avatar
Jan Möbius committed
20
21
22
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
Jan Möbius's avatar
Jan Möbius committed
23
 *                                                                           *
Jan Möbius's avatar
Jan Möbius committed
24
25
26
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
27
 *                                                                           *
Jan Möbius's avatar
Jan Möbius committed
28
29
30
31
32
33
34
35
36
37
38
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
Jan Möbius's avatar
Jan Möbius committed
39
40
 *                                                                           *
 * ========================================================================= */
41
42

/*===========================================================================*\
43
 *                                                                           *
44
45
 *   $Revision$                                                         *
 *   $Date$                   *
Jan Möbius's avatar
Jan Möbius committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
 *                                                                           *
\*===========================================================================*/


#ifndef OPENMESH_IO_OPTIONS_HH
#define OPENMESH_IO_OPTIONS_HH


//=== INCLUDES ================================================================


// OpenMesh
#include <OpenMesh/Core/System/config.h>


//== NAMESPACES ==============================================================


namespace OpenMesh {
namespace IO   {


//=== IMPLEMENTATION ==========================================================


/** \name Mesh Reading / Writing
    Option for reader and writer modules.
*/
//@{


//-----------------------------------------------------------------------------

/** \brief Set options for reader/writer modules.
 *
81
82
 *  The class is used in a twofold way.
 *  -# In combination with reader modules the class is used
Jan Möbius's avatar
Jan Möbius committed
83
84
85
86
87
 *     - to pass hints to the reading module, whether the input is
 *     binary and what byte ordering the binary data has
 *     - to retrieve information about the file contents after
 *     succesful reading.
 *  -# In combination with write modules the class gives directions to
88
 *     the writer module, whether to
Jan Möbius's avatar
Jan Möbius committed
89
90
91
 *     - use binary mode or not and what byte order to use
 *     - store one of the standard properties.
 *
92
 *  The option are defined in \c Options::Flag as bit values and stored in
Jan Möbius's avatar
Jan Möbius committed
93
94
95
96
97
98
99
 *  an \c int value as a bitset.
 */
class Options
{
public:
  typedef int       enum_type;
  typedef enum_type value_type;
100

Jan Möbius's avatar
Jan Möbius committed
101
102
103
  /// Definitions of %Options for reading and writing. The options can be
  /// or'ed.
  enum Flag {
104
105
106
107
      Default        = 0x0000, ///< No options
      Binary         = 0x0001, ///< Set binary mode for r/w
      MSB            = 0x0002, ///< Assume big endian byte ordering
      LSB            = 0x0004, ///< Assume little endian byte ordering
Jan Möbius's avatar
Jan Möbius committed
108
      Swap           = 0x0008, ///< Swap byte order in binary mode
109
110
111
      VertexNormal   = 0x0010, ///< Has (r) / store (w) vertex normals
      VertexColor    = 0x0020, ///< Has (r) / store (w) vertex colors
      VertexTexCoord = 0x0040, ///< Has (r) / store (w) texture coordinates
Mike Kremer's avatar
Mike Kremer committed
112
      EdgeColor      = 0x0080, ///< Has (r) / store (w) edge colors
113
114
      FaceNormal     = 0x0100, ///< Has (r) / store (w) face normals
      FaceColor      = 0x0200, ///< Has (r) / store (w) face colors
115
      FaceTexCoord   = 0x0400, ///< Has (r) / store (w) face texture coordinates
116
117
      ColorAlpha     = 0x0800, ///< Has (r) / store (w) alpha values for colors
      ColorFloat     = 0x1000, ///< Has (r) / store (w) float values for colors (currently only implemented for PLY and OFF files)
Max Lyon's avatar
Max Lyon committed
118
119
      Custom         = 0x2000, ///< Has (r)             custom properties (currently only implemented in PLY Reader ASCII version)
      Status         = 0x4000  ///< Has (r) / store (w) status properties
Jan Möbius's avatar
Jan Möbius committed
120
121
122
123
124
125
126
127
128
129
130
131
  };

public:

  /// Default constructor
  Options() : flags_( Default )
  { }


  /// Copy constructor
  Options(const Options& _opt) : flags_(_opt.flags_)
  { }
132

Jan Möbius's avatar
Jan Möbius committed
133
134
135
136
137

  /// Initializing constructor setting a single option
  Options(Flag _flg) : flags_( _flg)
  { }

138

Jan Möbius's avatar
Jan Möbius committed
139
140
141
142
  /// Initializing constructor setting multiple options
  Options(const value_type _flgs) : flags_( _flgs)
  { }

143

Jan Möbius's avatar
Jan Möbius committed
144
145
  ~Options()
  { }
146

Jan Möbius's avatar
Jan Möbius committed
147
148
149
150
151
152
153
154
155
156
157
158
  /// Restore state after default constructor.
  void cleanup(void)
  { flags_ = Default; }

  /// Clear all bits.
  void clear(void)
  { flags_ = 0; }

  /// Returns true if all bits are zero.
  bool is_empty(void) const { return !flags_; }

public:
159

Jan Möbius's avatar
Jan Möbius committed
160
161
162
163
164
165
166
167
168
169
170
171

  //@{
  /// Copy options defined in _rhs.

  Options& operator = ( const Options& _rhs )
  { flags_ = _rhs.flags_; return *this; }

  Options& operator = ( const value_type _rhs )
  { flags_ = _rhs; return *this; }

  //@}

172

Jan Möbius's avatar
Jan Möbius committed
173
174
175
176
177
178
179
  //@{
  /// Unset options defined in _rhs.

  Options& operator -= ( const value_type _rhs )
  { flags_ &= ~_rhs; return *this; }

  Options& unset( const value_type _rhs)
180
  { return (*this -= _rhs); }
Jan Möbius's avatar
Jan Möbius committed
181
182
183

  //@}

184

Jan Möbius's avatar
Jan Möbius committed
185
186
187

  //@{
  /// Set options defined in _rhs
188

Jan Möbius's avatar
Jan Möbius committed
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
  Options& operator += ( const value_type _rhs )
  { flags_ |= _rhs; return *this; }

  Options& set( const value_type _rhs)
  { return (*this += _rhs); }

  //@}

public:


  // Check if an option or several options are set.
  bool check(const value_type _rhs) const
  {
    return (flags_ & _rhs)==_rhs;
  }
205

Jan Möbius's avatar
Jan Möbius committed
206
207
208
209
  bool is_binary()           const { return check(Binary); }
  bool vertex_has_normal()   const { return check(VertexNormal); }
  bool vertex_has_color()    const { return check(VertexColor); }
  bool vertex_has_texcoord() const { return check(VertexTexCoord); }
Max Lyon's avatar
Max Lyon committed
210
  bool vertex_has_status()   const { return check(Status); }
211
  bool edge_has_color()      const { return check(EdgeColor); }
Max Lyon's avatar
Max Lyon committed
212
213
  bool edge_has_status()     const { return check(Status); }
  bool halfedge_has_status() const { return check(Status); }
Jan Möbius's avatar
Jan Möbius committed
214
215
  bool face_has_normal()     const { return check(FaceNormal); }
  bool face_has_color()      const { return check(FaceColor); }
216
  bool face_has_texcoord()   const { return check(FaceTexCoord); }
Max Lyon's avatar
Max Lyon committed
217
  bool face_has_status()     const { return check(Status); }
Jan Möbius's avatar
Jan Möbius committed
218
  bool color_has_alpha()     const { return check(ColorAlpha); }
219
  bool color_is_float()      const { return check(ColorFloat); }
Jan Möbius's avatar
Jan Möbius committed
220
221
222
223
224


  /// Returns true if _rhs has the same options enabled.
  bool operator == (const value_type _rhs) const
  { return flags_ == _rhs; }
225

Jan Möbius's avatar
Jan Möbius committed
226
227
228
229

  /// Returns true if _rhs does not have the same options enabled.
  bool operator != (const value_type _rhs) const
  { return flags_ != _rhs; }
230

Jan Möbius's avatar
Jan Möbius committed
231
232
233

  /// Returns the option set.
  operator value_type ()     const { return flags_; }
234

Jan Möbius's avatar
Jan Möbius committed
235
private:
236

Jan Möbius's avatar
Jan Möbius committed
237
  bool operator && (const value_type _rhs) const;
238

Jan Möbius's avatar
Jan Möbius committed
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
  value_type flags_;
};

//-----------------------------------------------------------------------------




//@}


//=============================================================================
} // namespace IO
} // namespace OpenMesh
//=============================================================================
#endif
//=============================================================================