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 );
197 value_type::key_type key;
198 value_type::mapped_type val;
200 for (
size_t i=0; i<N && _is.good(); ++i)
202 bytes += IO::restore( _is, key, _swap );
203 bytes += IO::restore( _is, val, _swap );
206 return _is.good() ? bytes : 0;
225 generate_cube<Mesh>(mesh);
233 mesh_property_stats(mesh);
236 std::cout <<
"Define some custom properties..\n";
244 std::cout <<
".. and registrate them at the mesh object.\n";
246 mesh.add_property(vprop_float,
"vprop_float");
247 mesh.add_property(eprop_bool,
"eprop_bool");
248 mesh.add_property(fprop_string,
"fprop_string");
249 mesh.add_property(hprop_mydata,
"hprop_mydata");
250 mesh.add_property(mprop_map,
"mprop_map");
253 mesh_property_stats(mesh);
256 std::cout <<
"Now let's fill the props..\n";
258 fill_props(mesh, vprop_float);
259 fill_props(mesh, eprop_bool);
260 fill_props(mesh, fprop_string);
261 fill_props(mesh, hprop_mydata);
262 fill_props(mesh, mprop_map);
265 std::cout <<
"Check props..\n";
266 #define CHK_PROP( PH ) \ 267 std::cout << " " << #PH << " " \ 268 << (fill_props(mesh, PH, true)?"ok\n":"error\n") 270 CHK_PROP(vprop_float);
271 CHK_PROP(eprop_bool);
272 CHK_PROP(fprop_string);
273 CHK_PROP(hprop_mydata);
278 std::cout <<
"Set persistent flag..\n";
279 #define SET_PERS( PH ) \ 280 mesh.property(PH).set_persistent(true); \ 281 std::cout << " " << #PH << " " \ 282 << (mesh.property(PH).persistent()?"ok\n":"failed!\n") 284 mesh.property(vprop_float).set_persistent(
true);
285 std::cout <<
" vprop_float " 286 << (mesh.property(vprop_float).persistent()?
"ok\n":
"failed!\n");
288 SET_PERS( eprop_bool );
289 SET_PERS( fprop_string );
290 SET_PERS( hprop_mydata );
291 mesh.mproperty(mprop_map).set_persistent(
true);
292 std::cout <<
" mprop_map " 293 << (mesh.mproperty(mprop_map).persistent()?
"ok\n":
"failed!\n");
296 std::cout <<
"Write mesh..";
298 std::cout <<
" ok\n";
301 std::cout <<
" failed\n";
306 std::cout <<
"Clear mesh\n";
308 mesh_stats(mesh,
" ");
311 std::cout <<
"Read back mesh..";
315 std::cout <<
" ok\n";
318 std::cout <<
" failed!\n";
321 mesh_stats(mesh,
" ");
323 catch( std::exception &x )
325 std::cerr << x.what() << std::endl;
330 std::cout <<
"Check props..\n";
331 #define CHK_PROP( PH ) \ 332 std::cout << " " << #PH << " " \ 333 << (fill_props(mesh, PH, true)?"ok\n":"error\n") 334 CHK_PROP(vprop_float);
335 CHK_PROP(eprop_bool);
336 CHK_PROP(fprop_string);
337 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.