Options.hh 8.38 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1 2 3
/*===========================================================================*\
 *                                                                           *
 *                               OpenMesh                                    *
4
 *      Copyright (C) 2001-2014 by Computer Graphics Group, RWTH Aachen      *
Jan Möbius's avatar
Jan Möbius committed
5 6
 *                           www.openmesh.org                                *
 *                                                                           *
7
 *---------------------------------------------------------------------------*
8
 *  This file is part of OpenMesh.                                           *
Jan Möbius's avatar
Jan Möbius committed
9
 *                                                                           *
10
 *  OpenMesh is free software: you can redistribute it and/or modify         *
11 12 13 14
 *  it under the terms of the GNU Lesser General Public License as           *
 *  published by the Free Software Foundation, either version 3 of           *
 *  the License, or (at your option) any later version with the              *
 *  following exceptions:                                                    *
Jan Möbius's avatar
Jan Möbius committed
15
 *                                                                           *
16 17 18 19 20 21 22
 *  If other files instantiate templates or use macros                       *
 *  or inline functions from this file, or you compile this file and         *
 *  link it with other files to produce an executable, this file does        *
 *  not by itself cause the resulting executable to be covered by the        *
 *  GNU Lesser General Public License. This exception does not however       *
 *  invalidate any other reasons why the executable file might be            *
 *  covered by the GNU Lesser General Public License.                        *
Jan Möbius's avatar
Jan Möbius committed
23
 *                                                                           *
24 25 26 27
 *  OpenMesh is distributed in the hope that it will be useful,              *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *  GNU Lesser General Public License for more details.                      *
Jan Möbius's avatar
Jan Möbius committed
28
 *                                                                           *
29 30 31 32
 *  You should have received a copy of the GNU LesserGeneral Public          *
 *  License along with OpenMesh.  If not,                                    *
 *  see <http://www.gnu.org/licenses/>.                                      *
 *                                                                           *
33
\*===========================================================================*/
34 35

/*===========================================================================*\
36
 *                                                                           *
37 38
 *   $Revision$                                                         *
 *   $Date$                   *
Jan Möbius's avatar
Jan Möbius committed
39 40 41 42 43 44 45 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
 *                                                                           *
\*===========================================================================*/


#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.
 *
74 75
 *  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
76 77 78 79 80
 *     - 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
81
 *     the writer module, whether to
Jan Möbius's avatar
Jan Möbius committed
82 83 84
 *     - use binary mode or not and what byte order to use
 *     - store one of the standard properties.
 *
85
 *  The option are defined in \c Options::Flag as bit values and stored in
Jan Möbius's avatar
Jan Möbius committed
86 87 88 89 90 91 92
 *  an \c int value as a bitset.
 */
class Options
{
public:
  typedef int       enum_type;
  typedef enum_type value_type;
93

Jan Möbius's avatar
Jan Möbius committed
94 95 96
  /// Definitions of %Options for reading and writing. The options can be
  /// or'ed.
  enum Flag {
97 98 99 100 101 102 103 104
      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
      Swap           = 0x0006, ///< Swap byte order in binary mode
      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
105
      EdgeColor      = 0x0080, ///< Has (r) / store (w) edge colors
106 107
      FaceNormal     = 0x0100, ///< Has (r) / store (w) face normals
      FaceColor      = 0x0200, ///< Has (r) / store (w) face colors
108
      FaceTexCoord   = 0x0400, ///< Has (r) / store (w) face texture coordinates
109 110 111
      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)
      Custom         = 0x2000  ///< Has (r)             custom properties (currently only implemented in PLY Reader ASCII version)
Jan Möbius's avatar
Jan Möbius committed
112 113 114 115 116 117 118 119 120 121 122 123
  };

public:

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


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

Jan Möbius's avatar
Jan Möbius committed
125 126 127 128 129

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

130

Jan Möbius's avatar
Jan Möbius committed
131 132 133 134
  /// Initializing constructor setting multiple options
  Options(const value_type _flgs) : flags_( _flgs)
  { }

135

Jan Möbius's avatar
Jan Möbius committed
136 137
  ~Options()
  { }
138

Jan Möbius's avatar
Jan Möbius committed
139 140 141 142 143 144 145 146 147 148 149 150
  /// 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:
151

Jan Möbius's avatar
Jan Möbius committed
152 153 154 155 156 157 158 159 160 161 162 163

  //@{
  /// 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; }

  //@}

164

Jan Möbius's avatar
Jan Möbius committed
165 166 167 168 169 170 171
  //@{
  /// Unset options defined in _rhs.

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

  Options& unset( const value_type _rhs)
172
  { return (*this -= _rhs); }
Jan Möbius's avatar
Jan Möbius committed
173 174 175

  //@}

176

Jan Möbius's avatar
Jan Möbius committed
177 178 179

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

Jan Möbius's avatar
Jan Möbius committed
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
  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;
  }
197

Jan Möbius's avatar
Jan Möbius committed
198 199 200 201
  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); }
202
  bool edge_has_color()      const { return check(EdgeColor); }
Jan Möbius's avatar
Jan Möbius committed
203 204
  bool face_has_normal()     const { return check(FaceNormal); }
  bool face_has_color()      const { return check(FaceColor); }
205
  bool face_has_texcoord()   const { return check(FaceTexCoord); }
Jan Möbius's avatar
Jan Möbius committed
206
  bool color_has_alpha()     const { return check(ColorAlpha); }
207
  bool color_is_float()      const { return check(ColorFloat); }
Jan Möbius's avatar
Jan Möbius committed
208 209 210 211 212


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

Jan Möbius's avatar
Jan Möbius committed
214 215 216 217

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

Jan Möbius's avatar
Jan Möbius committed
219 220 221

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

Jan Möbius's avatar
Jan Möbius committed
223
private:
224

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

Jan Möbius's avatar
Jan Möbius committed
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
  value_type flags_;
};

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




//@}


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