49 #ifndef OPENMESH_PROPERTY_HH 50 #define OPENMESH_PROPERTY_HH 56 #include <OpenMesh/Core/System/config.h> 57 #include <OpenMesh/Core/Mesh/Handles.hh> 58 #include <OpenMesh/Core/Utils/BaseProperty.hh> 99 typedef std::vector<T> vector_type;
100 typedef T value_type;
101 typedef typename vector_type::reference reference;
102 typedef typename vector_type::const_reference const_reference;
117 virtual void reserve(
size_t _n) { data_.reserve(_n); }
118 virtual void resize(
size_t _n) { data_.resize(_n); }
119 virtual void clear() { data_.clear(); vector_type().swap(data_); }
121 virtual void swap(
size_t _i0,
size_t _i1)
122 { std::swap(data_[_i0], data_[_i1]); }
123 virtual void copy(
size_t _i0,
size_t _i1)
124 { data_[_i1] = data_[_i0]; }
129 { check_and_set_persistent<T>( _yn ); }
134 #ifndef DOXY_IGNORE_THIS 136 size_t operator () (
size_t _b,
const T& _v )
137 {
return _b + IO::size_of<T>(_v); }
145 return std::accumulate(data_.begin(), data_.end(), size_t(0), plus());
151 virtual size_t store( std::ostream& _ostr,
bool _swap )
const 153 if ( IO::is_streamable<vector_type>() )
154 return IO::store(_ostr, data_, _swap );
157 bytes += IO::store( _ostr, data_[i], _swap );
161 virtual size_t restore( std::istream& _istr,
bool _swap )
163 if ( IO::is_streamable<vector_type>() )
164 return IO::restore(_istr, data_, _swap );
167 bytes += IO::restore( _istr, data_[i], _swap );
195 assert(
size_t(_idx) < data_.size() );
202 assert(
size_t(_idx) < data_.size());
231 typedef std::vector<bool> vector_type;
232 typedef bool value_type;
233 typedef vector_type::reference reference;
234 typedef vector_type::const_reference const_reference;
238 PropertyT(
const std::string& _name =
"<unknown>")
244 virtual void reserve(
size_t _n) { data_.reserve(_n); }
245 virtual void resize(
size_t _n) { data_.resize(_n); }
246 virtual void clear() { data_.clear(); vector_type().swap(data_); }
248 virtual void swap(
size_t _i0,
size_t _i1)
249 {
bool t(data_[_i0]); data_[_i0]=data_[_i1]; data_[_i1]=t; }
250 virtual void copy(
size_t _i0,
size_t _i1)
251 { data_[_i1] = data_[_i0]; }
257 check_and_set_persistent<bool>( _yn );
265 return _n_elem / 8 + ((_n_elem % 8)!=0);
268 size_t store( std::ostream& _ostr,
bool )
const 272 size_t N = data_.size() / 8;
273 size_t R = data_.size() % 8;
279 for (bidx=idx=0; idx < N; ++idx, bidx+=8)
281 bits =
static_cast<unsigned char>(data_[bidx])
282 | (static_cast<unsigned char>(data_[bidx+1]) << 1)
283 | (static_cast<unsigned char>(data_[bidx+2]) << 2)
284 | (static_cast<unsigned char>(data_[bidx+3]) << 3)
285 | (static_cast<unsigned char>(data_[bidx+4]) << 4)
286 | (static_cast<unsigned char>(data_[bidx+5]) << 5)
287 | (static_cast<unsigned char>(data_[bidx+6]) << 6)
288 | (static_cast<unsigned char>(data_[bidx+7]) << 7);
296 for (idx=0; idx < R; ++idx)
297 bits |= static_cast<unsigned char>(data_[bidx+idx]) << idx;
311 size_t N = data_.size() / 8;
312 size_t R = data_.size() % 8;
318 for (bidx=idx=0; idx < N; ++idx, bidx+=8)
321 data_[bidx+0] = (bits & 0x01) != 0;
322 data_[bidx+1] = (bits & 0x02) != 0;
323 data_[bidx+2] = (bits & 0x04) != 0;
324 data_[bidx+3] = (bits & 0x08) != 0;
325 data_[bidx+4] = (bits & 0x10) != 0;
326 data_[bidx+5] = (bits & 0x20) != 0;
327 data_[bidx+6] = (bits & 0x40) != 0;
328 data_[bidx+7] = (bits & 0x80) != 0;
335 for (idx=0; idx < R; ++idx)
336 data_[bidx+idx] = (bits & (1<<idx)) != 0;
359 assert(
size_t(_idx) < data_.size() );
366 assert(
size_t(_idx) < data_.size());
394 typedef std::string Value;
395 typedef std::vector<std::string> vector_type;
396 typedef std::string value_type;
397 typedef vector_type::reference reference;
398 typedef vector_type::const_reference const_reference;
402 PropertyT(
const std::string& _name =
"<unknown>")
408 virtual void reserve(
size_t _n) { data_.reserve(_n); }
409 virtual void resize(
size_t _n) { data_.resize(_n); }
410 virtual void clear() { data_.clear(); vector_type().swap(data_); }
411 virtual void push_back() { data_.push_back(std::string()); }
412 virtual void swap(
size_t _i0,
size_t _i1) {
413 std::swap(data_[_i0], data_[_i1]);
415 virtual void copy(
size_t _i0,
size_t _i1)
416 { data_[_i1] = data_[_i0]; }
421 { check_and_set_persistent<std::string>( _yn ); }
432 size_t store( std::ostream& _ostr,
bool _swap )
const 433 {
return IO::store( _ostr, data_, _swap ); }
435 size_t restore( std::istream& _istr,
bool _swap )
436 {
return IO::restore( _istr, data_, _swap ); }
440 const value_type*
data()
const {
444 return (value_type*) &data_[0];
449 assert(
size_t(_idx) < data_.size());
450 return ((value_type*) &data_[0])[_idx];
455 assert(
size_t(_idx) < data_.size());
456 return ((value_type*) &data_[0])[_idx];
474 typedef std::vector<T> vector_type;
475 typedef T value_type;
476 typedef typename vector_type::reference reference;
477 typedef typename vector_type::const_reference const_reference;
490 typedef T value_type;
504 typedef T value_type;
518 typedef T value_type;
532 typedef T value_type;
546 typedef T value_type;
554 #endif // OPENMESH_PROPERTY_HH defined reference operator[](int _idx)
Access the i'th element. No range check is performed!
Definition: Property.hh:357
Property specialization for bool type.
Definition: Property.hh:227
size_t store(std::ostream &_ostr, bool) const
Store self as one binary block.
Definition: Property.hh:268
reference operator[](int _idx)
Access the i'th element. No range check is performed!
Definition: Property.hh:448
Handle representing an edge property.
Definition: Property.hh:515
const_reference operator[](int _idx) const
Const access to the i'th element. No range check is performed!
Definition: Property.hh:200
virtual size_t element_size() const
Size of one element in bytes or UnknownSize if not known.
Definition: Property.hh:132
PropertyT< bool > * clone() const
Make a copy of self.
Definition: Property.hh:371
virtual size_t size_of(size_t _n_elem) const
Estimated size of property if it has _n_elem elements.
Definition: Property.hh:263
virtual void swap(size_t _i0, size_t _i1)
Let two elements swap their storage place.
Definition: Property.hh:248
virtual void reserve(size_t _n)
Reserve memory for n elements.
Definition: Property.hh:117
virtual size_t element_size() const
Size of one element in bytes or UnknownSize if not known.
Definition: Property.hh:424
virtual void reserve(size_t _n)
Reserve memory for n elements.
Definition: Property.hh:408
virtual size_t n_elements() const
Number of elements in property.
Definition: Property.hh:260
virtual void swap(size_t _i0, size_t _i1)
Let two elements swap their storage place.
Definition: Property.hh:121
virtual void copy(size_t _i0, size_t _i1)
Copy one element to another.
Definition: Property.hh:250
Default property class for any type T.
Definition: Property.hh:94
virtual size_t size_of() const
Return size of property in bytes.
Definition: BaseProperty.hh:145
virtual void push_back()
Extend the number of elements by one.
Definition: Property.hh:247
virtual size_t restore(std::istream &_istr, bool _swap)
Restore self from a binary block.
Definition: Property.hh:161
vector_type & data_vector()
Get reference to property vector (be careful, improper usage, e.g. resizing, may crash OpenMesh!!!) ...
Definition: Property.hh:347
PropertyT(const std::string &_name="<unknown>")
Default constructor.
Definition: Property.hh:107
virtual void set_persistent(bool _yn)
Enable or disable persistency.
Definition: Property.hh:420
size_t restore(std::istream &_istr, bool)
Restore self from a binary block.
Definition: Property.hh:307
BaseProperty(const std::string &_name="<unknown>")
Default constructor.
Definition: BaseProperty.hh:88
virtual void resize(size_t _n)
Resize storage to hold n elements.
Definition: Property.hh:409
virtual void copy(size_t _i0, size_t _i1)
Copy one element to another.
Definition: Property.hh:415
const_reference operator[](int _idx) const
Const access to the i'th element. No range check is performed!
Definition: Property.hh:364
Base class for all handle types.
Definition: Handles.hh:67
size_t restore(std::istream &_istr, bool _swap)
Restore self from a binary block.
Definition: Property.hh:435
PropertyT(const PropertyT &_rhs)
Copy constructor.
Definition: Property.hh:112
virtual void set_persistent(bool _yn)
Enable or disable persistency.
Definition: Property.hh:255
virtual void swap(size_t _i0, size_t _i1)
Let two elements swap their storage place.
Definition: Property.hh:412
Handle representing a halfedge property.
Definition: Property.hh:501
PropertyT< value_type > * clone() const
Return a deep copy of self.
Definition: Property.hh:459
virtual size_t size_of(size_t _n_elem) const
Estimated size of property if it has _n_elem elements.
Definition: Property.hh:148
const T * data() const
Get pointer to array (does not work for T==bool)
Definition: Property.hh:174
virtual size_t store(std::ostream &_ostr, bool _swap) const
Store self as one binary block.
Definition: Property.hh:151
virtual size_t size_of() const
Return size of property in bytes.
Definition: Property.hh:262
Base property handle.
Definition: Property.hh:471
const_reference operator[](int _idx) const
Const access the i'th element. No range check is performed!
Definition: Property.hh:454
virtual size_t element_size() const
Size of one element in bytes or UnknownSize if not known.
Definition: Property.hh:261
const vector_type & data_vector() const
Const access to property vector.
Definition: Property.hh:188
Handle representing a face property.
Definition: Property.hh:529
virtual void set_persistent(bool _yn)
Enable or disable persistency.
Definition: Property.hh:128
virtual size_t size_of() const
Return size of property in bytes.
Definition: Property.hh:425
virtual void resize(size_t _n)
Resize storage to hold n elements.
Definition: Property.hh:245
Handle representing a vertex property.
Definition: Property.hh:487
Handle representing a mesh property.
Definition: Property.hh:543
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:432
size_t size_of(const T &_v)
Binary read a short from _is and perform byte swapping if _swap is true.
Definition: StoreRestore.hh:94
virtual size_t size_of(void) const
Return size of property in bytes.
Definition: Property.hh:141
const vector_type & data_vector() const
Const access to property vector.
Definition: Property.hh:352
virtual void copy(size_t _i0, size_t _i1)
Copy one element to another.
Definition: Property.hh:123
Abstract class defining the basic interface of a dynamic property.
Definition: BaseProperty.hh:65
virtual void resize(size_t _n)
Resize storage to hold n elements.
Definition: Property.hh:118
virtual void reserve(size_t _n)
Reserve memory for n elements.
Definition: Property.hh:244
reference operator[](int _idx)
Access the i'th element. No range check is performed!
Definition: Property.hh:193
virtual void push_back()
Extend the number of elements by one.
Definition: Property.hh:120
virtual size_t n_elements() const
Number of elements in property.
Definition: Property.hh:423
PropertyT< T > * clone() const
Make a copy of self.
Definition: Property.hh:207
virtual void push_back()
Extend the number of elements by one.
Definition: Property.hh:411
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
virtual size_t size_of(size_t) const
Estimated size of property if it has _n_elem elements.
Definition: Property.hh:428
virtual void clear()
Clear all elements and free memory.
Definition: Property.hh:119
virtual void clear()
Clear all elements and free memory.
Definition: Property.hh:410
vector_type & data_vector()
Get reference to property vector (be careful, improper usage, e.g. resizing, may crash OpenMesh!!!) ...
Definition: Property.hh:183
virtual void clear()
Clear all elements and free memory.
Definition: Property.hh:246
virtual size_t n_elements() const
Number of elements in property.
Definition: Property.hh:131
static const size_t UnknownSize
Indicates an error when a size is returned by a member.
Definition: BaseProperty.hh:70