42 #ifndef OPENMESH_PROPERTY_HH
43 #define OPENMESH_PROPERTY_HH
49 #include <OpenMesh/Core/System/config.h>
50 #include <OpenMesh/Core/Mesh/Handles.hh>
51 #include <OpenMesh/Core/Utils/BaseProperty.hh>
92 typedef std::vector<T> vector_type;
94 typedef typename vector_type::reference reference;
95 typedef typename vector_type::const_reference const_reference;
110 virtual void reserve(
size_t _n) { data_.reserve(_n); }
111 virtual void resize(
size_t _n) { data_.resize(_n); }
112 virtual void clear() { data_.clear(); vector_type().swap(data_); }
114 virtual void swap(
size_t _i0,
size_t _i1)
115 { std::swap(data_[_i0], data_[_i1]); }
116 virtual void copy(
size_t _i0,
size_t _i1)
117 { data_[_i1] = data_[_i0]; }
122 { check_and_set_persistent<T>( _yn ); }
127 #ifndef DOXY_IGNORE_THIS
129 size_t operator () (
size_t _b,
const T& _v )
130 {
return _b + IO::size_of<T>(_v); }
138 return std::accumulate(data_.begin(), data_.end(), size_t(0), plus());
144 virtual size_t store( std::ostream& _ostr,
bool _swap )
const
146 if ( IO::is_streamable<vector_type>() )
147 return IO::store(_ostr, data_, _swap );
150 bytes += IO::store( _ostr, data_[i], _swap );
154 virtual size_t restore( std::istream& _istr,
bool _swap )
156 if ( IO::is_streamable<vector_type>() )
157 return IO::restore(_istr, data_, _swap );
160 bytes += IO::restore( _istr, data_[i], _swap );
184 assert(
size_t(_idx) < data_.size() );
191 assert(
size_t(_idx) < data_.size());
220 typedef std::vector<bool> vector_type;
221 typedef bool value_type;
222 typedef vector_type::reference reference;
223 typedef vector_type::const_reference const_reference;
227 PropertyT(
const std::string& _name =
"<unknown>")
233 virtual void reserve(
size_t _n) { data_.reserve(_n); }
234 virtual void resize(
size_t _n) { data_.resize(_n); }
235 virtual void clear() { data_.clear(); vector_type().swap(data_); }
237 virtual void swap(
size_t _i0,
size_t _i1)
238 {
bool t(data_[_i0]); data_[_i0]=data_[_i1]; data_[_i1]=t; }
239 virtual void copy(
size_t _i0,
size_t _i1)
240 { data_[_i1] = data_[_i0]; }
246 check_and_set_persistent<bool>( _yn );
254 return _n_elem / 8 + ((_n_elem % 8)!=0);
257 size_t store( std::ostream& _ostr,
bool )
const
261 size_t N = data_.size() / 8;
262 size_t R = data_.size() % 8;
268 for (bidx=idx=0; idx < N; ++idx, bidx+=8)
271 | (!!data_[bidx+1] << 1)
272 | (!!data_[bidx+2] << 2)
273 | (!!data_[bidx+3] << 3)
274 | (!!data_[bidx+4] << 4)
275 | (!!data_[bidx+5] << 5)
276 | (!!data_[bidx+6] << 6)
277 | (!!data_[bidx+7] << 7);
285 for (idx=0; idx < R; ++idx)
286 bits |= !!data_[bidx+idx] << idx;
291 std::cout << std::endl;
302 size_t N = data_.size() / 8;
303 size_t R = data_.size() % 8;
309 for (bidx=idx=0; idx < N; ++idx, bidx+=8)
312 data_[bidx+0] = !!(bits & 0x01);
313 data_[bidx+1] = !!(bits & 0x02);
314 data_[bidx+2] = !!(bits & 0x04);
315 data_[bidx+3] = !!(bits & 0x08);
316 data_[bidx+4] = !!(bits & 0x10);
317 data_[bidx+5] = !!(bits & 0x20);
318 data_[bidx+6] = !!(bits & 0x40);
319 data_[bidx+7] = !!(bits & 0x80);
326 for (idx=0; idx < R; ++idx)
327 data_[bidx+idx] = !!(bits & (1<<idx));
331 std::cout << std::endl;
348 assert(
size_t(_idx) < data_.size() );
355 assert(
size_t(_idx) < data_.size());
383 typedef std::string Value;
384 typedef std::vector<std::string> vector_type;
385 typedef std::string value_type;
386 typedef vector_type::reference reference;
387 typedef vector_type::const_reference const_reference;
391 PropertyT(
const std::string& _name =
"<unknown>")
397 virtual void reserve(
size_t _n) { data_.reserve(_n); }
398 virtual void resize(
size_t _n) { data_.resize(_n); }
399 virtual void clear() { data_.clear(); vector_type().swap(data_); }
400 virtual void push_back() { data_.push_back(std::string()); }
401 virtual void swap(
size_t _i0,
size_t _i1) {
402 std::swap(data_[_i0], data_[_i1]);
404 virtual void copy(
size_t _i0,
size_t _i1)
405 { data_[_i1] = data_[_i0]; }
410 { check_and_set_persistent<std::string>( _yn ); }
421 size_t store( std::ostream& _ostr,
bool _swap )
const
422 {
return IO::store( _ostr, data_, _swap ); }
424 size_t restore( std::istream& _istr,
bool _swap )
425 {
return IO::restore( _istr, data_, _swap ); }
429 const value_type*
data()
const {
433 return (value_type*) &data_[0];
438 assert(
size_t(_idx) < data_.size());
439 return ((value_type*) &data_[0])[_idx];
444 assert(
size_t(_idx) < data_.size());
445 return ((value_type*) &data_[0])[_idx];
463 typedef std::vector<T> vector_type;
464 typedef T value_type;
465 typedef typename vector_type::reference reference;
466 typedef typename vector_type::const_reference const_reference;
479 typedef T value_type;
493 typedef T value_type;
507 typedef T value_type;
521 typedef T value_type;
535 typedef T value_type;
543 #endif // OPENMESH_PROPERTY_HH defined
virtual void resize(size_t _n)
Resize storage to hold n elements.
Definition: Property.hh:398
PropertyT< value_type > * clone() const
Return a deep copy of self.
Definition: Property.hh:448
virtual void reserve(size_t _n)
Reserve memory for n elements.
Definition: Property.hh:397
reference operator[](int _idx)
Access the i'th element. No range check is performed!
Definition: Property.hh:346
Abstract class defining the basic interface of a dynamic property.
Definition: BaseProperty.hh:58
PropertyT< bool > * clone() const
Make a copy of self.
Definition: Property.hh:360
virtual void push_back()
Extend the number of elements by one.
Definition: Property.hh:113
const_reference operator[](int _idx) const
Const access to the i'th element. No range check is performed!
Definition: Property.hh:353
virtual void copy(size_t _i0, size_t _i1)
Copy one element to another.
Definition: Property.hh:239
virtual void reserve(size_t _n)
Reserve memory for n elements.
Definition: Property.hh:233
virtual void copy(size_t _i0, size_t _i1)
Copy one element to another.
Definition: Property.hh:116
Property specialization for bool type.
Definition: Property.hh:216
virtual void clear()
Clear all elements and free memory.
Definition: Property.hh:112
vector_type & data_vector()
Get reference to property vector (be careful, improper usage, e.g. resizing, may crash OpenMesh!!!) ...
Definition: Property.hh:176
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:56
virtual void set_persistent(bool _yn)
Enable or disable persistency.
Definition: Property.hh:121
virtual void push_back()
Extend the number of elements by one.
Definition: Property.hh:236
virtual size_t restore(std::istream &_istr, bool _swap)
Restore self from a binary block.
Definition: Property.hh:154
virtual size_t size_of() const
Return size of property in bytes.
Definition: Property.hh:251
size_t store(std::ostream &_ostr, bool) const
Store self as one binary block.
Definition: Property.hh:257
size_t store(std::ostream &_ostr, bool _swap) const
Store self as one binary block. Max. length of a string is 65535 bytes.
Definition: Property.hh:421
virtual size_t size_of() const
Return size of property in bytes.
Definition: BaseProperty.hh:138
size_t restore(std::istream &_istr, bool _swap)
Restore self from a binary block.
Definition: Property.hh:424
Base class for all handle types.
Definition: Handles.hh:60
virtual void swap(size_t _i0, size_t _i1)
Let two elements swap their storage place.
Definition: Property.hh:401
virtual void clear()
Clear all elements and free memory.
Definition: Property.hh:399
virtual size_t element_size() const
Size of one element in bytes or UnknownSize if not known.
Definition: Property.hh:250
PropertyT(const PropertyT &_rhs)
Copy constructor.
Definition: Property.hh:105
PropertyT< T > * clone() const
Make a copy of self.
Definition: Property.hh:196
virtual size_t store(std::ostream &_ostr, bool _swap) const
Store self as one binary block.
Definition: Property.hh:144
virtual size_t size_of() const
Return size of property in bytes.
Definition: Property.hh:414
virtual size_t element_size() const
Size of one element in bytes or UnknownSize if not known.
Definition: Property.hh:413
reference operator[](int _idx)
Access the i'th element. No range check is performed!
Definition: Property.hh:182
virtual void resize(size_t _n)
Resize storage to hold n elements.
Definition: Property.hh:234
Handle representing a mesh property.
Definition: Property.hh:532
virtual void clear()
Clear all elements and free memory.
Definition: Property.hh:235
const T * data() const
Get pointer to array (does not work for T==bool)
Definition: Property.hh:167
PropertyT(const std::string &_name="<unknown>")
Default constructor.
Definition: Property.hh:100
Default property class for any type T.
Definition: Property.hh:87
Handle representing an edge property.
Definition: Property.hh:504
virtual size_t n_elements() const
Number of elements in property.
Definition: Property.hh:124
static const size_t UnknownSize
Indicates an error when a size is returned by a member.
Definition: BaseProperty.hh:63
Handle representing a face property.
Definition: Property.hh:518
virtual size_t size_of(size_t) const
Estimated size of property if it has _n_elem elements.
Definition: Property.hh:417
const_reference operator[](int _idx) const
Const access to the i'th element. No range check is performed!
Definition: Property.hh:189
virtual void push_back()
Extend the number of elements by one.
Definition: Property.hh:400
virtual void swap(size_t _i0, size_t _i1)
Let two elements swap their storage place.
Definition: Property.hh:237
virtual size_t n_elements() const
Number of elements in property.
Definition: Property.hh:249
virtual void resize(size_t _n)
Resize storage to hold n elements.
Definition: Property.hh:111
Handle representing a halfedge property.
Definition: Property.hh:490
virtual void copy(size_t _i0, size_t _i1)
Copy one element to another.
Definition: Property.hh:404
Handle representing a vertex property.
Definition: Property.hh:476
virtual void set_persistent(bool _yn)
Enable or disable persistency.
Definition: Property.hh:409
virtual size_t size_of(size_t _n_elem) const
Estimated size of property if it has _n_elem elements.
Definition: Property.hh:252
size_t restore(std::istream &_istr, bool)
Restore self from a binary block.
Definition: Property.hh:298
Base property handle.
Definition: Property.hh:460
virtual size_t n_elements() const
Number of elements in property.
Definition: Property.hh:412
virtual size_t size_of(size_t _n_elem) const
Estimated size of property if it has _n_elem elements.
Definition: Property.hh:141
BaseProperty(const std::string &_name="<unknown>")
Default constructor.
Definition: BaseProperty.hh:81
reference operator[](int _idx)
Access the i'th element. No range check is performed!
Definition: Property.hh:437
virtual size_t size_of(void) const
Return size of property in bytes.
Definition: Property.hh:134
virtual size_t element_size() const
Size of one element in bytes or UnknownSize if not known.
Definition: Property.hh:125
virtual void reserve(size_t _n)
Reserve memory for n elements.
Definition: Property.hh:110
size_t size_of(const T &_v)
Binary read a short from _is and perform byte swapping if _swap is true.
Definition: StoreRestore.hh:87
const_reference operator[](int _idx) const
Const access the i'th element. No range check is performed!
Definition: Property.hh:443
vector_type & data_vector()
Get reference to property vector (be careful, improper usage, e.g. resizing, may crash OpenMesh!!!) ...
Definition: Property.hh:340
virtual void swap(size_t _i0, size_t _i1)
Let two elements swap their storage place.
Definition: Property.hh:114
virtual void set_persistent(bool _yn)
Enable or disable persistency.
Definition: Property.hh:244