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 );
188 assert(
size_t(_idx) < data_.size() );
195 assert(
size_t(_idx) < data_.size());
224 typedef std::vector<bool> vector_type;
225 typedef bool value_type;
226 typedef vector_type::reference reference;
227 typedef vector_type::const_reference const_reference;
231 PropertyT(
const std::string& _name =
"<unknown>")
237 virtual void reserve(
size_t _n) { data_.reserve(_n); }
238 virtual void resize(
size_t _n) { data_.resize(_n); }
239 virtual void clear() { data_.clear(); vector_type().swap(data_); }
241 virtual void swap(
size_t _i0,
size_t _i1)
242 {
bool t(data_[_i0]); data_[_i0]=data_[_i1]; data_[_i1]=t; }
243 virtual void copy(
size_t _i0,
size_t _i1)
244 { data_[_i1] = data_[_i0]; }
250 check_and_set_persistent<bool>( _yn );
258 return _n_elem / 8 + ((_n_elem % 8)!=0);
261 size_t store( std::ostream& _ostr,
bool )
const
265 size_t N = data_.size() / 8;
266 size_t R = data_.size() % 8;
272 for (bidx=idx=0; idx < N; ++idx, bidx+=8)
275 | (!!data_[bidx+1] << 1)
276 | (!!data_[bidx+2] << 2)
277 | (!!data_[bidx+3] << 3)
278 | (!!data_[bidx+4] << 4)
279 | (!!data_[bidx+5] << 5)
280 | (!!data_[bidx+6] << 6)
281 | (!!data_[bidx+7] << 7);
289 for (idx=0; idx < R; ++idx)
290 bits |= !!data_[bidx+idx] << idx;
295 std::cout << std::endl;
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);
317 data_[bidx+1] = !!(bits & 0x02);
318 data_[bidx+2] = !!(bits & 0x04);
319 data_[bidx+3] = !!(bits & 0x08);
320 data_[bidx+4] = !!(bits & 0x10);
321 data_[bidx+5] = !!(bits & 0x20);
322 data_[bidx+6] = !!(bits & 0x40);
323 data_[bidx+7] = !!(bits & 0x80);
330 for (idx=0; idx < R; ++idx)
331 data_[bidx+idx] = !!(bits & (1<<idx));
335 std::cout << std::endl;
356 assert(
size_t(_idx) < data_.size() );
363 assert(
size_t(_idx) < data_.size());
391 typedef std::string Value;
392 typedef std::vector<std::string> vector_type;
393 typedef std::string value_type;
394 typedef vector_type::reference reference;
395 typedef vector_type::const_reference const_reference;
399 PropertyT(
const std::string& _name =
"<unknown>")
405 virtual void reserve(
size_t _n) { data_.reserve(_n); }
406 virtual void resize(
size_t _n) { data_.resize(_n); }
407 virtual void clear() { data_.clear(); vector_type().swap(data_); }
408 virtual void push_back() { data_.push_back(std::string()); }
409 virtual void swap(
size_t _i0,
size_t _i1) {
410 std::swap(data_[_i0], data_[_i1]);
412 virtual void copy(
size_t _i0,
size_t _i1)
413 { data_[_i1] = data_[_i0]; }
418 { check_and_set_persistent<std::string>( _yn ); }
429 size_t store( std::ostream& _ostr,
bool _swap )
const
430 {
return IO::store( _ostr, data_, _swap ); }
432 size_t restore( std::istream& _istr,
bool _swap )
433 {
return IO::restore( _istr, data_, _swap ); }
437 const value_type*
data()
const {
441 return (value_type*) &data_[0];
446 assert(
size_t(_idx) < data_.size());
447 return ((value_type*) &data_[0])[_idx];
452 assert(
size_t(_idx) < data_.size());
453 return ((value_type*) &data_[0])[_idx];
471 typedef std::vector<T> vector_type;
472 typedef T value_type;
473 typedef typename vector_type::reference reference;
474 typedef typename vector_type::const_reference const_reference;
487 typedef T value_type;
501 typedef T value_type;
515 typedef T value_type;
529 typedef T value_type;
543 typedef T value_type;
551 #endif // OPENMESH_PROPERTY_HH defined
size_t restore(std::istream &_istr, bool _swap)
Restore self from a binary block.
Definition: Property.hh:432
virtual void swap(size_t _i0, size_t _i1)
Let two elements swap their storage place.
Definition: Property.hh:241
virtual size_t size_of() const
Return size of property in bytes.
Definition: Property.hh:255
vector_type & data_vector()
Get reference to property vector (be careful, improper usage, e.g. resizing, may crash OpenMesh!!!) ...
Definition: Property.hh:176
const_reference operator[](int _idx) const
Const access the i'th element. No range check is performed!
Definition: Property.hh:451
Handle representing an edge property.
Definition: Property.hh:512
Base class for all handle types.
Definition: Handles.hh:60
virtual void set_persistent(bool _yn)
Enable or disable persistency.
Definition: Property.hh:121
const vector_type & data_vector() const
Const access to property vector.
Definition: Property.hh:349
virtual void copy(size_t _i0, size_t _i1)
Copy one element to another.
Definition: Property.hh:412
virtual size_t restore(std::istream &_istr, bool _swap)
Restore self from a binary block.
Definition: Property.hh:154
Default property class for any type T.
Definition: Property.hh:87
virtual void clear()
Clear all elements and free memory.
Definition: Property.hh:239
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:422
static const size_t UnknownSize
Indicates an error when a size is returned by a member.
Definition: BaseProperty.hh:63
Handle representing a halfedge property.
Definition: Property.hh:498
size_t store(std::ostream &_ostr, bool) const
Store self as one binary block.
Definition: Property.hh:261
Base property handle.
Definition: Property.hh:468
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
virtual void push_back()
Extend the number of elements by one.
Definition: Property.hh:113
virtual void push_back()
Extend the number of elements by one.
Definition: Property.hh:408
virtual size_t size_of(size_t _n_elem) const
Estimated size of property if it has _n_elem elements.
Definition: Property.hh:256
virtual size_t n_elements() const
Number of elements in property.
Definition: Property.hh:420
virtual void reserve(size_t _n)
Reserve memory for n elements.
Definition: Property.hh:405
virtual void set_persistent(bool _yn)
Enable or disable persistency.
Definition: Property.hh:248
Property specialization for bool type.
Definition: Property.hh:220
virtual void resize(size_t _n)
Resize storage to hold n elements.
Definition: Property.hh:406
virtual size_t element_size() const
Size of one element in bytes or UnknownSize if not known.
Definition: Property.hh:254
virtual void copy(size_t _i0, size_t _i1)
Copy one element to another.
Definition: Property.hh:116
virtual void clear()
Clear all elements and free memory.
Definition: Property.hh:112
virtual void resize(size_t _n)
Resize storage to hold n elements.
Definition: Property.hh:238
virtual size_t n_elements() const
Number of elements in property.
Definition: Property.hh:124
const_reference operator[](int _idx) const
Const access to the i'th element. No range check is performed!
Definition: Property.hh:361
virtual void copy(size_t _i0, size_t _i1)
Copy one element to another.
Definition: Property.hh:243
const vector_type & data_vector() const
Const access to property vector.
Definition: Property.hh:181
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:429
const_reference operator[](int _idx) const
Const access to the i'th element. No range check is performed!
Definition: Property.hh:193
Abstract class defining the basic interface of a dynamic property.
Definition: BaseProperty.hh:58
virtual void set_persistent(bool _yn)
Enable or disable persistency.
Definition: Property.hh:417
reference operator[](int _idx)
Access the i'th element. No range check is performed!
Definition: Property.hh:445
virtual size_t n_elements() const
Number of elements in property.
Definition: Property.hh:253
PropertyT(const PropertyT &_rhs)
Copy constructor.
Definition: Property.hh:105
PropertyT< T > * clone() const
Make a copy of self.
Definition: Property.hh:200
virtual size_t element_size() const
Size of one element in bytes or UnknownSize if not known.
Definition: Property.hh:421
reference operator[](int _idx)
Access the i'th element. No range check is performed!
Definition: Property.hh:186
virtual void reserve(size_t _n)
Reserve memory for n elements.
Definition: Property.hh:237
Handle representing a face property.
Definition: Property.hh:526
virtual size_t size_of(size_t _n_elem) const
Estimated size of property if it has _n_elem elements.
Definition: Property.hh:141
reference operator[](int _idx)
Access the i'th element. No range check is performed!
Definition: Property.hh:354
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
virtual size_t size_of(void) const
Return size of property in bytes.
Definition: Property.hh:134
PropertyT< bool > * clone() const
Make a copy of self.
Definition: Property.hh:368
virtual size_t element_size() const
Size of one element in bytes or UnknownSize if not known.
Definition: Property.hh:125
virtual void clear()
Clear all elements and free memory.
Definition: Property.hh:407
virtual void reserve(size_t _n)
Reserve memory for n elements.
Definition: Property.hh:110
virtual void swap(size_t _i0, size_t _i1)
Let two elements swap their storage place.
Definition: Property.hh:114
BaseProperty(const std::string &_name="<unknown>")
Default constructor.
Definition: BaseProperty.hh:81
virtual size_t size_of(size_t) const
Estimated size of property if it has _n_elem elements.
Definition: Property.hh:425
virtual void push_back()
Extend the number of elements by one.
Definition: Property.hh:240
Handle representing a vertex property.
Definition: Property.hh:484
virtual void resize(size_t _n)
Resize storage to hold n elements.
Definition: Property.hh:111
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:56
vector_type & data_vector()
Get reference to property vector (be careful, improper usage, e.g. resizing, may crash OpenMesh!!!) ...
Definition: Property.hh:344
virtual void swap(size_t _i0, size_t _i1)
Let two elements swap their storage place.
Definition: Property.hh:409
Handle representing a mesh property.
Definition: Property.hh:540
virtual size_t size_of() const
Return size of property in bytes.
Definition: BaseProperty.hh:138
size_t restore(std::istream &_istr, bool)
Restore self from a binary block.
Definition: Property.hh:302
PropertyT< value_type > * clone() const
Return a deep copy of self.
Definition: Property.hh:456