5#include <OpenMesh/Core/IO/MeshIO.hh>
6#include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
7#include <OpenMesh/Core/Mesh/PolyMesh_ArrayKernelT.hh>
9#include "generate_cube.hh"
11#include "fill_props.hh"
35#ifndef DOXY_IGNORE_THIS
44 : ival(0), dval(0.0), bval(false)
48 : ival(_cpy.ival), dval(_cpy.dval), bval(_cpy.bval),
49 vec4fval(_cpy.vec4fval)
60 vec4fval = _rhs.vec4fval;
64 MyData& operator = (
int _rhs) { ival = _rhs;
return *
this; }
65 MyData& operator = (
double _rhs) { dval = _rhs;
return *
this; }
66 MyData& operator = (
bool _rhs) { bval = _rhs;
return *
this; }
68 { vec4fval = _rhs;
return *
this; }
73 bool operator == (
const MyData& _rhs)
const
75 return ival == _rhs.ival
78 && vec4fval == _rhs.vec4fval;
81 bool operator != (
const MyData& _rhs)
const {
return !(*
this == _rhs); }
89typedef std::map< std::string, unsigned int > MyMap;
94#ifndef DOXY_IGNORE_THIS
101 template <>
struct binary<
MyData>
103 typedef MyData value_type;
111 return sizeof(int)+
sizeof(
double)+
sizeof(bool)+
sizeof(
OpenMesh::Vec4f);
114 static size_t size_of(
const value_type&)
121 return "RegisteredDataType";
124 static size_t store(std::ostream& _os,
const value_type& _v,
bool _swap=
false)
127 bytes = IO::store( _os, _v.ival, _swap );
128 bytes += IO::store( _os, _v.dval, _swap );
129 bytes += IO::store( _os, _v.bval, _swap );
130 bytes += IO::store( _os, _v.vec4fval, _swap );
131 return _os.good() ? bytes : 0;
134 static size_t restore( std::istream& _is, value_type& _v,
bool _swap=
false)
137 bytes = IO::restore( _is, _v.ival, _swap );
138 bytes += IO::restore( _is, _v.dval, _swap );
139 bytes += IO::restore( _is, _v.bval, _swap );
140 bytes += IO::restore( _is, _v.vec4fval, _swap );
141 return _is.good() ? bytes : 0;
146 template <>
struct binary< MyMap >
148 typedef MyMap value_type;
153 static size_t size_of(
void) {
return UnknownSize; }
156 static size_t size_of(
const value_type& _v)
159 return sizeof(
unsigned int);
161 value_type::const_iterator it = _v.begin();
162 unsigned int N = _v.size();
165 for(;it!=_v.end(); ++it)
174 size_t store(std::ostream& _os,
const value_type& _v,
bool _swap=
false)
177 unsigned int N = _v.size();
179 value_type::const_iterator it = _v.begin();
181 bytes += IO::store( _os, N, _swap );
183 for (; it != _v.end() && _os.good(); ++it)
185 bytes += IO::store( _os, it->first, _swap );
186 bytes += IO::store( _os, it->second, _swap );
188 return _os.good() ? bytes : 0;
192 size_t restore( std::istream& _is, value_type& _v,
bool _swap=
false)
199 bytes += IO::restore( _is, N, _swap );
200 value_type::key_type key;
201 value_type::mapped_type val;
203 for (
size_t i=0; i<N && _is.good(); ++i)
205 bytes += IO::restore( _is, key, _swap );
206 bytes += IO::restore( _is, val, _swap );
209 return _is.good() ? bytes : 0;
228 generate_cube<Mesh>(mesh);
236 mesh_property_stats(mesh);
239 std::cout <<
"Define some custom properties..\n";
247 std::cout <<
".. and registrate them at the mesh object.\n";
249 mesh.add_property(vprop_float,
"vprop_float");
250 mesh.add_property(eprop_bool,
"eprop_bool");
251 mesh.add_property(fprop_string,
"fprop_string");
252 mesh.add_property(hprop_mydata,
"hprop_mydata");
253 mesh.add_property(mprop_map,
"mprop_map");
256 mesh_property_stats(mesh);
259 std::cout <<
"Now let's fill the props..\n";
261 fill_props(mesh, vprop_float);
262 fill_props(mesh, eprop_bool);
263 fill_props(mesh, fprop_string);
264 fill_props(mesh, hprop_mydata);
265 fill_props(mesh, mprop_map);
268 std::cout <<
"Check props..\n";
269#define CHK_PROP( PH ) \
270 std::cout << " " << #PH << " " \
271 << (fill_props(mesh, PH, true)?"ok\n":"error\n")
273 CHK_PROP(vprop_float);
274 CHK_PROP(eprop_bool);
275 CHK_PROP(fprop_string);
276 CHK_PROP(hprop_mydata);
281 std::cout <<
"Set persistent flag..\n";
282#define SET_PERS( PH ) \
283 mesh.property(PH).set_persistent(true); \
284 std::cout << " " << #PH << " " \
285 << (mesh.property(PH).persistent()?"ok\n":"failed!\n")
287 mesh.property(vprop_float).set_persistent(
true);
288 std::cout <<
" vprop_float "
289 << (mesh.property(vprop_float).persistent()?
"ok\n":
"failed!\n");
291 SET_PERS( eprop_bool );
292 SET_PERS( fprop_string );
293 SET_PERS( hprop_mydata );
294 mesh.mproperty(mprop_map).set_persistent(
true);
295 std::cout <<
" mprop_map "
296 << (mesh.mproperty(mprop_map).persistent()?
"ok\n":
"failed!\n");
299 std::cout <<
"Write mesh..";
301 std::cout <<
" ok\n";
304 std::cout <<
" failed\n";
309 std::cout <<
"Clear mesh\n";
311 mesh_stats(mesh,
" ");
314 std::cout <<
"Read back mesh..";
318 std::cout <<
" ok\n";
321 std::cout <<
" failed!\n";
324 mesh_stats(mesh,
" ");
326 catch( std::exception &x )
328 std::cerr << x.what() << std::endl;
333 std::cout <<
"Check props..\n";
334#define CHK_PROP( PH ) \
335 std::cout << " " << #PH << " " \
336 << (fill_props(mesh, PH, true)?"ok\n":"error\n")
337 CHK_PROP(vprop_float);
338 CHK_PROP(eprop_bool);
339 CHK_PROP(fprop_string);
340 CHK_PROP(hprop_mydata);
bool write_mesh(const Mesh &_mesh, const std::string &_filename, Options _opt=Options::Default, std::streamsize _precision=6)
Write a mesh to the file _filename.
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
static size_t restore(std::istream &, value_type &, bool=false, bool=true)
Restore a value of T and return the number of bytes read.
static const bool is_streamable
Can we store T? Set this to true in your specialization.
static size_t store(std::ostream &, const value_type &, bool=false, bool=true)
Store a value of T and return the number of bytes written.
static std::string type_identifier(void)
A string that identifies the type of T.
static size_t size_of(void)
What's the size of T? If it depends on the actual value (e.g. for vectors) return UnknownSize.