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 45 : ival(0), dval(0.0), bval(false)
49 : ival(_cpy.ival), dval(_cpy.dval), bval(_cpy.bval),
50 vec4fval(_cpy.vec4fval)
61 vec4fval = _rhs.vec4fval;
65 MyData& operator = (
int _rhs) { ival = _rhs;
return *
this; }
66 MyData& operator = (
double _rhs) { dval = _rhs;
return *
this; }
67 MyData& operator = (
bool _rhs) { bval = _rhs;
return *
this; }
69 { vec4fval = _rhs;
return *
this; }
74 bool operator == (
const MyData& _rhs)
const 76 return ival == _rhs.ival
79 && vec4fval == _rhs.vec4fval;
82 bool operator != (
const MyData& _rhs)
const {
return !(*
this == _rhs); }
91 typedef std::map< std::string, unsigned int > MyMap;
96 #ifndef DOXY_IGNORE_THIS 103 template <>
struct binary<
MyData>
105 typedef MyData value_type;
107 static const bool is_streamable =
true;
111 static size_t size_of(
void)
113 return sizeof(int)+
sizeof(
double)+
sizeof(bool)+
sizeof(
OpenMesh::Vec4f);
116 static size_t size_of(
const value_type&)
121 static size_t store(std::ostream& _os,
const value_type& _v,
bool _swap=
false)
124 bytes = IO::store( _os, _v.ival, _swap );
125 bytes += IO::store( _os, _v.dval, _swap );
126 bytes += IO::store( _os, _v.bval, _swap );
127 bytes += IO::store( _os, _v.vec4fval, _swap );
128 return _os.good() ? bytes : 0;
131 static size_t restore( std::istream& _is, value_type& _v,
bool _swap=
false)
134 bytes = IO::restore( _is, _v.ival, _swap );
135 bytes += IO::restore( _is, _v.dval, _swap );
136 bytes += IO::restore( _is, _v.bval, _swap );
137 bytes += IO::restore( _is, _v.vec4fval, _swap );
138 return _is.good() ? bytes : 0;
143 template <>
struct binary< MyMap >
145 typedef MyMap value_type;
147 static const bool is_streamable =
true;
150 static size_t size_of(
void) {
return UnknownSize; }
153 static size_t size_of(
const value_type& _v)
156 return sizeof(
unsigned int);
158 value_type::const_iterator it = _v.begin();
159 unsigned int N = _v.size();
162 for(;it!=_v.end(); ++it)
171 size_t store(std::ostream& _os,
const value_type& _v,
bool _swap=
false)
174 unsigned int N = _v.size();
176 value_type::const_iterator it = _v.begin();
178 bytes += IO::store( _os, N, _swap );
180 for (; it != _v.end() && _os.good(); ++it)
182 bytes += IO::store( _os, it->first, _swap );
183 bytes += IO::store( _os, it->second, _swap );
185 return _os.good() ? bytes : 0;
189 size_t restore( std::istream& _is, value_type& _v,
bool _swap=
false)
196 bytes += IO::restore( _is, N, _swap );
201 for (
size_t i=0; i<N && _is.good(); ++i)
203 bytes += IO::restore( _is, key, _swap );
204 bytes += IO::restore( _is, val, _swap );
207 return _is.good() ? bytes : 0;
226 generate_cube<Mesh>(mesh);
234 mesh_property_stats(mesh);
237 std::cout <<
"Define some custom properties..\n";
245 std::cout <<
".. and registrate them at the mesh object.\n";
247 mesh.add_property(vprop_float,
"vprop_float");
248 mesh.add_property(eprop_bool,
"eprop_bool");
249 mesh.add_property(fprop_string,
"fprop_string");
250 mesh.add_property(hprop_mydata,
"hprop_mydata");
251 mesh.add_property(mprop_map,
"mprop_map");
254 mesh_property_stats(mesh);
257 std::cout <<
"Now let's fill the props..\n";
259 fill_props(mesh, vprop_float);
260 fill_props(mesh, eprop_bool);
261 fill_props(mesh, fprop_string);
262 fill_props(mesh, hprop_mydata);
263 fill_props(mesh, mprop_map);
266 std::cout <<
"Check props..\n";
267 #define CHK_PROP( PH ) \ 268 std::cout << " " << #PH << " " \ 269 << (fill_props(mesh, PH, true)?"ok\n":"error\n") 271 CHK_PROP(vprop_float);
272 CHK_PROP(eprop_bool);
273 CHK_PROP(fprop_string);
274 CHK_PROP(hprop_mydata);
279 std::cout <<
"Set persistent flag..\n";
280 #define SET_PERS( PH ) \ 281 mesh.property(PH).set_persistent(true); \ 282 std::cout << " " << #PH << " " \ 283 << (mesh.property(PH).persistent()?"ok\n":"failed!\n") 285 mesh.property(vprop_float).set_persistent(
true);
286 std::cout <<
" vprop_float " 287 << (mesh.property(vprop_float).persistent()?
"ok\n":
"failed!\n");
289 SET_PERS( eprop_bool );
290 SET_PERS( fprop_string );
291 SET_PERS( hprop_mydata );
292 mesh.mproperty(mprop_map).set_persistent(
true);
293 std::cout <<
" mprop_map " 294 << (mesh.mproperty(mprop_map).persistent()?
"ok\n":
"failed!\n");
297 std::cout <<
"Write mesh..";
299 std::cout <<
" ok\n";
302 std::cout <<
" failed\n";
307 std::cout <<
"Clear mesh\n";
309 mesh_stats(mesh,
" ");
312 std::cout <<
"Read back mesh..";
316 std::cout <<
" ok\n";
319 std::cout <<
" failed!\n";
322 mesh_stats(mesh,
" ");
324 catch( std::exception &x )
326 std::cerr << x.what() << std::endl;
331 std::cout <<
"Check props..\n";
332 #define CHK_PROP( PH ) \ 333 std::cout << " " << #PH << " " \ 334 << (fill_props(mesh, PH, true)?"ok\n":"error\n") 335 CHK_PROP(vprop_float);
336 CHK_PROP(eprop_bool);
337 CHK_PROP(fprop_string);
338 CHK_PROP(hprop_mydata);
size_t size_of(const T &_v)
OpenMesh::PolyMesh_ArrayKernelT< PolyTraits > PolyMesh
Simple Name for Mesh.
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
OpenMesh::TriMesh_ArrayKernelT< TriTraits > TriMesh
Simple Name for Mesh.
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.