44 #ifndef OPENMESH_PROPERTY_HH 45 #define OPENMESH_PROPERTY_HH 51 #include <OpenMesh/Core/System/config.h> 52 #include <OpenMesh/Core/Mesh/Handles.hh> 53 #include <OpenMesh/Core/Utils/BaseProperty.hh> 94 typedef std::vector<T> vector_type;
96 typedef typename vector_type::reference reference;
97 typedef typename vector_type::const_reference const_reference;
112 virtual void reserve(
size_t _n) { data_.reserve(_n); }
113 virtual void resize(
size_t _n) { data_.resize(_n); }
114 virtual void clear() { data_.clear(); vector_type().swap(data_); }
116 virtual void swap(
size_t _i0,
size_t _i1)
117 { std::swap(data_[_i0], data_[_i1]); }
118 virtual void copy(
size_t _i0,
size_t _i1)
119 { data_[_i1] = data_[_i0]; }
124 { check_and_set_persistent<T>( _yn ); }
129 #ifndef DOXY_IGNORE_THIS 131 size_t operator () (
size_t _b,
const T& _v )
132 {
return _b + IO::size_of<T>(_v); }
140 return std::accumulate(data_.begin(), data_.end(), size_t(0), plus());
146 virtual size_t store( std::ostream& _ostr,
bool _swap )
const 148 if ( IO::is_streamable<vector_type>() )
149 return IO::store(_ostr, data_, _swap );
152 bytes += IO::store( _ostr, data_[i], _swap );
156 virtual size_t restore( std::istream& _istr,
bool _swap )
158 if ( IO::is_streamable<vector_type>() )
159 return IO::restore(_istr, data_, _swap );
162 bytes += IO::restore( _istr, data_[i], _swap );
190 assert(
size_t(_idx) < data_.size() );
197 assert(
size_t(_idx) < data_.size());
226 typedef std::vector<bool> vector_type;
227 typedef bool value_type;
228 typedef vector_type::reference reference;
229 typedef vector_type::const_reference const_reference;
233 PropertyT(
const std::string& _name =
"<unknown>")
239 virtual void reserve(
size_t _n) { data_.reserve(_n); }
240 virtual void resize(
size_t _n) { data_.resize(_n); }
241 virtual void clear() { data_.clear(); vector_type().swap(data_); }
243 virtual void swap(
size_t _i0,
size_t _i1)
244 {
bool t(data_[_i0]); data_[_i0]=data_[_i1]; data_[_i1]=t; }
245 virtual void copy(
size_t _i0,
size_t _i1)
246 { data_[_i1] = data_[_i0]; }
252 check_and_set_persistent<bool>( _yn );
260 return _n_elem / 8 + ((_n_elem % 8)!=0);
263 size_t store( std::ostream& _ostr,
bool )
const 267 size_t N = data_.size() / 8;
268 size_t R = data_.size() % 8;
274 for (bidx=idx=0; idx < N; ++idx, bidx+=8)
276 bits =
static_cast<unsigned char>(data_[bidx])
277 | (static_cast<unsigned char>(data_[bidx+1]) << 1)
278 | (static_cast<unsigned char>(data_[bidx+2]) << 2)
279 | (static_cast<unsigned char>(data_[bidx+3]) << 3)
280 | (static_cast<unsigned char>(data_[bidx+4]) << 4)
281 | (static_cast<unsigned char>(data_[bidx+5]) << 5)
282 | (static_cast<unsigned char>(data_[bidx+6]) << 6)
283 | (static_cast<unsigned char>(data_[bidx+7]) << 7);
291 for (idx=0; idx < R; ++idx)
292 bits |= static_cast<unsigned char>(data_[bidx+idx]) << idx;
306 size_t N = data_.size() / 8;
307 size_t R = data_.size() % 8;
313 for (bidx=idx=0; idx < N; ++idx, bidx+=8)
316 data_[bidx+0] = (bits & 0x01) != 0;
317 data_[bidx+1] = (bits & 0x02) != 0;
318 data_[bidx+2] = (bits & 0x04) != 0;
319 data_[bidx+3] = (bits & 0x08) != 0;
320 data_[bidx+4] = (bits & 0x10) != 0;
321 data_[bidx+5] = (bits & 0x20) != 0;
322 data_[bidx+6] = (bits & 0x40) != 0;
323 data_[bidx+7] = (bits & 0x80) != 0;
330 for (idx=0; idx < R; ++idx)
331 data_[bidx+idx] = (bits & (1<<idx)) != 0;
354 assert(
size_t(_idx) < data_.size() );
361 assert(
size_t(_idx) < data_.size());
389 typedef std::string Value;
390 typedef std::vector<std::string> vector_type;
391 typedef std::string value_type;
392 typedef vector_type::reference reference;
393 typedef vector_type::const_reference const_reference;
397 PropertyT(
const std::string& _name =
"<unknown>")
403 virtual void reserve(
size_t _n) { data_.reserve(_n); }
404 virtual void resize(
size_t _n) { data_.resize(_n); }
405 virtual void clear() { data_.clear(); vector_type().swap(data_); }
406 virtual void push_back() { data_.push_back(std::string()); }
407 virtual void swap(
size_t _i0,
size_t _i1) {
408 std::swap(data_[_i0], data_[_i1]);
410 virtual void copy(
size_t _i0,
size_t _i1)
411 { data_[_i1] = data_[_i0]; }
416 { check_and_set_persistent<std::string>( _yn ); }
427 size_t store( std::ostream& _ostr,
bool _swap )
const 428 {
return IO::store( _ostr, data_, _swap ); }
430 size_t restore( std::istream& _istr,
bool _swap )
431 {
return IO::restore( _istr, data_, _swap ); }
435 const value_type*
data()
const {
439 return (value_type*) &data_[0];
444 assert(
size_t(_idx) < data_.size());
445 return ((value_type*) &data_[0])[_idx];
450 assert(
size_t(_idx) < data_.size());
451 return ((value_type*) &data_[0])[_idx];
469 typedef std::vector<T> vector_type;
470 typedef T value_type;
471 typedef typename vector_type::reference reference;
472 typedef typename vector_type::const_reference const_reference;
485 typedef T value_type;
499 typedef T value_type;
513 typedef T value_type;
527 typedef T value_type;
541 typedef T value_type;
549 #endif // OPENMESH_PROPERTY_HH defined virtual void push_back()
Extend the number of elements by one.
Definition: Property.hh:406
virtual size_t store(std::ostream &_ostr, bool _swap) const
Store self as one binary block.
Definition: Property.hh:146
virtual void set_persistent(bool _yn)
Enable or disable persistency.
Definition: Property.hh:123
virtual void resize(size_t _n)
Resize storage to hold n elements.
Definition: Property.hh:240
virtual size_t size_of(void) const
Return size of property in bytes.
Definition: Property.hh:136
virtual void copy(size_t _i0, size_t _i1)
Copy one element to another.
Definition: Property.hh:118
Handle representing a face property.
Definition: Property.hh:524
size_t restore(std::istream &_istr, bool _swap)
Restore self from a binary block.
Definition: Property.hh:430
Handle representing a vertex property.
Definition: Property.hh:482
static const size_t UnknownSize
Indicates an error when a size is returned by a member.
Definition: BaseProperty.hh:65
PropertyT< bool > * clone() const
Make a copy of self.
Definition: Property.hh:366
virtual size_t element_size() const
Size of one element in bytes or UnknownSize if not known.
Definition: Property.hh:256
virtual void reserve(size_t _n)
Reserve memory for n elements.
Definition: Property.hh:112
virtual size_t n_elements() const
Number of elements in property.
Definition: Property.hh:418
virtual void set_persistent(bool _yn)
Enable or disable persistency.
Definition: Property.hh:415
virtual void copy(size_t _i0, size_t _i1)
Copy one element to another.
Definition: Property.hh:410
virtual size_t n_elements() const
Number of elements in property.
Definition: Property.hh:255
const_reference operator[](int _idx) const
Const access to the i'th element. No range check is performed!
Definition: Property.hh:195
virtual void copy(size_t _i0, size_t _i1)
Copy one element to another.
Definition: Property.hh:245
virtual void reserve(size_t _n)
Reserve memory for n elements.
Definition: Property.hh:403
PropertyT(const PropertyT &_rhs)
Copy constructor.
Definition: Property.hh:107
virtual void reserve(size_t _n)
Reserve memory for n elements.
Definition: Property.hh:239
PropertyT(const std::string &_name="<unknown>")
Default constructor.
Definition: Property.hh:102
const_reference operator[](int _idx) const
Const access the i'th element. No range check is performed!
Definition: Property.hh:449
virtual void swap(size_t _i0, size_t _i1)
Let two elements swap their storage place.
Definition: Property.hh:407
Abstract class defining the basic interface of a dynamic property.
Definition: BaseProperty.hh:60
const T * data() const
Get pointer to array (does not work for T==bool)
Definition: Property.hh:169
PropertyT< T > * clone() const
Make a copy of self.
Definition: Property.hh:202
vector_type & data_vector()
Get reference to property vector (be careful, improper usage, e.g. resizing, may crash OpenMesh!!!) ...
Definition: Property.hh:178
virtual void swap(size_t _i0, size_t _i1)
Let two elements swap their storage place.
Definition: Property.hh:116
virtual void resize(size_t _n)
Resize storage to hold n elements.
Definition: Property.hh:404
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:427
virtual void clear()
Clear all elements and free memory.
Definition: Property.hh:114
virtual size_t element_size() const
Size of one element in bytes or UnknownSize if not known.
Definition: Property.hh:419
virtual size_t n_elements() const
Number of elements in property.
Definition: Property.hh:126
virtual size_t size_of() const
Return size of property in bytes.
Definition: BaseProperty.hh:140
size_t store(std::ostream &_ostr, bool) const
Store self as one binary block.
Definition: Property.hh:263
Property specialization for bool type.
Definition: Property.hh:222
BaseProperty(const std::string &_name="<unknown>")
Default constructor.
Definition: BaseProperty.hh:83
virtual size_t size_of() const
Return size of property in bytes.
Definition: Property.hh:257
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
virtual void set_persistent(bool _yn)
Enable or disable persistency.
Definition: Property.hh:250
virtual size_t size_of() const
Return size of property in bytes.
Definition: Property.hh:420
virtual void clear()
Clear all elements and free memory.
Definition: Property.hh:405
Handle representing an edge property.
Definition: Property.hh:510
reference operator[](int _idx)
Access the i'th element. No range check is performed!
Definition: Property.hh:352
virtual size_t size_of(size_t) const
Estimated size of property if it has _n_elem elements.
Definition: Property.hh:423
virtual void swap(size_t _i0, size_t _i1)
Let two elements swap their storage place.
Definition: Property.hh:243
reference operator[](int _idx)
Access the i'th element. No range check is performed!
Definition: Property.hh:443
const vector_type & data_vector() const
Const access to property vector.
Definition: Property.hh:183
const vector_type & data_vector() const
Const access to property vector.
Definition: Property.hh:347
PropertyT< value_type > * clone() const
Return a deep copy of self.
Definition: Property.hh:454
virtual size_t size_of(size_t _n_elem) const
Estimated size of property if it has _n_elem elements.
Definition: Property.hh:143
virtual void clear()
Clear all elements and free memory.
Definition: Property.hh:241
vector_type & data_vector()
Get reference to property vector (be careful, improper usage, e.g. resizing, may crash OpenMesh!!!) ...
Definition: Property.hh:342
virtual void push_back()
Extend the number of elements by one.
Definition: Property.hh:242
virtual size_t restore(std::istream &_istr, bool _swap)
Restore self from a binary block.
Definition: Property.hh:156
Base property handle.
Definition: Property.hh:466
size_t size_of(const T &_v)
Binary read a short from _is and perform byte swapping if _swap is true.
Definition: StoreRestore.hh:89
Default property class for any type T.
Definition: Property.hh:89
size_t restore(std::istream &_istr, bool)
Restore self from a binary block.
Definition: Property.hh:302
const_reference operator[](int _idx) const
Const access to the i'th element. No range check is performed!
Definition: Property.hh:359
virtual void resize(size_t _n)
Resize storage to hold n elements.
Definition: Property.hh:113
Handle representing a mesh property.
Definition: Property.hh:538
Base class for all handle types.
Definition: Handles.hh:62
virtual size_t element_size() const
Size of one element in bytes or UnknownSize if not known.
Definition: Property.hh:127
virtual size_t size_of(size_t _n_elem) const
Estimated size of property if it has _n_elem elements.
Definition: Property.hh:258
virtual void push_back()
Extend the number of elements by one.
Definition: Property.hh:115
Handle representing a halfedge property.
Definition: Property.hh:496
reference operator[](int _idx)
Access the i'th element. No range check is performed!
Definition: Property.hh:188