44 #ifndef OPENMESH_PROPERTY_HH 45 #define OPENMESH_PROPERTY_HH 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 clear()
Clear all elements and free memory.
PropertyT(const PropertyT &_rhs)
Copy constructor.
virtual size_t size_of(void) const
Return size of property in bytes.
virtual void push_back()
Extend the number of elements by one.
size_t size_of(const T &_v)
vector_type & data_vector()
Get reference to property vector (be careful, improper usage, e.g. resizing, may crash OpenMesh!!!) ...
virtual void resize(size_t _n)
Resize storage to hold n elements.
virtual void swap(size_t _i0, size_t _i1)
Let two elements swap their storage place.
const vector_type & data_vector() const
Const access to property vector.
size_t restore(std::istream &_istr, bool)
static const size_t UnknownSize
Indicates an error when a size is returned by a member.
virtual void push_back()
Extend the number of elements by one.
virtual void swap(size_t _i0, size_t _i1)
Let two elements swap their storage place.
BaseProperty(const std::string &_name="<unknown>")
Default constructor.
virtual void push_back()
Extend the number of elements by one.
size_t store(std::ostream &_ostr, bool) const
Store self as one binary block.
virtual size_t element_size() const
Size of one element in bytes or UnknownSize if not known.
virtual size_t size_of(size_t) const
virtual void clear()
Clear all elements and free memory.
virtual void swap(size_t _i0, size_t _i1)
Let two elements swap their storage place.
virtual void clear()
Clear all elements and free memory.
PropertyT< bool > * clone() const
Make a copy of self.
reference operator[](int _idx)
Access the i'th element. No range check is performed!
PropertyT< T > * clone() const
Make a copy of self.
virtual size_t size_of() const
Return size of property in bytes.
size_t restore(std::istream &_istr, bool _swap)
virtual void reserve(size_t _n)
Reserve memory for n elements.
const_reference operator[](int _idx) const
Const access the i'th element. No range check is performed!
virtual void set_persistent(bool _yn)
const vector_type & data_vector() const
Const access to property vector.
virtual size_t size_of() const
Return size of property in bytes.
virtual size_t element_size() const
Size of one element in bytes or UnknownSize if not known.
Default property class for any type T.
vector_type & data_vector()
Get reference to property vector (be careful, improper usage, e.g. resizing, may crash OpenMesh!!!) ...
virtual size_t n_elements() const
Number of elements in property.
reference operator[](int _idx)
Access the i'th element. No range check is performed!
PropertyT(const std::string &_name="<unknown>")
Default constructor.
virtual size_t size_of() const
Return size of property in bytes.
PropertyT< value_type > * clone() const
Return a deep copy of self.
const T * data() const
Get pointer to array (does not work for T==bool)
Base class for all handle types.
reference operator[](int _idx)
Access the i'th element. No range check is performed!
virtual void resize(size_t _n)
Resize storage to hold n elements.
virtual size_t element_size() const
Size of one element in bytes or UnknownSize if not known.
virtual size_t restore(std::istream &_istr, bool _swap)
virtual size_t n_elements() const
Number of elements in property.
virtual size_t size_of(size_t _n_elem) const
virtual size_t n_elements() const
Number of elements in property.
const_reference operator[](int _idx) const
Const access to the i'th element. No range check is performed!
virtual void reserve(size_t _n)
Reserve memory for n elements.
virtual void set_persistent(bool _yn)
virtual void copy(size_t _i0, size_t _i1)
Copy one element to another.
size_t store(std::ostream &_ostr, bool _swap) const
Store self as one binary block. Max. length of a string is 65535 bytes.
virtual void copy(size_t _i0, size_t _i1)
Copy one element to another.
virtual size_t size_of(size_t _n_elem) const
virtual void copy(size_t _i0, size_t _i1)
Copy one element to another.
const_reference operator[](int _idx) const
Const access to the i'th element. No range check is performed!
virtual size_t store(std::ostream &_ostr, bool _swap) const
Store self as one binary block.
virtual void resize(size_t _n)
Resize storage to hold n elements.
virtual void set_persistent(bool _yn)
virtual void reserve(size_t _n)
Reserve memory for n elements.