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